@assistant-ui/react-ai-sdk 1.3.33 → 1.3.35

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.
Files changed (66) hide show
  1. package/dist/client.d.ts +1 -2
  2. package/dist/client.js +1 -2
  3. package/dist/frontendTools.d.ts +1 -1
  4. package/dist/generativeTools.d.ts +1 -1
  5. package/dist/generativeTools.d.ts.map +1 -1
  6. package/dist/generativeTools.js +1 -1
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.js +1 -2
  9. package/dist/index.native.d.ts +1 -2
  10. package/dist/index.native.js +1 -2
  11. package/dist/modelContentEnvelope.d.ts +2 -1
  12. package/dist/modelContentEnvelope.d.ts.map +1 -1
  13. package/dist/toolOutputConversion.d.ts +1 -1
  14. package/dist/ui/resumable.d.ts +2 -1
  15. package/dist/ui/resumable.d.ts.map +1 -1
  16. package/dist/ui/resumable.js +1 -1
  17. package/dist/ui/use-chat/AssistantChatTransport.js +2 -2
  18. package/dist/ui/use-chat/useAISDKRuntime.js +9 -1
  19. package/dist/ui/use-chat/useAISDKRuntime.js.map +1 -1
  20. package/dist/ui/use-chat/useExternalHistory.d.ts +4 -1
  21. package/dist/ui/use-chat/useExternalHistory.d.ts.map +1 -1
  22. package/dist/ui/use-chat/useExternalHistory.js +25 -1
  23. package/dist/ui/use-chat/useExternalHistory.js.map +1 -1
  24. package/dist/ui/utils/convertMessage.d.ts +1 -1
  25. package/dist/ui/utils/convertMessage.d.ts.map +1 -1
  26. package/dist/ui/utils/convertMessage.js +5 -2
  27. package/dist/ui/utils/convertMessage.js.map +1 -1
  28. package/package.json +6 -6
  29. package/src/ui/use-chat/useAISDKRuntime.test.ts +48 -1
  30. package/src/ui/use-chat/useAISDKRuntime.ts +19 -1
  31. package/src/ui/use-chat/useExternalHistory.ts +30 -1
  32. package/src/ui/utils/convertMessage.test.ts +36 -5
  33. package/src/ui/utils/convertMessage.ts +9 -1
  34. package/dist/assistant-stream/dist/core/AssistantStream.d.ts +0 -1
  35. package/dist/assistant-stream/dist/core/AssistantStreamChunk.d.ts +0 -1
  36. package/dist/assistant-stream/dist/core/accumulators/AssistantMessageStream.d.ts +0 -1
  37. package/dist/assistant-stream/dist/core/accumulators/assistant-message-accumulator.d.ts +0 -1
  38. package/dist/assistant-stream/dist/core/modules/assistant-stream.d.ts +0 -1
  39. package/dist/assistant-stream/dist/core/modules/text.d.ts +0 -1
  40. package/dist/assistant-stream/dist/core/modules/tool-call.d.ts +0 -1
  41. package/dist/assistant-stream/dist/core/serialization/PlainText.d.ts +0 -1
  42. package/dist/assistant-stream/dist/core/serialization/assistant-transport/AssistantTransport.d.ts +0 -1
  43. package/dist/assistant-stream/dist/core/serialization/data-stream/DataStream.d.ts +0 -1
  44. package/dist/assistant-stream/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts +0 -1
  45. package/dist/assistant-stream/dist/core/tool/ToolExecutionStream.d.ts +0 -1
  46. package/dist/assistant-stream/dist/core/tool/schema-utils.d.ts +0 -15
  47. package/dist/assistant-stream/dist/core/tool/schema-utils.d.ts.map +0 -1
  48. package/dist/assistant-stream/dist/core/tool/schema-utils.js +0 -59
  49. package/dist/assistant-stream/dist/core/tool/schema-utils.js.map +0 -1
  50. package/dist/assistant-stream/dist/core/tool/tool-types.d.ts +0 -69
  51. package/dist/assistant-stream/dist/core/tool/tool-types.d.ts.map +0 -1
  52. package/dist/assistant-stream/dist/core/tool/toolResultStream.d.ts +0 -1
  53. package/dist/assistant-stream/dist/core/utils/stream/AssistantMetaTransformStream.d.ts +0 -1
  54. package/dist/assistant-stream/dist/core/utils/stream/AssistantTransformStream.d.ts +0 -1
  55. package/dist/assistant-stream/dist/core/utils/types.d.ts +0 -1
  56. package/dist/assistant-stream/dist/index.d.ts +0 -2
  57. package/dist/assistant-stream/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts +0 -140
  58. package/dist/assistant-stream/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +0 -1
  59. package/dist/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.d.ts +0 -6
  60. package/dist/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.d.ts.map +0 -1
  61. package/dist/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.js +0 -6
  62. package/dist/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.js.map +0 -1
  63. package/dist/assistant-stream/dist/resumable/index.d.ts +0 -1
  64. package/dist/assistant-stream/dist/utils/json/json-value.d.ts +0 -10
  65. package/dist/assistant-stream/dist/utils/json/json-value.d.ts.map +0 -1
  66. package/dist/assistant-stream/dist/utils.d.ts +0 -1
@@ -8,10 +8,14 @@ import { validateUIMessages } from "ai";
8
8
  // in isolation). Every other dependency — useExternalStoreRuntime,
9
9
  // useToolInvocations, the message converter — runs for real.
10
10
  vi.mock("./useExternalHistory", () => ({
11
- useExternalHistory: vi.fn(() => false),
11
+ useExternalHistory: vi.fn(() => ({
12
+ isLoading: false,
13
+ deleteMessage: vi.fn().mockResolvedValue(undefined),
14
+ })),
12
15
  toExportedMessageRepository: vi.fn(),
13
16
  }));
14
17
 
18
+ import { useExternalHistory } from "./useExternalHistory";
15
19
  import { useAISDKRuntime } from "./useAISDKRuntime";
16
20
 
17
21
  const createChatHelpers = (messages: any[] = []) => {
@@ -46,6 +50,10 @@ const textOf = (message: any): string =>
46
50
  describe("useAISDKRuntime", () => {
47
51
  beforeEach(() => {
48
52
  vi.clearAllMocks();
53
+ vi.mocked(useExternalHistory).mockReturnValue({
54
+ isLoading: false,
55
+ deleteMessage: vi.fn().mockResolvedValue(undefined),
56
+ });
49
57
  });
50
58
 
51
59
  it("sends a new user message through the runtime", async () => {
@@ -277,6 +285,45 @@ describe("useAISDKRuntime", () => {
277
285
  );
278
286
  });
279
287
 
288
+ it("deletes only the selected message from AI SDK state", async () => {
289
+ const deleteMessage = vi.fn().mockResolvedValue(undefined);
290
+ vi.mocked(useExternalHistory).mockReturnValue({
291
+ isLoading: false,
292
+ deleteMessage,
293
+ });
294
+ const chat = createChatHelpers([
295
+ { id: "u1", role: "user", parts: [{ type: "text", text: "first" }] },
296
+ {
297
+ id: "a1",
298
+ role: "assistant",
299
+ parts: [{ type: "text", text: "first-answer" }],
300
+ },
301
+ { id: "u2", role: "user", parts: [{ type: "text", text: "second" }] },
302
+ {
303
+ id: "a2",
304
+ role: "assistant",
305
+ parts: [{ type: "text", text: "second-answer" }],
306
+ },
307
+ ]);
308
+
309
+ const { result } = renderHook(() => useAISDKRuntime(chat));
310
+
311
+ await waitFor(() => {
312
+ expect(result.current.thread.getState().messages).toHaveLength(4);
313
+ });
314
+
315
+ await act(async () => {
316
+ result.current.thread.getMessageById("u2").delete();
317
+ });
318
+
319
+ expect(deleteMessage).toHaveBeenCalledWith("u2");
320
+ expect(chat.messages.map((message: any) => message.id)).toEqual([
321
+ "u1",
322
+ "a1",
323
+ "a2",
324
+ ]);
325
+ });
326
+
280
327
  it("edit slices history to parentId and sends the edited message", async () => {
281
328
  const chat = createChatHelpers([
282
329
  { id: "u1", role: "user", parts: [{ type: "text", text: "first" }] },
@@ -158,7 +158,7 @@ export const useAISDKRuntime = <UI_MESSAGE extends UIMessage = UIMessage>(
158
158
  },
159
159
  }));
160
160
 
161
- const isLoading = useExternalHistory(
161
+ const { isLoading, deleteMessage: deleteHistoryMessage } = useExternalHistory(
162
162
  runtimeRef,
163
163
  adapters?.history ?? contextAdapters?.history,
164
164
  AISDKMessageConverter.toThreadMessages as (
@@ -315,6 +315,24 @@ export const useAISDKRuntime = <UI_MESSAGE extends UIMessage = UIMessage>(
315
315
  metadata: message.runConfig,
316
316
  });
317
317
  },
318
+ onDelete: async (messageId) => {
319
+ const threadMessages = runtimeRef.current.thread.getState().messages;
320
+ const messageIndex = threadMessages.findIndex(
321
+ (message) => message.id === messageId,
322
+ );
323
+ if (messageIndex === -1) return;
324
+
325
+ await deleteHistoryMessage(messageId);
326
+
327
+ const deleteIds = new Set(
328
+ getExternalStoreMessages<UI_MESSAGE>(threadMessages[messageIndex]!).map(
329
+ (message) => message.id,
330
+ ),
331
+ );
332
+ chatHelpers.setMessages((current) =>
333
+ current.filter((message) => !deleteIds.has(message.id)),
334
+ );
335
+ },
318
336
  onReload: async (parentId: string | null, config) => {
319
337
  lastRunConfigRef.current = config.runConfig;
320
338
  const newMessages = sliceMessagesUntil(chatHelpers.messages, parentId);
@@ -292,5 +292,34 @@ export const useExternalHistory = <TMessage>(
292
292
  };
293
293
  }, [formatAdapter, storageFormatAdapter, runtimeRef]);
294
294
 
295
- return isLoading;
295
+ const deleteMessage = useCallback(
296
+ async (messageId: string) => {
297
+ if (!formatAdapter?.delete) return;
298
+
299
+ const messages = runtimeRef.current.thread.getState().messages;
300
+ const messageIndex = messages.findIndex((m) => m.id === messageId);
301
+ if (messageIndex === -1) return;
302
+
303
+ const previousInnerMessages = messages
304
+ .slice(0, messageIndex)
305
+ .flatMap(getExternalStoreMessages<TMessage>);
306
+ let parentId = previousInnerMessages.at(-1)
307
+ ? storageFormatAdapter.getId(previousInnerMessages.at(-1)!)
308
+ : null;
309
+ const itemsToDelete = getExternalStoreMessages<TMessage>(
310
+ messages[messageIndex]!,
311
+ ).map((message) => {
312
+ const item = { parentId, message };
313
+ parentId = storageFormatAdapter.getId(message);
314
+ return item;
315
+ });
316
+
317
+ await formatAdapter.delete(itemsToDelete);
318
+
319
+ historyIds.current.delete(messageId);
320
+ },
321
+ [formatAdapter, runtimeRef, storageFormatAdapter],
322
+ );
323
+
324
+ return { isLoading, deleteMessage };
296
325
  };
@@ -1,5 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import type { ReadonlyJSONObject } from "assistant-stream/utils";
2
+ import {
3
+ getPartialJsonObjectFieldState,
4
+ type ReadonlyJSONObject,
5
+ } from "assistant-stream/utils";
3
6
  import {
4
7
  AISDKMessageConverter,
5
8
  type AISDKMessageConverterMetadata,
@@ -365,6 +368,34 @@ describe("AISDKMessageConverter", () => {
365
368
  expect(toolCall?.argsText).toBe('{"city":"NYC');
366
369
  });
367
370
 
371
+ it("attaches partial-JSON meta marking the trailing streaming field", () => {
372
+ const converted = AISDKMessageConverter.toThreadMessages([
373
+ {
374
+ id: "a1",
375
+ role: "assistant",
376
+ parts: [
377
+ {
378
+ type: "tool-weather",
379
+ toolCallId: "tc-1",
380
+ state: "input-streaming",
381
+ input: { city: "NYC", units: "F" },
382
+ },
383
+ ],
384
+ } as any,
385
+ ]);
386
+
387
+ const toolCall = converted[0]?.content.find(
388
+ (part): part is any => part.type === "tool-call",
389
+ );
390
+ expect(toolCall?.args).toMatchObject({ city: "NYC", units: "F" });
391
+ expect(getPartialJsonObjectFieldState(toolCall!.args, ["city"])).toBe(
392
+ "complete",
393
+ );
394
+ expect(getPartialJsonObjectFieldState(toolCall!.args, ["units"])).toBe(
395
+ "partial",
396
+ );
397
+ });
398
+
368
399
  it("keeps observed key order from streaming snapshots for final tool args", () => {
369
400
  const metadata: AISDKMessageConverterMetadata = {
370
401
  toolArgsKeyOrderCache: new Map<string, Map<string, string[]>>(),
@@ -518,19 +549,19 @@ describe("AISDKMessageConverter", () => {
518
549
 
519
550
  const first = convertWithInput({ city: "NYC" });
520
551
  expect(first?.argsText).toBe('{"city":"NYC');
521
- expect(first?.args).toEqual({ city: "NYC" });
552
+ expect(first?.args).toMatchObject({ city: "NYC" });
522
553
 
523
554
  const dropped = convertWithInput(null);
524
555
  expect(dropped?.argsText).toBe('{"city":"NYC');
525
- expect(dropped?.args).toEqual({ city: "NYC" });
556
+ expect(dropped?.args).toMatchObject({ city: "NYC" });
526
557
 
527
558
  const undef = convertWithInput(undefined);
528
559
  expect(undef?.argsText).toBe('{"city":"NYC');
529
- expect(undef?.args).toEqual({ city: "NYC" });
560
+ expect(undef?.args).toMatchObject({ city: "NYC" });
530
561
 
531
562
  const grown = convertWithInput({ city: "NYC", units: "F" });
532
563
  expect(grown?.argsText).toBe('{"city":"NYC","units":"F');
533
- expect(grown?.args).toEqual({ city: "NYC", units: "F" });
564
+ expect(grown?.args).toMatchObject({ city: "NYC", units: "F" });
534
565
  });
535
566
 
536
567
  it("preserves last good input across terminal state transitions", () => {
@@ -15,7 +15,10 @@ import {
15
15
  type ThreadMessageLike,
16
16
  type McpAppMetadata,
17
17
  } from "@assistant-ui/core";
18
- import type { ReadonlyJSONObject } from "assistant-stream/utils";
18
+ import {
19
+ parsePartialJsonObject,
20
+ type ReadonlyJSONObject,
21
+ } from "assistant-stream/utils";
19
22
  import { unwrapModelContentEnvelope } from "../../modelContentEnvelope";
20
23
 
21
24
  type MessageMetadata = ThreadMessageLike["metadata"];
@@ -259,6 +262,11 @@ function convertParts(
259
262
  if (part.state === "input-streaming") {
260
263
  // strip closing delimiters added by the AI SDK's fix-json
261
264
  argsText = stripClosingDelimiters(argsText);
265
+ // Re-parse so args carries the partial-JSON meta that marks which
266
+ // field is still mid-arrival, like every argsText-based runtime.
267
+ // The key-order cache appends new keys last, so the trailing field
268
+ // of the stripped text is the streaming frontier.
269
+ args = parsePartialJsonObject(argsText) ?? args;
262
270
  } else {
263
271
  metadata.toolArgsKeyOrderCache?.delete(argsKeyOrderCacheKey);
264
272
  if (
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,15 +0,0 @@
1
- import { JSONSchema7 } from "../../node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.js";
2
- import { ProviderOptions } from "./tool-types.js";
3
- //#region ../assistant-stream/dist/core/tool/schema-utils.d.ts
4
- //#region src/core/tool/schema-utils.d.ts
5
- /**
6
- * Type for a tool definition with JSON Schema parameters.
7
- */
8
- type ToolJSONSchema = {
9
- description?: string;
10
- parameters: JSONSchema7;
11
- providerOptions?: ProviderOptions;
12
- };
13
- //#endregion
14
- export { ToolJSONSchema };
15
- //# sourceMappingURL=schema-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema-utils.d.ts","names":["description","parameters","JSONSchema7","providerOptions","ProviderOptions","filter","name","Tool","tool","StandardSchemaV1","schema","Record","tools","ToToolsJSONSchemaOptions","options","ToolJSONSchema"],"sources":["../../../../../../assistant-stream/dist/core/tool/schema-utils.d.ts"],"mappings":";;;;AAEyD;;;AAAA,KAMpD,cAAA;EACHA,WAAAA;EACAC,UAAAA,EAAY,WAAA;EACZE,eAAAA,GAAkB,eAAe;AAAA"}
@@ -1,59 +0,0 @@
1
- //#region ../assistant-stream/dist/core/tool/schema-utils.js
2
- function isStandardSchema(schema) {
3
- return typeof schema === "object" && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object";
4
- }
5
- function hasToJSONSchemaMethod(schema) {
6
- return typeof schema === "object" && schema !== null && "toJSONSchema" in schema && typeof schema.toJSONSchema === "function";
7
- }
8
- function hasToJSONMethod(schema) {
9
- return typeof schema === "object" && schema !== null && "toJSON" in schema && typeof schema.toJSON === "function";
10
- }
11
- /**
12
- * Converts a schema to JSONSchema7.
13
- * Supports:
14
- * - StandardSchemaV1 with ~standard.toJSONSchema (e.g., Zod v4)
15
- * - StandardSchemaV1 with ~standard.jsonSchema.input() (e.g., Zod v4)
16
- * - Objects with toJSONSchema() method (e.g., Zod v4)
17
- * - Objects with toJSON() method
18
- * - Plain JSONSchema7 objects (must have a "type" property)
19
- */
20
- function toJSONSchema(schema) {
21
- if (isStandardSchema(schema)) {
22
- const toJSONSchemaMethod = schema["~standard"].toJSONSchema;
23
- if (typeof toJSONSchemaMethod === "function") return toJSONSchemaMethod();
24
- const jsonSchema = schema["~standard"].jsonSchema;
25
- if (typeof jsonSchema === "object" && jsonSchema !== null && typeof jsonSchema.input === "function") return jsonSchema.input();
26
- }
27
- if (hasToJSONSchemaMethod(schema)) return schema.toJSONSchema();
28
- if (hasToJSONMethod(schema)) return schema.toJSON();
29
- if (isStandardSchema(schema)) throw new Error("Could not convert schema to JSON Schema. The schema implements Standard Schema but does not support JSON Schema conversion. If you are using Zod, please upgrade to Zod v4 (npm install zod@latest). Alternatively, pass a plain JSON Schema object instead.");
30
- return schema;
31
- }
32
- function defaultToolFilter(_name, tool) {
33
- return !tool.disabled && tool.type !== "backend" && (tool.type !== "frontend" || tool.execute !== void 0);
34
- }
35
- function toolHasUploadableParameters(tool) {
36
- return tool.parameters !== void 0 && !tool.unstable_backendDefault?.parameters;
37
- }
38
- /**
39
- * Converts a record of tools to a record of tool definitions with JSON Schema parameters.
40
- * By default, filters out disabled tools and backend tools.
41
- *
42
- * Entries are emitted in alphabetical order so the resulting request body is
43
- * byte-identical regardless of the order in which tools were registered. This
44
- * keeps provider prompt caches stable across renders that mount tools in
45
- * different orders.
46
- */
47
- function toToolsJSONSchema(tools, options = {}) {
48
- if (!tools) return {};
49
- const filter = options.filter ?? defaultToolFilter;
50
- return Object.fromEntries(Object.entries(tools).filter(([name, tool]) => filter(name, tool)).filter((entry) => toolHasUploadableParameters(entry[1])).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, tool]) => [name, {
51
- ...tool.description && { description: tool.description },
52
- parameters: toJSONSchema(tool.parameters),
53
- ...tool.providerOptions && { providerOptions: tool.providerOptions }
54
- }]));
55
- }
56
- //#endregion
57
- export { toJSONSchema, toToolsJSONSchema };
58
-
59
- //# sourceMappingURL=schema-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema-utils.js","names":[],"sources":["../../../../../../assistant-stream/dist/core/tool/schema-utils.js"],"sourcesContent":["//#region src/core/tool/schema-utils.ts\nfunction isStandardSchema(schema) {\n\treturn typeof schema === \"object\" && schema !== null && \"~standard\" in schema && typeof schema[\"~standard\"] === \"object\";\n}\nfunction hasToJSONSchemaMethod(schema) {\n\treturn typeof schema === \"object\" && schema !== null && \"toJSONSchema\" in schema && typeof schema.toJSONSchema === \"function\";\n}\nfunction hasToJSONMethod(schema) {\n\treturn typeof schema === \"object\" && schema !== null && \"toJSON\" in schema && typeof schema.toJSON === \"function\";\n}\n/**\n* Converts a schema to JSONSchema7.\n* Supports:\n* - StandardSchemaV1 with ~standard.toJSONSchema (e.g., Zod v4)\n* - StandardSchemaV1 with ~standard.jsonSchema.input() (e.g., Zod v4)\n* - Objects with toJSONSchema() method (e.g., Zod v4)\n* - Objects with toJSON() method\n* - Plain JSONSchema7 objects (must have a \"type\" property)\n*/\nfunction toJSONSchema(schema) {\n\tif (isStandardSchema(schema)) {\n\t\tconst toJSONSchemaMethod = schema[\"~standard\"].toJSONSchema;\n\t\tif (typeof toJSONSchemaMethod === \"function\") return toJSONSchemaMethod();\n\t\tconst jsonSchema = schema[\"~standard\"].jsonSchema;\n\t\tif (typeof jsonSchema === \"object\" && jsonSchema !== null && typeof jsonSchema.input === \"function\") return jsonSchema.input();\n\t}\n\tif (hasToJSONSchemaMethod(schema)) return schema.toJSONSchema();\n\tif (hasToJSONMethod(schema)) return schema.toJSON();\n\tif (isStandardSchema(schema)) throw new Error(\"Could not convert schema to JSON Schema. The schema implements Standard Schema but does not support JSON Schema conversion. If you are using Zod, please upgrade to Zod v4 (npm install zod@latest). Alternatively, pass a plain JSON Schema object instead.\");\n\treturn schema;\n}\n/**\n* Returns a copy of the JSON Schema with `required` removed recursively,\n* making every property optional. Array item schemas are left unchanged.\n*/\nfunction toPartialJSONSchema(schema) {\n\tconst { required: _, ...result } = schema;\n\tif (result.properties) result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, prop]) => {\n\t\tif (typeof prop === \"object\" && prop !== null && !Array.isArray(prop)) {\n\t\t\tconst p = prop;\n\t\t\treturn [key, p.properties != null ? toPartialJSONSchema(p) : prop];\n\t\t}\n\t\treturn [key, prop];\n\t}));\n\treturn result;\n}\nfunction defaultToolFilter(_name, tool) {\n\treturn !tool.disabled && tool.type !== \"backend\" && (tool.type !== \"frontend\" || tool.execute !== void 0);\n}\nfunction toolHasUploadableParameters(tool) {\n\treturn tool.parameters !== void 0 && !tool.unstable_backendDefault?.parameters;\n}\n/**\n* Converts a record of tools to a record of tool definitions with JSON Schema parameters.\n* By default, filters out disabled tools and backend tools.\n*\n* Entries are emitted in alphabetical order so the resulting request body is\n* byte-identical regardless of the order in which tools were registered. This\n* keeps provider prompt caches stable across renders that mount tools in\n* different orders.\n*/\nfunction toToolsJSONSchema(tools, options = {}) {\n\tif (!tools) return {};\n\tconst filter = options.filter ?? defaultToolFilter;\n\treturn Object.fromEntries(Object.entries(tools).filter(([name, tool]) => filter(name, tool)).filter((entry) => toolHasUploadableParameters(entry[1])).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, tool]) => [name, {\n\t\t...tool.description && { description: tool.description },\n\t\tparameters: toJSONSchema(tool.parameters),\n\t\t...tool.providerOptions && { providerOptions: tool.providerOptions }\n\t}]));\n}\n//#endregion\nexport { toJSONSchema, toPartialJSONSchema, toToolsJSONSchema };\n\n//# sourceMappingURL=schema-utils.js.map"],"mappings":";AACA,SAAS,iBAAiB,QAAQ;CACjC,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,eAAe,UAAU,OAAO,OAAO,iBAAiB;AACjH;AACA,SAAS,sBAAsB,QAAQ;CACtC,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,kBAAkB,UAAU,OAAO,OAAO,iBAAiB;AACpH;AACA,SAAS,gBAAgB,QAAQ;CAChC,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,YAAY,UAAU,OAAO,OAAO,WAAW;AACxG;;;;;;;;;;AAUA,SAAS,aAAa,QAAQ;CAC7B,IAAI,iBAAiB,MAAM,GAAG;EAC7B,MAAM,qBAAqB,OAAO,YAAY,CAAC;EAC/C,IAAI,OAAO,uBAAuB,YAAY,OAAO,mBAAmB;EACxE,MAAM,aAAa,OAAO,YAAY,CAAC;EACvC,IAAI,OAAO,eAAe,YAAY,eAAe,QAAQ,OAAO,WAAW,UAAU,YAAY,OAAO,WAAW,MAAM;CAC9H;CACA,IAAI,sBAAsB,MAAM,GAAG,OAAO,OAAO,aAAa;CAC9D,IAAI,gBAAgB,MAAM,GAAG,OAAO,OAAO,OAAO;CAClD,IAAI,iBAAiB,MAAM,GAAG,MAAM,IAAI,MAAM,8PAA8P;CAC5S,OAAO;AACR;AAgBA,SAAS,kBAAkB,OAAO,MAAM;CACvC,OAAO,CAAC,KAAK,YAAY,KAAK,SAAS,cAAc,KAAK,SAAS,cAAc,KAAK,YAAY,KAAK;AACxG;AACA,SAAS,4BAA4B,MAAM;CAC1C,OAAO,KAAK,eAAe,KAAK,KAAK,CAAC,KAAK,yBAAyB;AACrE;;;;;;;;;;AAUA,SAAS,kBAAkB,OAAO,UAAU,CAAC,GAAG;CAC/C,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,MAAM,SAAS,QAAQ,UAAU;CACjC,OAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,UAAU,OAAO,MAAM,IAAI,CAAC,CAAC,CAAC,QAAQ,UAAU,4BAA4B,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,MAAM;EACjO,GAAG,KAAK,eAAe,EAAE,aAAa,KAAK,YAAY;EACvD,YAAY,aAAa,KAAK,UAAU;EACxC,GAAG,KAAK,mBAAmB,EAAE,iBAAiB,KAAK,gBAAgB;CACpE,CAAC,CAAC,CAAC;AACJ"}
@@ -1,69 +0,0 @@
1
- //#region ../assistant-stream/dist/core/tool/tool-types.d.ts
2
- //#region src/core/tool/tool-types.d.ts
3
- type ToolModelContentPart = {
4
- /** A text content part returned to the model after a tool call. */readonly type: "text"; /** Text that should be included in the model-visible tool result. */
5
- readonly text: string;
6
- } | {
7
- /** A file content part returned to the model after a tool call. */readonly type: "file";
8
- /**
9
- * File payload encoded as a provider-compatible string, commonly base64
10
- * for binary data.
11
- */
12
- readonly data: string; /** MIME type for the file payload. */
13
- readonly mediaType: string; /** Optional display filename for the file payload. */
14
- readonly filename?: string;
15
- };
16
- /**
17
- * Converts a tool's runtime result into content that is sent back to the
18
- * model.
19
- *
20
- * Return this when the value shown in the UI or stored as the tool result
21
- * should differ from the model-visible response. When omitted, the successful
22
- * tool result is sent back to the model as-is. If a tool returns a
23
- * `ToolResponse` with `modelContent`, that explicit content is used instead
24
- * of calling this function.
25
- *
26
- * @example
27
- * ```ts
28
- * const toModelOutput: ToolModelOutputFunction<
29
- * { documentId: string },
30
- * { summary: string; pdfBase64: string }
31
- * > = ({ output }) => [
32
- * { type: "text", text: output.summary },
33
- * {
34
- * type: "file",
35
- * data: output.pdfBase64,
36
- * mediaType: "application/pdf",
37
- * },
38
- * ];
39
- * ```
40
- */
41
- /**
42
- * Per-provider metadata forwarded into the wire request body verbatim.
43
- * assistant-ui does not interpret these values; downstream adapters (AI SDK,
44
- * custom routes) pass them to the model provider as-is.
45
- *
46
- * The outer key is the provider name (`anthropic`, `openai`, ...); the inner
47
- * object is whatever shape that provider's SDK expects under
48
- * `tool.providerOptions[providerName]`. Use this to enable provider-specific
49
- * tool behaviors such as Anthropic's `defer_loading`
50
- * (`{ anthropic: { deferLoading: true } }`) without adding provider-aware
51
- * code in assistant-ui.
52
- */
53
- type ProviderOptions = Record<string, Record<string, unknown>>;
54
- /**
55
- * Controls how a tool call's UI is presented relative to the assistant's
56
- * chain-of-thought trace.
57
- *
58
- * - `"inline"` — the tool call is part of the reasoning trace and is folded
59
- * into the chain-of-thought grouping alongside other routine tool calls.
60
- * - `"standalone"` — the tool call is surfaced on its own, outside the
61
- * chain-of-thought grouping (e.g. a human-in-the-loop prompt, a generative
62
- * UI surface, or an important action UI worth showing prominently).
63
- *
64
- * This is a client-side presentation hint only; it does not affect how the
65
- * tool is exposed to or executed by the model.
66
- */
67
- //#endregion
68
- export { ProviderOptions, ToolModelContentPart };
69
- //# sourceMappingURL=tool-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-types.d.ts","names":["type","text","data","mediaType","filename","TArgs","TResult","toolCallId","input","output","options","ToolModelContentPart","Promise","Record","get","PathT","TypePath","fieldPath","TypeAtPath","streamValues","AsyncIterableStream","DeepPartial","streamText","U","forEach","Array","ToolResponse","args","ToolCallArgsReader","response","ToolCallResponseReader","result","abortSignal","AbortSignal","human","payload","ToolExecutionContext","context","ToolCallReader","reader","ToolExecuteFunction","streamCall","ToolStreamCallFunction","display","ToolDisplay","ToolBase","description","parameters","disabled","execute","toModelOutput","experimental_onSchemaValidationError","providerOptions","StandardSchemaV1","JSONSchema7","ToolModelOutputFunction","OnSchemaValidationErrorFunction","ProviderOptions","providerId","supportsDeferredResults","url","headers","redirect","command","env","cwd","server","McpServerConfig","FrontendTool","BackendTool","HumanTool","ProviderTool","McpTool","ToolWithoutType","BackendToolDeclaration","Omit"],"sources":["../../../../../../assistant-stream/dist/core/tool/tool-types.d.ts"],"mappings":";;KAOK,oBAAA;EAEMC,4EADmED,IAAAA,UACnEC;EAAAA,SAAAA,IAAAA;AAAAA;EAQAE,4EANmEH,IAAAA;EAOnEI;;AAAQ;AAkGiE;EAlGzEA,SAFAF,IAAAA,UAiHS;EAAA,SAhHTC,SAAAA,UAgHkB;EAAA,SA/GlBC,QAAAA;AAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+GN,eAAA,GAAkB,MAAM,SAAS,MAAA"}
@@ -1 +0,0 @@
1
- export { };
@@ -1,2 +0,0 @@
1
- import { ProviderOptions, ToolModelContentPart } from "./core/tool/tool-types.js";
2
- import { ToolJSONSchema } from "./core/tool/schema-utils.js";
@@ -1,140 +0,0 @@
1
- //#region ../assistant-stream/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts
2
- //#region ../../node_modules/.pnpm/@types+json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts
3
- // ==================================================================================================
4
- // JSON Schema Draft 07
5
- // ==================================================================================================
6
- // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
7
- // --------------------------------------------------------------------------------------------------
8
- /**
9
- * Primitive type
10
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
11
- */
12
- type JSONSchema7TypeName = "string" //
13
- | "number" | "integer" | "boolean" | "object" | "array" | "null";
14
- /**
15
- * Primitive type
16
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
17
- */
18
- type JSONSchema7Type = string //
19
- | number | boolean | JSONSchema7Object | JSONSchema7Array | null; // Workaround for infinite type recursion
20
- interface JSONSchema7Object {
21
- [key: string]: JSONSchema7Type;
22
- } // Workaround for infinite type recursion
23
- // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
24
- interface JSONSchema7Array extends Array<JSONSchema7Type> {}
25
- /**
26
- * Meta schema
27
- *
28
- * Recommended values:
29
- * - 'http://json-schema.org/schema#'
30
- * - 'http://json-schema.org/hyper-schema#'
31
- * - 'http://json-schema.org/draft-07/schema#'
32
- * - 'http://json-schema.org/draft-07/hyper-schema#'
33
- *
34
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
35
- */
36
- type JSONSchema7Version = string;
37
- /**
38
- * JSON Schema v7
39
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
40
- */
41
- type JSONSchema7Definition = JSONSchema7 | boolean;
42
- interface JSONSchema7 {
43
- $id?: string | undefined;
44
- $ref?: string | undefined;
45
- $schema?: JSONSchema7Version | undefined;
46
- $comment?: string | undefined;
47
- /**
48
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
49
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
50
- */
51
- $defs?: {
52
- [key: string]: JSONSchema7Definition;
53
- } | undefined;
54
- /**
55
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
56
- */
57
- type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
58
- enum?: JSONSchema7Type[] | undefined;
59
- const?: JSONSchema7Type | undefined;
60
- /**
61
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
62
- */
63
- multipleOf?: number | undefined;
64
- maximum?: number | undefined;
65
- exclusiveMaximum?: number | undefined;
66
- minimum?: number | undefined;
67
- exclusiveMinimum?: number | undefined;
68
- /**
69
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
70
- */
71
- maxLength?: number | undefined;
72
- minLength?: number | undefined;
73
- pattern?: string | undefined;
74
- /**
75
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
76
- */
77
- items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
78
- additionalItems?: JSONSchema7Definition | undefined;
79
- maxItems?: number | undefined;
80
- minItems?: number | undefined;
81
- uniqueItems?: boolean | undefined;
82
- contains?: JSONSchema7Definition | undefined;
83
- /**
84
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
85
- */
86
- maxProperties?: number | undefined;
87
- minProperties?: number | undefined;
88
- required?: string[] | undefined;
89
- properties?: {
90
- [key: string]: JSONSchema7Definition;
91
- } | undefined;
92
- patternProperties?: {
93
- [key: string]: JSONSchema7Definition;
94
- } | undefined;
95
- additionalProperties?: JSONSchema7Definition | undefined;
96
- dependencies?: {
97
- [key: string]: JSONSchema7Definition | string[];
98
- } | undefined;
99
- propertyNames?: JSONSchema7Definition | undefined;
100
- /**
101
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
102
- */
103
- if?: JSONSchema7Definition | undefined;
104
- then?: JSONSchema7Definition | undefined;
105
- else?: JSONSchema7Definition | undefined;
106
- /**
107
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
108
- */
109
- allOf?: JSONSchema7Definition[] | undefined;
110
- anyOf?: JSONSchema7Definition[] | undefined;
111
- oneOf?: JSONSchema7Definition[] | undefined;
112
- not?: JSONSchema7Definition | undefined;
113
- /**
114
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
115
- */
116
- format?: string | undefined;
117
- /**
118
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
119
- */
120
- contentMediaType?: string | undefined;
121
- contentEncoding?: string | undefined;
122
- /**
123
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
124
- */
125
- definitions?: {
126
- [key: string]: JSONSchema7Definition;
127
- } | undefined;
128
- /**
129
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
130
- */
131
- title?: string | undefined;
132
- description?: string | undefined;
133
- default?: JSONSchema7Type | undefined;
134
- readOnly?: boolean | undefined;
135
- writeOnly?: boolean | undefined;
136
- examples?: JSONSchema7Type | undefined;
137
- } //#endregion
138
- //#endregion
139
- export { JSONSchema7 };
140
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":["JSONSchema7Object","JSONSchema7Array","key","JSONSchema7Type","Array","JSONSchema7","$id","$ref","$schema","JSONSchema7Version","$comment","$defs","JSONSchema7Definition","type","JSONSchema7TypeName","enum","const","multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","items","additionalItems","maxItems","minItems","uniqueItems","contains","maxProperties","minProperties","required","properties","patternProperties","additionalProperties","dependencies","propertyNames","if","then","else","allOf","anyOf","oneOf","not","format","contentMediaType","contentEncoding","definitions","title","description","default","readOnly","writeOnly","examples"],"sources":["../../../../../../../../../../assistant-stream/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;AAUwB;;;;AAAA,KAAnB,mBAAA;AAAA;;;;AAU2B;KAJ3B,eAAA;AAAA,qBACgB,iBAAA,GAAoB,gBAAgB;AAAA,UAE/C,iBAAA;EAAA,CACPE,GAAAA,WAAc,eAAe;AAAA;AAAA;AAAA,UAItB,gBAAA,SAAyB,KAAK,CAAC,eAAA;AAYlB;AAAA;;;;AAKiB;AAAA;;;;;AALjB,KAAlB,kBAAA;;;;;KAKA,qBAAA,GAAwB,WAAW;AAAA,UAC9B,WAAA;EACRI,GAAAA;EACAC,IAAAA;EACAC,OAAAA,GAAU,kBAAA;EACVE,QAAAA;EAmDiB;;;;EA9CjBC,KAAAA;IAAAA,CACGT,GAAAA,WAAc,qBAAA;EAAA;EA2DT;;;EAtDRW,IAAAA,GAAO,mBAAA,GAAsB,mBAAA;EAC7BE,IAAAA,GAAO,eAAA;EACPC,KAAAA,GAAQ,eAAA;EA6EkB;;;EAzE1BC,UAAAA;EACAC,OAAAA;EACAC,gBAAAA;EACAC,OAAAA;EACAC,gBAAAA;EAfiBT;;;EAmBjBU,SAAAA;EACAC,SAAAA;EACAC,OAAAA;EAdAR;;;EAkBAS,KAAAA,GAAQ,qBAAA,GAAwB,qBAAA;EAChCC,eAAAA,GAAkB,qBAAA;EAClBC,QAAAA;EACAC,QAAAA;EACAC,WAAAA;EACAC,QAAAA,GAAW,qBAAA;EATXN;;;EAaAO,aAAAA;EACAC,aAAAA;EACAC,QAAAA;EACAC,UAAAA;IAAAA,CACGhC,GAAAA,WAAc,qBAAA;EAAA;EAEjBiC,iBAAAA;IAAAA,CACGjC,GAAAA,WAAc,qBAAA;EAAA;EAEjBkC,oBAAAA,GAAuB,qBAAA;EACvBC,YAAAA;IAAAA,CACGnC,GAAAA,WAAc,qBAAA;EAAA;EAEjBoC,aAAAA,GAAgB,qBAAA;EAPhBH;;;EAWAI,EAAAA,GAAK,qBAAA;EACLC,IAAAA,GAAO,qBAAA;EACPC,IAAAA,GAAO,qBAAA;EARJvC;;;EAYHwC,KAAAA,GAAQ,qBAAA;EACRC,KAAAA,GAAQ,qBAAA;EACRC,KAAAA,GAAQ,qBAAA;EACRC,GAAAA,GAAM,qBAAA;EARCjC;;;EAYPkC,MAAAA;EAPQlC;;;EAWRmC,gBAAAA;EACAC,eAAAA;EATAH;;;EAaAI,WAAAA;IAAAA,CACG/C,GAAAA,WAAc,qBAAA;EAAA;EAAdA;;;EAKHgD,KAAAA;EACAC,WAAAA;EACAC,OAAAA,GAAU,eAAA;EACVC,QAAAA;EACAC,SAAAA;EACAC,QAAAA,GAAW,eAAA;AAAA"}
@@ -1,6 +0,0 @@
1
- //#region ../assistant-stream/dist/resumable/createResumableAssistantStreamResponse.d.ts
2
- //#region src/resumable/createResumableAssistantStreamResponse.d.ts
3
- declare const RESUMABLE_STREAM_ID_HEADER = "x-resumable-stream-id";
4
- //#endregion
5
- export { RESUMABLE_STREAM_ID_HEADER };
6
- //# sourceMappingURL=createResumableAssistantStreamResponse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createResumableAssistantStreamResponse.d.ts","names":["context","ResumableStreamContext","streamId","callback","AssistantStreamController","controller","PromiseLike","encoder","AssistantStreamEncoder","headers","HeadersInit","CreateResumableAssistantStreamResponseOptions","options","Promise","Response","missingResponse","CreateResumeAssistantStreamResponseOptions"],"sources":["../../../../../assistant-stream/dist/resumable/createResumableAssistantStreamResponse.d.ts"],"mappings":";;cAKc,0BAAA"}
@@ -1,6 +0,0 @@
1
- //#region ../assistant-stream/dist/resumable/createResumableAssistantStreamResponse.js
2
- const RESUMABLE_STREAM_ID_HEADER = "x-resumable-stream-id";
3
- //#endregion
4
- export { RESUMABLE_STREAM_ID_HEADER };
5
-
6
- //# sourceMappingURL=createResumableAssistantStreamResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createResumableAssistantStreamResponse.js","names":[],"sources":["../../../../../assistant-stream/dist/resumable/createResumableAssistantStreamResponse.js"],"sourcesContent":["import { DataStreamEncoder } from \"../core/serialization/data-stream/DataStream.js\";\nimport { createAssistantStream } from \"../core/modules/assistant-stream.js\";\n//#region src/resumable/createResumableAssistantStreamResponse.ts\nconst RESUMABLE_STREAM_ID_HEADER = \"x-resumable-stream-id\";\nasync function createResumableAssistantStreamResponse(options) {\n\tconst encoder = (options.encoder ?? (() => new DataStreamEncoder()))();\n\tconst stream = await options.context.run(options.streamId, () => {\n\t\treturn createAssistantStream(options.callback).pipeThrough(encoder);\n\t});\n\treturn new Response(stream, { headers: mergeHeaders(encoder.headers, options.headers, options.streamId) });\n}\nasync function createResumeAssistantStreamResponse(options) {\n\tconst stream = await options.context.resume(options.streamId);\n\tif (!stream) return options.missingResponse?.() ?? defaultMissingResponse();\n\tconst encoder = (options.encoder ?? (() => new DataStreamEncoder()))();\n\treturn new Response(stream, { headers: mergeHeaders(encoder.headers, options.headers, options.streamId) });\n}\nfunction defaultMissingResponse() {\n\treturn new Response(JSON.stringify({ error: \"stream not found\" }), {\n\t\tstatus: 404,\n\t\theaders: { \"Content-Type\": \"application/json\" }\n\t});\n}\nfunction mergeHeaders(encoderHeaders, extra, streamId) {\n\tconst merged = new Headers(encoderHeaders ?? {});\n\tif (extra) for (const [key, value] of new Headers(extra)) merged.set(key, value);\n\tmerged.set(RESUMABLE_STREAM_ID_HEADER, streamId);\n\treturn merged;\n}\n//#endregion\nexport { RESUMABLE_STREAM_ID_HEADER, createResumableAssistantStreamResponse, createResumeAssistantStreamResponse };\n\n//# sourceMappingURL=createResumableAssistantStreamResponse.js.map"],"mappings":";AAGA,MAAM,6BAA6B"}
@@ -1 +0,0 @@
1
- import { RESUMABLE_STREAM_ID_HEADER } from "./createResumableAssistantStreamResponse.js";