@assistant-ui/react 0.11.22 → 0.11.24

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 (29) hide show
  1. package/dist/client/types/Part.d.ts +2 -2
  2. package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts +2 -2
  3. package/dist/legacy-runtime/runtime/MessagePartRuntime.js.map +1 -1
  4. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts +4 -1
  5. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -1
  6. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +15 -10
  7. package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
  8. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts +1 -1
  9. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts.map +1 -1
  10. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +2 -2
  11. package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
  12. package/dist/model-context/frame/AssistantFrameProvider.js +2 -2
  13. package/dist/model-context/frame/AssistantFrameProvider.js.map +1 -1
  14. package/dist/primitives/thread/ThreadSuggestion.d.ts +35 -3
  15. package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
  16. package/dist/primitives/thread/ThreadSuggestion.js +17 -5
  17. package/dist/primitives/thread/ThreadSuggestion.js.map +1 -1
  18. package/dist/tests/setup.js +8 -8
  19. package/dist/tests/setup.js.map +1 -1
  20. package/dist/types/MessagePartTypes.d.ts +4 -1
  21. package/dist/types/MessagePartTypes.d.ts.map +1 -1
  22. package/package.json +2 -2
  23. package/src/client/types/Part.ts +2 -2
  24. package/src/legacy-runtime/runtime/MessagePartRuntime.ts +2 -2
  25. package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +17 -12
  26. package/src/legacy-runtime/runtime-cores/external-store/auto-status.tsx +4 -4
  27. package/src/model-context/frame/AssistantFrameProvider.ts +2 -2
  28. package/src/primitives/thread/ThreadSuggestion.tsx +43 -5
  29. package/src/types/MessagePartTypes.ts +1 -1
@@ -44,7 +44,10 @@ export type ToolCallMessagePart<TArgs = ReadonlyJSONObject, TResult = unknown> =
44
44
  readonly isError?: boolean | undefined;
45
45
  readonly argsText: string;
46
46
  readonly artifact?: unknown;
47
- readonly interrupt?: unknown;
47
+ readonly interrupt?: {
48
+ type: "human";
49
+ payload: unknown;
50
+ };
48
51
  readonly parentId?: string;
49
52
  };
50
53
  export type ThreadUserMessagePart = TextMessagePart | ImageMessagePart | FileMessagePart | Unstable_AudioMessagePart;
@@ -1 +1 @@
1
- {"version":3,"file":"MessagePartTypes.d.ts","sourceRoot":"","sources":["../../src/types/MessagePartTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC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0B,GAClC,eAAe,GACf,oBAAoB,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,eAAe,GACf,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.11.22",
31
+ "version": "0.11.24",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -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.32",
62
+ "assistant-stream": "^0.2.33",
63
63
  "json-schema": "^0.4.0",
64
64
  "nanoid": "5.1.6",
65
65
  "react-textarea-autosize": "^8.5.9",
@@ -27,8 +27,8 @@ export type MessagePartClientApi = {
27
27
  addToolResult(result: any | ToolResponse<any>): void;
28
28
 
29
29
  /**
30
- * Resume an interrupted tool call with a payload.
31
- * This is useful when a tool has interrupted its execution and is waiting for user input.
30
+ * Resume a tool call that is waiting for human input with a payload.
31
+ * This is useful when a tool has requested human input and is waiting for a response.
32
32
  */
33
33
  resumeToolCall(payload: unknown): void;
34
34
 
@@ -31,8 +31,8 @@ export type MessagePartRuntime = {
31
31
  addToolResult(result: any | ToolResponse<any>): void;
32
32
 
33
33
  /**
34
- * Resume an interrupted tool call with a payload.
35
- * This is useful when a tool has interrupted its execution and is waiting for user input.
34
+ * Resume a tool call that is waiting for human input with a payload.
35
+ * This is useful when a tool has requested human input and is waiting for a response.
36
36
  */
37
37
  resumeToolCall(payload: unknown): void;
38
38
 
@@ -39,7 +39,7 @@ type UseToolInvocationsParams = {
39
39
 
40
40
  export type ToolExecutionStatus =
41
41
  | { type: "executing" }
42
- | { type: "interrupt"; payload: unknown };
42
+ | { type: "interrupt"; payload: { type: "human"; payload: unknown } };
43
43
 
44
44
  export function useToolInvocations({
45
45
  state,
@@ -58,7 +58,7 @@ export function useToolInvocations({
58
58
  >
59
59
  >({});
60
60
 
61
- const interruptedToolsRef = useRef<
61
+ const humanInputRef = useRef<
62
62
  Map<
63
63
  string,
64
64
  {
@@ -76,18 +76,21 @@ export function useToolInvocations({
76
76
  () => acRef.current?.signal ?? new AbortController().signal,
77
77
  (toolCallId: string, payload: unknown) => {
78
78
  return new Promise<unknown>((resolve, reject) => {
79
- // Reject previous interrupt if it exists
80
- const previous = interruptedToolsRef.current.get(toolCallId);
79
+ // Reject previous human input request if it exists
80
+ const previous = humanInputRef.current.get(toolCallId);
81
81
  if (previous) {
82
82
  previous.reject(
83
- new Error("Interrupt was superseded by a new interrupt"),
83
+ new Error("Human input request was superseded by a new request"),
84
84
  );
85
85
  }
86
86
 
87
- interruptedToolsRef.current.set(toolCallId, { resolve, reject });
87
+ humanInputRef.current.set(toolCallId, { resolve, reject });
88
88
  setToolStatuses((prev) => ({
89
89
  ...prev,
90
- [toolCallId]: { type: "interrupt", payload },
90
+ [toolCallId]: {
91
+ type: "interrupt",
92
+ payload: { type: "human", payload },
93
+ },
91
94
  }));
92
95
  });
93
96
  },
@@ -206,10 +209,10 @@ export function useToolInvocations({
206
209
  }, [state, controller, onResult]);
207
210
 
208
211
  const abort = () => {
209
- interruptedToolsRef.current.forEach(({ reject }) => {
212
+ humanInputRef.current.forEach(({ reject }) => {
210
213
  reject(new Error("Tool execution aborted"));
211
214
  });
212
- interruptedToolsRef.current.clear();
215
+ humanInputRef.current.clear();
213
216
  setToolStatuses({});
214
217
 
215
218
  acRef.current.abort();
@@ -223,9 +226,9 @@ export function useToolInvocations({
223
226
  },
224
227
  abort,
225
228
  resume: (toolCallId: string, payload: unknown) => {
226
- const handlers = interruptedToolsRef.current.get(toolCallId);
229
+ const handlers = humanInputRef.current.get(toolCallId);
227
230
  if (handlers) {
228
- interruptedToolsRef.current.delete(toolCallId);
231
+ humanInputRef.current.delete(toolCallId);
229
232
  setToolStatuses((prev) => {
230
233
  const next = { ...prev };
231
234
  delete next[toolCallId];
@@ -233,7 +236,9 @@ export function useToolInvocations({
233
236
  });
234
237
  handlers.resolve(payload);
235
238
  } else {
236
- throw new Error(`Tool call ${toolCallId} is not interrupted`);
239
+ throw new Error(
240
+ `Tool call ${toolCallId} is not waiting for human input`,
241
+ );
237
242
  }
238
243
  },
239
244
  };
@@ -11,7 +11,7 @@ const AUTO_STATUS_PENDING = Object.freeze({
11
11
  reason: "tool-calls",
12
12
  });
13
13
 
14
- const AUTO_STATUS_SUSPENDED = Object.freeze({
14
+ const AUTO_STATUS_INTERRUPT = Object.freeze({
15
15
  type: "requires-action",
16
16
  reason: "interrupt",
17
17
  });
@@ -22,13 +22,13 @@ export const isAutoStatus = (status: MessageStatus) =>
22
22
  export const getAutoStatus = (
23
23
  isLast: boolean,
24
24
  isRunning: boolean,
25
- hasSuspendedToolCalls: boolean,
25
+ hasInterruptedToolCalls: boolean,
26
26
  hasPendingToolCalls: boolean,
27
27
  ) =>
28
28
  isLast && isRunning
29
29
  ? AUTO_STATUS_RUNNING
30
- : hasSuspendedToolCalls
31
- ? AUTO_STATUS_SUSPENDED
30
+ : hasInterruptedToolCalls
31
+ ? AUTO_STATUS_INTERRUPT
32
32
  : hasPendingToolCalls
33
33
  ? AUTO_STATUS_PENDING
34
34
  : AUTO_STATUS_COMPLETE;
@@ -133,9 +133,9 @@ export class AssistantFrameProvider {
133
133
  ? await tool.execute(message.args, {
134
134
  toolCallId: message.id,
135
135
  abortSignal: new AbortController().signal,
136
- interrupt: async () => {
136
+ human: async () => {
137
137
  throw new Error(
138
- "Tool interrupt is not supported in frame context",
138
+ "Tool human input is not supported in frame context",
139
139
  );
140
140
  },
141
141
  })
@@ -10,23 +10,61 @@ import { useAssistantState, useAssistantApi } from "../../context";
10
10
 
11
11
  const useThreadSuggestion = ({
12
12
  prompt,
13
+ send,
14
+ clearComposer = true,
13
15
  autoSend,
16
+ method: _method,
14
17
  }: {
18
+ /** The suggestion prompt. */
15
19
  prompt: string;
16
- method?: "replace";
20
+
21
+ /**
22
+ * When true, automatically sends the message.
23
+ * When false, replaces or appends the composer text with the suggestion - depending on the value of `clearComposer`.
24
+ */
25
+ send?: boolean | undefined;
26
+
27
+ /**
28
+ * Whether to clear the composer after sending.
29
+ * When send is set to false, determines if composer text is replaced with suggestion (true, default),
30
+ * or if it's appended to the composer text (false).
31
+ *
32
+ * @default true
33
+ */
34
+ clearComposer?: boolean | undefined;
35
+
36
+ /** @deprecated Use `send` instead. */
17
37
  autoSend?: boolean | undefined;
38
+
39
+ /** @deprecated Use `clearComposer` instead. */
40
+ method?: "replace";
18
41
  }) => {
19
42
  const api = useAssistantApi();
20
43
  const disabled = useAssistantState(({ thread }) => thread.isDisabled);
21
44
 
45
+ // ========== Deprecation Mapping ==========
46
+ const resolvedSend = send ?? autoSend ?? false;
47
+ // ==========================================
48
+
22
49
  const callback = useCallback(() => {
23
50
  const isRunning = api.thread().getState().isRunning;
24
- if (autoSend && !isRunning) {
51
+
52
+ if (resolvedSend && !isRunning) {
25
53
  api.thread().append(prompt);
54
+ if (clearComposer) {
55
+ api.composer().setText("");
56
+ }
26
57
  } else {
27
- api.composer().setText(prompt);
58
+ if (clearComposer) {
59
+ api.composer().setText(prompt);
60
+ } else {
61
+ const currentText = api.composer().getState().text;
62
+ api
63
+ .composer()
64
+ .setText(currentText.trim() ? `${currentText} ${prompt}` : prompt);
65
+ }
28
66
  }
29
- }, [api, autoSend, prompt]);
67
+ }, [api, resolvedSend, clearComposer, prompt]);
30
68
 
31
69
  if (disabled) return null;
32
70
  return callback;
@@ -40,5 +78,5 @@ export namespace ThreadPrimitiveSuggestion {
40
78
  export const ThreadPrimitiveSuggestion = createActionButton(
41
79
  "ThreadPrimitive.Suggestion",
42
80
  useThreadSuggestion,
43
- ["prompt", "autoSend", "method"],
81
+ ["prompt", "send", "clearComposer", "autoSend", "method"],
44
82
  );
@@ -54,7 +54,7 @@ export type ToolCallMessagePart<
54
54
  readonly isError?: boolean | undefined;
55
55
  readonly argsText: string;
56
56
  readonly artifact?: unknown;
57
- readonly interrupt?: unknown;
57
+ readonly interrupt?: { type: "human"; payload: unknown };
58
58
  readonly parentId?: string;
59
59
  };
60
60