@assistant-ui/react 0.11.34 → 0.11.36

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 (216) hide show
  1. package/dist/augmentations.d.ts +9 -0
  2. package/dist/augmentations.d.ts.map +1 -1
  3. package/dist/client/AssistantClient.d.ts +13 -57
  4. package/dist/client/AssistantClient.d.ts.map +1 -1
  5. package/dist/client/AssistantClient.js +49 -26
  6. package/dist/client/AssistantClient.js.map +1 -1
  7. package/dist/client/ModelContext.d.ts +8 -0
  8. package/dist/client/ModelContext.d.ts.map +1 -0
  9. package/dist/client/ModelContext.js +21 -0
  10. package/dist/client/ModelContext.js.map +1 -0
  11. package/dist/client/ModelContextClient.d.ts +7 -0
  12. package/dist/client/ModelContextClient.d.ts.map +1 -0
  13. package/dist/client/ModelContextClient.js +18 -0
  14. package/dist/client/ModelContextClient.js.map +1 -0
  15. package/dist/client/ToolUIClient.d.ts.map +1 -1
  16. package/dist/client/ToolUIClient.js +45 -3
  17. package/dist/client/ToolUIClient.js.map +1 -1
  18. package/dist/client/ToolUIContext.d.ts +4 -0
  19. package/dist/client/ToolUIContext.d.ts.map +1 -0
  20. package/dist/client/ToolUIContext.js +20 -0
  21. package/dist/client/ToolUIContext.js.map +1 -0
  22. package/dist/client/Tools.d.ts +10 -0
  23. package/dist/client/Tools.d.ts.map +1 -0
  24. package/dist/client/Tools.js +55 -0
  25. package/dist/client/Tools.js.map +1 -0
  26. package/dist/client/types/ModelContext.d.ts +12 -0
  27. package/dist/client/types/ModelContext.d.ts.map +1 -0
  28. package/dist/client/types/ModelContext.js +1 -0
  29. package/dist/client/types/ModelContext.js.map +1 -0
  30. package/dist/client/types/ThreadList.d.ts.map +1 -1
  31. package/dist/client/types/ToolUI.d.ts +12 -1
  32. package/dist/client/types/ToolUI.d.ts.map +1 -1
  33. package/dist/client/types/Tools.d.ts +9 -0
  34. package/dist/client/types/Tools.d.ts.map +1 -0
  35. package/dist/client/types/Tools.js +1 -0
  36. package/dist/client/types/Tools.js.map +1 -0
  37. package/dist/context/providers/AttachmentByIndexProvider.d.ts.map +1 -1
  38. package/dist/context/providers/AttachmentByIndexProvider.js +20 -24
  39. package/dist/context/providers/AttachmentByIndexProvider.js.map +1 -1
  40. package/dist/context/providers/MessageByIndexProvider.d.ts.map +1 -1
  41. package/dist/context/providers/MessageByIndexProvider.js +27 -29
  42. package/dist/context/providers/MessageByIndexProvider.js.map +1 -1
  43. package/dist/context/providers/MessageProvider.d.ts.map +1 -1
  44. package/dist/context/providers/MessageProvider.js +11 -13
  45. package/dist/context/providers/MessageProvider.js.map +1 -1
  46. package/dist/context/providers/PartByIndexProvider.d.ts.map +1 -1
  47. package/dist/context/providers/PartByIndexProvider.js +11 -13
  48. package/dist/context/providers/PartByIndexProvider.js.map +1 -1
  49. package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
  50. package/dist/context/providers/TextMessagePartProvider.js +11 -13
  51. package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
  52. package/dist/context/providers/ThreadListItemProvider.d.ts.map +1 -1
  53. package/dist/context/providers/ThreadListItemProvider.js +41 -45
  54. package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
  55. package/dist/context/react/AssistantApiContext.d.ts +33 -4
  56. package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
  57. package/dist/context/react/AssistantApiContext.js +35 -17
  58. package/dist/context/react/AssistantApiContext.js.map +1 -1
  59. package/dist/context/react/index.d.ts +1 -1
  60. package/dist/context/react/index.d.ts.map +1 -1
  61. package/dist/context/react/index.js +5 -1
  62. package/dist/context/react/index.js.map +1 -1
  63. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  64. package/dist/legacy-runtime/AssistantRuntimeProvider.js +7 -9
  65. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  66. package/dist/legacy-runtime/RuntimeAdapter.d.ts +7 -0
  67. package/dist/legacy-runtime/RuntimeAdapter.d.ts.map +1 -0
  68. package/dist/legacy-runtime/RuntimeAdapter.js +20 -0
  69. package/dist/legacy-runtime/RuntimeAdapter.js.map +1 -0
  70. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts +2 -0
  71. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
  72. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +6 -2
  73. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
  74. package/dist/legacy-runtime/hooks/AssistantContext.d.ts +14 -1
  75. package/dist/legacy-runtime/hooks/AssistantContext.d.ts.map +1 -1
  76. package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
  77. package/dist/legacy-runtime/hooks/AssistantContext.js.map +1 -1
  78. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +6 -0
  79. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +1 -1
  80. package/dist/legacy-runtime/hooks/AttachmentContext.js.map +1 -1
  81. package/dist/legacy-runtime/hooks/ComposerContext.d.ts +41 -2
  82. package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +1 -1
  83. package/dist/legacy-runtime/hooks/ComposerContext.js.map +1 -1
  84. package/dist/legacy-runtime/hooks/MessageContext.d.ts +36 -2
  85. package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +1 -1
  86. package/dist/legacy-runtime/hooks/MessageContext.js.map +1 -1
  87. package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +6 -0
  88. package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +1 -1
  89. package/dist/legacy-runtime/hooks/MessagePartContext.js.map +1 -1
  90. package/dist/legacy-runtime/hooks/ThreadContext.d.ts +26 -1
  91. package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +1 -1
  92. package/dist/legacy-runtime/hooks/ThreadContext.js.map +1 -1
  93. package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +6 -0
  94. package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +1 -1
  95. package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +1 -1
  96. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts +2 -2
  97. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts.map +1 -1
  98. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js +4 -2
  99. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js.map +1 -1
  100. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +2 -0
  101. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
  102. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts +3 -0
  103. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  104. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +14 -4
  105. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  106. package/dist/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.d.ts +1 -0
  107. package/dist/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.d.ts.map +1 -1
  108. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.d.ts +1 -0
  109. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.d.ts.map +1 -1
  110. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.js +3 -0
  111. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.js.map +1 -1
  112. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.d.ts +4 -1
  113. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
  114. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.js +2 -2
  115. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
  116. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  117. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +7 -1
  118. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  119. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts +2 -12
  120. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts.map +1 -1
  121. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +45 -15
  122. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
  123. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +2 -0
  124. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  125. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +4 -2
  126. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  127. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.d.ts +4 -1
  128. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
  129. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.js +2 -2
  130. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.js.map +1 -1
  131. package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js +1 -1
  132. package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js.map +1 -1
  133. package/dist/model-context/index.d.ts +2 -0
  134. package/dist/model-context/index.d.ts.map +1 -1
  135. package/dist/model-context/index.js +6 -0
  136. package/dist/model-context/index.js.map +1 -1
  137. package/dist/model-context/makeAssistantVisible.js +1 -1
  138. package/dist/model-context/makeAssistantVisible.js.map +1 -1
  139. package/dist/model-context/toolbox.d.ts +28 -0
  140. package/dist/model-context/toolbox.d.ts.map +1 -0
  141. package/dist/model-context/toolbox.js +15 -0
  142. package/dist/model-context/toolbox.js.map +1 -0
  143. package/dist/model-context/useAssistantInstructions.js +1 -1
  144. package/dist/model-context/useAssistantInstructions.js.map +1 -1
  145. package/dist/model-context/useAssistantTool.js +1 -1
  146. package/dist/model-context/useAssistantTool.js.map +1 -1
  147. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  148. package/dist/primitives/message/MessageParts.js +2 -2
  149. package/dist/primitives/message/MessageParts.js.map +1 -1
  150. package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
  151. package/dist/primitives/message/MessagePartsGrouped.js +2 -2
  152. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  153. package/dist/tests/setup.js +8 -11
  154. package/dist/tests/setup.js.map +1 -1
  155. package/dist/utils/tap-store/derived-scopes.d.ts +81 -0
  156. package/dist/utils/tap-store/derived-scopes.d.ts.map +1 -0
  157. package/dist/utils/tap-store/derived-scopes.js +67 -0
  158. package/dist/utils/tap-store/derived-scopes.js.map +1 -0
  159. package/dist/utils/tap-store/index.d.ts +1 -0
  160. package/dist/utils/tap-store/index.d.ts.map +1 -1
  161. package/dist/utils/tap-store/index.js +4 -0
  162. package/dist/utils/tap-store/index.js.map +1 -1
  163. package/dist/utils/tap-store/tap-api.js +1 -1
  164. package/dist/utils/tap-store/tap-api.js.map +1 -1
  165. package/package.json +9 -9
  166. package/src/augmentations.ts +12 -0
  167. package/src/client/AssistantClient.ts +64 -38
  168. package/src/client/ModelContext.ts +28 -0
  169. package/src/client/ModelContextClient.ts +16 -0
  170. package/src/client/ToolUIClient.ts +50 -3
  171. package/src/client/ToolUIContext.ts +22 -0
  172. package/src/client/Tools.ts +68 -0
  173. package/src/client/types/ModelContext.ts +15 -0
  174. package/src/client/types/ThreadList.ts +4 -0
  175. package/src/client/types/ToolUI.ts +10 -1
  176. package/src/client/types/Tools.ts +11 -0
  177. package/src/context/providers/AttachmentByIndexProvider.tsx +21 -25
  178. package/src/context/providers/MessageByIndexProvider.tsx +31 -33
  179. package/src/context/providers/MessageProvider.tsx +12 -14
  180. package/src/context/providers/PartByIndexProvider.tsx +12 -14
  181. package/src/context/providers/TextMessagePartProvider.tsx +12 -14
  182. package/src/context/providers/ThreadListItemProvider.tsx +42 -46
  183. package/src/context/react/AssistantApiContext.tsx +69 -29
  184. package/src/context/react/index.ts +5 -1
  185. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +7 -9
  186. package/src/legacy-runtime/RuntimeAdapter.ts +19 -0
  187. package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +10 -1
  188. package/src/legacy-runtime/hooks/AssistantContext.ts +16 -2
  189. package/src/legacy-runtime/hooks/AttachmentContext.ts +6 -0
  190. package/src/legacy-runtime/hooks/ComposerContext.ts +41 -2
  191. package/src/legacy-runtime/hooks/MessageContext.ts +37 -2
  192. package/src/legacy-runtime/hooks/MessagePartContext.ts +6 -0
  193. package/src/legacy-runtime/hooks/ThreadContext.ts +27 -1
  194. package/src/legacy-runtime/hooks/ThreadListItemContext.ts +6 -0
  195. package/src/legacy-runtime/runtime-cores/assistant-transport/index.ts +2 -0
  196. package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +3 -0
  197. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +35 -14
  198. package/src/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.tsx +1 -0
  199. package/src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx +4 -0
  200. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.tsx +4 -2
  201. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +7 -1
  202. package/src/legacy-runtime/runtime-cores/external-store/auto-status.tsx +49 -16
  203. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +4 -0
  204. package/src/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.tsx +4 -2
  205. package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -1
  206. package/src/model-context/index.ts +9 -0
  207. package/src/model-context/makeAssistantVisible.tsx +1 -1
  208. package/src/model-context/toolbox.tsx +37 -0
  209. package/src/model-context/useAssistantInstructions.tsx +1 -1
  210. package/src/model-context/useAssistantTool.tsx +1 -1
  211. package/src/primitives/message/MessageParts.tsx +3 -2
  212. package/src/primitives/message/MessagePartsGrouped.tsx +3 -2
  213. package/src/tests/setup.ts +2 -8
  214. package/src/utils/tap-store/derived-scopes.ts +185 -0
  215. package/src/utils/tap-store/index.ts +9 -0
  216. package/src/utils/tap-store/tap-api.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { ComposerRuntime } from \"../runtime/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n *\n * const handleSend = () => {\n * if (runtime.getState().canSend) {\n * runtime.send();\n * }\n * };\n *\n * const handleCancel = () => {\n * if (runtime.getState().canCancel) {\n * runtime.cancel();\n * }\n * };\n *\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.composer.source\n ? (api.composer().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ComposerRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * Hook to access the current composer state.\n *\n * This hook provides reactive access to the composer's state, including text content,\n * attachments, editing status, and send/cancel capabilities.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected composer state or the entire composer state if no selector provided\n *\n * @example\n * ```tsx\n * function ComposerStatus() {\n * const text = useComposer((state) => state.text);\n * const canSend = useComposer((state) => state.canSend);\n * const attachmentCount = useComposer((state) => state.attachments.length);\n *\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n * ```\n */\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,iBAAiB,yBAAyB;AAEnD,SAAS,iCAAiC;AA8CnC,SAAS,mBAAmB,SAER;AACzB,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,SAAS,SACR,IAAI,SAAS,EAAE,wBAAwB,KAAK,OAC7C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AACA,SAAO;AACT;AA4BO,IAAM,cAAc,0BAA0B,kBAAkB;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { ComposerRuntime } from \"../runtime/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * // Before:\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n * const handleSend = () => {\n * if (runtime.getState().canSend) {\n * runtime.send();\n * }\n * };\n * const handleCancel = () => {\n * if (runtime.getState().canCancel) {\n * runtime.cancel();\n * }\n * };\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n *\n * // After:\n * function ComposerActions() {\n * const api = useAssistantApi();\n * const canSend = useAssistantState(({ composer }) => composer.canSend);\n * const canCancel = useAssistantState(({ composer }) => composer.canCancel);\n * const handleSend = () => {\n * if (canSend) {\n * api.composer().send();\n * }\n * };\n * const handleCancel = () => {\n * if (canCancel) {\n * api.composer().cancel();\n * }\n * };\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.composer.source\n ? (api.composer().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ComposerRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the current composer state.\n *\n * This hook provides reactive access to the composer's state, including text content,\n * attachments, editing status, and send/cancel capabilities.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected composer state or the entire composer state if no selector provided\n *\n * @example\n * ```tsx\n * // Before:\n * function ComposerStatus() {\n * const text = useComposer((state) => state.text);\n * const canSend = useComposer((state) => state.canSend);\n * const attachmentCount = useComposer((state) => state.attachments.length);\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n *\n * // After:\n * function ComposerStatus() {\n * const text = useAssistantState(({ composer }) => composer.text);\n * const canSend = useAssistantState(({ composer }) => composer.canSend);\n * const attachmentCount = useAssistantState(({ composer }) => composer.attachments.length);\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n * ```\n */\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,iBAAiB,yBAAyB;AAEnD,SAAS,iCAAiC;AAqEnC,SAAS,mBAAmB,SAER;AACzB,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,SAAS,SACR,IAAI,SAAS,EAAE,wBAAwB,KAAK,OAC7C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AACA,SAAO;AACT;AA4CO,IAAM,cAAc,0BAA0B,kBAAkB;","names":[]}
@@ -1,5 +1,7 @@
1
1
  import { MessageRuntime } from "../runtime/MessageRuntime";
2
2
  /**
3
+ * @deprecated Use `useAssistantApi()` with `api.message()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
4
+ *
3
5
  * Hook to access the MessageRuntime from the current context.
4
6
  *
5
7
  * The MessageRuntime provides access to message-level state and actions,
@@ -11,17 +13,32 @@ import { MessageRuntime } from "../runtime/MessageRuntime";
11
13
  *
12
14
  * @example
13
15
  * ```tsx
16
+ * // Before:
14
17
  * function MessageActions() {
15
18
  * const runtime = useMessageRuntime();
16
- *
17
19
  * const handleReload = () => {
18
20
  * runtime.reload();
19
21
  * };
20
- *
21
22
  * const handleEdit = () => {
22
23
  * runtime.startEdit();
23
24
  * };
25
+ * return (
26
+ * <div>
27
+ * <button onClick={handleReload}>Reload</button>
28
+ * <button onClick={handleEdit}>Edit</button>
29
+ * </div>
30
+ * );
31
+ * }
24
32
  *
33
+ * // After:
34
+ * function MessageActions() {
35
+ * const api = useAssistantApi();
36
+ * const handleReload = () => {
37
+ * api.message().reload();
38
+ * };
39
+ * const handleEdit = () => {
40
+ * api.message().startEdit();
41
+ * };
25
42
  * return (
26
43
  * <div>
27
44
  * <button onClick={handleReload}>Reload</button>
@@ -38,6 +55,8 @@ export declare function useMessageRuntime(options?: {
38
55
  optional?: boolean | undefined;
39
56
  }): MessageRuntime | null;
40
57
  /**
58
+ * @deprecated Use `useAssistantState(({ message }) => message)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
59
+ *
41
60
  * Hook to access the current message state.
42
61
  *
43
62
  * This hook provides reactive access to the message's state, including content,
@@ -48,11 +67,23 @@ export declare function useMessageRuntime(options?: {
48
67
  *
49
68
  * @example
50
69
  * ```tsx
70
+ * // Before:
51
71
  * function MessageContent() {
52
72
  * const role = useMessage((state) => state.role);
53
73
  * const content = useMessage((state) => state.content);
54
74
  * const isLoading = useMessage((state) => state.status.type === "running");
75
+ * return (
76
+ * <div className={`message-${role}`}>
77
+ * {isLoading ? "Loading..." : content.map(part => part.text).join("")}
78
+ * </div>
79
+ * );
80
+ * }
55
81
  *
82
+ * // After:
83
+ * function MessageContent() {
84
+ * const role = useAssistantState(({ message }) => message.role);
85
+ * const content = useAssistantState(({ message }) => message.content);
86
+ * const isLoading = useAssistantState(({ message }) => message.status.type === "running");
56
87
  * return (
57
88
  * <div className={`message-${role}`}>
58
89
  * {isLoading ? "Loading..." : content.map(part => part.text).join("")}
@@ -88,6 +119,9 @@ export declare const useMessage: {
88
119
  selector: ((state: import("../runtime").MessageState) => TSelected) | undefined;
89
120
  }): import("../runtime").MessageState | TSelected | null;
90
121
  };
122
+ /**
123
+ * @deprecated Use `useAssistantState(({ message }) => message.composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
124
+ */
91
125
  export declare const useEditComposer: {
92
126
  (): import("../runtime").EditComposerState;
93
127
  <TSelected>(selector: (state: import("../runtime").EditComposerState) => TSelected): TSelected;
@@ -1 +1 @@
1
- {"version":3,"file":"MessageContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/MessageContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,cAAc,CAAC;AACnB,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,cAAc,GAAG,IAAI,CAAC;AAgB1B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;CAA+C,CAAC;AAKvE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;CAE3B,CAAC"}
1
+ {"version":3,"file":"MessageContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/MessageContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,cAAc,CAAC;AACnB,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,cAAc,GAAG,IAAI,CAAC;AAgB1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;CAA+C,CAAC;AAMvE;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;CAE3B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/hooks/MessageContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessageRuntime } from \"../runtime/MessageRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { EditComposerRuntime } from \"../runtime\";\n\n/**\n * Hook to access the MessageRuntime from the current context.\n *\n * The MessageRuntime provides access to message-level state and actions,\n * including message content, status, editing capabilities, and branching.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The MessageRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MessageActions() {\n * const runtime = useMessageRuntime();\n *\n * const handleReload = () => {\n * runtime.reload();\n * };\n *\n * const handleEdit = () => {\n * runtime.startEdit();\n * };\n *\n * return (\n * <div>\n * <button onClick={handleReload}>Reload</button>\n * <button onClick={handleEdit}>Edit</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useMessageRuntime(options?: {\n optional?: false | undefined;\n}): MessageRuntime;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}): MessageRuntime | null;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.message.source\n ? (api.message().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"MessageRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * Hook to access the current message state.\n *\n * This hook provides reactive access to the message's state, including content,\n * role, status, and other message-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected message state or the entire message state if no selector provided\n *\n * @example\n * ```tsx\n * function MessageContent() {\n * const role = useMessage((state) => state.role);\n * const content = useMessage((state) => state.content);\n * const isLoading = useMessage((state) => state.status.type === \"running\");\n *\n * return (\n * <div className={`message-${role}`}>\n * {isLoading ? \"Loading...\" : content.map(part => part.text).join(\"\")}\n * </div>\n * );\n * }\n * ```\n */\nexport const useMessage = createStateHookForRuntime(useMessageRuntime);\n\nconst useEditComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;\nexport const useEditComposer = createStateHookForRuntime(\n useEditComposerRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,iCAAiC;AAyCnC,SAAS,kBAAkB,SAE/B;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,QAAQ,SACP,IAAI,QAAQ,EAAE,wBAAwB,KAAK,OAC5C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,SAAO;AACT;AA0BO,IAAM,aAAa,0BAA0B,iBAAiB;AAErE,IAAM,yBAAyB,CAAC,QAEE,kBAAkB,GAAG,GAAG,YAAY;AAC/D,IAAM,kBAAkB;AAAA,EAC7B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/hooks/MessageContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessageRuntime } from \"../runtime/MessageRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { EditComposerRuntime } from \"../runtime\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.message()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the MessageRuntime from the current context.\n *\n * The MessageRuntime provides access to message-level state and actions,\n * including message content, status, editing capabilities, and branching.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The MessageRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * // Before:\n * function MessageActions() {\n * const runtime = useMessageRuntime();\n * const handleReload = () => {\n * runtime.reload();\n * };\n * const handleEdit = () => {\n * runtime.startEdit();\n * };\n * return (\n * <div>\n * <button onClick={handleReload}>Reload</button>\n * <button onClick={handleEdit}>Edit</button>\n * </div>\n * );\n * }\n *\n * // After:\n * function MessageActions() {\n * const api = useAssistantApi();\n * const handleReload = () => {\n * api.message().reload();\n * };\n * const handleEdit = () => {\n * api.message().startEdit();\n * };\n * return (\n * <div>\n * <button onClick={handleReload}>Reload</button>\n * <button onClick={handleEdit}>Edit</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useMessageRuntime(options?: {\n optional?: false | undefined;\n}): MessageRuntime;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}): MessageRuntime | null;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.message.source\n ? (api.message().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"MessageRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use `useAssistantState(({ message }) => message)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the current message state.\n *\n * This hook provides reactive access to the message's state, including content,\n * role, status, and other message-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected message state or the entire message state if no selector provided\n *\n * @example\n * ```tsx\n * // Before:\n * function MessageContent() {\n * const role = useMessage((state) => state.role);\n * const content = useMessage((state) => state.content);\n * const isLoading = useMessage((state) => state.status.type === \"running\");\n * return (\n * <div className={`message-${role}`}>\n * {isLoading ? \"Loading...\" : content.map(part => part.text).join(\"\")}\n * </div>\n * );\n * }\n *\n * // After:\n * function MessageContent() {\n * const role = useAssistantState(({ message }) => message.role);\n * const content = useAssistantState(({ message }) => message.content);\n * const isLoading = useAssistantState(({ message }) => message.status.type === \"running\");\n * return (\n * <div className={`message-${role}`}>\n * {isLoading ? \"Loading...\" : content.map(part => part.text).join(\"\")}\n * </div>\n * );\n * }\n * ```\n */\nexport const useMessage = createStateHookForRuntime(useMessageRuntime);\n\nconst useEditComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;\n\n/**\n * @deprecated Use `useAssistantState(({ message }) => message.composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport const useEditComposer = createStateHookForRuntime(\n useEditComposerRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,iCAAiC;AA0DnC,SAAS,kBAAkB,SAE/B;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,QAAQ,SACP,IAAI,QAAQ,EAAE,wBAAwB,KAAK,OAC5C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,SAAO;AACT;AAwCO,IAAM,aAAa,0BAA0B,iBAAiB;AAErE,IAAM,yBAAyB,CAAC,QAEE,kBAAkB,GAAG,GAAG,YAAY;AAK/D,IAAM,kBAAkB;AAAA,EAC7B;AACF;","names":[]}
@@ -1,10 +1,16 @@
1
1
  import { MessagePartRuntime } from "../runtime/MessagePartRuntime";
2
+ /**
3
+ * @deprecated Use `useAssistantApi()` with `api.part()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
4
+ */
2
5
  export declare function useMessagePartRuntime(options?: {
3
6
  optional?: false | undefined;
4
7
  }): MessagePartRuntime;
5
8
  export declare function useMessagePartRuntime(options?: {
6
9
  optional?: boolean | undefined;
7
10
  }): MessagePartRuntime | null;
11
+ /**
12
+ * @deprecated Use `useAssistantState(({ part }) => part)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
13
+ */
8
14
  export declare const useMessagePart: {
9
15
  (): import("../runtime").MessagePartState;
10
16
  <TSelected>(selector: (state: import("../runtime").MessagePartState) => TSelected): TSelected;
@@ -1 +1 @@
1
- {"version":3,"file":"MessagePartContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAInE,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,CAAC;AACvB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAc9B,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CAAmD,CAAC"}
1
+ {"version":3,"file":"MessagePartContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAInE;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,CAAC;AACvB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAc9B;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CAAmD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessagePartRuntime } from \"../runtime/MessagePartRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useMessagePartRuntime(options?: {\n optional?: false | undefined;\n}): MessagePartRuntime;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}): MessagePartRuntime | null;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.part.source ? (api.part().__internal_getRuntime?.() ?? null) : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"MessagePartRuntime is not available\");\n }\n return runtime;\n}\n\nexport const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,sBAAsB,SAEnC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,KAAK,SAAU,IAAI,KAAK,EAAE,wBAAwB,KAAK,OAAQ;AAAA,EACrE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AACA,SAAO;AACT;AAEO,IAAM,iBAAiB,0BAA0B,qBAAqB;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessagePartRuntime } from \"../runtime/MessagePartRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.part()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport function useMessagePartRuntime(options?: {\n optional?: false | undefined;\n}): MessagePartRuntime;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}): MessagePartRuntime | null;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.part.source ? (api.part().__internal_getRuntime?.() ?? null) : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"MessagePartRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use `useAssistantState(({ part }) => part)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAW5C,SAAS,sBAAsB,SAEnC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,KAAK,SAAU,IAAI,KAAK,EAAE,wBAAwB,KAAK,OAAQ;AAAA,EACrE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AACA,SAAO;AACT;AAKO,IAAM,iBAAiB,0BAA0B,qBAAqB;","names":[]}
@@ -1,6 +1,8 @@
1
1
  import { ThreadRuntime } from "../runtime/ThreadRuntime";
2
2
  import { ModelContext } from "../../model-context";
3
3
  /**
4
+ * @deprecated Use `useAssistantApi()` with `api.thread()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
5
+ *
4
6
  * Hook to access the ThreadRuntime from the current context.
5
7
  *
6
8
  * The ThreadRuntime provides access to thread-level state and actions,
@@ -12,13 +14,21 @@ import { ModelContext } from "../../model-context";
12
14
  *
13
15
  * @example
14
16
  * ```tsx
17
+ * // Before:
15
18
  * function MyComponent() {
16
19
  * const runtime = useThreadRuntime();
17
- *
18
20
  * const handleSendMessage = (text: string) => {
19
21
  * runtime.append({ role: "user", content: [{ type: "text", text }] });
20
22
  * };
23
+ * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
24
+ * }
21
25
  *
26
+ * // After:
27
+ * function MyComponent() {
28
+ * const api = useAssistantApi();
29
+ * const handleSendMessage = (text: string) => {
30
+ * api.thread().append({ role: "user", content: [{ type: "text", text }] });
31
+ * };
22
32
  * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
23
33
  * }
24
34
  * ```
@@ -30,6 +40,8 @@ export declare function useThreadRuntime(options?: {
30
40
  optional?: boolean | undefined;
31
41
  }): ThreadRuntime | null;
32
42
  /**
43
+ * @deprecated Use `useAssistantState(({ thread }) => thread)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
44
+ *
33
45
  * Hook to access the current thread state.
34
46
  *
35
47
  * This hook provides reactive access to the thread's state, including messages,
@@ -40,10 +52,17 @@ export declare function useThreadRuntime(options?: {
40
52
  *
41
53
  * @example
42
54
  * ```tsx
55
+ * // Before:
43
56
  * function ThreadStatus() {
44
57
  * const isRunning = useThread((state) => state.isRunning);
45
58
  * const messageCount = useThread((state) => state.messages.length);
59
+ * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
60
+ * }
46
61
  *
62
+ * // After:
63
+ * function ThreadStatus() {
64
+ * const isRunning = useAssistantState(({ thread }) => thread.isRunning);
65
+ * const messageCount = useAssistantState(({ thread }) => thread.messages.length);
47
66
  * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
48
67
  * }
49
68
  * ```
@@ -75,6 +94,9 @@ export declare const useThread: {
75
94
  selector: ((state: import("../runtime").ThreadState) => TSelected) | undefined;
76
95
  }): import("../runtime").ThreadState | TSelected | null;
77
96
  };
97
+ /**
98
+ * @deprecated Use `useAssistantState(({ thread }) => thread.composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
99
+ */
78
100
  export declare const useThreadComposer: {
79
101
  (): import("../runtime").ThreadComposerState;
80
102
  <TSelected>(selector: (state: import("../runtime").ThreadComposerState) => TSelected): TSelected;
@@ -102,6 +124,9 @@ export declare const useThreadComposer: {
102
124
  selector: ((state: import("../runtime").ThreadComposerState) => TSelected) | undefined;
103
125
  }): import("../runtime").ThreadComposerState | TSelected | null;
104
126
  };
127
+ /**
128
+ * @deprecated Use `useAssistantState(({ thread }) => thread.modelContext)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
129
+ */
105
130
  export declare function useThreadModelContext(options?: {
106
131
  optional?: false | undefined;
107
132
  }): ModelContext;
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,aAAa,CAAC;AAClB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,aAAa,GAAG,IAAI,CAAC;AAYzB;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;CAA8C,CAAC;AAKrE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,YAAY,CAAC;AACjB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,YAAY,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"ThreadContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,aAAa,CAAC;AAClB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,aAAa,GAAG,IAAI,CAAC;AAYzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;CAA8C,CAAC;AAMrE;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,YAAY,CAAC;AACjB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,YAAY,GAAG,IAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { ThreadRuntime } from \"../runtime/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../runtime\";\nimport {\n useAssistantApi,\n useAssistantEvent,\n useAssistantState,\n} from \"../../context/react\";\n\n/**\n * Hook to access the ThreadRuntime from the current context.\n *\n * The ThreadRuntime provides access to thread-level state and actions,\n * including message management, thread state, and composer functionality.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ThreadRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const runtime = useThreadRuntime();\n *\n * const handleSendMessage = (text: string) => {\n * runtime.append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n *\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n * ```\n */\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.thread.source ? (api.thread().__internal_getRuntime?.() ?? null) : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * Hook to access the current thread state.\n *\n * This hook provides reactive access to the thread's state, including messages,\n * running status, capabilities, and other thread-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected thread state or the entire thread state if no selector provided\n *\n * @example\n * ```tsx\n * function ThreadStatus() {\n * const isRunning = useThread((state) => state.isRunning);\n * const messageCount = useThread((state) => state.messages.length);\n *\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n * ```\n */\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useAssistantEvent(\"thread.model-context-update\", () => rerender({}));\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,gBAAgB;AAGzB,SAAS,iCAAiC;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA+BA,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,OAAO,SAAU,IAAI,OAAO,EAAE,wBAAwB,KAAK,OAAQ;AAAA,EACzE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO;AACT;AAqBO,IAAM,YAAY,0BAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,oBAAkB,+BAA+B,MAAM,SAAS,CAAC,CAAC,CAAC;AAEnE,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { ThreadRuntime } from \"../runtime/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../runtime\";\nimport {\n useAssistantApi,\n useAssistantEvent,\n useAssistantState,\n} from \"../../context/react\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.thread()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the ThreadRuntime from the current context.\n *\n * The ThreadRuntime provides access to thread-level state and actions,\n * including message management, thread state, and composer functionality.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ThreadRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * // Before:\n * function MyComponent() {\n * const runtime = useThreadRuntime();\n * const handleSendMessage = (text: string) => {\n * runtime.append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n *\n * // After:\n * function MyComponent() {\n * const api = useAssistantApi();\n * const handleSendMessage = (text: string) => {\n * api.thread().append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n * ```\n */\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.thread.source ? (api.thread().__internal_getRuntime?.() ?? null) : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use `useAssistantState(({ thread }) => thread)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the current thread state.\n *\n * This hook provides reactive access to the thread's state, including messages,\n * running status, capabilities, and other thread-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected thread state or the entire thread state if no selector provided\n *\n * @example\n * ```tsx\n * // Before:\n * function ThreadStatus() {\n * const isRunning = useThread((state) => state.isRunning);\n * const messageCount = useThread((state) => state.messages.length);\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n *\n * // After:\n * function ThreadStatus() {\n * const isRunning = useAssistantState(({ thread }) => thread.isRunning);\n * const messageCount = useAssistantState(({ thread }) => thread.messages.length);\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n * ```\n */\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\n\n/**\n * @deprecated Use `useAssistantState(({ thread }) => thread.composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\n/**\n * @deprecated Use `useAssistantState(({ thread }) => thread.modelContext)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useAssistantEvent(\"thread.model-context-update\", () => rerender({}));\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,gBAAgB;AAGzB,SAAS,iCAAiC;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAyCA,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,OAAO,SAAU,IAAI,OAAO,EAAE,wBAAwB,KAAK,OAAQ;AAAA,EACzE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO;AACT;AA8BO,IAAM,YAAY,0BAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAKhE,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAWO,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,oBAAkB,+BAA+B,MAAM,SAAS,CAAC,CAAC,CAAC;AAEnE,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
@@ -1,10 +1,16 @@
1
1
  import { ThreadListItemRuntime } from "../runtime/ThreadListItemRuntime";
2
+ /**
3
+ * @deprecated Use `useAssistantApi()` with `api.threadListItem()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
4
+ */
2
5
  export declare function useThreadListItemRuntime(options?: {
3
6
  optional?: false | undefined;
4
7
  }): ThreadListItemRuntime;
5
8
  export declare function useThreadListItemRuntime(options?: {
6
9
  optional?: boolean | undefined;
7
10
  }): ThreadListItemRuntime | null;
11
+ /**
12
+ * @deprecated Use `useAssistantState(({ threadListItem }) => threadListItem)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
13
+ */
8
14
  export declare const useThreadListItem: {
9
15
  (): import("../runtime").ThreadListItemState;
10
16
  <TSelected>(selector: (state: import("../runtime").ThreadListItemState) => TSelected): TSelected;
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadListItemContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,qBAAqB,CAAC;AAC1B,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,qBAAqB,GAAG,IAAI,CAAC;AAgBjC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC"}
1
+ {"version":3,"file":"ThreadListItemContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAIzE;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,qBAAqB,CAAC;AAC1B,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,qBAAqB,GAAG,IAAI,CAAC;AAgBjC;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"sourcesContent":["\"use client\";\n\nimport { ThreadListItemRuntime } from \"../runtime/ThreadListItemRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useThreadListItemRuntime(options?: {\n optional?: false | undefined;\n}): ThreadListItemRuntime;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadListItemRuntime | null;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.threadListItem.source\n ? (api.threadListItem().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadListItemRuntime is not available\");\n }\n return runtime;\n}\n\nexport const useThreadListItem = createStateHookForRuntime(\n useThreadListItemRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,yBAAyB,SAEtC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,eAAe,SACd,IAAI,eAAe,EAAE,wBAAwB,KAAK,OACnD;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACA,SAAO;AACT;AAEO,IAAM,oBAAoB;AAAA,EAC/B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"sourcesContent":["\"use client\";\n\nimport { ThreadListItemRuntime } from \"../runtime/ThreadListItemRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.threadListItem()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport function useThreadListItemRuntime(options?: {\n optional?: false | undefined;\n}): ThreadListItemRuntime;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadListItemRuntime | null;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.threadListItem.source\n ? (api.threadListItem().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadListItemRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use `useAssistantState(({ threadListItem }) => threadListItem)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport const useThreadListItem = createStateHookForRuntime(\n useThreadListItemRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAW5C,SAAS,yBAAyB,SAEtC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,eAAe,SACd,IAAI,eAAe,EAAE,wBAAwB,KAAK,OACnD;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACA,SAAO;AACT;AAKO,IAAM,oBAAoB;AAAA,EAC/B;AACF;","names":[]}
@@ -1,3 +1,3 @@
1
- export { useAssistantTransportRuntime, useAssistantTransportSendCommand, } from "./useAssistantTransportRuntime";
2
- export type { AssistantTransportConnectionMetadata, AssistantTransportCommand, } from "./types";
1
+ export { useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, } from "./useAssistantTransportRuntime";
2
+ export type { AssistantTransportConnectionMetadata, AssistantTransportCommand, AssistantTransportProtocol, } from "./types";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,GACjC,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,oCAAoC,EACpC,yBAAyB,GAC1B,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,oCAAoC,EACpC,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,SAAS,CAAC"}
@@ -1,10 +1,12 @@
1
1
  // src/legacy-runtime/runtime-cores/assistant-transport/index.ts
2
2
  import {
3
3
  useAssistantTransportRuntime,
4
- useAssistantTransportSendCommand
4
+ useAssistantTransportSendCommand,
5
+ useAssistantTransportState
5
6
  } from "./useAssistantTransportRuntime.js";
6
7
  export {
7
8
  useAssistantTransportRuntime,
8
- useAssistantTransportSendCommand
9
+ useAssistantTransportSendCommand,
10
+ useAssistantTransportState
9
11
  };
10
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/index.ts"],"sourcesContent":["export {\n useAssistantTransportRuntime,\n useAssistantTransportSendCommand,\n} from \"./useAssistantTransportRuntime\";\nexport type {\n AssistantTransportConnectionMetadata,\n AssistantTransportCommand,\n} from \"./types\";\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/index.ts"],"sourcesContent":["export {\n useAssistantTransportRuntime,\n useAssistantTransportSendCommand,\n useAssistantTransportState,\n} from \"./useAssistantTransportRuntime\";\nexport type {\n AssistantTransportConnectionMetadata,\n AssistantTransportCommand,\n AssistantTransportProtocol,\n} from \"./types\";\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -50,10 +50,12 @@ export type CommandQueueState = {
50
50
  };
51
51
  export type QueuedCommand = AssistantTransportCommand;
52
52
  export type HeadersValue = Record<string, string> | Headers;
53
+ export type AssistantTransportProtocol = "data-stream" | "assistant-transport";
53
54
  export type AssistantTransportOptions<T> = {
54
55
  initialState: T;
55
56
  api: string;
56
57
  resumeApi?: string;
58
+ protocol?: AssistantTransportProtocol;
57
59
  converter: AssistantTransportStateConverter<T>;
58
60
  headers: HeadersValue | (() => Promise<HeadersValue>);
59
61
  body?: object;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM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CAAC,MAAM,EAAE;QAClB,QAAQ,EAAE,yBAAyB,EAAE,CAAC;QACtC,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;KACjD,KAAK,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE;QACT,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;QAC5C,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC;KAC5C,CAAC;CACH,CAAC"}
@@ -1,6 +1,9 @@
1
1
  import { AssistantRuntime } from "../../runtime/AssistantRuntime";
2
2
  import { AssistantTransportOptions, AssistantTransportCommand } from "./types";
3
+ import { UserExternalState } from "../../../augmentations";
3
4
  export declare const useAssistantTransportSendCommand: () => (command: AssistantTransportCommand) => void;
5
+ export declare function useAssistantTransportState(): UserExternalState;
6
+ export declare function useAssistantTransportState<T>(selector: (state: UserExternalState) => T): T;
4
7
  /**
5
8
  * @alpha This is an experimental API that is subject to change.
6
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useAssistantTransportRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAQlE,OAAO,EACL,yBAAyB,EAKzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AA+BjB,eAAO,MAAM,gCAAgC,SAGnC,SAAS,yBAAyB,SAK3C,CAAC;AAyNF;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,EAC5C,SAAS,yBAAyB,CAAC,CAAC,CAAC,KACpC,gBAQF,CAAC"}
1
+ {"version":3,"file":"useAssistantTransportRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AASlE,OAAO,EACL,yBAAyB,EAKzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AASjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D,eAAO,MAAM,gCAAgC,SAGnC,SAAS,yBAAyB,SAK3C,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,iBAAiB,CAAC;AAChE,wBAAgB,0BAA0B,CAAC,CAAC,EAC1C,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,CAAC,GACxC,CAAC,CAAC;AAsOL;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,EAC5C,SAAS,yBAAyB,CAAC,CAAC,CAAC,KACpC,gBAQF,CAAC"}
@@ -9,6 +9,7 @@ import { useState, useRef, useMemo } from "react";
9
9
  import {
10
10
  AssistantMessageAccumulator,
11
11
  DataStreamDecoder,
12
+ AssistantTransportDecoder,
12
13
  unstable_createInitialMessage as createInitialMessage
13
14
  } from "assistant-stream";
14
15
  import { useCommandQueue } from "./commandQueue.js";
@@ -18,7 +19,7 @@ import { useToolInvocations } from "./useToolInvocations.js";
18
19
  import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils.js";
19
20
  import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime.js";
20
21
  import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory.js";
21
- import { useAssistantApi } from "../../../context/react/index.js";
22
+ import { useAssistantApi, useAssistantState } from "../../../context/react/index.js";
22
23
  var symbolAssistantTransportExtras = Symbol("assistant-transport-extras");
23
24
  var asAssistantTransportExtras = (extras) => {
24
25
  if (typeof extras !== "object" || extras == null || !(symbolAssistantTransportExtras in extras))
@@ -35,6 +36,11 @@ var useAssistantTransportSendCommand = () => {
35
36
  transportExtras.sendCommand(command);
36
37
  };
37
38
  };
39
+ function useAssistantTransportState(selector = (t) => t) {
40
+ return useAssistantState(
41
+ ({ thread }) => selector(asAssistantTransportExtras(thread.extras).state)
42
+ );
43
+ }
38
44
  var useAssistantTransportThreadRuntime = (options) => {
39
45
  const agentStateRef = useRef(options.initialState);
40
46
  const [, rerender] = useState(0);
@@ -75,8 +81,10 @@ var useAssistantTransportThreadRuntime = (options) => {
75
81
  if (!response.body) {
76
82
  throw new Error("Response body is null");
77
83
  }
84
+ const protocol = options.protocol ?? "data-stream";
85
+ const decoder = protocol === "assistant-transport" ? new AssistantTransportDecoder() : new DataStreamDecoder();
78
86
  let err;
79
- const stream = response.body.pipeThrough(new DataStreamDecoder()).pipeThrough(
87
+ const stream = response.body.pipeThrough(decoder).pipeThrough(
80
88
  new AssistantMessageAccumulator({
81
89
  initialMessage: createInitialMessage({
82
90
  unstable_state: agentStateRef.current ?? null
@@ -149,7 +157,8 @@ var useAssistantTransportThreadRuntime = (options) => {
149
157
  [symbolAssistantTransportExtras]: true,
150
158
  sendCommand: (command) => {
151
159
  commandQueue.enqueue(command);
152
- }
160
+ },
161
+ state: agentStateRef.current
153
162
  },
154
163
  onNew: async (message) => {
155
164
  if (message.role !== "user")
@@ -221,6 +230,7 @@ var useAssistantTransportRuntime = (options) => {
221
230
  };
222
231
  export {
223
232
  useAssistantTransportRuntime,
224
- useAssistantTransportSendCommand
233
+ useAssistantTransportSendCommand,
234
+ useAssistantTransportState
225
235
  };
226
236
  //# sourceMappingURL=useAssistantTransportRuntime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReadonlyJSONObject,\n type ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { AppendMessage } from \"../../../types\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport { AddToolResultOptions } from \"../core\";\nimport { useState, useRef, useMemo } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n unstable_createInitialMessage as createInitialMessage,\n} from \"assistant-stream\";\nimport {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n AssistantTransportCommand,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport { ToolExecutionStatus, useToolInvocations } from \"./useToolInvocations\";\nimport { toAISDKTools, getEnabledTools, createRequestHeaders } from \"./utils\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"../remote-thread-list/adapter/in-memory\";\nimport { useAssistantApi } from \"../../../context/react\";\n\nconst symbolAssistantTransportExtras = Symbol(\"assistant-transport-extras\");\ntype AssistantTransportExtras = {\n [symbolAssistantTransportExtras]: true;\n sendCommand: (command: AssistantTransportCommand) => void;\n};\n\nconst asAssistantTransportExtras = (\n extras: unknown,\n): AssistantTransportExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolAssistantTransportExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useAssistantTransportRuntime\",\n );\n\n return extras as AssistantTransportExtras;\n};\n\nexport const useAssistantTransportSendCommand = () => {\n const api = useAssistantApi();\n\n return (command: AssistantTransportCommand) => {\n const extras = api.thread().getState().extras;\n const transportExtras = asAssistantTransportExtras(extras);\n transportExtras.sendCommand(command);\n };\n};\n\nconst useAssistantTransportThreadRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume)\n throw new Error(\"No commands to send\");\n\n const headers = await createRequestHeaders(options.headers);\n const context = runtime.thread.getModelContext();\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n commands,\n state: agentStateRef.current,\n system: context.system,\n tools: context.tools\n ? toAISDKTools(getEnabledTools(context.tools))\n : undefined,\n ...context.callSettings,\n ...context.config,\n ...options.body,\n }),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n let err: string | undefined;\n const stream = response.body\n .pipeThrough(new DataStreamDecoder())\n .pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n throttle: isResume,\n onError: (error) => {\n err = error;\n },\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n\n if (err) {\n throw new Error(err);\n }\n },\n onFinish: options.onFinish,\n onCancel: () => {\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n\n commandQueue.reset();\n },\n onError: (error) => {\n const cmds = [...commandQueue.state.inTransit];\n options.onError?.(error as Error, {\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n commandQueue.markDelivered();\n },\n });\n\n // Tool execution status state\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n toolStatuses,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n messages: converted.messages,\n state: converted.state,\n isRunning: converted.isRunning,\n adapters: options.adapters,\n extras: {\n [symbolAssistantTransportExtras]: true,\n sendCommand: (command: AssistantTransportCommand) => {\n commandQueue.enqueue(command);\n },\n } satisfies AssistantTransportExtras,\n onNew: async (message: AppendMessage): Promise<void> => {\n if (message.role !== \"user\")\n throw new Error(\"Only user messages are supported\");\n\n // Convert AppendMessage to AddMessageCommand\n const parts: UserMessagePart[] = [];\n\n const content = [\n ...message.content,\n ...(message.attachments?.flatMap((a) => a.content) ?? []),\n ];\n for (const contentPart of content) {\n if (contentPart.type === \"text\") {\n parts.push({ type: \"text\", text: contentPart.text });\n } else if (contentPart.type === \"image\") {\n parts.push({ type: \"image\", image: contentPart.image });\n }\n }\n\n const command: AddMessageCommand = {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n };\n\n commandQueue.enqueue(command);\n },\n onCancel: async () => {\n runManager.cancel();\n toolInvocations.abort();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n toolInvocations.reset();\n rerender((prev) => prev + 1);\n },\n });\n\n const toolInvocations = useToolInvocations({\n state: converted,\n getTools: () => runtime.thread.getModelContext().tools,\n onResult: commandQueue.enqueue,\n setToolStatuses,\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n });\n return runtime;\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,+BAA+B;AAGxC,SAAS,UAAU,QAAQ,eAAe;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA,iCAAiC;AAAA,OAC5B;AASP,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAA8B,0BAA0B;AACxD,SAAS,cAAc,iBAAiB,4BAA4B;AACpE,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAC1C,SAAS,uBAAuB;AAEhC,IAAM,iCAAiC,OAAO,4BAA4B;AAM1E,IAAM,6BAA6B,CACjC,WAC6B;AAC7B,MACE,OAAO,WAAW,YAClB,UAAU,QACV,EAAE,kCAAkC;AAEpC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAEO,IAAM,mCAAmC,MAAM;AACpD,QAAM,MAAM,gBAAgB;AAE5B,SAAO,CAAC,YAAuC;AAC7C,UAAM,SAAS,IAAI,OAAO,EAAE,SAAS,EAAE;AACvC,UAAM,kBAAkB,2BAA2B,MAAM;AACzD,oBAAgB,YAAY,OAAO;AAAA,EACrC;AACF;AAEA,IAAM,qCAAqC,CACzC,YACqB;AACrB,QAAM,gBAAgB,OAAO,QAAQ,YAAY;AACjD,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC;AAC/B,QAAM,gBAAgB,OAAO,KAAK;AAClC,QAAM,eAAe,g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,YAAY;AAAA,QACxB,QAAQ,YAAY;AAAA,QACpB,UAAU,YAAY;AAAA,QACtB,SAAS,YAAY;AAAA,QACrB,GAAI,YAAY,YAAY,EAAE,UAAU,YAAY,SAAS;AAAA,MAC/D;AAEA,mBAAa,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,qBAAqB,OAAO,UAAU;AACpC,oBAAc,UAAU;AACxB,sBAAgB,MAAM;AACtB,eAAS,CAAC,SAAS,OAAO,CAAC;AAAA,IAC7B;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB;AAAA,IACzC,OAAO;AAAA,IACP,UAAU,MAAM,QAAQ,OAAO,gBAAgB,EAAE;AAAA,IACjD,UAAU,aAAa;AAAA,IACvB;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAKO,IAAM,+BAA+B,CAC1C,YACqB;AACrB,QAAM,UAAU,2BAA2B;AAAA,IACzC,aAAa,SAAS,cAAc;AAClC,aAAO,mCAAmC,OAAO;AAAA,IACnD;AAAA,IACA,SAAS,IAAI,0BAA0B;AAAA,EACzC,CAAC;AACD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReadonlyJSONObject,\n type ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { AppendMessage } from \"../../../types\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport { AddToolResultOptions } from \"../core\";\nimport { useState, useRef, useMemo } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n AssistantTransportDecoder,\n unstable_createInitialMessage as createInitialMessage,\n} from \"assistant-stream\";\nimport {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n AssistantTransportCommand,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport { ToolExecutionStatus, useToolInvocations } from \"./useToolInvocations\";\nimport { toAISDKTools, getEnabledTools, createRequestHeaders } from \"./utils\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"../remote-thread-list/adapter/in-memory\";\nimport { useAssistantApi, useAssistantState } from \"../../../context/react\";\nimport { UserExternalState } from \"../../../augmentations\";\n\nconst symbolAssistantTransportExtras = Symbol(\"assistant-transport-extras\");\ntype AssistantTransportExtras = {\n [symbolAssistantTransportExtras]: true;\n sendCommand: (command: AssistantTransportCommand) => void;\n state: UserExternalState;\n};\n\nconst asAssistantTransportExtras = (\n extras: unknown,\n): AssistantTransportExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolAssistantTransportExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useAssistantTransportRuntime\",\n );\n\n return extras as AssistantTransportExtras;\n};\n\nexport const useAssistantTransportSendCommand = () => {\n const api = useAssistantApi();\n\n return (command: AssistantTransportCommand) => {\n const extras = api.thread().getState().extras;\n const transportExtras = asAssistantTransportExtras(extras);\n transportExtras.sendCommand(command);\n };\n};\n\nexport function useAssistantTransportState(): UserExternalState;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T,\n): T;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T = (t) => t as T,\n): T | UserExternalState {\n return useAssistantState(({ thread }) =>\n selector(asAssistantTransportExtras(thread.extras).state),\n );\n}\n\nconst useAssistantTransportThreadRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume)\n throw new Error(\"No commands to send\");\n\n const headers = await createRequestHeaders(options.headers);\n const context = runtime.thread.getModelContext();\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n commands,\n state: agentStateRef.current,\n system: context.system,\n tools: context.tools\n ? toAISDKTools(getEnabledTools(context.tools))\n : undefined,\n ...context.callSettings,\n ...context.config,\n ...options.body,\n }),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Select decoder based on protocol option\n const protocol = options.protocol ?? \"data-stream\";\n const decoder =\n protocol === \"assistant-transport\"\n ? new AssistantTransportDecoder()\n : new DataStreamDecoder();\n\n let err: string | undefined;\n const stream = response.body.pipeThrough(decoder).pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n throttle: isResume,\n onError: (error) => {\n err = error;\n },\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n\n if (err) {\n throw new Error(err);\n }\n },\n onFinish: options.onFinish,\n onCancel: () => {\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n\n commandQueue.reset();\n },\n onError: (error) => {\n const cmds = [...commandQueue.state.inTransit];\n options.onError?.(error as Error, {\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n commandQueue.markDelivered();\n },\n });\n\n // Tool execution status state\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n toolStatuses,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n messages: converted.messages,\n state: converted.state,\n isRunning: converted.isRunning,\n adapters: options.adapters,\n extras: {\n [symbolAssistantTransportExtras]: true,\n sendCommand: (command: AssistantTransportCommand) => {\n commandQueue.enqueue(command);\n },\n state: agentStateRef.current as UserExternalState,\n } satisfies AssistantTransportExtras,\n onNew: async (message: AppendMessage): Promise<void> => {\n if (message.role !== \"user\")\n throw new Error(\"Only user messages are supported\");\n\n // Convert AppendMessage to AddMessageCommand\n const parts: UserMessagePart[] = [];\n\n const content = [\n ...message.content,\n ...(message.attachments?.flatMap((a) => a.content) ?? []),\n ];\n for (const contentPart of content) {\n if (contentPart.type === \"text\") {\n parts.push({ type: \"text\", text: contentPart.text });\n } else if (contentPart.type === \"image\") {\n parts.push({ type: \"image\", image: contentPart.image });\n }\n }\n\n const command: AddMessageCommand = {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n };\n\n commandQueue.enqueue(command);\n },\n onCancel: async () => {\n runManager.cancel();\n toolInvocations.abort();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n toolInvocations.reset();\n rerender((prev) => prev + 1);\n },\n });\n\n const toolInvocations = useToolInvocations({\n state: converted,\n getTools: () => runtime.thread.getModelContext().tools,\n onResult: commandQueue.enqueue,\n setToolStatuses,\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n });\n return runtime;\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,+BAA+B;AAGxC,SAAS,UAAU,QAAQ,eAAe;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,iCAAiC;AAAA,OAC5B;AASP,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAA8B,0BAA0B;AACxD,SAAS,cAAc,iBAAiB,4BAA4B;AACpE,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAGnD,IAAM,iCAAiC,OAAO,4BAA4B;AAO1E,IAAM,6BAA6B,CACjC,WAC6B;AAC7B,MACE,OAAO,WAAW,YAClB,UAAU,QACV,EAAE,kCAAkC;AAEpC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAEO,IAAM,mCAAmC,MAAM;AACpD,QAAM,MAAM,gBAAgB;AAE5B,SAAO,CAAC,YAAuC;AAC7C,UAAM,SAAS,IAAI,OAAO,EAAE,SAAS,EAAE;AACvC,UAA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from "./ThreadListRuntimeCore";
5
5
  export type AssistantRuntimeCore = {
6
6
  readonly threads: ThreadListRuntimeCore;
7
7
  registerModelContextProvider: (provider: ModelContextProvider) => Unsubscribe;
8
+ getModelContextProvider: () => ModelContextProvider;
8
9
  /**
9
10
  * EXPERIMENTAL: A component that is rendered inside the AssistantRuntimeProvider.
10
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantRuntimeCore.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IAExC,4BAA4B,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,WAAW,CAAC;IAE9E;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACtD,CAAC"}
1
+ {"version":3,"file":"AssistantRuntimeCore.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IAExC,4BAA4B,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,WAAW,CAAC;IAC9E,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;IAEpD;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACtD,CAAC"}
@@ -7,5 +7,6 @@ export declare abstract class BaseAssistantRuntimeCore implements AssistantRunti
7
7
  protected readonly _contextProvider: CompositeContextProvider;
8
8
  abstract get threads(): ThreadListRuntimeCore;
9
9
  registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;
10
+ getModelContextProvider(): ModelContextProvider;
10
11
  }
11
12
  //# sourceMappingURL=BaseAssistantRuntimeCore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseAssistantRuntimeCore.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,8BAAsB,wBAAyB,YAAW,oBAAoB;IAC5E,SAAS,CAAC,QAAQ,CAAC,gBAAgB,2BAAkC;IACrE,aAAoB,OAAO,IAAI,qBAAqB,CAAC;IAE9C,4BAA4B,CACjC,QAAQ,EAAE,oBAAoB,GAC7B,WAAW;CAGf"}
1
+ {"version":3,"file":"BaseAssistantRuntimeCore.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,8BAAsB,wBAAyB,YAAW,oBAAoB;IAC5E,SAAS,CAAC,QAAQ,CAAC,gBAAgB,2BAAkC;IACrE,aAAoB,OAAO,IAAI,qBAAqB,CAAC;IAE9C,4BAA4B,CACjC,QAAQ,EAAE,oBAAoB,GAC7B,WAAW;IAIP,uBAAuB,IAAI,oBAAoB;CAGvD"}
@@ -5,6 +5,9 @@ var BaseAssistantRuntimeCore = class {
5
5
  registerModelContextProvider(provider) {
6
6
  return this._contextProvider.registerModelContextProvider(provider);
7
7
  }
8
+ getModelContextProvider() {
9
+ return this._contextProvider;
10
+ }
8
11
  };
9
12
  export {
10
13
  BaseAssistantRuntimeCore
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx"],"sourcesContent":["import { type ModelContextProvider } from \"../../../model-context/ModelContextTypes\";\nimport type { Unsubscribe } from \"../../../types/Unsubscribe\";\nimport type { AssistantRuntimeCore } from \"./AssistantRuntimeCore\";\nimport { CompositeContextProvider } from \"../../../utils/CompositeContextProvider\";\nimport { ThreadListRuntimeCore } from \"./ThreadListRuntimeCore\";\n\nexport abstract class BaseAssistantRuntimeCore implements AssistantRuntimeCore {\n protected readonly _contextProvider = new CompositeContextProvider();\n public abstract get threads(): ThreadListRuntimeCore;\n\n public registerModelContextProvider(\n provider: ModelContextProvider,\n ): Unsubscribe {\n return this._contextProvider.registerModelContextProvider(provider);\n }\n}\n"],"mappings":";AAGA,SAAS,gCAAgC;AAGlC,IAAe,2BAAf,MAAwE;AAAA,EAC1D,mBAAmB,IAAI,yBAAyB;AAAA,EAG5D,6BACL,UACa;AACb,WAAO,KAAK,iBAAiB,6BAA6B,QAAQ;AAAA,EACpE;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx"],"sourcesContent":["import { type ModelContextProvider } from \"../../../model-context/ModelContextTypes\";\nimport type { Unsubscribe } from \"../../../types/Unsubscribe\";\nimport type { AssistantRuntimeCore } from \"./AssistantRuntimeCore\";\nimport { CompositeContextProvider } from \"../../../utils/CompositeContextProvider\";\nimport { ThreadListRuntimeCore } from \"./ThreadListRuntimeCore\";\n\nexport abstract class BaseAssistantRuntimeCore implements AssistantRuntimeCore {\n protected readonly _contextProvider = new CompositeContextProvider();\n public abstract get threads(): ThreadListRuntimeCore;\n\n public registerModelContextProvider(\n provider: ModelContextProvider,\n ): Unsubscribe {\n return this._contextProvider.registerModelContextProvider(provider);\n }\n\n public getModelContextProvider(): ModelContextProvider {\n return this._contextProvider;\n }\n}\n"],"mappings":";AAGA,SAAS,gCAAgC;AAGlC,IAAe,2BAAf,MAAwE;AAAA,EAC1D,mBAAmB,IAAI,yBAAyB;AAAA,EAG5D,6BACL,UACa;AACb,WAAO,KAAK,iBAAiB,6BAA6B,QAAQ;AAAA,EACpE;AAAA,EAEO,0BAAgD;AACrD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -30,7 +30,10 @@ export declare class ExternalStoreThreadListRuntimeCore implements ThreadListRun
30
30
  archive(threadId: string): Promise<void>;
31
31
  unarchive(threadId: string): Promise<void>;
32
32
  delete(threadId: string): Promise<void>;
33
- initialize(): never;
33
+ initialize(threadId: string): Promise<{
34
+ remoteId: string;
35
+ externalId: string | undefined;
36
+ }>;
34
37
  generateTitle(): never;
35
38
  private _subscriptions;
36
39
  subscribe(callback: () => void): Unsubscribe;