@truefoundry/assistant-ui-runtime 0.1.3-rc.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truefoundry/assistant-ui-runtime",
3
- "version": "0.1.3-rc.3",
3
+ "version": "0.1.5",
4
4
  "description": "TrueFoundry Gateway agent runtime adapter for assistant-ui",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -50,7 +50,7 @@
50
50
  "peerDependencies": {
51
51
  "@types/react": "*",
52
52
  "react": "^18 || ^19",
53
- "truefoundry-gateway-sdk": "^0.3.2-rc.1"
53
+ "truefoundry-gateway-sdk": "^0.4.0-rc.5"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "@types/react": {
@@ -63,7 +63,7 @@
63
63
  "@types/react": "^19.2.17",
64
64
  "jsdom": "^29.1.1",
65
65
  "react": "^19.2.4",
66
- "truefoundry-gateway-sdk": "0.3.2-rc.1",
66
+ "truefoundry-gateway-sdk": "0.4.0-rc.5",
67
67
  "tsup": "^8.5.0",
68
68
  "typescript": "^5.9.3",
69
69
  "vitest": "^4.1.9"
@@ -12,11 +12,11 @@ describe("user message branch helpers", () => {
12
12
  expect(parseTurnIdFromMessageId("turn-abc-user")).toBe("turn-abc");
13
13
  });
14
14
 
15
- it("resolveBranchPreviousTurnId returns null for the first turn", () => {
15
+ it("resolveBranchPreviousTurnId returns \"none\" for the first turn", () => {
16
16
  const turns: SessionTurnRecord[] = [
17
17
  { id: "a", createdAt: "", state: { status: "done", requiredActions: [], completedAt: "" } },
18
18
  ];
19
- expect(resolveBranchPreviousTurnId(turns, "a")).toBeNull();
19
+ expect(resolveBranchPreviousTurnId(turns, "a")).toBe("none");
20
20
  });
21
21
 
22
22
  it("resolveBranchPreviousTurnId returns the prior turn id", () => {
@@ -178,7 +178,7 @@ async function sessionEventItemsFromTurns(
178
178
  turnId: turn.id,
179
179
  input: turn.input,
180
180
  state: { status: "running" },
181
- createdBy: { subjectId: "u1", subjectType: "user" },
181
+ createdBy: { subjectId: "u1", subjectType: "user", subjectSlug: "u1" },
182
182
  createdAt: turn.createdAt,
183
183
  },
184
184
  });
@@ -636,7 +636,7 @@ describe("convertTurnMessages", () => {
636
636
  input: [{ type: "user.message", content: "run tool" }],
637
637
  state: {
638
638
  status: "done",
639
- output: null,
639
+ output: undefined,
640
640
  requiredActions: [
641
641
  approvalRequired({
642
642
  id: "approval-event",
@@ -703,7 +703,7 @@ describe("convertTurnMessages", () => {
703
703
  input: [{ type: "user.message", content: "run tool" }],
704
704
  state: {
705
705
  status: "done",
706
- output: null,
706
+ output: undefined,
707
707
  requiredActions: [
708
708
  approvalRequired({
709
709
  id: "approval-event",
@@ -787,7 +787,7 @@ describe("convertTurnMessages", () => {
787
787
  input: [{ type: "user.message", content: "ask me" }],
788
788
  state: {
789
789
  status: "done",
790
- output: null,
790
+ output: undefined,
791
791
  requiredActions: [
792
792
  responseRequired({
793
793
  id: "resp-req-1",
@@ -859,7 +859,7 @@ describe("convertTurnMessages", () => {
859
859
  input: [{ type: "user.message", content: "ask me" }],
860
860
  state: {
861
861
  status: "done",
862
- output: null,
862
+ output: undefined,
863
863
  requiredActions: [
864
864
  responseRequired({
865
865
  id: "resp-req-1",
@@ -2186,7 +2186,7 @@ describe("buildSnapshotFromSessionEvents", () => {
2186
2186
  turnId: "t1",
2187
2187
  input: [{ type: "user.message", content: "hello" }],
2188
2188
  state: { status: "running" },
2189
- createdBy: { subjectId: "u1", subjectType: "user" },
2189
+ createdBy: { subjectId: "u1", subjectType: "user", subjectSlug: "u1" },
2190
2190
  createdAt,
2191
2191
  },
2192
2192
  },
@@ -2241,7 +2241,7 @@ describe("buildSnapshotFromSessionEvents", () => {
2241
2241
  turnId: "t1",
2242
2242
  input: [{ type: "user.message", content: "first" }],
2243
2243
  state: { status: "running" },
2244
- createdBy: { subjectId: "u1", subjectType: "user" },
2244
+ createdBy: { subjectId: "u1", subjectType: "user", subjectSlug: "u1" },
2245
2245
  createdAt,
2246
2246
  },
2247
2247
  },
@@ -2286,7 +2286,7 @@ describe("buildSnapshotFromSessionEvents", () => {
2286
2286
  turnId: "t1",
2287
2287
  input: [{ type: "user.message", content: "first" }],
2288
2288
  state: { status: "running" },
2289
- createdBy: { subjectId: "u1", subjectType: "user" },
2289
+ createdBy: { subjectId: "u1", subjectType: "user", subjectSlug: "u1" },
2290
2290
  createdAt,
2291
2291
  },
2292
2292
  },
@@ -2311,7 +2311,7 @@ describe("buildSnapshotFromSessionEvents", () => {
2311
2311
  turnId: "t2",
2312
2312
  input: [{ type: "user.message", content: "second" }],
2313
2313
  state: { status: "running" },
2314
- createdBy: { subjectId: "u1", subjectType: "user" },
2314
+ createdBy: { subjectId: "u1", subjectType: "user", subjectSlug: "u1" },
2315
2315
  createdAt,
2316
2316
  },
2317
2317
  },
@@ -2380,7 +2380,7 @@ describe("buildSnapshotFromSessionEvents", () => {
2380
2380
  turnId: id,
2381
2381
  input: [{ type: "user.message", content: text }],
2382
2382
  state: { status: "running" },
2383
- createdBy: { subjectId: "u1", subjectType: "user" },
2383
+ createdBy: { subjectId: "u1", subjectType: "user", subjectSlug: "u1" },
2384
2384
  createdAt,
2385
2385
  },
2386
2386
  },
@@ -1276,24 +1276,24 @@ export async function buildSnapshotBeforeTurnIndex(
1276
1276
  return snapshot;
1277
1277
  }
1278
1278
 
1279
- /** Gateway turn id to branch from when resubmitting at `turnIndex` (null for first turn). */
1279
+ /** Gateway turn id to branch from when resubmitting at `turnIndex` (`"none"` for first turn). */
1280
1280
  export async function resolveGatewayBranchPreviousTurnId(
1281
1281
  session: AgentSession,
1282
1282
  turnIndex: number,
1283
1283
  orderedTurns?: Turn[],
1284
- ): Promise<string | null> {
1284
+ ): Promise<string> {
1285
1285
  if (turnIndex <= 0) {
1286
- return null;
1286
+ return "none";
1287
1287
  }
1288
1288
  const turns = orderedTurns ?? (await listSessionTurnsOrdered(session));
1289
- return turns[turnIndex - 1]?.id ?? null;
1289
+ return turns[turnIndex - 1]?.id ?? "none";
1290
1290
  }
1291
1291
 
1292
1292
  /** Resolves `previousTurnId` by turn id so partial history windows stay correct. */
1293
1293
  export async function resolveGatewayBranchPreviousTurnIdForTurn(
1294
1294
  session: AgentSession,
1295
1295
  turnId: string,
1296
- ): Promise<string | null> {
1296
+ ): Promise<string> {
1297
1297
  const turns = await listSessionTurnsOrdered(session);
1298
1298
  const turnIndex = turns.findIndex((turn) => turn.id === turnId);
1299
1299
  return resolveGatewayBranchPreviousTurnId(session, turnIndex, turns);
@@ -1456,14 +1456,14 @@ export function parseTurnIdFromMessageId(messageId: string): string {
1456
1456
  return messageId.replace(/-user$/, "");
1457
1457
  }
1458
1458
 
1459
- /** Parent turn id for branching before `turnId`; `null` when editing the first turn. */
1459
+ /** Parent turn id for branching before `turnId`; `"none"` when editing the first turn. */
1460
1460
  export function resolveBranchPreviousTurnId(
1461
1461
  turns: readonly SessionTurnRecord[],
1462
1462
  turnId: string,
1463
- ): string | null {
1463
+ ): string {
1464
1464
  const turnIndex = turns.findIndex((turn) => turn.id === turnId);
1465
1465
  if (turnIndex <= 0) {
1466
- return null;
1466
+ return "none";
1467
1467
  }
1468
1468
  return turns[turnIndex - 1]!.id;
1469
1469
  }
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
- import { mergeAgentSpec } from "./private/agentSpec.js";
3
+ import { mergeAgentSpec, type AgentSpec } from "./private/agentSpec.js";
4
4
  import {
5
5
  resolveTrueFoundryAgentConfig,
6
6
  resolveTrueFoundryAgentRuntimeOptions,
@@ -80,14 +80,14 @@ describe("mergeAgentSpec", () => {
80
80
  });
81
81
 
82
82
  it("replaces mcpServers array wholesale", () => {
83
- const base = {
83
+ const base: AgentSpec = {
84
84
  model: { name: "openai/gpt-4o" },
85
- mcpServers: [{ name: "github", enableTools: ["@all"] }],
85
+ mcpServers: [{ type: "truefoundry-mcp-registry", name: "github", enableTools: ["@all"] }],
86
86
  };
87
87
  const next = mergeAgentSpec(base, {
88
- mcpServers: [{ name: "slack", enableTools: ["@all"] }],
88
+ mcpServers: [{ type: "truefoundry-mcp-registry", name: "slack", enableTools: ["@all"] }],
89
89
  });
90
- expect(next.mcpServers).toEqual([{ name: "slack", enableTools: ["@all"] }]);
90
+ expect(next.mcpServers).toEqual([{ type: "truefoundry-mcp-registry", name: "slack", enableTools: ["@all"] }]);
91
91
  });
92
92
 
93
93
  it("replaces skills array wholesale", () => {
@@ -102,9 +102,9 @@ describe("mergeAgentSpec", () => {
102
102
  });
103
103
 
104
104
  it("model partial update does not clear mcpServers or skills", () => {
105
- const base = {
105
+ const base: AgentSpec = {
106
106
  model: { name: "openai/gpt-4o", params: { maxTokens: 1024 } },
107
- mcpServers: [{ name: "github", enableTools: ["@all"] }],
107
+ mcpServers: [{ type: "truefoundry-mcp-registry", name: "github", enableTools: ["@all"] }],
108
108
  skills: [{ fqn: "acme/skill-a:1", preload: false }],
109
109
  };
110
110
  const next = mergeAgentSpec(base, {
@@ -142,7 +142,7 @@ describe("foldPeerThreads", () => {
142
142
  id: "spawn-1",
143
143
  type: "function",
144
144
  function: { name: "create_sub_agent", arguments: "{}" },
145
- },
145
+ toolInfo: { type: "truefoundry-system", name: "create_sub_agent" }, },
146
146
  ],
147
147
  }),
148
148
  );
@@ -74,7 +74,9 @@ function ensureModelMessageContentArray(message: ModelMessageEvent): void {
74
74
  if (Array.isArray(message.content)) {
75
75
  return;
76
76
  }
77
- message.content = normalizeModelMessageContent(message);
77
+ // Gateway may stream `image_url` content blocks that aren't in the SDK content union yet.
78
+ (message as { content?: ModelMessageContentPart[] }).content =
79
+ normalizeModelMessageContent(message);
78
80
  }
79
81
 
80
82
  function mergeContentBlockDeltas(
@@ -104,7 +104,7 @@ describe("createTrueFoundryDraftThreadListAdapter", () => {
104
104
  const liveAgentSpec: AgentSpec = {
105
105
  model: { name: "anthropic/claude-opus-4-8" },
106
106
  instructions: "You are helpful.",
107
- mcpServers: [{ name: "github", enableTools: ["@all"] }],
107
+ mcpServers: [{ type: "truefoundry-mcp-registry", name: "github", enableTools: ["@all"] }],
108
108
  skills: [{ fqn: "acme/skill-a:1", preload: false }],
109
109
  };
110
110
  const createDraftSession = vi.fn().mockResolvedValue(
@@ -13,9 +13,9 @@ const createdAt = new Date().toISOString();
13
13
 
14
14
  function streamData(
15
15
  sequenceNumber: number,
16
- event: TurnStreamData["event"],
16
+ event: TurnStreamData["event"] | Record<string, unknown>,
17
17
  ): TurnStreamData {
18
- return { sequenceNumber, event };
18
+ return { sequenceNumber, event: event as TurnStreamData["event"] };
19
19
  }
20
20
 
21
21
  async function collectUpdates(
@@ -150,7 +150,7 @@ describe("streamTurn", () => {
150
150
  });
151
151
  });
152
152
 
153
- it("omits previousTurnId when branching from root", async () => {
153
+ it("forwards previousTurnId \"none\" when branching from root", async () => {
154
154
  const execute = vi.fn(() => (async function* () {})());
155
155
  const prepareTurn = vi.fn(() => ({ execute }));
156
156
  const session = {
@@ -162,13 +162,14 @@ describe("streamTurn", () => {
162
162
  streamTurnContent(
163
163
  session,
164
164
  new PeerThreadFoldState(),
165
- { userMessage: "first", previousTurnId: null },
165
+ { userMessage: "first", previousTurnId: "none" },
166
166
  new AbortController().signal,
167
167
  ),
168
168
  );
169
169
 
170
170
  expect(prepareTurn).toHaveBeenCalledWith({
171
171
  input: [{ type: "user.message", content: "first" }],
172
+ previousTurnId: "none",
172
173
  });
173
174
  });
174
175
 
@@ -248,6 +249,7 @@ describe("streamTurn", () => {
248
249
  status: "error",
249
250
  message:
250
251
  "Publisher Model is not servable in region us-central1.",
252
+ completedAt: createdAt,
251
253
  },
252
254
  });
253
255
  })(),
@@ -285,6 +287,7 @@ describe("streamTurn", () => {
285
287
  createdAt,
286
288
  state: {
287
289
  status: "error",
290
+ completedAt: createdAt,
288
291
  message: "boom",
289
292
  },
290
293
  });
package/src/streamTurn.ts CHANGED
@@ -1,9 +1,9 @@
1
- import {
2
- type AgentSession,
3
- type Turn,
4
- type TurnInputItem,
5
- TrueFoundryGatewayApi,
1
+ import type {
2
+ AgentSession,
3
+ Turn,
4
+ TurnInputItem,
6
5
  } from "truefoundry-gateway-sdk/agents";
6
+ import type { TruefoundryGatewayApi } from "truefoundry-gateway-sdk";
7
7
 
8
8
  import {
9
9
  streamTurnEvents,
@@ -18,10 +18,10 @@ export type StreamTurnOptions = {
18
18
  resumeMcpAuth?: boolean;
19
19
  inputs?: RequiredActionInput[];
20
20
  /**
21
- * Branch anchor for `prepareTurn`. Omit for `"auto"`. Pass `null` for a fresh
22
- * root turn — sent as `previous_turn_id: null` on the wire.
21
+ * Branch anchor for `prepareTurn`. Omit for `"auto"`. Pass `"none"` for a fresh
22
+ * root turn — sent as `previous_turn_id: "none"` on the wire.
23
23
  */
24
- previousTurnId?: string | null;
24
+ previousTurnId?: TruefoundryGatewayApi.PreviousTurnIdInput;
25
25
  /** Extra headers for the createTurn request (`execute` request options). */
26
26
  headers?: Record<string, string>;
27
27
  };
@@ -62,18 +62,9 @@ export async function* streamTurnContent(
62
62
  */
63
63
  onTurnIdAvailable?: (turnId: string) => void,
64
64
  ): AsyncGenerator<TurnStreamUpdate> {
65
- // When previousTurnId is explicitly null, pass it through to prepareTurn so the
66
- // SDK serializer emits `previous_turn_id: null` on the wire (first turn in session).
67
- // The SDK type doesn't admit null, but the Fern serializer handles it correctly.
68
- const previousTurnId: TrueFoundryGatewayApi.PreviousTurnIdInput | null | undefined =
69
- options.previousTurnId === null
70
- ? null
71
- : (options.previousTurnId ?? "auto");
72
65
  const turn = session.prepareTurn({
73
66
  input: buildTurnInput(options),
74
- ...(previousTurnId !== undefined
75
- ? { previousTurnId: previousTurnId as TrueFoundryGatewayApi.PreviousTurnIdInput }
76
- : {}),
67
+ previousTurnId: options.previousTurnId ?? "auto",
77
68
  });
78
69
 
79
70
  const onAbort = bindAbort(session, abortSignal);
@@ -23,7 +23,7 @@ export function createTrueFoundryThreadListAdapter(options: {
23
23
  const threads = page.data.map((session) => ({
24
24
  status: "regular" as const,
25
25
  remoteId: session.id,
26
- title: session.title,
26
+ title: session.title ?? undefined,
27
27
  lastMessageAt: new Date(session.updatedAt),
28
28
  }));
29
29
  return {
@@ -42,7 +42,7 @@ export function createTrueFoundryThreadListAdapter(options: {
42
42
  return {
43
43
  status: "regular" as const,
44
44
  remoteId: session.id,
45
- title: session.title,
45
+ title: session.title ?? undefined,
46
46
  lastMessageAt: new Date(session.updatedAt),
47
47
  };
48
48
  },
@@ -80,7 +80,7 @@ export type UseTrueFoundryAgentMessagesOptions = {
80
80
  export type SendTurnOptions =
81
81
  | {
82
82
  userMessage: UserMessageContent;
83
- previousTurnId?: string | null;
83
+ previousTurnId?: string;
84
84
  /**
85
85
  * When branching (edit/reset), the already-rewound history to send from.
86
86
  * Applied atomically with `pendingUser` so a stale React snapshot cannot
@@ -596,7 +596,7 @@ export function useTrueFoundryAgentMessages({
596
596
  isContinuation && continuationTurnId != null
597
597
  ? continuationTurnId
598
598
  : generateId();
599
- // First turns must send previousTurnId: null.
599
+ // First turns must send previousTurnId: "none".
600
600
  const isFirstTurnInSession =
601
601
  "userMessage" in options &&
602
602
  options.previousTurnId === undefined &&
@@ -697,7 +697,7 @@ export function useTrueFoundryAgentMessages({
697
697
  ...(options.previousTurnId !== undefined
698
698
  ? { previousTurnId: options.previousTurnId }
699
699
  : isFirstTurnInSession
700
- ? { previousTurnId: null }
700
+ ? { previousTurnId: "none" }
701
701
  : {}),
702
702
  ...streamHeaders,
703
703
  },
@@ -30,7 +30,6 @@ import {
30
30
  createDraftSessionBridge,
31
31
  DRAFT_SESSION_LAST_UPDATED_AT_HEADER,
32
32
  } from "./private/draftSessionBridge.js";
33
- import { getGatewayFromPrivateClient } from "./private/getGatewayFromPrivateClient.js";
34
33
  import { MCP_AUTH_RESUME_RUN_CUSTOM_KEY } from "./mcpAuth.js";
35
34
  import { createTrueFoundryDraftThreadListAdapter } from "./private/truefoundryDraftThreadListAdapter.js";
36
35
  import { trueFoundryExtras } from "./truefoundryExtras.js";
@@ -164,9 +163,7 @@ function useTrueFoundryAgentRuntimeImpl(
164
163
  onError?.(error);
165
164
  throw error;
166
165
  }
167
- // Same gateway.agents.downloadSandboxFile path as before, via the wrapped client.
168
- const gateway = getGatewayFromPrivateClient(privateClient);
169
- const response = await gateway.agents.downloadSandboxFile(sandboxId, { path });
166
+ const response = await privateClient.downloadSandboxFile(sandboxId, { path });
170
167
  return await response.blob();
171
168
  },
172
169
  [privateClient, sandboxId, onError],