@assistant-ui/react 0.11.33 → 0.11.35

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 (49) hide show
  1. package/dist/augmentations.d.ts +9 -0
  2. package/dist/augmentations.d.ts.map +1 -1
  3. package/dist/client/ThreadMessageClient.d.ts.map +1 -1
  4. package/dist/client/ThreadMessageClient.js +1 -1
  5. package/dist/client/ThreadMessageClient.js.map +1 -1
  6. package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +0 -1
  7. package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
  8. package/dist/legacy-runtime/runtime/ThreadRuntime.js +1 -1
  9. package/dist/legacy-runtime/runtime/ThreadRuntime.js.map +1 -1
  10. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts +2 -2
  11. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts.map +1 -1
  12. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js +4 -2
  13. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js.map +1 -1
  14. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +2 -0
  15. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
  16. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts +3 -0
  17. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  18. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +14 -4
  19. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  20. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts +0 -5
  21. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts.map +1 -1
  22. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.js +0 -7
  23. package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.js.map +1 -1
  24. package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +0 -1
  25. package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
  26. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  27. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +3 -0
  28. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  29. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
  30. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +0 -3
  31. package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
  32. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +0 -2
  33. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  34. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +0 -2
  35. package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  36. package/dist/tests/setup.js +202 -469
  37. package/dist/tests/setup.js.map +1 -1
  38. package/package.json +7 -7
  39. package/src/augmentations.ts +12 -0
  40. package/src/client/ThreadMessageClient.tsx +1 -4
  41. package/src/legacy-runtime/runtime/ThreadRuntime.ts +1 -4
  42. package/src/legacy-runtime/runtime-cores/assistant-transport/index.ts +2 -0
  43. package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +3 -0
  44. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +35 -14
  45. package/src/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.tsx +0 -8
  46. package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +0 -1
  47. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +5 -0
  48. package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +0 -4
  49. package/src/tests/setup.ts +2 -8
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.11.33",
31
+ "version": "0.11.35",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -48,8 +48,8 @@
48
48
  ],
49
49
  "sideEffects": false,
50
50
  "dependencies": {
51
- "assistant-cloud": "^0.1.4",
52
- "@assistant-ui/tap": "^0.1.3",
51
+ "assistant-cloud": "^0.1.5",
52
+ "@assistant-ui/tap": "^0.1.4",
53
53
  "@radix-ui/primitive": "^1.1.3",
54
54
  "@radix-ui/react-compose-refs": "^1.1.2",
55
55
  "@radix-ui/react-context": "^1.1.2",
@@ -59,7 +59,7 @@
59
59
  "@radix-ui/react-use-callback-ref": "^1.1.1",
60
60
  "@radix-ui/react-use-escape-keydown": "^1.1.1",
61
61
  "@standard-schema/spec": "^1.0.0",
62
- "assistant-stream": "^0.2.36",
62
+ "assistant-stream": "^0.2.38",
63
63
  "json-schema": "^0.4.0",
64
64
  "nanoid": "5.1.6",
65
65
  "react-textarea-autosize": "^8.5.9",
@@ -84,11 +84,11 @@
84
84
  "@stryker-mutator/core": "^9.2.0",
85
85
  "@stryker-mutator/vitest-runner": "^9.2.0",
86
86
  "@types/json-schema": "^7.0.15",
87
- "@types/node": "^24.8.1",
87
+ "@types/node": "^24.9.1",
88
88
  "eslint": "^9",
89
- "eslint-config-next": "15.5.6",
89
+ "eslint-config-next": "16.0.0",
90
90
  "tsx": "^4.20.6",
91
- "vitest": "^3.2.4",
91
+ "vitest": "^4.0.1",
92
92
  "@assistant-ui/x-buildutils": "0.0.1"
93
93
  },
94
94
  "publishConfig": {
@@ -11,6 +11,12 @@
11
11
  * data: string;
12
12
  * };
13
13
  * }
14
+ *
15
+ * interface ExternalState {
16
+ * myCustomState: {
17
+ * foo: string;
18
+ * };
19
+ * }
14
20
  * }
15
21
  * }
16
22
  * ```
@@ -18,6 +24,12 @@
18
24
  export namespace Assistant {
19
25
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
20
26
  export interface Commands {}
27
+
28
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
29
+ export interface ExternalState {}
21
30
  }
22
31
 
23
32
  export type UserCommands = Assistant.Commands[keyof Assistant.Commands];
33
+ export type UserExternalState = keyof Assistant.ExternalState extends never
34
+ ? Record<string, unknown>
35
+ : Assistant.ExternalState[keyof Assistant.ExternalState];
@@ -106,10 +106,7 @@ export const ThreadMessageClient = resource(
106
106
  branchNumber,
107
107
  branchCount,
108
108
  speech: undefined,
109
- submittedFeedback:
110
- message.role === "assistant"
111
- ? message.metadata.submittedFeedback
112
- : undefined,
109
+ submittedFeedback: message.metadata.submittedFeedback,
113
110
  isCopied: isCopiedState,
114
111
  isHovering: isHoveringState,
115
112
  };
@@ -485,10 +485,7 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
485
485
  const thread = this._threadBinding.getState();
486
486
 
487
487
  const branches = thread.getBranches(message.id);
488
- const submittedFeedback =
489
- message.role === "assistant"
490
- ? message.metadata.submittedFeedback
491
- : undefined;
488
+ const submittedFeedback = message.metadata.submittedFeedback;
492
489
 
493
490
  return {
494
491
  ...message,
@@ -1,8 +1,10 @@
1
1
  export {
2
2
  useAssistantTransportRuntime,
3
3
  useAssistantTransportSendCommand,
4
+ useAssistantTransportState,
4
5
  } from "./useAssistantTransportRuntime";
5
6
  export type {
6
7
  AssistantTransportConnectionMetadata,
7
8
  AssistantTransportCommand,
9
+ AssistantTransportProtocol,
8
10
  } from "./types";
@@ -79,10 +79,13 @@ export type QueuedCommand = AssistantTransportCommand;
79
79
  // Options types
80
80
  export type HeadersValue = Record<string, string> | Headers;
81
81
 
82
+ export type AssistantTransportProtocol = "data-stream" | "assistant-transport";
83
+
82
84
  export type AssistantTransportOptions<T> = {
83
85
  initialState: T;
84
86
  api: string;
85
87
  resumeApi?: string;
88
+ protocol?: AssistantTransportProtocol;
86
89
  converter: AssistantTransportStateConverter<T>;
87
90
  headers: HeadersValue | (() => Promise<HeadersValue>);
88
91
  body?: object;
@@ -13,6 +13,7 @@ import { useState, useRef, useMemo } from "react";
13
13
  import {
14
14
  AssistantMessageAccumulator,
15
15
  DataStreamDecoder,
16
+ AssistantTransportDecoder,
16
17
  unstable_createInitialMessage as createInitialMessage,
17
18
  } from "assistant-stream";
18
19
  import {
@@ -30,12 +31,14 @@ import { ToolExecutionStatus, useToolInvocations } from "./useToolInvocations";
30
31
  import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils";
31
32
  import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime";
32
33
  import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory";
33
- import { useAssistantApi } from "../../../context/react";
34
+ import { useAssistantApi, useAssistantState } from "../../../context/react";
35
+ import { UserExternalState } from "../../../augmentations";
34
36
 
35
37
  const symbolAssistantTransportExtras = Symbol("assistant-transport-extras");
36
38
  type AssistantTransportExtras = {
37
39
  [symbolAssistantTransportExtras]: true;
38
40
  sendCommand: (command: AssistantTransportCommand) => void;
41
+ state: UserExternalState;
39
42
  };
40
43
 
41
44
  const asAssistantTransportExtras = (
@@ -63,6 +66,18 @@ export const useAssistantTransportSendCommand = () => {
63
66
  };
64
67
  };
65
68
 
69
+ export function useAssistantTransportState(): UserExternalState;
70
+ export function useAssistantTransportState<T>(
71
+ selector: (state: UserExternalState) => T,
72
+ ): T;
73
+ export function useAssistantTransportState<T>(
74
+ selector: (state: UserExternalState) => T = (t) => t as T,
75
+ ): T | UserExternalState {
76
+ return useAssistantState(({ thread }) =>
77
+ selector(asAssistantTransportExtras(thread.extras).state),
78
+ );
79
+ }
80
+
66
81
  const useAssistantTransportThreadRuntime = <T,>(
67
82
  options: AssistantTransportOptions<T>,
68
83
  ): AssistantRuntime => {
@@ -114,21 +129,26 @@ const useAssistantTransportThreadRuntime = <T,>(
114
129
  throw new Error("Response body is null");
115
130
  }
116
131
 
132
+ // Select decoder based on protocol option
133
+ const protocol = options.protocol ?? "data-stream";
134
+ const decoder =
135
+ protocol === "assistant-transport"
136
+ ? new AssistantTransportDecoder()
137
+ : new DataStreamDecoder();
138
+
117
139
  let err: string | undefined;
118
- const stream = response.body
119
- .pipeThrough(new DataStreamDecoder())
120
- .pipeThrough(
121
- new AssistantMessageAccumulator({
122
- initialMessage: createInitialMessage({
123
- unstable_state:
124
- (agentStateRef.current as ReadonlyJSONValue) ?? null,
125
- }),
126
- throttle: isResume,
127
- onError: (error) => {
128
- err = error;
129
- },
140
+ const stream = response.body.pipeThrough(decoder).pipeThrough(
141
+ new AssistantMessageAccumulator({
142
+ initialMessage: createInitialMessage({
143
+ unstable_state:
144
+ (agentStateRef.current as ReadonlyJSONValue) ?? null,
130
145
  }),
131
- );
146
+ throttle: isResume,
147
+ onError: (error) => {
148
+ err = error;
149
+ },
150
+ }),
151
+ );
132
152
 
133
153
  let markedDelivered = false;
134
154
 
@@ -206,6 +226,7 @@ const useAssistantTransportThreadRuntime = <T,>(
206
226
  sendCommand: (command: AssistantTransportCommand) => {
207
227
  commandQueue.enqueue(command);
208
228
  },
229
+ state: agentStateRef.current as UserExternalState,
209
230
  } satisfies AssistantTransportExtras,
210
231
  onNew: async (message: AppendMessage): Promise<void> => {
211
232
  if (message.role !== "user")
@@ -126,14 +126,6 @@ export abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {
126
126
  return () => this._subscriptions.delete(callback);
127
127
  }
128
128
 
129
- public getSubmittedFeedback(messageId: string) {
130
- const messageData = this.repository.getMessage(messageId);
131
- if (messageData.message.role === "assistant") {
132
- return messageData.message.metadata.submittedFeedback;
133
- }
134
- return undefined;
135
- }
136
-
137
129
  public submitFeedback({ messageId, type }: SubmitFeedbackOptions) {
138
130
  const adapter = this.adapters?.feedback;
139
131
  if (!adapter) throw new Error("Feedback adapter not configured");
@@ -96,7 +96,6 @@ export type ThreadRuntimeCore = Readonly<{
96
96
  speak: (messageId: string) => void;
97
97
  stopSpeaking: () => void;
98
98
 
99
- getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;
100
99
  submitFeedback: (feedback: SubmitFeedbackOptions) => void;
101
100
 
102
101
  getModelContext: () => ModelContext;
@@ -155,6 +155,11 @@ const joinExternalMessages = (
155
155
  ...output.metadata.custom,
156
156
  };
157
157
  }
158
+
159
+ if (output.metadata.submittedFeedback) {
160
+ assistantMessage.metadata.submittedFeedback =
161
+ output.metadata.submittedFeedback;
162
+ }
158
163
  }
159
164
  // TODO keep this in sync
160
165
  }
@@ -48,10 +48,6 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
48
48
  throw EMPTY_THREAD_ERROR;
49
49
  },
50
50
 
51
- getSubmittedFeedback() {
52
- return undefined;
53
- },
54
-
55
51
  submitFeedback() {
56
52
  throw EMPTY_THREAD_ERROR;
57
53
  },
@@ -1,11 +1,5 @@
1
1
  // This file contains setup code for tests
2
2
  import { vi } from "vitest";
3
3
 
4
- // Set up global mocks if needed
5
- // Using a fixed date to avoid recursive calls
6
- const OriginalDate = global.Date;
7
- const fixedDate = new OriginalDate("2023-01-01");
8
- global.Date = vi.fn(() => fixedDate) as any;
9
- global.Date.now = vi.fn(() => fixedDate.getTime());
10
-
11
- // Add any other global setup needed for tests
4
+ // Use Vitest's built-in to mock Date
5
+ vi.setSystemTime(new Date("2023-01-01"));