@assistant-ui/react 0.12.1 → 0.12.5

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 (143) hide show
  1. package/dist/client/ExternalThread.d.ts +16 -0
  2. package/dist/client/ExternalThread.d.ts.map +1 -0
  3. package/dist/client/ExternalThread.js +329 -0
  4. package/dist/client/ExternalThread.js.map +1 -0
  5. package/dist/client/InMemoryThreadList.d.ts +9 -0
  6. package/dist/client/InMemoryThreadList.d.ts.map +1 -0
  7. package/dist/client/InMemoryThreadList.js +129 -0
  8. package/dist/client/InMemoryThreadList.js.map +1 -0
  9. package/dist/client/Suggestions.d.ts +11 -0
  10. package/dist/client/Suggestions.d.ts.map +1 -0
  11. package/dist/client/Suggestions.js +43 -0
  12. package/dist/client/Suggestions.js.map +1 -0
  13. package/dist/client/Tools.d.ts.map +1 -1
  14. package/dist/client/Tools.js +5 -1
  15. package/dist/client/Tools.js.map +1 -1
  16. package/dist/client/index.d.ts +6 -0
  17. package/dist/client/index.d.ts.map +1 -0
  18. package/dist/client/index.js +6 -0
  19. package/dist/client/index.js.map +1 -0
  20. package/dist/context/providers/SuggestionByIndexProvider.d.ts +6 -0
  21. package/dist/context/providers/SuggestionByIndexProvider.d.ts.map +1 -0
  22. package/dist/context/providers/SuggestionByIndexProvider.js +14 -0
  23. package/dist/context/providers/SuggestionByIndexProvider.js.map +1 -0
  24. package/dist/context/providers/index.d.ts +1 -0
  25. package/dist/context/providers/index.d.ts.map +1 -1
  26. package/dist/context/providers/index.js +1 -0
  27. package/dist/context/providers/index.js.map +1 -1
  28. package/dist/devtools/index.d.ts +1 -1
  29. package/dist/devtools/index.d.ts.map +1 -1
  30. package/dist/devtools/index.js +1 -1
  31. package/dist/devtools/index.js.map +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts +5 -0
  37. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  38. package/dist/legacy-runtime/AssistantRuntimeProvider.js +9 -5
  39. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  40. package/dist/legacy-runtime/RuntimeAdapter.js +2 -1
  41. package/dist/legacy-runtime/RuntimeAdapter.js.map +1 -1
  42. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  43. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +3 -5
  44. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  45. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts +10 -12
  46. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts.map +1 -1
  47. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js +14 -19
  48. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js.map +1 -1
  49. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  50. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +32 -4
  51. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  52. package/dist/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.d.ts.map +1 -1
  53. package/dist/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.js +3 -0
  54. package/dist/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.js.map +1 -1
  55. package/dist/model-context/index.d.ts +1 -0
  56. package/dist/model-context/index.d.ts.map +1 -1
  57. package/dist/model-context/index.js +1 -0
  58. package/dist/model-context/index.js.map +1 -1
  59. package/dist/primitives/assistantModal/AssistantModalRoot.js +1 -1
  60. package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
  61. package/dist/primitives/index.d.ts +1 -0
  62. package/dist/primitives/index.d.ts.map +1 -1
  63. package/dist/primitives/index.js +1 -0
  64. package/dist/primitives/index.js.map +1 -1
  65. package/dist/primitives/message/MessageParts.d.ts +11 -0
  66. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  67. package/dist/primitives/message/MessageParts.js +18 -2
  68. package/dist/primitives/message/MessageParts.js.map +1 -1
  69. package/dist/primitives/message/MessagePartsGrouped.js +1 -1
  70. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  71. package/dist/primitives/suggestion/SuggestionDescription.d.ts +18 -0
  72. package/dist/primitives/suggestion/SuggestionDescription.d.ts.map +1 -0
  73. package/dist/primitives/suggestion/SuggestionDescription.js +19 -0
  74. package/dist/primitives/suggestion/SuggestionDescription.js.map +1 -0
  75. package/dist/primitives/suggestion/SuggestionTitle.d.ts +18 -0
  76. package/dist/primitives/suggestion/SuggestionTitle.d.ts.map +1 -0
  77. package/dist/primitives/suggestion/SuggestionTitle.js +19 -0
  78. package/dist/primitives/suggestion/SuggestionTitle.js.map +1 -0
  79. package/dist/primitives/suggestion/SuggestionTrigger.d.ts +49 -0
  80. package/dist/primitives/suggestion/SuggestionTrigger.d.ts.map +1 -0
  81. package/dist/primitives/suggestion/SuggestionTrigger.js +45 -0
  82. package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -0
  83. package/dist/primitives/suggestion/index.d.ts +4 -0
  84. package/dist/primitives/suggestion/index.d.ts.map +1 -0
  85. package/dist/primitives/suggestion/index.js +4 -0
  86. package/dist/primitives/suggestion/index.js.map +1 -0
  87. package/dist/primitives/thread/ThreadSuggestions.d.ts +53 -0
  88. package/dist/primitives/thread/ThreadSuggestions.d.ts.map +1 -0
  89. package/dist/primitives/thread/ThreadSuggestions.js +58 -0
  90. package/dist/primitives/thread/ThreadSuggestions.js.map +1 -0
  91. package/dist/primitives/thread/index.d.ts +1 -0
  92. package/dist/primitives/thread/index.d.ts.map +1 -1
  93. package/dist/primitives/thread/index.js +1 -0
  94. package/dist/primitives/thread/index.js.map +1 -1
  95. package/dist/types/scopes/index.d.ts +2 -0
  96. package/dist/types/scopes/index.d.ts.map +1 -1
  97. package/dist/types/scopes/suggestion.d.ts +20 -0
  98. package/dist/types/scopes/suggestion.d.ts.map +1 -0
  99. package/dist/types/scopes/suggestion.js +2 -0
  100. package/dist/types/scopes/suggestion.js.map +1 -0
  101. package/dist/types/scopes/suggestions.d.ts +20 -0
  102. package/dist/types/scopes/suggestions.d.ts.map +1 -0
  103. package/dist/types/scopes/suggestions.js +2 -0
  104. package/dist/types/scopes/suggestions.js.map +1 -0
  105. package/dist/types/store-augmentation.d.ts +4 -0
  106. package/dist/types/store-augmentation.d.ts.map +1 -1
  107. package/dist/utils/idUtils.d.ts +2 -0
  108. package/dist/utils/idUtils.d.ts.map +1 -1
  109. package/dist/utils/idUtils.js +3 -0
  110. package/dist/utils/idUtils.js.map +1 -1
  111. package/package.json +12 -12
  112. package/src/client/ExternalThread.ts +491 -0
  113. package/src/client/InMemoryThreadList.ts +197 -0
  114. package/src/client/Suggestions.ts +74 -0
  115. package/src/client/Tools.ts +10 -1
  116. package/src/client/index.ts +12 -0
  117. package/src/context/providers/SuggestionByIndexProvider.tsx +23 -0
  118. package/src/context/providers/index.ts +1 -0
  119. package/src/devtools/index.ts +1 -1
  120. package/src/index.ts +1 -0
  121. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +15 -6
  122. package/src/legacy-runtime/RuntimeAdapter.ts +2 -1
  123. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +3 -4
  124. package/src/legacy-runtime/runtime-cores/assistant-transport/utils.ts +19 -24
  125. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +42 -7
  126. package/src/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.tsx +3 -0
  127. package/src/model-context/index.ts +2 -0
  128. package/src/primitives/assistantModal/AssistantModalRoot.tsx +1 -1
  129. package/src/primitives/index.ts +1 -0
  130. package/src/primitives/message/MessageParts.tsx +45 -1
  131. package/src/primitives/message/MessagePartsGrouped.tsx +1 -1
  132. package/src/primitives/suggestion/SuggestionDescription.tsx +33 -0
  133. package/src/primitives/suggestion/SuggestionTitle.tsx +33 -0
  134. package/src/primitives/suggestion/SuggestionTrigger.tsx +79 -0
  135. package/src/primitives/suggestion/index.ts +3 -0
  136. package/src/primitives/thread/ThreadSuggestions.tsx +109 -0
  137. package/src/primitives/thread/index.ts +4 -0
  138. package/src/tests/external-message-converter.test.ts +105 -16
  139. package/src/types/scopes/index.ts +12 -0
  140. package/src/types/scopes/suggestion.ts +20 -0
  141. package/src/types/scopes/suggestions.ts +21 -0
  142. package/src/types/store-augmentation.ts +4 -0
  143. package/src/utils/idUtils.tsx +4 -0
@@ -0,0 +1,197 @@
1
+ import { resource, tapState, tapMemo } from "@assistant-ui/tap";
2
+ import {
3
+ type ClientOutput,
4
+ tapClientLookup,
5
+ Derived,
6
+ attachDefaultPeers,
7
+ tapClientResource,
8
+ } from "@assistant-ui/store";
9
+ import { withKey } from "@assistant-ui/tap";
10
+ import type { ResourceElement } from "@assistant-ui/tap";
11
+ import type { ThreadState } from "../types/scopes/thread";
12
+ import { Suggestions } from "./Suggestions";
13
+ import { ModelContext } from "./ModelContextClient";
14
+ import { Tools } from "./Tools";
15
+
16
+ export type InMemoryThreadListProps = {
17
+ thread: (threadId: string) => ResourceElement<ClientOutput<"thread">>;
18
+ onSwitchToThread?: (threadId: string) => void;
19
+ onSwitchToNewThread?: () => void;
20
+ };
21
+
22
+ type ThreadData = {
23
+ id: string;
24
+ title?: string;
25
+ status: "regular" | "archived";
26
+ };
27
+
28
+ // ThreadListItem Client
29
+ const ThreadListItemClient = resource(
30
+ (props: {
31
+ data: ThreadData;
32
+ onSwitchTo: () => void;
33
+ onArchive: () => void;
34
+ onUnarchive: () => void;
35
+ onDelete: () => void;
36
+ }): ClientOutput<"threadListItem"> => {
37
+ const { data, onSwitchTo, onArchive, onUnarchive, onDelete } = props;
38
+ const state = tapMemo(
39
+ () => ({
40
+ id: data.id,
41
+ remoteId: undefined,
42
+ externalId: undefined,
43
+ title: data.title,
44
+ status: data.status,
45
+ }),
46
+ [data.id, data.title, data.status],
47
+ );
48
+
49
+ return {
50
+ state,
51
+ methods: {
52
+ getState: () => state,
53
+ switchTo: onSwitchTo,
54
+ rename: () => {},
55
+ archive: onArchive,
56
+ unarchive: onUnarchive,
57
+ delete: onDelete,
58
+ generateTitle: () => {},
59
+ initialize: async () => ({ remoteId: data.id, externalId: undefined }),
60
+ detach: () => {},
61
+ },
62
+ };
63
+ },
64
+ );
65
+
66
+ // InMemoryThreadList Client
67
+ export const InMemoryThreadList = resource(
68
+ (props: InMemoryThreadListProps): ClientOutput<"threads"> => {
69
+ const {
70
+ thread: threadFactory,
71
+ onSwitchToThread,
72
+ onSwitchToNewThread,
73
+ } = props;
74
+
75
+ const [mainThreadId, setMainThreadId] = tapState("main");
76
+ const [threads, setThreads] = tapState<readonly ThreadData[]>(() => [
77
+ { id: "main", title: "Main Thread", status: "regular" },
78
+ ]);
79
+
80
+ const handleSwitchToThread = (threadId: string) => {
81
+ setMainThreadId(threadId);
82
+ onSwitchToThread?.(threadId);
83
+ };
84
+
85
+ const handleArchive = (threadId: string) => {
86
+ setThreads((prev) =>
87
+ prev.map((t) =>
88
+ t.id === threadId ? { ...t, status: "archived" as const } : t,
89
+ ),
90
+ );
91
+ };
92
+
93
+ const handleUnarchive = (threadId: string) => {
94
+ setThreads((prev) =>
95
+ prev.map((t) =>
96
+ t.id === threadId ? { ...t, status: "regular" as const } : t,
97
+ ),
98
+ );
99
+ };
100
+
101
+ const handleDelete = (threadId: string) => {
102
+ setThreads((prev) => prev.filter((t) => t.id !== threadId));
103
+ if (mainThreadId === threadId) {
104
+ const remaining = threads.filter((t) => t.id !== threadId);
105
+ setMainThreadId(remaining[0]?.id || "main");
106
+ }
107
+ };
108
+
109
+ const handleSwitchToNewThread = () => {
110
+ const newId = `thread-${Date.now()}`;
111
+ setThreads((prev) => [
112
+ ...prev,
113
+ { id: newId, title: "New Thread", status: "regular" },
114
+ ]);
115
+ setMainThreadId(newId);
116
+ onSwitchToNewThread?.();
117
+ };
118
+
119
+ const threadListItems = tapClientLookup(
120
+ () =>
121
+ threads.map((t) =>
122
+ withKey(
123
+ t.id,
124
+ ThreadListItemClient({
125
+ data: t,
126
+ onSwitchTo: () => handleSwitchToThread(t.id),
127
+ onArchive: () => handleArchive(t.id),
128
+ onUnarchive: () => handleUnarchive(t.id),
129
+ onDelete: () => handleDelete(t.id),
130
+ }),
131
+ ),
132
+ ),
133
+ [threads],
134
+ );
135
+
136
+ // Create the main thread
137
+ const mainThreadClient = tapClientResource(threadFactory(mainThreadId));
138
+
139
+ const state = tapMemo(() => {
140
+ const regularThreads = threads.filter((t) => t.status === "regular");
141
+ const archivedThreads = threads.filter((t) => t.status === "archived");
142
+ const mainThreadState = mainThreadClient.state as ThreadState;
143
+
144
+ return {
145
+ mainThreadId,
146
+ newThreadId: null,
147
+ isLoading: false,
148
+ threadIds: regularThreads.map((t) => t.id),
149
+ archivedThreadIds: archivedThreads.map((t) => t.id),
150
+ threadItems: threadListItems.state,
151
+ main: mainThreadState,
152
+ };
153
+ }, [mainThreadId, threads, threadListItems.state, mainThreadClient.state]);
154
+
155
+ return {
156
+ state,
157
+ methods: {
158
+ getState: () => state,
159
+ switchToThread: handleSwitchToThread,
160
+ switchToNewThread: handleSwitchToNewThread,
161
+ item: (selector) => {
162
+ if (selector === "main") {
163
+ const index = threads.findIndex((t) => t.id === mainThreadId);
164
+ return threadListItems.get({ index: index === -1 ? 0 : index });
165
+ }
166
+ if ("id" in selector) {
167
+ const index = threads.findIndex((t) => t.id === selector.id);
168
+ return threadListItems.get({ index });
169
+ }
170
+ return threadListItems.get(selector);
171
+ },
172
+ thread: () => mainThreadClient.methods,
173
+ },
174
+ };
175
+ },
176
+ );
177
+
178
+ attachDefaultPeers(InMemoryThreadList, {
179
+ thread: Derived({
180
+ source: "threads",
181
+ query: { type: "main" },
182
+ get: (aui) => aui.threads().thread("main"),
183
+ }),
184
+ threadListItem: Derived({
185
+ source: "threads",
186
+ query: { type: "main" },
187
+ get: (aui) => aui.threads().item("main"),
188
+ }),
189
+ composer: Derived({
190
+ source: "thread",
191
+ query: {},
192
+ get: (aui) => aui.threads().thread("main").composer,
193
+ }),
194
+ modelContext: ModelContext(),
195
+ tools: Tools({}),
196
+ suggestions: Suggestions(),
197
+ });
@@ -0,0 +1,74 @@
1
+ import { resource, tapState, withKey } from "@assistant-ui/tap";
2
+ import { type ClientOutput, tapClientLookup } from "@assistant-ui/store";
3
+ import type { SuggestionsState, SuggestionState } from "../types/scopes";
4
+
5
+ export type SuggestionConfig =
6
+ | string
7
+ | { title: string; label: string; prompt: string };
8
+
9
+ const SuggestionClient = resource(
10
+ (state: SuggestionState): ClientOutput<"suggestion"> => {
11
+ return {
12
+ state,
13
+ methods: {
14
+ getState: () => state,
15
+ },
16
+ };
17
+ },
18
+ );
19
+
20
+ const SuggestionsResource = resource(
21
+ (suggestions?: SuggestionConfig[]): ClientOutput<"suggestions"> => {
22
+ const [state] = tapState<SuggestionsState>(() => {
23
+ const normalizedSuggestions = (suggestions ?? []).map((s) => {
24
+ if (typeof s === "string") {
25
+ return {
26
+ title: s,
27
+ label: "",
28
+ prompt: s,
29
+ };
30
+ }
31
+ return {
32
+ title: s.title,
33
+ label: s.label,
34
+ prompt: s.prompt,
35
+ };
36
+ });
37
+
38
+ return {
39
+ suggestions: normalizedSuggestions,
40
+ };
41
+ });
42
+
43
+ const suggestionClients = tapClientLookup(
44
+ () =>
45
+ state.suggestions.map((suggestion, index) =>
46
+ withKey(index, SuggestionClient(suggestion)),
47
+ ),
48
+ [state.suggestions],
49
+ );
50
+
51
+ return {
52
+ state,
53
+ methods: {
54
+ getState: () => state,
55
+ suggestion: ({ index }: { index: number }) => {
56
+ return suggestionClients.get({ index });
57
+ },
58
+ },
59
+ };
60
+ },
61
+ );
62
+
63
+ export const Suggestions: {
64
+ (): import("@assistant-ui/tap").ResourceElement<
65
+ ClientOutput<"suggestions">,
66
+ undefined
67
+ >;
68
+ (
69
+ suggestions: SuggestionConfig[],
70
+ ): import("@assistant-ui/tap").ResourceElement<
71
+ ClientOutput<"suggestions">,
72
+ SuggestionConfig[]
73
+ >;
74
+ } = SuggestionsResource as any;
@@ -1,9 +1,14 @@
1
1
  import { resource, tapState, tapEffect, tapCallback } from "@assistant-ui/tap";
2
- import { tapAssistantClientRef, type ClientOutput } from "@assistant-ui/store";
2
+ import {
3
+ tapAssistantClientRef,
4
+ type ClientOutput,
5
+ attachDefaultPeers,
6
+ } from "@assistant-ui/store";
3
7
  import { ToolsState } from "../types/scopes";
4
8
  import type { Tool } from "assistant-stream";
5
9
  import { type Toolkit } from "../model-context/toolbox";
6
10
  import { ToolCallMessagePartComponent } from "../types";
11
+ import { ModelContext } from "./ModelContextClient";
7
12
 
8
13
  export const Tools = resource(
9
14
  ({ toolkit }: { toolkit?: Toolkit }): ClientOutput<"tools"> => {
@@ -86,3 +91,7 @@ export const Tools = resource(
86
91
  };
87
92
  },
88
93
  );
94
+
95
+ attachDefaultPeers(Tools, {
96
+ modelContext: ModelContext(),
97
+ });
@@ -0,0 +1,12 @@
1
+ export { ModelContext as ModelContextClient } from "./ModelContextClient";
2
+ export { Tools } from "./Tools";
3
+ export { Suggestions, type SuggestionConfig } from "./Suggestions";
4
+ export {
5
+ ExternalThread,
6
+ type ExternalThreadProps,
7
+ type ExternalThreadMessage,
8
+ } from "./ExternalThread";
9
+ export {
10
+ InMemoryThreadList,
11
+ type InMemoryThreadListProps,
12
+ } from "./InMemoryThreadList";
@@ -0,0 +1,23 @@
1
+ "use client";
2
+
3
+ import { type FC, type PropsWithChildren } from "react";
4
+ import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
5
+
6
+ export type SuggestionByIndexProviderProps = PropsWithChildren<{
7
+ index: number;
8
+ }>;
9
+
10
+ export const SuggestionByIndexProvider: FC<SuggestionByIndexProviderProps> = ({
11
+ index,
12
+ children,
13
+ }) => {
14
+ const aui = useAui({
15
+ suggestion: Derived({
16
+ source: "suggestions",
17
+ query: { index },
18
+ get: (aui) => aui.suggestions().suggestion({ index }),
19
+ }),
20
+ });
21
+
22
+ return <AuiProvider value={aui}>{children}</AuiProvider>;
23
+ };
@@ -4,6 +4,7 @@ export {
4
4
  ThreadListItemRuntimeProvider,
5
5
  } from "./ThreadListItemProvider";
6
6
  export { MessageByIndexProvider } from "./MessageByIndexProvider";
7
+ export { SuggestionByIndexProvider } from "./SuggestionByIndexProvider";
7
8
  export { PartByIndexProvider } from "./PartByIndexProvider";
8
9
  export {
9
10
  MessageAttachmentByIndexProvider,
@@ -1 +1 @@
1
- export { DevToolsHooks } from "./DevToolsHooks";
1
+ export { DevToolsHooks, DevToolsProviderApi } from "./DevToolsHooks";
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export * from "./model-context";
25
25
  export * from "./primitives";
26
26
  export * from "./types";
27
27
  export * from "./devtools";
28
+ export * from "./client";
28
29
 
29
30
  export * as INTERNAL from "./internal";
30
31
  export type { ToolExecutionStatus } from "./internal";
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { FC, memo, PropsWithChildren } from "react";
4
- import { useAui, AuiProvider } from "@assistant-ui/store";
3
+ import { FC, memo, PropsWithChildren, useEffect } from "react";
4
+ import { useAui, AuiProvider, AssistantClient } from "@assistant-ui/store";
5
5
  import { AssistantRuntime } from "./runtime/AssistantRuntime";
6
6
  import { AssistantRuntimeCore } from "./runtime-cores/core/AssistantRuntimeCore";
7
7
  import { RuntimeAdapter } from "./RuntimeAdapter";
8
8
  import { ThreadPrimitiveViewportProvider } from "../context/providers/ThreadViewportProvider";
9
+ import { DevToolsProviderApi } from "../devtools";
9
10
 
10
11
  export namespace AssistantRuntimeProvider {
11
12
  export type Props = PropsWithChildren<{
@@ -13,6 +14,11 @@ export namespace AssistantRuntimeProvider {
13
14
  * The runtime to provide to the rest of your app.
14
15
  */
15
16
  runtime: AssistantRuntime;
17
+
18
+ /**
19
+ * The aui instance to extend. If not provided, a new aui instance will be created.
20
+ */
21
+ aui?: AssistantClient;
16
22
  }>;
17
23
  }
18
24
 
@@ -22,10 +28,13 @@ const getRenderComponent = (runtime: AssistantRuntime) => {
22
28
 
23
29
  export const AssistantRuntimeProviderImpl: FC<
24
30
  AssistantRuntimeProvider.Props
25
- > = ({ children, runtime }) => {
26
- const aui = useAui({
27
- threads: RuntimeAdapter(runtime),
28
- });
31
+ > = ({ children, aui: parent = null, runtime }) => {
32
+ const aui = useAui({ threads: RuntimeAdapter(runtime) }, { parent: parent });
33
+
34
+ useEffect(() => {
35
+ if (process.env["NODE_ENV"] === "production") return;
36
+ return DevToolsProviderApi.register(aui);
37
+ }, [aui]);
29
38
 
30
39
  const RenderComponent = getRenderComponent(runtime);
31
40
 
@@ -7,7 +7,7 @@ import {
7
7
  attachDefaultPeers,
8
8
  } from "@assistant-ui/store";
9
9
  import { ModelContext } from "../client/ModelContextClient";
10
- import { Tools } from "../model-context";
10
+ import { Tools, Suggestions } from "../model-context";
11
11
 
12
12
  export const RuntimeAdapter = resource((runtime: AssistantRuntime) => {
13
13
  const clientRef = tapAssistantClientRef();
@@ -29,6 +29,7 @@ export const RuntimeAdapter = resource((runtime: AssistantRuntime) => {
29
29
  attachDefaultPeers(RuntimeAdapter, {
30
30
  modelContext: ModelContext(),
31
31
  tools: Tools({}),
32
+ suggestions: Suggestions(),
32
33
  threadListItem: Derived({
33
34
  source: "threads",
34
35
  query: { type: "main" },
@@ -15,6 +15,7 @@ import {
15
15
  DataStreamDecoder,
16
16
  AssistantTransportDecoder,
17
17
  unstable_createInitialMessage as createInitialMessage,
18
+ toToolsJSONSchema,
18
19
  } from "assistant-stream";
19
20
  import {
20
21
  AssistantTransportOptions,
@@ -28,7 +29,7 @@ import { useCommandQueue } from "./commandQueue";
28
29
  import { useRunManager } from "./runManager";
29
30
  import { useConvertedState } from "./useConvertedState";
30
31
  import { ToolExecutionStatus, useToolInvocations } from "./useToolInvocations";
31
- import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils";
32
+ import { createRequestHeaders } from "./utils";
32
33
  import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime";
33
34
  import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory";
34
35
  import { useAui, useAuiState } from "@assistant-ui/store";
@@ -115,9 +116,7 @@ const useAssistantTransportThreadRuntime = <T,>(
115
116
  commands,
116
117
  state: agentStateRef.current,
117
118
  system: context.system,
118
- tools: context.tools
119
- ? toAISDKTools(getEnabledTools(context.tools))
120
- : undefined,
119
+ tools: context.tools ? toToolsJSONSchema(context.tools) : undefined,
121
120
  threadId,
122
121
  ...(parentIdRef.current !== undefined && {
123
122
  parentId: parentIdRef.current,
@@ -1,42 +1,37 @@
1
- import { Tool } from "assistant-stream";
2
- import type { JSONSchema7 } from "json-schema";
3
- import { z } from "zod";
1
+ import { Tool, toToolsJSONSchema, type ToolJSONSchema } from "assistant-stream";
4
2
 
5
- // Convert tools to AI SDK format
6
- export const toAISDKTools = (tools: Record<string, Tool>) => {
7
- return Object.fromEntries(
8
- Object.entries(tools).map(([name, tool]) => [
9
- name,
10
- {
11
- ...(tool.description ? { description: tool.description } : undefined),
12
- parameters: (tool.parameters instanceof z.ZodType
13
- ? z.toJSONSchema(tool.parameters)
14
- : tool.parameters) as JSONSchema7,
15
- },
16
- ]),
17
- );
18
- };
3
+ /**
4
+ * @deprecated Use `toToolsJSONSchema` from `assistant-stream` instead.
5
+ */
6
+ export function toAISDKTools(
7
+ tools: Record<string, Tool>,
8
+ ): Record<string, ToolJSONSchema> {
9
+ return toToolsJSONSchema(tools, { filter: () => true });
10
+ }
19
11
 
20
- // Filter enabled tools
21
- export const getEnabledTools = (tools: Record<string, Tool>) => {
12
+ /**
13
+ * @deprecated Use `toToolsJSONSchema` from `assistant-stream` instead, which includes filtering by default.
14
+ */
15
+ export function getEnabledTools(
16
+ tools: Record<string, Tool>,
17
+ ): Record<string, Tool> {
22
18
  return Object.fromEntries(
23
19
  Object.entries(tools).filter(
24
20
  ([, tool]) => !tool.disabled && tool.type !== "backend",
25
21
  ),
26
22
  );
27
- };
23
+ }
28
24
 
29
- // Create headers for fetch request
30
- export const createRequestHeaders = async (
25
+ export async function createRequestHeaders(
31
26
  headersValue:
32
27
  | Record<string, string>
33
28
  | Headers
34
29
  | (() => Promise<Record<string, string> | Headers>),
35
- ): Promise<Headers> => {
30
+ ): Promise<Headers> {
36
31
  const resolvedHeaders =
37
32
  typeof headersValue === "function" ? await headersValue() : headersValue;
38
33
 
39
34
  const headers = new Headers(resolvedHeaders);
40
35
  headers.set("Content-Type", "application/json");
41
36
  return headers;
42
- };
37
+ }
@@ -11,6 +11,8 @@ import { getAutoStatus, isAutoStatus } from "./auto-status";
11
11
  import { ThreadMessage, ToolCallMessagePart } from "../../../types";
12
12
  import { ToolExecutionStatus } from "../assistant-transport/useToolInvocations";
13
13
  import { ReadonlyJSONValue } from "assistant-stream/utils";
14
+ import { generateErrorMessageId } from "../../../utils/idUtils";
15
+ import { ThreadAssistantMessage } from "../../../types/AssistantTypes";
14
16
 
15
17
  export namespace useExternalMessageConverter {
16
18
  export type Message =
@@ -262,6 +264,28 @@ const chunkExternalMessages = <T,>(
262
264
  return results;
263
265
  };
264
266
 
267
+ function createErrorAssistantMessage(
268
+ error: ReadonlyJSONValue,
269
+ ): ThreadAssistantMessage {
270
+ return Object.assign<ThreadAssistantMessage, { [symbolInnerMessage]: [] }>(
271
+ {
272
+ id: generateErrorMessageId(),
273
+ role: "assistant",
274
+ content: [],
275
+ status: { type: "incomplete", reason: "error", error },
276
+ createdAt: new Date(),
277
+ metadata: {
278
+ unstable_state: null,
279
+ unstable_annotations: [],
280
+ unstable_data: [],
281
+ custom: {},
282
+ steps: [],
283
+ },
284
+ },
285
+ { [symbolInnerMessage]: [] },
286
+ );
287
+ }
288
+
265
289
  export const convertExternalMessages = <T extends WeakKey>(
266
290
  messages: T[],
267
291
  callback: useExternalMessageConverter.Callback<T>,
@@ -278,14 +302,9 @@ export const convertExternalMessages = <T extends WeakKey>(
278
302
 
279
303
  const chunks = chunkExternalMessages(callbackResults);
280
304
 
281
- return chunks.map((message, idx) => {
305
+ const result = chunks.map((message, idx) => {
282
306
  const isLast = idx === chunks.length - 1;
283
307
  const joined = joinExternalMessages(message.outputs);
284
- const hasSuspendedToolCalls =
285
- typeof joined.content === "object" &&
286
- joined.content.some(
287
- (c) => c.type === "tool-call" && c.result === undefined,
288
- );
289
308
  const hasPendingToolCalls =
290
309
  typeof joined.content === "object" &&
291
310
  joined.content.some(
@@ -294,7 +313,7 @@ export const convertExternalMessages = <T extends WeakKey>(
294
313
  const autoStatus = getAutoStatus(
295
314
  isLast,
296
315
  isRunning,
297
- hasSuspendedToolCalls,
316
+ hasPendingToolCalls,
298
317
  hasPendingToolCalls,
299
318
  isLast ? metadata.error : undefined,
300
319
  );
@@ -306,6 +325,15 @@ export const convertExternalMessages = <T extends WeakKey>(
306
325
  (newMessage as any)[symbolInnerMessage] = message.inputs;
307
326
  return newMessage;
308
327
  });
328
+
329
+ if (metadata.error) {
330
+ const lastMessage = result.at(-1);
331
+ if (!lastMessage || lastMessage.role !== "assistant") {
332
+ result.push(createErrorAssistantMessage(metadata.error));
333
+ }
334
+ }
335
+
336
+ return result;
309
337
  };
310
338
 
311
339
  export const useExternalMessageConverter = <T extends WeakKey>({
@@ -411,6 +439,13 @@ export const useExternalMessageConverter = <T extends WeakKey>({
411
439
  symbolInnerMessage
412
440
  ] = messages;
413
441
 
442
+ if (state.metadata.error) {
443
+ const lastMessage = threadMessages.at(-1);
444
+ if (!lastMessage || lastMessage.role !== "assistant") {
445
+ threadMessages.push(createErrorAssistantMessage(state.metadata.error));
446
+ }
447
+ }
448
+
414
449
  return threadMessages;
415
450
  }, [state, messages, isRunning, joinStrategy]);
416
451
  };
@@ -31,6 +31,9 @@ export class BaseSubscribable {
31
31
  if (errors.length === 1) {
32
32
  throw errors[0];
33
33
  } else {
34
+ for (const error of errors) {
35
+ console.error(error);
36
+ }
34
37
  throw new AggregateError(errors);
35
38
  }
36
39
  }
@@ -23,5 +23,7 @@ export type { Toolkit, ToolDefinition } from "./toolbox";
23
23
 
24
24
  export { Tools } from "../client/Tools";
25
25
 
26
+ export { Suggestions, type SuggestionConfig } from "../client/Suggestions";
27
+
26
28
  export * from "./registry";
27
29
  export * from "./frame";
@@ -28,7 +28,7 @@ const useAssistantModalOpenState = ({
28
28
  return aui.on("thread.runStart", () => {
29
29
  setOpen(true);
30
30
  });
31
- }, [unstable_openOnRunStart, setOpen, aui]);
31
+ }, [unstable_openOnRunStart, aui]);
32
32
 
33
33
  return state;
34
34
  };
@@ -8,6 +8,7 @@ export * as MessagePartPrimitive from "./messagePart";
8
8
  export * as ErrorPrimitive from "./error";
9
9
  export * as MessagePrimitive from "./message";
10
10
  export * as ThreadPrimitive from "./thread";
11
+ export * as SuggestionPrimitive from "./suggestion";
11
12
  export * as ThreadListPrimitive from "./threadList";
12
13
  export * as ThreadListItemPrimitive from "./threadListItem";
13
14
  export * as ThreadListItemMorePrimitive from "./threadListItemMore";