@assistant-ui/react 0.7.69 → 0.7.70

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/dist/api/MessageRuntime.d.ts +2 -1
  2. package/dist/api/MessageRuntime.d.ts.map +1 -1
  3. package/dist/api/MessageRuntime.js +9 -2
  4. package/dist/api/MessageRuntime.js.map +1 -1
  5. package/dist/api/MessageRuntime.mjs +9 -2
  6. package/dist/api/MessageRuntime.mjs.map +1 -1
  7. package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
  8. package/dist/context/providers/ThreadRuntimeProvider.js +3 -5
  9. package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
  10. package/dist/context/providers/ThreadRuntimeProvider.mjs +3 -5
  11. package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
  12. package/dist/context/providers/ThreadViewportProvider.d.ts +3 -0
  13. package/dist/context/providers/ThreadViewportProvider.d.ts.map +1 -0
  14. package/dist/context/providers/ThreadViewportProvider.js +63 -0
  15. package/dist/context/providers/ThreadViewportProvider.js.map +1 -0
  16. package/dist/context/providers/ThreadViewportProvider.mjs +42 -0
  17. package/dist/context/providers/ThreadViewportProvider.mjs.map +1 -0
  18. package/dist/context/react/ThreadContext.d.ts +0 -18
  19. package/dist/context/react/ThreadContext.d.ts.map +1 -1
  20. package/dist/context/react/ThreadContext.js +2 -11
  21. package/dist/context/react/ThreadContext.js.map +1 -1
  22. package/dist/context/react/ThreadContext.mjs +1 -8
  23. package/dist/context/react/ThreadContext.mjs.map +1 -1
  24. package/dist/context/react/ThreadViewportContext.d.ts +24 -0
  25. package/dist/context/react/ThreadViewportContext.d.ts.map +1 -0
  26. package/dist/context/react/ThreadViewportContext.js +44 -0
  27. package/dist/context/react/ThreadViewportContext.js.map +1 -0
  28. package/dist/context/react/ThreadViewportContext.mjs +18 -0
  29. package/dist/context/react/ThreadViewportContext.mjs.map +1 -0
  30. package/dist/context/react/index.d.ts +2 -1
  31. package/dist/context/react/index.d.ts.map +1 -1
  32. package/dist/context/react/index.js +3 -2
  33. package/dist/context/react/index.js.map +1 -1
  34. package/dist/context/react/index.mjs +4 -2
  35. package/dist/context/react/index.mjs.map +1 -1
  36. package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
  37. package/dist/context/stores/ThreadViewport.js +1 -0
  38. package/dist/context/stores/ThreadViewport.js.map +1 -1
  39. package/dist/context/stores/ThreadViewport.mjs +2 -0
  40. package/dist/context/stores/ThreadViewport.mjs.map +1 -1
  41. package/dist/model-context/ModelContextTypes.d.ts +3 -0
  42. package/dist/model-context/ModelContextTypes.d.ts.map +1 -1
  43. package/dist/model-context/ModelContextTypes.js.map +1 -1
  44. package/dist/model-context/ModelContextTypes.mjs.map +1 -1
  45. package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
  46. package/dist/primitives/thread/ThreadScrollToBottom.js +3 -4
  47. package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
  48. package/dist/primitives/thread/ThreadScrollToBottom.mjs +1 -2
  49. package/dist/primitives/thread/ThreadScrollToBottom.mjs.map +1 -1
  50. package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
  51. package/dist/primitives/thread/ThreadViewport.js +5 -1
  52. package/dist/primitives/thread/ThreadViewport.js.map +1 -1
  53. package/dist/primitives/thread/ThreadViewport.mjs +5 -1
  54. package/dist/primitives/thread/ThreadViewport.mjs.map +1 -1
  55. package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
  56. package/dist/primitives/thread/useThreadViewportAutoScroll.js +2 -1
  57. package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
  58. package/dist/primitives/thread/useThreadViewportAutoScroll.mjs +2 -4
  59. package/dist/primitives/thread/useThreadViewportAutoScroll.mjs.map +1 -1
  60. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts +1 -1
  61. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
  62. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +1 -0
  63. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
  64. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +1 -0
  65. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
  66. package/dist/runtimes/edge/streams/toolResultStream.d.ts.map +1 -1
  67. package/dist/runtimes/edge/streams/toolResultStream.js +13 -15
  68. package/dist/runtimes/edge/streams/toolResultStream.js.map +1 -1
  69. package/dist/runtimes/edge/streams/toolResultStream.mjs +13 -15
  70. package/dist/runtimes/edge/streams/toolResultStream.mjs.map +1 -1
  71. package/dist/utils/hooks/useOnScrollToBottom.js +2 -2
  72. package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
  73. package/dist/utils/hooks/useOnScrollToBottom.mjs +1 -1
  74. package/dist/utils/hooks/useOnScrollToBottom.mjs.map +1 -1
  75. package/package.json +3 -3
  76. package/src/api/MessageRuntime.ts +14 -5
  77. package/src/context/providers/ThreadRuntimeProvider.tsx +4 -5
  78. package/src/context/providers/ThreadViewportProvider.tsx +49 -0
  79. package/src/context/react/ThreadContext.ts +0 -8
  80. package/src/context/react/ThreadViewportContext.ts +23 -0
  81. package/src/context/react/index.ts +4 -1
  82. package/src/context/stores/ThreadViewport.tsx +2 -0
  83. package/src/model-context/ModelContextTypes.ts +7 -0
  84. package/src/primitives/thread/ThreadScrollToBottom.tsx +1 -2
  85. package/src/primitives/thread/ThreadViewport.tsx +13 -1
  86. package/src/primitives/thread/useThreadViewportAutoScroll.tsx +2 -4
  87. package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +4 -1
  88. package/src/runtimes/edge/streams/toolResultStream.ts +20 -18
  89. package/src/utils/hooks/useOnScrollToBottom.tsx +1 -1
@@ -58,8 +58,9 @@ export declare class MessageRuntimeImpl implements MessageRuntime {
58
58
  constructor(_core: MessageStateBinding, _threadBinding: ThreadRuntimeCoreBinding);
59
59
  protected __internal_bindMethods(): void;
60
60
  readonly composer: EditComposerRuntimeImpl;
61
+ private _getEditComposerRuntimeCore;
61
62
  getState(): MessageState;
62
- reload({ runConfig }?: ReloadConfig): void;
63
+ reload(reloadConfig?: ReloadConfig): void;
63
64
  speak(): void;
64
65
  stopSpeaking(): void;
65
66
  submitFeedback({ type }: {
@@ -1 +1 @@
1
- {"version":3,"file":"MessageRuntime.d.ts","sourceRoot":"","sources":["../../src/api/MessageRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EAClB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,SAAS,EACT,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EAEjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAI3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAMpE,eAAO,MAAM,mBAAmB,YACrB,aAAa,aACX,MAAM,QACX,qBAAqB,GAAG,0BAA0B,KACvD,yBAcF,CAAC;AAoBF,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAA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;CAuBxC"}
@@ -71,7 +71,7 @@ var MessageRuntimeImpl = class {
71
71
  ref: this.path.ref + `${this.path.ref}.composer`,
72
72
  composerSource: "edit"
73
73
  },
74
- getState: () => this._threadBinding.getState().getEditComposer(this._core.getState().id),
74
+ getState: this._getEditComposerRuntimeCore,
75
75
  subscribe: (callback) => this._threadBinding.subscribe(callback)
76
76
  }),
77
77
  () => this._threadBinding.getState().beginEdit(this._core.getState().id)
@@ -94,10 +94,17 @@ var MessageRuntimeImpl = class {
94
94
  this.switchToBranch = this.switchToBranch.bind(this);
95
95
  }
96
96
  composer;
97
+ _getEditComposerRuntimeCore = () => {
98
+ return this._threadBinding.getState().getEditComposer(this._core.getState().id);
99
+ };
97
100
  getState() {
98
101
  return this._core.getState();
99
102
  }
100
- reload({ runConfig = {} } = {}) {
103
+ reload(reloadConfig = {}) {
104
+ const editComposerRuntimeCore = this._getEditComposerRuntimeCore();
105
+ const composerRuntimeCore = editComposerRuntimeCore ?? this._threadBinding.getState().composer;
106
+ const composer = editComposerRuntimeCore ?? composerRuntimeCore;
107
+ const { runConfig = composer.runConfig } = reloadConfig;
101
108
  const state = this._core.getState();
102
109
  if (state.role !== "assistant")
103
110
  throw new Error("Can only reload assistant messages");
@@ -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: () =>\n this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id),\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n 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 public getState() {\n return this._core.getState();\n }\n\n public reload({ 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,CAAC,KAAK,QAAQ;AAChB,aAAO,QAAQ;AAAA,IACjB,OAAO;AACL,aAAO;AAAA,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"],"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":";;;;;;;;;;;;;;;;;;;;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,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,MAAI,OAAO,QAAQ,QAAQ,SAAS;AACpC,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,iDAAkB,GAAI,KAAa,iDAAkB,EAAE;AAAA,IAC7D;AAAA,EACF,CAAC;AACH;AA0DO,IAAM,qBAAN,MAAmD;AAAA,EAKxD,YACU,OACA,gBACR;AAFQ;AACA;AAER,SAAK,WAAW,IAAI;AAAA,MAClB,IAAI,2DAA0B;AAAA,QAC5B,M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;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,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":[]}
@@ -52,7 +52,7 @@ var MessageRuntimeImpl = class {
52
52
  ref: this.path.ref + `${this.path.ref}.composer`,
53
53
  composerSource: "edit"
54
54
  },
55
- getState: () => this._threadBinding.getState().getEditComposer(this._core.getState().id),
55
+ getState: this._getEditComposerRuntimeCore,
56
56
  subscribe: (callback) => this._threadBinding.subscribe(callback)
57
57
  }),
58
58
  () => this._threadBinding.getState().beginEdit(this._core.getState().id)
@@ -75,10 +75,17 @@ var MessageRuntimeImpl = class {
75
75
  this.switchToBranch = this.switchToBranch.bind(this);
76
76
  }
77
77
  composer;
78
+ _getEditComposerRuntimeCore = () => {
79
+ return this._threadBinding.getState().getEditComposer(this._core.getState().id);
80
+ };
78
81
  getState() {
79
82
  return this._core.getState();
80
83
  }
81
- reload({ runConfig = {} } = {}) {
84
+ reload(reloadConfig = {}) {
85
+ const editComposerRuntimeCore = this._getEditComposerRuntimeCore();
86
+ const composerRuntimeCore = editComposerRuntimeCore ?? this._threadBinding.getState().composer;
87
+ const composer = editComposerRuntimeCore ?? composerRuntimeCore;
88
+ const { runConfig = composer.runConfig } = reloadConfig;
82
89
  const state = this._core.getState();
83
90
  if (state.role !== "assistant")
84
91
  throw new Error("Can only reload assistant messages");
@@ -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: () =>\n this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id),\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n 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 public getState() {\n return this._core.getState();\n }\n\n public reload({ 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,MAAI,OAAO,QAAQ,QAAQ,SAAS;AACpC,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,IAC7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;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
+ {"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,sB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,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,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":"ThreadRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAMnD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAIxE,KAAK,mBAAmB,GAAG;IACzB,eAAe,EAAE,qBAAqB,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAeF,eAAO,MAAM,qBAAqB,EAAE,EAAE,CACpC,iBAAiB,CAAC,mBAAmB,CAAC,CAoBvC,CAAC"}
1
+ {"version":3,"file":"ThreadRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAKxE,KAAK,mBAAmB,GAAG;IACzB,eAAe,EAAE,qBAAqB,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAeF,eAAO,MAAM,qBAAqB,EAAE,EAAE,CACpC,iBAAiB,CAAC,mBAAmB,CAAC,CAmBvC,CAAC"}
@@ -26,11 +26,11 @@ __export(ThreadRuntimeProvider_exports, {
26
26
  module.exports = __toCommonJS(ThreadRuntimeProvider_exports);
27
27
  var import_react = require("react");
28
28
  var import_ThreadContext = require("../react/ThreadContext.js");
29
- var import_ThreadViewport = require("../stores/ThreadViewport.js");
30
29
  var import_ReadonlyStore = require("../ReadonlyStore.js");
31
30
  var import_zustand = require("zustand");
32
31
  var import_ThreadListItemRuntimeProvider = require("./ThreadListItemRuntimeProvider.js");
33
32
  var import_ensureBinding = require("../react/utils/ensureBinding.js");
33
+ var import_ThreadViewportProvider = require("./ThreadViewportProvider.js");
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var useThreadRuntimeStore = (runtime) => {
36
36
  const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime));
@@ -44,13 +44,11 @@ var useThreadRuntimeStore = (runtime) => {
44
44
  var ThreadRuntimeProvider = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {
45
45
  const useThreadRuntime = useThreadRuntimeStore(runtime);
46
46
  const [context] = (0, import_react.useState)(() => {
47
- const useViewport = (0, import_ThreadViewport.makeThreadViewportStore)();
48
47
  return {
49
- useThreadRuntime,
50
- useViewport
48
+ useThreadRuntime
51
49
  };
52
50
  });
53
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadListItemRuntimeProvider.ThreadListItemRuntimeProvider, { runtime: threadListItemRuntime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadContext.ThreadContext.Provider, { value: context, children }) });
51
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadListItemRuntimeProvider.ThreadListItemRuntimeProvider, { runtime: threadListItemRuntime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadContext.ThreadContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadViewportProvider.ThreadViewportProvider, { children }) }) });
54
52
  };
55
53
  // Annotate the CommonJS export names for ESM import in node:
56
54
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { create } from \"zustand\";\nimport { ThreadListItemRuntime } from \"../../api/ThreadListItemRuntime\";\nimport { ThreadListItemRuntimeProvider } from \"./ThreadListItemRuntimeProvider\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\ntype ThreadProviderProps = {\n listItemRuntime: ThreadListItemRuntime;\n runtime: ThreadRuntime;\n};\n\nconst useThreadRuntimeStore = (runtime: ThreadRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.composer);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ThreadRuntimeProvider: FC<\n PropsWithChildren<ThreadProviderProps>\n> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {\n const useThreadRuntime = useThreadRuntimeStore(runtime);\n\n const [context] = useState<ThreadContextValue>(() => {\n const useViewport = makeThreadViewportStore();\n\n return {\n useThreadRuntime,\n useViewport,\n };\n });\n\n return (\n <ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>\n <ThreadContext.Provider value={context}>\n {children}\n </ThreadContext.Provider>\n </ThreadListItemRuntimeProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAoC;AAEpC,2BAA8B;AAC9B,4BAAwC;AACxC,2BAA8B;AAE9B,qBAAuB;AAEvB,2CAA8C;AAC9C,2BAA8B;AAoCxB;AA7BN,IAAM,wBAAwB,CAAC,YAA2B;AACxD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AACrB,4CAAc,QAAQ,QAAQ;AAE9B,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,wBAET,CAAC,EAAE,UAAU,iBAAiB,uBAAuB,QAAQ,MAAM;AACrE,QAAM,mBAAmB,sBAAsB,OAAO;AAEtD,QAAM,CAAC,OAAO,QAAI,uBAA6B,MAAM;AACnD,UAAM,kBAAc,+CAAwB;AAE5C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,4CAAC,sEAA8B,SAAS,uBACtC,sDAAC,mCAAc,UAAd,EAAuB,OAAO,SAC5B,UACH,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { create } from \"zustand\";\nimport { ThreadListItemRuntime } from \"../../api/ThreadListItemRuntime\";\nimport { ThreadListItemRuntimeProvider } from \"./ThreadListItemRuntimeProvider\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\nimport { ThreadViewportProvider } from \"./ThreadViewportProvider\";\n\ntype ThreadProviderProps = {\n listItemRuntime: ThreadListItemRuntime;\n runtime: ThreadRuntime;\n};\n\nconst useThreadRuntimeStore = (runtime: ThreadRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.composer);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ThreadRuntimeProvider: FC<\n PropsWithChildren<ThreadProviderProps>\n> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {\n const useThreadRuntime = useThreadRuntimeStore(runtime);\n\n const [context] = useState<ThreadContextValue>(() => {\n return {\n useThreadRuntime,\n };\n });\n\n return (\n <ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>\n <ThreadContext.Provider value={context}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </ThreadContext.Provider>\n </ThreadListItemRuntimeProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAoC;AAEpC,2BAA8B;AAC9B,2BAA8B;AAE9B,qBAAuB;AAEvB,2CAA8C;AAC9C,2BAA8B;AAC9B,oCAAuC;AAoC/B;AA7BR,IAAM,wBAAwB,CAAC,YAA2B;AACxD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AACrB,4CAAc,QAAQ,QAAQ;AAE9B,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,wBAET,CAAC,EAAE,UAAU,iBAAiB,uBAAuB,QAAQ,MAAM;AACrE,QAAM,mBAAmB,sBAAsB,OAAO;AAEtD,QAAM,CAAC,OAAO,QAAI,uBAA6B,MAAM;AACnD,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,4CAAC,sEAA8B,SAAS,uBACtC,sDAAC,mCAAc,UAAd,EAAuB,OAAO,SAG7B,sDAAC,wDAAwB,UAAS,GACpC,GACF;AAEJ;","names":[]}
@@ -3,11 +3,11 @@
3
3
  // src/context/providers/ThreadRuntimeProvider.tsx
4
4
  import { useEffect, useState } from "react";
5
5
  import { ThreadContext } from "../react/ThreadContext.mjs";
6
- import { makeThreadViewportStore } from "../stores/ThreadViewport.mjs";
7
6
  import { writableStore } from "../ReadonlyStore.mjs";
8
7
  import { create } from "zustand";
9
8
  import { ThreadListItemRuntimeProvider } from "./ThreadListItemRuntimeProvider.mjs";
10
9
  import { ensureBinding } from "../react/utils/ensureBinding.mjs";
10
+ import { ThreadViewportProvider } from "./ThreadViewportProvider.mjs";
11
11
  import { jsx } from "react/jsx-runtime";
12
12
  var useThreadRuntimeStore = (runtime) => {
13
13
  const [store] = useState(() => create(() => runtime));
@@ -21,13 +21,11 @@ var useThreadRuntimeStore = (runtime) => {
21
21
  var ThreadRuntimeProvider = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {
22
22
  const useThreadRuntime = useThreadRuntimeStore(runtime);
23
23
  const [context] = useState(() => {
24
- const useViewport = makeThreadViewportStore();
25
24
  return {
26
- useThreadRuntime,
27
- useViewport
25
+ useThreadRuntime
28
26
  };
29
27
  });
30
- return /* @__PURE__ */ jsx(ThreadListItemRuntimeProvider, { runtime: threadListItemRuntime, children: /* @__PURE__ */ jsx(ThreadContext.Provider, { value: context, children }) });
28
+ return /* @__PURE__ */ jsx(ThreadListItemRuntimeProvider, { runtime: threadListItemRuntime, children: /* @__PURE__ */ jsx(ThreadContext.Provider, { value: context, children: /* @__PURE__ */ jsx(ThreadViewportProvider, { children }) }) });
31
29
  };
32
30
  export {
33
31
  ThreadRuntimeProvider
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { create } from \"zustand\";\nimport { ThreadListItemRuntime } from \"../../api/ThreadListItemRuntime\";\nimport { ThreadListItemRuntimeProvider } from \"./ThreadListItemRuntimeProvider\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\ntype ThreadProviderProps = {\n listItemRuntime: ThreadListItemRuntime;\n runtime: ThreadRuntime;\n};\n\nconst useThreadRuntimeStore = (runtime: ThreadRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.composer);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ThreadRuntimeProvider: FC<\n PropsWithChildren<ThreadProviderProps>\n> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {\n const useThreadRuntime = useThreadRuntimeStore(runtime);\n\n const [context] = useState<ThreadContextValue>(() => {\n const useViewport = makeThreadViewportStore();\n\n return {\n useThreadRuntime,\n useViewport,\n };\n });\n\n return (\n <ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>\n <ThreadContext.Provider value={context}>\n {children}\n </ThreadContext.Provider>\n </ThreadListItemRuntimeProvider>\n );\n};\n"],"mappings":";;;AAGA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC,SAAS,qBAAqB;AAE9B,SAAS,cAAc;AAEvB,SAAS,qCAAqC;AAC9C,SAAS,qBAAqB;AAoCxB;AA7BN,IAAM,wBAAwB,CAAC,YAA2B;AACxD,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AACrB,kBAAc,QAAQ,QAAQ;AAE9B,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,wBAET,CAAC,EAAE,UAAU,iBAAiB,uBAAuB,QAAQ,MAAM;AACrE,QAAM,mBAAmB,sBAAsB,OAAO;AAEtD,QAAM,CAAC,OAAO,IAAI,SAA6B,MAAM;AACnD,UAAM,cAAc,wBAAwB;AAE5C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,iCAA8B,SAAS,uBACtC,8BAAC,cAAc,UAAd,EAAuB,OAAO,SAC5B,UACH,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { create } from \"zustand\";\nimport { ThreadListItemRuntime } from \"../../api/ThreadListItemRuntime\";\nimport { ThreadListItemRuntimeProvider } from \"./ThreadListItemRuntimeProvider\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\nimport { ThreadViewportProvider } from \"./ThreadViewportProvider\";\n\ntype ThreadProviderProps = {\n listItemRuntime: ThreadListItemRuntime;\n runtime: ThreadRuntime;\n};\n\nconst useThreadRuntimeStore = (runtime: ThreadRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.composer);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ThreadRuntimeProvider: FC<\n PropsWithChildren<ThreadProviderProps>\n> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {\n const useThreadRuntime = useThreadRuntimeStore(runtime);\n\n const [context] = useState<ThreadContextValue>(() => {\n return {\n useThreadRuntime,\n };\n });\n\n return (\n <ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>\n <ThreadContext.Provider value={context}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </ThreadContext.Provider>\n </ThreadListItemRuntimeProvider>\n );\n};\n"],"mappings":";;;AAGA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAE9B,SAAS,cAAc;AAEvB,SAAS,qCAAqC;AAC9C,SAAS,qBAAqB;AAC9B,SAAS,8BAA8B;AAoC/B;AA7BR,IAAM,wBAAwB,CAAC,YAA2B;AACxD,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AACrB,kBAAc,QAAQ,QAAQ;AAE9B,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,wBAET,CAAC,EAAE,UAAU,iBAAiB,uBAAuB,QAAQ,MAAM;AACrE,QAAM,mBAAmB,sBAAsB,OAAO;AAEtD,QAAM,CAAC,OAAO,IAAI,SAA6B,MAAM;AACnD,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,iCAA8B,SAAS,uBACtC,8BAAC,cAAc,UAAd,EAAuB,OAAO,SAG7B,8BAAC,0BAAwB,UAAS,GACpC,GACF;AAEJ;","names":[]}
@@ -0,0 +1,3 @@
1
+ import type { FC, PropsWithChildren } from "react";
2
+ export declare const ThreadViewportProvider: FC<PropsWithChildren>;
3
+ //# sourceMappingURL=ThreadViewportProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThreadViewportProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/ThreadViewportProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAgCnD,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,iBAAiB,CAcxD,CAAC"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/context/providers/ThreadViewportProvider.tsx
22
+ var ThreadViewportProvider_exports = {};
23
+ __export(ThreadViewportProvider_exports, {
24
+ ThreadViewportProvider: () => ThreadViewportProvider
25
+ });
26
+ module.exports = __toCommonJS(ThreadViewportProvider_exports);
27
+ var import_react = require("react");
28
+ var import_ThreadViewport = require("../stores/ThreadViewport.js");
29
+ var import_ThreadViewportContext = require("../react/ThreadViewportContext.js");
30
+ var import_ReadonlyStore = require("../ReadonlyStore.js");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
32
+ var useThreadViewportStoreValue = () => {
33
+ const outerViewport = (0, import_ThreadViewportContext.useThreadViewportStore)({ optional: true });
34
+ const [store] = (0, import_react.useState)(() => (0, import_ThreadViewport.makeThreadViewportStore)());
35
+ (0, import_react.useEffect)(() => {
36
+ return outerViewport?.getState().onScrollToBottom(() => {
37
+ store.getState().scrollToBottom();
38
+ });
39
+ }, [outerViewport, store]);
40
+ (0, import_react.useEffect)(() => {
41
+ if (!outerViewport) return;
42
+ return store.subscribe((state) => {
43
+ if (outerViewport.getState().isAtBottom !== state.isAtBottom) {
44
+ (0, import_ReadonlyStore.writableStore)(outerViewport).setState({ isAtBottom: state.isAtBottom });
45
+ }
46
+ });
47
+ }, [store, outerViewport]);
48
+ return store;
49
+ };
50
+ var ThreadViewportProvider = ({ children }) => {
51
+ const useThreadViewport = useThreadViewportStoreValue();
52
+ const [context] = (0, import_react.useState)(() => {
53
+ return {
54
+ useThreadViewport
55
+ };
56
+ });
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadViewportContext.ThreadViewportContext.Provider, { value: context, children });
58
+ };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ ThreadViewportProvider
62
+ });
63
+ //# sourceMappingURL=ThreadViewportProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/providers/ThreadViewportProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport {\n ThreadViewportContext,\n ThreadViewportContextValue,\n useThreadViewportStore,\n} from \"../react/ThreadViewportContext\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nconst useThreadViewportStoreValue = () => {\n const outerViewport = useThreadViewportStore({ optional: true });\n const [store] = useState(() => makeThreadViewportStore());\n\n useEffect(() => {\n return outerViewport?.getState().onScrollToBottom(() => {\n store.getState().scrollToBottom();\n });\n }, [outerViewport, store]);\n\n useEffect(() => {\n if (!outerViewport) return;\n return store.subscribe((state) => {\n if (outerViewport.getState().isAtBottom !== state.isAtBottom) {\n writableStore(outerViewport).setState({ isAtBottom: state.isAtBottom });\n }\n });\n }, [store, outerViewport]);\n\n return store;\n};\n\nexport const ThreadViewportProvider: FC<PropsWithChildren> = ({ children }) => {\n const useThreadViewport = useThreadViewportStoreValue();\n\n const [context] = useState<ThreadViewportContextValue>(() => {\n return {\n useThreadViewport,\n };\n });\n\n return (\n <ThreadViewportContext.Provider value={context}>\n {children}\n </ThreadViewportContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAoC;AACpC,4BAAwC;AACxC,mCAIO;AACP,2BAA8B;AAkC1B;AAhCJ,IAAM,8BAA8B,MAAM;AACxC,QAAM,oBAAgB,qDAAuB,EAAE,UAAU,KAAK,CAAC;AAC/D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,+CAAwB,CAAC;AAExD,8BAAU,MAAM;AACd,WAAO,eAAe,SAAS,EAAE,iBAAiB,MAAM;AACtD,YAAM,SAAS,EAAE,eAAe;AAAA,IAClC,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,KAAK,CAAC;AAEzB,8BAAU,MAAM;AACd,QAAI,CAAC,cAAe;AACpB,WAAO,MAAM,UAAU,CAAC,UAAU;AAChC,UAAI,cAAc,SAAS,EAAE,eAAe,MAAM,YAAY;AAC5D,gDAAc,aAAa,EAAE,SAAS,EAAE,YAAY,MAAM,WAAW,CAAC;AAAA,MACxE;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,OAAO,aAAa,CAAC;AAEzB,SAAO;AACT;AAEO,IAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,oBAAoB,4BAA4B;AAEtD,QAAM,CAAC,OAAO,QAAI,uBAAqC,MAAM;AAC3D,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,4CAAC,mDAAsB,UAAtB,EAA+B,OAAO,SACpC,UACH;AAEJ;","names":[]}
@@ -0,0 +1,42 @@
1
+ "use client";
2
+
3
+ // src/context/providers/ThreadViewportProvider.tsx
4
+ import { useEffect, useState } from "react";
5
+ import { makeThreadViewportStore } from "../stores/ThreadViewport.mjs";
6
+ import {
7
+ ThreadViewportContext,
8
+ useThreadViewportStore
9
+ } from "../react/ThreadViewportContext.mjs";
10
+ import { writableStore } from "../ReadonlyStore.mjs";
11
+ import { jsx } from "react/jsx-runtime";
12
+ var useThreadViewportStoreValue = () => {
13
+ const outerViewport = useThreadViewportStore({ optional: true });
14
+ const [store] = useState(() => makeThreadViewportStore());
15
+ useEffect(() => {
16
+ return outerViewport?.getState().onScrollToBottom(() => {
17
+ store.getState().scrollToBottom();
18
+ });
19
+ }, [outerViewport, store]);
20
+ useEffect(() => {
21
+ if (!outerViewport) return;
22
+ return store.subscribe((state) => {
23
+ if (outerViewport.getState().isAtBottom !== state.isAtBottom) {
24
+ writableStore(outerViewport).setState({ isAtBottom: state.isAtBottom });
25
+ }
26
+ });
27
+ }, [store, outerViewport]);
28
+ return store;
29
+ };
30
+ var ThreadViewportProvider = ({ children }) => {
31
+ const useThreadViewport = useThreadViewportStoreValue();
32
+ const [context] = useState(() => {
33
+ return {
34
+ useThreadViewport
35
+ };
36
+ });
37
+ return /* @__PURE__ */ jsx(ThreadViewportContext.Provider, { value: context, children });
38
+ };
39
+ export {
40
+ ThreadViewportProvider
41
+ };
42
+ //# sourceMappingURL=ThreadViewportProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/providers/ThreadViewportProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport {\n ThreadViewportContext,\n ThreadViewportContextValue,\n useThreadViewportStore,\n} from \"../react/ThreadViewportContext\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nconst useThreadViewportStoreValue = () => {\n const outerViewport = useThreadViewportStore({ optional: true });\n const [store] = useState(() => makeThreadViewportStore());\n\n useEffect(() => {\n return outerViewport?.getState().onScrollToBottom(() => {\n store.getState().scrollToBottom();\n });\n }, [outerViewport, store]);\n\n useEffect(() => {\n if (!outerViewport) return;\n return store.subscribe((state) => {\n if (outerViewport.getState().isAtBottom !== state.isAtBottom) {\n writableStore(outerViewport).setState({ isAtBottom: state.isAtBottom });\n }\n });\n }, [store, outerViewport]);\n\n return store;\n};\n\nexport const ThreadViewportProvider: FC<PropsWithChildren> = ({ children }) => {\n const useThreadViewport = useThreadViewportStoreValue();\n\n const [context] = useState<ThreadViewportContextValue>(() => {\n return {\n useThreadViewport,\n };\n });\n\n return (\n <ThreadViewportContext.Provider value={context}>\n {children}\n </ThreadViewportContext.Provider>\n );\n};\n"],"mappings":";;;AAGA,SAAS,WAAW,gBAAgB;AACpC,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qBAAqB;AAkC1B;AAhCJ,IAAM,8BAA8B,MAAM;AACxC,QAAM,gBAAgB,uBAAuB,EAAE,UAAU,KAAK,CAAC;AAC/D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,wBAAwB,CAAC;AAExD,YAAU,MAAM;AACd,WAAO,eAAe,SAAS,EAAE,iBAAiB,MAAM;AACtD,YAAM,SAAS,EAAE,eAAe;AAAA,IAClC,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,KAAK,CAAC;AAEzB,YAAU,MAAM;AACd,QAAI,CAAC,cAAe;AACpB,WAAO,MAAM,UAAU,CAAC,UAAU;AAChC,UAAI,cAAc,SAAS,EAAE,eAAe,MAAM,YAAY;AAC5D,sBAAc,aAAa,EAAE,SAAS,EAAE,YAAY,MAAM,WAAW,CAAC;AAAA,MACxE;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,OAAO,aAAa,CAAC;AAEzB,SAAO;AACT;AAEO,IAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,oBAAoB,4BAA4B;AAEtD,QAAM,CAAC,OAAO,IAAI,SAAqC,MAAM;AAC3D,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,SACpC,UACH;AAEJ;","names":[]}
@@ -1,11 +1,9 @@
1
- import type { ThreadViewportState } from "../stores/ThreadViewport";
2
1
  import { ReadonlyStore } from "../ReadonlyStore";
3
2
  import { UseBoundStore } from "zustand";
4
3
  import { ThreadRuntime } from "../../api/ThreadRuntime";
5
4
  import { ModelContext } from "../../model-context";
6
5
  export type ThreadContextValue = {
7
6
  useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;
8
- useViewport: UseBoundStore<ReadonlyStore<ThreadViewportState>>;
9
7
  };
10
8
  export declare const ThreadContext: import("react").Context<ThreadContextValue | null>;
11
9
  export declare function useThreadRuntime(options?: {
@@ -68,22 +66,6 @@ export declare const useThreadComposer: {
68
66
  selector: ((state: import("../..").ThreadComposerState) => TSelected) | undefined;
69
67
  }): import("../..").ThreadComposerState | TSelected | null;
70
68
  };
71
- export declare const useThreadViewport: {
72
- (): ThreadViewportState;
73
- <TSelected>(selector: (state: ThreadViewportState) => TSelected): TSelected;
74
- (options: {
75
- optional: true;
76
- }): ThreadViewportState | null;
77
- <TSelected>(options: {
78
- optional: true;
79
- selector?: (state: ThreadViewportState) => TSelected;
80
- }): TSelected | null;
81
- }, useThreadViewportStore: {
82
- (): ReadonlyStore<ThreadViewportState>;
83
- (options: {
84
- optional: true;
85
- }): ReadonlyStore<ThreadViewportState> | null;
86
- };
87
69
  export declare function useThreadModelContext(options?: {
88
70
  optional?: false | undefined;
89
71
  }): ModelContext;
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ThreadContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,aAA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EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,EAAE,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;CAC/D,CAAC;AAEF,eAAO,MAAM,aAAa,oDAAiD,CAAC;AAO5E,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,aAAa,CAAC;AAClB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,aAAa,GAAG,IAAI,CAAC;AAOzB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;CAA8C,CAAC;AAKrE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,YAAY,CAAC;AACjB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,YAAY,GAAG,IAAI,CAAC"}
@@ -25,14 +25,11 @@ __export(ThreadContext_exports, {
25
25
  useThread: () => useThread,
26
26
  useThreadComposer: () => useThreadComposer,
27
27
  useThreadModelContext: () => useThreadModelContext,
28
- useThreadRuntime: () => useThreadRuntime,
29
- useThreadViewport: () => useThreadViewport,
30
- useThreadViewportStore: () => useThreadViewportStore
28
+ useThreadRuntime: () => useThreadRuntime
31
29
  });
32
30
  module.exports = __toCommonJS(ThreadContext_exports);
33
31
  var import_react = require("react");
34
32
  var import_createContextHook = require("./utils/createContextHook.js");
35
- var import_createContextStoreHook = require("./utils/createContextStoreHook.js");
36
33
  var import_createStateHookForRuntime = require("./utils/createStateHookForRuntime.js");
37
34
  var ThreadContext = (0, import_react.createContext)(null);
38
35
  var useThreadContext = (0, import_createContextHook.createContextHook)(
@@ -49,10 +46,6 @@ var useThreadComposerRuntime = (opt) => useThreadRuntime(opt)?.composer ?? null;
49
46
  var useThreadComposer = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
50
47
  useThreadComposerRuntime
51
48
  );
52
- var {
53
- useViewport: useThreadViewport,
54
- useViewportStore: useThreadViewportStore
55
- } = (0, import_createContextStoreHook.createContextStoreHook)(useThreadContext, "useViewport");
56
49
  function useThreadModelContext(options) {
57
50
  const [, rerender] = (0, import_react.useState)({});
58
51
  const runtime = useThreadRuntime(options);
@@ -68,8 +61,6 @@ function useThreadModelContext(options) {
68
61
  useThread,
69
62
  useThreadComposer,
70
63
  useThreadModelContext,
71
- useThreadRuntime,
72
- useThreadViewport,
73
- useThreadViewportStore
64
+ useThreadRuntime
74
65
  });
75
66
  //# sourceMappingURL=ThreadContext.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport type { ThreadViewportState } from \"../stores/ThreadViewport\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../../api\";\n\nexport type ThreadContextValue = {\n useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;\n useViewport: UseBoundStore<ReadonlyStore<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nconst useThreadContext = createContextHook(\n ThreadContext,\n \"AssistantRuntimeProvider\",\n);\n\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const context = useThreadContext(options);\n if (!context) return null;\n return context.useThreadRuntime();\n}\n\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport const {\n useViewport: useThreadViewport,\n useViewportStore: useThreadViewportStore,\n} = createContextStoreHook(useThreadContext, \"useViewport\");\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useEffect(() => {\n return runtime?.unstable_on(\"model-context-update\", () => rerender({}));\n }, [runtime]);\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAmD;AAInD,+BAAkC;AAClC,oCAAuC;AAGvC,uCAA0C;AAQnC,IAAM,oBAAgB,4BAAyC,IAAI;AAE1E,IAAM,uBAAmB;AAAA,EACvB;AAAA,EACA;AACF;AAQO,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,UAAU,iBAAiB,OAAO;AACxC,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,iBAAiB;AAClC;AAEO,IAAM,gBAAY,4DAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,wBAAoB;AAAA,EAC/B;AACF;AAEO,IAAM;AAAA,EACX,aAAa;AAAA,EACb,kBAAkB;AACpB,QAAI,sDAAuB,kBAAkB,aAAa;AAQnD,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,QAAI,uBAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,8BAAU,MAAM;AACd,WAAO,SAAS,YAAY,wBAAwB,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,EACxE,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../../api\";\n\nexport type ThreadContextValue = {\n useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nconst useThreadContext = createContextHook(\n ThreadContext,\n \"AssistantRuntimeProvider\",\n);\n\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const context = useThreadContext(options);\n if (!context) return null;\n return context.useThreadRuntime();\n}\n\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useEffect(() => {\n return runtime?.unstable_on(\"model-context-update\", () => rerender({}));\n }, [runtime]);\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAmD;AAGnD,+BAAkC;AAGlC,uCAA0C;AAOnC,IAAM,oBAAgB,4BAAyC,IAAI;AAE1E,IAAM,uBAAmB;AAAA,EACvB;AAAA,EACA;AACF;AAQO,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,UAAU,iBAAiB,OAAO;AACxC,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,iBAAiB;AAClC;AAEO,IAAM,gBAAY,4DAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,wBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,QAAI,uBAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,8BAAU,MAAM;AACd,WAAO,SAAS,YAAY,wBAAwB,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,EACxE,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
@@ -3,7 +3,6 @@
3
3
  // src/context/react/ThreadContext.ts
4
4
  import { createContext, useEffect, useState } from "react";
5
5
  import { createContextHook } from "./utils/createContextHook.mjs";
6
- import { createContextStoreHook } from "./utils/createContextStoreHook.mjs";
7
6
  import { createStateHookForRuntime } from "./utils/createStateHookForRuntime.mjs";
8
7
  var ThreadContext = createContext(null);
9
8
  var useThreadContext = createContextHook(
@@ -20,10 +19,6 @@ var useThreadComposerRuntime = (opt) => useThreadRuntime(opt)?.composer ?? null;
20
19
  var useThreadComposer = createStateHookForRuntime(
21
20
  useThreadComposerRuntime
22
21
  );
23
- var {
24
- useViewport: useThreadViewport,
25
- useViewportStore: useThreadViewportStore
26
- } = createContextStoreHook(useThreadContext, "useViewport");
27
22
  function useThreadModelContext(options) {
28
23
  const [, rerender] = useState({});
29
24
  const runtime = useThreadRuntime(options);
@@ -38,8 +33,6 @@ export {
38
33
  useThread,
39
34
  useThreadComposer,
40
35
  useThreadModelContext,
41
- useThreadRuntime,
42
- useThreadViewport,
43
- useThreadViewportStore
36
+ useThreadRuntime
44
37
  };
45
38
  //# sourceMappingURL=ThreadContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport type { ThreadViewportState } from \"../stores/ThreadViewport\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../../api\";\n\nexport type ThreadContextValue = {\n useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;\n useViewport: UseBoundStore<ReadonlyStore<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nconst useThreadContext = createContextHook(\n ThreadContext,\n \"AssistantRuntimeProvider\",\n);\n\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const context = useThreadContext(options);\n if (!context) return null;\n return context.useThreadRuntime();\n}\n\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport const {\n useViewport: useThreadViewport,\n useViewportStore: useThreadViewportStore,\n} = createContextStoreHook(useThreadContext, \"useViewport\");\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useEffect(() => {\n return runtime?.unstable_on(\"model-context-update\", () => rerender({}));\n }, [runtime]);\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,eAAe,WAAW,gBAAgB;AAInD,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAGvC,SAAS,iCAAiC;AAQnC,IAAM,gBAAgB,cAAyC,IAAI;AAE1E,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AACF;AAQO,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,UAAU,iBAAiB,OAAO;AACxC,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,iBAAiB;AAClC;AAEO,IAAM,YAAY,0BAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAEO,IAAM;AAAA,EACX,aAAa;AAAA,EACb,kBAAkB;AACpB,IAAI,uBAAuB,kBAAkB,aAAa;AAQnD,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,YAAU,MAAM;AACd,WAAO,SAAS,YAAY,wBAAwB,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,EACxE,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../../api\";\n\nexport type ThreadContextValue = {\n useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nconst useThreadContext = createContextHook(\n ThreadContext,\n \"AssistantRuntimeProvider\",\n);\n\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const context = useThreadContext(options);\n if (!context) return null;\n return context.useThreadRuntime();\n}\n\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useEffect(() => {\n return runtime?.unstable_on(\"model-context-update\", () => rerender({}));\n }, [runtime]);\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,eAAe,WAAW,gBAAgB;AAGnD,SAAS,yBAAyB;AAGlC,SAAS,iCAAiC;AAOnC,IAAM,gBAAgB,cAAyC,IAAI;AAE1E,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AACF;AAQO,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,UAAU,iBAAiB,OAAO;AACxC,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,iBAAiB;AAClC;AAEO,IAAM,YAAY,0BAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,YAAU,MAAM;AACd,WAAO,SAAS,YAAY,wBAAwB,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,EACxE,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}