@assistant-ui/react 0.11.35 → 0.11.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/dist/client/AssistantClient.d.ts +13 -57
  2. package/dist/client/AssistantClient.d.ts.map +1 -1
  3. package/dist/client/AssistantClient.js +49 -26
  4. package/dist/client/AssistantClient.js.map +1 -1
  5. package/dist/client/ModelContext.d.ts +8 -0
  6. package/dist/client/ModelContext.d.ts.map +1 -0
  7. package/dist/client/ModelContext.js +21 -0
  8. package/dist/client/ModelContext.js.map +1 -0
  9. package/dist/client/ModelContextClient.d.ts +7 -0
  10. package/dist/client/ModelContextClient.d.ts.map +1 -0
  11. package/dist/client/ModelContextClient.js +18 -0
  12. package/dist/client/ModelContextClient.js.map +1 -0
  13. package/dist/client/ToolUIClient.d.ts.map +1 -1
  14. package/dist/client/ToolUIClient.js +45 -3
  15. package/dist/client/ToolUIClient.js.map +1 -1
  16. package/dist/client/ToolUIContext.d.ts +4 -0
  17. package/dist/client/ToolUIContext.d.ts.map +1 -0
  18. package/dist/client/ToolUIContext.js +20 -0
  19. package/dist/client/ToolUIContext.js.map +1 -0
  20. package/dist/client/Tools.d.ts +10 -0
  21. package/dist/client/Tools.d.ts.map +1 -0
  22. package/dist/client/Tools.js +55 -0
  23. package/dist/client/Tools.js.map +1 -0
  24. package/dist/client/types/ModelContext.d.ts +12 -0
  25. package/dist/client/types/ModelContext.d.ts.map +1 -0
  26. package/dist/client/types/ModelContext.js +1 -0
  27. package/dist/client/types/ModelContext.js.map +1 -0
  28. package/dist/client/types/ThreadList.d.ts.map +1 -1
  29. package/dist/client/types/ToolUI.d.ts +12 -1
  30. package/dist/client/types/ToolUI.d.ts.map +1 -1
  31. package/dist/client/types/Tools.d.ts +9 -0
  32. package/dist/client/types/Tools.d.ts.map +1 -0
  33. package/dist/client/types/Tools.js +1 -0
  34. package/dist/client/types/Tools.js.map +1 -0
  35. package/dist/context/providers/AttachmentByIndexProvider.d.ts.map +1 -1
  36. package/dist/context/providers/AttachmentByIndexProvider.js +20 -24
  37. package/dist/context/providers/AttachmentByIndexProvider.js.map +1 -1
  38. package/dist/context/providers/MessageByIndexProvider.d.ts.map +1 -1
  39. package/dist/context/providers/MessageByIndexProvider.js +27 -29
  40. package/dist/context/providers/MessageByIndexProvider.js.map +1 -1
  41. package/dist/context/providers/MessageProvider.d.ts.map +1 -1
  42. package/dist/context/providers/MessageProvider.js +11 -13
  43. package/dist/context/providers/MessageProvider.js.map +1 -1
  44. package/dist/context/providers/PartByIndexProvider.d.ts.map +1 -1
  45. package/dist/context/providers/PartByIndexProvider.js +11 -13
  46. package/dist/context/providers/PartByIndexProvider.js.map +1 -1
  47. package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
  48. package/dist/context/providers/TextMessagePartProvider.js +11 -13
  49. package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
  50. package/dist/context/providers/ThreadListItemProvider.d.ts.map +1 -1
  51. package/dist/context/providers/ThreadListItemProvider.js +41 -45
  52. package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
  53. package/dist/context/react/AssistantApiContext.d.ts +33 -4
  54. package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
  55. package/dist/context/react/AssistantApiContext.js +35 -17
  56. package/dist/context/react/AssistantApiContext.js.map +1 -1
  57. package/dist/context/react/index.d.ts +1 -1
  58. package/dist/context/react/index.d.ts.map +1 -1
  59. package/dist/context/react/index.js +5 -1
  60. package/dist/context/react/index.js.map +1 -1
  61. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  62. package/dist/legacy-runtime/AssistantRuntimeProvider.js +7 -9
  63. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  64. package/dist/legacy-runtime/RuntimeAdapter.d.ts +7 -0
  65. package/dist/legacy-runtime/RuntimeAdapter.d.ts.map +1 -0
  66. package/dist/legacy-runtime/RuntimeAdapter.js +20 -0
  67. package/dist/legacy-runtime/RuntimeAdapter.js.map +1 -0
  68. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts +2 -0
  69. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
  70. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +6 -2
  71. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
  72. package/dist/legacy-runtime/hooks/AssistantContext.d.ts +14 -1
  73. package/dist/legacy-runtime/hooks/AssistantContext.d.ts.map +1 -1
  74. package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
  75. package/dist/legacy-runtime/hooks/AssistantContext.js.map +1 -1
  76. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +6 -0
  77. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +1 -1
  78. package/dist/legacy-runtime/hooks/AttachmentContext.js.map +1 -1
  79. package/dist/legacy-runtime/hooks/ComposerContext.d.ts +41 -2
  80. package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +1 -1
  81. package/dist/legacy-runtime/hooks/ComposerContext.js.map +1 -1
  82. package/dist/legacy-runtime/hooks/MessageContext.d.ts +36 -2
  83. package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +1 -1
  84. package/dist/legacy-runtime/hooks/MessageContext.js.map +1 -1
  85. package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +6 -0
  86. package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +1 -1
  87. package/dist/legacy-runtime/hooks/MessagePartContext.js.map +1 -1
  88. package/dist/legacy-runtime/hooks/ThreadContext.d.ts +26 -1
  89. package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +1 -1
  90. package/dist/legacy-runtime/hooks/ThreadContext.js.map +1 -1
  91. package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +6 -0
  92. package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +1 -1
  93. package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +1 -1
  94. package/dist/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.d.ts +1 -0
  95. package/dist/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.d.ts.map +1 -1
  96. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.d.ts +1 -0
  97. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.d.ts.map +1 -1
  98. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.js +3 -0
  99. package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.js.map +1 -1
  100. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.d.ts +4 -1
  101. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
  102. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.js +2 -2
  103. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
  104. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  105. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +7 -1
  106. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  107. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts +2 -12
  108. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts.map +1 -1
  109. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +45 -15
  110. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
  111. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +2 -0
  112. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  113. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +4 -2
  114. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  115. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.d.ts +4 -1
  116. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
  117. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.js +2 -2
  118. package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.js.map +1 -1
  119. package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js +1 -1
  120. package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js.map +1 -1
  121. package/dist/model-context/index.d.ts +2 -0
  122. package/dist/model-context/index.d.ts.map +1 -1
  123. package/dist/model-context/index.js +6 -0
  124. package/dist/model-context/index.js.map +1 -1
  125. package/dist/model-context/makeAssistantVisible.js +1 -1
  126. package/dist/model-context/makeAssistantVisible.js.map +1 -1
  127. package/dist/model-context/toolbox.d.ts +28 -0
  128. package/dist/model-context/toolbox.d.ts.map +1 -0
  129. package/dist/model-context/toolbox.js +15 -0
  130. package/dist/model-context/toolbox.js.map +1 -0
  131. package/dist/model-context/useAssistantInstructions.js +1 -1
  132. package/dist/model-context/useAssistantInstructions.js.map +1 -1
  133. package/dist/model-context/useAssistantTool.js +1 -1
  134. package/dist/model-context/useAssistantTool.js.map +1 -1
  135. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  136. package/dist/primitives/message/MessageParts.js +2 -2
  137. package/dist/primitives/message/MessageParts.js.map +1 -1
  138. package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
  139. package/dist/primitives/message/MessagePartsGrouped.js +2 -2
  140. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  141. package/dist/tests/setup.js +7 -7
  142. package/dist/tests/setup.js.map +1 -1
  143. package/dist/utils/tap-store/derived-scopes.d.ts +81 -0
  144. package/dist/utils/tap-store/derived-scopes.d.ts.map +1 -0
  145. package/dist/utils/tap-store/derived-scopes.js +67 -0
  146. package/dist/utils/tap-store/derived-scopes.js.map +1 -0
  147. package/dist/utils/tap-store/index.d.ts +1 -0
  148. package/dist/utils/tap-store/index.d.ts.map +1 -1
  149. package/dist/utils/tap-store/index.js +4 -0
  150. package/dist/utils/tap-store/index.js.map +1 -1
  151. package/dist/utils/tap-store/tap-api.js +1 -1
  152. package/dist/utils/tap-store/tap-api.js.map +1 -1
  153. package/package.json +9 -9
  154. package/src/client/AssistantClient.ts +64 -38
  155. package/src/client/ModelContext.ts +28 -0
  156. package/src/client/ModelContextClient.ts +16 -0
  157. package/src/client/ToolUIClient.ts +50 -3
  158. package/src/client/ToolUIContext.ts +22 -0
  159. package/src/client/Tools.ts +68 -0
  160. package/src/client/types/ModelContext.ts +15 -0
  161. package/src/client/types/ThreadList.ts +4 -0
  162. package/src/client/types/ToolUI.ts +10 -1
  163. package/src/client/types/Tools.ts +11 -0
  164. package/src/context/providers/AttachmentByIndexProvider.tsx +21 -25
  165. package/src/context/providers/MessageByIndexProvider.tsx +31 -33
  166. package/src/context/providers/MessageProvider.tsx +12 -14
  167. package/src/context/providers/PartByIndexProvider.tsx +12 -14
  168. package/src/context/providers/TextMessagePartProvider.tsx +12 -14
  169. package/src/context/providers/ThreadListItemProvider.tsx +42 -46
  170. package/src/context/react/AssistantApiContext.tsx +69 -29
  171. package/src/context/react/index.ts +5 -1
  172. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +7 -9
  173. package/src/legacy-runtime/RuntimeAdapter.ts +19 -0
  174. package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +10 -1
  175. package/src/legacy-runtime/hooks/AssistantContext.ts +16 -2
  176. package/src/legacy-runtime/hooks/AttachmentContext.ts +6 -0
  177. package/src/legacy-runtime/hooks/ComposerContext.ts +41 -2
  178. package/src/legacy-runtime/hooks/MessageContext.ts +37 -2
  179. package/src/legacy-runtime/hooks/MessagePartContext.ts +6 -0
  180. package/src/legacy-runtime/hooks/ThreadContext.ts +27 -1
  181. package/src/legacy-runtime/hooks/ThreadListItemContext.ts +6 -0
  182. package/src/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.tsx +1 -0
  183. package/src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx +4 -0
  184. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.tsx +4 -2
  185. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +7 -1
  186. package/src/legacy-runtime/runtime-cores/external-store/auto-status.tsx +49 -16
  187. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +4 -0
  188. package/src/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.tsx +4 -2
  189. package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -1
  190. package/src/model-context/index.ts +9 -0
  191. package/src/model-context/makeAssistantVisible.tsx +1 -1
  192. package/src/model-context/toolbox.tsx +37 -0
  193. package/src/model-context/useAssistantInstructions.tsx +1 -1
  194. package/src/model-context/useAssistantTool.tsx +1 -1
  195. package/src/primitives/message/MessageParts.tsx +3 -2
  196. package/src/primitives/message/MessagePartsGrouped.tsx +3 -2
  197. package/src/utils/tap-store/derived-scopes.ts +185 -0
  198. package/src/utils/tap-store/index.ts +9 -0
  199. package/src/utils/tap-store/tap-api.ts +1 -1
@@ -2,7 +2,11 @@
2
2
  // TODO createContextStoreHook does not work well with server-side nextjs bundler
3
3
  // use client necessary here for now
4
4
 
5
- export { useAssistantApi, type AssistantApi } from "./AssistantApiContext";
5
+ export {
6
+ useAssistantApi,
7
+ useExtendedAssistantApi,
8
+ type AssistantApi,
9
+ } from "./AssistantApiContext";
6
10
  export { useAssistantState } from "./hooks/useAssistantState";
7
11
  export { useAssistantEvent } from "./hooks/useAssistantEvent";
8
12
 
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
 
3
3
  import { FC, memo, PropsWithChildren } from "react";
4
- import { AssistantProvider } from "../context/react/AssistantApiContext";
4
+ import {
5
+ AssistantProvider,
6
+ useAssistantApi,
7
+ } from "../context/react/AssistantApiContext";
5
8
  import { AssistantRuntime } from "./runtime/AssistantRuntime";
6
9
  import { AssistantRuntimeCore } from "./runtime-cores/core/AssistantRuntimeCore";
7
- import { useAssistantClient } from "../client/AssistantClient";
8
- import { ThreadListClient } from "./client/ThreadListRuntimeClient";
10
+ import { RuntimeAdapter } from "./RuntimeAdapter";
9
11
 
10
12
  export namespace AssistantProvider {
11
13
  export type Props = PropsWithChildren<{
@@ -24,12 +26,8 @@ export const AssistantRuntimeProviderImpl: FC<AssistantProvider.Props> = ({
24
26
  children,
25
27
  runtime,
26
28
  }) => {
27
- const api = useAssistantClient({
28
- threads: ThreadListClient({
29
- runtime: runtime.threads,
30
- }),
31
- registerModelContextProvider: runtime.registerModelContextProvider,
32
- __internal_runtime: runtime,
29
+ const api = useAssistantApi({
30
+ threads: RuntimeAdapter(runtime),
33
31
  });
34
32
 
35
33
  const RenderComponent = getRenderComponent(runtime);
@@ -0,0 +1,19 @@
1
+ import { resource, tapEffect, tapInlineResource } from "@assistant-ui/tap";
2
+ import type { AssistantRuntime } from "./runtime/AssistantRuntime";
3
+ import { ThreadListClient } from "./client/ThreadListRuntimeClient";
4
+ import { tapModelContext } from "../client/ModelContext";
5
+
6
+ export const RuntimeAdapter = resource((runtime: AssistantRuntime) => {
7
+ const modelContext = tapModelContext();
8
+
9
+ tapEffect(() => {
10
+ return runtime.registerModelContextProvider(modelContext);
11
+ }, [runtime, modelContext]);
12
+
13
+ return tapInlineResource(
14
+ ThreadListClient({
15
+ runtime: runtime.threads,
16
+ __internal_assistantRuntime: runtime,
17
+ }),
18
+ );
19
+ });
@@ -9,6 +9,7 @@ import {
9
9
  ThreadListClientState,
10
10
  ThreadListClientApi,
11
11
  } from "../../client/types/ThreadList";
12
+ import type { AssistantRuntime } from "../runtime/AssistantRuntime";
12
13
 
13
14
  const ThreadListItemClientById = resource(
14
15
  ({ runtime, id }: { runtime: ThreadListRuntime; id: string }) => {
@@ -25,7 +26,13 @@ const ThreadListItemClientById = resource(
25
26
  );
26
27
 
27
28
  export const ThreadListClient = resource(
28
- ({ runtime }: { runtime: ThreadListRuntime }) => {
29
+ ({
30
+ runtime,
31
+ __internal_assistantRuntime,
32
+ }: {
33
+ runtime: ThreadListRuntime;
34
+ __internal_assistantRuntime: AssistantRuntime;
35
+ }) => {
29
36
  const runtimeState = tapSubscribable(runtime);
30
37
 
31
38
  const main = tapInlineResource(
@@ -80,6 +87,8 @@ export const ThreadListClient = resource(
80
87
  switchToNewThread: () => {
81
88
  runtime.switchToNewThread();
82
89
  },
90
+
91
+ __internal_getAssistantRuntime: () => __internal_assistantRuntime,
83
92
  });
84
93
  },
85
94
  );
@@ -6,6 +6,8 @@ import type { ThreadListRuntime } from "../runtime/ThreadListRuntime";
6
6
  import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
7
7
 
8
8
  /**
9
+ * @deprecated Use `useAssistantApi()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
10
+ *
9
11
  * Hook to access the AssistantRuntime from the current context.
10
12
  *
11
13
  * The AssistantRuntime provides access to the top-level assistant state and actions,
@@ -17,13 +19,21 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
17
19
  *
18
20
  * @example
19
21
  * ```tsx
22
+ * // Before:
20
23
  * function MyComponent() {
21
24
  * const runtime = useAssistantRuntime();
22
- *
23
25
  * const handleNewThread = () => {
24
26
  * runtime.switchToNewThread();
25
27
  * };
28
+ * return <button onClick={handleNewThread}>New Thread</button>;
29
+ * }
26
30
  *
31
+ * // After:
32
+ * function MyComponent() {
33
+ * const api = useAssistantApi();
34
+ * const handleNewThread = () => {
35
+ * api.threads().switchToNewThread();
36
+ * };
27
37
  * return <button onClick={handleNewThread}>New Thread</button>;
28
38
  * }
29
39
  * ```
@@ -38,7 +48,7 @@ export function useAssistantRuntime(options?: {
38
48
  optional?: boolean | undefined;
39
49
  }) {
40
50
  const api = useAssistantApi();
41
- const runtime = api.__internal_getRuntime?.() ?? null;
51
+ const runtime = api.threads().__internal_getAssistantRuntime?.() ?? null;
42
52
 
43
53
  if (!runtime && !options?.optional) {
44
54
  throw new Error("AssistantRuntime is not available");
@@ -50,4 +60,8 @@ export function useAssistantRuntime(options?: {
50
60
  const useThreadListRuntime = (opt: {
51
61
  optional: boolean | undefined;
52
62
  }): ThreadListRuntime | null => useAssistantRuntime(opt)?.threads ?? null;
63
+
64
+ /**
65
+ * @deprecated Use `useAssistantState(({ threads }) => threads)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
66
+ */
53
67
  export const useThreadList = createStateHookForRuntime(useThreadListRuntime);
@@ -4,6 +4,9 @@ import { AttachmentRuntime } from "../runtime/AttachmentRuntime";
4
4
  import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
5
5
  import { useAssistantApi, useAssistantState } from "../../context/react";
6
6
 
7
+ /**
8
+ * @deprecated Use `useAssistantApi()` with `api.attachment()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
9
+ */
7
10
  export function useAttachmentRuntime(options?: {
8
11
  optional?: false | undefined;
9
12
  }): AttachmentRuntime;
@@ -80,6 +83,9 @@ export function useMessageAttachmentRuntime(options?: {
80
83
  return attachmentRuntime as AttachmentRuntime<"message">;
81
84
  }
82
85
 
86
+ /**
87
+ * @deprecated Use `useAssistantState(({ attachment }) => attachment)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
88
+ */
83
89
  export const useAttachment = createStateHookForRuntime(useAttachmentRuntime);
84
90
 
85
91
  export const useThreadComposerAttachment = createStateHookForRuntime(
@@ -5,6 +5,8 @@ import { ComposerRuntime } from "../runtime/ComposerRuntime";
5
5
  import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
6
6
 
7
7
  /**
8
+ * @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
9
+ *
8
10
  * Hook to access the ComposerRuntime from the current context.
9
11
  *
10
12
  * The ComposerRuntime provides access to composer state and actions for message
@@ -18,21 +20,42 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
18
20
  *
19
21
  * @example
20
22
  * ```tsx
23
+ * // Before:
21
24
  * function ComposerActions() {
22
25
  * const runtime = useComposerRuntime();
23
- *
24
26
  * const handleSend = () => {
25
27
  * if (runtime.getState().canSend) {
26
28
  * runtime.send();
27
29
  * }
28
30
  * };
29
- *
30
31
  * const handleCancel = () => {
31
32
  * if (runtime.getState().canCancel) {
32
33
  * runtime.cancel();
33
34
  * }
34
35
  * };
36
+ * return (
37
+ * <div>
38
+ * <button onClick={handleSend}>Send</button>
39
+ * <button onClick={handleCancel}>Cancel</button>
40
+ * </div>
41
+ * );
42
+ * }
35
43
  *
44
+ * // After:
45
+ * function ComposerActions() {
46
+ * const api = useAssistantApi();
47
+ * const canSend = useAssistantState(({ composer }) => composer.canSend);
48
+ * const canCancel = useAssistantState(({ composer }) => composer.canCancel);
49
+ * const handleSend = () => {
50
+ * if (canSend) {
51
+ * api.composer().send();
52
+ * }
53
+ * };
54
+ * const handleCancel = () => {
55
+ * if (canCancel) {
56
+ * api.composer().cancel();
57
+ * }
58
+ * };
36
59
  * return (
37
60
  * <div>
38
61
  * <button onClick={handleSend}>Send</button>
@@ -64,6 +87,8 @@ export function useComposerRuntime(options?: {
64
87
  }
65
88
 
66
89
  /**
90
+ * @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
91
+ *
67
92
  * Hook to access the current composer state.
68
93
  *
69
94
  * This hook provides reactive access to the composer's state, including text content,
@@ -74,11 +99,25 @@ export function useComposerRuntime(options?: {
74
99
  *
75
100
  * @example
76
101
  * ```tsx
102
+ * // Before:
77
103
  * function ComposerStatus() {
78
104
  * const text = useComposer((state) => state.text);
79
105
  * const canSend = useComposer((state) => state.canSend);
80
106
  * const attachmentCount = useComposer((state) => state.attachments.length);
107
+ * return (
108
+ * <div>
109
+ * Text: {text.length} chars,
110
+ * Attachments: {attachmentCount},
111
+ * Can send: {canSend}
112
+ * </div>
113
+ * );
114
+ * }
81
115
  *
116
+ * // After:
117
+ * function ComposerStatus() {
118
+ * const text = useAssistantState(({ composer }) => composer.text);
119
+ * const canSend = useAssistantState(({ composer }) => composer.canSend);
120
+ * const attachmentCount = useAssistantState(({ composer }) => composer.attachments.length);
82
121
  * return (
83
122
  * <div>
84
123
  * Text: {text.length} chars,
@@ -6,6 +6,8 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
6
6
  import { EditComposerRuntime } from "../runtime";
7
7
 
8
8
  /**
9
+ * @deprecated Use `useAssistantApi()` with `api.message()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
10
+ *
9
11
  * Hook to access the MessageRuntime from the current context.
10
12
  *
11
13
  * The MessageRuntime provides access to message-level state and actions,
@@ -17,17 +19,32 @@ import { EditComposerRuntime } from "../runtime";
17
19
  *
18
20
  * @example
19
21
  * ```tsx
22
+ * // Before:
20
23
  * function MessageActions() {
21
24
  * const runtime = useMessageRuntime();
22
- *
23
25
  * const handleReload = () => {
24
26
  * runtime.reload();
25
27
  * };
26
- *
27
28
  * const handleEdit = () => {
28
29
  * runtime.startEdit();
29
30
  * };
31
+ * return (
32
+ * <div>
33
+ * <button onClick={handleReload}>Reload</button>
34
+ * <button onClick={handleEdit}>Edit</button>
35
+ * </div>
36
+ * );
37
+ * }
30
38
  *
39
+ * // After:
40
+ * function MessageActions() {
41
+ * const api = useAssistantApi();
42
+ * const handleReload = () => {
43
+ * api.message().reload();
44
+ * };
45
+ * const handleEdit = () => {
46
+ * api.message().startEdit();
47
+ * };
31
48
  * return (
32
49
  * <div>
33
50
  * <button onClick={handleReload}>Reload</button>
@@ -59,6 +76,8 @@ export function useMessageRuntime(options?: {
59
76
  }
60
77
 
61
78
  /**
79
+ * @deprecated Use `useAssistantState(({ message }) => message)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
80
+ *
62
81
  * Hook to access the current message state.
63
82
  *
64
83
  * This hook provides reactive access to the message's state, including content,
@@ -69,11 +88,23 @@ export function useMessageRuntime(options?: {
69
88
  *
70
89
  * @example
71
90
  * ```tsx
91
+ * // Before:
72
92
  * function MessageContent() {
73
93
  * const role = useMessage((state) => state.role);
74
94
  * const content = useMessage((state) => state.content);
75
95
  * const isLoading = useMessage((state) => state.status.type === "running");
96
+ * return (
97
+ * <div className={`message-${role}`}>
98
+ * {isLoading ? "Loading..." : content.map(part => part.text).join("")}
99
+ * </div>
100
+ * );
101
+ * }
76
102
  *
103
+ * // After:
104
+ * function MessageContent() {
105
+ * const role = useAssistantState(({ message }) => message.role);
106
+ * const content = useAssistantState(({ message }) => message.content);
107
+ * const isLoading = useAssistantState(({ message }) => message.status.type === "running");
77
108
  * return (
78
109
  * <div className={`message-${role}`}>
79
110
  * {isLoading ? "Loading..." : content.map(part => part.text).join("")}
@@ -87,6 +118,10 @@ export const useMessage = createStateHookForRuntime(useMessageRuntime);
87
118
  const useEditComposerRuntime = (opt: {
88
119
  optional: boolean | undefined;
89
120
  }): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;
121
+
122
+ /**
123
+ * @deprecated Use `useAssistantState(({ message }) => message.composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
124
+ */
90
125
  export const useEditComposer = createStateHookForRuntime(
91
126
  useEditComposerRuntime,
92
127
  );
@@ -4,6 +4,9 @@ import { MessagePartRuntime } from "../runtime/MessagePartRuntime";
4
4
  import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
5
5
  import { useAssistantApi, useAssistantState } from "../../context/react";
6
6
 
7
+ /**
8
+ * @deprecated Use `useAssistantApi()` with `api.part()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
9
+ */
7
10
  export function useMessagePartRuntime(options?: {
8
11
  optional?: false | undefined;
9
12
  }): MessagePartRuntime;
@@ -23,4 +26,7 @@ export function useMessagePartRuntime(options?: {
23
26
  return runtime;
24
27
  }
25
28
 
29
+ /**
30
+ * @deprecated Use `useAssistantState(({ part }) => part)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
31
+ */
26
32
  export const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);
@@ -12,6 +12,8 @@ import {
12
12
  } from "../../context/react";
13
13
 
14
14
  /**
15
+ * @deprecated Use `useAssistantApi()` with `api.thread()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
16
+ *
15
17
  * Hook to access the ThreadRuntime from the current context.
16
18
  *
17
19
  * The ThreadRuntime provides access to thread-level state and actions,
@@ -23,13 +25,21 @@ import {
23
25
  *
24
26
  * @example
25
27
  * ```tsx
28
+ * // Before:
26
29
  * function MyComponent() {
27
30
  * const runtime = useThreadRuntime();
28
- *
29
31
  * const handleSendMessage = (text: string) => {
30
32
  * runtime.append({ role: "user", content: [{ type: "text", text }] });
31
33
  * };
34
+ * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
35
+ * }
32
36
  *
37
+ * // After:
38
+ * function MyComponent() {
39
+ * const api = useAssistantApi();
40
+ * const handleSendMessage = (text: string) => {
41
+ * api.thread().append({ role: "user", content: [{ type: "text", text }] });
42
+ * };
33
43
  * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
34
44
  * }
35
45
  * ```
@@ -52,6 +62,8 @@ export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
52
62
  }
53
63
 
54
64
  /**
65
+ * @deprecated Use `useAssistantState(({ thread }) => thread)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
66
+ *
55
67
  * Hook to access the current thread state.
56
68
  *
57
69
  * This hook provides reactive access to the thread's state, including messages,
@@ -62,10 +74,17 @@ export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
62
74
  *
63
75
  * @example
64
76
  * ```tsx
77
+ * // Before:
65
78
  * function ThreadStatus() {
66
79
  * const isRunning = useThread((state) => state.isRunning);
67
80
  * const messageCount = useThread((state) => state.messages.length);
81
+ * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
82
+ * }
68
83
  *
84
+ * // After:
85
+ * function ThreadStatus() {
86
+ * const isRunning = useAssistantState(({ thread }) => thread.isRunning);
87
+ * const messageCount = useAssistantState(({ thread }) => thread.messages.length);
69
88
  * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
70
89
  * }
71
90
  * ```
@@ -75,10 +94,17 @@ export const useThread = createStateHookForRuntime(useThreadRuntime);
75
94
  const useThreadComposerRuntime = (opt: {
76
95
  optional: boolean | undefined;
77
96
  }): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;
97
+
98
+ /**
99
+ * @deprecated Use `useAssistantState(({ thread }) => thread.composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
100
+ */
78
101
  export const useThreadComposer = createStateHookForRuntime(
79
102
  useThreadComposerRuntime,
80
103
  );
81
104
 
105
+ /**
106
+ * @deprecated Use `useAssistantState(({ thread }) => thread.modelContext)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
107
+ */
82
108
  export function useThreadModelContext(options?: {
83
109
  optional?: false | undefined;
84
110
  }): ModelContext;
@@ -4,6 +4,9 @@ import { ThreadListItemRuntime } from "../runtime/ThreadListItemRuntime";
4
4
  import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
5
5
  import { useAssistantApi, useAssistantState } from "../../context/react";
6
6
 
7
+ /**
8
+ * @deprecated Use `useAssistantApi()` with `api.threadListItem()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
9
+ */
7
10
  export function useThreadListItemRuntime(options?: {
8
11
  optional?: false | undefined;
9
12
  }): ThreadListItemRuntime;
@@ -25,6 +28,9 @@ export function useThreadListItemRuntime(options?: {
25
28
  return runtime;
26
29
  }
27
30
 
31
+ /**
32
+ * @deprecated Use `useAssistantState(({ threadListItem }) => threadListItem)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
33
+ */
28
34
  export const useThreadListItem = createStateHookForRuntime(
29
35
  useThreadListItemRuntime,
30
36
  );
@@ -7,6 +7,7 @@ export type AssistantRuntimeCore = {
7
7
  readonly threads: ThreadListRuntimeCore;
8
8
 
9
9
  registerModelContextProvider: (provider: ModelContextProvider) => Unsubscribe;
10
+ getModelContextProvider: () => ModelContextProvider;
10
11
 
11
12
  /**
12
13
  * EXPERIMENTAL: A component that is rendered inside the AssistantRuntimeProvider.
@@ -13,4 +13,8 @@ export abstract class BaseAssistantRuntimeCore implements AssistantRuntimeCore {
13
13
  ): Unsubscribe {
14
14
  return this._contextProvider.registerModelContextProvider(provider);
15
15
  }
16
+
17
+ public getModelContextProvider(): ModelContextProvider {
18
+ return this._contextProvider;
19
+ }
16
20
  }
@@ -212,8 +212,10 @@ export class ExternalStoreThreadListRuntimeCore
212
212
  onDelete(threadId);
213
213
  }
214
214
 
215
- public initialize(): never {
216
- throw new Error("Method not implemented.");
215
+ public initialize(
216
+ threadId: string,
217
+ ): Promise<{ remoteId: string; externalId: string | undefined }> {
218
+ return Promise.resolve({ remoteId: threadId, externalId: undefined });
217
219
  }
218
220
 
219
221
  public generateTitle(): never {
@@ -162,7 +162,13 @@ export class ExternalStoreThreadRuntimeCore
162
162
  if (!store.convertMessage) return m;
163
163
 
164
164
  const isLast = idx === store.messages!.length - 1;
165
- const autoStatus = getAutoStatus(isLast, isRunning, false, false);
165
+ const autoStatus = getAutoStatus(
166
+ isLast,
167
+ isRunning,
168
+ false,
169
+ false,
170
+ undefined,
171
+ );
166
172
 
167
173
  if (
168
174
  cache &&
@@ -1,34 +1,67 @@
1
+ import { ReadonlyJSONValue } from "assistant-stream/utils";
1
2
  import { MessageStatus } from "../../../types";
2
3
 
3
- const AUTO_STATUS_RUNNING = Object.freeze({ type: "running" });
4
- const AUTO_STATUS_COMPLETE = Object.freeze({
5
- type: "complete",
6
- reason: "unknown",
7
- });
4
+ const symbolAutoStatus = Symbol("autoStatus");
8
5
 
9
- const AUTO_STATUS_PENDING = Object.freeze({
10
- type: "requires-action",
11
- reason: "tool-calls",
12
- });
6
+ const AUTO_STATUS_RUNNING = Object.freeze(
7
+ Object.assign({ type: "running" as const }, { [symbolAutoStatus]: true }),
8
+ );
9
+ const AUTO_STATUS_COMPLETE = Object.freeze(
10
+ Object.assign(
11
+ {
12
+ type: "complete" as const,
13
+ reason: "unknown" as const,
14
+ },
15
+ { [symbolAutoStatus]: true },
16
+ ),
17
+ );
13
18
 
14
- const AUTO_STATUS_INTERRUPT = Object.freeze({
15
- type: "requires-action",
16
- reason: "interrupt",
17
- });
19
+ const AUTO_STATUS_PENDING = Object.freeze(
20
+ Object.assign(
21
+ {
22
+ type: "requires-action" as const,
23
+ reason: "tool-calls" as const,
24
+ },
25
+ { [symbolAutoStatus]: true },
26
+ ),
27
+ );
28
+
29
+ const AUTO_STATUS_INTERRUPT = Object.freeze(
30
+ Object.assign(
31
+ {
32
+ type: "requires-action" as const,
33
+ reason: "interrupt" as const,
34
+ },
35
+ { [symbolAutoStatus]: true },
36
+ ),
37
+ );
18
38
 
19
39
  export const isAutoStatus = (status: MessageStatus) =>
20
- status === AUTO_STATUS_RUNNING || status === AUTO_STATUS_COMPLETE;
40
+ (status as any)[symbolAutoStatus] === true;
21
41
 
22
42
  export const getAutoStatus = (
23
43
  isLast: boolean,
24
44
  isRunning: boolean,
25
45
  hasInterruptedToolCalls: boolean,
26
46
  hasPendingToolCalls: boolean,
27
- ) =>
28
- isLast && isRunning
47
+ error?: ReadonlyJSONValue,
48
+ ): MessageStatus => {
49
+ if (isLast && error) {
50
+ return Object.assign(
51
+ {
52
+ type: "incomplete" as const,
53
+ reason: "error" as const,
54
+ error: error,
55
+ },
56
+ { [symbolAutoStatus]: true },
57
+ );
58
+ }
59
+
60
+ return isLast && isRunning
29
61
  ? AUTO_STATUS_RUNNING
30
62
  : hasInterruptedToolCalls
31
63
  ? AUTO_STATUS_INTERRUPT
32
64
  : hasPendingToolCalls
33
65
  ? AUTO_STATUS_PENDING
34
66
  : AUTO_STATUS_COMPLETE;
67
+ };
@@ -10,6 +10,7 @@ import { fromThreadMessageLike, ThreadMessageLike } from "./ThreadMessageLike";
10
10
  import { getAutoStatus, isAutoStatus } from "./auto-status";
11
11
  import { ThreadMessage, ToolCallMessagePart } from "../../../types";
12
12
  import { ToolExecutionStatus } from "../assistant-transport/useToolInvocations";
13
+ import { ReadonlyJSONValue } from "assistant-stream/utils";
13
14
 
14
15
  export namespace useExternalMessageConverter {
15
16
  export type Message =
@@ -30,6 +31,7 @@ export namespace useExternalMessageConverter {
30
31
 
31
32
  export type Metadata = {
32
33
  readonly toolStatuses?: Record<string, ToolExecutionStatus>;
34
+ readonly error?: ReadonlyJSONValue;
33
35
  };
34
36
 
35
37
  export type Callback<T> = (
@@ -263,6 +265,7 @@ export const convertExternalMessages = <T extends WeakKey>(
263
265
  isRunning,
264
266
  hasSuspendedToolCalls,
265
267
  hasPendingToolCalls,
268
+ isLast ? metadata.error : undefined,
266
269
  );
267
270
  const newMessage = fromThreadMessageLike(
268
271
  joined,
@@ -348,6 +351,7 @@ export const useExternalMessageConverter = <T extends WeakKey>({
348
351
  isRunning,
349
352
  hasSuspendedToolCalls,
350
353
  hasPendingToolCalls,
354
+ isLast ? state.metadata.error : undefined,
351
355
  );
352
356
 
353
357
  if (
@@ -104,8 +104,10 @@ export class LocalThreadListRuntimeCore
104
104
  throw new Error("Method not implemented.");
105
105
  }
106
106
 
107
- public initialize(): never {
108
- throw new Error("Method not implemented.");
107
+ public initialize(
108
+ threadId: string,
109
+ ): Promise<{ remoteId: string; externalId: string | undefined }> {
110
+ return Promise.resolve({ remoteId: threadId, externalId: undefined });
109
111
  }
110
112
 
111
113
  public generateTitle(): never {
@@ -67,7 +67,7 @@ export const ExportedMessageRepository = {
67
67
  fromThreadMessageLike(
68
68
  m,
69
69
  generateId(),
70
- getAutoStatus(false, false, false, false),
70
+ getAutoStatus(false, false, false, false, undefined),
71
71
  ),
72
72
  );
73
73
 
@@ -19,5 +19,14 @@ export { tool } from "./tool";
19
19
 
20
20
  export { makeAssistantVisible } from "./makeAssistantVisible";
21
21
 
22
+ export {
23
+ Toolkit,
24
+ type ToolDefinition,
25
+ type ToolkitFallback,
26
+ type ToolkitLayout,
27
+ } from "./toolbox";
28
+
29
+ export { Tools } from "../client/Tools";
30
+
22
31
  export * from "./registry";
23
32
  export * from "./frame";
@@ -76,7 +76,7 @@ export const makeAssistantVisible = <T extends ComponentType<any>>(
76
76
 
77
77
  const { clickable, editable } = config ?? {};
78
78
  useEffect(() => {
79
- return api.registerModelContextProvider({
79
+ return api.modelContext().register({
80
80
  getModelContext: () => {
81
81
  return {
82
82
  tools: {