@assistant-ui/react 0.11.5 → 0.11.6

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 (80) hide show
  1. package/dist/client/AssistantClient.d.ts.map +1 -1
  2. package/dist/client/AssistantClient.js +1 -2
  3. package/dist/client/AssistantClient.js.map +1 -1
  4. package/dist/client/ToolUIClient.d.ts +3 -2
  5. package/dist/client/ToolUIClient.d.ts.map +1 -1
  6. package/dist/client/ToolUIClient.js +1 -5
  7. package/dist/client/ToolUIClient.js.map +1 -1
  8. package/dist/context/providers/AttachmentProvider.js +3 -3
  9. package/dist/context/providers/AttachmentProvider.js.map +1 -1
  10. package/dist/context/providers/MessageProvider.js +2 -2
  11. package/dist/context/providers/MessageProvider.js.map +1 -1
  12. package/dist/context/providers/PartProvider.js +2 -2
  13. package/dist/context/providers/PartProvider.js.map +1 -1
  14. package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
  15. package/dist/context/providers/TextMessagePartProvider.js +6 -7
  16. package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
  17. package/dist/context/providers/ThreadListItemProvider.js +3 -3
  18. package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
  19. package/dist/context/react/AssistantApiContext.d.ts +1 -1
  20. package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
  21. package/dist/context/react/AssistantApiContext.js +4 -3
  22. package/dist/context/react/AssistantApiContext.js.map +1 -1
  23. package/dist/context/react/index.d.ts +1 -0
  24. package/dist/context/react/index.d.ts.map +1 -1
  25. package/dist/context/react/index.js +2 -0
  26. package/dist/context/react/index.js.map +1 -1
  27. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  28. package/dist/legacy-runtime/AssistantRuntimeProvider.js +1 -5
  29. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  30. package/dist/legacy-runtime/client/AttachmentRuntimeClient.d.ts +2 -4
  31. package/dist/legacy-runtime/client/AttachmentRuntimeClient.d.ts.map +1 -1
  32. package/dist/legacy-runtime/client/AttachmentRuntimeClient.js +10 -10
  33. package/dist/legacy-runtime/client/AttachmentRuntimeClient.js.map +1 -1
  34. package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts +3 -2
  35. package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
  36. package/dist/legacy-runtime/client/ComposerRuntimeClient.js +1 -5
  37. package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
  38. package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts +1 -1
  39. package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts.map +1 -1
  40. package/dist/legacy-runtime/client/MessagePartRuntimeClient.js +10 -10
  41. package/dist/legacy-runtime/client/MessagePartRuntimeClient.js.map +1 -1
  42. package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts +3 -3
  43. package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts.map +1 -1
  44. package/dist/legacy-runtime/client/MessageRuntimeClient.js +31 -31
  45. package/dist/legacy-runtime/client/MessageRuntimeClient.js.map +1 -1
  46. package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.d.ts +2 -2
  47. package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.d.ts.map +1 -1
  48. package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.js +17 -17
  49. package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.js.map +1 -1
  50. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts +3 -2
  51. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
  52. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +1 -5
  53. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
  54. package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts +3 -2
  55. package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
  56. package/dist/legacy-runtime/client/ThreadRuntimeClient.js +1 -5
  57. package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
  58. package/dist/utils/tap-store/tap-api.d.ts +9 -1
  59. package/dist/utils/tap-store/tap-api.d.ts.map +1 -1
  60. package/dist/utils/tap-store/tap-api.js +12 -2
  61. package/dist/utils/tap-store/tap-api.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/client/AssistantClient.ts +1 -4
  64. package/src/client/ToolUIClient.ts +1 -6
  65. package/src/context/providers/AttachmentProvider.tsx +3 -3
  66. package/src/context/providers/MessageProvider.tsx +2 -2
  67. package/src/context/providers/PartProvider.tsx +2 -2
  68. package/src/context/providers/TextMessagePartProvider.tsx +5 -7
  69. package/src/context/providers/ThreadListItemProvider.tsx +3 -3
  70. package/src/context/react/AssistantApiContext.tsx +7 -2
  71. package/src/context/react/index.ts +2 -0
  72. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +1 -15
  73. package/src/legacy-runtime/client/AttachmentRuntimeClient.ts +10 -11
  74. package/src/legacy-runtime/client/ComposerRuntimeClient.ts +1 -6
  75. package/src/legacy-runtime/client/MessagePartRuntimeClient.ts +13 -14
  76. package/src/legacy-runtime/client/MessageRuntimeClient.ts +35 -36
  77. package/src/legacy-runtime/client/ThreadListItemRuntimeClient.ts +17 -18
  78. package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +1 -6
  79. package/src/legacy-runtime/client/ThreadRuntimeClient.ts +1 -6
  80. package/src/utils/tap-store/tap-api.ts +19 -2
@@ -3,7 +3,7 @@
3
3
  import { useMemo, type FC, type PropsWithChildren } from "react";
4
4
  import {
5
5
  AssistantApi,
6
- AssistantApiProvider,
6
+ AssistantProvider,
7
7
  useAssistantApi,
8
8
  createAssistantApiField,
9
9
  } from "../react/AssistantApiContext";
@@ -24,5 +24,5 @@ export const PartByIndexProvider: FC<
24
24
  } satisfies Partial<AssistantApi>;
25
25
  }, [api, index]);
26
26
 
27
- return <AssistantApiProvider api={api2}>{children}</AssistantApiProvider>;
27
+ return <AssistantProvider api={api2}>{children}</AssistantProvider>;
28
28
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useMemo, type FC, type PropsWithChildren } from "react";
4
4
  import {
5
- AssistantApiProvider,
5
+ AssistantProvider,
6
6
  AssistantApi,
7
7
  createAssistantApiField,
8
8
  } from "../react/AssistantApiContext";
@@ -25,15 +25,13 @@ const TextMessagePartClient = resource(
25
25
  [text, isRunning],
26
26
  );
27
27
 
28
- const api = tapApi<MessagePartClientApi>({
28
+ return tapApi<MessagePartClientApi>({
29
29
  getState: () => state,
30
30
  addToolResult: () => {
31
31
  throw new Error("Not supported");
32
32
  },
33
33
  __internal_getRuntime: () => null,
34
34
  });
35
-
36
- return api;
37
35
  },
38
36
  );
39
37
 
@@ -51,12 +49,12 @@ export const TextMessagePartProvider: FC<
51
49
  part: createAssistantApiField({
52
50
  source: "root",
53
51
  query: {},
54
- get: () => store.getState(),
52
+ get: () => store.getState().api,
55
53
  }),
56
54
  subscribe: store.subscribe,
57
- // flushSync: store.flushSync,
55
+ flushSync: store.flushSync,
58
56
  } satisfies Partial<AssistantApi>;
59
57
  }, [store]);
60
58
 
61
- return <AssistantApiProvider api={api}>{children}</AssistantApiProvider>;
59
+ return <AssistantProvider api={api}>{children}</AssistantProvider>;
62
60
  };
@@ -3,7 +3,7 @@
3
3
  import { useMemo, type FC, type PropsWithChildren } from "react";
4
4
  import {
5
5
  AssistantApi,
6
- AssistantApiProvider,
6
+ AssistantProvider,
7
7
  useAssistantApi,
8
8
  createAssistantApiField,
9
9
  } from "../react/AssistantApiContext";
@@ -42,7 +42,7 @@ export const ThreadListItemByIndexProvider: FC<
42
42
  } satisfies Partial<AssistantApi>;
43
43
  }, [api, index, archived]);
44
44
 
45
- return <AssistantApiProvider api={api2}>{children}</AssistantApiProvider>;
45
+ return <AssistantProvider api={api2}>{children}</AssistantProvider>;
46
46
  };
47
47
 
48
48
  export const ThreadListItemByIdProvider: FC<
@@ -73,5 +73,5 @@ export const ThreadListItemByIdProvider: FC<
73
73
  } satisfies Partial<AssistantApi>;
74
74
  }, [api, id]);
75
75
 
76
- return <AssistantApiProvider api={api2}>{children}</AssistantApiProvider>;
76
+ return <AssistantProvider api={api2}>{children}</AssistantProvider>;
77
77
  };
@@ -43,6 +43,7 @@ import {
43
43
  ThreadListClientApi,
44
44
  ThreadListClientState,
45
45
  } from "../../client/types/ThreadList";
46
+ import { ThreadViewportProvider } from "../providers/ThreadViewportProvider";
46
47
 
47
48
  export type AssistantState = {
48
49
  readonly threads: ThreadListClientState;
@@ -280,13 +281,17 @@ const extendApi = (
280
281
  };
281
282
  };
282
283
 
283
- export const AssistantApiProvider: FC<
284
+ export const AssistantProvider: FC<
284
285
  PropsWithChildren<{ api: Partial<AssistantApi> }>
285
286
  > = ({ api: api2, children }) => {
286
287
  const api = useAssistantApi();
287
288
  const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
288
289
 
289
290
  return (
290
- <AssistantApiContext value={extendedApi}>{children}</AssistantApiContext>
291
+ <AssistantApiContext value={extendedApi}>
292
+ {/* TODO temporarily allow accessing viewport state from outside the viewport */}
293
+ {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}
294
+ <ThreadViewportProvider>{children}</ThreadViewportProvider>
295
+ </AssistantApiContext>
291
296
  );
292
297
  };
@@ -54,3 +54,5 @@ export {
54
54
  useThreadListItemRuntime,
55
55
  useThreadListItem,
56
56
  } from "../../legacy-runtime/hooks/ThreadListItemContext";
57
+
58
+ export { AssistantProvider } from "./AssistantApiContext";
@@ -1,12 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  import { FC, memo, PropsWithChildren } from "react";
4
- import { AssistantApiProvider } from "../context/react/AssistantApiContext";
4
+ import { AssistantProvider } from "../context/react/AssistantApiContext";
5
5
  import { AssistantRuntime } from "./runtime/AssistantRuntime";
6
6
  import { AssistantRuntimeCore } from "./runtime-cores/core/AssistantRuntimeCore";
7
7
  import { useAssistantClient } from "../client/AssistantClient";
8
-
9
- import { ThreadViewportProvider } from "../context/providers/ThreadViewportProvider";
10
8
  import { ThreadListClient } from "./client/ThreadListRuntimeClient";
11
9
 
12
10
  export namespace AssistantProvider {
@@ -46,15 +44,3 @@ export const AssistantRuntimeProviderImpl: FC<AssistantProvider.Props> = ({
46
44
  };
47
45
 
48
46
  export const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
49
-
50
- const AssistantProvider: FC<
51
- PropsWithChildren<{ api: ReturnType<typeof useAssistantClient> }>
52
- > = ({ children, api }) => {
53
- return (
54
- <AssistantApiProvider api={api}>
55
- {/* TODO temporarily allow accessing viewport state from outside the viewport */}
56
- {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}
57
- <ThreadViewportProvider>{children}</ThreadViewportProvider>
58
- </AssistantApiProvider>
59
- );
60
- };
@@ -7,16 +7,15 @@ import { tapSubscribable } from "../util-hooks/tapSubscribable";
7
7
  export const AttachmentRuntimeClient = resource(
8
8
  ({ runtime }: { runtime: AttachmentRuntime }) => {
9
9
  const state = tapSubscribable(runtime);
10
- const api = tapApi<AttachmentClientApi>({
11
- getState: () => state,
12
- remove: runtime.remove,
13
- __internal_getRuntime: () => runtime,
14
- });
15
-
16
- return {
17
- state: state,
18
- api,
19
- key: state.id,
20
- };
10
+ return tapApi<AttachmentClientApi>(
11
+ {
12
+ getState: () => state,
13
+ remove: runtime.remove,
14
+ __internal_getRuntime: () => runtime,
15
+ },
16
+ {
17
+ key: state.id,
18
+ },
19
+ );
21
20
  },
22
21
  );
@@ -98,7 +98,7 @@ export const ComposerClient = resource(
98
98
  };
99
99
  }, [runtimeState, attachments.state]);
100
100
 
101
- const api = tapApi<ComposerClientApi>({
101
+ return tapApi<ComposerClientApi>({
102
102
  getState: () => state,
103
103
 
104
104
  setText: runtime.setText,
@@ -126,10 +126,5 @@ export const ComposerClient = resource(
126
126
 
127
127
  __internal_getRuntime: () => runtime,
128
128
  });
129
-
130
- return {
131
- state,
132
- api,
133
- };
134
129
  },
135
130
  );
@@ -7,21 +7,20 @@ export const MessagePartClient = resource(
7
7
  ({ runtime }: { runtime: MessagePartRuntime }) => {
8
8
  const runtimeState = tapSubscribable(runtime);
9
9
 
10
- const api = tapApi<MessagePartClientApi>({
11
- getState: () => runtimeState,
10
+ return tapApi<MessagePartClientApi>(
11
+ {
12
+ getState: () => runtimeState,
12
13
 
13
- addToolResult: (result) => runtime.addToolResult(result),
14
+ addToolResult: (result) => runtime.addToolResult(result),
14
15
 
15
- __internal_getRuntime: () => runtime,
16
- });
17
-
18
- return {
19
- key:
20
- runtimeState.type === "tool-call"
21
- ? "toolCallId-" + runtimeState.toolCallId
22
- : undefined,
23
- state: runtimeState,
24
- api,
25
- };
16
+ __internal_getRuntime: () => runtime,
17
+ },
18
+ {
19
+ key:
20
+ runtimeState.type === "tool-call"
21
+ ? "toolCallId-" + runtimeState.toolCallId
22
+ : undefined,
23
+ },
24
+ );
26
25
  },
27
26
  );
@@ -99,44 +99,43 @@ export const MessageClient = resource(
99
99
  isHoveringState,
100
100
  ]);
101
101
 
102
- const api = tapApi<MessageClientApi>({
103
- getState: () => state,
104
-
105
- composer: composer.api,
106
-
107
- reload: (config) => runtime.reload(config),
108
- speak: () => runtime.speak(),
109
- stopSpeaking: () => runtime.stopSpeaking(),
110
- submitFeedback: (feedback) => runtime.submitFeedback(feedback),
111
- switchToBranch: (options) => runtime.switchToBranch(options),
112
- getCopyText: () => runtime.unstable_getCopyText(),
113
-
114
- part: (selector) => {
115
- if ("index" in selector) {
116
- return parts.api({ index: selector.index });
117
- } else {
118
- return parts.api({ key: "toolCallId-" + selector.toolCallId });
119
- }
120
- },
121
-
122
- attachment: (selector) => {
123
- if ("id" in selector) {
124
- return attachments.api({ key: selector.id });
125
- } else {
126
- return attachments.api(selector);
127
- }
128
- },
102
+ return tapApi<MessageClientApi>(
103
+ {
104
+ getState: () => state,
105
+
106
+ composer: composer.api,
107
+
108
+ reload: (config) => runtime.reload(config),
109
+ speak: () => runtime.speak(),
110
+ stopSpeaking: () => runtime.stopSpeaking(),
111
+ submitFeedback: (feedback) => runtime.submitFeedback(feedback),
112
+ switchToBranch: (options) => runtime.switchToBranch(options),
113
+ getCopyText: () => runtime.unstable_getCopyText(),
114
+
115
+ part: (selector) => {
116
+ if ("index" in selector) {
117
+ return parts.api({ index: selector.index });
118
+ } else {
119
+ return parts.api({ key: "toolCallId-" + selector.toolCallId });
120
+ }
121
+ },
129
122
 
130
- setIsCopied,
131
- setIsHovering,
123
+ attachment: (selector) => {
124
+ if ("id" in selector) {
125
+ return attachments.api({ key: selector.id });
126
+ } else {
127
+ return attachments.api(selector);
128
+ }
129
+ },
132
130
 
133
- __internal_getRuntime: () => runtime,
134
- });
131
+ setIsCopied,
132
+ setIsHovering,
135
133
 
136
- return {
137
- key: runtimeState.id,
138
- state,
139
- api,
140
- };
134
+ __internal_getRuntime: () => runtime,
135
+ },
136
+ {
137
+ key: runtimeState.id,
138
+ },
139
+ );
141
140
  },
142
141
  );
@@ -38,23 +38,22 @@ export const ThreadListItemClient = resource(
38
38
  };
39
39
  }, [runtime, events]);
40
40
 
41
- const api = tapApi<ThreadListItemClientApi>({
42
- getState: () => runtimeState,
43
- switchTo: runtime.switchTo,
44
- rename: runtime.rename,
45
- archive: runtime.archive,
46
- unarchive: runtime.unarchive,
47
- delete: runtime.delete,
48
- generateTitle: runtime.generateTitle,
49
- initialize: runtime.initialize,
50
- detach: runtime.detach,
51
- __internal_getRuntime: () => runtime,
52
- });
53
-
54
- return {
55
- state: runtimeState,
56
- api,
57
- key: runtimeState.id,
58
- };
41
+ return tapApi<ThreadListItemClientApi>(
42
+ {
43
+ getState: () => runtimeState,
44
+ switchTo: runtime.switchTo,
45
+ rename: runtime.rename,
46
+ archive: runtime.archive,
47
+ unarchive: runtime.unarchive,
48
+ delete: runtime.delete,
49
+ generateTitle: runtime.generateTitle,
50
+ initialize: runtime.initialize,
51
+ detach: runtime.detach,
52
+ __internal_getRuntime: () => runtime,
53
+ },
54
+ {
55
+ key: runtimeState.id,
56
+ },
57
+ );
59
58
  },
60
59
  );
@@ -53,7 +53,7 @@ export const ThreadListClient = resource(
53
53
  };
54
54
  }, [runtimeState, threadItems.state, main.state]);
55
55
 
56
- const api = tapApi<ThreadListClientApi>({
56
+ return tapApi<ThreadListClientApi>({
57
57
  getState: () => state,
58
58
 
59
59
  thread: () => main.api,
@@ -81,10 +81,5 @@ export const ThreadListClient = resource(
81
81
  runtime.switchToNewThread();
82
82
  },
83
83
  });
84
-
85
- return {
86
- state,
87
- api,
88
- };
89
84
  },
90
85
  );
@@ -111,7 +111,7 @@ export const ThreadClient = resource(
111
111
  };
112
112
  }, [runtimeState, messages, composer.state]);
113
113
 
114
- const api = tapApi<ThreadClientApi>({
114
+ return tapApi<ThreadClientApi>({
115
115
  getState: () => state,
116
116
 
117
117
  composer: composer.api,
@@ -136,10 +136,5 @@ export const ThreadClient = resource(
136
136
 
137
137
  __internal_getRuntime: () => runtime,
138
138
  });
139
-
140
- return {
141
- state,
142
- api,
143
- };
144
139
  },
145
140
  );
@@ -34,15 +34,32 @@ class ReadonlyApiHandler<TApi extends ApiObject> implements ProxyHandler<TApi> {
34
34
  }
35
35
  }
36
36
 
37
- export const tapApi = <TApi extends ApiObject>(api: TApi) => {
37
+ export const tapApi = <TApi extends ApiObject & { getState: () => any }>(
38
+ api: TApi,
39
+ options?: {
40
+ key?: string | undefined;
41
+ },
42
+ ) => {
38
43
  const ref = tapRef(() => api);
39
44
  tapEffect(() => {
40
45
  ref.current = api;
41
46
  });
42
47
 
43
- return tapMemo(
48
+ const apiProxy = tapMemo(
44
49
  () =>
45
50
  new Proxy<TApi>({} as TApi, new ReadonlyApiHandler(() => ref.current)),
46
51
  [],
47
52
  );
53
+
54
+ const key = options?.key;
55
+ const state = api.getState();
56
+
57
+ return tapMemo(
58
+ () => ({
59
+ key,
60
+ state,
61
+ api: apiProxy,
62
+ }),
63
+ [state, key],
64
+ );
48
65
  };