@assistant-ui/react 0.7.1 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/dist/api/ContentPartRuntime.d.ts +5 -1
  2. package/dist/api/ContentPartRuntime.d.ts.map +1 -1
  3. package/dist/api/ContentPartRuntime.js.map +1 -1
  4. package/dist/api/ContentPartRuntime.mjs.map +1 -1
  5. package/dist/api/RuntimePathTypes.d.ts +0 -3
  6. package/dist/api/RuntimePathTypes.d.ts.map +1 -1
  7. package/dist/api/RuntimePathTypes.js.map +1 -1
  8. package/dist/api/ThreadListRuntime.d.ts +0 -5
  9. package/dist/api/ThreadListRuntime.d.ts.map +1 -1
  10. package/dist/api/ThreadListRuntime.js +4 -10
  11. package/dist/api/ThreadListRuntime.js.map +1 -1
  12. package/dist/api/ThreadListRuntime.mjs +4 -10
  13. package/dist/api/ThreadListRuntime.mjs.map +1 -1
  14. package/dist/runtimes/edge/converters/fromCoreMessage.d.ts.map +1 -1
  15. package/dist/runtimes/edge/converters/fromCoreMessage.js +6 -3
  16. package/dist/runtimes/edge/converters/fromCoreMessage.js.map +1 -1
  17. package/dist/runtimes/edge/converters/fromCoreMessage.mjs +6 -3
  18. package/dist/runtimes/edge/converters/fromCoreMessage.mjs.map +1 -1
  19. package/dist/runtimes/edge/converters/fromLanguageModelMessages.d.ts.map +1 -1
  20. package/dist/runtimes/edge/converters/fromLanguageModelMessages.js +3 -2
  21. package/dist/runtimes/edge/converters/fromLanguageModelMessages.js.map +1 -1
  22. package/dist/runtimes/edge/converters/fromLanguageModelMessages.mjs +3 -2
  23. package/dist/runtimes/edge/converters/fromLanguageModelMessages.mjs.map +1 -1
  24. package/dist/runtimes/external-store/ThreadMessageLike.d.ts +5 -1
  25. package/dist/runtimes/external-store/ThreadMessageLike.d.ts.map +1 -1
  26. package/dist/runtimes/external-store/ThreadMessageLike.js +18 -6
  27. package/dist/runtimes/external-store/ThreadMessageLike.js.map +1 -1
  28. package/dist/runtimes/external-store/ThreadMessageLike.mjs +18 -6
  29. package/dist/runtimes/external-store/ThreadMessageLike.mjs.map +1 -1
  30. package/dist/runtimes/local/ChatModelAdapter.d.ts +4 -4
  31. package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
  32. package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
  33. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  34. package/dist/runtimes/local/LocalThreadRuntimeCore.js +1 -0
  35. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  36. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +1 -0
  37. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
  38. package/dist/types/AssistantTypes.d.ts +60 -51
  39. package/dist/types/AssistantTypes.d.ts.map +1 -1
  40. package/dist/types/AssistantTypes.js.map +1 -1
  41. package/dist/ui/{attachment.d.ts → attachment-ui.d.ts} +3 -3
  42. package/dist/ui/attachment-ui.d.ts.map +1 -0
  43. package/dist/ui/{attachment.js → attachment-ui.js} +9 -9
  44. package/dist/ui/attachment-ui.js.map +1 -0
  45. package/dist/ui/{attachment.mjs → attachment-ui.mjs} +6 -6
  46. package/dist/ui/attachment-ui.mjs.map +1 -0
  47. package/dist/ui/composer.js +2 -2
  48. package/dist/ui/composer.js.map +1 -1
  49. package/dist/ui/composer.mjs +1 -1
  50. package/dist/ui/composer.mjs.map +1 -1
  51. package/dist/ui/index.d.ts +1 -1
  52. package/dist/ui/index.d.ts.map +1 -1
  53. package/dist/ui/index.js +2 -2
  54. package/dist/ui/index.js.map +1 -1
  55. package/dist/ui/index.mjs +1 -1
  56. package/dist/ui/index.mjs.map +1 -1
  57. package/dist/ui/user-message.js +2 -2
  58. package/dist/ui/user-message.js.map +1 -1
  59. package/dist/ui/user-message.mjs +1 -1
  60. package/dist/ui/user-message.mjs.map +1 -1
  61. package/dist/utils/smooth/SmoothContext.d.ts +42 -42
  62. package/package.json +3 -3
  63. package/src/api/ContentPartRuntime.ts +6 -2
  64. package/src/api/RuntimePathTypes.ts +0 -4
  65. package/src/api/ThreadListRuntime.ts +4 -16
  66. package/src/runtimes/edge/converters/fromCoreMessage.ts +4 -0
  67. package/src/runtimes/edge/converters/fromLanguageModelMessages.ts +5 -2
  68. package/src/runtimes/external-store/ThreadMessageLike.tsx +21 -4
  69. package/src/runtimes/local/ChatModelAdapter.tsx +4 -4
  70. package/src/runtimes/local/LocalThreadRuntimeCore.tsx +1 -0
  71. package/src/types/AssistantTypes.ts +65 -52
  72. package/src/ui/{attachment.tsx → attachment-ui.tsx} +3 -3
  73. package/src/ui/composer.tsx +1 -1
  74. package/src/ui/index.ts +1 -1
  75. package/src/ui/user-message.tsx +1 -1
  76. package/dist/ui/attachment.d.ts.map +0 -1
  77. package/dist/ui/attachment.js.map +0 -1
  78. package/dist/ui/attachment.mjs.map +0 -1
@@ -1,15 +1,17 @@
1
1
  // src/runtimes/external-store/ThreadMessageLike.tsx
2
2
  var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
3
- const { role, id, createdAt, attachments, status } = like;
3
+ const { role, id, createdAt, attachments, status, metadata } = like;
4
4
  const common = {
5
5
  id: id ?? fallbackId,
6
6
  createdAt: createdAt ?? /* @__PURE__ */ new Date()
7
7
  };
8
8
  const content = typeof like.content === "string" ? [{ type: "text", text: like.content }] : like.content;
9
9
  if (role !== "user" && attachments)
10
- throw new Error("Attachments are only supported for user messages");
10
+ throw new Error("attachments are only supported for user messages");
11
11
  if (role !== "assistant" && status)
12
- throw new Error("Status is only supported for assistant messages");
12
+ throw new Error("status is only supported for assistant messages");
13
+ if (role !== "assistant" && metadata?.steps)
14
+ throw new Error("metadata.steps is only supported for assistant messages");
13
15
  switch (role) {
14
16
  case "assistant":
15
17
  return {
@@ -36,7 +38,11 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
36
38
  }
37
39
  }
38
40
  }).filter((c) => !!c),
39
- status: status ?? fallbackStatus
41
+ status: status ?? fallbackStatus,
42
+ metadata: {
43
+ custom: metadata?.custom ?? {},
44
+ steps: metadata?.steps ?? []
45
+ }
40
46
  };
41
47
  case "user":
42
48
  return {
@@ -56,7 +62,10 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
56
62
  }
57
63
  }
58
64
  }),
59
- attachments: attachments ?? []
65
+ attachments: attachments ?? [],
66
+ metadata: {
67
+ custom: metadata?.custom ?? {}
68
+ }
60
69
  };
61
70
  case "system":
62
71
  if (content.length !== 1 || content[0].type !== "text")
@@ -66,7 +75,10 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
66
75
  return {
67
76
  ...common,
68
77
  role,
69
- content
78
+ content,
79
+ metadata: {
80
+ custom: metadata?.custom ?? {}
81
+ }
70
82
  };
71
83
  default: {
72
84
  const unsupportedRole = role;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/external-store/ThreadMessageLike.tsx"],"sourcesContent":["import {\n MessageStatus,\n TextContentPart,\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadAssistantMessage,\n ThreadUserContentPart,\n ThreadUserMessage,\n ThreadSystemMessage,\n CompleteAttachment,\n} from \"../../types\";\nimport {\n CoreToolCallContentPart,\n Unstable_AudioContentPart,\n} from \"../../types/AssistantTypes\";\n\nexport type ThreadMessageLike = {\n role: \"assistant\" | \"user\" | \"system\";\n content:\n | string\n | (\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart\n | ToolCallContentPart<any, any>\n | CoreToolCallContentPart<any, any>\n | UIContentPart\n )[];\n id?: string | undefined;\n createdAt?: Date | undefined;\n status?: MessageStatus | undefined;\n attachments?: CompleteAttachment[] | undefined;\n // TODO metadata\n};\n\nexport const fromThreadMessageLike = (\n like: ThreadMessageLike,\n fallbackId: string,\n fallbackStatus: MessageStatus,\n): ThreadMessage => {\n const { role, id, createdAt, attachments, status } = like;\n const common = {\n id: id ?? fallbackId,\n createdAt: createdAt ?? new Date(),\n };\n\n const content =\n typeof like.content === \"string\"\n ? [{ type: \"text\" as const, text: like.content }]\n : like.content;\n\n if (role !== \"user\" && attachments)\n throw new Error(\"Attachments are only supported for user messages\");\n\n if (role !== \"assistant\" && status)\n throw new Error(\"Status is only supported for assistant messages\");\n\n switch (role) {\n case \"assistant\":\n return {\n ...common,\n role,\n content: content\n .map((part): ThreadAssistantContentPart | null => {\n const type = part.type;\n switch (type) {\n case \"text\":\n if (part.text.trim().length === 0) return null;\n return part;\n\n case \"ui\":\n return part;\n\n case \"tool-call\": {\n if (\"argsText\" in part) return part;\n return {\n ...part,\n argsText: JSON.stringify(part.args),\n };\n }\n\n default: {\n const unhandledType: \"image\" | \"audio\" = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n }\n })\n .filter((c) => !!c),\n status: status ?? fallbackStatus,\n } satisfies ThreadAssistantMessage;\n\n case \"user\":\n return {\n ...common,\n role,\n content: content.map((part): ThreadUserContentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"ui\":\n case \"image\":\n case \"audio\":\n return part;\n\n default: {\n const unhandledType: \"tool-call\" = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n }\n }),\n attachments: attachments ?? [],\n } satisfies ThreadUserMessage;\n\n case \"system\":\n if (content.length !== 1 || content[0]!.type !== \"text\")\n throw new Error(\n \"System messages must have exactly one text content part.\",\n );\n\n return {\n ...common,\n role,\n content: content as [TextContentPart],\n } satisfies ThreadSystemMessage;\n\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n};\n"],"mappings":";AAsCO,IAAM,wBAAwB,CACnC,MACA,YACA,mBACkB;AAClB,QAAM,EAAE,MAAM,IAAI,WAAW,aAAa,OAAO,IAAI;AACrD,QAAM,SAAS;AAAA,IACb,IAAI,MAAM;AAAA,IACV,WAAW,aAAa,oBAAI,KAAK;AAAA,EACnC;AAEA,QAAM,UACJ,OAAO,KAAK,YAAY,WACpB,CAAC,EAAE,MAAM,QAAiB,MA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,CAAC,EAAG,SAAS;AAC/C,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAEF,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,QACA;AAAA,MACF;AAAA,IAEF,SAAS;AACP,YAAM,kBAAyB;AAC/B,YAAM,IAAI,MAAM,yBAAyB,eAAe,EAAE;AAAA,IAC5D;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/external-store/ThreadMessageLike.tsx"],"sourcesContent":["import {\n MessageStatus,\n TextContentPart,\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadAssistantMessage,\n ThreadUserContentPart,\n ThreadUserMessage,\n ThreadSystemMessage,\n CompleteAttachment,\n} from \"../../types\";\nimport {\n CoreToolCallContentPart,\n ThreadStep,\n Unstable_AudioContentPart,\n} from \"../../types/AssistantTypes\";\n\nexport type ThreadMessageLike = {\n role: \"assistant\" | \"user\" | \"system\";\n content:\n | string\n | (\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart\n | ToolCallContentPart<any, any>\n | CoreToolCallContentPart<any, any>\n | UIContentPart\n )[];\n id?: string | undefined;\n createdAt?: Date | undefined;\n status?: MessageStatus | undefined;\n attachments?: CompleteAttachment[] | undefined;\n metadata?: {\n steps?: ThreadStep[] | undefined;\n custom?: Record<string, unknown> | undefined;\n };\n};\n\nexport const fromThreadMessageLike = (\n like: ThreadMessageLike,\n fallbackId: string,\n fallbackStatus: MessageStatus,\n): ThreadMessage => {\n const { role, id, createdAt, attachments, status, metadata } = like;\n const common = {\n id: id ?? fallbackId,\n createdAt: createdAt ?? new Date(),\n };\n\n const content =\n typeof like.content === \"string\"\n ? [{ type: \"text\" as const, text: like.content }]\n : like.content;\n\n if (role !== \"user\" && attachments)\n throw new Error(\"attachments are only supported for user messages\");\n\n if (role !== \"assistant\" && status)\n throw new Error(\"status is only supported for assistant messages\");\n\n if (role !== \"assistant\" && metadata?.steps)\n throw new Error(\"metadata.steps is only supported for assistant messages\");\n\n switch (role) {\n case \"assistant\":\n return {\n ...common,\n role,\n content: content\n .map((part): ThreadAssistantContentPart | null => {\n const type = part.type;\n switch (type) {\n case \"text\":\n if (part.text.trim().length === 0) return null;\n return part;\n\n case \"ui\":\n return part;\n\n case \"tool-call\": {\n if (\"argsText\" in part) return part;\n return {\n ...part,\n argsText: JSON.stringify(part.args),\n };\n }\n\n default: {\n const unhandledType: \"image\" | \"audio\" = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n }\n })\n .filter((c) => !!c),\n status: status ?? fallbackStatus,\n metadata: {\n custom: metadata?.custom ?? {},\n steps: metadata?.steps ?? [],\n },\n } satisfies ThreadAssistantMessage;\n\n case \"user\":\n return {\n ...common,\n role,\n content: content.map((part): ThreadUserContentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"ui\":\n case \"image\":\n case \"audio\":\n return part;\n\n default: {\n const unhandledType: \"tool-call\" = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n }\n }),\n attachments: attachments ?? [],\n metadata: {\n custom: metadata?.custom ?? {},\n },\n } satisfies ThreadUserMessage;\n\n case \"system\":\n if (content.length !== 1 || content[0]!.type !== \"text\")\n throw new Error(\n \"System messages must have exactly one text content part.\",\n );\n\n return {\n ...common,\n role,\n content: content as [TextContentPart],\n metadata: {\n custom: metadata?.custom ?? {},\n },\n } satisfies ThreadSystemMessage;\n\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n};\n"],"mappings":";AA0CO,IAAM,wBAAwB,CACnC,MACA,YACA,mBACkB;AAClB,QAAM,EAAE,MAAM,IAAI,WAAW,aAAa,QAAQ,SAAS,IAAI;AAC/D,QAAM,SAAS;AAAA,IACb,IAAI,MAAM;AAAA,IACV,WAAW,aAAa,oBAAI,KAAK;AAAA,EACnC;AAEA,QAAM,UACJ,OAAO,KAAK,YAAY,WACpB,CAAC,EAAE,MAAM,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oBAAM,IAAI,MAAM,8BAA8B,aAAa,EAAE;AAAA,YAC/D;AAAA,UACF;AAAA,QACF,CAAC;AAAA,QACD,aAAa,eAAe,CAAC;AAAA,QAC7B,UAAU;AAAA,UACR,QAAQ,UAAU,UAAU,CAAC;AAAA,QAC/B;AAAA,MACF;AAAA,IAEF,KAAK;AACH,UAAI,QAAQ,WAAW,KAAK,QAAQ,CAAC,EAAG,SAAS;AAC/C,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAEF,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,QACA;AAAA,QACA,UAAU;AAAA,UACR,QAAQ,UAAU,UAAU,CAAC;AAAA,QAC/B;AAAA,MACF;AAAA,IAEF,SAAS;AACP,YAAM,kBAAyB;AAC/B,YAAM,IAAI,MAAM,yBAAyB,eAAe,EAAE;AAAA,IAC5D;AAAA,EACF;AACF;","names":[]}
@@ -5,11 +5,11 @@ export type ChatModelRunUpdate = {
5
5
  metadata?: Record<string, unknown>;
6
6
  };
7
7
  export type ChatModelRunResult = {
8
- content?: ThreadAssistantContentPart[];
9
- status?: MessageStatus;
8
+ content?: ThreadAssistantContentPart[] | undefined;
9
+ status?: MessageStatus | undefined;
10
10
  metadata?: {
11
- steps?: ThreadStep[];
12
- custom?: Record<string, unknown>;
11
+ steps?: ThreadStep[] | undefined;
12
+ custom?: Record<string, unknown> | undefined;
13
13
  };
14
14
  };
15
15
  export type ChatModelRunOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"ChatModelAdapter.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/ChatModelAdapter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,0BAA0B,EAC1B,aAAa,EACb,UAAU,EACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,Q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AC;IACnC,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;QACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;KAC9C,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,WAAW,CAAC;IAEpB,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,CACH,OAAO,EAAE,mBAAmB,KACzB,OAAO,CAAC,kBAAkB,CAAC,GAAG,cAAc,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;CAC7E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/local/ChatModelAdapter.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n MessageStatus,\n ThreadAssistantContentPart,\n ThreadMessage,\n ThreadStep,\n} from \"../../types/AssistantTypes\";\nimport type { ModelConfig } from \"../../types/ModelConfigTypes\";\n\nexport type ChatModelRunUpdate = {\n content: ThreadAssistantContentPart[];\n metadata?: Record<string, unknown>;\n};\n\nexport type ChatModelRunResult = {\n content?: ThreadAssistantContentPart[];\n status?: MessageStatus;\n metadata?: {\n steps?: ThreadStep[];\n custom?: Record<string, unknown>;\n };\n};\n\nexport type ChatModelRunOptions = {\n messages: ThreadMessage[];\n abortSignal: AbortSignal;\n config: ModelConfig;\n\n unstable_assistantMessageId?: string;\n};\n\nexport type ChatModelAdapter = {\n run: (\n options: ChatModelRunOptions,\n ) => Promise<ChatModelRunResult> | AsyncGenerator<ChatModelRunResult, void>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/local/ChatModelAdapter.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n MessageStatus,\n ThreadAssistantContentPart,\n ThreadMessage,\n ThreadStep,\n} from \"../../types/AssistantTypes\";\nimport type { ModelConfig } from \"../../types/ModelConfigTypes\";\n\nexport type ChatModelRunUpdate = {\n content: ThreadAssistantContentPart[];\n metadata?: Record<string, unknown>;\n};\n\nexport type ChatModelRunResult = {\n content?: ThreadAssistantContentPart[] | undefined;\n status?: MessageStatus | undefined;\n metadata?: {\n steps?: ThreadStep[] | undefined;\n custom?: Record<string, unknown> | undefined;\n };\n};\n\nexport type ChatModelRunOptions = {\n messages: ThreadMessage[];\n abortSignal: AbortSignal;\n config: ModelConfig;\n\n unstable_assistantMessageId?: string;\n};\n\nexport type ChatModelAdapter = {\n run: (\n options: ChatModelRunOptions,\n ) => Promise<ChatModelRunResult> | AsyncGenerator<ChatModelRunResult, void>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"LocalThreadRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EAEd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,qBAAa,sBACX,SAAQ,qBACR,YAAW,iBAAiB;IAE5B,SAAgB,YAAY;;;;;;;;;MAS1B;IAEF,OAAO,CAAC,eAAe,CAAgC;IAEvD,SAAgB,UAAU,SAAS;IACnC,SAAgB,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAM;IAE9D,IAAW,QAAQ;;;;;MAElB;gBAGC,cAAc,EAAE,mBAAmB,EACnC,QAAQ,EAAE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AAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAuB/C,gBAAgB;IA0GvB,SAAS;IAKT,aAAa,CAAC,EACnB,SAAS,EACT,UAAU,EACV,MAAM,GACP,EAAE,oBAAoB;CAkCxB"}
@@ -102,6 +102,7 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
102
102
  role: "assistant",
103
103
  status: { type: "running" },
104
104
  content: [],
105
+ metadata: { steps: [], custom: {} },
105
106
  createdAt: /* @__PURE__ */ new Date()
106
107
  };
107
108
  this._notifyEventSubscribers("run-start");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { LocalThreadMetadataRuntimeCore } from \"./LocalThreadMetadataRuntimeCore\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider, new LocalThreadMetadataRuntimeCore(threadId));\n this.setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n public get extras() {\n return undefined;\n }\n\n public setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _transitionAwayFromNewState() {\n if (this.metadata.state === \"new\") {\n this.metadata.create();\n }\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this._transitionAwayFromNewState();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun(newMessage.id);\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n this._transitionAwayFromNewState();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAM3B,kBAAgC;AAEhC,4BAA+B;AAO/B,mCAAsC;AACtC,4CAA+C;AAExC,IAAM,yBAAN,cACG,mDAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,UACA,SACA;AACA,UAAM,gBAAgB,IAAI,qEAA+B,QAAQ,CAAC;AAClE,SAAK,WAAW,OAAO;AAAA,EACzB;AAAA,EAEQ;AAAA,EAER,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,SAAkC;AAClD,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,WAAW;AAEhB,QAAI,aAAa;AAEjB,UAAM,WAAW,QAAQ,UAAU,WAAW;AAC9C,QAAI,KAAK,aAAa,WAAW,UAA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eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,aAAS,sCAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,OAAO;AAAA,IACzC;AAAA,EACF;AACF;","names":["steps"]}
1
+ {"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { LocalThreadMetadataRuntimeCore } from \"./LocalThreadMetadataRuntimeCore\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider, new LocalThreadMetadataRuntimeCore(threadId));\n this.setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n public get extras() {\n return undefined;\n }\n\n public setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _transitionAwayFromNewState() {\n if (this.metadata.state === \"new\") {\n this.metadata.create();\n }\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this._transitionAwayFromNewState();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun(newMessage.id);\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n this._transitionAwayFromNewState();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAM3B,kBAAgC;AAEhC,4BAA+B;AAO/B,mCAAsC;AACtC,4CAA+C;AAExC,IAAM,yBAAN,cACG,mDAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,UACA,SACA;AACA,UAAM,gBAAgB,IAAI,qEAA+B,QAAQ,CAAC;AAClE,SAAK,WAAW,OAAO;AAAA,EACzB;AAAA,EAEQ;AAAA,EAER,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,SAAkC;AAClD,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,WAAW;AAEhB,QAAI,aAAa;AAEjB,UAAM,WAAW,QAAQ,UAAU,WAAW;AAC9C,QAAI,KAAK,aAAa,WAAW,UAAU;AACzC,WAAK,aAAa,SAAS;AAC3B,mBAAa;AAAA,IACf;AAEA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AAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,aAAS,sCAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,OAAO;AAAA,IACzC;AAAA,EACF;AACF;","names":["steps"]}
@@ -78,6 +78,7 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
78
78
  role: "assistant",
79
79
  status: { type: "running" },
80
80
  content: [],
81
+ metadata: { steps: [], custom: {} },
81
82
  createdAt: /* @__PURE__ */ new Date()
82
83
  };
83
84
  this._notifyEventSubscribers("run-start");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { LocalThreadMetadataRuntimeCore } from \"./LocalThreadMetadataRuntimeCore\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider, new LocalThreadMetadataRuntimeCore(threadId));\n this.setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n public get extras() {\n return undefined;\n }\n\n public setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _transitionAwayFromNewState() {\n if (this.metadata.state === \"new\") {\n this.metadata.create();\n }\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this._transitionAwayFromNewState();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun(newMessage.id);\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n this._transitionAwayFromNewState();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAM3B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAO/B,SAAS,6BAA6B;AACtC,SAAS,sCAAsC;AAExC,IAAM,yBAAN,cACG,sBAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,UACA,SACA;AACA,UAAM,gBAAgB,IAAI,+BAA+B,QAAQ,CAAC;AAClE,SAAK,WAAW,OAAO;AAAA,EACzB;AAAA,EAEQ;AAAA,EAER,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,SAAkC;AAClD,QAAI,KAAK,aAAa,QAA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AQ;AACZ,UAAM,aAAa,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,SAAS,eAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,OAAO;AAAA,IACzC;AAAA,EACF;AACF;","names":["steps"]}
1
+ {"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { LocalThreadMetadataRuntimeCore } from \"./LocalThreadMetadataRuntimeCore\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider, new LocalThreadMetadataRuntimeCore(threadId));\n this.setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n public get extras() {\n return undefined;\n }\n\n public setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _transitionAwayFromNewState() {\n if (this.metadata.state === \"new\") {\n this.metadata.create();\n }\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this._transitionAwayFromNewState();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun(newMessage.id);\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n this._transitionAwayFromNewState();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAM3B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAO/B,SAAS,6BAA6B;AACtC,SAAS,sCAAsC;AAExC,IAAM,yBAAN,cACG,sBAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,UACA,SACA;AACA,UAAM,gBAAgB,IAAI,+BAA+B,QAAQ,CAAC;AAClE,SAAK,WAAW,OAAO;AAAA,EACzB;AAAA,EAEQ;AAAA,EAER,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,SAAkC;AAClD,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,WAAW;AAEhB,QAAI,aAAa;AAEjB,UAAM,WAAW,QAAQ,UAAU,WAAW;AAC9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QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,SAAS,eAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,OAAO;AAAA,IACzC;AAAA,EACF;AACF;","names":["steps"]}
@@ -2,89 +2,95 @@ import type { ReactNode } from "react";
2
2
  import { CompleteAttachment } from "./AttachmentTypes";
3
3
  export type MessageRole = "user" | "assistant" | "system";
4
4
  export type TextContentPart = {
5
- type: "text";
6
- text: string;
5
+ readonly type: "text";
6
+ readonly text: string;
7
7
  };
8
8
  export type ImageContentPart = {
9
- type: "image";
10
- image: string;
9
+ readonly type: "image";
10
+ readonly image: string;
11
11
  };
12
12
  export type Unstable_AudioContentPart = {
13
- type: "audio";
14
- audio: {
15
- data: string;
16
- format: "mp3" | "wav";
13
+ readonly type: "audio";
14
+ readonly audio: {
15
+ readonly data: string;
16
+ readonly format: "mp3" | "wav";
17
17
  };
18
18
  };
19
19
  export type UIContentPart = {
20
- type: "ui";
21
- display: ReactNode;
20
+ readonly type: "ui";
21
+ readonly display: ReactNode;
22
22
  };
23
23
  export type CoreToolCallContentPart<TArgs extends Record<string, unknown> = Record<string | number, unknown>, TResult = unknown> = {
24
- type: "tool-call";
25
- toolCallId: string;
26
- toolName: string;
27
- args: TArgs;
28
- result?: TResult | undefined;
29
- isError?: boolean | undefined;
24
+ readonly type: "tool-call";
25
+ readonly toolCallId: string;
26
+ readonly toolName: string;
27
+ readonly args: TArgs;
28
+ readonly result?: TResult | undefined;
29
+ readonly isError?: boolean | undefined;
30
30
  };
31
31
  export type ToolCallContentPart<TArgs extends Record<string, unknown> = Record<string | number, unknown>, TResult = unknown> = CoreToolCallContentPart<TArgs, TResult> & {
32
- argsText: string;
32
+ readonly argsText: string;
33
33
  };
34
34
  export type ThreadUserContentPart = TextContentPart | ImageContentPart | Unstable_AudioContentPart | UIContentPart;
35
35
  export type ThreadAssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
36
36
  type MessageCommonProps = {
37
- id: string;
38
- createdAt: Date;
37
+ readonly id: string;
38
+ readonly createdAt: Date;
39
39
  };
40
40
  export type ThreadStep = {
41
- usage?: {
42
- promptTokens: number;
43
- completionTokens: number;
41
+ readonly usage?: {
42
+ readonly promptTokens: number;
43
+ readonly completionTokens: number;
44
44
  } | undefined;
45
45
  };
46
46
  export type ContentPartStatus = {
47
- type: "running";
47
+ readonly type: "running";
48
48
  } | {
49
- type: "complete";
49
+ readonly type: "complete";
50
50
  } | {
51
- type: "incomplete";
52
- reason: "cancelled" | "length" | "content-filter" | "other" | "error";
53
- error?: unknown;
51
+ readonly type: "incomplete";
52
+ readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error";
53
+ readonly error?: unknown;
54
54
  };
55
55
  export type ToolCallContentPartStatus = {
56
- type: "requires-action";
57
- reason: "tool-calls";
56
+ readonly type: "requires-action";
57
+ readonly reason: "tool-calls";
58
58
  } | ContentPartStatus;
59
59
  export type MessageStatus = {
60
- type: "running";
60
+ readonly type: "running";
61
61
  } | {
62
- type: "requires-action";
63
- reason: "tool-calls";
62
+ readonly type: "requires-action";
63
+ readonly reason: "tool-calls";
64
64
  } | {
65
- type: "complete";
66
- reason: "stop" | "unknown";
65
+ readonly type: "complete";
66
+ readonly reason: "stop" | "unknown";
67
67
  } | {
68
- type: "incomplete";
69
- reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
70
- error?: unknown;
68
+ readonly type: "incomplete";
69
+ readonly reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
70
+ readonly error?: unknown;
71
71
  };
72
72
  export type ThreadSystemMessage = MessageCommonProps & {
73
- role: "system";
74
- content: [TextContentPart];
73
+ readonly role: "system";
74
+ readonly content: [TextContentPart];
75
+ readonly metadata: {
76
+ readonly custom: Record<string, unknown>;
77
+ };
75
78
  };
76
79
  export type ThreadUserMessage = MessageCommonProps & {
77
- role: "user";
78
- content: ThreadUserContentPart[];
79
- attachments: readonly CompleteAttachment[];
80
+ readonly role: "user";
81
+ readonly content: ThreadUserContentPart[];
82
+ readonly attachments: readonly CompleteAttachment[];
83
+ readonly metadata: {
84
+ readonly custom: Record<string, unknown>;
85
+ };
80
86
  };
81
87
  export type ThreadAssistantMessage = MessageCommonProps & {
82
- role: "assistant";
83
- content: ThreadAssistantContentPart[];
84
- status: MessageStatus;
85
- metadata?: {
86
- steps?: ThreadStep[] | undefined;
87
- custom?: Record<string, unknown> | undefined;
88
+ readonly role: "assistant";
89
+ readonly content: ThreadAssistantContentPart[];
90
+ readonly status: MessageStatus;
91
+ readonly metadata: {
92
+ readonly steps: ThreadStep[];
93
+ readonly custom: Record<string, unknown>;
88
94
  };
89
95
  };
90
96
  export type AppendMessage = CoreMessage & {
@@ -93,9 +99,12 @@ export type AppendMessage = CoreMessage & {
93
99
  startRun?: boolean | undefined;
94
100
  };
95
101
  type BaseThreadMessage = {
96
- status?: ThreadAssistantMessage["status"];
97
- metadata?: ThreadAssistantMessage["metadata"];
98
- attachments?: ThreadUserMessage["attachments"];
102
+ readonly status?: ThreadAssistantMessage["status"];
103
+ readonly metadata: {
104
+ readonly steps?: ThreadStep[];
105
+ readonly custom: Record<string, unknown>;
106
+ };
107
+ readonly attachments?: ThreadUserMessage["attachments"];
99
108
  };
100
109
  export type ThreadMessage = BaseThreadMessage & (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);
101
110
  /** Core Message Types (without UI content parts) */
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantTypes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AE;QACjB,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;QAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC1C,CAAC;IACF,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAC3C,CAAC,mBAAmB,GAAG,iBAAiB,GAAG,sBAAsB,CAAC,CAAC;AAErE,oDAAoD;AAEpD,MAAM,MAAM,mBAAmB,GAC3B,eAAe,GACf,gBAAgB,GAChB,yBAAyB,CAAC;AAC9B,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf,uBAAuB,CAAC;AAE5B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,wBAAwB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,eAAe,GACf,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/AssistantTypes.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { CompleteAttachment } from \"./AttachmentTypes\";\n\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\n\nexport type TextContentPart = {\n type: \"text\";\n text: string;\n};\n\nexport type ImageContentPart = {\n type: \"image\";\n image: string;\n};\n\nexport type Unstable_AudioContentPart = {\n type: \"audio\";\n audio: {\n data: string;\n format: \"mp3\" | \"wav\";\n };\n};\n\nexport type UIContentPart = {\n type: \"ui\";\n display: ReactNode;\n};\n\nexport type CoreToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = {\n type: \"tool-call\";\n toolCallId: string;\n toolName: string;\n args: TArgs;\n result?: TResult | undefined;\n isError?: boolean | undefined;\n};\n\nexport type ToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = CoreToolCallContentPart<TArgs, TResult> & {\n argsText: string;\n};\n\nexport type ThreadUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart\n | UIContentPart;\n\nexport type ThreadAssistantContentPart =\n | TextContentPart\n | ToolCallContentPart\n | UIContentPart;\n\ntype MessageCommonProps = {\n id: string;\n createdAt: Date;\n};\n\nexport type ThreadStep = {\n usage?:\n | {\n promptTokens: number;\n completionTokens: number;\n }\n | undefined;\n};\n\nexport type ContentPartStatus =\n | {\n type: \"running\";\n }\n | {\n type: \"complete\";\n }\n | {\n type: \"incomplete\";\n reason: \"cancelled\" | \"length\" | \"content-filter\" | \"other\" | \"error\";\n error?: unknown;\n };\n\nexport type ToolCallContentPartStatus =\n | {\n type: \"requires-action\";\n reason: \"tool-calls\";\n }\n | ContentPartStatus;\n\nexport type MessageStatus =\n | {\n type: \"running\";\n }\n | {\n type: \"requires-action\";\n reason: \"tool-calls\";\n }\n | {\n type: \"complete\";\n reason: \"stop\" | \"unknown\";\n }\n | {\n type: \"incomplete\";\n reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n error?: unknown;\n };\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n role: \"system\";\n content: [TextContentPart];\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n role: \"user\";\n content: ThreadUserContentPart[];\n attachments: readonly CompleteAttachment[];\n // TODO metadata\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n role: \"assistant\";\n content: ThreadAssistantContentPart[];\n status: MessageStatus;\n metadata?: {\n steps?: ThreadStep[] | undefined;\n custom?: Record<string, unknown> | undefined;\n };\n};\n\nexport type AppendMessage = CoreMessage & {\n parentId: string | null;\n attachments: readonly CompleteAttachment[];\n startRun?: boolean | undefined;\n};\n\ntype BaseThreadMessage = {\n status?: ThreadAssistantMessage[\"status\"];\n metadata?: ThreadAssistantMessage[\"metadata\"];\n attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\n/** Core Message Types (without UI content parts) */\n\nexport type CoreUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart;\nexport type CoreAssistantContentPart =\n | TextContentPart\n | CoreToolCallContentPart;\n\nexport type CoreSystemMessage = {\n role: \"system\";\n content: [TextContentPart];\n};\n\nexport type CoreUserMessage = {\n role: \"user\";\n content: CoreUserContentPart[];\n};\n\nexport type CoreAssistantMessage = {\n role: \"assistant\";\n content: CoreAssistantContentPart[];\n};\n\nexport type CoreMessage =\n | CoreSystemMessage\n | CoreUserMessage\n | CoreAssistantMessage;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/AssistantTypes.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { CompleteAttachment } from \"./AttachmentTypes\";\n\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\n\nexport type TextContentPart = {\n readonly type: \"text\";\n readonly text: string;\n};\n\nexport type ImageContentPart = {\n readonly type: \"image\";\n readonly image: string;\n};\n\nexport type Unstable_AudioContentPart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type UIContentPart = {\n readonly type: \"ui\";\n readonly display: ReactNode;\n};\n\nexport type CoreToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: TArgs;\n readonly result?: TResult | undefined;\n readonly isError?: boolean | undefined;\n};\n\nexport type ToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = CoreToolCallContentPart<TArgs, TResult> & {\n readonly argsText: string;\n};\n\nexport type ThreadUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart\n | UIContentPart;\n\nexport type ThreadAssistantContentPart =\n | TextContentPart\n | ToolCallContentPart\n | UIContentPart;\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadStep = {\n readonly usage?:\n | {\n readonly promptTokens: number;\n readonly completionTokens: number;\n }\n | undefined;\n};\n\nexport type ContentPartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallContentPartStatus =\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | ContentPartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: [TextContentPart];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: ThreadUserContentPart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: ThreadAssistantContentPart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly steps: ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type AppendMessage = CoreMessage & {\n parentId: string | null;\n attachments: readonly CompleteAttachment[];\n startRun?: boolean | undefined;\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly steps?: ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\n/** Core Message Types (without UI content parts) */\n\nexport type CoreUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart;\nexport type CoreAssistantContentPart =\n | TextContentPart\n | CoreToolCallContentPart;\n\nexport type CoreSystemMessage = {\n role: \"system\";\n content: [TextContentPart];\n};\n\nexport type CoreUserMessage = {\n role: \"user\";\n content: CoreUserContentPart[];\n};\n\nexport type CoreAssistantMessage = {\n role: \"assistant\";\n content: CoreAssistantContentPart[];\n};\n\nexport type CoreMessage =\n | CoreSystemMessage\n | CoreUserMessage\n | CoreAssistantMessage;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { type FC } from "react";
2
2
  import { TooltipIconButtonProps } from "./base/tooltip-icon-button";
3
- declare const Attachment: FC;
3
+ declare const AttachmentUI: FC;
4
4
  declare const exports: {
5
5
  Root: import("react").ForwardRefExoticComponent<Partial<Omit<Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
6
6
  ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
@@ -9,6 +9,6 @@ declare const exports: {
9
9
  }, "ref"> & import("react").RefAttributes<HTMLDivElement>, "ref">> & import("react").RefAttributes<HTMLDivElement>>;
10
10
  Remove: import("react").ForwardRefExoticComponent<Partial<TooltipIconButtonProps> & import("react").RefAttributes<HTMLButtonElement>>;
11
11
  };
12
- declare const _default: typeof Attachment & typeof exports;
12
+ declare const _default: typeof AttachmentUI & typeof exports;
13
13
  export default _default;
14
- //# sourceMappingURL=attachment.d.ts.map
14
+ //# sourceMappingURL=attachment-ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment-ui.d.ts","sourceRoot":"","sources":["../../src/ui/attachment-ui.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,EAAE,EACR,MAAM,OAAO,CAAC;AAIf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAiHpC,QAAA,MAAM,YAAY,EAAE,EAqCnB,CAAC;AAoCF,QAAA,MAAM,OAAO;;;;;;;CAGZ,CAAC;wBAEqD,OAAO,YAAY,GACxE,OAAO,OAAO;AADhB,wBACiB"}
@@ -18,12 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  };
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
 
21
- // src/ui/attachment.tsx
22
- var attachment_exports = {};
23
- __export(attachment_exports, {
24
- default: () => attachment_default
21
+ // src/ui/attachment-ui.tsx
22
+ var attachment_ui_exports = {};
23
+ __export(attachment_ui_exports, {
24
+ default: () => attachment_ui_default
25
25
  });
26
- module.exports = __toCommonJS(attachment_exports);
26
+ module.exports = __toCommonJS(attachment_ui_exports);
27
27
  var import_react = require("react");
28
28
  var import_lucide_react = require("lucide-react");
29
29
  var import_withDefaults = require("./utils/withDefaults.cjs");
@@ -109,7 +109,7 @@ var AttachmentThumb = () => {
109
109
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base.AvatarImage, { src })
110
110
  ] });
111
111
  };
112
- var Attachment = () => {
112
+ var AttachmentUI = () => {
113
113
  const canRemove = (0, import_AttachmentContext.useAttachment)((a) => a.source !== "message");
114
114
  const typeLabel = (0, import_AttachmentContext.useAttachment)((a) => {
115
115
  const type = a.type;
@@ -137,7 +137,7 @@ var Attachment = () => {
137
137
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base.TooltipContent, { side: "top", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.AttachmentPrimitive.Name, {}) })
138
138
  ] });
139
139
  };
140
- Attachment.displayName = "Attachment";
140
+ AttachmentUI.displayName = "Attachment";
141
141
  var AttachmentRemove = (0, import_react.forwardRef)((props, ref) => {
142
142
  const {
143
143
  strings: {
@@ -161,5 +161,5 @@ var exports2 = {
161
161
  Root: AttachmentRoot,
162
162
  Remove: AttachmentRemove
163
163
  };
164
- var attachment_default = Object.assign(Attachment, exports2);
165
- //# sourceMappingURL=attachment.js.map
164
+ var attachment_ui_default = Object.assign(AttachmentUI, exports2);
165
+ //# sourceMappingURL=attachment-ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ui/attachment-ui.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n PropsWithChildren,\n useEffect,\n useState,\n type FC,\n} from \"react\";\nimport { CircleXIcon, FileIcon } from \"lucide-react\";\nimport { withDefaults } from \"./utils/withDefaults\";\nimport { useThreadConfig } from \"./thread-config\";\nimport {\n TooltipIconButton,\n TooltipIconButtonProps,\n} from \"./base/tooltip-icon-button\";\nimport { AttachmentPrimitive } from \"../primitives\";\nimport { useAttachment } from \"../context/react/AttachmentContext\";\nimport {\n AvatarImage,\n AvatarRoot,\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"./base\";\nimport { Dialog, DialogTrigger, DialogContent } from \"./base/dialog\";\nimport { AvatarFallback } from \"@radix-ui/react-avatar\";\nimport { useShallow } from \"zustand/shallow\";\nimport { DialogTitle } from \"@radix-ui/react-dialog\";\n\nconst AttachmentRoot = withDefaults(AttachmentPrimitive.Root, {\n className: \"aui-attachment-root\",\n});\n\nAttachmentRoot.displayName = \"AttachmentRoot\";\n\nconst useFileSrc = (file: File | undefined) => {\n const [src, setSrc] = useState<string | undefined>(undefined);\n\n useEffect(() => {\n if (!file) {\n setSrc(undefined);\n return;\n }\n\n const objectUrl = URL.createObjectURL(file);\n setSrc(objectUrl);\n\n return () => {\n URL.revokeObjectURL(objectUrl);\n };\n }, [file]);\n\n return src;\n};\n\nconst useAttachmentSrc = () => {\n const { file, src } = useAttachment(\n useShallow((a): { file?: File; src?: string } => {\n if (a.type !== \"image\") return {};\n if (a.file) return { file: a.file };\n const src = a.content?.filter((c) => c.type === \"image\")[0]?.image;\n if (!src) return {};\n return { src };\n }),\n );\n\n return useFileSrc(file) ?? src;\n};\n\ntype AttachmentPreviewProps = {\n src: string;\n};\n\nconst AttachmentPreview: FC<AttachmentPreviewProps> = ({ src }) => {\n const [isLoaded, setIsLoaded] = useState(false);\n\n return (\n // eslint-disable-next-line @next/next/no-img-element\n <img\n src={src}\n style={{\n width: \"auto\",\n height: \"auto\",\n maxWidth: \"75dvh\",\n maxHeight: \"75dvh\",\n display: isLoaded ? \"block\" : \"none\",\n overflow: \"clip\",\n }}\n onLoad={() => setIsLoaded(true)}\n alt=\"Image Preview\"\n />\n );\n};\n\nconst AttachmentPreviewDialog: FC<PropsWithChildren> = ({ children }) => {\n const src = useAttachmentSrc();\n\n if (!src) return children;\n\n return (\n <Dialog>\n <DialogTrigger className=\"aui-attachment-preview-trigger\" asChild>\n {children}\n </DialogTrigger>\n <DialogContent>\n <DialogTitle className=\"aui-sr-only\">\n Image Attachment Preview\n </DialogTitle>\n <AttachmentPreview src={src} />\n </DialogContent>\n </Dialog>\n );\n};\n\nconst AttachmentThumb: FC = () => {\n const isImage = useAttachment((a) => a.type === \"image\");\n const src = useAttachmentSrc();\n return (\n <AvatarRoot className=\"aui-attachment-thumb\">\n <AvatarFallback delayMs={isImage ? 200 : 0}>\n <FileIcon />\n </AvatarFallback>\n <AvatarImage src={src}></AvatarImage>\n </AvatarRoot>\n );\n};\n\nconst AttachmentUI: FC = () => {\n const canRemove = useAttachment((a) => a.source !== \"message\");\n const typeLabel = useAttachment((a) => {\n const type = a.type;\n switch (type) {\n case \"image\":\n return \"Image\";\n case \"document\":\n return \"Document\";\n case \"file\":\n return \"File\";\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n });\n return (\n <Tooltip>\n <AttachmentPreviewDialog>\n <TooltipTrigger asChild>\n <AttachmentRoot>\n <AttachmentThumb />\n <div className=\"aui-attachment-text\">\n <p className=\"aui-attachment-name\">\n <AttachmentPrimitive.Name />\n </p>\n <p className=\"aui-attachment-type\">{typeLabel}</p>\n </div>\n {canRemove && <AttachmentRemove />}\n </AttachmentRoot>\n </TooltipTrigger>\n </AttachmentPreviewDialog>\n <TooltipContent side=\"top\">\n <AttachmentPrimitive.Name />\n </TooltipContent>\n </Tooltip>\n );\n};\n\nAttachmentUI.displayName = \"Attachment\";\n\nnamespace AttachmentRemove {\n export type Element = HTMLButtonElement;\n export type Props = Partial<TooltipIconButtonProps>;\n}\n\nconst AttachmentRemove = forwardRef<\n AttachmentRemove.Element,\n AttachmentRemove.Props\n>((props, ref) => {\n const {\n strings: {\n composer: { removeAttachment: { tooltip = \"Remove file\" } = {} } = {},\n } = {},\n } = useThreadConfig();\n\n return (\n <AttachmentPrimitive.Remove asChild>\n <TooltipIconButton\n tooltip={tooltip}\n className=\"aui-attachment-remove\"\n side=\"top\"\n {...props}\n ref={ref}\n >\n {props.children ?? <CircleXIcon />}\n </TooltipIconButton>\n </AttachmentPrimitive.Remove>\n );\n});\n\nAttachmentRemove.displayName = \"AttachmentRemove\";\n\nconst exports = {\n Root: AttachmentRoot,\n Remove: AttachmentRemove,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AA,gDAAC,2BACC,sDAAC,8BAAe,SAAO,MACrB,uDAAC,kBACC;AAAA,kDAAC,mBAAgB;AAAA,MACjB,6CAAC,SAAI,WAAU,uBACb;AAAA,oDAAC,OAAE,WAAU,uBACX,sDAAC,sCAAoB,MAApB,EAAyB,GAC5B;AAAA,QACA,4CAAC,OAAE,WAAU,uBAAuB,qBAAU;AAAA,SAChD;AAAA,MACC,aAAa,4CAAC,oBAAiB;AAAA,OAClC,GACF,GACF;AAAA,IACA,4CAAC,8BAAe,MAAK,OACnB,sDAAC,sCAAoB,MAApB,EAAyB,GAC5B;AAAA,KACF;AAEJ;AAEA,aAAa,cAAc;AAO3B,IAAM,uBAAmB,yBAGvB,CAAC,OAAO,QAAQ;AAChB,QAAM;AAAA,IACJ,SAAS;AAAA,MACP,UAAU,EAAE,kBAAkB,EAAE,UAAU,cAAc,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,IACtE,IAAI,CAAC;AAAA,EACP,QAAI,sCAAgB;AAEpB,SACE,4CAAC,sCAAoB,QAApB,EAA2B,SAAO,MACjC;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAU;AAAA,MACV,MAAK;AAAA,MACJ,GAAG;AAAA,MACJ;AAAA,MAEC,gBAAM,YAAY,4CAAC,mCAAY;AAAA;AAAA,EAClC,GACF;AAEJ,CAAC;AAED,iBAAiB,cAAc;AAE/B,IAAMC,WAAU;AAAA,EACd,MAAM;AAAA,EACN,QAAQ;AACV;AAEA,IAAO,wBAAQ,OAAO,OAAO,cAAcA,QAAO;","names":["src","exports"]}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- // src/ui/attachment.tsx
3
+ // src/ui/attachment-ui.tsx
4
4
  import {
5
5
  forwardRef,
6
6
  useEffect,
@@ -98,7 +98,7 @@ var AttachmentThumb = () => {
98
98
  /* @__PURE__ */ jsx(AvatarImage, { src })
99
99
  ] });
100
100
  };
101
- var Attachment = () => {
101
+ var AttachmentUI = () => {
102
102
  const canRemove = useAttachment((a) => a.source !== "message");
103
103
  const typeLabel = useAttachment((a) => {
104
104
  const type = a.type;
@@ -126,7 +126,7 @@ var Attachment = () => {
126
126
  /* @__PURE__ */ jsx(TooltipContent, { side: "top", children: /* @__PURE__ */ jsx(AttachmentPrimitive.Name, {}) })
127
127
  ] });
128
128
  };
129
- Attachment.displayName = "Attachment";
129
+ AttachmentUI.displayName = "Attachment";
130
130
  var AttachmentRemove = forwardRef((props, ref) => {
131
131
  const {
132
132
  strings: {
@@ -150,8 +150,8 @@ var exports = {
150
150
  Root: AttachmentRoot,
151
151
  Remove: AttachmentRemove
152
152
  };
153
- var attachment_default = Object.assign(Attachment, exports);
153
+ var attachment_ui_default = Object.assign(AttachmentUI, exports);
154
154
  export {
155
- attachment_default as default
155
+ attachment_ui_default as default
156
156
  };
157
- //# sourceMappingURL=attachment.mjs.map
157
+ //# sourceMappingURL=attachment-ui.mjs.map