@assistant-ui/react 0.5.93 → 0.5.95

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"MessageRuntime.d.ts","sourceRoot":"","sources":["../../src/api/MessageRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EAEjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAI3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAMpE,eAAO,MAAM,mBAAmB,YACrB,aAAa,aACX,MAAM,QACX,qBAAqB,GAAG,0BAA0B,KACvD,yBAsBF,CAAC;AAEF,eAAO,MAAM,aAAa;;;EAA4C,CAAC;AA4BvE,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IACzC;;OAEG;IACH,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAE5B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IAChC,iBAAiB,EAAE,iBAAiB,GAAG,S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AAE,MAAM,GAAG,kBAAkB,CAAC;IAEnE,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE,CAAC;CAC9E,CAAC;AAEF,qBAAa,kBAAmB,YAAW,cAAc;IAMrD,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,cAAc;IANxB,IAAW,IAAI,uBAEd;gBAGS,KAAK,EAAE,mBAAmB,EAC1B,cAAc,EAAE,wBAAwB;IAmB3C,QAAQ,0BAAC;IAET,QAAQ;IAIR,MAAM;IASN,KAAK;IAOL,YAAY;IAYZ,cAAc,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAAA;KAAE;IAU1D,cAAc,CAAC,EACpB,QAAQ,EACR,QAAQ,GACT,EAAE;QACD,QAAQ,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;QAC3C,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC/B;IAuBM,oBAAoB;IAIpB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;IAI9B,qBAAqB,CAAC,GAAG,EAAE,MAAM;IAmBjC,0BAA0B,CAAC,UAAU,EAAE,MAAM;IA0B7C,oBAAoB,CAAC,GAAG,EAAE,MAAM;CAwBxC"}
@@ -35,18 +35,16 @@ const COMPLETE_STATUS = {
35
35
  };
36
36
  const toContentPartStatus = (message, partIndex, part) => {
37
37
  if (message.role !== "assistant") return COMPLETE_STATUS;
38
- const isLastPart = partIndex === Math.max(0, message.content.length - 1);
39
- if (part.type !== "tool-call") {
40
- if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
41
- throw new Error(
42
- "Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
43
- );
44
- return isLastPart ? message.status : COMPLETE_STATUS;
45
- }
46
- if (!!part.result) {
47
- return COMPLETE_STATUS;
38
+ if (part.type === "tool-call") {
39
+ if (!part.result) {
40
+ return message.status;
41
+ } else {
42
+ return COMPLETE_STATUS;
43
+ }
48
44
  }
49
- return message.status;
45
+ const isLastPart = partIndex === Math.max(0, message.content.length - 1);
46
+ if (message.status.type === "requires-action") return COMPLETE_STATUS;
47
+ return isLastPart ? message.status : COMPLETE_STATUS;
50
48
  };
51
49
  const EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
52
50
  const getContentPartState = (message, partIndex) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (part.type !== \"tool-call\") {\n if (\n \"reason\" in message.status &&\n message.status.reason === \"tool-calls\" &&\n isLastPart\n )\n throw new Error(\n \"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui.\",\n );\n\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n }\n\n if (!!part.result) {\n return COMPLETE_STATUS;\n }\n\n return message.status as ToolCallContentPartStatus;\n};\n\nexport const EMPTY_CONTENT = Object.freeze({ type: \"text\", text: \"\" });\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n let part = message.content[partIndex];\n if (!part) {\n // for empty messages, show an empty text content part\n if (message.content.length === 0 && partIndex === 0) {\n part = EMPTY_CONTENT;\n } else {\n return SKIP_UPDATE;\n }\n } else if (\n message.content.length === 1 &&\n part.type === \"text\" &&\n part.text.length === 0\n ) {\n // ensure reference equality for equivalent empty text parts\n part = EMPTY_CONTENT;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({ ...part, part, status });\n};\n\nexport type MessageState = ThreadMessage & {\n /**\n * @deprecated You can directly access message fields in the state. Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.\n */\n message: ThreadMessage;\n parentId: string | null;\n isLast: boolean;\n /**\n * @deprecated Use `branchNumber` and `branchCount` instead. This will be removed in 0.6.0.\n */\n branches: readonly string[];\n\n branchNumber: number;\n branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: () =>\n this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id),\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n public composer;\n\n public getState() {\n return this._core.getState();\n }\n\n public reload() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun(state.parentId);\n }\n\n public speak() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n attachment: attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,kCAAqC;AACrC,+BAIO;AACP,6BAGO;AACP,gCAIO;AAGP,uCAA0C;AAC1C,yBAA4B;AAC5B,mCAAsC;AAGtC,MAAM,kBAAqC;AAAA,EACzC,MAAM;AACR;AAEO,MAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,QAAM,aAAa,cAAc,KAAK,IAAI,GAAG,QAAQ,QAAQ,SAAS,CAAC;AACvE,MAAI,KAAK,SAAS,aAAa;AAC7B,QACE,YAAY,QAAQ,UACpB,QAAQ,OAAO,WAAW,gBAC1B;AAEA,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAEF,WAAO,aAAc,QAAQ,SAA+B;AAAA,EAC9D;AAEA,MAAI,CAAC,CAAC,KAAK,QAAQ;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ;AACjB;AAEO,MAAM,gBAAgB,OAAO,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,CAAC;AAErE,MAAM,sBAAsB,CAC1B,SACA,cACmC;AACnC,MAAI,OAAO,QAAQ,QAAQ,SAAS;AACpC,MAAI,CAAC,MAAM;AAET,QAAI,QAAQ,QAAQ,WAAW,KAAK,cAAc,GAAG;AACnD,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF,WACE,QAAQ,QAAQ,WAAW,KAC3B,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T,IAAI,mDAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,GAAG,KAAK;AAAA,UACR,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,UACxD,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH;AAAA,YACA,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallContentPartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n};\n\nexport const EMPTY_CONTENT = Object.freeze({ type: \"text\", text: \"\" });\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n let part = message.content[partIndex];\n if (!part) {\n // for empty messages, show an empty text content part\n if (message.content.length === 0 && partIndex === 0) {\n part = EMPTY_CONTENT;\n } else {\n return SKIP_UPDATE;\n }\n } else if (\n message.content.length === 1 &&\n part.type === \"text\" &&\n part.text.length === 0\n ) {\n // ensure reference equality for equivalent empty text parts\n part = EMPTY_CONTENT;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({ ...part, part, status });\n};\n\nexport type MessageState = ThreadMessage & {\n /**\n * @deprecated You can directly access message fields in the state. Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.\n */\n message: ThreadMessage;\n parentId: string | null;\n isLast: boolean;\n /**\n * @deprecated Use `branchNumber` and `branchCount` instead. This will be removed in 0.6.0.\n */\n branches: readonly string[];\n\n branchNumber: number;\n branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: () =>\n this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id),\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n public composer;\n\n public getState() {\n return this._core.getState();\n }\n\n public reload() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun(state.parentId);\n }\n\n public speak() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n attachment: attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,kCAAqC;AACrC,+BAIO;AACP,6BAGO;AACP,gCAIO;AAGP,uCAA0C;AAC1C,yBAA4B;AAC5B,mCAAsC;AAGtC,MAAM,kBAAqC;AAAA,EACzC,MAAM;AACR;AAEO,MAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,MAAI,KAAK,SAAS,aAAa;AAC7B,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,QAAQ;AAAA,IACjB,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,KAAK,IAAI,GAAG,QAAQ,QAAQ,SAAS,CAAC;AACvE,MAAI,QAAQ,OAAO,SAAS,kBAAmB,QAAO;AACtD,SAAO,aAAc,QAAQ,SAA+B;AAC9D;AAEO,MAAM,gBAAgB,OAAO,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,CAAC;AAErE,MAAM,sBAAsB,CAC1B,SACA,cACmC;AACnC,MAAI,OAAO,QAAQ,QAAQ,SAAS;AACpC,MAAI,CAAC,MAAM;AAET,QAAI,QAAQ,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AAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,qBAAqB,KAAa;AACvC,WAAO,IAAI;AAAA,MACT,IAAI,mDAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,GAAG,KAAK;AAAA,UACR,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,UACxD,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH;AAAA,YACA,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -16,18 +16,16 @@ const COMPLETE_STATUS = {
16
16
  };
17
17
  const toContentPartStatus = (message, partIndex, part) => {
18
18
  if (message.role !== "assistant") return COMPLETE_STATUS;
19
- const isLastPart = partIndex === Math.max(0, message.content.length - 1);
20
- if (part.type !== "tool-call") {
21
- if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
22
- throw new Error(
23
- "Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
24
- );
25
- return isLastPart ? message.status : COMPLETE_STATUS;
26
- }
27
- if (!!part.result) {
28
- return COMPLETE_STATUS;
19
+ if (part.type === "tool-call") {
20
+ if (!part.result) {
21
+ return message.status;
22
+ } else {
23
+ return COMPLETE_STATUS;
24
+ }
29
25
  }
30
- return message.status;
26
+ const isLastPart = partIndex === Math.max(0, message.content.length - 1);
27
+ if (message.status.type === "requires-action") return COMPLETE_STATUS;
28
+ return isLastPart ? message.status : COMPLETE_STATUS;
31
29
  };
32
30
  const EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
33
31
  const getContentPartState = (message, partIndex) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (part.type !== \"tool-call\") {\n if (\n \"reason\" in message.status &&\n message.status.reason === \"tool-calls\" &&\n isLastPart\n )\n throw new Error(\n \"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui.\",\n );\n\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n }\n\n if (!!part.result) {\n return COMPLETE_STATUS;\n }\n\n return message.status as ToolCallContentPartStatus;\n};\n\nexport const EMPTY_CONTENT = Object.freeze({ type: \"text\", text: \"\" });\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n let part = message.content[partIndex];\n if (!part) {\n // for empty messages, show an empty text content part\n if (message.content.length === 0 && partIndex === 0) {\n part = EMPTY_CONTENT;\n } else {\n return SKIP_UPDATE;\n }\n } else if (\n message.content.length === 1 &&\n part.type === \"text\" &&\n part.text.length === 0\n ) {\n // ensure reference equality for equivalent empty text parts\n part = EMPTY_CONTENT;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({ ...part, part, status });\n};\n\nexport type MessageState = ThreadMessage & {\n /**\n * @deprecated You can directly access message fields in the state. Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.\n */\n message: ThreadMessage;\n parentId: string | null;\n isLast: boolean;\n /**\n * @deprecated Use `branchNumber` and `branchCount` instead. This will be removed in 0.6.0.\n */\n branches: readonly string[];\n\n branchNumber: number;\n branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: () =>\n this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id),\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n public composer;\n\n public getState() {\n return this._core.getState();\n }\n\n public reload() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun(state.parentId);\n }\n\n public speak() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n attachment: attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":"AAcA,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OAEK;AAGP,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAGtC,MAAM,kBAAqC;AAAA,EACzC,MAAM;AACR;AAEO,MAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,QAAM,aAAa,cAAc,KAAK,IAAI,GAAG,QAAQ,QAAQ,SAAS,CAAC;AACvE,MAAI,KAAK,SAAS,aAAa;AAC7B,QACE,YAAY,QAAQ,UACpB,QAAQ,OAAO,WAAW,gBAC1B;AAEA,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAEF,WAAO,aAAc,QAAQ,SAA+B;AAAA,EAC9D;AAEA,MAAI,CAAC,CAAC,KAAK,QAAQ;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ;AACjB;AAEO,MAAM,gBAAgB,OAAO,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,CAAC;AAErE,MAAM,sBAAsB,CAC1B,SACA,cACmC;AACnC,MAAI,OAAO,QAAQ,QAAQ,SAAS;AACpC,MAAI,CAAC,MAAM;AAET,QAAI,QAAQ,QAAQ,WAAW,KAAK,cAAc,GAAG;AACnD,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF,WACE,QAAQ,QAAQ,WAAW,KAC3B,KAAK,SAAS,UACd,KAAK,KAAK,WAAW,GACrB;AAEA,WAAO;AAAA,EACT;AAGA,QAAM,SAAS,oBAAoB,SAAS,WAAW,IAAI;AAC3D,SAAO,OAAO,OAAO,EAAE,GAAG,MAAM,MAAM,OAAO,CAAC;AAChD;AA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,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH;AAAA,YACA,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallContentPartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n};\n\nexport const EMPTY_CONTENT = Object.freeze({ type: \"text\", text: \"\" });\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n let part = message.content[partIndex];\n if (!part) {\n // for empty messages, show an empty text content part\n if (message.content.length === 0 && partIndex === 0) {\n part = EMPTY_CONTENT;\n } else {\n return SKIP_UPDATE;\n }\n } else if (\n message.content.length === 1 &&\n part.type === \"text\" &&\n part.text.length === 0\n ) {\n // ensure reference equality for equivalent empty text parts\n part = EMPTY_CONTENT;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({ ...part, part, status });\n};\n\nexport type MessageState = ThreadMessage & {\n /**\n * @deprecated You can directly access message fields in the state. Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.\n */\n message: ThreadMessage;\n parentId: string | null;\n isLast: boolean;\n /**\n * @deprecated Use `branchNumber` and `branchCount` instead. This will be removed in 0.6.0.\n */\n branches: readonly string[];\n\n branchNumber: number;\n branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: () =>\n this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id),\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n public composer;\n\n public getState() {\n return this._core.getState();\n }\n\n public reload() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun(state.parentId);\n }\n\n public speak() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (!state) throw new Error(\"Message is not available\");\n\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n attachment: attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":"AAcA,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OAEK;AAGP,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAGtC,MAAM,kBAAqC;AAAA,EACzC,MAAM;AACR;AAEO,MAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,MAAI,KAAK,SAAS,aAAa;AAC7B,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,QAAQ;AAAA,IACjB,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,KAAK,IAAI,GAAG,QAAQ,QAAQ,SAAS,CAAC;AACvE,MAAI,QAAQ,OAAO,SAAS,kBAAmB,QAAO;AACtD,SAAO,aAAc,QAAQ,SAA+B;AAC9D;AAEO,MAAM,gBAAgB,OAAO,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,CAAC;AAErE,MAAM,sBAAsB,CAC1B,SACA,cACmC;AACnC,MAAI,OAAO,QAAQ,QAAQ,SAAS;AACpC,MAAI,CAAC,MAAM;AAET,QAAI,QAAQ,QAAQ,WAAW,KAAK,cAAc,GAAG;AACnD,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF,WACE,QAAQ,QAAQ,WAAW,KAC3B,KAAK,SAAS,UACd,KAAK,KAAK,WAAW,GACrB;AA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J,GAAG,KAAK;AAAA,UACR,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,UACxD,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH;AAAA,YACA,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,48 @@
1
+ {
2
+ ".aui-root": {
3
+ "@apply text-aui-foreground": {}
4
+ },
5
+ ".aui-root *": {
6
+ "@apply border-aui-border": {}
7
+ },
8
+ ".aui-button": {
9
+ "@apply focus-visible:ring-aui-ring inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:opacity-50": {}
10
+ },
11
+ ".aui-button-primary": {
12
+ "@apply bg-aui-primary text-aui-primary-foreground hover:bg-aui-primary/90 shadow": {}
13
+ },
14
+ ".aui-button-outline": {
15
+ "@apply border-aui-input bg-aui-background hover:bg-aui-accent hover:text-aui-accent-foreground border shadow-sm": {}
16
+ },
17
+ ".aui-button-ghost": {
18
+ "@apply hover:bg-aui-accent hover:text-aui-accent-foreground": {}
19
+ },
20
+ ".aui-button-medium": {
21
+ "@apply h-9 px-4 py-2": {}
22
+ },
23
+ ".aui-button-icon": {
24
+ "@apply size-6 p-1": {}
25
+ },
26
+ ".aui-sr-only": {
27
+ "@apply sr-only": {}
28
+ },
29
+ ".aui-avatar-root": {
30
+ "@apply relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full": {}
31
+ },
32
+ ".aui-avatar-image": {
33
+ "@apply aspect-square h-full w-full object-cover": {}
34
+ },
35
+ ".aui-avatar-fallback": {
36
+ "@apply bg-aui-muted flex h-full w-full items-center justify-center rounded-full": {}
37
+ },
38
+ ".aui-tooltip-content": {
39
+ "@apply bg-aui-popover text-aui-popover-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 overflow-hidden rounded-md border px-3 py-1.5 text-sm shadow-md": {}
40
+ },
41
+ ".aui-dialog-overlay": {
42
+ "@apply data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80": {}
43
+ },
44
+ ".aui-dialog-content": {
45
+ "@apply data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed left-[50%] top-[50%] z-50": {},
46
+ "@apply grid translate-x-[-50%] translate-y-[-50%] shadow-lg duration-200": {}
47
+ }
48
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ ":root": {
3
+ "--aui-background": "0 0% 100%",
4
+ "--aui-foreground": "240 10% 3.9%",
5
+ "--aui-card": "0 0% 100%",
6
+ "--aui-card-foreground": "240 10% 3.9%",
7
+ "--aui-popover": "0 0% 100%",
8
+ "--aui-popover-foreground": "240 10% 3.9%",
9
+ "--aui-primary": "240 5.9% 10%",
10
+ "--aui-primary-foreground": "0 0% 98%",
11
+ "--aui-secondary": "240 4.8% 95.9%",
12
+ "--aui-secondary-foreground": "240 5.9% 10%",
13
+ "--aui-muted": "240 4.8% 95.9%",
14
+ "--aui-muted-foreground": "240 3.8% 46.1%",
15
+ "--aui-accent": "240 4.8% 95.9%",
16
+ "--aui-accent-foreground": "240 5.9% 10%",
17
+ "--aui-destructive": "0 84.2% 60.2%",
18
+ "--aui-destructive-foreground": "0 0% 98%",
19
+ "--aui-border": "240 5.9% 90%",
20
+ "--aui-input": "240 5.9% 90%",
21
+ "--aui-ring": "240 10% 3.9%",
22
+ "--aui-radius": "0.5rem"
23
+ },
24
+ ".dark": {
25
+ "--aui-background": "0 0% 7%",
26
+ "--aui-foreground": "0 0% 98%",
27
+ "--aui-card": "240 10% 3.9%",
28
+ "--aui-card-foreground": "0 0% 98%",
29
+ "--aui-popover": "240 10% 3.9%",
30
+ "--aui-popover-foreground": "0 0% 98%",
31
+ "--aui-primary": "0 0% 98%",
32
+ "--aui-primary-foreground": "240 5.9% 10%",
33
+ "--aui-secondary": "240 3.7% 15.9%",
34
+ "--aui-secondary-foreground": "0 0% 98%",
35
+ "--aui-muted": "240 3.7% 15.9%",
36
+ "--aui-muted-foreground": "240 5% 64.9%",
37
+ "--aui-accent": "240 3.7% 15.9%",
38
+ "--aui-accent-foreground": "0 0% 98%",
39
+ "--aui-destructive": "0 62.8% 30.6%",
40
+ "--aui-destructive-foreground": "0 0% 98%",
41
+ "--aui-border": "240 3.7% 15.9%",
42
+ "--aui-input": "240 3.7% 15.9%",
43
+ "--aui-ring": "240 4.9% 83.9%"
44
+ }
45
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ ".aui-modal-content": {
3
+ "@apply bg-aui-popover text-aui-popover-foreground z-50 h-[500px] w-[400px] overflow-clip rounded-xl border p-0 shadow-md outline-none": {},
4
+ "@apply [&>.aui-thread-root]:bg-inherit": {},
5
+ "@apply data-[state=closed]:animate-out data-[state=open]:animate-in": {},
6
+ "@apply data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0": {},
7
+ "@apply data-[state=closed]:zoom-out data-[state=open]:zoom-in": {},
8
+ "@apply data-[state=open]:slide-in-from-bottom-1/2 data-[state=open]:slide-in-from-right-1/2 data-[state=closed]:slide-out-to-bottom-1/2 data-[state=closed]:slide-out-to-right-1/2": {}
9
+ },
10
+ ".aui-modal-anchor": {
11
+ "@apply fixed bottom-4 right-4 size-11": {}
12
+ },
13
+ ".aui-modal-button": {
14
+ "@apply size-full rounded-full shadow transition-transform hover:scale-110 active:scale-90": {}
15
+ },
16
+ ".aui-modal-button-closed-icon": {
17
+ "@apply absolute size-6 transition-all": {},
18
+ "@apply data-[state=closed]:rotate-0 data-[state=open]:rotate-90": {},
19
+ "@apply data-[state=closed]:scale-100 data-[state=open]:scale-0": {}
20
+ },
21
+ ".aui-modal-button-open-icon": {
22
+ "@apply absolute size-6 transition-all": {},
23
+ "@apply data-[state=closed]:-rotate-90 data-[state=open]:rotate-0": {},
24
+ "@apply data-[state=closed]:scale-0 data-[state=open]:scale-100": {}
25
+ }
26
+ }
@@ -0,0 +1,153 @@
1
+ {
2
+ ".aui-thread-root": {
3
+ "@apply bg-aui-background box-border h-full": {},
4
+ "@apply [&>.aui-thread-viewport]:bg-inherit": {}
5
+ },
6
+ ".aui-thread-viewport": {
7
+ "@apply bg-aui-background flex h-full flex-col items-center overflow-y-scroll scroll-smooth px-4 pt-8": {}
8
+ },
9
+ ".aui-thread-viewport-footer": {
10
+ "@apply sticky bottom-0 mt-3 flex w-full max-w-2xl flex-col items-center justify-end rounded-t-lg bg-inherit pb-4": {}
11
+ },
12
+ ".aui-thread-scroll-to-bottom": {
13
+ "@apply absolute -top-8 rounded-full disabled:invisible": {}
14
+ },
15
+ ".aui-thread-followup-suggestions": {
16
+ "@apply flex min-h-8 items-center justify-center gap-2": {}
17
+ },
18
+ ".aui-thread-followup-suggestion": {
19
+ "@apply bg-aui-background hover:bg-aui-muted/80 rounded-full border px-3 py-1 text-sm transition-colors ease-in": {}
20
+ },
21
+ ".aui-thread-welcome-root": {
22
+ "@apply flex w-full max-w-2xl flex-grow flex-col": {}
23
+ },
24
+ ".aui-thread-welcome-center": {
25
+ "@apply flex w-full flex-grow flex-col items-center justify-center": {}
26
+ },
27
+ ".aui-thread-welcome-message": {
28
+ "@apply mt-4 font-medium": {}
29
+ },
30
+ ".aui-thread-welcome-suggestion-container": {
31
+ "@apply mt-3 flex w-full items-stretch justify-center gap-4": {}
32
+ },
33
+ ".aui-thread-welcome-suggestion": {
34
+ "@apply hover:bg-aui-muted/80 flex max-w-sm grow basis-0 flex-col items-center justify-center rounded-lg border p-3 transition-colors ease-in": {}
35
+ },
36
+ ".aui-thread-welcome-suggestion-text": {
37
+ "@apply line-clamp-2 text-ellipsis text-sm font-semibold": {}
38
+ },
39
+ ".aui-composer-root": {
40
+ "@apply focus-within:border-aui-ring/20 flex w-full flex-wrap items-end rounded-lg border bg-inherit px-2.5 shadow-sm transition-colors ease-in": {}
41
+ },
42
+ ".aui-composer-input": {
43
+ "@apply placeholder:text-aui-muted-foreground max-h-40 flex-grow resize-none border-none bg-transparent px-2 py-4 text-sm outline-none focus:ring-0 disabled:cursor-not-allowed": {}
44
+ },
45
+ ".aui-composer-send,\n.aui-composer-cancel,\n.aui-composer-attach": {
46
+ "@apply my-2.5 size-8 p-2 transition-opacity ease-in": {}
47
+ },
48
+ ".aui-composer-attachments": {
49
+ "@apply flex w-full flex-row gap-3 px-10": {}
50
+ },
51
+ ".aui-attachment-root": {
52
+ "@apply relative mt-3 flex h-12 w-40 items-center justify-center gap-2 rounded-lg border p-1": {}
53
+ },
54
+ ".aui-attachment-preview-trigger": {
55
+ "@apply hover:bg-aui-accent/50 cursor-pointer transition-colors": {}
56
+ },
57
+ ".aui-attachment-thumb": {
58
+ "@apply bg-aui-muted flex size-10 items-center justify-center rounded border text-sm": {}
59
+ },
60
+ ".aui-attachment-text": {
61
+ "@apply flex-grow basis-0": {}
62
+ },
63
+ ".aui-attachment-name": {
64
+ "@apply text-aui-muted-foreground line-clamp-1 text-ellipsis text-xs font-bold": {}
65
+ },
66
+ ".aui-attachment-type": {
67
+ "@apply text-aui-muted-foreground text-xs": {}
68
+ },
69
+ ".aui-attachment-remove": {
70
+ "@apply text-aui-muted-foreground [&>svg]:bg-aui-background absolute -right-3 -top-3 size-6 [&>svg]:size-4 [&>svg]:rounded-full": {}
71
+ },
72
+ ".aui-user-message-root": {
73
+ "@apply grid auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] gap-y-2 [&>*]:col-start-2": {},
74
+ "@apply w-full max-w-2xl py-4": {}
75
+ },
76
+ ":where(.aui-user-message-root) > .aui-user-action-bar-root": {
77
+ "@apply col-start-1 row-start-2 mr-3 mt-2.5": {}
78
+ },
79
+ ":where(.aui-user-message-root) > .aui-user-message-attachments": {
80
+ "@apply col-span-full col-start-1 row-start-1": {},
81
+ "@apply justify-end": {}
82
+ },
83
+ ":where(.aui-user-message-root) > .aui-user-message-content": {
84
+ "@apply col-start-2 row-start-2": {}
85
+ },
86
+ ":where(.aui-user-message-root) > .aui-branch-picker-root": {
87
+ "@apply col-span-full col-start-1 row-start-3": {},
88
+ "@apply -mr-1 justify-end": {}
89
+ },
90
+ ".aui-user-message-content": {
91
+ "@apply bg-aui-muted text-aui-foreground max-w-xl break-words rounded-3xl px-5 py-2.5": {}
92
+ },
93
+ ".aui-user-message-attachments": {
94
+ "@apply flex w-full flex-row gap-3": {}
95
+ },
96
+ ".aui-user-action-bar-root": {
97
+ "@apply flex flex-col items-end": {}
98
+ },
99
+ ".aui-edit-composer-root": {
100
+ "@apply bg-aui-muted my-4 flex w-full max-w-2xl flex-col gap-2 rounded-xl": {}
101
+ },
102
+ ".aui-edit-composer-input": {
103
+ "@apply text-aui-foreground flex h-8 w-full resize-none bg-transparent p-4 pb-0 outline-none": {}
104
+ },
105
+ ".aui-edit-composer-footer": {
106
+ "@apply mx-3 mb-3 flex items-center justify-center gap-2 self-end": {}
107
+ },
108
+ ".aui-assistant-message-root": {
109
+ "@apply grid grid-cols-[auto_auto_1fr] grid-rows-[auto_1fr]": {},
110
+ "@apply relative w-full max-w-2xl py-4": {}
111
+ },
112
+ ":where(.aui-assistant-message-root) > .aui-avatar-root": {
113
+ "@apply col-start-1 row-span-full row-start-1 mr-4": {}
114
+ },
115
+ ":where(.aui-assistant-message-root) > .aui-branch-picker-root": {
116
+ "@apply col-start-2 row-start-2": {},
117
+ "@apply -ml-2 mr-2": {}
118
+ },
119
+ ":where(.aui-assistant-message-root) > .aui-assistant-action-bar-root": {
120
+ "@apply col-start-3 row-start-2": {},
121
+ "@apply -ml-1": {}
122
+ },
123
+ ":where(.aui-assistant-message-root) > .aui-assistant-message-content": {
124
+ "@apply col-span-2 col-start-2 row-start-1 my-1.5": {}
125
+ },
126
+ ".aui-assistant-message-content": {
127
+ "@apply text-aui-foreground max-w-xl break-words leading-7": {}
128
+ },
129
+ ".aui-assistant-action-bar-root": {
130
+ "@apply text-aui-muted-foreground flex gap-1": {}
131
+ },
132
+ ":where(.aui-assistant-action-bar-root)[data-floating]": {
133
+ "@apply bg-aui-background absolute rounded-md border p-1 shadow-sm": {}
134
+ },
135
+ ":where(.aui-assistant-action-bar-feedback-positive)[data-submitted]": {
136
+ "@apply text-green-600 hover:text-green-700 dark:text-green-500 dark:hover:text-green-400": {}
137
+ },
138
+ ":where(.aui-assistant-action-bar-feedback-negative)[data-submitted]": {
139
+ "@apply text-red-600 hover:text-red-700 dark:text-red-500 dark:hover:text-red-400": {}
140
+ },
141
+ ".aui-branch-picker-root": {
142
+ "@apply text-aui-muted-foreground inline-flex items-center text-xs": {}
143
+ },
144
+ ".aui-branch-picker-state": {
145
+ "@apply font-medium": {}
146
+ },
147
+ ".aui-text": {
148
+ "@apply whitespace-pre-line": {}
149
+ },
150
+ ".aui-text-running::after": {
151
+ "@apply animate-pulse font-sans content-['\\25CF'] ltr:ml-1 rtl:mr-1": {}
152
+ }
153
+ }
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.5.93",
32
+ "version": "0.5.95",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -57,6 +57,7 @@
57
57
  "types": "./dist/index.d.ts",
58
58
  "files": [
59
59
  "dist",
60
+ "generated",
60
61
  "edge",
61
62
  "tailwindcss",
62
63
  "src",
@@ -134,7 +135,7 @@
134
135
  "url": "https://github.com/Yonom/assistant-ui/issues"
135
136
  },
136
137
  "scripts": {
137
- "build": "tsx scripts/build.mts && pnpm run build:declarations",
138
+ "build": "tsx scripts/build.mts && pnpm build:declarations",
138
139
  "build:declarations": "tsc -p tsconfig.declarations.json"
139
140
  }
140
141
  }
@@ -45,25 +45,17 @@ export const toContentPartStatus = (
45
45
  ): ToolCallContentPartStatus => {
46
46
  if (message.role !== "assistant") return COMPLETE_STATUS;
47
47
 
48
- const isLastPart = partIndex === Math.max(0, message.content.length - 1);
49
- if (part.type !== "tool-call") {
50
- if (
51
- "reason" in message.status &&
52
- message.status.reason === "tool-calls" &&
53
- isLastPart
54
- )
55
- throw new Error(
56
- "Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui.",
57
- );
58
-
59
- return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;
60
- }
61
-
62
- if (!!part.result) {
63
- return COMPLETE_STATUS;
48
+ if (part.type === "tool-call") {
49
+ if (!part.result) {
50
+ return message.status as ToolCallContentPartStatus;
51
+ } else {
52
+ return COMPLETE_STATUS;
53
+ }
64
54
  }
65
55
 
66
- return message.status as ToolCallContentPartStatus;
56
+ const isLastPart = partIndex === Math.max(0, message.content.length - 1);
57
+ if (message.status.type === "requires-action") return COMPLETE_STATUS;
58
+ return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;
67
59
  };
68
60
 
69
61
  export const EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });