@assistant-ui/react 0.7.46 → 0.7.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/api/AssistantRuntime.d.ts +1 -0
  2. package/dist/api/AssistantRuntime.d.ts.map +1 -1
  3. package/dist/api/AssistantRuntime.js +5 -0
  4. package/dist/api/AssistantRuntime.js.map +1 -1
  5. package/dist/api/AssistantRuntime.mjs +5 -0
  6. package/dist/api/AssistantRuntime.mjs.map +1 -1
  7. package/dist/api/AttachmentRuntime.d.ts +1 -0
  8. package/dist/api/AttachmentRuntime.d.ts.map +1 -1
  9. package/dist/api/AttachmentRuntime.js +5 -0
  10. package/dist/api/AttachmentRuntime.js.map +1 -1
  11. package/dist/api/AttachmentRuntime.mjs +5 -0
  12. package/dist/api/AttachmentRuntime.mjs.map +1 -1
  13. package/dist/api/ComposerRuntime.d.ts +2 -0
  14. package/dist/api/ComposerRuntime.d.ts.map +1 -1
  15. package/dist/api/ComposerRuntime.js +19 -0
  16. package/dist/api/ComposerRuntime.js.map +1 -1
  17. package/dist/api/ComposerRuntime.mjs +19 -0
  18. package/dist/api/ComposerRuntime.mjs.map +1 -1
  19. package/dist/api/ContentPartRuntime.d.ts +1 -0
  20. package/dist/api/ContentPartRuntime.d.ts.map +1 -1
  21. package/dist/api/ContentPartRuntime.js +5 -0
  22. package/dist/api/ContentPartRuntime.js.map +1 -1
  23. package/dist/api/ContentPartRuntime.mjs +5 -0
  24. package/dist/api/ContentPartRuntime.mjs.map +1 -1
  25. package/dist/api/MessageRuntime.d.ts +1 -0
  26. package/dist/api/MessageRuntime.d.ts.map +1 -1
  27. package/dist/api/MessageRuntime.js +13 -0
  28. package/dist/api/MessageRuntime.js.map +1 -1
  29. package/dist/api/MessageRuntime.mjs +13 -0
  30. package/dist/api/MessageRuntime.mjs.map +1 -1
  31. package/dist/api/ThreadListItemRuntime.d.ts +1 -0
  32. package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
  33. package/dist/api/ThreadListItemRuntime.js +11 -0
  34. package/dist/api/ThreadListItemRuntime.js.map +1 -1
  35. package/dist/api/ThreadListItemRuntime.mjs +11 -0
  36. package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
  37. package/dist/api/ThreadListRuntime.d.ts +1 -0
  38. package/dist/api/ThreadListRuntime.d.ts.map +1 -1
  39. package/dist/api/ThreadListRuntime.js +10 -0
  40. package/dist/api/ThreadListRuntime.js.map +1 -1
  41. package/dist/api/ThreadListRuntime.mjs +10 -0
  42. package/dist/api/ThreadListRuntime.mjs.map +1 -1
  43. package/dist/api/ThreadRuntime.d.ts +1 -1
  44. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  45. package/dist/api/ThreadRuntime.js +14 -3
  46. package/dist/api/ThreadRuntime.js.map +1 -1
  47. package/dist/api/ThreadRuntime.mjs +14 -3
  48. package/dist/api/ThreadRuntime.mjs.map +1 -1
  49. package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
  50. package/dist/context/providers/AssistantRuntimeProvider.js +5 -14
  51. package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
  52. package/dist/context/providers/AssistantRuntimeProvider.mjs +5 -14
  53. package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
  54. package/dist/context/providers/AttachmentRuntimeProvider.d.ts.map +1 -1
  55. package/dist/context/providers/AttachmentRuntimeProvider.js +5 -16
  56. package/dist/context/providers/AttachmentRuntimeProvider.js.map +1 -1
  57. package/dist/context/providers/AttachmentRuntimeProvider.mjs +6 -21
  58. package/dist/context/providers/AttachmentRuntimeProvider.mjs.map +1 -1
  59. package/dist/context/providers/ContentPartRuntimeProvider.d.ts +0 -1
  60. package/dist/context/providers/ContentPartRuntimeProvider.d.ts.map +1 -1
  61. package/dist/context/providers/ContentPartRuntimeProvider.js +5 -15
  62. package/dist/context/providers/ContentPartRuntimeProvider.js.map +1 -1
  63. package/dist/context/providers/ContentPartRuntimeProvider.mjs +4 -13
  64. package/dist/context/providers/ContentPartRuntimeProvider.mjs.map +1 -1
  65. package/dist/context/providers/MessageRuntimeProvider.d.ts.map +1 -1
  66. package/dist/context/providers/MessageRuntimeProvider.js +3 -22
  67. package/dist/context/providers/MessageRuntimeProvider.js.map +1 -1
  68. package/dist/context/providers/MessageRuntimeProvider.mjs +3 -22
  69. package/dist/context/providers/MessageRuntimeProvider.mjs.map +1 -1
  70. package/dist/context/providers/TextContentPartProvider.d.ts.map +1 -1
  71. package/dist/context/providers/TextContentPartProvider.js +13 -12
  72. package/dist/context/providers/TextContentPartProvider.js.map +1 -1
  73. package/dist/context/providers/TextContentPartProvider.mjs +13 -12
  74. package/dist/context/providers/TextContentPartProvider.mjs.map +1 -1
  75. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts +0 -1
  76. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -1
  77. package/dist/context/providers/ThreadListItemRuntimeProvider.js +5 -15
  78. package/dist/context/providers/ThreadListItemRuntimeProvider.js.map +1 -1
  79. package/dist/context/providers/ThreadListItemRuntimeProvider.mjs +4 -13
  80. package/dist/context/providers/ThreadListItemRuntimeProvider.mjs.map +1 -1
  81. package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
  82. package/dist/context/providers/ThreadRuntimeProvider.js +5 -24
  83. package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
  84. package/dist/context/providers/ThreadRuntimeProvider.mjs +6 -25
  85. package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
  86. package/dist/context/react/AssistantContext.d.ts +26 -17
  87. package/dist/context/react/AssistantContext.d.ts.map +1 -1
  88. package/dist/context/react/AssistantContext.js +3 -4
  89. package/dist/context/react/AssistantContext.js.map +1 -1
  90. package/dist/context/react/AssistantContext.mjs +3 -4
  91. package/dist/context/react/AssistantContext.mjs.map +1 -1
  92. package/dist/context/react/AttachmentContext.d.ts +558 -30
  93. package/dist/context/react/AttachmentContext.d.ts.map +1 -1
  94. package/dist/context/react/AttachmentContext.js +32 -52
  95. package/dist/context/react/AttachmentContext.js.map +1 -1
  96. package/dist/context/react/AttachmentContext.mjs +33 -52
  97. package/dist/context/react/AttachmentContext.mjs.map +1 -1
  98. package/dist/context/react/ComposerContext.d.ts +28 -19
  99. package/dist/context/react/ComposerContext.d.ts.map +1 -1
  100. package/dist/context/react/ComposerContext.js +2 -19
  101. package/dist/context/react/ComposerContext.js.map +1 -1
  102. package/dist/context/react/ComposerContext.mjs +4 -20
  103. package/dist/context/react/ComposerContext.mjs.map +1 -1
  104. package/dist/context/react/ContentPartContext.d.ts +22 -16
  105. package/dist/context/react/ContentPartContext.d.ts.map +1 -1
  106. package/dist/context/react/ContentPartContext.js +2 -7
  107. package/dist/context/react/ContentPartContext.js.map +1 -1
  108. package/dist/context/react/ContentPartContext.mjs +2 -6
  109. package/dist/context/react/ContentPartContext.mjs.map +1 -1
  110. package/dist/context/react/MessageContext.d.ts +49 -29
  111. package/dist/context/react/MessageContext.d.ts.map +1 -1
  112. package/dist/context/react/MessageContext.js +5 -9
  113. package/dist/context/react/MessageContext.js.map +1 -1
  114. package/dist/context/react/MessageContext.mjs +5 -8
  115. package/dist/context/react/MessageContext.mjs.map +1 -1
  116. package/dist/context/react/ThreadContext.d.ts +44 -24
  117. package/dist/context/react/ThreadContext.d.ts.map +1 -1
  118. package/dist/context/react/ThreadContext.js +5 -9
  119. package/dist/context/react/ThreadContext.js.map +1 -1
  120. package/dist/context/react/ThreadContext.mjs +5 -8
  121. package/dist/context/react/ThreadContext.mjs.map +1 -1
  122. package/dist/context/react/ThreadListItemContext.d.ts +22 -16
  123. package/dist/context/react/ThreadListItemContext.d.ts.map +1 -1
  124. package/dist/context/react/ThreadListItemContext.js +3 -6
  125. package/dist/context/react/ThreadListItemContext.js.map +1 -1
  126. package/dist/context/react/ThreadListItemContext.mjs +3 -5
  127. package/dist/context/react/ThreadListItemContext.mjs.map +1 -1
  128. package/dist/context/react/index.d.ts +1 -0
  129. package/dist/context/react/index.d.ts.map +1 -1
  130. package/dist/context/react/index.js +3 -0
  131. package/dist/context/react/index.js.map +1 -1
  132. package/dist/context/react/index.mjs +2 -0
  133. package/dist/context/react/index.mjs.map +1 -1
  134. package/dist/context/react/utils/createContextHook.d.ts +3 -8
  135. package/dist/context/react/utils/createContextHook.d.ts.map +1 -1
  136. package/dist/context/react/utils/createContextHook.js.map +1 -1
  137. package/dist/context/react/utils/createContextHook.mjs.map +1 -1
  138. package/dist/context/react/utils/createStateHookForRuntime.d.ts +31 -0
  139. package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +1 -0
  140. package/dist/context/react/utils/createStateHookForRuntime.js +47 -0
  141. package/dist/context/react/utils/createStateHookForRuntime.js.map +1 -0
  142. package/dist/context/react/utils/createStateHookForRuntime.mjs +24 -0
  143. package/dist/context/react/utils/createStateHookForRuntime.mjs.map +1 -0
  144. package/dist/context/react/utils/ensureBinding.d.ts +2 -0
  145. package/dist/context/react/utils/ensureBinding.d.ts.map +1 -0
  146. package/dist/context/react/utils/ensureBinding.js +36 -0
  147. package/dist/context/react/utils/ensureBinding.js.map +1 -0
  148. package/dist/context/react/utils/ensureBinding.mjs +11 -0
  149. package/dist/context/react/utils/ensureBinding.mjs.map +1 -0
  150. package/dist/context/react/utils/useRuntimeState.d.ts +10 -0
  151. package/dist/context/react/utils/useRuntimeState.d.ts.map +1 -0
  152. package/dist/context/react/utils/useRuntimeState.js +48 -0
  153. package/dist/context/react/utils/useRuntimeState.js.map +1 -0
  154. package/dist/context/react/utils/useRuntimeState.mjs +22 -0
  155. package/dist/context/react/utils/useRuntimeState.mjs.map +1 -0
  156. package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts +1 -1
  157. package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts.map +1 -1
  158. package/dist/runtimes/adapters/attachment/AttachmentAdapter.js.map +1 -1
  159. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts +1 -1
  160. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts.map +1 -1
  161. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js +1 -1
  162. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js.map +1 -1
  163. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs +1 -1
  164. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs.map +1 -1
  165. package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.d.ts.map +1 -1
  166. package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.js.map +1 -1
  167. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
  168. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +22 -2
  169. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  170. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +22 -2
  171. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
  172. package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
  173. package/dist/runtimes/local/useLocalRuntime.js +4 -0
  174. package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
  175. package/dist/runtimes/local/useLocalRuntime.mjs +4 -0
  176. package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
  177. package/package.json +3 -3
  178. package/src/api/AssistantRuntime.ts +7 -0
  179. package/src/api/AttachmentRuntime.ts +6 -0
  180. package/src/api/ComposerRuntime.ts +21 -0
  181. package/src/api/ContentPartRuntime.ts +6 -0
  182. package/src/api/MessageRuntime.ts +15 -0
  183. package/src/api/ThreadListItemRuntime.ts +12 -0
  184. package/src/api/ThreadListRuntime.ts +11 -0
  185. package/src/api/ThreadRuntime.ts +15 -4
  186. package/src/context/providers/AssistantRuntimeProvider.tsx +5 -17
  187. package/src/context/providers/AttachmentRuntimeProvider.tsx +6 -24
  188. package/src/context/providers/ContentPartRuntimeProvider.tsx +4 -14
  189. package/src/context/providers/MessageRuntimeProvider.tsx +5 -31
  190. package/src/context/providers/TextContentPartProvider.tsx +26 -22
  191. package/src/context/providers/ThreadListItemRuntimeProvider.tsx +3 -14
  192. package/src/context/providers/ThreadRuntimeProvider.tsx +7 -33
  193. package/src/context/react/AssistantContext.ts +7 -7
  194. package/src/context/react/AttachmentContext.ts +45 -136
  195. package/src/context/react/ComposerContext.ts +6 -29
  196. package/src/context/react/ContentPartContext.ts +3 -8
  197. package/src/context/react/MessageContext.ts +10 -13
  198. package/src/context/react/ThreadContext.ts +9 -12
  199. package/src/context/react/ThreadListItemContext.ts +4 -7
  200. package/src/context/react/index.ts +2 -0
  201. package/src/context/react/utils/createContextHook.ts +1 -3
  202. package/src/context/react/utils/createStateHookForRuntime.ts +80 -0
  203. package/src/context/react/utils/ensureBinding.ts +45 -0
  204. package/src/context/react/utils/useRuntimeState.ts +43 -0
  205. package/src/runtimes/adapters/attachment/AttachmentAdapter.ts +3 -1
  206. package/src/runtimes/adapters/attachment/CompositeAttachmentAdapter.ts +1 -1
  207. package/src/runtimes/adapters/thread-history/ThreadHistoryAdapter.ts +1 -0
  208. package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +24 -2
  209. package/src/runtimes/local/useLocalRuntime.tsx +5 -0
@@ -96,6 +96,20 @@ var ThreadRuntimeImpl = class {
96
96
  })
97
97
  );
98
98
  }
99
+ __internal_bindMethods() {
100
+ this.append = this.append.bind(this);
101
+ this.startRun = this.startRun.bind(this);
102
+ this.cancelRun = this.cancelRun.bind(this);
103
+ this.stopSpeaking = this.stopSpeaking.bind(this);
104
+ this.export = this.export.bind(this);
105
+ this.import = this.import.bind(this);
106
+ this.getMesssageByIndex = this.getMesssageByIndex.bind(this);
107
+ this.getMesssageById = this.getMesssageById.bind(this);
108
+ this.subscribe = this.subscribe.bind(this);
109
+ this.unstable_on = this.unstable_on.bind(this);
110
+ this.getModelConfig = this.getModelConfig.bind(this);
111
+ this.getState = this.getState.bind(this);
112
+ }
99
113
  composer;
100
114
  getState() {
101
115
  return this._threadBinding.getStateState();
@@ -121,9 +135,6 @@ var ThreadRuntimeImpl = class {
121
135
  stopSpeaking() {
122
136
  return this._threadBinding.getState().stopSpeaking();
123
137
  }
124
- getSubmittedFeedback(messageId) {
125
- return this._threadBinding.getState().getSubmittedFeedback(messageId);
126
- }
127
138
  export() {
128
139
  return this._threadBinding.getState().export();
129
140
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n ThreadRuntimeEventType,\n StartRunConfig,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./RuntimePathTypes\";\nimport { ThreadListItemState } from \"./ThreadListItemRuntime\";\nimport { RunConfig } from \"../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n ...message,\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n /**\n * @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.\n */\n startRun(parentId: string | null): void;\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n public startRun(configOrParentId: string | null | CreateStartRunConfig) {\n const config =\n configOrParentId === null || typeof configOrParentId === \"string\"\n ? { parentId: configOrParentId }\n : configOrParentId;\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAeA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAQ5B,SAAS,gCAAgC;AAQzC,IAAM,mBAAmB,CAAC,YAAkD;AAC1E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AAAA,IAC9B,WAAW,QAAQ,aAAa,CAAC;AAAA,EACnC;AACF;AAaA,IAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,UAAU;AAAA,MACV,WAAW,CAAC;AAAA,MACZ,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa;AAC3D,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,QAAQ,YAAY,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,IACrD,UAAU,QAAQ,YAAY;AAAA,IAC9B,MAAM,QAAQ,QAAQ;AAAA,IACtB,aAAa,QAAQ,eAAe,CAAC;AAAA,EACvC;AACF;AAgEO,IAAM,iBAAiB,CAC5B,SACA,wBACgB;AAChB,QAAM,cAAc,QAAQ,SAAS,GAAG,EAAE;AAC1C,SA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,cAAc,QAAQ,KAAK,cAAc;AAAA,YAExD;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,6BAA6B,oBAAI,IAGvC;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,2BAA2B,IAAI,KAAK;AACvD,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,yBAAyB;AAAA,QACrC;AAAA,QACA,SAAS,KAAK;AAAA,MAChB,CAAC;AACD,WAAK,2BAA2B,IAAI,OAAO,OAAO;AAAA,IACpD;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
1
+ {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n ThreadRuntimeEventType,\n StartRunConfig,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./RuntimePathTypes\";\nimport { ThreadListItemState } from \"./ThreadListItemRuntime\";\nimport { RunConfig } from \"../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n ...message,\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n /**\n * @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.\n */\n startRun(parentId: string | null): void;\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.getMesssageByIndex = this.getMesssageByIndex.bind(this);\n this.getMesssageById = this.getMesssageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelConfig = this.getModelConfig.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n public startRun(configOrParentId: string | null | CreateStartRunConfig) {\n const config =\n configOrParentId === null || typeof configOrParentId === \"string\"\n ? { parentId: configOrParentId }\n : configOrParentId;\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAeA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAQ5B,SAAS,gCAAgC;AAQzC,IAAM,mBAAmB,CAAC,YAAkD;AAC1E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AAAA,IAC9B,WAAW,QAAQ,aAAa,CAAC;AAAA,EACnC;AACF;AAaA,IAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,UAAU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AAI,UAAU,KAAK,2BAA2B,IAAI,KAAK;AACvD,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,yBAAyB;AAAA,QACrC;AAAA,QACA,SAAS,KAAK;AAAA,MAChB,CAAC;AACD,WAAK,2BAA2B,IAAI,OAAO,OAAO;AAAA,IACpD;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,EAAE,EACF,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAK9D,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;AAiCD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,wBAAwB,CAAC,KAAK,CA0B/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,sEAAqC,CAAC"}
1
+ {"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,EAAE,EACF,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAM9D,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;AAsBD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,wBAAwB,CAAC,KAAK,CAwB/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,sEAAqC,CAAC"}
@@ -31,10 +31,12 @@ var import_AssistantToolUIs = require("../stores/AssistantToolUIs.js");
31
31
  var import_ThreadRuntimeProvider = require("./ThreadRuntimeProvider.js");
32
32
  var import_zustand = require("zustand");
33
33
  var import_ReadonlyStore = require("../ReadonlyStore.js");
34
+ var import_ensureBinding = require("../react/utils/ensureBinding.js");
34
35
  var import_jsx_runtime = require("react/jsx-runtime");
35
36
  var useAssistantRuntimeStore = (runtime) => {
36
37
  const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime));
37
38
  (0, import_react.useEffect)(() => {
39
+ (0, import_ensureBinding.ensureBinding)(runtime);
38
40
  (0, import_ReadonlyStore.writableStore)(store).setState(runtime, true);
39
41
  }, [runtime, store]);
40
42
  return store;
@@ -42,29 +44,18 @@ var useAssistantRuntimeStore = (runtime) => {
42
44
  var useAssistantToolUIsStore = () => {
43
45
  return (0, import_react.useMemo)(() => (0, import_AssistantToolUIs.makeAssistantToolUIsStore)(), []);
44
46
  };
45
- var useThreadListStore = (runtime) => {
46
- const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime.threadList.getState()));
47
- (0, import_react.useEffect)(() => {
48
- const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.threadList.getState(), true);
49
- updateState();
50
- return runtime.threadList.subscribe(updateState);
51
- }, [runtime, store]);
52
- return store;
53
- };
54
47
  var getRenderComponent = (runtime) => {
55
48
  return runtime._core?.RenderComponent;
56
49
  };
57
50
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
58
51
  const useAssistantRuntime = useAssistantRuntimeStore(runtime);
59
52
  const useToolUIs = useAssistantToolUIsStore();
60
- const useThreadList = useThreadListStore(runtime);
61
- const context = (0, import_react.useMemo)(() => {
53
+ const [context] = (0, import_react.useState)(() => {
62
54
  return {
63
55
  useToolUIs,
64
- useAssistantRuntime,
65
- useThreadList
56
+ useAssistantRuntime
66
57
  };
67
- }, [useAssistantRuntime, useToolUIs, useThreadList]);
58
+ });
68
59
  const RenderComponent = getRenderComponent(runtime);
69
60
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_AssistantContext.AssistantContext.Provider, { value: context, children: [
70
61
  RenderComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RenderComponent, {}),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst useThreadListStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime.threadList.getState()));\n\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.threadList.getState(), true);\n updateState();\n return runtime.threadList.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const useThreadList = useThreadListStore(runtime);\n const context = useMemo(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n useThreadList,\n };\n }, [useAssistantRuntime, useToolUIs, useThreadList]);\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantContext.Provider value={context}>\n {RenderComponent && <RenderComponent />}\n <ThreadRuntimeProvider\n runtime={runtime.thread}\n listItemRuntime={runtime.threadList.mainItem}\n >\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAOO;AACP,8BAAiC;AACjC,8BAA0C;AAC1C,mCAAsC;AAEtC,qBAAuB;AACvB,2BAA8B;AA4D1B;AAhDJ,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,aAAO,sBAAQ,UAAM,mDAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,WAAW,SAAS,CAAC,CAAC;AAE1E,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,WAAW,SAAS,GAAG,IAAI;AACnE,gBAAY;AACZ,WAAO,QAAQ,WAAW,UAAU,WAAW;AAAA,EACjD,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,cAAU,sBAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,YAAY,aAAa,CAAC;AAEnD,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,6CAAC,yCAAiB,UAAjB,EAA0B,OAAO,SAC/B;AAAA,uBAAmB,4CAAC,mBAAgB;AAAA,IACrC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,QAAQ;AAAA,QACjB,iBAAiB,QAAQ,WAAW;AAAA,QAEnC;AAAA;AAAA,IACH;AAAA,KACF;AAEJ;AAEO,IAAM,+BAA2B,mBAAK,4BAA4B;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n \n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const [context] = useState(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n };\n });\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantContext.Provider value={context}>\n {RenderComponent && <RenderComponent />}\n <ThreadRuntimeProvider\n runtime={runtime.thread}\n listItemRuntime={runtime.threadList.mainItem}\n >\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAOO;AACP,8BAAiC;AACjC,8BAA0C;AAC1C,mCAAsC;AAEtC,qBAAuB;AACvB,2BAA8B;AAE9B,2BAA8B;AA8C1B;AAnCJ,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AAErB,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,aAAO,sBAAQ,UAAM,mDAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,6CAAC,yCAAiB,UAAjB,EAA0B,OAAO,SAC/B;AAAA,uBAAmB,4CAAC,mBAAgB;AAAA,IACrC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,QAAQ;AAAA,QACjB,iBAAiB,QAAQ,WAAW;AAAA,QAEnC;AAAA;AAAA,IACH;AAAA,KACF;AAEJ;AAEO,IAAM,+BAA2B,mBAAK,4BAA4B;","names":[]}
@@ -12,10 +12,12 @@ import { makeAssistantToolUIsStore } from "../stores/AssistantToolUIs.mjs";
12
12
  import { ThreadRuntimeProvider } from "./ThreadRuntimeProvider.mjs";
13
13
  import { create } from "zustand";
14
14
  import { writableStore } from "../ReadonlyStore.mjs";
15
+ import { ensureBinding } from "../react/utils/ensureBinding.mjs";
15
16
  import { jsx, jsxs } from "react/jsx-runtime";
16
17
  var useAssistantRuntimeStore = (runtime) => {
17
18
  const [store] = useState(() => create(() => runtime));
18
19
  useEffect(() => {
20
+ ensureBinding(runtime);
19
21
  writableStore(store).setState(runtime, true);
20
22
  }, [runtime, store]);
21
23
  return store;
@@ -23,29 +25,18 @@ var useAssistantRuntimeStore = (runtime) => {
23
25
  var useAssistantToolUIsStore = () => {
24
26
  return useMemo(() => makeAssistantToolUIsStore(), []);
25
27
  };
26
- var useThreadListStore = (runtime) => {
27
- const [store] = useState(() => create(() => runtime.threadList.getState()));
28
- useEffect(() => {
29
- const updateState = () => writableStore(store).setState(runtime.threadList.getState(), true);
30
- updateState();
31
- return runtime.threadList.subscribe(updateState);
32
- }, [runtime, store]);
33
- return store;
34
- };
35
28
  var getRenderComponent = (runtime) => {
36
29
  return runtime._core?.RenderComponent;
37
30
  };
38
31
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
39
32
  const useAssistantRuntime = useAssistantRuntimeStore(runtime);
40
33
  const useToolUIs = useAssistantToolUIsStore();
41
- const useThreadList = useThreadListStore(runtime);
42
- const context = useMemo(() => {
34
+ const [context] = useState(() => {
43
35
  return {
44
36
  useToolUIs,
45
- useAssistantRuntime,
46
- useThreadList
37
+ useAssistantRuntime
47
38
  };
48
- }, [useAssistantRuntime, useToolUIs, useThreadList]);
39
+ });
49
40
  const RenderComponent = getRenderComponent(runtime);
50
41
  return /* @__PURE__ */ jsxs(AssistantContext.Provider, { value: context, children: [
51
42
  RenderComponent && /* @__PURE__ */ jsx(RenderComponent, {}),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst useThreadListStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime.threadList.getState()));\n\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.threadList.getState(), true);\n updateState();\n return runtime.threadList.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const useThreadList = useThreadListStore(runtime);\n const context = useMemo(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n useThreadList,\n };\n }, [useAssistantRuntime, useToolUIs, useThreadList]);\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantContext.Provider value={context}>\n {RenderComponent && <RenderComponent />}\n <ThreadRuntimeProvider\n runtime={runtime.thread}\n listItemRuntime={runtime.threadList.mainItem}\n >\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AA4D1B,SACsB,KADtB;AAhDJ,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,SAAO,QAAQ,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,QAAQ,WAAW,SAAS,CAAC,CAAC;AAE1E,YAAU,MAAM;AACd,UAAM,cAAc,MAClB,cAAc,KAAK,EAAE,SAAS,QAAQ,WAAW,SAAS,GAAG,IAAI;AACnE,gBAAY;AACZ,WAAO,QAAQ,WAAW,UAAU,WAAW;AAAA,EACjD,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,UAAU,QAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,YAAY,aAAa,CAAC;AAEnD,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,qBAAC,iBAAiB,UAAjB,EAA0B,OAAO,SAC/B;AAAA,uBAAmB,oBAAC,mBAAgB;AAAA,IACrC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,QAAQ;AAAA,QACjB,iBAAiB,QAAQ,WAAW;AAAA,QAEnC;AAAA;AAAA,IACH;AAAA,KACF;AAEJ;AAEO,IAAM,2BAA2B,KAAK,4BAA4B;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n \n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const [context] = useState(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n };\n });\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantContext.Provider value={context}>\n {RenderComponent && <RenderComponent />}\n <ThreadRuntimeProvider\n runtime={runtime.thread}\n listItemRuntime={runtime.threadList.mainItem}\n >\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AA8C1B,SACsB,KADtB;AAnCJ,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AAErB,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,SAAO,QAAQ,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,qBAAC,iBAAiB,UAAjB,EAA0B,OAAO,SAC/B;AAAA,uBAAmB,oBAAC,mBAAgB;AAAA,IACrC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,QAAQ;AAAA,QACjB,iBAAiB,QAAQ,WAAW;AAAA,QAEnC;AAAA;AAAA,IACH;AAAA,KACF;AAEJ;AAEO,IAAM,2BAA2B,KAAK,4BAA4B;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"AttachmentRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EAAE,EACP,KAAK,iBAAiB,EAIvB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,yBAAiB,yBAAyB,CAAC;IACzC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,iBAAiB,CAAC;KAC5B,CAAC,CAAC;CACJ;AAuBD,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,yBAAyB,CAAC,KAAK,CAoBzE,CAAC"}
1
+ {"version":3,"file":"AttachmentRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAI7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,yBAAiB,yBAAyB,CAAC;IACzC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,iBAAiB,CAAC;KAC5B,CAAC,CAAC;CACJ;AAcD,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,yBAAyB,CAAC,KAAK,CAgBzE,CAAC"}
@@ -28,37 +28,26 @@ var import_react = require("react");
28
28
  var import_zustand = require("zustand");
29
29
  var import_AttachmentContext = require("../react/AttachmentContext.js");
30
30
  var import_ReadonlyStore = require("../ReadonlyStore.js");
31
+ var import_ensureBinding = require("../react/utils/ensureBinding.js");
31
32
  var import_jsx_runtime = require("react/jsx-runtime");
32
33
  var useAttachmentRuntimeStore = (runtime) => {
33
34
  const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime));
34
35
  (0, import_react.useEffect)(() => {
36
+ (0, import_ensureBinding.ensureBinding)(runtime);
35
37
  (0, import_ReadonlyStore.writableStore)(store).setState(runtime, true);
36
38
  }, [runtime, store]);
37
39
  return store;
38
40
  };
39
- var useAttachmentStore = (runtime) => {
40
- const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime.getState()));
41
- (0, import_react.useEffect)(() => {
42
- const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.getState(), true);
43
- updateState();
44
- return runtime.subscribe(updateState);
45
- }, [runtime, store]);
46
- return store;
47
- };
48
41
  var AttachmentRuntimeProvider = ({
49
42
  runtime,
50
43
  children
51
44
  }) => {
52
45
  const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);
53
- const useAttachment = useAttachmentStore(runtime);
54
- const source = useAttachment((s) => s.source);
55
- const context = (0, import_react.useMemo)(() => {
46
+ const [context] = (0, import_react.useState)(() => {
56
47
  return {
57
- source,
58
- useAttachmentRuntime,
59
- useAttachment
48
+ useAttachmentRuntime
60
49
  };
61
- }, [useAttachmentRuntime, useAttachment]);
50
+ });
62
51
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_AttachmentContext.AttachmentContext.Provider, { value: context, children });
63
52
  };
64
53
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FC,\n type PropsWithChildren,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\n\nexport namespace AttachmentRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: AttachmentRuntime;\n }>;\n}\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\nconst useAttachmentStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const useAttachment = useAttachmentStore(runtime);\n const source = useAttachment((s) => s.source);\n const context = useMemo(() => {\n return {\n source,\n useAttachmentRuntime,\n useAttachment,\n };\n }, [useAttachmentRuntime, useAttachment]);\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAMO;AACP,qBAAuB;AACvB,+BAAkC;AAClC,2BAA8B;AA8C1B;AArCJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AACA,IAAM,qBAAqB,CAAC,YAA+B;AACzD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAiE,CAAC;AAAA,EAC7E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,SAAS,cAAc,CAAC,MAAM,EAAE,MAAM;AAC5C,QAAM,cAAU,sBAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,sBAAsB,aAAa,CAAC;AAExC,SACE,4CAAC,2CAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AttachmentRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: AttachmentRuntime;\n }>;\n}\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const [context] = useState(() => {\n return {\n useAttachmentRuntime,\n };\n });\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqE;AACrE,qBAAuB;AACvB,+BAAkC;AAClC,2BAA8B;AAE9B,2BAA8B;AAgC1B;AAxBJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AAErB,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAiE,CAAC;AAAA,EAC7E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,4CAAC,2CAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}
@@ -1,45 +1,30 @@
1
1
  "use client";
2
2
 
3
3
  // src/context/providers/AttachmentRuntimeProvider.tsx
4
- import {
5
- useEffect,
6
- useMemo,
7
- useState
8
- } from "react";
4
+ import { useEffect, useState } from "react";
9
5
  import { create } from "zustand";
10
6
  import { AttachmentContext } from "../react/AttachmentContext.mjs";
11
7
  import { writableStore } from "../ReadonlyStore.mjs";
8
+ import { ensureBinding } from "../react/utils/ensureBinding.mjs";
12
9
  import { jsx } from "react/jsx-runtime";
13
10
  var useAttachmentRuntimeStore = (runtime) => {
14
11
  const [store] = useState(() => create(() => runtime));
15
12
  useEffect(() => {
13
+ ensureBinding(runtime);
16
14
  writableStore(store).setState(runtime, true);
17
15
  }, [runtime, store]);
18
16
  return store;
19
17
  };
20
- var useAttachmentStore = (runtime) => {
21
- const [store] = useState(() => create(() => runtime.getState()));
22
- useEffect(() => {
23
- const updateState = () => writableStore(store).setState(runtime.getState(), true);
24
- updateState();
25
- return runtime.subscribe(updateState);
26
- }, [runtime, store]);
27
- return store;
28
- };
29
18
  var AttachmentRuntimeProvider = ({
30
19
  runtime,
31
20
  children
32
21
  }) => {
33
22
  const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);
34
- const useAttachment = useAttachmentStore(runtime);
35
- const source = useAttachment((s) => s.source);
36
- const context = useMemo(() => {
23
+ const [context] = useState(() => {
37
24
  return {
38
- source,
39
- useAttachmentRuntime,
40
- useAttachment
25
+ useAttachmentRuntime
41
26
  };
42
- }, [useAttachmentRuntime, useAttachment]);
27
+ });
43
28
  return /* @__PURE__ */ jsx(AttachmentContext.Provider, { value: context, children });
44
29
  };
45
30
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FC,\n type PropsWithChildren,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\n\nexport namespace AttachmentRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: AttachmentRuntime;\n }>;\n}\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\nconst useAttachmentStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const useAttachment = useAttachmentStore(runtime);\n const source = useAttachment((s) => s.source);\n const context = useMemo(() => {\n return {\n source,\n useAttachmentRuntime,\n useAttachment,\n };\n }, [useAttachmentRuntime, useAttachment]);\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AA8C1B;AArCJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AACA,IAAM,qBAAqB,CAAC,YAA+B;AACzD,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,YAAU,MAAM;AACd,UAAM,cAAc,MAClB,cAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAiE,CAAC;AAAA,EAC7E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,SAAS,cAAc,CAAC,MAAM,EAAE,MAAM;AAC5C,QAAM,UAAU,QAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,sBAAsB,aAAa,CAAC;AAExC,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AttachmentRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: AttachmentRuntime;\n }>;\n}\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const [context] = useState(() => {\n return {\n useAttachmentRuntime,\n };\n });\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;AAEA,SAA0C,WAAW,gBAAgB;AACrE,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AAgC1B;AAxBJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AAErB,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAiE,CAAC;AAAA,EAC7E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}
@@ -5,6 +5,5 @@ export declare namespace ContentPartRuntimeProvider {
5
5
  runtime: ContentPartRuntime;
6
6
  }>;
7
7
  }
8
- export declare const useContentPartStore: (runtime: ContentPartRuntime) => import("zustand").UseBoundStore<import("zustand").StoreApi<import("../..").ContentPartState>>;
9
8
  export declare const ContentPartRuntimeProvider: FC<ContentPartRuntimeProvider.Props>;
10
9
  //# sourceMappingURL=ContentPartRuntimeProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentPartRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAK7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,yBAAiB,0BAA0B,CAAC;IAC1C,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,kBAAkB,CAAC;KAC7B,CAAC,CAAC;CACJ;AAYD,eAAO,MAAM,mBAAmB,YAAa,kBAAkB,kGAU9D,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,EAAE,CACzC,0BAA0B,CAAC,KAAK,CAajC,CAAC"}
1
+ {"version":3,"file":"ContentPartRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAK7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,yBAAiB,0BAA0B,CAAC;IAC1C,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,kBAAkB,CAAC;KAC7B,CAAC,CAAC;CACJ;AAcD,eAAO,MAAM,0BAA0B,EAAE,EAAE,CACzC,0BAA0B,CAAC,KAAK,CAYjC,CAAC"}
@@ -21,42 +21,32 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/context/providers/ContentPartRuntimeProvider.tsx
22
22
  var ContentPartRuntimeProvider_exports = {};
23
23
  __export(ContentPartRuntimeProvider_exports, {
24
- ContentPartRuntimeProvider: () => ContentPartRuntimeProvider,
25
- useContentPartStore: () => useContentPartStore
24
+ ContentPartRuntimeProvider: () => ContentPartRuntimeProvider
26
25
  });
27
26
  module.exports = __toCommonJS(ContentPartRuntimeProvider_exports);
28
27
  var import_react = require("react");
29
28
  var import_zustand = require("zustand");
30
29
  var import_ContentPartContext = require("../react/ContentPartContext.js");
31
30
  var import_ReadonlyStore = require("../ReadonlyStore.js");
31
+ var import_ensureBinding = require("../react/utils/ensureBinding.js");
32
32
  var import_jsx_runtime = require("react/jsx-runtime");
33
33
  var useContentPartRuntimeStore = (runtime) => {
34
34
  const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime));
35
35
  (0, import_react.useEffect)(() => {
36
+ (0, import_ensureBinding.ensureBinding)(runtime);
36
37
  (0, import_ReadonlyStore.writableStore)(store).setState(runtime, true);
37
38
  }, [runtime, store]);
38
39
  return store;
39
40
  };
40
- var useContentPartStore = (runtime) => {
41
- const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime.getState()));
42
- (0, import_react.useEffect)(() => {
43
- const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.getState(), true);
44
- updateState();
45
- return runtime.subscribe(updateState);
46
- }, [runtime, store]);
47
- return store;
48
- };
49
41
  var ContentPartRuntimeProvider = ({ runtime, children }) => {
50
42
  const useContentPartRuntime = useContentPartRuntimeStore(runtime);
51
- const useContentPart = useContentPartStore(runtime);
52
43
  const [context] = (0, import_react.useState)(() => {
53
- return { useContentPartRuntime, useContentPart };
44
+ return { useContentPartRuntime };
54
45
  });
55
46
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentPartContext.ContentPartContext.Provider, { value: context, children });
56
47
  };
57
48
  // Annotate the CommonJS export names for ESM import in node:
58
49
  0 && (module.exports = {
59
- ContentPartRuntimeProvider,
60
- useContentPartStore
50
+ ContentPartRuntimeProvider
61
51
  });
62
52
  //# sourceMappingURL=ContentPartRuntimeProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\n\nexport namespace ContentPartRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: ContentPartRuntime;\n }>;\n}\n\nconst useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const useContentPartStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ContentPartRuntimeProvider: FC<\n ContentPartRuntimeProvider.Props\n> = ({ runtime, children }) => {\n const useContentPartRuntime = useContentPartRuntimeStore(runtime);\n const useContentPart = useContentPartStore(runtime);\n const [context] = useState<ContentPartContextValue>(() => {\n return { useContentPartRuntime, useContentPart };\n });\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqE;AACrE,qBAAuB;AACvB,gCAAmC;AAEnC,2BAA8B;AAyC1B;AAhCJ,IAAM,6BAA6B,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,sBAAsB,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,6BAET,CAAC,EAAE,SAAS,SAAS,MAAM;AAC7B,QAAM,wBAAwB,2BAA2B,OAAO;AAChE,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,CAAC,OAAO,QAAI,uBAAkC,MAAM;AACxD,WAAO,EAAE,uBAAuB,eAAe;AAAA,EACjD,CAAC;AAED,SACE,4CAAC,6CAAmB,UAAnB,EAA4B,OAAO,SACjC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace ContentPartRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: ContentPartRuntime;\n }>;\n}\n\nconst useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ContentPartRuntimeProvider: FC<\n ContentPartRuntimeProvider.Props\n> = ({ runtime, children }) => {\n const useContentPartRuntime = useContentPartRuntimeStore(runtime);\n const [context] = useState<ContentPartContextValue>(() => {\n return { useContentPartRuntime };\n });\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqE;AACrE,qBAAuB;AACvB,gCAAmC;AAEnC,2BAA8B;AAE9B,2BAA8B;AA6B1B;AArBJ,IAAM,6BAA6B,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AAErB,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,6BAET,CAAC,EAAE,SAAS,SAAS,MAAM;AAC7B,QAAM,wBAAwB,2BAA2B,OAAO;AAChE,QAAM,CAAC,OAAO,QAAI,uBAAkC,MAAM;AACxD,WAAO,EAAE,sBAAsB;AAAA,EACjC,CAAC;AAED,SACE,4CAAC,6CAAmB,UAAnB,EAA4B,OAAO,SACjC,UACH;AAEJ;","names":[]}
@@ -5,33 +5,24 @@ import { useEffect, useState } from "react";
5
5
  import { create } from "zustand";
6
6
  import { ContentPartContext } from "../react/ContentPartContext.mjs";
7
7
  import { writableStore } from "../ReadonlyStore.mjs";
8
+ import { ensureBinding } from "../react/utils/ensureBinding.mjs";
8
9
  import { jsx } from "react/jsx-runtime";
9
10
  var useContentPartRuntimeStore = (runtime) => {
10
11
  const [store] = useState(() => create(() => runtime));
11
12
  useEffect(() => {
13
+ ensureBinding(runtime);
12
14
  writableStore(store).setState(runtime, true);
13
15
  }, [runtime, store]);
14
16
  return store;
15
17
  };
16
- var useContentPartStore = (runtime) => {
17
- const [store] = useState(() => create(() => runtime.getState()));
18
- useEffect(() => {
19
- const updateState = () => writableStore(store).setState(runtime.getState(), true);
20
- updateState();
21
- return runtime.subscribe(updateState);
22
- }, [runtime, store]);
23
- return store;
24
- };
25
18
  var ContentPartRuntimeProvider = ({ runtime, children }) => {
26
19
  const useContentPartRuntime = useContentPartRuntimeStore(runtime);
27
- const useContentPart = useContentPartStore(runtime);
28
20
  const [context] = useState(() => {
29
- return { useContentPartRuntime, useContentPart };
21
+ return { useContentPartRuntime };
30
22
  });
31
23
  return /* @__PURE__ */ jsx(ContentPartContext.Provider, { value: context, children });
32
24
  };
33
25
  export {
34
- ContentPartRuntimeProvider,
35
- useContentPartStore
26
+ ContentPartRuntimeProvider
36
27
  };
37
28
  //# sourceMappingURL=ContentPartRuntimeProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\n\nexport namespace ContentPartRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: ContentPartRuntime;\n }>;\n}\n\nconst useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const useContentPartStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ContentPartRuntimeProvider: FC<\n ContentPartRuntimeProvider.Props\n> = ({ runtime, children }) => {\n const useContentPartRuntime = useContentPartRuntimeStore(runtime);\n const useContentPart = useContentPartStore(runtime);\n const [context] = useState<ContentPartContextValue>(() => {\n return { useContentPartRuntime, useContentPart };\n });\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;AAEA,SAA0C,WAAW,gBAAgB;AACrE,SAAS,cAAc;AACvB,SAAS,0BAA0B;AAEnC,SAAS,qBAAqB;AAyC1B;AAhCJ,IAAM,6BAA6B,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,sBAAsB,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,YAAU,MAAM;AACd,UAAM,cAAc,MAClB,cAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,6BAET,CAAC,EAAE,SAAS,SAAS,MAAM;AAC7B,QAAM,wBAAwB,2BAA2B,OAAO;AAChE,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,CAAC,OAAO,IAAI,SAAkC,MAAM;AACxD,WAAO,EAAE,uBAAuB,eAAe;AAAA,EACjD,CAAC;AAED,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/ContentPartRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace ContentPartRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: ContentPartRuntime;\n }>;\n}\n\nconst useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ContentPartRuntimeProvider: FC<\n ContentPartRuntimeProvider.Props\n> = ({ runtime, children }) => {\n const useContentPartRuntime = useContentPartRuntimeStore(runtime);\n const [context] = useState<ContentPartContextValue>(() => {\n return { useContentPartRuntime };\n });\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;AAEA,SAA0C,WAAW,gBAAgB;AACrE,SAAS,cAAc;AACvB,SAAS,0BAA0B;AAEnC,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AA6B1B;AArBJ,IAAM,6BAA6B,CAAC,YAAgC;AAClE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AAErB,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,6BAET,CAAC,EAAE,SAAS,SAAS,MAAM;AAC7B,QAAM,wBAAwB,2BAA2B,OAAO;AAChE,QAAM,CAAC,OAAO,IAAI,SAAkC,MAAM;AACxD,WAAO,EAAE,sBAAsB;AAAA,EACjC,CAAC;AAED,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,UACH;AAEJ;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"MessageRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/MessageRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAM7E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,cAAc,CAAC;KACzB,CAAC,CAAC;CACJ;AA4CD,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAiBnE,CAAC"}
1
+ {"version":3,"file":"MessageRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/MessageRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAM7E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,cAAc,CAAC;KACzB,CAAC,CAAC;CACJ;AAmBD,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAenE,CAAC"}
@@ -29,47 +29,28 @@ var import_zustand = require("zustand");
29
29
  var import_MessageContext = require("../react/MessageContext.js");
30
30
  var import_MessageUtils = require("../stores/MessageUtils.js");
31
31
  var import_ReadonlyStore = require("../ReadonlyStore.js");
32
+ var import_ensureBinding = require("../react/utils/ensureBinding.js");
32
33
  var import_jsx_runtime = require("react/jsx-runtime");
33
34
  var useMessageRuntimeStore = (runtime) => {
34
35
  const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime));
35
36
  (0, import_react.useEffect)(() => {
37
+ (0, import_ensureBinding.ensureBinding)(runtime);
36
38
  (0, import_ReadonlyStore.writableStore)(store).setState(runtime, true);
37
39
  }, [runtime, store]);
38
40
  return store;
39
41
  };
40
- var useMessageStore = (runtime) => {
41
- const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime.getState()));
42
- (0, import_react.useEffect)(() => {
43
- const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.getState(), true);
44
- updateState();
45
- return runtime.subscribe(updateState);
46
- }, [runtime, store]);
47
- return store;
48
- };
49
42
  var useMessageUtilsStore = () => {
50
43
  const [store] = (0, import_react.useState)(() => (0, import_MessageUtils.makeMessageUtilsStore)());
51
44
  return store;
52
45
  };
53
- var useEditComposerStore = (useMessageRuntime) => {
54
- const runtime = useMessageRuntime.getState().composer;
55
- const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime.getState()));
56
- (0, import_react.useEffect)(() => {
57
- const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.getState());
58
- updateState();
59
- return runtime.subscribe(updateState);
60
- }, [runtime, store]);
61
- return store;
62
- };
63
46
  var MessageRuntimeProvider = ({
64
47
  runtime,
65
48
  children
66
49
  }) => {
67
50
  const useMessageRuntime = useMessageRuntimeStore(runtime);
68
- const useMessage = useMessageStore(runtime);
69
51
  const useMessageUtils = useMessageUtilsStore();
70
- const useEditComposer = useEditComposerStore(useMessageRuntime);
71
52
  const [context] = (0, import_react.useState)(() => {
72
- return { useMessageRuntime, useMessage, useMessageUtils, useEditComposer };
53
+ return { useMessageRuntime, useMessageUtils };
73
54
  });
74
55
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_MessageContext.MessageContext.Provider, { value: context, children });
75
56
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/MessageRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { MessageContext } from \"../react/MessageContext\";\nimport type { MessageContextValue } from \"../react/MessageContext\";\nimport { makeMessageUtilsStore } from \"../stores/MessageUtils\";\nimport { ReadonlyStore, writableStore } from \"../ReadonlyStore\";\nimport { MessageRuntime } from \"../../api/MessageRuntime\";\n\nexport namespace MessageRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: MessageRuntime;\n }>;\n}\n\nconst useMessageRuntimeStore = (runtime: MessageRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useMessageStore = (runtime: MessageRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useMessageUtilsStore = () => {\n const [store] = useState(() => makeMessageUtilsStore());\n return store;\n};\n\nconst useEditComposerStore = (\n useMessageRuntime: ReadonlyStore<MessageRuntime>,\n) => {\n const runtime = useMessageRuntime.getState().composer;\n const [store] = useState(() => create(() => runtime.getState()));\n\n useEffect(() => {\n const updateState = () => writableStore(store).setState(runtime.getState());\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const MessageRuntimeProvider: FC<MessageRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useMessageRuntime = useMessageRuntimeStore(runtime);\n const useMessage = useMessageStore(runtime);\n const useMessageUtils = useMessageUtilsStore();\n const useEditComposer = useEditComposerStore(useMessageRuntime);\n const [context] = useState<MessageContextValue>(() => {\n return { useMessageRuntime, useMessage, useMessageUtils, useEditComposer };\n });\n\n return (\n <MessageContext.Provider value={context}>\n {children}\n </MessageContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqE;AACrE,qBAAuB;AACvB,4BAA+B;AAE/B,0BAAsC;AACtC,2BAA6C;AAgEzC;AAvDJ,IAAM,yBAAyB,CAAC,YAA4B;AAC1D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,kBAAkB,CAAC,YAA4B;AACnD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,uBAAuB,MAAM;AACjC,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,2CAAsB,CAAC;AACtD,SAAO;AACT;AAEA,IAAM,uBAAuB,CAC3B,sBACG;AACH,QAAM,UAAU,kBAAkB,SAAS,EAAE;AAC7C,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAE/D,8BAAU,MAAM;AACd,UAAM,cAAc,UAAM,oCAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,CAAC;AAC1E,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,yBAA2D,CAAC;AAAA,EACvE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,oBAAoB,uBAAuB,OAAO;AACxD,QAAM,aAAa,gBAAgB,OAAO;AAC1C,QAAM,kBAAkB,qBAAqB;AAC7C,QAAM,kBAAkB,qBAAqB,iBAAiB;AAC9D,QAAM,CAAC,OAAO,QAAI,uBAA8B,MAAM;AACpD,WAAO,EAAE,mBAAmB,YAAY,iBAAiB,gBAAgB;AAAA,EAC3E,CAAC;AAED,SACE,4CAAC,qCAAe,UAAf,EAAwB,OAAO,SAC7B,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/MessageRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { MessageContext } from \"../react/MessageContext\";\nimport type { MessageContextValue } from \"../react/MessageContext\";\nimport { makeMessageUtilsStore } from \"../stores/MessageUtils\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { MessageRuntime } from \"../../api/MessageRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace MessageRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: MessageRuntime;\n }>;\n}\n\nconst useMessageRuntimeStore = (runtime: MessageRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useMessageUtilsStore = () => {\n const [store] = useState(() => makeMessageUtilsStore());\n return store;\n};\n\nexport const MessageRuntimeProvider: FC<MessageRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useMessageRuntime = useMessageRuntimeStore(runtime);\n const useMessageUtils = useMessageUtilsStore();\n const [context] = useState<MessageContextValue>(() => {\n return { useMessageRuntime, useMessageUtils };\n });\n\n return (\n <MessageContext.Provider value={context}>\n {children}\n </MessageContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqE;AACrE,qBAAuB;AACvB,4BAA+B;AAE/B,0BAAsC;AACtC,2BAA8B;AAE9B,2BAA8B;AAoC1B;AA5BJ,IAAM,yBAAyB,CAAC,YAA4B;AAC1D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AAErB,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,uBAAuB,MAAM;AACjC,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,2CAAsB,CAAC;AACtD,SAAO;AACT;AAEO,IAAM,yBAA2D,CAAC;AAAA,EACvE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,oBAAoB,uBAAuB,OAAO;AACxD,QAAM,kBAAkB,qBAAqB;AAC7C,QAAM,CAAC,OAAO,QAAI,uBAA8B,MAAM;AACpD,WAAO,EAAE,mBAAmB,gBAAgB;AAAA,EAC9C,CAAC;AAED,SACE,4CAAC,qCAAe,UAAf,EAAwB,OAAO,SAC7B,UACH;AAEJ;","names":[]}