@blocksdiy/react-common 1.23.0 → 1.24.0

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.
@@ -7,6 +7,15 @@ export interface Attachment {
7
7
  fileType: string;
8
8
  fileName: string;
9
9
  }
10
+ export interface AgentChatComponent {
11
+ id: string;
12
+ name: string;
13
+ toolName?: string;
14
+ code?: string;
15
+ input?: Record<string, unknown>;
16
+ description?: string;
17
+ }
18
+ export declare const getAgentChatComponentToolName: (name: string) => string;
10
19
  export interface AgentChat {
11
20
  initialPrompt?: {
12
21
  content?: string;
@@ -34,8 +43,10 @@ export interface AgentChatContextValue {
34
43
  currentThreadId?: string;
35
44
  agent: Agent | null;
36
45
  agentChat: AgentChat | null;
46
+ components: AgentChatComponent[];
37
47
  sendMessage: (message: Omit<UserMessage, "id" | "role">) => Promise<void>;
38
48
  sendFromInputs: () => Promise<void>;
49
+ stopGeneration: () => void;
39
50
  addAttachments: (attachments: Attachment[]) => void;
40
51
  removeAttachment: (url: string) => void;
41
52
  clearAttachments: () => void;
@@ -56,6 +67,7 @@ export interface AgentChatRootProps {
56
67
  /** When true with `agentId`, route direct Deep Agent chat through the AI SDK UI-message stream. */
57
68
  useAgentBlockDirectChat?: boolean;
58
69
  agentChatId?: string;
70
+ componentIds?: string[];
59
71
  defaultThreadId?: string;
60
72
  noPersistency?: boolean;
61
73
  children?: ReactNode;
@@ -63,7 +75,7 @@ export interface AgentChatRootProps {
63
75
  chatContext?: any;
64
76
  chatContextFiles?: Attachment[];
65
77
  }
66
- export declare const AgentChatRoot: ({ ...props }: AgentChatRootProps) => import("react/jsx-runtime").JSX.Element;
78
+ export declare const AgentChatRoot: ({ ...props }: AgentChatRootProps) => import("react/jsx-runtime").JSX.Element | null;
67
79
  export interface AgentChatMessageProps {
68
80
  message: Message;
69
81
  index: number;
@@ -1 +1 @@
1
- {"version":3,"file":"new-agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/new-agent-chat.tsx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G,+BAA+B,2CAsDlE;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EACV,OAAe,EACf,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,wBAAwB,2CAIxD;AAED,MAAM,WAAW,8BAA8B;IAC7C,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,yBAAyB,CAAC,EACxC,UAAU,EACV,OAAe,EACf,OAAO,EACP,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,8BAA8B,2CAcjE"}
@@ -9,6 +9,9 @@ export { useRenderTool, useRenderToolCall, useDefaultRenderTool, useHumanInTheLo
9
9
  // Needed so the `agent.threadId` mirror commits before CopilotKit's
10
10
  // connect-on-mount effect reads it.
11
11
  const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
12
+ export const getAgentChatComponentToolName = (name) => {
13
+ return name.replace(/[^a-zA-Z0-9_-]/g, "_").toLowerCase();
14
+ };
12
15
  const MAX_FILE_SIZE_MB = 5;
13
16
  const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
14
17
  // CopilotKit v2 requires a UUID `thread_id`; non-UUIDs get replaced per
@@ -84,16 +87,17 @@ const SessionReadables = () => {
84
87
  // });
85
88
  return null;
86
89
  };
87
- const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentThreadId, setCurrentThreadId, children, }) => {
90
+ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, componentIds, currentThreadId, setCurrentThreadId, children, }) => {
88
91
  const [agentChat, setAgentChat] = useState(null);
89
92
  const [agent, setAgent] = useState(null);
93
+ const [components, setComponents] = useState([]);
90
94
  // `isConfigLoaded` covers the (small, parallel) async fetch of the
91
95
  // agent + agentChat block configs. The actual chat transcript loads
92
96
  // through CopilotKit's `connectAgent` pipeline, which surfaces via
93
97
  // `isAvailable` below — see `isFetchingMessages` for the combined
94
98
  // "are we still warming up" signal exposed to consumers.
95
99
  const [isConfigLoaded, setIsConfigLoaded] = useState(false);
96
- const { messages: copilotMessages, sendMessage: copilotSendMessage, isAvailable: isAgentReady, isLoading: isAgentRunning, agent: copilotAgent, } = useCopilotChatInternal();
100
+ const { messages: copilotMessages, sendMessage: copilotSendMessage, stopGeneration: copilotStopGeneration, isAvailable: isAgentReady, isLoading: isAgentRunning, agent: copilotAgent, } = useCopilotChatInternal();
97
101
  // Mirror `currentThreadId` onto the agent instance — the `<CopilotKit>`
98
102
  // prop only feeds React context, but `agent.threadId` is what hits the
99
103
  // wire and the LangGraph checkpoint. `<CopilotChat>` does this for you;
@@ -110,9 +114,17 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
110
114
  const [attachments, setAttachments] = useState([]);
111
115
  const [isDraggingFiles, setIsDraggingFiles] = useState(false);
112
116
  const blocksApiService = useMemo(() => new BlocksApiService({ token }), [token]);
117
+ const canSendMessage = Boolean(agentChatId && agentChat && agent && isConfigLoaded && isAgentReady && !isAgentRunning);
113
118
  const sendMessage = useCallback((message) => {
119
+ if (!canSendMessage) {
120
+ return Promise.resolve();
121
+ }
114
122
  return copilotSendMessage({ id: generateId(), role: "user", ...message });
115
- }, [copilotSendMessage]);
123
+ }, [canSendMessage, copilotSendMessage]);
124
+ const stopGeneration = useCallback(() => {
125
+ copilotStopGeneration();
126
+ copilotAgent?.abortRun?.();
127
+ }, [copilotAgent, copilotStopGeneration]);
116
128
  const getAgentChatBlock = useCallback(async () => {
117
129
  if (!agentChatId) {
118
130
  return null;
@@ -123,6 +135,33 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
123
135
  }
124
136
  return agentChatBlock;
125
137
  }, [agentChatId, blocksApiService]);
138
+ const getChatComponentBlocks = useCallback(async () => {
139
+ if (!componentIds?.length) {
140
+ return [];
141
+ }
142
+ const maybeComponentBlocks = await Promise.all(componentIds.map(async (componentId) => {
143
+ try {
144
+ const block = await blocksApiService.getBlock(componentId);
145
+ const id = block?.id ?? componentId;
146
+ const name = block?.name;
147
+ if (!id || !name) {
148
+ return null;
149
+ }
150
+ return {
151
+ id,
152
+ name,
153
+ code: block?.data?.code,
154
+ input: block?.data?.input,
155
+ description: block?.data?.description,
156
+ toolName: getAgentChatComponentToolName(name),
157
+ };
158
+ }
159
+ catch {
160
+ return null;
161
+ }
162
+ }));
163
+ return maybeComponentBlocks.filter((component) => Boolean(component));
164
+ }, [blocksApiService, componentIds]);
126
165
  const sendAgentInitialPrompt = useCallback((agentInitialPrompt) => {
127
166
  if (!agentInitialPrompt) {
128
167
  return;
@@ -146,6 +185,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
146
185
  currentThreadId ?? "",
147
186
  agentId ?? "",
148
187
  agentChatId ?? "",
188
+ componentIds?.join(",") ?? "",
149
189
  token ?? "",
150
190
  appId ?? "",
151
191
  ].join("|");
@@ -160,7 +200,10 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
160
200
  try {
161
201
  const agentChatBlock = await getAgentChatBlock();
162
202
  const effectiveAgentId = agentId ?? agentChatBlock?.data?.agentBlockId;
163
- const agentBlock = effectiveAgentId ? await blocksApiService.getBlock(effectiveAgentId) : null;
203
+ const [agentBlock, chatComponentBlocks] = await Promise.all([
204
+ effectiveAgentId ? blocksApiService.getBlock(effectiveAgentId) : null,
205
+ getChatComponentBlocks(),
206
+ ]);
164
207
  if (ac.signal.aborted) {
165
208
  return;
166
209
  }
@@ -172,6 +215,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
172
215
  disableGeneratingDynamicChatComponent: agentChatBlock.data.disableGeneratingDynamicChatComponent,
173
216
  hideToolsUi: agentChatBlock.data.hideToolsUi,
174
217
  });
218
+ setComponents(chatComponentBlocks);
175
219
  setAgent({
176
220
  id: agentBlock.id,
177
221
  title: agentBlock?.data?.title,
@@ -211,8 +255,18 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
211
255
  // a render-order race where `isAgentReady` flips true before the
212
256
  // mirrored React state catches up, which would otherwise double-send
213
257
  // the prompt on top of replayed history.
258
+ //
259
+ // `canSendMessage` is also part of the gate: `sendMessage` silently
260
+ // no-ops when its closed-over `canSendMessage` is false (e.g. while
261
+ // the `agent` mirror is committing or CopilotKit briefly reports
262
+ // `isLoading`). Without this guard the optimistic `initialPromptSentRef`
263
+ // flip below would lock the prompt out forever after a single
264
+ // dropped call. Re-runs as soon as the gate opens.
214
265
  useEffect(() => {
215
- if (!isAgentReady || !isConfigLoaded || initialPromptSentRef.current) {
266
+ if (initialPromptSentRef.current) {
267
+ return;
268
+ }
269
+ if (!isAgentReady || !isConfigLoaded) {
216
270
  return;
217
271
  }
218
272
  if (!agentChat?.initialPrompt) {
@@ -222,10 +276,16 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
222
276
  initialPromptSentRef.current = true;
223
277
  return;
224
278
  }
279
+ if (!canSendMessage) {
280
+ return;
281
+ }
225
282
  initialPromptSentRef.current = true;
226
283
  sendAgentInitialPrompt(agentChat.initialPrompt);
227
- }, [isAgentReady, isConfigLoaded, agentChat, copilotAgent, sendAgentInitialPrompt]);
284
+ }, [isAgentReady, isConfigLoaded, agentChat, copilotAgent, canSendMessage, sendAgentInitialPrompt]);
228
285
  const sendFromInputs = async () => {
286
+ if (!canSendMessage) {
287
+ return;
288
+ }
229
289
  const currentPrompt = prompt;
230
290
  // const currentAttachments = attachments;
231
291
  setPrompt("");
@@ -285,6 +345,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
285
345
  attachments,
286
346
  sendMessage,
287
347
  sendFromInputs,
348
+ stopGeneration,
288
349
  addAttachments,
289
350
  removeAttachment,
290
351
  clearAttachments,
@@ -298,18 +359,16 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
298
359
  isAgentReady,
299
360
  agentChat,
300
361
  agent,
362
+ components,
301
363
  currentThreadId,
302
364
  }, children: children }));
303
365
  };
304
366
  export const AgentChatRoot = ({ ...props
305
- // agentHarness,
306
- // useAgentBlockDirectChat,
307
- // chatContextFiles,
308
367
  // agentChatData,
309
368
  // memoryEnabled = false,
310
369
  // shortTermMemory,
311
370
  }) => {
312
- const { appId, token, children, agentId, agentChatId, chatId, defaultThreadId, noPersistency, chatContext } = props;
371
+ const { appId, token, children, agentId, agentHarness, useAgentBlockDirectChat, agentChatId, componentIds, chatId, defaultThreadId, noPersistency, chatContext, chatContextFiles, } = props;
313
372
  const currentAppVersion = AppVersionService.getCurrentVersionNumber();
314
373
  const socketId = websocketsService.getSocketId();
315
374
  const headers = useMemo(() => ({
@@ -320,15 +379,22 @@ export const AgentChatRoot = ({ ...props
320
379
  }), [token, currentAppVersion, socketId, appId]);
321
380
  const [currentThreadId, setCurrentThreadId] = useState(() => defaultThreadId ?? (noPersistency ? crypto.randomUUID() : DEFAULT_CHAT_THREAD_ID));
322
381
  const chatContextStr = chatContext == null ? undefined : typeof chatContext === "string" ? chatContext : JSON.stringify(chatContext);
382
+ if (!appId || !agentChatId) {
383
+ return null;
384
+ }
323
385
  return (_jsxs(CopilotKit, { runtimeUrl: `${getApiHost()}/agent-chat-stream`, agent: "default", headers: headers, threadId: currentThreadId,
324
386
  // debug={true}
325
387
  properties: {
326
388
  appId,
327
389
  agentId,
390
+ agentHarness,
391
+ useAgentBlockDirectChat,
328
392
  agentChatId,
329
393
  chatId,
394
+ noPersistency,
330
395
  chatContext: chatContextStr,
331
- }, children: [_jsx(SessionReadables, {}), _jsx(ChatInitializer, { agentId: agentId, agentChatId: agentChatId, chatId: chatId, noPersistency: noPersistency, token: token, appId: appId, currentThreadId: currentThreadId, setCurrentThreadId: setCurrentThreadId, children: children })] }));
396
+ chatContextFiles,
397
+ }, children: [_jsx(SessionReadables, {}), _jsx(ChatInitializer, { agentId: agentId, agentChatId: agentChatId, chatId: chatId, noPersistency: noPersistency, token: token, appId: appId, componentIds: componentIds, currentThreadId: currentThreadId, setCurrentThreadId: setCurrentThreadId, children: children })] }));
332
398
  };
333
399
  export function AgentChatMessage({ message, index, ...props }) {
334
400
  return _jsx("div", { "data-message-index": index, "data-message-role": message.role, ...props });
@@ -367,7 +433,8 @@ export function AgentChatFetching({ asChild = false, ...props }) {
367
433
  return _jsx(Comp, { "data-slot": "agent-chat-fetching", ...props });
368
434
  }
369
435
  export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste, onDragOver, onDragLeave, onDrop, onSubmit, acceptFiles = true, ...props }) {
370
- const { setIsDraggingFiles, addAttachments, prompt, setPrompt, sendFromInputs } = useAgentChat();
436
+ const { setIsDraggingFiles, addAttachments, prompt, setPrompt, sendFromInputs, isThinking, isAgentReady, isFetchingMessages, } = useAgentChat();
437
+ const isDisabled = props.disabled || isThinking || !isAgentReady || isFetchingMessages;
371
438
  const handleDragOver = useCallback((e) => {
372
439
  if (!acceptFiles) {
373
440
  return;
@@ -402,10 +469,13 @@ export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste,
402
469
  const handleKeyDown = useCallback((e) => {
403
470
  if (e.key === "Enter" && !e.shiftKey) {
404
471
  e.preventDefault();
472
+ if (isDisabled) {
473
+ return;
474
+ }
405
475
  onSubmit?.(e);
406
476
  sendFromInputs();
407
477
  }
408
- }, [sendFromInputs, onSubmit]);
478
+ }, [isDisabled, onSubmit, sendFromInputs]);
409
479
  const handleChange = useCallback((e) => {
410
480
  setPrompt(e.target.value);
411
481
  }, [setPrompt]);
@@ -455,11 +525,20 @@ export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste,
455
525
  : onDrop, "data-slot": "agent-chat-input", ...props }));
456
526
  }
457
527
  export function AgentChatSendTrigger({ asChild = false, onClick, disabled, ...props }) {
458
- const { isThinking, isAgentReady, isFetchingMessages, sendFromInputs } = useAgentChat();
528
+ const { isThinking, isAgentReady, isFetchingMessages, sendFromInputs, stopGeneration } = useAgentChat();
459
529
  const Comp = asChild ? Slot : "button";
460
- const isDisabled = disabled ?? (isThinking || !isAgentReady || isFetchingMessages);
530
+ const isDisabled = disabled ?? (!isThinking && (!isAgentReady || isFetchingMessages));
461
531
  return (_jsx(Comp, { onClick: (e) => {
462
- sendFromInputs();
532
+ if (isDisabled) {
533
+ e.preventDefault();
534
+ return;
535
+ }
536
+ if (isThinking) {
537
+ stopGeneration();
538
+ }
539
+ else {
540
+ sendFromInputs();
541
+ }
463
542
  onClick?.(e);
464
543
  }, disabled: isDisabled, "data-slot": "agent-chat-send-trigger", ...props }));
465
544
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocksdiy/react-common",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "type": "module",
5
5
  "description": "React common",
6
6
  "keywords": [],