@assistant-ui/react 0.8.4 → 0.8.6
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/api/MessageRuntime.js +1 -1
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/MessageRuntime.mjs +1 -1
- package/dist/api/MessageRuntime.mjs.map +1 -1
- package/dist/api/subscribable/NestedSubscriptionSubject.d.ts.map +1 -1
- package/dist/api/subscribable/NestedSubscriptionSubject.js.map +1 -1
- package/dist/api/subscribable/NestedSubscriptionSubject.mjs.map +1 -1
- package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +1 -1
- package/dist/context/react/utils/createStateHookForRuntime.js.map +1 -1
- package/dist/context/react/utils/createStateHookForRuntime.mjs.map +1 -1
- package/dist/context/react/utils/ensureBinding.js.map +1 -1
- package/dist/context/react/utils/ensureBinding.mjs.map +1 -1
- package/dist/model-context/makeAssistantVisible.d.ts.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +2 -1
- package/dist/model-context/makeAssistantVisible.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.mjs +2 -1
- package/dist/model-context/makeAssistantVisible.mjs.map +1 -1
- package/dist/model-context/useAssistantInstructions.js +1 -1
- package/dist/model-context/useAssistantInstructions.js.map +1 -1
- package/dist/model-context/useAssistantInstructions.mjs +1 -1
- package/dist/model-context/useAssistantInstructions.mjs.map +1 -1
- package/dist/model-context/useAssistantToolUI.js +1 -1
- package/dist/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/model-context/useAssistantToolUI.mjs +1 -1
- package/dist/model-context/useAssistantToolUI.mjs.map +1 -1
- package/dist/model-context/useInlineRender.d.ts.map +1 -1
- package/dist/model-context/useInlineRender.js +8 -5
- package/dist/model-context/useInlineRender.js.map +1 -1
- package/dist/model-context/useInlineRender.mjs +8 -5
- package/dist/model-context/useInlineRender.mjs.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.d.ts.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js +6 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.mjs +6 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.mjs.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +7 -2
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.mjs +7 -2
- package/dist/primitives/composer/ComposerInput.mjs.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.mjs +4 -1
- package/dist/primitives/thread/ThreadScrollToBottom.mjs.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +1 -0
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.mjs +1 -0
- package/dist/primitives/thread/ThreadViewport.mjs.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.mjs +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.mjs.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js +3 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +3 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts +7 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js +2 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs +2 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.d.ts.map +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.js.map +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.mjs.map +1 -1
- package/dist/runtimes/external-store/external-message-converter.js +1 -1
- package/dist/runtimes/external-store/external-message-converter.js.map +1 -1
- package/dist/runtimes/external-store/external-message-converter.mjs +1 -1
- package/dist/runtimes/external-store/external-message-converter.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +3 -1
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +3 -1
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.js +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.mjs +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/MessageRuntime.ts +1 -1
- package/src/api/subscribable/NestedSubscriptionSubject.ts +7 -2
- package/src/context/react/utils/createStateHookForRuntime.ts +3 -0
- package/src/context/react/utils/ensureBinding.ts +1 -1
- package/src/model-context/makeAssistantVisible.tsx +3 -1
- package/src/model-context/useAssistantInstructions.tsx +1 -1
- package/src/model-context/useAssistantToolUI.tsx +1 -1
- package/src/model-context/useInlineRender.tsx +8 -5
- package/src/primitives/assistantModal/AssistantModalRoot.tsx +6 -1
- package/src/primitives/composer/ComposerInput.tsx +7 -2
- package/src/primitives/thread/ThreadScrollToBottom.tsx +4 -1
- package/src/primitives/thread/ThreadViewport.tsx +3 -0
- package/src/primitives/thread/useThreadViewportAutoScroll.tsx +1 -1
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +3 -1
- package/src/runtimes/edge/EdgeChatAdapter.ts +14 -2
- package/src/runtimes/edge/createEdgeRuntimeAPI.ts +9 -4
- package/src/runtimes/external-store/external-message-converter.tsx +1 -1
- package/src/runtimes/local/useLocalRuntime.tsx +3 -1
- package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +1 -1
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +1 -1
- package/src/runtimes/remote-thread-list/adapter/cloud.tsx +1 -1
@@ -49,7 +49,7 @@ var toContentPartStatus = (message, partIndex, part) => {
|
|
49
49
|
return isLastPart ? message.status : COMPLETE_STATUS;
|
50
50
|
};
|
51
51
|
var getContentPartState = (message, partIndex) => {
|
52
|
-
|
52
|
+
const part = message.content[partIndex];
|
53
53
|
if (!part) {
|
54
54
|
return import_SKIP_UPDATE.SKIP_UPDATE;
|
55
55
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\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 = Object.freeze({\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\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n let part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\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 readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\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 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 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: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.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 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 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 source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\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AAAA,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,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 { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\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 = Object.freeze({\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\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\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 readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\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 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 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: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.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 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 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 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;AAIA,qCAAmC;AAYnC,kCAAqC;AACrC,+BAIO;AACP,6BAGO;AACP,gCAIO;AAGP,uCAA0C;AAC1C,yBAA4B;AAC5B,mCAAsC;AAGtC,IAAM,kBAAqC,OAAO,OAAO;AAAA,EACvD,MAAM;AACR,CAAC;AAEM,IAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,MAAI,KAAK,SAAS,aAAa;AAC7B,QAAI,CAA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cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
@@ -30,7 +30,7 @@ var toContentPartStatus = (message, partIndex, part) => {
|
|
30
30
|
return isLastPart ? message.status : COMPLETE_STATUS;
|
31
31
|
};
|
32
32
|
var getContentPartState = (message, partIndex) => {
|
33
|
-
|
33
|
+
const part = message.content[partIndex];
|
34
34
|
if (!part) {
|
35
35
|
return SKIP_UPDATE;
|
36
36
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\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 = Object.freeze({\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\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n let part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\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 readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\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 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 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: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.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 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 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 source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";AAIA,SAAS,0BAA0B;AAYnC,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,IAAM,kBAAqC,OAAO,OAAO;AAAA,EACvD,MAAM;AACR,CAAC;AAEM,IAAM,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;A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AU,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 { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\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 = Object.freeze({\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\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\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 readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\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 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 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: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.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 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 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 source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";AAIA,SAAS,0BAA0B;AAYnC,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,IAAM,kBAAqC,OAAO,OAAO;AAAA,EACvD,MAAM;AACR,CAAC;AAEM,IAAM,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;AAEA,IAAM,sBAAsB,CAC1B,SACA,cACmC;AACnC,QAAM,OAAO,QAAQ,QAAQ,SAAS;AACtC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAGA,QAAM,SAAS,oBAAoB,SAAS,WAAW,IAAI;AAC3D,SAAO,OAAO,OAAO;AAAA,IACnB,GAAG;AAAA,IACH,GAAG,EAAE,CAAC,kBAAkB,GAAI,KAAa,kBAAkB,EAAE;AAAA,IAC7D;AAAA,EACF,CAAC;AACH;AA0DO,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AM,QAAQ,KAAK,MAAM,SAAS;AAClC,gBAAM,MAAM,MAAM,QAAQ;AAAA,YACxB,CAAC,SACC,KAAK,SAAS,eAAe,KAAK,eAAe;AAAA,UACrD;AACA,cAAI,QAAQ,GAAI,QAAO;AACvB,iBAAO,oBAAoB,OAAO,GAAG;AAAA,QACvC;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,qBAAqB,KAAa;AACvC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;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,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"NestedSubscriptionSubject.d.ts","sourceRoot":"","sources":["../../../src/api/subscribable/NestedSubscriptionSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,qBAAa,yBAAyB,
|
1
|
+
{"version":3,"file":"NestedSubscriptionSubject.d.ts","sourceRoot":"","sources":["../../../src/api/subscribable/NestedSubscriptionSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,qBAAa,yBAAyB,CAClC,MAAM,SAAS,YAAY,GAAG,SAAS,EACvC,KAAK,CAEP,SAAQ,WACR,YACE,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAAC,EACpC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC;IAMvB,OAAO,CAAC,OAAO;IAJ3B,IAAW,IAAI,UAEd;gBAEmB,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC;IAIvD,QAAQ;IAIR,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI;IAI1C,SAAS,CAAC,QAAQ,IAAI,WAAW;CAwBlC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/api/subscribable/NestedSubscriptionSubject.ts"],"sourcesContent":["import { Unsubscribe } from \"../../types\";\nimport { BaseSubject } from \"./BaseSubject\";\nimport {\n NestedSubscribable,\n Subscribable,\n SubscribableWithState,\n} from \"./Subscribable\";\n\nexport class NestedSubscriptionSubject
|
1
|
+
{"version":3,"sources":["../../../src/api/subscribable/NestedSubscriptionSubject.ts"],"sourcesContent":["import { Unsubscribe } from \"../../types\";\nimport { BaseSubject } from \"./BaseSubject\";\nimport {\n NestedSubscribable,\n Subscribable,\n SubscribableWithState,\n} from \"./Subscribable\";\n\nexport class NestedSubscriptionSubject<\n TState extends Subscribable | undefined,\n TPath,\n >\n extends BaseSubject\n implements\n SubscribableWithState<TState, TPath>,\n NestedSubscribable<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(private binding: NestedSubscribable<TState, TPath>) {\n super();\n }\n\n public getState() {\n return this.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = () => {\n this.notifySubscribers();\n };\n\n let lastState = this.binding.getState();\n let innerUnsubscribe = lastState?.subscribe(callback);\n const onRuntimeUpdate = () => {\n const newState = this.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = this.binding.getState()?.subscribe(callback);\n\n callback();\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA4B;AAOrB,IAAM,4BAAN,cAIG,+BAIV;AAAA,EAKE,YAAoB,SAA4C;AAC9D,UAAM;AADY;AAAA,EAEpB;AAAA,EANA,IAAW,OAAO;AAChB,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA,EAMO,WAAW;AAChB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC/B;AAAA,EAEO,eAAe,UAAsB;AAC1C,WAAO,KAAK,QAAQ,UAAU,QAAQ;AAAA,EACxC;AAAA,EAEU,WAAwB;AAChC,UAAM,WAAW,MAAM;AACrB,WAAK,kBAAkB;AAAA,IACzB;AAEA,QAAI,YAAY,KAAK,QAAQ,SAAS;AACtC,QAAI,mBAAmB,WAAW,UAAU,QAAQ;AACpD,UAAM,kBAAkB,MAAM;AAC5B,YAAM,WAAW,KAAK,QAAQ,SAAS;AACvC,UAAI,aAAa,UAAW;AAC5B,kBAAY;AAEZ,yBAAmB;AACnB,yBAAmB,KAAK,QAAQ,SAAS,GAAG,UAAU,QAAQ;AAE9D,eAAS;AAAA,IACX;AAEA,UAAM,mBAAmB,KAAK,eAAe,eAAe;AAC5D,WAAO,MAAM;AACX,yBAAmB;AACnB,yBAAmB;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/api/subscribable/NestedSubscriptionSubject.ts"],"sourcesContent":["import { Unsubscribe } from \"../../types\";\nimport { BaseSubject } from \"./BaseSubject\";\nimport {\n NestedSubscribable,\n Subscribable,\n SubscribableWithState,\n} from \"./Subscribable\";\n\nexport class NestedSubscriptionSubject
|
1
|
+
{"version":3,"sources":["../../../src/api/subscribable/NestedSubscriptionSubject.ts"],"sourcesContent":["import { Unsubscribe } from \"../../types\";\nimport { BaseSubject } from \"./BaseSubject\";\nimport {\n NestedSubscribable,\n Subscribable,\n SubscribableWithState,\n} from \"./Subscribable\";\n\nexport class NestedSubscriptionSubject<\n TState extends Subscribable | undefined,\n TPath,\n >\n extends BaseSubject\n implements\n SubscribableWithState<TState, TPath>,\n NestedSubscribable<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(private binding: NestedSubscribable<TState, TPath>) {\n super();\n }\n\n public getState() {\n return this.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = () => {\n this.notifySubscribers();\n };\n\n let lastState = this.binding.getState();\n let innerUnsubscribe = lastState?.subscribe(callback);\n const onRuntimeUpdate = () => {\n const newState = this.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = this.binding.getState()?.subscribe(callback);\n\n callback();\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n"],"mappings":";AACA,SAAS,mBAAmB;AAOrB,IAAM,4BAAN,cAIG,YAIV;AAAA,EAKE,YAAoB,SAA4C;AAC9D,UAAM;AADY;AAAA,EAEpB;AAAA,EANA,IAAW,OAAO;AAChB,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA,EAMO,WAAW;AAChB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC/B;AAAA,EAEO,eAAe,UAAsB;AAC1C,WAAO,KAAK,QAAQ,UAAU,QAAQ;AAAA,EACxC;AAAA,EAEU,WAAwB;AAChC,UAAM,WAAW,MAAM;AACrB,WAAK,kBAAkB;AAAA,IACzB;AAEA,QAAI,YAAY,KAAK,QAAQ,SAAS;AACtC,QAAI,mBAAmB,WAAW,UAAU,QAAQ;AACpD,UAAM,kBAAkB,MAAM;AAC5B,YAAM,WAAW,KAAK,QAAQ,SAAS;AACvC,UAAI,aAAa,UAAW;AAC5B,kBAAY;AAEZ,yBAAmB;AACnB,yBAAmB,KAAK,QAAQ,SAAS,GAAG,UAAU,QAAQ;AAE9D,eAAS;AAAA,IACX;AAEA,UAAM,mBAAmB,KAAK,eAAe,eAAe;AAC5D,WAAO,MAAM;AACX,yBAAmB;AACnB,yBAAmB;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createStateHookForRuntime.d.ts","sourceRoot":"","sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;AAE3B,wBAAgB,yBAAyB,CAAC,MAAM,EAC9C,UAAU,EAAE,CAAC,OAAO,EAAE;IACpB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B,KAAK,mBAAmB,CAAC,MAAM,CAAC,GAAG,IAAI;QAGf,MAAM;KAGT,SAAS,YACnB,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,GACrC,SAAS;KAGU,SAAS,YACnB,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAAS,GACnD,SAAS,GAAG,MAAM;cAGU;QAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;KAAE,GAAG,MAAM;cAGzC;QAC7B,QAAQ,CAAC,EAAE,OAAO,GAAG,S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AM;cAGU;QAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;KAAE,GAAG,MAAM;cAGzC;QAC7B,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAChC,GAAG,MAAM,GAAG,IAAI;KAGK,SAAS,WAAW;QACxC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;QAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;KACxC,GAAG,SAAS;KAGS,SAAS,WAAW;QACxC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;QAC7B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAAS,CAAC;KACtD,GAAG,SAAS,GAAG,MAAM;KAGA,SAAS,WAAW;QACxC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;KACxC,GAAG,SAAS,GAAG,IAAI;KAGE,SAAS,WAAW;QACxC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC/B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAAS,CAAC;KACtD,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI;EA6B9B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"sourcesContent":["import {\n SubscribableRuntime,\n useRuntimeStateInternal,\n} from \"./useRuntimeState\";\n\nexport function createStateHookForRuntime<TState>(\n useRuntime: (options: {\n optional: boolean | undefined;\n }) => SubscribableRuntime<TState> | null,\n) {\n // empty\n function useStoreHook(): TState;\n\n // selector\n function useStoreHook<TSelected>(\n selector: (state: TState) => TSelected,\n ): TSelected;\n\n // selector?\n function useStoreHook<TSelected>(\n selector: ((state: TState) => TSelected) | undefined,\n ): TSelected | TState;\n\n // optional=false\n function useStoreHook(options: { optional?: false | undefined }): TState;\n\n // optional?\n function useStoreHook(options: {\n optional?: boolean | undefined;\n }): TState | null;\n\n // optional=false, selector\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected;\n\n // optional=false, selector?\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState;\n\n // optional?, selector\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected | null;\n\n // optional?, selector?\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState | null;\n\n function useStoreHook<TSelected>(\n param?:\n | ((state: TState) => TSelected)\n | {\n optional?: boolean | undefined;\n selector?: ((state: TState) => TSelected) | undefined;\n },\n ): TSelected | TState | null {\n let optional = false;\n let selector: ((state: TState) => TSelected) | undefined;\n\n if (typeof param === \"function\") {\n selector = param;\n } else if (param) {\n optional = !!param.optional;\n selector = param.selector;\n }\n\n const store = useRuntime({ optional });\n if (!store) return null;\n return useRuntimeStateInternal(store, selector);\n }\n\n return useStoreHook;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAGO;AAEA,SAAS,0BACd,YAGA;AA8CA,WAAS,aACP,OAM2B;AAC3B,QAAI,WAAW;AACf,QAAI;AAEJ,QAAI,OAAO,UAAU,YAAY;AAC/B,iBAAW;AAAA,IACb,WAAW,OAAO;AAChB,iBAAW,CAAC,CAAC,MAAM;AACnB,iBAAW,MAAM;AAAA,IACnB;AAEA,UAAM,QAAQ,WAAW,EAAE,SAAS,CAAC;AACrC,QAAI,CAAC,MAAO,QAAO;
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"sourcesContent":["import {\n SubscribableRuntime,\n useRuntimeStateInternal,\n} from \"./useRuntimeState\";\n\nexport function createStateHookForRuntime<TState>(\n useRuntime: (options: {\n optional: boolean | undefined;\n }) => SubscribableRuntime<TState> | null,\n) {\n // empty\n function useStoreHook(): TState;\n\n // selector\n function useStoreHook<TSelected>(\n selector: (state: TState) => TSelected,\n ): TSelected;\n\n // selector?\n function useStoreHook<TSelected>(\n selector: ((state: TState) => TSelected) | undefined,\n ): TSelected | TState;\n\n // optional=false\n function useStoreHook(options: { optional?: false | undefined }): TState;\n\n // optional?\n function useStoreHook(options: {\n optional?: boolean | undefined;\n }): TState | null;\n\n // optional=false, selector\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected;\n\n // optional=false, selector?\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState;\n\n // optional?, selector\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected | null;\n\n // optional?, selector?\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState | null;\n\n function useStoreHook<TSelected>(\n param?:\n | ((state: TState) => TSelected)\n | {\n optional?: boolean | undefined;\n selector?: ((state: TState) => TSelected) | undefined;\n },\n ): TSelected | TState | null {\n let optional = false;\n let selector: ((state: TState) => TSelected) | undefined;\n\n if (typeof param === \"function\") {\n selector = param;\n } else if (param) {\n optional = !!param.optional;\n selector = param.selector;\n }\n\n const store = useRuntime({ optional });\n if (!store) return null;\n\n // it is ok to call useRuntimeStateInternal conditionally because it will never become null if its available\n // eslint-ignore-next-line react-hooks/rules-of-hooks\n return useRuntimeStateInternal(store, selector);\n }\n\n return useStoreHook;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAGO;AAEA,SAAS,0BACd,YAGA;AA8CA,WAAS,aACP,OAM2B;AAC3B,QAAI,WAAW;AACf,QAAI;AAEJ,QAAI,OAAO,UAAU,YAAY;AAC/B,iBAAW;AAAA,IACb,WAAW,OAAO;AAChB,iBAAW,CAAC,CAAC,MAAM;AACnB,iBAAW,MAAM;AAAA,IACnB;AAEA,UAAM,QAAQ,WAAW,EAAE,SAAS,CAAC;AACrC,QAAI,CAAC,MAAO,QAAO;AAInB,eAAO,gDAAwB,OAAO,QAAQ;AAAA,EAChD;AAEA,SAAO;AACT;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"sourcesContent":["import {\n SubscribableRuntime,\n useRuntimeStateInternal,\n} from \"./useRuntimeState\";\n\nexport function createStateHookForRuntime<TState>(\n useRuntime: (options: {\n optional: boolean | undefined;\n }) => SubscribableRuntime<TState> | null,\n) {\n // empty\n function useStoreHook(): TState;\n\n // selector\n function useStoreHook<TSelected>(\n selector: (state: TState) => TSelected,\n ): TSelected;\n\n // selector?\n function useStoreHook<TSelected>(\n selector: ((state: TState) => TSelected) | undefined,\n ): TSelected | TState;\n\n // optional=false\n function useStoreHook(options: { optional?: false | undefined }): TState;\n\n // optional?\n function useStoreHook(options: {\n optional?: boolean | undefined;\n }): TState | null;\n\n // optional=false, selector\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected;\n\n // optional=false, selector?\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState;\n\n // optional?, selector\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected | null;\n\n // optional?, selector?\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState | null;\n\n function useStoreHook<TSelected>(\n param?:\n | ((state: TState) => TSelected)\n | {\n optional?: boolean | undefined;\n selector?: ((state: TState) => TSelected) | undefined;\n },\n ): TSelected | TState | null {\n let optional = false;\n let selector: ((state: TState) => TSelected) | undefined;\n\n if (typeof param === \"function\") {\n selector = param;\n } else if (param) {\n optional = !!param.optional;\n selector = param.selector;\n }\n\n const store = useRuntime({ optional });\n if (!store) return null;\n return useRuntimeStateInternal(store, selector);\n }\n\n return useStoreHook;\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,OACK;AAEA,SAAS,0BACd,YAGA;AA8CA,WAAS,aACP,OAM2B;AAC3B,QAAI,WAAW;AACf,QAAI;AAEJ,QAAI,OAAO,UAAU,YAAY;AAC/B,iBAAW;AAAA,IACb,WAAW,OAAO;AAChB,iBAAW,CAAC,CAAC,MAAM;AACnB,iBAAW,MAAM;AAAA,IACnB;AAEA,UAAM,QAAQ,WAAW,EAAE,SAAS,CAAC;AACrC,QAAI,CAAC,MAAO,QAAO;
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"sourcesContent":["import {\n SubscribableRuntime,\n useRuntimeStateInternal,\n} from \"./useRuntimeState\";\n\nexport function createStateHookForRuntime<TState>(\n useRuntime: (options: {\n optional: boolean | undefined;\n }) => SubscribableRuntime<TState> | null,\n) {\n // empty\n function useStoreHook(): TState;\n\n // selector\n function useStoreHook<TSelected>(\n selector: (state: TState) => TSelected,\n ): TSelected;\n\n // selector?\n function useStoreHook<TSelected>(\n selector: ((state: TState) => TSelected) | undefined,\n ): TSelected | TState;\n\n // optional=false\n function useStoreHook(options: { optional?: false | undefined }): TState;\n\n // optional?\n function useStoreHook(options: {\n optional?: boolean | undefined;\n }): TState | null;\n\n // optional=false, selector\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected;\n\n // optional=false, selector?\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState;\n\n // optional?, selector\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected | null;\n\n // optional?, selector?\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState | null;\n\n function useStoreHook<TSelected>(\n param?:\n | ((state: TState) => TSelected)\n | {\n optional?: boolean | undefined;\n selector?: ((state: TState) => TSelected) | undefined;\n },\n ): TSelected | TState | null {\n let optional = false;\n let selector: ((state: TState) => TSelected) | undefined;\n\n if (typeof param === \"function\") {\n selector = param;\n } else if (param) {\n optional = !!param.optional;\n selector = param.selector;\n }\n\n const store = useRuntime({ optional });\n if (!store) return null;\n\n // it is ok to call useRuntimeStateInternal conditionally because it will never become null if its available\n // eslint-ignore-next-line react-hooks/rules-of-hooks\n return useRuntimeStateInternal(store, selector);\n }\n\n return useStoreHook;\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,OACK;AAEA,SAAS,0BACd,YAGA;AA8CA,WAAS,aACP,OAM2B;AAC3B,QAAI,WAAW;AACf,QAAI;AAEJ,QAAI,OAAO,UAAU,YAAY;AAC/B,iBAAW;AAAA,IACb,WAAW,OAAO;AAChB,iBAAW,CAAC,CAAC,MAAM;AACnB,iBAAW,MAAM;AAAA,IACnB;AAEA,UAAM,QAAQ,WAAW,EAAE,SAAS,CAAC;AACrC,QAAI,CAAC,MAAO,QAAO;AAInB,WAAO,wBAAwB,OAAO,QAAQ;AAAA,EAChD;AAEA,SAAO;AACT;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/ensureBinding.ts"],"sourcesContent":["type Bindable = {\n __internal_bindMethods?: () => void;\n __isBound?: boolean;\n};\nconst debugVerifyPrototype = (\n runtime: Record<string, unknown>,\n prototype: any,\n) => {\n const unboundMethods = Object.getOwnPropertyNames(prototype).filter(\n (methodStr) => {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);\n const isMethod = descriptor && typeof descriptor.value === \"function\";\n if (!isMethod) return false;\n\n const methodName = methodStr as keyof typeof runtime | \"constructor\";\n return (\n isMethod &&\n !methodName.startsWith(\"_\") &&\n methodName !== \"constructor\" &&\n prototype[methodName] === runtime[methodName]\n );\n },\n );\n\n if (unboundMethods.length > 0) {\n throw new Error(\n \"The following methods are not bound: \" + JSON.stringify(unboundMethods),\n );\n }\n\n const prototypePrototype = Object.getPrototypeOf(prototype);\n if (prototypePrototype && prototypePrototype !== Object.prototype) {\n debugVerifyPrototype(runtime, prototypePrototype);\n }\n};\nexport const ensureBinding = (r: unknown) => {\n const runtime = r as Bindable;\n if (runtime.__isBound) return;\n\n runtime.__internal_bindMethods?.();\n runtime.__isBound = true;\n\n // @ts-
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/ensureBinding.ts"],"sourcesContent":["type Bindable = {\n __internal_bindMethods?: () => void;\n __isBound?: boolean;\n};\nconst debugVerifyPrototype = (\n runtime: Record<string, unknown>,\n prototype: any,\n) => {\n const unboundMethods = Object.getOwnPropertyNames(prototype).filter(\n (methodStr) => {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);\n const isMethod = descriptor && typeof descriptor.value === \"function\";\n if (!isMethod) return false;\n\n const methodName = methodStr as keyof typeof runtime | \"constructor\";\n return (\n isMethod &&\n !methodName.startsWith(\"_\") &&\n methodName !== \"constructor\" &&\n prototype[methodName] === runtime[methodName]\n );\n },\n );\n\n if (unboundMethods.length > 0) {\n throw new Error(\n \"The following methods are not bound: \" + JSON.stringify(unboundMethods),\n );\n }\n\n const prototypePrototype = Object.getPrototypeOf(prototype);\n if (prototypePrototype && prototypePrototype !== Object.prototype) {\n debugVerifyPrototype(runtime, prototypePrototype);\n }\n};\nexport const ensureBinding = (r: unknown) => {\n const runtime = r as Bindable;\n if (runtime.__isBound) return;\n\n runtime.__internal_bindMethods?.();\n runtime.__isBound = true;\n\n // @ts-expect-error - strip this out in production build\n DEV: debugVerifyPrototype(runtime, Object.getPrototypeOf(runtime));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCO,IAAM,gBAAgB,CAAC,MAAe;AAC3C,QAAM,UAAU;AAChB,MAAI,QAAQ,UAAW;AAEvB,UAAQ,yBAAyB;AACjC,UAAQ,YAAY;AAItB;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/ensureBinding.ts"],"sourcesContent":["type Bindable = {\n __internal_bindMethods?: () => void;\n __isBound?: boolean;\n};\nconst debugVerifyPrototype = (\n runtime: Record<string, unknown>,\n prototype: any,\n) => {\n const unboundMethods = Object.getOwnPropertyNames(prototype).filter(\n (methodStr) => {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);\n const isMethod = descriptor && typeof descriptor.value === \"function\";\n if (!isMethod) return false;\n\n const methodName = methodStr as keyof typeof runtime | \"constructor\";\n return (\n isMethod &&\n !methodName.startsWith(\"_\") &&\n methodName !== \"constructor\" &&\n prototype[methodName] === runtime[methodName]\n );\n },\n );\n\n if (unboundMethods.length > 0) {\n throw new Error(\n \"The following methods are not bound: \" + JSON.stringify(unboundMethods),\n );\n }\n\n const prototypePrototype = Object.getPrototypeOf(prototype);\n if (prototypePrototype && prototypePrototype !== Object.prototype) {\n debugVerifyPrototype(runtime, prototypePrototype);\n }\n};\nexport const ensureBinding = (r: unknown) => {\n const runtime = r as Bindable;\n if (runtime.__isBound) return;\n\n runtime.__internal_bindMethods?.();\n runtime.__isBound = true;\n\n // @ts-
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/ensureBinding.ts"],"sourcesContent":["type Bindable = {\n __internal_bindMethods?: () => void;\n __isBound?: boolean;\n};\nconst debugVerifyPrototype = (\n runtime: Record<string, unknown>,\n prototype: any,\n) => {\n const unboundMethods = Object.getOwnPropertyNames(prototype).filter(\n (methodStr) => {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);\n const isMethod = descriptor && typeof descriptor.value === \"function\";\n if (!isMethod) return false;\n\n const methodName = methodStr as keyof typeof runtime | \"constructor\";\n return (\n isMethod &&\n !methodName.startsWith(\"_\") &&\n methodName !== \"constructor\" &&\n prototype[methodName] === runtime[methodName]\n );\n },\n );\n\n if (unboundMethods.length > 0) {\n throw new Error(\n \"The following methods are not bound: \" + JSON.stringify(unboundMethods),\n );\n }\n\n const prototypePrototype = Object.getPrototypeOf(prototype);\n if (prototypePrototype && prototypePrototype !== Object.prototype) {\n debugVerifyPrototype(runtime, prototypePrototype);\n }\n};\nexport const ensureBinding = (r: unknown) => {\n const runtime = r as Bindable;\n if (runtime.__isBound) return;\n\n runtime.__internal_bindMethods?.();\n runtime.__isBound = true;\n\n // @ts-expect-error - strip this out in production build\n DEV: debugVerifyPrototype(runtime, Object.getPrototypeOf(runtime));\n};\n"],"mappings":";AAmCO,IAAM,gBAAgB,CAAC,MAAe;AAC3C,QAAM,UAAU;AAChB,MAAI,QAAQ,UAAW;AAEvB,UAAQ,yBAAyB;AACjC,UAAQ,YAAY;AAItB;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"makeAssistantVisible.d.ts","sourceRoot":"","sources":["../../src/model-context/makeAssistantVisible.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,aAAa,EAMd,MAAM,OAAO,CAAC;AAiDf,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,EAC/D,WAAW,CAAC,EACZ,SAAS;IAAE,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,
|
1
|
+
{"version":3,"file":"makeAssistantVisible.d.ts","sourceRoot":"","sources":["../../src/model-context/makeAssistantVisible.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,aAAa,EAMd,MAAM,OAAO,CAAC;AAiDf,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,EAC/D,WAAW,CAAC,EACZ,SAAS;IAAE,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,KA2CrC,CACxC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
@@ -86,7 +86,7 @@ var makeAssistantVisible = (Component, config) => {
|
|
86
86
|
};
|
87
87
|
}
|
88
88
|
});
|
89
|
-
}, [config?.clickable, config?.editable, isNestedReadable]);
|
89
|
+
}, [config?.clickable, config?.editable, isNestedReadable, assistant]);
|
90
90
|
const ref = (0, import_react_compose_refs.useComposedRefs)(componentRef, outerRef);
|
91
91
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadableContext.Provider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
92
92
|
Component,
|
@@ -99,6 +99,7 @@ var makeAssistantVisible = (Component, config) => {
|
|
99
99
|
) });
|
100
100
|
}
|
101
101
|
);
|
102
|
+
ReadableComponent.displayName = Component.displayName;
|
102
103
|
return ReadableComponent;
|
103
104
|
};
|
104
105
|
var makeAssistantVisible_default = makeAssistantVisible;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n ComponentType,\n ForwardedRef,\n PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { z } from \"zod\";\nimport { useAssistantRuntime } from \"../context\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"./tool\";\n\nconst click = tool({\n parameters: z.object({\n clickId: z.string(),\n }),\n execute: async ({ clickId }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst edit = tool({\n parameters: z.object({\n editId: z.string(),\n value: z.string(),\n }),\n execute: async ({ editId, value }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n el.value = value;\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const assistant = useAssistantRuntime();\n useEffect(() => {\n return assistant.registerModelContextProvider({\n getModelContext: () => {\n return {\n tools: {\n ...(config?.clickable ? { click } : {}),\n ...(config?.editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [config?.clickable, config?.editable, isNestedReadable]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAUO;AACP,iBAAkB;AAClB,qBAAoC;AACpC,gCAAgC;AAChC,kBAAqB;AA6EX;AA3EV,IAAM,YAAQ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AAM,gBAAY,oCAAoB;AACtC,kCAAU,MAAM;AACd,eAAO,UAAU,6BAA6B;AAAA,UAC5C,iBAAiB,MAAM;AACrB,mBAAO;AAAA,cACL,OAAO;AAAA,gBACL,GAAI,QAAQ,YAAY,EAAE,MAAM,IAAI,CAAC;AAAA,gBACrC,GAAI,QAAQ,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,cACrC;AAAA,cACA,QAAQ,CAAC,mBACL,aAAa,SAAS,YACtB;AAAA,YACN;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,GAAG,CAAC,QAAQ,WAAW,QAAQ,UAAU,
|
1
|
+
{"version":3,"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n ComponentType,\n ForwardedRef,\n PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { z } from \"zod\";\nimport { useAssistantRuntime } from \"../context\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"./tool\";\n\nconst click = tool({\n parameters: z.object({\n clickId: z.string(),\n }),\n execute: async ({ clickId }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst edit = tool({\n parameters: z.object({\n editId: z.string(),\n value: z.string(),\n }),\n execute: async ({ editId, value }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n el.value = value;\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const assistant = useAssistantRuntime();\n useEffect(() => {\n return assistant.registerModelContextProvider({\n getModelContext: () => {\n return {\n tools: {\n ...(config?.clickable ? { click } : {}),\n ...(config?.editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [config?.clickable, config?.editable, isNestedReadable, assistant]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n ReadableComponent.displayName = Component.displayName;\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAUO;AACP,iBAAkB;AAClB,qBAAoC;AACpC,gCAAgC;AAChC,kBAAqB;AA6EX;AA3EV,IAAM,YAAQ,kBAAK;AAAA,EACjB,YAAY,aAAE,OAAO;AAAA,IACnB,SAAS,aAAE,OAAO;AAAA,EACpB,CAAC;AAAA,EACD,SAAS,OAAO,EAAE,QAAQ,MAAM;AAC9B,UAAM,iBAAiB,IAAI,OAAO,OAAO;AACzC,UAAM,KAAK,SAAS,cAAc,mBAAmB,cAAc,IAAI;AACvE,QAAI,cAAc,aAAa;AAC7B,SAAG,MAAM;AAGT,YAAM,IAAI,QAAQ,CAAC,YAA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A,YACN;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,GAAG,CAAC,QAAQ,WAAW,QAAQ,UAAU,kBAAkB,SAAS,CAAC;AAErE,YAAM,UAAM,2CAAgB,cAAc,QAAQ;AAElD,aACE,4CAAC,gBAAgB,UAAhB,EAAyB,OAAO,MAC/B;AAAA,QAAC;AAAA;AAAA,UACE,GAAI;AAAA,UACJ,GAAI,QAAQ,YAAY,EAAE,iBAAiB,QAAQ,IAAI,CAAC;AAAA,UACxD,GAAI,QAAQ,WAAW,EAAE,gBAAgB,QAAQ,IAAI,CAAC;AAAA,UACvD;AAAA;AAAA,MACF,GACF;AAAA,IAEJ;AAAA,EACF;AAEA,oBAAkB,cAAc,UAAU;AAE1C,SAAO;AACT;AAEA,IAAO,+BAAQ;","names":[]}
|
@@ -69,7 +69,7 @@ var makeAssistantVisible = (Component, config) => {
|
|
69
69
|
};
|
70
70
|
}
|
71
71
|
});
|
72
|
-
}, [config?.clickable, config?.editable, isNestedReadable]);
|
72
|
+
}, [config?.clickable, config?.editable, isNestedReadable, assistant]);
|
73
73
|
const ref = useComposedRefs(componentRef, outerRef);
|
74
74
|
return /* @__PURE__ */ jsx(ReadableContext.Provider, { value: true, children: /* @__PURE__ */ jsx(
|
75
75
|
Component,
|
@@ -82,6 +82,7 @@ var makeAssistantVisible = (Component, config) => {
|
|
82
82
|
) });
|
83
83
|
}
|
84
84
|
);
|
85
|
+
ReadableComponent.displayName = Component.displayName;
|
85
86
|
return ReadableComponent;
|
86
87
|
};
|
87
88
|
var makeAssistantVisible_default = makeAssistantVisible;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n ComponentType,\n ForwardedRef,\n PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { z } from \"zod\";\nimport { useAssistantRuntime } from \"../context\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"./tool\";\n\nconst click = tool({\n parameters: z.object({\n clickId: z.string(),\n }),\n execute: async ({ clickId }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst edit = tool({\n parameters: z.object({\n editId: z.string(),\n value: z.string(),\n }),\n execute: async ({ editId, value }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n el.value = value;\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const assistant = useAssistantRuntime();\n useEffect(() => {\n return assistant.registerModelContextProvider({\n getModelContext: () => {\n return {\n tools: {\n ...(config?.clickable ? { click } : {}),\n ...(config?.editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [config?.clickable, config?.editable, isNestedReadable]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAClB,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AA6EX;AA3EV,IAAM,QAAQ,KAAK;AAAA,EACjB,YAAY,EAAE,OAAO;AAAA,IACnB,SAAS,EAAE,OAAO;AAAA,EACpB,CAAC;AAAA,EACD,SAAS,OAAO,EAAE,QAAQ,MAAM;AAC9B,UAAM,iBAAiB,IAAI,OAAO,OAAO;AACzC,UAAM,KAAK,SAAS,cAAc,mBAAmB,cAAc,IAAI;AACvE,QAAI,cAAc,aAAa;AAC7B,SAAG,MAAM;AAGT,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC;AACxD,aAAO,CAAC;AAAA,IACV,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;AAED,IAAM,OAAO,KAAK;AAAA,EAChB,YAAY,EAAE,OAAO;AAAA,IACnB,QAAQ,EAAE,OAAO;AAAA,IACjB,OAAO,EAAE,OAAO;AAAA,EAClB,CAAC;AAAA,EACD,SAAS,OAAO,EAAE,QAAQ,MAAM,MAAM;AACpC,UAAM,gBAAgB,IAAI,OAAO,MAAM;AACvC,UAAM,KAAK,SAAS,cAAc,kBAAkB,aAAa,IAAI;AACrE,QAAI,cAAc,oBAAoB,cAAc,qBAAqB;AACvE,SAAG,QAAQ;AACX,SAAG,cAAc,IAAI,MAAM,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC;AACtD,SAAG,cAAc,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,CAAC,CAAC;AAGvD,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC;AACxD,aAAO,CAAC;AAAA,IACV,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;AAED,IAAM,kBAAkB,cAAuB,KAAK;AAE7C,IAAM,uBAAuB,CAClC,WACA,WACG;AACH,QAAM,oBAAoB;AAAA,IACxB,CAAC,OAA2B,aAAgC;AAC1D,YAAM,mBAAmB,WAAW,eAAe;AAEnD,YAAM,UAAU,MAAM;AACtB,YAAM,eAAe,OAAoB,IAAI;AAE7C,YAAM,YAAY,oBAAoB;AACtC,gBAAU,MAAM;AACd,eAAO,UAAU,6BAA6B;AAAA,UAC5C,iBAAiB,MAAM;AACrB,mBAAO;AAAA,cACL,OAAO;AAAA,gBACL,GAAI,QAAQ,YAAY,EAAE,MAAM,IAAI,CAAC;AAAA,gBACrC,GAAI,QAAQ,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,cACrC;AAAA,cACA,QAAQ,CAAC,mBACL,aAAa,SAAS,YACtB;AAAA,YACN;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,GAAG,CAAC,QAAQ,WAAW,QAAQ,UAAU,
|
1
|
+
{"version":3,"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n ComponentType,\n ForwardedRef,\n PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { z } from \"zod\";\nimport { useAssistantRuntime } from \"../context\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"./tool\";\n\nconst click = tool({\n parameters: z.object({\n clickId: z.string(),\n }),\n execute: async ({ clickId }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst edit = tool({\n parameters: z.object({\n editId: z.string(),\n value: z.string(),\n }),\n execute: async ({ editId, value }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n el.value = value;\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const assistant = useAssistantRuntime();\n useEffect(() => {\n return assistant.registerModelContextProvider({\n getModelContext: () => {\n return {\n tools: {\n ...(config?.clickable ? { click } : {}),\n ...(config?.editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [config?.clickable, config?.editable, isNestedReadable, assistant]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n ReadableComponent.displayName = Component.displayName;\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAClB,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,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,eAAe,OAAoB,IAAI;AAE7C,YAAM,YAAY,oBAAoB;AACtC,gBAAU,MAAM;AACd,eAAO,UAAU,6BAA6B;AAAA,UAC5C,iBAAiB,MAAM;AACrB,mBAAO;AAAA,cACL,OAAO;AAAA,gBACL,GAAI,QAAQ,YAAY,EAAE,MAAM,IAAI,CAAC;AAAA,gBACrC,GAAI,QAAQ,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,cACrC;AAAA,cACA,QAAQ,CAAC,mBACL,aAAa,SAAS,YACtB;AAAA,YACN;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,GAAG,CAAC,QAAQ,WAAW,QAAQ,UAAU,kBAAkB,SAAS,CAAC;AAErE,YAAM,MAAM,gBAAgB,cAAc,QAAQ;AAElD,aACE,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,MAC/B;AAAA,QAAC;AAAA;AAAA,UACE,GAAI;AAAA,UACJ,GAAI,QAAQ,YAAY,EAAE,iBAAiB,QAAQ,IAAI,CAAC;AAAA,UACxD,GAAI,QAAQ,WAAW,EAAE,gBAAgB,QAAQ,IAAI,CAAC;AAAA,UACvD;AAAA;AAAA,MACF,GACF;AAAA,IAEJ;AAAA,EACF;AAEA,oBAAkB,cAAc,UAAU;AAE1C,SAAO;AACT;AAEA,IAAO,+BAAQ;","names":[]}
|
@@ -41,7 +41,7 @@ var useAssistantInstructions = (config) => {
|
|
41
41
|
return assistantRuntime.registerModelContextProvider({
|
42
42
|
getModelContext: () => config2
|
43
43
|
});
|
44
|
-
}, [assistantRuntime, instruction]);
|
44
|
+
}, [assistantRuntime, instruction, disabled]);
|
45
45
|
};
|
46
46
|
// Annotate the CommonJS export names for ESM import in node:
|
47
47
|
0 && (module.exports = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useAssistantInstructions.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantRuntime } from \"../context\";\n\ntype AssistantInstructionsConfig = {\n disabled?: boolean | undefined;\n instruction: string;\n};\n\nconst getInstructions = (\n instruction: string | AssistantInstructionsConfig,\n): AssistantInstructionsConfig => {\n if (typeof instruction === \"string\") return { instruction };\n return instruction;\n};\n\nexport const useAssistantInstructions = (\n config: string | AssistantInstructionsConfig,\n) => {\n const { instruction, disabled = false } = getInstructions(config);\n const assistantRuntime = useAssistantRuntime();\n\n useEffect(() => {\n if (disabled) return;\n\n const config = {\n system: instruction,\n };\n return assistantRuntime.registerModelContextProvider({\n getModelContext: () => config,\n });\n }, [assistantRuntime, instruction]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,qBAAoC;AAOpC,IAAM,kBAAkB,CACtB,gBACgC;AAChC,MAAI,OAAO,gBAAgB,SAAU,QAAO,EAAE,YAAY;AAC1D,SAAO;AACT;AAEO,IAAM,2BAA2B,CACtC,WACG;AACH,QAAM,EAAE,aAAa,WAAW,MAAM,IAAI,gBAAgB,MAAM;AAChE,QAAM,uBAAmB,oCAAoB;AAE7C,8BAAU,MAAM;AACd,QAAI,SAAU;AAEd,UAAMA,UAAS;AAAA,MACb,QAAQ;AAAA,IACV;AACA,WAAO,iBAAiB,6BAA6B;AAAA,MACnD,iBAAiB,MAAMA;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,kBAAkB,
|
1
|
+
{"version":3,"sources":["../../src/model-context/useAssistantInstructions.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantRuntime } from \"../context\";\n\ntype AssistantInstructionsConfig = {\n disabled?: boolean | undefined;\n instruction: string;\n};\n\nconst getInstructions = (\n instruction: string | AssistantInstructionsConfig,\n): AssistantInstructionsConfig => {\n if (typeof instruction === \"string\") return { instruction };\n return instruction;\n};\n\nexport const useAssistantInstructions = (\n config: string | AssistantInstructionsConfig,\n) => {\n const { instruction, disabled = false } = getInstructions(config);\n const assistantRuntime = useAssistantRuntime();\n\n useEffect(() => {\n if (disabled) return;\n\n const config = {\n system: instruction,\n };\n return assistantRuntime.registerModelContextProvider({\n getModelContext: () => config,\n });\n }, [assistantRuntime, instruction, disabled]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,qBAAoC;AAOpC,IAAM,kBAAkB,CACtB,gBACgC;AAChC,MAAI,OAAO,gBAAgB,SAAU,QAAO,EAAE,YAAY;AAC1D,SAAO;AACT;AAEO,IAAM,2BAA2B,CACtC,WACG;AACH,QAAM,EAAE,aAAa,WAAW,MAAM,IAAI,gBAAgB,MAAM;AAChE,QAAM,uBAAmB,oCAAoB;AAE7C,8BAAU,MAAM;AACd,QAAI,SAAU;AAEd,UAAMA,UAAS;AAAA,MACb,QAAQ;AAAA,IACV;AACA,WAAO,iBAAiB,6BAA6B;AAAA,MACnD,iBAAiB,MAAMA;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,kBAAkB,aAAa,QAAQ,CAAC;AAC9C;","names":["config"]}
|
@@ -18,7 +18,7 @@ var useAssistantInstructions = (config) => {
|
|
18
18
|
return assistantRuntime.registerModelContextProvider({
|
19
19
|
getModelContext: () => config2
|
20
20
|
});
|
21
|
-
}, [assistantRuntime, instruction]);
|
21
|
+
}, [assistantRuntime, instruction, disabled]);
|
22
22
|
};
|
23
23
|
export {
|
24
24
|
useAssistantInstructions
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useAssistantInstructions.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantRuntime } from \"../context\";\n\ntype AssistantInstructionsConfig = {\n disabled?: boolean | undefined;\n instruction: string;\n};\n\nconst getInstructions = (\n instruction: string | AssistantInstructionsConfig,\n): AssistantInstructionsConfig => {\n if (typeof instruction === \"string\") return { instruction };\n return instruction;\n};\n\nexport const useAssistantInstructions = (\n config: string | AssistantInstructionsConfig,\n) => {\n const { instruction, disabled = false } = getInstructions(config);\n const assistantRuntime = useAssistantRuntime();\n\n useEffect(() => {\n if (disabled) return;\n\n const config = {\n system: instruction,\n };\n return assistantRuntime.registerModelContextProvider({\n getModelContext: () => config,\n });\n }, [assistantRuntime, instruction]);\n};\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAOpC,IAAM,kBAAkB,CACtB,gBACgC;AAChC,MAAI,OAAO,gBAAgB,SAAU,QAAO,EAAE,YAAY;AAC1D,SAAO;AACT;AAEO,IAAM,2BAA2B,CACtC,WACG;AACH,QAAM,EAAE,aAAa,WAAW,MAAM,IAAI,gBAAgB,MAAM;AAChE,QAAM,mBAAmB,oBAAoB;AAE7C,YAAU,MAAM;AACd,QAAI,SAAU;AAEd,UAAMA,UAAS;AAAA,MACb,QAAQ;AAAA,IACV;AACA,WAAO,iBAAiB,6BAA6B;AAAA,MACnD,iBAAiB,MAAMA;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,kBAAkB,
|
1
|
+
{"version":3,"sources":["../../src/model-context/useAssistantInstructions.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantRuntime } from \"../context\";\n\ntype AssistantInstructionsConfig = {\n disabled?: boolean | undefined;\n instruction: string;\n};\n\nconst getInstructions = (\n instruction: string | AssistantInstructionsConfig,\n): AssistantInstructionsConfig => {\n if (typeof instruction === \"string\") return { instruction };\n return instruction;\n};\n\nexport const useAssistantInstructions = (\n config: string | AssistantInstructionsConfig,\n) => {\n const { instruction, disabled = false } = getInstructions(config);\n const assistantRuntime = useAssistantRuntime();\n\n useEffect(() => {\n if (disabled) return;\n\n const config = {\n system: instruction,\n };\n return assistantRuntime.registerModelContextProvider({\n getModelContext: () => config,\n });\n }, [assistantRuntime, instruction, disabled]);\n};\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAOpC,IAAM,kBAAkB,CACtB,gBACgC;AAChC,MAAI,OAAO,gBAAgB,SAAU,QAAO,EAAE,YAAY;AAC1D,SAAO;AACT;AAEO,IAAM,2BAA2B,CACtC,WACG;AACH,QAAM,EAAE,aAAa,WAAW,MAAM,IAAI,gBAAgB,MAAM;AAChE,QAAM,mBAAmB,oBAAoB;AAE7C,YAAU,MAAM;AACd,QAAI,SAAU;AAEd,UAAMA,UAAS;AAAA,MACb,QAAQ;AAAA,IACV;AACA,WAAO,iBAAiB,6BAA6B;AAAA,MACnD,iBAAiB,MAAMA;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,kBAAkB,aAAa,QAAQ,CAAC;AAC9C;","names":["config"]}
|
@@ -31,7 +31,7 @@ var useAssistantToolUI = (tool) => {
|
|
31
31
|
(0, import_react.useEffect)(() => {
|
32
32
|
if (!tool) return;
|
33
33
|
return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);
|
34
|
-
}, [toolUIsStore, tool?.toolName, tool?.render]);
|
34
|
+
}, [toolUIsStore, tool?.toolName, tool?.render, !tool]);
|
35
35
|
};
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
37
37
|
0 && (module.exports = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useToolUIsStore } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const toolUIsStore = useToolUIsStore();\n useEffect(() => {\n if (!tool) return;\n return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);\n }, [toolUIsStore, tool?.toolName, tool?.render]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,8BAAgC;AAQzB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,mBAAe,yCAAgB;AACrC,8BAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,WAAO,aAAa,SAAS,EAAE,UAAU,KAAK,UAAU,KAAK,MAAM;AAAA,EACrE,GAAG,CAAC,cAAc,MAAM,UAAU,MAAM,
|
1
|
+
{"version":3,"sources":["../../src/model-context/useAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useToolUIsStore } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const toolUIsStore = useToolUIsStore();\n useEffect(() => {\n if (!tool) return;\n return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);\n }, [toolUIsStore, tool?.toolName, tool?.render, !tool]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,8BAAgC;AAQzB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,mBAAe,yCAAgB;AACrC,8BAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,WAAO,aAAa,SAAS,EAAE,UAAU,KAAK,UAAU,KAAK,MAAM;AAAA,EACrE,GAAG,CAAC,cAAc,MAAM,UAAU,MAAM,QAAQ,CAAC,IAAI,CAAC;AACxD;","names":[]}
|
@@ -8,7 +8,7 @@ var useAssistantToolUI = (tool) => {
|
|
8
8
|
useEffect(() => {
|
9
9
|
if (!tool) return;
|
10
10
|
return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);
|
11
|
-
}, [toolUIsStore, tool?.toolName, tool?.render]);
|
11
|
+
}, [toolUIsStore, tool?.toolName, tool?.render, !tool]);
|
12
12
|
};
|
13
13
|
export {
|
14
14
|
useAssistantToolUI
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useToolUIsStore } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const toolUIsStore = useToolUIsStore();\n useEffect(() => {\n if (!tool) return;\n return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);\n }, [toolUIsStore, tool?.toolName, tool?.render]);\n};\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAQzB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,eAAe,gBAAgB;AACrC,YAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,WAAO,aAAa,SAAS,EAAE,UAAU,KAAK,UAAU,KAAK,MAAM;AAAA,EACrE,GAAG,CAAC,cAAc,MAAM,UAAU,MAAM,
|
1
|
+
{"version":3,"sources":["../../src/model-context/useAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useToolUIsStore } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const toolUIsStore = useToolUIsStore();\n useEffect(() => {\n if (!tool) return;\n return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);\n }, [toolUIsStore, tool?.toolName, tool?.render, !tool]);\n};\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAQzB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,eAAe,gBAAgB;AACrC,YAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,WAAO,aAAa,SAAS,EAAE,UAAU,KAAK,UAAU,KAAK,MAAM;AAAA,EACrE,GAAG,CAAC,cAAc,MAAM,UAAU,MAAM,QAAQ,CAAC,IAAI,CAAC;AACxD;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useInlineRender.d.ts","sourceRoot":"","sources":["../../src/model-context/useInlineRender.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAoC,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAGpD,eAAO,MAAM,eAAe,GAAI,KAAK,EAAE,OAAO,EAC5C,QAAQ,EAAE,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KACnD,EAAE,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useInlineRender.d.ts","sourceRoot":"","sources":["../../src/model-context/useInlineRender.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAoC,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAGpD,eAAO,MAAM,eAAe,GAAI,KAAK,EAAE,OAAO,EAC5C,QAAQ,EAAE,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KACnD,EAAE,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAc7C,CAAC"}
|
@@ -30,11 +30,14 @@ var useInlineRender = (toolUI) => {
|
|
30
30
|
const [useToolUI] = (0, import_react.useState)(() => (0, import_zustand.create)(() => toolUI));
|
31
31
|
(0, import_react.useEffect)(() => {
|
32
32
|
useToolUI.setState(toolUI);
|
33
|
-
});
|
34
|
-
return (0, import_react.useCallback)(
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
}, [toolUI, useToolUI]);
|
34
|
+
return (0, import_react.useCallback)(
|
35
|
+
function ToolUI(args) {
|
36
|
+
const toolUI2 = useToolUI();
|
37
|
+
return toolUI2(args);
|
38
|
+
},
|
39
|
+
[useToolUI]
|
40
|
+
);
|
38
41
|
};
|
39
42
|
// Annotate the CommonJS export names for ESM import in node:
|
40
43
|
0 && (module.exports = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useInlineRender.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useCallback, useEffect, useState } from \"react\";\nimport { ToolCallContentPartProps } from \"../types\";\nimport { create } from \"zustand\";\n\nexport const useInlineRender = <TArgs, TResult>(\n toolUI: FC<ToolCallContentPartProps<TArgs, TResult>>,\n): FC<ToolCallContentPartProps<TArgs, TResult>> => {\n const [useToolUI] = useState(() => create(() => toolUI));\n\n useEffect(() => {\n useToolUI.setState(toolUI);\n });\n\n return useCallback((args)
|
1
|
+
{"version":3,"sources":["../../src/model-context/useInlineRender.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useCallback, useEffect, useState } from \"react\";\nimport { ToolCallContentPartProps } from \"../types\";\nimport { create } from \"zustand\";\n\nexport const useInlineRender = <TArgs, TResult>(\n toolUI: FC<ToolCallContentPartProps<TArgs, TResult>>,\n): FC<ToolCallContentPartProps<TArgs, TResult>> => {\n const [useToolUI] = useState(() => create(() => toolUI));\n\n useEffect(() => {\n useToolUI.setState(toolUI);\n }, [toolUI, useToolUI]);\n\n return useCallback(\n function ToolUI(args) {\n const toolUI = useToolUI();\n return toolUI(args);\n },\n [useToolUI],\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqD;AAErD,qBAAuB;AAEhB,IAAM,kBAAkB,CAC7B,WACiD;AACjD,QAAM,CAAC,SAAS,QAAI,uBAAS,UAAM,uBAAO,MAAM,MAAM,CAAC;AAEvD,8BAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,GAAG,CAAC,QAAQ,SAAS,CAAC;AAEtB,aAAO;AAAA,IACL,SAAS,OAAO,MAAM;AACpB,YAAMA,UAAS,UAAU;AACzB,aAAOA,QAAO,IAAI;AAAA,IACpB;AAAA,IACA,CAAC,SAAS;AAAA,EACZ;AACF;","names":["toolUI"]}
|
@@ -7,11 +7,14 @@ var useInlineRender = (toolUI) => {
|
|
7
7
|
const [useToolUI] = useState(() => create(() => toolUI));
|
8
8
|
useEffect(() => {
|
9
9
|
useToolUI.setState(toolUI);
|
10
|
-
});
|
11
|
-
return useCallback(
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
}, [toolUI, useToolUI]);
|
11
|
+
return useCallback(
|
12
|
+
function ToolUI(args) {
|
13
|
+
const toolUI2 = useToolUI();
|
14
|
+
return toolUI2(args);
|
15
|
+
},
|
16
|
+
[useToolUI]
|
17
|
+
);
|
15
18
|
};
|
16
19
|
export {
|
17
20
|
useInlineRender
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useInlineRender.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useCallback, useEffect, useState } from \"react\";\nimport { ToolCallContentPartProps } from \"../types\";\nimport { create } from \"zustand\";\n\nexport const useInlineRender = <TArgs, TResult>(\n toolUI: FC<ToolCallContentPartProps<TArgs, TResult>>,\n): FC<ToolCallContentPartProps<TArgs, TResult>> => {\n const [useToolUI] = useState(() => create(() => toolUI));\n\n useEffect(() => {\n useToolUI.setState(toolUI);\n });\n\n return useCallback((args)
|
1
|
+
{"version":3,"sources":["../../src/model-context/useInlineRender.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useCallback, useEffect, useState } from \"react\";\nimport { ToolCallContentPartProps } from \"../types\";\nimport { create } from \"zustand\";\n\nexport const useInlineRender = <TArgs, TResult>(\n toolUI: FC<ToolCallContentPartProps<TArgs, TResult>>,\n): FC<ToolCallContentPartProps<TArgs, TResult>> => {\n const [useToolUI] = useState(() => create(() => toolUI));\n\n useEffect(() => {\n useToolUI.setState(toolUI);\n }, [toolUI, useToolUI]);\n\n return useCallback(\n function ToolUI(args) {\n const toolUI = useToolUI();\n return toolUI(args);\n },\n [useToolUI],\n );\n};\n"],"mappings":";;;AAEA,SAAa,aAAa,WAAW,gBAAgB;AAErD,SAAS,cAAc;AAEhB,IAAM,kBAAkB,CAC7B,WACiD;AACjD,QAAM,CAAC,SAAS,IAAI,SAAS,MAAM,OAAO,MAAM,MAAM,CAAC;AAEvD,YAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,GAAG,CAAC,QAAQ,SAAS,CAAC;AAEtB,SAAO;AAAA,IACL,SAAS,OAAO,MAAM;AACpB,YAAMA,UAAS,UAAU;AACzB,aAAOA,QAAO,IAAI;AAAA,IACpB;AAAA,IACA,CAAC,SAAS;AAAA,EACZ;AACF;","names":["toolUI"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantModalRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAK5D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG,gBAAgB,CAAC,YAAY,GAAG;QAClD,uBAAuB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAC/C,CAAC;CACH;
|
1
|
+
{"version":3,"file":"AssistantModalRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAK5D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG,gBAAgB,CAAC,YAAY,GAAG;QAClD,uBAAuB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAC/C,CAAC;CACH;AA6BD,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAC1C,2BAA2B,CAAC,KAAK,CAwBlC,CAAC"}
|
@@ -52,7 +52,12 @@ var useAssistantModalOpenState = ({
|
|
52
52
|
return threadRuntime.unstable_on("run-start", () => {
|
53
53
|
setOpen(true);
|
54
54
|
});
|
55
|
-
}, [
|
55
|
+
}, [
|
56
|
+
unstable_openOnRunStart,
|
57
|
+
setOpen,
|
58
|
+
threadRuntime,
|
59
|
+
!unstable_openOnRunStart
|
60
|
+
]);
|
56
61
|
return state;
|
57
62
|
};
|
58
63
|
var AssistantModalPrimitiveRoot = ({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect, useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\nimport { useThreadRuntime } from \"../../context\";\n\nexport namespace AssistantModalPrimitiveRoot {\n export type Props = PopoverPrimitive.PopoverProps & {\n unstable_openOnRunStart?: boolean | undefined;\n };\n}\n\nconst useAssistantModalOpenState = ({\n defaultOpen = false,\n unstable_openOnRunStart = true,\n}: {\n defaultOpen?: boolean | undefined;\n unstable_openOnRunStart?: boolean | undefined;\n}) => {\n const state = useState(defaultOpen);\n\n const [, setOpen] = state;\n const threadRuntime = useThreadRuntime();\n useEffect(() => {\n if (!unstable_openOnRunStart) return undefined;\n\n return threadRuntime.unstable_on(\"run-start\", () => {\n setOpen(true);\n });\n }, [unstable_openOnRunStart]);\n\n return state;\n};\n\nexport const AssistantModalPrimitiveRoot: FC<\n AssistantModalPrimitiveRoot.Props\n> = ({\n __scopeAssistantModal,\n defaultOpen,\n unstable_openOnRunStart,\n open,\n onOpenChange,\n ...rest\n}: ScopedProps<AssistantModalPrimitiveRoot.Props>) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n const [modalOpen, setOpen] = useAssistantModalOpenState({\n defaultOpen,\n unstable_openOnRunStart,\n });\n\n return (\n <PopoverPrimitive.Root\n {...scope}\n open={open === undefined ? modalOpen : open}\n onOpenChange={composeEventHandlers(onOpenChange, setOpen)}\n {...rest}\n />\n );\n};\n\nAssistantModalPrimitiveRoot.displayName = \"AssistantModalPrimitive.Root\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAwC;AACxC,uBAAkC;AAClC,uBAAqC;AACrC,mBAA6C;AAC7C,qBAAiC;
|
1
|
+
{"version":3,"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect, useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\nimport { useThreadRuntime } from \"../../context\";\n\nexport namespace AssistantModalPrimitiveRoot {\n export type Props = PopoverPrimitive.PopoverProps & {\n unstable_openOnRunStart?: boolean | undefined;\n };\n}\n\nconst useAssistantModalOpenState = ({\n defaultOpen = false,\n unstable_openOnRunStart = true,\n}: {\n defaultOpen?: boolean | undefined;\n unstable_openOnRunStart?: boolean | undefined;\n}) => {\n const state = useState(defaultOpen);\n\n const [, setOpen] = state;\n const threadRuntime = useThreadRuntime();\n useEffect(() => {\n if (!unstable_openOnRunStart) return undefined;\n\n return threadRuntime.unstable_on(\"run-start\", () => {\n setOpen(true);\n });\n }, [\n unstable_openOnRunStart,\n setOpen,\n threadRuntime,\n !unstable_openOnRunStart,\n ]);\n\n return state;\n};\n\nexport const AssistantModalPrimitiveRoot: FC<\n AssistantModalPrimitiveRoot.Props\n> = ({\n __scopeAssistantModal,\n defaultOpen,\n unstable_openOnRunStart,\n open,\n onOpenChange,\n ...rest\n}: ScopedProps<AssistantModalPrimitiveRoot.Props>) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n const [modalOpen, setOpen] = useAssistantModalOpenState({\n defaultOpen,\n unstable_openOnRunStart,\n });\n\n return (\n <PopoverPrimitive.Root\n {...scope}\n open={open === undefined ? modalOpen : open}\n onOpenChange={composeEventHandlers(onOpenChange, setOpen)}\n {...rest}\n />\n );\n};\n\nAssistantModalPrimitiveRoot.displayName = \"AssistantModalPrimitive.Root\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAwC;AACxC,uBAAkC;AAClC,uBAAqC;AACrC,mBAA6C;AAC7C,qBAAiC;AAqD7B;AA7CJ,IAAM,6BAA6B,CAAC;AAAA,EAClC,cAAc;AAAA,EACd,0BAA0B;AAC5B,MAGM;AACJ,QAAM,YAAQ,uBAAS,WAAW;AAElC,QAAM,CAAC,EAAE,OAAO,IAAI;AACpB,QAAM,oBAAgB,iCAAiB;AACvC,8BAAU,MAAM;AACd,QAAI,CAAC,wBAAyB,QAAO;AAErC,WAAO,cAAc,YAAY,aAAa,MAAM;AAClD,cAAQ,IAAI;AAAA,IACd,CAAC;AAAA,EACH,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAEO,IAAM,8BAET,CAAC;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAsD;AACpD,QAAM,YAAQ,8BAAgB,qBAAqB;AAEnD,QAAM,CAAC,WAAW,OAAO,IAAI,2BAA2B;AAAA,IACtD;AAAA,IACA;AAAA,EACF,CAAC;AAED,SACE;AAAA,IAAkB;AAAA,IAAjB;AAAA,MACE,GAAG;AAAA,MACJ,MAAM,SAAS,SAAY,YAAY;AAAA,MACvC,kBAAc,uCAAqB,cAAc,OAAO;AAAA,MACvD,GAAG;AAAA;AAAA,EACN;AAEJ;AAEA,4BAA4B,cAAc;","names":[]}
|
@@ -19,7 +19,12 @@ var useAssistantModalOpenState = ({
|
|
19
19
|
return threadRuntime.unstable_on("run-start", () => {
|
20
20
|
setOpen(true);
|
21
21
|
});
|
22
|
-
}, [
|
22
|
+
}, [
|
23
|
+
unstable_openOnRunStart,
|
24
|
+
setOpen,
|
25
|
+
threadRuntime,
|
26
|
+
!unstable_openOnRunStart
|
27
|
+
]);
|
23
28
|
return state;
|
24
29
|
};
|
25
30
|
var AssistantModalPrimitiveRoot = ({
|