@assistant-ui/react 0.11.21 → 0.11.23

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 (176) hide show
  1. package/dist/augmentations.d.ts +20 -9
  2. package/dist/augmentations.d.ts.map +1 -1
  3. package/dist/client/AssistantClient.d.ts +6 -7
  4. package/dist/client/AssistantClient.d.ts.map +1 -1
  5. package/dist/client/AssistantClient.js +9 -4
  6. package/dist/client/AssistantClient.js.map +1 -1
  7. package/dist/client/NoOpComposerClient.d.ts +9 -0
  8. package/dist/client/NoOpComposerClient.d.ts.map +1 -0
  9. package/dist/client/NoOpComposerClient.js +59 -0
  10. package/dist/client/NoOpComposerClient.js.map +1 -0
  11. package/dist/client/ThreadMessageClient.d.ts +14 -0
  12. package/dist/client/ThreadMessageClient.d.ts.map +1 -0
  13. package/dist/client/ThreadMessageClient.js +140 -0
  14. package/dist/client/ThreadMessageClient.js.map +1 -0
  15. package/dist/client/types/Part.d.ts +5 -0
  16. package/dist/client/types/Part.d.ts.map +1 -1
  17. package/dist/client/types/Thread.d.ts +8 -0
  18. package/dist/client/types/Thread.d.ts.map +1 -1
  19. package/dist/context/providers/MessageProvider.d.ts +1 -8
  20. package/dist/context/providers/MessageProvider.d.ts.map +1 -1
  21. package/dist/context/providers/MessageProvider.js +4 -181
  22. package/dist/context/providers/MessageProvider.js.map +1 -1
  23. package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
  24. package/dist/context/providers/TextMessagePartProvider.js +3 -1
  25. package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
  26. package/dist/context/react/AssistantApiContext.d.ts +3 -1
  27. package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
  28. package/dist/context/react/AssistantApiContext.js +17 -4
  29. package/dist/context/react/AssistantApiContext.js.map +1 -1
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/internal.d.ts +1 -0
  34. package/dist/internal.d.ts.map +1 -1
  35. package/dist/internal.js +5 -1
  36. package/dist/internal.js.map +1 -1
  37. package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts.map +1 -1
  38. package/dist/legacy-runtime/client/MessagePartRuntimeClient.js +9 -10
  39. package/dist/legacy-runtime/client/MessagePartRuntimeClient.js.map +1 -1
  40. package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
  41. package/dist/legacy-runtime/client/ThreadRuntimeClient.js +6 -0
  42. package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
  43. package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
  44. package/dist/legacy-runtime/hooks/AssistantContext.js.map +1 -1
  45. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +1 -1
  46. package/dist/legacy-runtime/hooks/AttachmentContext.js +1 -1
  47. package/dist/legacy-runtime/hooks/AttachmentContext.js.map +1 -1
  48. package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +1 -1
  49. package/dist/legacy-runtime/hooks/ComposerContext.js +1 -1
  50. package/dist/legacy-runtime/hooks/ComposerContext.js.map +1 -1
  51. package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +1 -1
  52. package/dist/legacy-runtime/hooks/MessageContext.js +1 -1
  53. package/dist/legacy-runtime/hooks/MessageContext.js.map +1 -1
  54. package/dist/legacy-runtime/hooks/MessagePartContext.js +1 -1
  55. package/dist/legacy-runtime/hooks/MessagePartContext.js.map +1 -1
  56. package/dist/legacy-runtime/hooks/ThreadContext.js +1 -1
  57. package/dist/legacy-runtime/hooks/ThreadContext.js.map +1 -1
  58. package/dist/legacy-runtime/hooks/ThreadListItemContext.js +1 -1
  59. package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +1 -1
  60. package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts +6 -0
  61. package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts.map +1 -1
  62. package/dist/legacy-runtime/runtime/MessagePartRuntime.js +13 -0
  63. package/dist/legacy-runtime/runtime/MessagePartRuntime.js.map +1 -1
  64. package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +1 -0
  65. package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
  66. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +2 -0
  67. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
  68. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  69. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +5 -2
  70. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  71. package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts +2 -1
  72. package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts.map +1 -1
  73. package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js +3 -3
  74. package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js.map +1 -1
  75. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts +12 -1
  76. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -1
  77. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +48 -7
  78. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
  79. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts +2 -1
  80. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts.map +1 -1
  81. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.js.map +1 -1
  82. package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +6 -1
  83. package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
  84. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts +5 -1
  85. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts.map +1 -1
  86. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -1
  87. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  88. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +6 -1
  89. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  90. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts +4 -1
  91. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts.map +1 -1
  92. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +5 -1
  93. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
  94. package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts +3 -2
  95. package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts.map +1 -1
  96. package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js +6 -4
  97. package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js.map +1 -1
  98. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +8 -3
  99. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  100. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +20 -6
  101. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  102. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts +2 -1
  103. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  104. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js +3 -0
  105. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js.map +1 -1
  106. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
  107. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +3 -0
  108. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
  109. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +2 -0
  110. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  111. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
  112. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  113. package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js +1 -1
  114. package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js.map +1 -1
  115. package/dist/model-context/frame/AssistantFrameProvider.d.ts.map +1 -1
  116. package/dist/model-context/frame/AssistantFrameProvider.js +6 -1
  117. package/dist/model-context/frame/AssistantFrameProvider.js.map +1 -1
  118. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  119. package/dist/primitives/message/MessageParts.js +12 -3
  120. package/dist/primitives/message/MessageParts.js.map +1 -1
  121. package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
  122. package/dist/primitives/message/MessagePartsGrouped.js +11 -2
  123. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  124. package/dist/types/AssistantTypes.d.ts +2 -2
  125. package/dist/types/AssistantTypes.d.ts.map +1 -1
  126. package/dist/types/MessagePartComponentTypes.d.ts +1 -0
  127. package/dist/types/MessagePartComponentTypes.d.ts.map +1 -1
  128. package/dist/types/MessagePartTypes.d.ts +4 -0
  129. package/dist/types/MessagePartTypes.d.ts.map +1 -1
  130. package/dist/utils/smooth/SmoothContext.d.ts +6 -6
  131. package/package.json +2 -2
  132. package/src/augmentations.ts +21 -24
  133. package/src/client/AssistantClient.ts +15 -8
  134. package/src/client/NoOpComposerClient.tsx +56 -0
  135. package/src/client/ThreadMessageClient.tsx +161 -0
  136. package/src/client/types/Attachment.ts +1 -1
  137. package/src/client/types/Composer.ts +1 -1
  138. package/src/client/types/Message.ts +1 -1
  139. package/src/client/types/Part.ts +7 -1
  140. package/src/client/types/Thread.ts +11 -1
  141. package/src/client/types/ThreadListItem.ts +1 -1
  142. package/src/context/providers/MessageProvider.tsx +4 -222
  143. package/src/context/providers/TextMessagePartProvider.tsx +3 -1
  144. package/src/context/react/AssistantApiContext.tsx +27 -5
  145. package/src/index.ts +3 -0
  146. package/src/internal.ts +4 -0
  147. package/src/legacy-runtime/client/MessagePartRuntimeClient.ts +12 -13
  148. package/src/legacy-runtime/client/ThreadRuntimeClient.ts +6 -0
  149. package/src/legacy-runtime/hooks/AssistantContext.ts +1 -1
  150. package/src/legacy-runtime/hooks/AttachmentContext.ts +3 -1
  151. package/src/legacy-runtime/hooks/ComposerContext.ts +3 -1
  152. package/src/legacy-runtime/hooks/MessageContext.ts +3 -1
  153. package/src/legacy-runtime/hooks/MessagePartContext.ts +1 -1
  154. package/src/legacy-runtime/hooks/ThreadContext.ts +1 -1
  155. package/src/legacy-runtime/hooks/ThreadListItemContext.ts +1 -1
  156. package/src/legacy-runtime/runtime/MessagePartRuntime.ts +23 -0
  157. package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +2 -0
  158. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +10 -3
  159. package/src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts +4 -2
  160. package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +73 -6
  161. package/src/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.tsx +2 -0
  162. package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +7 -1
  163. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.tsx +4 -1
  164. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +8 -1
  165. package/src/legacy-runtime/runtime-cores/external-store/auto-status.tsx +11 -3
  166. package/src/legacy-runtime/runtime-cores/external-store/createMessageConverter.tsx +9 -2
  167. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +33 -5
  168. package/src/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.tsx +5 -0
  169. package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +4 -0
  170. package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -1
  171. package/src/model-context/frame/AssistantFrameProvider.ts +5 -0
  172. package/src/primitives/message/MessageParts.tsx +11 -3
  173. package/src/primitives/message/MessagePartsGrouped.tsx +10 -2
  174. package/src/types/AssistantTypes.ts +2 -2
  175. package/src/types/MessagePartComponentTypes.tsx +1 -0
  176. package/src/types/MessagePartTypes.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { AttachmentRuntime } from \"../runtime/AttachmentRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.attachment.source ? api.attachment().__internal_getRuntime() : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"AttachmentRuntime is not available\");\n }\n return runtime;\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"thread-composer\">;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"thread-composer\">;\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"edit-composer\">;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a message's ComposerPrimitive.Attachments component.\",\n );\n\n return attachmentRuntime as AttachmentRuntime<\"edit-composer\">;\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"message\">;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"message\">;\n}\n\nexport const useAttachment = createStateHookForRuntime(useAttachmentRuntime);\n\nexport const useThreadComposerAttachment = createStateHookForRuntime(\n useThreadComposerAttachmentRuntime,\n);\nexport const useEditComposerAttachment = createStateHookForRuntime(\n useEditComposerAttachmentRuntime,\n);\nexport const useMessageAttachment = createStateHookForRuntime(\n useMessageAttachmentRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,qBAAqB,SAER;AAC3B,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,WAAW,SAAS,IAAI,WAAW,EAAE,sBAAsB,IAAI;AAAA,EACrE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;AAQO,SAAS,mCAAmC,SAEH;AAC9C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,iCAAiC,SAEH;AAC5C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQO,SAAS,4BAA4B,SAEJ;AACtC,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAEO,IAAM,gBAAgB,0BAA0B,oBAAoB;AAEpE,IAAM,8BAA8B;AAAA,EACzC;AACF;AACO,IAAM,4BAA4B;AAAA,EACvC;AACF;AACO,IAAM,uBAAuB;AAAA,EAClC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { AttachmentRuntime } from \"../runtime/AttachmentRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.attachment.source\n ? (api.attachment().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"AttachmentRuntime is not available\");\n }\n return runtime;\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"thread-composer\">;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"thread-composer\">;\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"edit-composer\">;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a message's ComposerPrimitive.Attachments component.\",\n );\n\n return attachmentRuntime as AttachmentRuntime<\"edit-composer\">;\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"message\">;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"message\">;\n}\n\nexport const useAttachment = createStateHookForRuntime(useAttachmentRuntime);\n\nexport const useThreadComposerAttachment = createStateHookForRuntime(\n useThreadComposerAttachmentRuntime,\n);\nexport const useEditComposerAttachment = createStateHookForRuntime(\n useEditComposerAttachmentRuntime,\n);\nexport const useMessageAttachment = createStateHookForRuntime(\n useMessageAttachmentRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,qBAAqB,SAER;AAC3B,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,WAAW,SACV,IAAI,WAAW,EAAE,wBAAwB,KAAK,OAC/C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;AAQO,SAAS,mCAAmC,SAEH;AAC9C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,iCAAiC,SAEH;AAC5C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQO,SAAS,4BAA4B,SAEJ;AACtC,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAEO,IAAM,gBAAgB,0BAA0B,oBAAoB;AAEpE,IAAM,8BAA8B;AAAA,EACzC;AACF;AACO,IAAM,4BAA4B;AAAA,EACvC;AACF;AACO,IAAM,uBAAuB;AAAA,EAClC;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAAC;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,eAAe,GAAG,IAAI,CAAC;AAc3B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CAAgD,CAAC"}
1
+ {"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAAC;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,eAAe,GAAG,IAAI,CAAC;AAgB3B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CAAgD,CAAC"}
@@ -6,7 +6,7 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
6
6
  function useComposerRuntime(options) {
7
7
  const api = useAssistantApi();
8
8
  const runtime = useAssistantState(
9
- () => api.composer.source ? api.composer().__internal_getRuntime() : null
9
+ () => api.composer.source ? api.composer().__internal_getRuntime?.() ?? null : null
10
10
  );
11
11
  if (!runtime && !options?.optional) {
12
12
  throw new Error("ComposerRuntime is not available");
@@ -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 ? api.composer().__internal_getRuntime() : 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,SAAS,IAAI,SAAS,EAAE,sBAAsB,IAAI;AAAA,EACjE;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 * 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 +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;AAc1B;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -6,7 +6,7 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
6
6
  function useMessageRuntime(options) {
7
7
  const api = useAssistantApi();
8
8
  const runtime = useAssistantState(
9
- () => api.message.source ? api.message().__internal_getRuntime() : null
9
+ () => api.message.source ? api.message().__internal_getRuntime?.() ?? null : null
10
10
  );
11
11
  if (!runtime && !options?.optional) {
12
12
  throw new Error("MessageRuntime is not available");
@@ -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 ? api.message().__internal_getRuntime() : 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,SAAS,IAAI,QAAQ,EAAE,sBAAsB,IAAI;AAAA,EAC/D;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 * 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":[]}
@@ -6,7 +6,7 @@ import { useAssistantApi, useAssistantState } from "../../context/react/index.js
6
6
  function useMessagePartRuntime(options) {
7
7
  const api = useAssistantApi();
8
8
  const runtime = useAssistantState(
9
- () => api.part.source ? api.part().__internal_getRuntime() : null
9
+ () => api.part.source ? api.part().__internal_getRuntime?.() ?? null : null
10
10
  );
11
11
  if (!runtime && !options?.optional) {
12
12
  throw new Error("MessagePartRuntime is not available");
@@ -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,\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,SAAS,IAAI,KAAK,EAAE,sBAAsB,IAAI;AAAA,EACzD;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\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":[]}
@@ -11,7 +11,7 @@ import {
11
11
  function useThreadRuntime(options) {
12
12
  const api = useAssistantApi();
13
13
  const runtime = useAssistantState(
14
- () => api.thread.source ? api.thread().__internal_getRuntime() : null
14
+ () => api.thread.source ? api.thread().__internal_getRuntime?.() ?? null : null
15
15
  );
16
16
  if (!runtime && !options?.optional) {
17
17
  throw new Error("ThreadRuntime is not available");
@@ -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,\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,SAAS,IAAI,OAAO,EAAE,sBAAsB,IAAI;AAAA,EAC7D;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 * 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":[]}
@@ -6,7 +6,7 @@ import { useAssistantApi, useAssistantState } from "../../context/react/index.js
6
6
  function useThreadListItemRuntime(options) {
7
7
  const api = useAssistantApi();
8
8
  const runtime = useAssistantState(
9
- () => api.threadListItem.source ? api.threadListItem().__internal_getRuntime() : null
9
+ () => api.threadListItem.source ? api.threadListItem().__internal_getRuntime?.() ?? null : null
10
10
  );
11
11
  if (!runtime && !options?.optional) {
12
12
  throw new Error("ThreadListItemRuntime is not available");
@@ -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()\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,SACf,IAAI,eAAe,EAAE,sBAAsB,IAC3C;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\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":[]}
@@ -15,6 +15,11 @@ export type MessagePartRuntime = {
15
15
  * This is useful when you are collecting a tool result via user input ("human tool calls").
16
16
  */
17
17
  addToolResult(result: any | ToolResponse<any>): void;
18
+ /**
19
+ * Resume a tool call that is waiting for human input with a payload.
20
+ * This is useful when a tool has requested human input and is waiting for a response.
21
+ */
22
+ resumeToolCall(payload: unknown): void;
18
23
  readonly path: MessagePartRuntimePath;
19
24
  getState(): MessagePartState;
20
25
  subscribe(callback: () => void): Unsubscribe;
@@ -28,6 +33,7 @@ export declare class MessagePartRuntimeImpl implements MessagePartRuntime {
28
33
  protected __internal_bindMethods(): void;
29
34
  getState(): MessagePartState;
30
35
  addToolResult(result: any | ToolResponse<any>): void;
36
+ resumeToolCall(payload: unknown): void;
31
37
  subscribe(callback: () => void): Unsubscribe;
32
38
  }
33
39
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"MessagePartRuntime.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/runtime/MessagePartRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D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E,OAAO;IAgB/B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;CAGtC"}
@@ -12,6 +12,7 @@ var MessagePartRuntimeImpl = class {
12
12
  }
13
13
  __internal_bindMethods() {
14
14
  this.addToolResult = this.addToolResult.bind(this);
15
+ this.resumeToolCall = this.resumeToolCall.bind(this);
15
16
  this.getState = this.getState.bind(this);
16
17
  this.subscribe = this.subscribe.bind(this);
17
18
  }
@@ -42,6 +43,18 @@ var MessagePartRuntimeImpl = class {
42
43
  isError: response.isError
43
44
  });
44
45
  }
46
+ resumeToolCall(payload) {
47
+ const state = this.contentBinding.getState();
48
+ if (!state) throw new Error("Message part is not available");
49
+ if (state.type !== "tool-call")
50
+ throw new Error("Tried to resume tool call on non-tool message part");
51
+ if (!this.threadApi) throw new Error("Thread API is not available");
52
+ const toolCallId = state.toolCallId;
53
+ this.threadApi.getState().resumeToolCall({
54
+ toolCallId,
55
+ payload
56
+ });
57
+ }
45
58
  subscribe(callback) {
46
59
  return this.contentBinding.subscribe(callback);
47
60
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/runtime/MessagePartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport type { MessageStateBinding } from \"./RuntimeBindings\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../../types\";\nimport { MessagePartRuntimePath } from \"./RuntimePathTypes\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n /**\n * Add tool result to a tool call message part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any | ToolResponse<any>): void;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: MessagePartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";AAWA,SAAS,oBAAoB;AA0BtB,IAAM,yBAAN,MAA2D;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAER,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAVA,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAUU,yBAAyB;AACjC,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAiC;AACpD,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,UAAM,WAAW,aAAa,WAAW,MAAM;AAC/C,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA,QAAQ,SAAS;AAAA,MACjB,UAAU,SAAS;AAAA,MACnB,SAAS,SAAS;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/runtime/MessagePartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport type { MessageStateBinding } from \"./RuntimeBindings\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../../types\";\nimport { MessagePartRuntimePath } from \"./RuntimePathTypes\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n /**\n * Add tool result to a tool call message part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any | ToolResponse<any>): void;\n\n /**\n * Resume a tool call that is waiting for human input with a payload.\n * This is useful when a tool has requested human input and is waiting for a response.\n */\n resumeToolCall(payload: unknown): void;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: MessagePartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.resumeToolCall = this.resumeToolCall.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public resumeToolCall(payload: unknown) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to resume tool call on non-tool message part\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const toolCallId = state.toolCallId;\n this.threadApi.getState().resumeToolCall({\n toolCallId,\n payload,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";AAWA,SAAS,oBAAoB;AAgCtB,IAAM,yBAAN,MAA2D;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAER,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAVA,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAUU,yBAAyB;AACjC,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;AACnD,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAiC;AACpD,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,UAAM,WAAW,aAAa,WAAW,MAAM;AAC/C,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA,QAAQ,SAAS;AAAA,MACjB,UAAU,SAAS;AAAA,MACnB,SAAS,SAAS;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EAEO,eAAe,SAAkB;AACtC,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,oDAAoD;AAEtE,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,aAAa,MAAM;AACzB,SAAK,UAAU,SAAS,EAAE,eAAe;AAAA,MACvC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
@@ -174,6 +174,7 @@ export declare class ThreadRuntimeImpl implements ThreadRuntime {
174
174
  resumeRun: (config: ResumeRunConfig) => void;
175
175
  cancelRun: () => void;
176
176
  addToolResult: (options: import("../runtime-cores").AddToolResultOptions) => void;
177
+ resumeToolCall: (options: import("../runtime-cores/core/ThreadRuntimeCore").ResumeToolCallOptions) => void;
177
178
  speak: (messageId: string) => void;
178
179
  stopSpeaking: () => void;
179
180
  getSubmittedFeedback: (messageId: string) => import("../runtime-cores/core/ThreadRuntimeCore").SubmittedFeedback | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadRuntime.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/runtime/ThreadRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,eAAe,EAChB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,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AAC,kBAAkB;IA4C1B,OAAO,CAAC,0BAA0B,CAG9B;IAEG,WAAW,CAChB,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,EAAE,MAAM,IAAI,GACnB,WAAW;CAWf"}
@@ -2,6 +2,7 @@ import { ReadonlyJSONValue } from "assistant-stream/utils";
2
2
  import { ThreadMessage } from "../../../types";
3
3
  import { AttachmentAdapter, ThreadHistoryAdapter } from "..";
4
4
  import { UserCommands } from "../../../augmentations";
5
+ import type { ToolExecutionStatus } from "./useToolInvocations";
5
6
  export type TextPart = {
6
7
  readonly type: "text";
7
8
  readonly text: string;
@@ -40,6 +41,7 @@ export type AssistantTransportState = {
40
41
  export type AssistantTransportConnectionMetadata = {
41
42
  pendingCommands: AssistantTransportCommand[];
42
43
  isSending: boolean;
44
+ toolStatuses: Record<string, ToolExecutionStatus>;
43
45
  };
44
46
  export type AssistantTransportStateConverter<T> = (state: T, connectionMetadata: AssistantTransportConnectionMetadata) => AssistantTransportState;
45
47
  export type CommandQueueState = {
@@ -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,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,M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Z,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,gCAAgC,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,EAAE,YAAY,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,CACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE;QACN,QAAQ,EAAE,yBAAyB,EAAE,CAAC;QACtC,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;KACjD,KACE,IAAI,CAAC;IACV,QAAQ,CAAC,EAAE,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 +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;AAkNF;;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;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"}
@@ -128,6 +128,7 @@ var useAssistantTransportThreadRuntime = (options) => {
128
128
  commandQueue.markDelivered();
129
129
  }
130
130
  });
131
+ const [toolStatuses, setToolStatuses] = useState({});
131
132
  const pendingCommands = useMemo(
132
133
  () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],
133
134
  [commandQueue.state]
@@ -136,7 +137,8 @@ var useAssistantTransportThreadRuntime = (options) => {
136
137
  options.converter,
137
138
  agentStateRef.current,
138
139
  pendingCommands,
139
- runManager.isRunning
140
+ runManager.isRunning,
141
+ toolStatuses
140
142
  );
141
143
  const runtime = useExternalStoreRuntime({
142
144
  messages: converted.messages,
@@ -203,7 +205,8 @@ var useAssistantTransportThreadRuntime = (options) => {
203
205
  const toolInvocations = useToolInvocations({
204
206
  state: converted,
205
207
  getTools: () => runtime.thread.getModelContext().tools,
206
- onResult: commandQueue.enqueue
208
+ onResult: commandQueue.enqueue,
209
+ setToolStatuses
207
210
  });
208
211
  return runtime;
209
212
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ReadonlyJSONObject,\n 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 { 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 // 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 );\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 });\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,SAAS,0BAA0B;AACnC,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;A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iBAAiB,OACf,gBACkB;AAClB,YAAM,UAAgC;AAAA,QACpC,MAAM;AAAA,QACN,YAAY,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,EACzB,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 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,gBAAgB;AAAA,IACnC,SAAS,MAAM,WAAW,SAAS;AAAA,EACrC,CAAC;AAED,QAAM,aAAa,cAAc;AAAA,IAC/B,OAAO,OAAO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Y,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,3 +1,4 @@
1
1
  import type { AssistantTransportCommand, AssistantTransportState, AssistantTransportStateConverter } from "./types";
2
- export declare function useConvertedState<T>(converter: AssistantTransportStateConverter<T>, agentState: T, pendingCommands: AssistantTransportCommand[], isSending: boolean): AssistantTransportState;
2
+ import type { ToolExecutionStatus } from "./useToolInvocations";
3
+ export declare function useConvertedState<T>(converter: AssistantTransportStateConverter<T>, agentState: T, pendingCommands: AssistantTransportCommand[], isSending: boolean, toolStatuses: Record<string, ToolExecutionStatus>): AssistantTransportState;
3
4
  //# sourceMappingURL=useConvertedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useConvertedState.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,EACjC,MAAM,SAAS,CAAC;AAEjB,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,SAAS,EAAE,gCAAgC,CAAC,CAAC,CAAC,EAC9C,UAAU,EAAE,CAAC,EACb,eAAe,EAAE,yBAAyB,EAAE,EAC5C,SAAS,EAAE,OAAO,GACjB,uBAAuB,CAKzB"}
1
+ {"version":3,"file":"useConvertedState.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,EACjC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,SAAS,EAAE,gCAAgC,CAAC,CAAC,CAAC,EAC9C,UAAU,EAAE,CAAC,EACb,eAAe,EAAE,yBAAyB,EAAE,EAC5C,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAChD,uBAAuB,CAKzB"}
@@ -1,9 +1,9 @@
1
1
  // src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts
2
2
  import { useMemo } from "react";
3
- function useConvertedState(converter, agentState, pendingCommands, isSending) {
3
+ function useConvertedState(converter, agentState, pendingCommands, isSending, toolStatuses) {
4
4
  return useMemo(
5
- () => converter(agentState, { pendingCommands, isSending }),
6
- [converter, agentState, pendingCommands, isSending]
5
+ () => converter(agentState, { pendingCommands, isSending, toolStatuses }),
6
+ [converter, agentState, pendingCommands, isSending, toolStatuses]
7
7
  );
8
8
  }
9
9
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport type {\n AssistantTransportCommand,\n AssistantTransportState,\n AssistantTransportStateConverter,\n} from \"./types\";\n\nexport function useConvertedState<T>(\n converter: AssistantTransportStateConverter<T>,\n agentState: T,\n pendingCommands: AssistantTransportCommand[],\n isSending: boolean,\n): AssistantTransportState {\n return useMemo(\n () => converter(agentState, { pendingCommands, isSending }),\n [converter, agentState, pendingCommands, isSending],\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAOjB,SAAS,kBACd,WACA,YACA,iBACA,WACyB;AACzB,SAAO;AAAA,IACL,MAAM,UAAU,YAAY,EAAE,iBAAiB,UAAU,CAAC;AAAA,IAC1D,CAAC,WAAW,YAAY,iBAAiB,SAAS;AAAA,EACpD;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport type {\n AssistantTransportCommand,\n AssistantTransportState,\n AssistantTransportStateConverter,\n} from \"./types\";\nimport type { ToolExecutionStatus } from \"./useToolInvocations\";\n\nexport function useConvertedState<T>(\n converter: AssistantTransportStateConverter<T>,\n agentState: T,\n pendingCommands: AssistantTransportCommand[],\n isSending: boolean,\n toolStatuses: Record<string, ToolExecutionStatus>,\n): AssistantTransportState {\n return useMemo(\n () => converter(agentState, { pendingCommands, isSending, toolStatuses }),\n [converter, agentState, pendingCommands, isSending, toolStatuses],\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAQjB,SAAS,kBACd,WACA,YACA,iBACA,WACA,cACyB;AACzB,SAAO;AAAA,IACL,MAAM,UAAU,YAAY,EAAE,iBAAiB,WAAW,aAAa,CAAC;AAAA,IACxE,CAAC,WAAW,YAAY,iBAAiB,WAAW,YAAY;AAAA,EAClE;AACF;","names":[]}
@@ -4,10 +4,21 @@ type UseToolInvocationsParams = {
4
4
  state: AssistantTransportState;
5
5
  getTools: () => Record<string, Tool> | undefined;
6
6
  onResult: (command: AssistantTransportCommand) => void;
7
+ setToolStatuses: (updater: Record<string, ToolExecutionStatus> | ((prev: Record<string, ToolExecutionStatus>) => Record<string, ToolExecutionStatus>)) => void;
7
8
  };
8
- export declare function useToolInvocations({ state, getTools, onResult, }: UseToolInvocationsParams): {
9
+ export type ToolExecutionStatus = {
10
+ type: "executing";
11
+ } | {
12
+ type: "interrupt";
13
+ payload: {
14
+ type: "human";
15
+ payload: unknown;
16
+ };
17
+ };
18
+ export declare function useToolInvocations({ state, getTools, onResult, setToolStatuses, }: UseToolInvocationsParams): {
9
19
  reset: () => void;
10
20
  abort: () => void;
21
+ resume: (toolCallId: string, payload: unknown) => void;
11
22
  };
12
23
  export {};
13
24
  //# sourceMappingURL=useToolInvocations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useToolInvocations.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAejB,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,CAAC;IACjD,QAAQ,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,IAAI,CAAC;CACxD,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,QAAQ,GACT,EAAE,wBAAwB;;;EAwI1B"}
1
+ {"version":3,"file":"useToolInvocations.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAejB,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,CAAC;IACjD,QAAQ,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,IAAI,CAAC;IACvD,eAAe,EAAE,CACf,OAAO,EACH,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GACnC,CAAC,CACC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,KACtC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,KAC1C,IAAI,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC;AAExE,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,eAAe,GAChB,EAAE,wBAAwB;;;yBAgLF,MAAM,WAAW,OAAO;EAehD"}
@@ -19,15 +19,32 @@ var isArgsTextComplete = (argsText) => {
19
19
  function useToolInvocations({
20
20
  state,
21
21
  getTools,
22
- onResult
22
+ onResult,
23
+ setToolStatuses
23
24
  }) {
24
25
  const lastToolStates = useRef({});
26
+ const humanInputRef = useRef(/* @__PURE__ */ new Map());
25
27
  const acRef = useRef(new AbortController());
26
28
  const [controller] = useState(() => {
27
29
  const [stream, controller2] = createAssistantStreamController();
28
30
  const transform = unstable_toolResultStream(
29
31
  getTools,
30
- () => acRef.current?.signal ?? new AbortController().signal
32
+ () => acRef.current?.signal ?? new AbortController().signal,
33
+ (toolCallId, payload) => {
34
+ return new Promise((resolve, reject) => {
35
+ const previous = humanInputRef.current.get(toolCallId);
36
+ if (previous) {
37
+ previous.reject(
38
+ new Error("Human input request was superseded by a new request")
39
+ );
40
+ }
41
+ humanInputRef.current.set(toolCallId, { resolve, reject });
42
+ setToolStatuses((prev) => ({
43
+ ...prev,
44
+ [toolCallId]: { type: "interrupt", payload: { type: "human", payload } }
45
+ }));
46
+ });
47
+ }
31
48
  );
32
49
  stream.pipeThrough(transform).pipeThrough(new AssistantMetaTransformStream()).pipeTo(
33
50
  new WritableStream({
@@ -43,6 +60,11 @@ function useToolInvocations({
43
60
  isError: chunk.isError,
44
61
  ...chunk.artifact && { artifact: chunk.artifact }
45
62
  });
63
+ setToolStatuses((prev) => {
64
+ const next = { ...prev };
65
+ delete next[chunk.meta.toolCallId];
66
+ return next;
67
+ });
46
68
  }
47
69
  }
48
70
  })
@@ -120,15 +142,34 @@ function useToolInvocations({
120
142
  });
121
143
  }
122
144
  }, [state, controller, onResult]);
145
+ const abort = () => {
146
+ humanInputRef.current.forEach(({ reject }) => {
147
+ reject(new Error("Tool execution aborted"));
148
+ });
149
+ humanInputRef.current.clear();
150
+ setToolStatuses({});
151
+ acRef.current.abort();
152
+ acRef.current = new AbortController();
153
+ };
123
154
  return {
124
155
  reset: () => {
125
- acRef.current.abort();
126
- acRef.current = new AbortController();
156
+ abort();
127
157
  isInititialState.current = true;
128
158
  },
129
- abort: () => {
130
- acRef.current.abort();
131
- acRef.current = new AbortController();
159
+ abort,
160
+ resume: (toolCallId, payload) => {
161
+ const handlers = humanInputRef.current.get(toolCallId);
162
+ if (handlers) {
163
+ humanInputRef.current.delete(toolCallId);
164
+ setToolStatuses((prev) => {
165
+ const next = { ...prev };
166
+ delete next[toolCallId];
167
+ return next;
168
+ });
169
+ handlers.resolve(payload);
170
+ } else {
171
+ throw new Error(`Tool call ${toolCallId} is not waiting for human input`);
172
+ }
132
173
  }
133
174
  };
134
175
  }