@assistant-ui/react 0.11.19 → 0.11.21

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 (61) hide show
  1. package/dist/augmentations.d.ts +12 -0
  2. package/dist/augmentations.d.ts.map +1 -0
  3. package/dist/augmentations.js +1 -0
  4. package/dist/augmentations.js.map +1 -0
  5. package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts +1 -1
  6. package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
  7. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts +1 -1
  8. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts.map +1 -1
  9. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js +6 -2
  10. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js.map +1 -1
  11. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +2 -1
  12. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
  13. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts +2 -1
  14. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  15. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +25 -1
  16. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  17. package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +1 -0
  18. package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
  19. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  20. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +6 -0
  21. package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  22. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts +1 -0
  23. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  24. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js +1 -0
  25. package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js.map +1 -1
  26. package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts +1 -1
  27. package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts.map +1 -1
  28. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
  29. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +1 -0
  30. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
  31. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  32. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.js +1 -3
  33. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
  34. package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts +3 -3
  35. package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts.map +1 -1
  36. package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js.map +1 -1
  37. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts +2 -2
  38. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
  39. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
  40. package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
  41. package/dist/primitives/branchPicker/BranchPickerNext.js +7 -3
  42. package/dist/primitives/branchPicker/BranchPickerNext.js.map +1 -1
  43. package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
  44. package/dist/primitives/branchPicker/BranchPickerPrevious.js +7 -3
  45. package/dist/primitives/branchPicker/BranchPickerPrevious.js.map +1 -1
  46. package/dist/tests/setup.js +8 -8
  47. package/dist/tests/setup.js.map +1 -1
  48. package/package.json +9 -9
  49. package/src/augmentations.ts +26 -0
  50. package/src/legacy-runtime/runtime-cores/assistant-transport/index.ts +4 -1
  51. package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +3 -1
  52. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +39 -0
  53. package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +1 -0
  54. package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +7 -0
  55. package/src/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.tsx +1 -0
  56. package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +1 -0
  57. package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +1 -4
  58. package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx +3 -3
  59. package/src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx +2 -1
  60. package/src/primitives/branchPicker/BranchPickerNext.tsx +11 -3
  61. package/src/primitives/branchPicker/BranchPickerPrevious.tsx +11 -3
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.11.19",
31
+ "version": "0.11.21",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -61,10 +61,10 @@
61
61
  "@standard-schema/spec": "^1.0.0",
62
62
  "assistant-stream": "^0.2.29",
63
63
  "json-schema": "^0.4.0",
64
- "nanoid": "5.1.5",
64
+ "nanoid": "5.1.6",
65
65
  "react-textarea-autosize": "^8.5.9",
66
- "zod": "^4.0.17",
67
- "zustand": "^5.0.7"
66
+ "zod": "^4.1.11",
67
+ "zustand": "^5.0.8"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@types/react": "*",
@@ -81,13 +81,13 @@
81
81
  }
82
82
  },
83
83
  "devDependencies": {
84
- "@stryker-mutator/core": "^9.0.1",
85
- "@stryker-mutator/vitest-runner": "^9.0.1",
84
+ "@stryker-mutator/core": "^9.1.1",
85
+ "@stryker-mutator/vitest-runner": "^9.1.1",
86
86
  "@types/json-schema": "^7.0.15",
87
- "@types/node": "^24.3.0",
87
+ "@types/node": "^24.5.2",
88
88
  "eslint": "^9",
89
- "eslint-config-next": "15.4.6",
90
- "tsx": "^4.20.4",
89
+ "eslint-config-next": "15.5.4",
90
+ "tsx": "^4.20.6",
91
91
  "vitest": "^3.2.4",
92
92
  "@assistant-ui/x-buildutils": "0.0.1"
93
93
  },
@@ -0,0 +1,26 @@
1
+ declare global {
2
+ interface Assistant {
3
+ Commands: unknown;
4
+ }
5
+ }
6
+
7
+ type GetAugmentation<
8
+ Key extends keyof Assistant,
9
+ ExpectedType,
10
+ FallbackType = ExpectedType,
11
+ > = unknown extends Assistant[Key]
12
+ ? FallbackType
13
+ : Assistant[Key] extends ExpectedType
14
+ ? Assistant[Key]
15
+ : {
16
+ ErrorMessage: `There is an error in the type you provided for Assistant.${Key}`;
17
+ };
18
+
19
+ type UserCommandsRecord = GetAugmentation<
20
+ "Commands",
21
+ Record<string, unknown>,
22
+ Record<string, never>
23
+ >;
24
+
25
+ export type UserCommands =
26
+ UserCommandsRecord extends Record<string, infer V> ? V : never;
@@ -1,4 +1,7 @@
1
- export { useAssistantTransportRuntime } from "./useAssistantTransportRuntime";
1
+ export {
2
+ useAssistantTransportRuntime,
3
+ useAssistantTransportSendCommand,
4
+ } from "./useAssistantTransportRuntime";
2
5
  export type {
3
6
  AssistantTransportConnectionMetadata,
4
7
  AssistantTransportCommand,
@@ -1,6 +1,7 @@
1
1
  import { ReadonlyJSONValue } from "assistant-stream/utils";
2
2
  import { ThreadMessage } from "../../../types";
3
3
  import { AttachmentAdapter, ThreadHistoryAdapter } from "..";
4
+ import { UserCommands } from "../../../augmentations";
4
5
 
5
6
  // Message part types
6
7
  export type TextPart = {
@@ -42,7 +43,8 @@ export type AddToolResultCommand = {
42
43
 
43
44
  export type AssistantTransportCommand =
44
45
  | AddMessageCommand
45
- | AddToolResultCommand;
46
+ | AddToolResultCommand
47
+ | UserCommands;
46
48
 
47
49
  // State types
48
50
  export type AssistantTransportState = {
@@ -21,6 +21,7 @@ import {
21
21
  AddToolResultCommand,
22
22
  UserMessagePart,
23
23
  QueuedCommand,
24
+ AssistantTransportCommand,
24
25
  } from "./types";
25
26
  import { useCommandQueue } from "./commandQueue";
26
27
  import { useRunManager } from "./runManager";
@@ -29,6 +30,38 @@ import { useToolInvocations } from "./useToolInvocations";
29
30
  import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils";
30
31
  import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime";
31
32
  import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory";
33
+ import { useAssistantApi } from "../../../context/react";
34
+
35
+ const symbolAssistantTransportExtras = Symbol("assistant-transport-extras");
36
+ type AssistantTransportExtras = {
37
+ [symbolAssistantTransportExtras]: true;
38
+ sendCommand: (command: AssistantTransportCommand) => void;
39
+ };
40
+
41
+ const asAssistantTransportExtras = (
42
+ extras: unknown,
43
+ ): AssistantTransportExtras => {
44
+ if (
45
+ typeof extras !== "object" ||
46
+ extras == null ||
47
+ !(symbolAssistantTransportExtras in extras)
48
+ )
49
+ throw new Error(
50
+ "This method can only be called when you are using useAssistantTransportRuntime",
51
+ );
52
+
53
+ return extras as AssistantTransportExtras;
54
+ };
55
+
56
+ export const useAssistantTransportSendCommand = () => {
57
+ const api = useAssistantApi();
58
+
59
+ return (command: AssistantTransportCommand) => {
60
+ const extras = api.thread().getState().extras;
61
+ const transportExtras = asAssistantTransportExtras(extras);
62
+ transportExtras.sendCommand(command);
63
+ };
64
+ };
32
65
 
33
66
  const useAssistantTransportThreadRuntime = <T,>(
34
67
  options: AssistantTransportOptions<T>,
@@ -162,6 +195,12 @@ const useAssistantTransportThreadRuntime = <T,>(
162
195
  state: converted.state,
163
196
  isRunning: converted.isRunning,
164
197
  adapters: options.adapters,
198
+ extras: {
199
+ [symbolAssistantTransportExtras]: true,
200
+ sendCommand: (command: AssistantTransportCommand) => {
201
+ commandQueue.enqueue(command);
202
+ },
203
+ } satisfies AssistantTransportExtras,
165
204
  onNew: async (message: AppendMessage): Promise<void> => {
166
205
  if (message.role !== "user")
167
206
  throw new Error("Only user messages are supported");
@@ -14,6 +14,7 @@ import {
14
14
 
15
15
  export type RuntimeCapabilities = {
16
16
  readonly switchToBranch: boolean;
17
+ readonly switchBranchDuringRun: boolean;
17
18
  readonly edit: boolean;
18
19
  readonly reload: boolean;
19
20
  readonly cancel: boolean;
@@ -43,6 +43,7 @@ export class ExternalStoreThreadRuntimeCore
43
43
 
44
44
  private _capabilities: RuntimeCapabilities = {
45
45
  switchToBranch: false,
46
+ switchBranchDuringRun: false,
46
47
  edit: false,
47
48
  reload: false,
48
49
  cancel: false,
@@ -108,6 +109,7 @@ export class ExternalStoreThreadRuntimeCore
108
109
  this.suggestions = store.suggestions ?? EMPTY_ARRAY;
109
110
  this._capabilities = {
110
111
  switchToBranch: this._store.setMessages !== undefined,
112
+ switchBranchDuringRun: false, // External store never supports branch switching during run
111
113
  edit: this._store.onEdit !== undefined,
112
114
  reload: this._store.onReload !== undefined,
113
115
  cancel: this._store.onCancel !== undefined,
@@ -228,6 +230,11 @@ export class ExternalStoreThreadRuntimeCore
228
230
  if (!this._store.setMessages)
229
231
  throw new Error("Runtime does not support switching branches.");
230
232
 
233
+ // Silently ignore branch switches while running
234
+ if (this._store.isRunning) {
235
+ return;
236
+ }
237
+
231
238
  this.repository.switchToBranch(branchId);
232
239
  this.updateMessages(this.repository.getMessages());
233
240
  }
@@ -30,6 +30,7 @@ export class LocalThreadRuntimeCore
30
30
  {
31
31
  public readonly capabilities = {
32
32
  switchToBranch: true,
33
+ switchBranchDuringRun: true,
33
34
  edit: true,
34
35
  reload: true,
35
36
  cancel: true,
@@ -132,6 +132,7 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
132
132
 
133
133
  capabilities: {
134
134
  switchToBranch: false,
135
+ switchBranchDuringRun: false,
135
136
  edit: false,
136
137
  reload: false,
137
138
  cancel: false,
@@ -90,10 +90,7 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
90
90
  throw new Error("Thread not found. This is a bug in assistant-ui.");
91
91
 
92
92
  aliveThread.runtime = threadBinding.getState();
93
-
94
- if (isMounted) {
95
- this._notifySubscribers();
96
- }
93
+ this._notifySubscribers();
97
94
  }, [threadId, threadBinding]);
98
95
 
99
96
  const isMounted = useRef(false);
@@ -16,14 +16,14 @@ import { InMemoryThreadListAdapter } from "./in-memory";
16
16
  import { CloudFileAttachmentAdapter } from "../../adapters";
17
17
 
18
18
  type ThreadData = {
19
- externalId: string;
19
+ externalId: string | undefined;
20
20
  };
21
21
 
22
22
  type CloudThreadListAdapterOptions = {
23
23
  cloud?: AssistantCloud | undefined;
24
24
 
25
- create?(): Promise<ThreadData>;
26
- delete?(threadId: string): Promise<void>;
25
+ create?: (() => Promise<ThreadData>) | undefined;
26
+ delete?: ((threadId: string) => Promise<void>) | undefined;
27
27
  };
28
28
 
29
29
  const baseUrl =
@@ -6,6 +6,7 @@ import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadL
6
6
  import { RemoteThreadListOptions } from "./types";
7
7
  import { AssistantRuntimeImpl } from "../../../internal";
8
8
  import { AssistantRuntimeCore } from "../core/AssistantRuntimeCore";
9
+ import { AssistantRuntime } from "../../runtime/AssistantRuntime";
9
10
 
10
11
  class RemoteThreadListRuntimeCore
11
12
  extends BaseAssistantRuntimeCore
@@ -28,7 +29,7 @@ class RemoteThreadListRuntimeCore
28
29
 
29
30
  export const useRemoteThreadListRuntime = (
30
31
  options: RemoteThreadListOptions,
31
- ) => {
32
+ ): AssistantRuntime => {
32
33
  const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
33
34
  useEffect(() => {
34
35
  runtime.threads.__internal_setOptions(options);
@@ -10,9 +10,17 @@ import { useAssistantState, useAssistantApi } from "../../context";
10
10
 
11
11
  const useBranchPickerNext = () => {
12
12
  const api = useAssistantApi();
13
- const disabled = useAssistantState(
14
- ({ message }) => message.branchNumber >= message.branchCount,
15
- );
13
+ const disabled = useAssistantState(({ thread, message }) => {
14
+ // Disabled if no next branch
15
+ if (message.branchNumber >= message.branchCount) return true;
16
+
17
+ // Disabled if running and capability not supported
18
+ if (thread.isRunning && !thread.capabilities.switchBranchDuringRun) {
19
+ return true;
20
+ }
21
+
22
+ return false;
23
+ });
16
24
 
17
25
  const callback = useCallback(() => {
18
26
  api.message().switchToBranch({ position: "next" });
@@ -31,9 +31,17 @@ import { useAssistantState, useAssistantApi } from "../../context";
31
31
  */
32
32
  const useBranchPickerPrevious = () => {
33
33
  const api = useAssistantApi();
34
- const disabled = useAssistantState(
35
- ({ message }) => message.branchNumber <= 1,
36
- );
34
+ const disabled = useAssistantState(({ thread, message }) => {
35
+ // Disabled if no previous branch
36
+ if (message.branchNumber <= 1) return true;
37
+
38
+ // Disabled if running and capability not supported
39
+ if (thread.isRunning && !thread.capabilities.switchBranchDuringRun) {
40
+ return true;
41
+ }
42
+
43
+ return false;
44
+ });
37
45
 
38
46
  const callback = useCallback(() => {
39
47
  api.message().switchToBranch({ position: "previous" });