Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The local backend (`start_local.sh`) accepts requests from any `http://localhost
**Projects** groups pipelines, runs and documents, and every project belongs to a workspace. **Tangent** turns a project into a chat with an agent that can build, run and debug its pipelines. Both are beta features and are off by default. Turn them on under **Settings → Beta Features** once you have a backend that supports them:

- **Projects** needs a Tangle backend that includes the Projects API (workspaces and projects). The released open-source backend does not include it yet. The backend also needs at least one active workspace. An admin can create one with **Create Workspace** in the backend's API docs (`<backend URL>/docs`).
- **Tangent** needs Projects, a running [Tangent shell](https://github.com/TangleML/tangent-shell), and the app started with `VITE_ENABLE_TANGENT=true`; without that variable the Tangent toggle stays locked. In development the app looks for the shell at `http://localhost:5173`. `pnpm oss:dev` sets up and starts the shell next to the app.
- **Tangent** needs Projects, a running [Tangent shell](https://github.com/TangleML/tangent-shell), and the app started with `VITE_ENABLE_TANGENT=true`; without that variable the Tangent toggle stays locked. In development the app looks for the shell at `http://localhost:5173`. Sessions use the agent bundle named in the workspace's data as `tangentBundleId`, or `tangle` when it isn't set; the open-source shell ships `tangle-oss`, so a workspace that uses it sets `"tangentBundleId": "tangle-oss"`. `pnpm oss:dev` sets up and starts the shell next to the app.

### AI provider configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function mockBaseUrl(baseUrl: string | null) {
vi.mocked(useTangentBaseUrl).mockReturnValue({
baseUrl,
localAddress: null,
bundleId: "tangle",
isLoading: false,
isError: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function mockBaseUrl(baseUrl: string | null) {
vi.mocked(useTangentBaseUrl).mockReturnValue({
baseUrl,
localAddress: null,
bundleId: "tangle",
isLoading: false,
isError: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function useProjectStore(
askedSessionId?: string;
userId?: string;
tangentBaseUrl: string | null;
bundleId: string;
},
): TangentProjectStore {
const create = () => {
Expand All @@ -61,6 +62,7 @@ function useProjectStore(
: undefined,
);
store.setTangentBaseUrl(tangentBaseUrl);
store.setBundleId(seed.bundleId);
store.setDefaultSessionId(seed.defaultSessionId);
if (seed.askedSessionId) store.selectSession(seed.askedSessionId);
return store;
Expand All @@ -84,13 +86,14 @@ export function TangentProjectProvider({
} = useProjectSessions(projectId);
const ensureSharedFolderId = useProjectSharedFolder(projectId);
const asked = readTangentSessionParam(useSearch({ strict: false }));
const { baseUrl } = useTangentBaseUrl(projectId);
const { baseUrl, bundleId } = useTangentBaseUrl(projectId);
const queryClient = useQueryClient();
const store = useProjectStore(projectId, {
defaultSessionId: sessions[0]?.sessionId,
askedSessionId: asked?.kind === "existing" ? asked.sessionId : undefined,
userId: queryClient.getQueryData(userQueryOptions.queryKey)?.id,
tangentBaseUrl: baseUrl,
bundleId,
});
const storage = usePipelineStorage();
const recordSessionRun = useRecordSessionRun();
Expand Down Expand Up @@ -135,6 +138,10 @@ export function TangentProjectProvider({
store.setDefaultSessionId(defaultSessionId);
}, [store, defaultSessionId]);

useEffect(() => {
store.setBundleId(bundleId);
}, [store, bundleId]);

const authToken = useRemoteEnvAuthToken();
useBackfillSessionTags({
projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function given(
vi.mocked(useTangentBaseUrl).mockReturnValue({
baseUrl,
localAddress: null,
bundleId: "tangle",
isLoading: false,
isError: false,
});
Expand Down
10 changes: 9 additions & 1 deletion src/routes/v2/pages/Tangent/hooks/useTangentBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { resolveTangentBaseUrl } from "@/routes/v2/pages/Tangent/services/tangentBaseUrl";
import { TANGENT_BUNDLE_ID } from "@/routes/v2/pages/Tangent/constants";
import {
resolveTangentBaseUrl,
resolveTangentBundleId,
} from "@/routes/v2/pages/Tangent/services/tangentBaseUrl";
import { useProject } from "@/services/projects/useProjects";
import { useWorkspace } from "@/services/projects/useWorkspaces";

interface TangentBaseUrl {
baseUrl: string | null;
localAddress: string | null;
bundleId: string;
isLoading: boolean;
isError: boolean;
}
Expand Down Expand Up @@ -33,6 +38,9 @@ export function useTangentBaseUrl(projectId: string): TangentBaseUrl {
return {
baseUrl: resolution?.baseUrl ?? null,
localAddress: resolution?.localAddress ?? null,
bundleId: workspace
? resolveTangentBundleId(workspace.metadata)
: TANGENT_BUNDLE_ID,
isLoading: isProjectLoading || isWorkspaceLoading,
isError: isProjectError || isWorkspaceError,
};
Expand Down
8 changes: 5 additions & 3 deletions src/routes/v2/pages/Tangent/services/sessionStartError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TANGENT_BUNDLE_ID } from "@/routes/v2/pages/Tangent/constants";
import { getErrorMessage, safeJsonParse } from "@/utils/string";
import { isRecord } from "@/utils/typeGuards";

Expand All @@ -18,9 +17,12 @@ export function isMissingBundleError(error: unknown): boolean {
return tangentMessage(error) === MISSING_BUNDLE;
}

export function describeSessionStartError(error: unknown): string {
export function describeSessionStartError(
error: unknown,
bundleId: string,
): string {
if (isMissingBundleError(error)) {
return `This Tangent server doesn't have the "${TANGENT_BUNDLE_ID}" agent bundle installed.`;
return `This Tangent server doesn't have the "${bundleId}" agent bundle installed. To use a different bundle, set "tangentBundleId" in the workspace's data.`;
}
return tangentMessage(error);
}
27 changes: 25 additions & 2 deletions src/routes/v2/pages/Tangent/services/tangentBaseUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { afterEach, describe, expect, it, vi } from "vitest";

import { DEV_TANGENT_BASE_URL } from "@/routes/v2/pages/Tangent/constants";
import {
DEV_TANGENT_BASE_URL,
TANGENT_BUNDLE_ID,
} from "@/routes/v2/pages/Tangent/constants";

import { resolveTangentBaseUrl } from "./tangentBaseUrl";
import {
resolveTangentBaseUrl,
resolveTangentBundleId,
} from "./tangentBaseUrl";

afterEach(() => {
vi.unstubAllEnvs();
Expand Down Expand Up @@ -110,3 +116,20 @@ describe("resolveTangentBaseUrl", () => {
});
});
});

describe("resolveTangentBundleId", () => {
it("uses the bundle the workspace names", () => {
expect(resolveTangentBundleId({ tangentBundleId: " tangle-oss " })).toBe(
"tangle-oss",
);
});

it.each([
["no metadata", null],
["no tangentBundleId", { tangentBaseUrl: "https://tangent.example.com" }],
["a blank tangentBundleId", { tangentBundleId: " " }],
["a non-string tangentBundleId", { tangentBundleId: 7 }],
])("falls back to the default bundle for %s", (_case, metadata) => {
expect(resolveTangentBundleId(metadata)).toBe(TANGENT_BUNDLE_ID);
});
});
20 changes: 19 additions & 1 deletion src/routes/v2/pages/Tangent/services/tangentBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DEV_TANGENT_BASE_URL } from "@/routes/v2/pages/Tangent/constants";
import {
DEV_TANGENT_BASE_URL,
TANGENT_BUNDLE_ID,
} from "@/routes/v2/pages/Tangent/constants";
import { isRecord } from "@/utils/typeGuards";

export interface TangentBaseUrlResolution {
Expand Down Expand Up @@ -73,3 +76,18 @@ export function resolveTangentBaseUrl(

return { baseUrl: normalized, localAddress: null };
}

/**
* The agent bundle that backs sessions started in a workspace. Defaults to
* {@link TANGENT_BUNDLE_ID} so a workspace that doesn't name one keeps the
* standard Tangle bundle.
*/
export function resolveTangentBundleId(
metadata: Record<string, unknown> | null | undefined,
): string {
if (!isRecord(metadata)) return TANGENT_BUNDLE_ID;
const { tangentBundleId } = metadata;
if (typeof tangentBundleId !== "string") return TANGENT_BUNDLE_ID;
const trimmed = tangentBundleId.trim();
return trimmed.length > 0 ? trimmed : TANGENT_BUNDLE_ID;
}
21 changes: 20 additions & 1 deletion src/routes/v2/pages/Tangent/store/TangentProjectStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,31 @@ describe("TangentProjectStore.startSession", () => {

await expect(store.startSession()).resolves.toBe(false);

const message = `This Tangent server doesn't have the "${TANGENT_BUNDLE_ID}" agent bundle installed.`;
const message = `This Tangent server doesn't have the "${TANGENT_BUNDLE_ID}" agent bundle installed. To use a different bundle, set "tangentBundleId" in the workspace's data.`;
expect(io.newSession).toHaveBeenCalledTimes(1);
expect(io.notify).toHaveBeenCalledWith(message, "error");
expect(store.sessionStartError).toBe(message);
});

it("starts sessions with the workspace's bundle and names it when it is missing", async () => {
const store = new TangentProjectStore("project-1");
const io = makeSessionIo(null);
io.newSession.mockRejectedValue(
new Error('{"error":"Agent bundle not found"}'),
);
store.setSessionIo(io);
store.setBundleId("tangle-oss");

await store.startSession();

expect(io.newSession).toHaveBeenCalledWith(
"",
"tangle-oss",
expect.anything(),
);
expect(store.sessionStartError).toContain('the "tangle-oss" agent bundle');
});

it("reads the message out of a refusal's JSON body", async () => {
const store = new TangentProjectStore("project-1");
const io = makeSessionIo(null);
Expand Down
16 changes: 9 additions & 7 deletions src/routes/v2/pages/Tangent/store/TangentProjectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class TangentProjectStore {

@observable.ref accessor openTabs: OpenTabs;
@observable accessor tangentBaseUrl: string | null = null;
@observable accessor bundleId: string = TANGENT_BUNDLE_ID;
@observable.shallow accessor chatBySession = new Map<string, ChatSlice>();

// Live tab wiring is intentionally non-observable: it's registered/read by the
Expand Down Expand Up @@ -165,6 +166,10 @@ export class TangentProjectStore {
this.tangentBaseUrl = baseUrl;
}

@action setBundleId(bundleId: string) {
this.bundleId = bundleId;
}

@action setSessionIo(io: TangentSessionIo) {
this.#io = io;
}
Expand Down Expand Up @@ -242,6 +247,7 @@ export class TangentProjectStore {
const io = this.#io;
if (!io) return false;
const previous = this.activeSessionId;
const bundleId = this.bundleId;
runInAction(() => {
this.isStartingSession = true;
this.sessionStartError = undefined;
Expand Down Expand Up @@ -279,7 +285,7 @@ export class TangentProjectStore {
memory: shared?.memory ?? BUNDLE_KNOWLEDGE_BINDING,
});
const { sessionId } = await io
.newSession(prompt, TANGENT_BUNDLE_ID, sessionOptions(sharedMemory))
.newSession(prompt, bundleId, sessionOptions(sharedMemory))
.catch((error: unknown) => {
if (!sharedMemory || isMissingBundleError(error)) throw error;
// The stored folder id may be unknown to this Tangent server (base
Expand All @@ -289,11 +295,7 @@ export class TangentProjectStore {
"Failed to start a session with the project's shared folder; retrying without it",
error,
);
return io.newSession(
prompt,
TANGENT_BUNDLE_ID,
sessionOptions(undefined),
);
return io.newSession(prompt, bundleId, sessionOptions(undefined));
});
const resource = await io.attachSession(sessionId, options?.name);
runInAction(() => {
Expand All @@ -306,7 +308,7 @@ export class TangentProjectStore {
}
return true;
} catch (error) {
const message = describeSessionStartError(error);
const message = describeSessionStartError(error, bundleId);
runInAction(() => {
this.sessionStartError = message;
});
Expand Down
Loading