@assistant-ui/react 0.7.46 → 0.7.48

Sign up to get free protection for your applications and to get access to all the features.
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 +6 -14
  51. package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
  52. package/dist/context/providers/AssistantRuntimeProvider.mjs +6 -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 +6 -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 +46 -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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/composer/BaseComposerRuntimeCore.tsx"],"sourcesContent":["import {\n Attachment,\n CompleteAttachment,\n PendingAttachment,\n} from \"../../types/AttachmentTypes\";\nimport { AppendMessage } from \"../../types\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport {\n ComposerRuntimeCore,\n ComposerRuntimeEventType,\n} from \"../core/ComposerRuntimeCore\";\nimport { MessageRole, RunConfig } from \"../../types/AssistantTypes\";\nimport { BaseSubscribable } from \"../remote-thread-list/BaseSubscribable\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n\n public getAttachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n await Promise.all(this._attachments.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send() {\n const adapter = this.getAttachmentAdapter();\n const attachments =\n adapter && this.attachments.length > 0\n ? await Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n role: this.role,\n content: this.text ? [{ type: \"text\", text: this.text }] : [],\n attachments,\n runConfig: this.runConfig,\n };\n this._emptyTextAndAttachments();\n\n this.handleSend(message);\n this._notifyEventSubscribers(\"send\");\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(file: File) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const attachment = await adapter.add({ file });\n\n this._attachments = [...this._attachments, attachment as PendingAttachment];\n this._notifyEventSubscribers(\"attachment_add\");\n this._notifySubscribers();\n }\n\n async removeAttachment(attachmentId: string) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n await adapter.remove(attachment);\n\n // this._attachments.toSpliced(index, 1); - not yet widely supported\n this._attachments = [\n ...this._attachments.slice(0, index),\n ...this._attachments.slice(index + 1),\n ];\n this._notifySubscribers();\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<() => void>\n >();\n\n protected _notifyEventSubscribers(event: ComposerRuntimeEventType) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback();\n }\n\n public unstable_on(event: ComposerRuntimeEventType, callback: () => void) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n this._eventSubscribers.set(event, new Set([callback]));\n } else {\n subscribers.add(callback);\n }\n\n return () => {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n subscribers.delete(callback);\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,8BAAiC;AAEjC,IAAM,uBAAuB,CAAC,MAC5B,EAAE,OAAO,SAAS;AAEb,IAAe,0BAAf,cACG,yCAEV;AAAA,E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EA,MAAM,iBAAiB,cAAsB;AAC3C,UAAM,UAAU,KAAK,qBAAqB;AAC1C,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,+BAA+B;AAE7D,UAAM,QAAQ,KAAK,aAAa,UAAU,CAAC,MAAM,EAAE,OAAO,YAAY;AACtE,QAAI,UAAU,GAAI,OAAM,IAAI,MAAM,sBAAsB;AACxD,UAAM,aAAa,KAAK,aAAa,KAAK;AAE1C,UAAM,QAAQ,OAAO,UAAU;AAG/B,SAAK,eAAe;AAAA,MAClB,GAAG,KAAK,aAAa,MAAM,GAAG,KAAK;AAAA,MACnC,GAAG,KAAK,aAAa,MAAM,QAAQ,CAAC;AAAA,IACtC;AACA,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEQ,oBAAoB,oBAAI,IAG9B;AAAA,EAEQ,wBAAwB,OAAiC;AACjE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,YAAa;AAElB,eAAW,YAAY,YAAa,UAAS;AAAA,EAC/C;AAAA,EAEO,YAAY,OAAiC,UAAsB;AACxE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,aAAa;AAChB,WAAK,kBAAkB,IAAI,OAAO,oBAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;AAAA,IACvD,OAAO;AACL,kBAAY,IAAI,QAAQ;AAAA,IAC1B;AAEA,WAAO,MAAM;AACX,YAAMA,eAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,UAAI,CAACA,aAAa;AAClB,MAAAA,aAAY,OAAO,QAAQ;AAAA,IAC7B;AAAA,EACF;AACF;","names":["subscribers"]}
1
+ {"version":3,"sources":["../../../src/runtimes/composer/BaseComposerRuntimeCore.tsx"],"sourcesContent":["import {\n Attachment,\n CompleteAttachment,\n PendingAttachment,\n} from \"../../types/AttachmentTypes\";\nimport { AppendMessage } from \"../../types\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport {\n ComposerRuntimeCore,\n ComposerRuntimeEventType,\n} from \"../core/ComposerRuntimeCore\";\nimport { MessageRole, RunConfig } from \"../../types/AssistantTypes\";\nimport { BaseSubscribable } from \"../remote-thread-list/BaseSubscribable\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n\n public getAttachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n await Promise.all(this._attachments.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send() {\n const adapter = this.getAttachmentAdapter();\n const attachments =\n adapter && this.attachments.length > 0\n ? await Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n role: this.role,\n content: this.text ? [{ type: \"text\", text: this.text }] : [],\n attachments,\n runConfig: this.runConfig,\n };\n this._emptyTextAndAttachments();\n\n this.handleSend(message);\n this._notifyEventSubscribers(\"send\");\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(file: File) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const upsertAttachment = (a: PendingAttachment) => {\n const idx = this._attachments.findIndex((attachment) => attachment.id === a.id);\n if (idx !== -1)\n this._attachments = [\n ...this._attachments.slice(0, idx),\n a,\n ...this._attachments.slice(idx + 1),\n ];\n else {\n this._attachments = [...this._attachments, a];\n this._notifyEventSubscribers(\"attachment_add\");\n }\n\n this._notifySubscribers();\n };\n\n const promiseOrGenerator = adapter.add({ file });\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n upsertAttachment(r);\n }\n } else {\n upsertAttachment(await promiseOrGenerator);\n }\n\n this._notifyEventSubscribers(\"attachment_add\");\n this._notifySubscribers();\n }\n\n async removeAttachment(attachmentId: string) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n await adapter.remove(attachment);\n\n // this._attachments.toSpliced(index, 1); - not yet widely supported\n this._attachments = [\n ...this._attachments.slice(0, index),\n ...this._attachments.slice(index + 1),\n ];\n this._notifySubscribers();\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<() => void>\n >();\n\n protected _notifyEventSubscribers(event: ComposerRuntimeEventType) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback();\n }\n\n public unstable_on(event: ComposerRuntimeEventType, callback: () => void) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n this._eventSubscribers.set(event, new Set([callback]));\n } else {\n subscribers.add(callback);\n }\n\n return () => {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n subscribers.delete(callback);\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,8BAAiC;AAEjC,IAAM,uBAAuB,CAAC,MAC5B,EAAE,OAAO,SAAS;AAEb,IAAe,0BAAf,cACG,yCAEV;AAAA,EACkB,YAAY;AAAA,EAIrB,sBAA8B;AACnC,WAAO,KAAK,qBAAqB,GAAG,UAAU;AAAA,EAChD;AAAA,EAEQ,eAAsC,CAAC;AAAA,EAC/C,IAAW,cAAc;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,eAAe,OAA8B;AACrD,SAAK,eAAe;AACpB,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAIA,IAAW,UAAU;AACnB,WAAO,CAAC,KAAK,KAAK,KAAK,KAAK,CAAC,KAAK,YAAY;AAAA,EAChD;AAAA,EAEQ,QAAQ;AAAA,EAEhB,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ,QAAqB;AAAA,EAE7B,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ,aAAwB,CAAC;AAAA,EAEjC,IAAI,YAAY;AACd,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,QAAQ,OAAe;AAC5B,QAAI,KA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A+B;AAE7D,UAAM,QAAQ,KAAK,aAAa,UAAU,CAAC,MAAM,EAAE,OAAO,YAAY;AACtE,QAAI,UAAU,GAAI,OAAM,IAAI,MAAM,sBAAsB;AACxD,UAAM,aAAa,KAAK,aAAa,KAAK;AAE1C,UAAM,QAAQ,OAAO,UAAU;AAG/B,SAAK,eAAe;AAAA,MAClB,GAAG,KAAK,aAAa,MAAM,GAAG,KAAK;AAAA,MACnC,GAAG,KAAK,aAAa,MAAM,QAAQ,CAAC;AAAA,IACtC;AACA,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEQ,oBAAoB,oBAAI,IAG9B;AAAA,EAEQ,wBAAwB,OAAiC;AACjE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,YAAa;AAElB,eAAW,YAAY,YAAa,UAAS;AAAA,EAC/C;AAAA,EAEO,YAAY,OAAiC,UAAsB;AACxE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,aAAa;AAChB,WAAK,kBAAkB,IAAI,OAAO,oBAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;AAAA,IACvD,OAAO;AACL,kBAAY,IAAI,QAAQ;AAAA,IAC1B;AAEA,WAAO,MAAM;AACX,YAAMA,eAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,UAAI,CAACA,aAAa;AAClB,MAAAA,aAAY,OAAO,QAAQ;AAAA,IAC7B;AAAA,EACF;AACF;","names":["subscribers"]}
@@ -95,8 +95,28 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
95
95
  async addAttachment(file) {
96
96
  const adapter = this.getAttachmentAdapter();
97
97
  if (!adapter) throw new Error("Attachments are not supported");
98
- const attachment = await adapter.add({ file });
99
- this._attachments = [...this._attachments, attachment];
98
+ const upsertAttachment = (a) => {
99
+ const idx = this._attachments.findIndex((attachment) => attachment.id === a.id);
100
+ if (idx !== -1)
101
+ this._attachments = [
102
+ ...this._attachments.slice(0, idx),
103
+ a,
104
+ ...this._attachments.slice(idx + 1)
105
+ ];
106
+ else {
107
+ this._attachments = [...this._attachments, a];
108
+ this._notifyEventSubscribers("attachment_add");
109
+ }
110
+ this._notifySubscribers();
111
+ };
112
+ const promiseOrGenerator = adapter.add({ file });
113
+ if (Symbol.asyncIterator in promiseOrGenerator) {
114
+ for await (const r of promiseOrGenerator) {
115
+ upsertAttachment(r);
116
+ }
117
+ } else {
118
+ upsertAttachment(await promiseOrGenerator);
119
+ }
100
120
  this._notifyEventSubscribers("attachment_add");
101
121
  this._notifySubscribers();
102
122
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/composer/BaseComposerRuntimeCore.tsx"],"sourcesContent":["import {\n Attachment,\n CompleteAttachment,\n PendingAttachment,\n} from \"../../types/AttachmentTypes\";\nimport { AppendMessage } from \"../../types\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport {\n ComposerRuntimeCore,\n ComposerRuntimeEventType,\n} from \"../core/ComposerRuntimeCore\";\nimport { MessageRole, RunConfig } from \"../../types/AssistantTypes\";\nimport { BaseSubscribable } from \"../remote-thread-list/BaseSubscribable\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n\n public getAttachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n await Promise.all(this._attachments.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send() {\n const adapter = this.getAttachmentAdapter();\n const attachments =\n adapter && this.attachments.length > 0\n ? await Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n role: this.role,\n content: this.text ? [{ type: \"text\", text: this.text }] : [],\n attachments,\n runConfig: this.runConfig,\n };\n this._emptyTextAndAttachments();\n\n this.handleSend(message);\n this._notifyEventSubscribers(\"send\");\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(file: File) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const attachment = await adapter.add({ file });\n\n this._attachments = [...this._attachments, attachment as PendingAttachment];\n this._notifyEventSubscribers(\"attachment_add\");\n this._notifySubscribers();\n }\n\n async removeAttachment(attachmentId: string) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n await adapter.remove(attachment);\n\n // this._attachments.toSpliced(index, 1); - not yet widely supported\n this._attachments = [\n ...this._attachments.slice(0, index),\n ...this._attachments.slice(index + 1),\n ];\n this._notifySubscribers();\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<() => void>\n >();\n\n protected _notifyEventSubscribers(event: ComposerRuntimeEventType) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback();\n }\n\n public unstable_on(event: ComposerRuntimeEventType, callback: () => void) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n this._eventSubscribers.set(event, new Set([callback]));\n } else {\n subscribers.add(callback);\n }\n\n return () => {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n subscribers.delete(callback);\n };\n }\n}\n"],"mappings":";AAYA,SAAS,wBAAwB;AAEjC,IAAM,uBAAuB,CAAC,MAC5B,EAAE,OAAO,SAAS;AAEb,IAAe,0BAAf,cACG,iBAEV;AAAA,EACkB,YAAY;AAAA,EAIrB,sBAA8B;AACnC,WAAO,KAAK,qBAAqB,GAAG,UAAU;AAAA,EAChD;AAAA,EAEQ,eAAsC,CAAC;AAAA,EAC/C,IAAW,cAAc;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,eAAe,OAA8B;AACrD,SAAK,eAAe;AACpB,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAIA,IAAW,UAAU;AACnB,WAAO,CAAC,KAAK,KAAK,KAAK,KAAK,CAAC,KAAK,YAAY;AAAA,EAChD;AAAA,EAEQ,QAAQ;AAAA,EAEhB,IAAI,OAAO;AACT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AK,aAAa,MAAM,QAAQ,CAAC;AAAA,IACtC;AACA,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEQ,oBAAoB,oBAAI,IAG9B;AAAA,EAEQ,wBAAwB,OAAiC;AACjE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,YAAa;AAElB,eAAW,YAAY,YAAa,UAAS;AAAA,EAC/C;AAAA,EAEO,YAAY,OAAiC,UAAsB;AACxE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,aAAa;AAChB,WAAK,kBAAkB,IAAI,OAAO,oBAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;AAAA,IACvD,OAAO;AACL,kBAAY,IAAI,QAAQ;AAAA,IAC1B;AAEA,WAAO,MAAM;AACX,YAAMA,eAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,UAAI,CAACA,aAAa;AAClB,MAAAA,aAAY,OAAO,QAAQ;AAAA,IAC7B;AAAA,EACF;AACF;","names":["subscribers"]}
1
+ {"version":3,"sources":["../../../src/runtimes/composer/BaseComposerRuntimeCore.tsx"],"sourcesContent":["import {\n Attachment,\n CompleteAttachment,\n PendingAttachment,\n} from \"../../types/AttachmentTypes\";\nimport { AppendMessage } from \"../../types\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport {\n ComposerRuntimeCore,\n ComposerRuntimeEventType,\n} from \"../core/ComposerRuntimeCore\";\nimport { MessageRole, RunConfig } from \"../../types/AssistantTypes\";\nimport { BaseSubscribable } from \"../remote-thread-list/BaseSubscribable\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n\n public getAttachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n await Promise.all(this._attachments.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send() {\n const adapter = this.getAttachmentAdapter();\n const attachments =\n adapter && this.attachments.length > 0\n ? await Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n role: this.role,\n content: this.text ? [{ type: \"text\", text: this.text }] : [],\n attachments,\n runConfig: this.runConfig,\n };\n this._emptyTextAndAttachments();\n\n this.handleSend(message);\n this._notifyEventSubscribers(\"send\");\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(file: File) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const upsertAttachment = (a: PendingAttachment) => {\n const idx = this._attachments.findIndex((attachment) => attachment.id === a.id);\n if (idx !== -1)\n this._attachments = [\n ...this._attachments.slice(0, idx),\n a,\n ...this._attachments.slice(idx + 1),\n ];\n else {\n this._attachments = [...this._attachments, a];\n this._notifyEventSubscribers(\"attachment_add\");\n }\n\n this._notifySubscribers();\n };\n\n const promiseOrGenerator = adapter.add({ file });\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n upsertAttachment(r);\n }\n } else {\n upsertAttachment(await promiseOrGenerator);\n }\n\n this._notifyEventSubscribers(\"attachment_add\");\n this._notifySubscribers();\n }\n\n async removeAttachment(attachmentId: string) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n await adapter.remove(attachment);\n\n // this._attachments.toSpliced(index, 1); - not yet widely supported\n this._attachments = [\n ...this._attachments.slice(0, index),\n ...this._attachments.slice(index + 1),\n ];\n this._notifySubscribers();\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<() => void>\n >();\n\n protected _notifyEventSubscribers(event: ComposerRuntimeEventType) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback();\n }\n\n public unstable_on(event: ComposerRuntimeEventType, callback: () => void) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n this._eventSubscribers.set(event, new Set([callback]));\n } else {\n subscribers.add(callback);\n }\n\n return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Ac,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,YAAa;AAElB,eAAW,YAAY,YAAa,UAAS;AAAA,EAC/C;AAAA,EAEO,YAAY,OAAiC,UAAsB;AACxE,UAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,QAAI,CAAC,aAAa;AAChB,WAAK,kBAAkB,IAAI,OAAO,oBAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;AAAA,IACvD,OAAO;AACL,kBAAY,IAAI,QAAQ;AAAA,IAC1B;AAEA,WAAO,MAAM;AACX,YAAMA,eAAc,KAAK,kBAAkB,IAAI,KAAK;AACpD,UAAI,CAACA,aAAa;AAClB,MAAAA,aAAY,OAAO,QAAQ;AAAA,IAC7B;AAAA,EACF;AACF;","names":["subscribers"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACrE,CAAC;AAgBF,eAAO,MAAM,eAAe,YACjB,gBAAgB,oCACQ,mBAAmB,iBAiBrD,CAAC"}
1
+ {"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACrE,CAAC;AAqBF,eAAO,MAAM,eAAe,YACjB,gBAAgB,oCACQ,mBAAmB,iBAiBrD,CAAC"}
@@ -33,6 +33,10 @@ var LocalRuntimeImpl = class _LocalRuntimeImpl extends import_AssistantRuntime.A
33
33
  super(core, import_internal.ThreadRuntimeImpl);
34
34
  this.core = core;
35
35
  }
36
+ __internal_bindMethods() {
37
+ super.__internal_bindMethods();
38
+ this.reset = this.reset.bind(this);
39
+ }
36
40
  reset(options) {
37
41
  this.core.reset(options);
38
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAE7C,8BAAiC;AAEjC,8BAGO;AACP,sBAAkC;AAMlC,IAAM,mBAAN,MAAM,0BAAyB,6CAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iCAAiB;AADH;AAAA,EAE5B;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,yCAAiB,KAAK,eAAe,CAAC;AAE3E,8BAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AAAA,EACtE,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,aAAO,sBAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.reset = this.reset.bind(this);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAE7C,8BAAiC;AAEjC,8BAGO;AACP,sBAAkC;AAMlC,IAAM,mBAAN,MAAM,0BAAyB,6CAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iCAAiB;AADH;AAAA,EAE5B;AAAA,EAEgB,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,yCAAiB,KAAK,eAAe,CAAC;AAE3E,8BAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AAAA,EACtE,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,aAAO,sBAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
@@ -12,6 +12,10 @@ var LocalRuntimeImpl = class _LocalRuntimeImpl extends AssistantRuntimeImpl {
12
12
  super(core, ThreadRuntimeImpl);
13
13
  this.core = core;
14
14
  }
15
+ __internal_bindMethods() {
16
+ super.__internal_bindMethods();
17
+ this.reset = this.reset.bind(this);
18
+ }
15
19
  reset(options) {
16
20
  this.core.reset(options);
17
21
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAMlC,IAAM,mBAAN,MAAM,0BAAyB,qBAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iBAAiB;AADH;AAAA,EAE5B;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,iBAAiB,KAAK,eAAe,CAAC;AAE3E,YAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AAAA,EACtE,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,SAAO,QAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.reset = this.reset.bind(this);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAMlC,IAAM,mBAAN,MAAM,0BAAyB,qBAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iBAAiB;AADH;AAAA,EAE5B;AAAA,EAEgB,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,iBAAiB,KAAK,eAAe,CAAC;AAE3E,YAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AAAA,EACtE,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,SAAO,QAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.7.46",
32
+ "version": "0.7.48",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -118,8 +118,8 @@
118
118
  "tailwindcss-animate": "^1.0.7",
119
119
  "tsx": "^4.19.2",
120
120
  "@assistant-ui/tsbuildutils": "^0.0.1",
121
- "@assistant-ui/tsconfig": "0.0.0",
122
- "@assistant-ui/tailwindcss-transformer": "0.1.0"
121
+ "@assistant-ui/tailwindcss-transformer": "0.1.0",
122
+ "@assistant-ui/tsconfig": "0.0.0"
123
123
  },
124
124
  "publishConfig": {
125
125
  "access": "public",
@@ -67,6 +67,13 @@ export class AssistantRuntimeImpl implements AssistantRuntime {
67
67
  this._thread = this.threadList.main;
68
68
  }
69
69
 
70
+ protected __internal_bindMethods() {
71
+ this.switchToNewThread = this.switchToNewThread.bind(this);
72
+ this.switchToThread = this.switchToThread.bind(this);
73
+ this.registerModelConfigProvider =
74
+ this.registerModelConfigProvider.bind(this);
75
+ }
76
+
70
77
  public get thread() {
71
78
  return this._thread;
72
79
  }
@@ -56,6 +56,12 @@ export abstract class AttachmentRuntimeImpl<
56
56
 
57
57
  constructor(private _core: AttachmentSnapshotBinding<Source>) {}
58
58
 
59
+ protected __internal_bindMethods() {
60
+ this.getState = this.getState.bind(this);
61
+ this.remove = this.remove.bind(this);
62
+ this.subscribe = this.subscribe.bind(this);
63
+ }
64
+
59
65
  public getState(): AttachmentState & { source: Source } {
60
66
  return this._core.getState();
61
67
  }
@@ -127,6 +127,22 @@ export abstract class ComposerRuntimeImpl implements ComposerRuntime {
127
127
 
128
128
  constructor(protected _core: ComposerRuntimeCoreBinding) {}
129
129
 
130
+ protected __internal_bindMethods() {
131
+ this.setText = this.setText.bind(this);
132
+ this.setRunConfig = this.setRunConfig.bind(this);
133
+ this.getState = this.getState.bind(this);
134
+ this.subscribe = this.subscribe.bind(this);
135
+ this.addAttachment = this.addAttachment.bind(this);
136
+ this.reset = this.reset.bind(this);
137
+ this.clearAttachments = this.clearAttachments.bind(this);
138
+ this.send = this.send.bind(this);
139
+ this.cancel = this.cancel.bind(this);
140
+ this.setRole = this.setRole.bind(this);
141
+ this.getAttachmentAccept = this.getAttachmentAccept.bind(this);
142
+ this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);
143
+ this.unstable_on = this.unstable_on.bind(this);
144
+ }
145
+
130
146
  public abstract getState(): ComposerState;
131
147
 
132
148
  public setText(text: string) {
@@ -330,6 +346,11 @@ export class EditComposerRuntimeImpl
330
346
  this._getState = stateBinding.getState.bind(stateBinding);
331
347
  }
332
348
 
349
+ public override __internal_bindMethods() {
350
+ super.__internal_bindMethods();
351
+ this.beginEdit = this.beginEdit.bind(this);
352
+ }
353
+
333
354
  public override getState(): EditComposerState {
334
355
  return this._getState();
335
356
  }
@@ -45,6 +45,12 @@ export class ContentPartRuntimeImpl implements ContentPartRuntime {
45
45
  private threadApi?: ThreadRuntimeCoreBinding,
46
46
  ) {}
47
47
 
48
+ protected __internal_bindMethods() {
49
+ this.addToolResult = this.addToolResult.bind(this);
50
+ this.getState = this.getState.bind(this);
51
+ this.subscribe = this.subscribe.bind(this);
52
+ }
53
+
48
54
  public getState() {
49
55
  return this.contentBinding.getState();
50
56
  }
@@ -174,6 +174,21 @@ export class MessageRuntimeImpl implements MessageRuntime {
174
174
  );
175
175
  }
176
176
 
177
+ protected __internal_bindMethods() {
178
+ this.reload = this.reload.bind(this);
179
+ this.getState = this.getState.bind(this);
180
+ this.subscribe = this.subscribe.bind(this);
181
+ this.getContentPartByIndex = this.getContentPartByIndex.bind(this);
182
+ this.getContentPartByToolCallId =
183
+ this.getContentPartByToolCallId.bind(this);
184
+ this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);
185
+ this.unstable_getCopyText = this.unstable_getCopyText.bind(this);
186
+ this.speak = this.speak.bind(this);
187
+ this.stopSpeaking = this.stopSpeaking.bind(this);
188
+ this.submitFeedback = this.submitFeedback.bind(this);
189
+ this.switchToBranch = this.switchToBranch.bind(this);
190
+ }
191
+
177
192
  public readonly composer;
178
193
 
179
194
  public getState() {
@@ -55,6 +55,18 @@ export class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {
55
55
  private _threadListBinding: ThreadListRuntimeCoreBinding,
56
56
  ) {}
57
57
 
58
+ protected __internal_bindMethods() {
59
+ this.switchTo = this.switchTo.bind(this);
60
+ this.rename = this.rename.bind(this);
61
+ this.archive = this.archive.bind(this);
62
+ this.unarchive = this.unarchive.bind(this);
63
+ this.delete = this.delete.bind(this);
64
+ this.initialize = this.initialize.bind(this);
65
+ this.subscribe = this.subscribe.bind(this);
66
+ this.unstable_on = this.unstable_on.bind(this);
67
+ this.getState = this.getState.bind(this);
68
+ }
69
+
58
70
  public getState(): ThreadListItemState {
59
71
  return this._core.getState();
60
72
  }
@@ -116,6 +116,17 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
116
116
  );
117
117
  }
118
118
 
119
+ protected __internal_bindMethods() {
120
+ this.switchToThread = this.switchToThread.bind(this);
121
+ this.switchToNewThread = this.switchToNewThread.bind(this);
122
+ this.getState = this.getState.bind(this);
123
+ this.subscribe = this.subscribe.bind(this);
124
+ this.getById = this.getById.bind(this);
125
+ this.getItemById = this.getItemById.bind(this);
126
+ this.getItemByIndex = this.getItemByIndex.bind(this);
127
+ this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);
128
+ }
129
+
119
130
  public switchToThread(threadId: string): Promise<void> {
120
131
  return this._core.switchToThread(threadId);
121
132
  }
@@ -286,6 +286,21 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
286
286
  );
287
287
  }
288
288
 
289
+ protected __internal_bindMethods() {
290
+ this.append = this.append.bind(this);
291
+ this.startRun = this.startRun.bind(this);
292
+ this.cancelRun = this.cancelRun.bind(this);
293
+ this.stopSpeaking = this.stopSpeaking.bind(this);
294
+ this.export = this.export.bind(this);
295
+ this.import = this.import.bind(this);
296
+ this.getMesssageByIndex = this.getMesssageByIndex.bind(this);
297
+ this.getMesssageById = this.getMesssageById.bind(this);
298
+ this.subscribe = this.subscribe.bind(this);
299
+ this.unstable_on = this.unstable_on.bind(this);
300
+ this.getModelConfig = this.getModelConfig.bind(this);
301
+ this.getState = this.getState.bind(this);
302
+ }
303
+
289
304
  public readonly composer;
290
305
 
291
306
  public getState() {
@@ -324,10 +339,6 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
324
339
  return this._threadBinding.getState().stopSpeaking();
325
340
  }
326
341
 
327
- public getSubmittedFeedback(messageId: string) {
328
- return this._threadBinding.getState().getSubmittedFeedback(messageId);
329
- }
330
-
331
342
  public export() {
332
343
  return this._threadBinding.getState().export();
333
344
  }
@@ -15,6 +15,7 @@ import { AssistantRuntime } from "../../api/AssistantRuntime";
15
15
  import { create } from "zustand";
16
16
  import { writableStore } from "../ReadonlyStore";
17
17
  import { AssistantRuntimeCore } from "../../runtimes/core/AssistantRuntimeCore";
18
+ import { ensureBinding } from "../react/utils/ensureBinding";
18
19
 
19
20
  export namespace AssistantRuntimeProvider {
20
21
  export type Props = PropsWithChildren<{
@@ -29,6 +30,9 @@ const useAssistantRuntimeStore = (runtime: AssistantRuntime) => {
29
30
  const [store] = useState(() => create(() => runtime));
30
31
 
31
32
  useEffect(() => {
33
+ ensureBinding(runtime);
34
+ ensureBinding(runtime.threads);
35
+
32
36
  writableStore(store).setState(runtime, true);
33
37
  }, [runtime, store]);
34
38
 
@@ -39,19 +43,6 @@ const useAssistantToolUIsStore = () => {
39
43
  return useMemo(() => makeAssistantToolUIsStore(), []);
40
44
  };
41
45
 
42
- const useThreadListStore = (runtime: AssistantRuntime) => {
43
- const [store] = useState(() => create(() => runtime.threadList.getState()));
44
-
45
- useEffect(() => {
46
- const updateState = () =>
47
- writableStore(store).setState(runtime.threadList.getState(), true);
48
- updateState();
49
- return runtime.threadList.subscribe(updateState);
50
- }, [runtime, store]);
51
-
52
- return store;
53
- };
54
-
55
46
  const getRenderComponent = (runtime: AssistantRuntime) => {
56
47
  return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;
57
48
  };
@@ -61,14 +52,12 @@ export const AssistantRuntimeProviderImpl: FC<
61
52
  > = ({ children, runtime }) => {
62
53
  const useAssistantRuntime = useAssistantRuntimeStore(runtime);
63
54
  const useToolUIs = useAssistantToolUIsStore();
64
- const useThreadList = useThreadListStore(runtime);
65
- const context = useMemo(() => {
55
+ const [context] = useState(() => {
66
56
  return {
67
57
  useToolUIs,
68
58
  useAssistantRuntime,
69
- useThreadList,
70
59
  };
71
- }, [useAssistantRuntime, useToolUIs, useThreadList]);
60
+ });
72
61
 
73
62
  const RenderComponent = getRenderComponent(runtime);
74
63
 
@@ -1,16 +1,11 @@
1
1
  "use client";
2
2
 
3
- import {
4
- type FC,
5
- type PropsWithChildren,
6
- useEffect,
7
- useMemo,
8
- useState,
9
- } from "react";
3
+ import { type FC, type PropsWithChildren, useEffect, useState } from "react";
10
4
  import { create } from "zustand";
11
5
  import { AttachmentContext } from "../react/AttachmentContext";
12
6
  import { writableStore } from "../ReadonlyStore";
13
7
  import { AttachmentRuntime } from "../../api/AttachmentRuntime";
8
+ import { ensureBinding } from "../react/utils/ensureBinding";
14
9
 
15
10
  export namespace AttachmentRuntimeProvider {
16
11
  export type Props = PropsWithChildren<{
@@ -22,18 +17,9 @@ const useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {
22
17
  const [store] = useState(() => create(() => runtime));
23
18
 
24
19
  useEffect(() => {
25
- writableStore(store).setState(runtime, true);
26
- }, [runtime, store]);
20
+ ensureBinding(runtime);
27
21
 
28
- return store;
29
- };
30
- const useAttachmentStore = (runtime: AttachmentRuntime) => {
31
- const [store] = useState(() => create(() => runtime.getState()));
32
- useEffect(() => {
33
- const updateState = () =>
34
- writableStore(store).setState(runtime.getState(), true);
35
- updateState();
36
- return runtime.subscribe(updateState);
22
+ writableStore(store).setState(runtime, true);
37
23
  }, [runtime, store]);
38
24
 
39
25
  return store;
@@ -44,15 +30,11 @@ export const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({
44
30
  children,
45
31
  }) => {
46
32
  const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);
47
- const useAttachment = useAttachmentStore(runtime);
48
- const source = useAttachment((s) => s.source);
49
- const context = useMemo(() => {
33
+ const [context] = useState(() => {
50
34
  return {
51
- source,
52
35
  useAttachmentRuntime,
53
- useAttachment,
54
36
  };
55
- }, [useAttachmentRuntime, useAttachment]);
37
+ });
56
38
 
57
39
  return (
58
40
  <AttachmentContext.Provider value={context}>
@@ -6,6 +6,7 @@ import { ContentPartContext } from "../react/ContentPartContext";
6
6
  import type { ContentPartContextValue } from "../react/ContentPartContext";
7
7
  import { writableStore } from "../ReadonlyStore";
8
8
  import { ContentPartRuntime } from "../../api/ContentPartRuntime";
9
+ import { ensureBinding } from "../react/utils/ensureBinding";
9
10
 
10
11
  export namespace ContentPartRuntimeProvider {
11
12
  export type Props = PropsWithChildren<{
@@ -17,19 +18,9 @@ const useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {
17
18
  const [store] = useState(() => create(() => runtime));
18
19
 
19
20
  useEffect(() => {
20
- writableStore(store).setState(runtime, true);
21
- }, [runtime, store]);
21
+ ensureBinding(runtime);
22
22
 
23
- return store;
24
- };
25
-
26
- export const useContentPartStore = (runtime: ContentPartRuntime) => {
27
- const [store] = useState(() => create(() => runtime.getState()));
28
- useEffect(() => {
29
- const updateState = () =>
30
- writableStore(store).setState(runtime.getState(), true);
31
- updateState();
32
- return runtime.subscribe(updateState);
23
+ writableStore(store).setState(runtime, true);
33
24
  }, [runtime, store]);
34
25
 
35
26
  return store;
@@ -39,9 +30,8 @@ export const ContentPartRuntimeProvider: FC<
39
30
  ContentPartRuntimeProvider.Props
40
31
  > = ({ runtime, children }) => {
41
32
  const useContentPartRuntime = useContentPartRuntimeStore(runtime);
42
- const useContentPart = useContentPartStore(runtime);
43
33
  const [context] = useState<ContentPartContextValue>(() => {
44
- return { useContentPartRuntime, useContentPart };
34
+ return { useContentPartRuntime };
45
35
  });
46
36
 
47
37
  return (
@@ -5,8 +5,9 @@ import { create } from "zustand";
5
5
  import { MessageContext } from "../react/MessageContext";
6
6
  import type { MessageContextValue } from "../react/MessageContext";
7
7
  import { makeMessageUtilsStore } from "../stores/MessageUtils";
8
- import { ReadonlyStore, writableStore } from "../ReadonlyStore";
8
+ import { writableStore } from "../ReadonlyStore";
9
9
  import { MessageRuntime } from "../../api/MessageRuntime";
10
+ import { ensureBinding } from "../react/utils/ensureBinding";
10
11
 
11
12
  export namespace MessageRuntimeProvider {
12
13
  export type Props = PropsWithChildren<{
@@ -18,19 +19,9 @@ const useMessageRuntimeStore = (runtime: MessageRuntime) => {
18
19
  const [store] = useState(() => create(() => runtime));
19
20
 
20
21
  useEffect(() => {
21
- writableStore(store).setState(runtime, true);
22
- }, [runtime, store]);
22
+ ensureBinding(runtime);
23
23
 
24
- return store;
25
- };
26
-
27
- const useMessageStore = (runtime: MessageRuntime) => {
28
- const [store] = useState(() => create(() => runtime.getState()));
29
- useEffect(() => {
30
- const updateState = () =>
31
- writableStore(store).setState(runtime.getState(), true);
32
- updateState();
33
- return runtime.subscribe(updateState);
24
+ writableStore(store).setState(runtime, true);
34
25
  }, [runtime, store]);
35
26
 
36
27
  return store;
@@ -41,31 +32,14 @@ const useMessageUtilsStore = () => {
41
32
  return store;
42
33
  };
43
34
 
44
- const useEditComposerStore = (
45
- useMessageRuntime: ReadonlyStore<MessageRuntime>,
46
- ) => {
47
- const runtime = useMessageRuntime.getState().composer;
48
- const [store] = useState(() => create(() => runtime.getState()));
49
-
50
- useEffect(() => {
51
- const updateState = () => writableStore(store).setState(runtime.getState());
52
- updateState();
53
- return runtime.subscribe(updateState);
54
- }, [runtime, store]);
55
-
56
- return store;
57
- };
58
-
59
35
  export const MessageRuntimeProvider: FC<MessageRuntimeProvider.Props> = ({
60
36
  runtime,
61
37
  children,
62
38
  }) => {
63
39
  const useMessageRuntime = useMessageRuntimeStore(runtime);
64
- const useMessage = useMessageStore(runtime);
65
40
  const useMessageUtils = useMessageUtilsStore();
66
- const useEditComposer = useEditComposerStore(useMessageRuntime);
67
41
  const [context] = useState<MessageContextValue>(() => {
68
- return { useMessageRuntime, useMessage, useMessageUtils, useEditComposer };
42
+ return { useMessageRuntime, useMessageUtils };
69
43
  });
70
44
 
71
45
  return (