@assistant-ui/react 0.11.23 → 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.
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.11.23",
31
+ "version": "0.11.24",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -87,7 +87,10 @@ export function useToolInvocations({
87
87
  humanInputRef.current.set(toolCallId, { resolve, reject });
88
88
  setToolStatuses((prev) => ({
89
89
  ...prev,
90
- [toolCallId]: { type: "interrupt", payload: { type: "human", payload } },
90
+ [toolCallId]: {
91
+ type: "interrupt",
92
+ payload: { type: "human", payload },
93
+ },
91
94
  }));
92
95
  });
93
96
  },
@@ -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 waiting for human input`);
239
+ throw new Error(
240
+ `Tool call ${toolCallId} is not waiting for human input`,
241
+ );
237
242
  }
238
243
  },
239
244
  };
@@ -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
  );