@assistant-ui/core 0.3.10 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -5
- package/dist/internal.js +5 -4
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +17 -10
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +15 -2
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +2 -3
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +2 -16
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/internal.d.ts +4 -4
- package/dist/runtime/internal.js +4 -4
- package/dist/store/clients/external-thread.d.ts +54 -0
- package/dist/store/clients/external-thread.d.ts.map +1 -0
- package/dist/store/clients/external-thread.js +1354 -0
- package/dist/store/clients/external-thread.js.map +1 -0
- package/dist/store/clients/single-thread-list.d.ts +9 -0
- package/dist/store/clients/single-thread-list.d.ts.map +1 -0
- package/dist/store/clients/single-thread-list.js +171 -0
- package/dist/store/clients/single-thread-list.js.map +1 -0
- package/dist/store/index.d.ts +3 -1
- package/dist/store/index.js +3 -1
- package/dist/types/augmentations.d.ts +33 -0
- package/dist/types/augmentations.d.ts.map +1 -0
- package/dist/types/augmentations.js +0 -0
- package/dist/utils/normalizePartStatus.d.ts +3 -2
- package/dist/utils/normalizePartStatus.d.ts.map +1 -1
- package/dist/utils/normalizePartStatus.js +15 -1
- package/dist/utils/normalizePartStatus.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +6 -0
- package/src/internal.ts +1 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +49 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +11 -2
- package/src/react/runtimes/external-message-converter.test.ts +71 -0
- package/src/react/runtimes/external-message-converter.test.tsx +9 -0
- package/src/react/runtimes/external-message-converter.ts +35 -2
- package/src/runtime/api/message-runtime.test.ts +1 -1
- package/src/runtime/api/message-runtime.ts +2 -35
- package/src/store/clients/external-thread.ts +1152 -0
- package/src/store/clients/single-thread-list.ts +115 -0
- package/src/store/index.ts +6 -0
- package/src/tests/external-thread-attachments.test.tsx +370 -0
- package/src/tests/external-thread-branches.test.tsx +157 -0
- package/src/tests/external-thread-feedback.test.tsx +204 -0
- package/src/tests/external-thread-parity.test.tsx +494 -0
- package/src/tests/external-thread-speech.test.tsx +328 -0
- package/src/types/augmentations.ts +33 -0
- package/src/utils/normalizePartStatus.ts +27 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","COMPLETE_STATUS","normalizePartStatus","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","toMessagePartStatus","message","partIndex","part","role","type","result","undefined","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","Object","freeze","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport {\n COMPLETE_STATUS,\n normalizePartStatus,\n} from \"../../utils/normalizePartStatus\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (part.result === undefined) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n if (message.status.type === \"running\") {\n const status = normalizePartStatus(part);\n if (status) return status;\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 MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status: status as MessagePartStatus,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): 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 getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\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 private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\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 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 (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 getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { 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 getMessagePartState(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}.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 source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;AAsCA,MAAa0B,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOrB;CAEzC,IAAIoB,KAAKE,SAAS,aAAa;EAC7B,IAAIF,KAAKG,WAAWC,KAAAA,GAClB,OAAON,QAAQO;OAEf,OAAOzB;CAEX;CAEA,IAAIkB,QAAQO,OAAOH,SAAS,WAAW;EACrC,MAAMG,SAASxB,oBAAoBmB,IAAI;EACvC,IAAIK,QAAQ,OAAOA;CACrB;CAEA,MAAMC,aAAaP,cAAcQ,KAAKC,IAAI,GAAGV,QAAQW,QAAQC,SAAS,CAAC;CACvE,IAAIZ,QAAQO,OAAOH,SAAS,mBAAmB,OAAOtB;CACtD,OAAO0B,aAAcR,QAAQO,SAA+BzB;AAC9D;AAEA,MAAM+B,uBACJb,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQW,QAAQV;CAC7B,IAAI,CAACC,MACH,OAAOhB;CAIT,MAAMqB,SAASR,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAOa,OAAOC,OAAO;EACnB,GAAGd;GAC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,EAAC;IACtE4B,qBAAqB;KAAErE,MAAM;KAAcyC;IAAW;GACxD;GACAjB,gBAAgB;IACd,MAAMgC,QAAQ,KAAKX,MAAMrB,SAAS;IAClC,MAAMe,MAAMiB,MAAMjD,QAAQiE,WACvB1E,SACCA,KAAKE,SAAS,eAAeF,KAAK2C,eAAeA,UACrD;IACA,IAAIF,QAAQ,IAAI,OAAOzD;IACvB,OAAO2B,oBAAoB+C,OAAOjB,GAAG;GACvC;GACAH,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKC,cACP;CACF;CAEA,qBAA4BP,KAAa;EACvC,OAAO,IAAIrD,6BACT,IAAIH,sBAAsB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAE1E,MAAM;KAASc,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ThreadMessage","Unsubscribe","MessagePartStatus","RunConfig","toMessagePartStatus","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","getMessagePartState","message","MessageState","partIndex","part","content","status","Object","freeze","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","type","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","role","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type { ThreadMessage } from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { toMessagePartStatus } from \"../../utils/normalizePartStatus\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status: status as MessagePartStatus,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): 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 getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\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 private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\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 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 (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 getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { 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 getMessagePartState(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}.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 source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;AA8BA,MAAMsB,uBACJC,SACAE,cACmC;CACnC,MAAMC,OAAOH,QAAQI,QAAQF;CAC7B,IAAI,CAACC,MACH,OAAOjB;CAIT,MAAMmB,SAAStB,oBAAoBiB,SAASE,WAAWC,IAAI;CAC3D,OAAOG,OAAOC,OAAO;EACnB,GAAGJ;GACGzB,qBAAsByB,KAAazB;EACjC2B;CACV,CAAC;AACH;AAyDA,IAAamC,qBAAb,MAA0D;CACxD,IAAWvB,OAAO;EAChB,OAAO,KAAKwB,MAAMxB;CACpB;CAEA;CACA;CAEA0B,YACEF,OACAC,gBACA;EACA,KAAKD,QAAQA;EACb,KAAKC,iBAAiBA;EACtB,KAAKxB,WAAW,IAAI1B,wBAClB,IAAIP,0BAA0B;GAC5BgC,MAAM;IACJ,GAAG,KAAKA;IACR2B,KAAK,GAAG,KAAK3B,KAAK2B,IAAG;IACrBC,gBAAgB;GAClB;GACA1B,UAAU,KAAK2B;GACfd,YAAYC,aAAa,KAAKS,eAAeV,UAAUC,QAAQ;EACjE,CAAC,SACK,KAAKS,eAAevB,SAAS,CAAC,CAAC4B,UAAU,KAAKN,MAAMtB,SAAS,CAAC,CAAC6B,EAAE,CACzE;EAEA,KAAKC,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAK3B,SAAS,KAAKA,OAAO4B,KAAK,IAAI;EACnC,KAAK9B,SAAS,KAAKA,OAAO8B,KAAK,IAAI;EACnC,KAAK/B,WAAW,KAAKA,SAAS+B,KAAK,IAAI;EACvC,KAAKlB,YAAY,KAAKA,UAAUkB,KAAK,I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V;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { fromThreadMessageLike } from "./utils/thread-message-like.js";
|
|
2
2
|
import { ExportedMessageRepository, ExportedMessageRepositoryItem, MessageRepository } from "./utils/message-repository.js";
|
|
3
3
|
import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, MessageStateBinding, ThreadComposerRuntimeCoreBinding } from "./api/bindings.js";
|
|
4
|
-
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
5
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
6
|
-
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
7
|
-
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
8
4
|
import { BaseAssistantRuntimeCore } from "./base/base-assistant-runtime-core.js";
|
|
9
5
|
import { BaseComposerRuntimeCore } from "./base/base-composer-runtime-core.js";
|
|
10
6
|
import { DefaultThreadComposerRuntimeCore } from "./base/default-thread-composer-runtime-core.js";
|
|
@@ -12,6 +8,10 @@ import { DefaultEditComposerRuntimeCore } from "./base/default-edit-composer-run
|
|
|
12
8
|
import { BaseThreadRuntimeCore } from "./base/base-thread-runtime-core.js";
|
|
13
9
|
import { ThreadListItemRuntimeImpl, ThreadListItemStateBinding } from "./api/thread-list-item-runtime.js";
|
|
14
10
|
import { ThreadListRuntimeCoreBinding, ThreadListRuntimeImpl } from "./api/thread-list-runtime.js";
|
|
11
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
12
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
13
|
+
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
14
|
+
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
15
15
|
import { symbolInnerMessage } from "./utils/external-store-message.js";
|
|
16
16
|
import { getAutoStatus, isAutoStatus } from "./utils/auto-status.js";
|
|
17
17
|
import { ThreadListItemRuntimeBinding, ThreadRuntimeCoreBinding, ThreadRuntimeImpl, getThreadState } from "./api/thread-runtime.js";
|
package/dist/runtime/internal.js
CHANGED
|
@@ -2,16 +2,16 @@ import { fromThreadMessageLike } from "./utils/thread-message-like.js";
|
|
|
2
2
|
import { symbolInnerMessage } from "./utils/external-store-message.js";
|
|
3
3
|
import { getAutoStatus, isAutoStatus } from "./utils/auto-status.js";
|
|
4
4
|
import { ExportedMessageRepository, MessageRepository } from "./utils/message-repository.js";
|
|
5
|
-
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
6
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
7
|
-
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
8
|
-
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
9
5
|
import { BaseAssistantRuntimeCore } from "./base/base-assistant-runtime-core.js";
|
|
10
6
|
import { BaseComposerRuntimeCore } from "./base/base-composer-runtime-core.js";
|
|
11
7
|
import { DefaultThreadComposerRuntimeCore } from "./base/default-thread-composer-runtime-core.js";
|
|
12
8
|
import { DefaultEditComposerRuntimeCore } from "./base/default-edit-composer-runtime-core.js";
|
|
13
9
|
import { BaseThreadRuntimeCore } from "./base/base-thread-runtime-core.js";
|
|
14
10
|
import { ThreadListItemRuntimeImpl } from "./api/thread-list-item-runtime.js";
|
|
11
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
12
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
13
|
+
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
14
|
+
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
15
15
|
import { ThreadRuntimeImpl, getThreadState } from "./api/thread-runtime.js";
|
|
16
16
|
import { ThreadListRuntimeImpl } from "./api/thread-list-runtime.js";
|
|
17
17
|
import { AssistantRuntimeImpl } from "./api/assistant-runtime.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AppendMessage, ThreadMessage } from "../../types/message.js";
|
|
2
|
+
import { AttachmentAdapter } from "../../adapters/attachment.js";
|
|
3
|
+
import { FeedbackAdapter } from "../../adapters/feedback.js";
|
|
4
|
+
import { SpeechSynthesisAdapter } from "../../adapters/speech.js";
|
|
5
|
+
import { ExternalThreadQueueAdapter } from "../../runtime/queue/external-thread-queue-adapter.js";
|
|
6
|
+
import { AddToolResultOptions, RespondToToolApprovalOptions, ResumeToolCallOptions } from "../../runtime/interfaces/thread-runtime-core.js";
|
|
7
|
+
import { ExternalThreadBranchAdapter } from "../../runtime/branch/external-thread-branch-adapter.js";
|
|
8
|
+
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
9
|
+
import { ClientOutput } from "@assistant-ui/store";
|
|
10
|
+
//#region src/store/clients/external-thread.d.ts
|
|
11
|
+
type ExternalThreadMessage = ThreadMessage & {
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
type ExternalThreadProps = {
|
|
15
|
+
messages: readonly ExternalThreadMessage[];
|
|
16
|
+
isRunning?: boolean;
|
|
17
|
+
isLoading?: boolean | undefined;
|
|
18
|
+
state?: ReadonlyJSONValue | undefined;
|
|
19
|
+
extras?: unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Whether sending new messages is currently disabled. When `true`, the
|
|
22
|
+
* thread composer's input remains usable but `send()` is a no-op and
|
|
23
|
+
* `composer.canSend` is `false`. Edit composers (saving message edits)
|
|
24
|
+
* intentionally ignore this flag.
|
|
25
|
+
*/
|
|
26
|
+
isSendDisabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Callback for new messages (non-queue runtimes).
|
|
29
|
+
* @note Unused when `queue` is provided — new messages are routed through `queue.enqueue` instead.
|
|
30
|
+
*/
|
|
31
|
+
onNew?: (message: AppendMessage) => void;
|
|
32
|
+
onEdit?: (message: AppendMessage) => void;
|
|
33
|
+
onReload?: (parentId: string | null) => void;
|
|
34
|
+
onStartRun?: () => void;
|
|
35
|
+
onCancel?: () => void;
|
|
36
|
+
onResume?: (() => void) | undefined;
|
|
37
|
+
onAddToolResult?: ((options: AddToolResultOptions) => void) | undefined;
|
|
38
|
+
/** Callback for resuming a tool call that is waiting for human input. */
|
|
39
|
+
onResumeToolCall?: ((options: ResumeToolCallOptions) => void) | undefined;
|
|
40
|
+
onLoadExternalState?: ((state: unknown) => void) | undefined;
|
|
41
|
+
attachmentAdapter?: AttachmentAdapter | undefined;
|
|
42
|
+
feedbackAdapter?: FeedbackAdapter | undefined;
|
|
43
|
+
speechAdapter?: SpeechSynthesisAdapter | undefined;
|
|
44
|
+
/** Queue adapter for runtimes that support message queuing and steering. */
|
|
45
|
+
queue?: ExternalThreadQueueAdapter;
|
|
46
|
+
/** Branch adapter for runtimes that track sibling variants of messages. */
|
|
47
|
+
branches?: ExternalThreadBranchAdapter;
|
|
48
|
+
/** Callback for tool approval decisions. Absent: responding to an approval throws a capability error. */
|
|
49
|
+
onRespondToToolApproval?: (options: RespondToToolApprovalOptions) => void;
|
|
50
|
+
};
|
|
51
|
+
declare const ExternalThread: import("@assistant-ui/tap").Resource<ClientOutput<"thread">, [ExternalThreadProps]>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ExternalThread, ExternalThreadMessage, ExternalThreadProps };
|
|
54
|
+
//# sourceMappingURL=external-thread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-thread.d.ts","names":[],"sources":["../../../src/store/clients/external-thread.ts"],"mappings":";;;;;;;;;;KAuDY,wBAAwB;EAClC;;KAgBU;EACV,mBAAmB;EACnB;EACA;EACA,QAAQ;EACR;;;;;;;EAOA;;;;;EAKA,SAAS,SAAS;EAClB,UAAU,SAAS;EACnB,YAAY;EACZ;EACA;EACA;EACA,oBAAoB,SAAS;;EAE7B,qBAAqB,SAAS;EAC9B,wBAAwB;EACxB,oBAAoB;EACpB,kBAAkB;EAClB,gBAAgB;;EAEhB,QAAQ;;EAER,WAAW;;EAEX,2BAA2B,SAAS;;cA2+BzB,4CAAc,SAAA,yBAAA"}
|