@blocksdiy/react-common 1.30.0 → 1.30.2
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.
|
@@ -50,7 +50,7 @@ export interface AgentChatContextValue {
|
|
|
50
50
|
currentThreadId?: string;
|
|
51
51
|
agent: Agent | null;
|
|
52
52
|
agentChat: AgentChat | null;
|
|
53
|
-
components:
|
|
53
|
+
components: any[];
|
|
54
54
|
sendMessage: (message: Omit<UserMessage, "id" | "role">) => Promise<void>;
|
|
55
55
|
sendFromInputs: () => Promise<void>;
|
|
56
56
|
stopGeneration: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/new-agent-chat.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAM/D,OAAO,EAEL,SAAS,EACT,cAAc,EAQf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,2BAA2B,CAAC;AAQnC,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,aAAa,CAAC,EA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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"}
|
|
@@ -120,10 +120,9 @@ const SessionReadables = () => {
|
|
|
120
120
|
// });
|
|
121
121
|
return null;
|
|
122
122
|
};
|
|
123
|
-
const ChatInitializer = ({
|
|
123
|
+
const ChatInitializer = ({ agentBlock, agentChatBlock, chatId, token, appId, components, currentThreadId, setCurrentThreadId, children, }) => {
|
|
124
124
|
const [agentChat, setAgentChat] = useState(null);
|
|
125
125
|
const [agent, setAgent] = useState(null);
|
|
126
|
-
const [components, setComponents] = useState([]);
|
|
127
126
|
// `isConfigLoaded` covers the (small, parallel) async fetch of the
|
|
128
127
|
// agent + agentChat block configs. The actual chat transcript loads
|
|
129
128
|
// through CopilotKit's `connectAgent` pipeline, which surfaces via
|
|
@@ -147,9 +146,8 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
147
146
|
const [prompt, setPrompt] = useState("");
|
|
148
147
|
const [attachments, setAttachments] = useState([]);
|
|
149
148
|
const [isDraggingFiles, setIsDraggingFiles] = useState(false);
|
|
150
|
-
const blocksApiService = useMemo(() => new BlocksApiService({ token }), [token]);
|
|
151
149
|
const attachmentsEnabled = agentChat ? agentChat.disableAttachments !== true : false;
|
|
152
|
-
const canSendMessage = Boolean(
|
|
150
|
+
const canSendMessage = Boolean(agentChatBlock && agentChat && agent && isConfigLoaded && isAgentReady && !isAgentRunning);
|
|
153
151
|
const isFetchingMessages = !isConfigLoaded || (!isAgentReady && copilotMessages.length === 0);
|
|
154
152
|
// CopilotKit reports `isLoading` during connect/replay as well as real runs.
|
|
155
153
|
// Only expose thinking once the bootstrap connect phase has completed.
|
|
@@ -182,47 +180,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
182
180
|
copilotStopGeneration();
|
|
183
181
|
copilotAgent?.abortRun?.();
|
|
184
182
|
}, [copilotAgent, copilotStopGeneration]);
|
|
185
|
-
const
|
|
186
|
-
if (!agentChatId) {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
const agentChatBlock = await blocksApiService.getBlock(agentChatId);
|
|
190
|
-
if (!agentChatBlock) {
|
|
191
|
-
throw new Error("Agent chat block not found");
|
|
192
|
-
}
|
|
193
|
-
return agentChatBlock;
|
|
194
|
-
}, [agentChatId, blocksApiService]);
|
|
195
|
-
const getChatComponentBlocks = useCallback(async () => {
|
|
196
|
-
if (!componentIds?.length) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
const maybeComponentBlocks = await Promise.all(componentIds.map(async (componentId) => {
|
|
200
|
-
try {
|
|
201
|
-
const block = await blocksApiService.getBlock(componentId);
|
|
202
|
-
const id = block?.id ?? componentId;
|
|
203
|
-
const name = typeof block?.name === "string" ? block.name.trim() : "";
|
|
204
|
-
const code = typeof block?.data?.code === "string" ? block.data.code.trim() : "";
|
|
205
|
-
const description = typeof block?.data?.description === "string" ? block.data.description.trim() : "";
|
|
206
|
-
if (!id || !name || !code || !description) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
id,
|
|
211
|
-
name,
|
|
212
|
-
code,
|
|
213
|
-
input: block?.data?.input,
|
|
214
|
-
description,
|
|
215
|
-
toolName: getAgentChatComponentToolName(name),
|
|
216
|
-
userInterrupt: Boolean(block?.data?.userInterrupt),
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
catch {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
}));
|
|
223
|
-
return maybeComponentBlocks.filter((component) => Boolean(component));
|
|
224
|
-
}, [blocksApiService, componentIds]);
|
|
225
|
-
const componentIdsKey = componentIds?.join(",") ?? "";
|
|
183
|
+
const componentsKey = components?.map((component) => component.id).join(",") ?? "";
|
|
226
184
|
const initKeyRef = useRef(null);
|
|
227
185
|
// Guard against re-firing the initial prompt across re-renders of the
|
|
228
186
|
// post-connect effect. Reset whenever the init key changes (thread
|
|
@@ -232,9 +190,9 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
232
190
|
const initKey = [
|
|
233
191
|
chatId ?? "",
|
|
234
192
|
currentThreadId ?? "",
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
193
|
+
agentBlock?.id ?? "",
|
|
194
|
+
agentChatBlock?.id ?? "",
|
|
195
|
+
componentsKey,
|
|
238
196
|
token ?? "",
|
|
239
197
|
appId ?? "",
|
|
240
198
|
].join("|");
|
|
@@ -247,12 +205,6 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
247
205
|
const initialize = async () => {
|
|
248
206
|
setIsConfigLoaded(false);
|
|
249
207
|
try {
|
|
250
|
-
const agentChatBlock = await getAgentChatBlock();
|
|
251
|
-
const effectiveAgentId = agentId ?? agentChatBlock?.data?.agentBlockId;
|
|
252
|
-
const [agentBlock, chatComponentBlocks] = await Promise.all([
|
|
253
|
-
effectiveAgentId ? blocksApiService.getBlock(effectiveAgentId) : null,
|
|
254
|
-
getChatComponentBlocks(),
|
|
255
|
-
]);
|
|
256
208
|
if (ac.signal.aborted) {
|
|
257
209
|
return;
|
|
258
210
|
}
|
|
@@ -265,7 +217,6 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
265
217
|
hideToolsUi: agentChatBlock.data.hideToolsUi,
|
|
266
218
|
disableAttachments: agentChatBlock.data.disableAttachments,
|
|
267
219
|
});
|
|
268
|
-
setComponents(chatComponentBlocks);
|
|
269
220
|
setAgent({
|
|
270
221
|
id: agentBlock.id,
|
|
271
222
|
title: agentBlock?.data?.title,
|
|
@@ -292,7 +243,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
292
243
|
initialPromptSentRef.current = false;
|
|
293
244
|
};
|
|
294
245
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
295
|
-
}, [chatId, currentThreadId,
|
|
246
|
+
}, [chatId, currentThreadId, agentBlock?.id, agentChatBlock?.id, componentsKey, token, appId]);
|
|
296
247
|
// After CopilotKit's `connectAgent` resolves, the agent's message list
|
|
297
248
|
// already reflects whatever the backend replayed (history + any
|
|
298
249
|
// seeded initial messages). If the thread is still empty AND the
|
|
@@ -440,7 +391,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
440
391
|
isAgentReady,
|
|
441
392
|
agentChat,
|
|
442
393
|
agent,
|
|
443
|
-
components,
|
|
394
|
+
components: components ?? [],
|
|
444
395
|
currentThreadId,
|
|
445
396
|
}, children: children }));
|
|
446
397
|
};
|
|
@@ -458,23 +409,89 @@ export const AgentChatRoot = ({ ...props
|
|
|
458
409
|
...(appId ? { "x-app-id": appId } : {}),
|
|
459
410
|
}), [token, socketId, appId]);
|
|
460
411
|
const [currentThreadId, setCurrentThreadId] = useState(() => defaultThreadId ?? (noPersistency ? crypto.randomUUID() : DEFAULT_CHAT_THREAD_ID));
|
|
412
|
+
const blocksApiService = useMemo(() => new BlocksApiService({ token }), [token]);
|
|
413
|
+
const [agentChatBlock, setAgentChatBlock] = useState(null);
|
|
414
|
+
const [agentBlock, setAgentBlock] = useState(null);
|
|
415
|
+
const [components, setComponents] = useState([]);
|
|
461
416
|
const chatContextStr = chatContext == null ? undefined : typeof chatContext === "string" ? chatContext : JSON.stringify(chatContext);
|
|
462
|
-
|
|
417
|
+
const getAgentChatBlock = useCallback(async () => {
|
|
418
|
+
if (!agentChatId) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
const agentChatBlock = await blocksApiService.getBlock(agentChatId, appId, "agent", "agent_chat");
|
|
422
|
+
if (!agentChatBlock) {
|
|
423
|
+
throw new Error("Agent chat block not found");
|
|
424
|
+
}
|
|
425
|
+
return agentChatBlock;
|
|
426
|
+
}, [agentChatId, appId, blocksApiService]);
|
|
427
|
+
const getAgentBlock = useCallback(async (agentBlockId) => {
|
|
428
|
+
if (!agentBlockId) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
const agentBlock = await blocksApiService.getBlock(agentBlockId, appId, "agent", "agent");
|
|
432
|
+
if (!agentBlock) {
|
|
433
|
+
throw new Error("Agent chat block not found");
|
|
434
|
+
}
|
|
435
|
+
return agentBlock;
|
|
436
|
+
}, [appId, blocksApiService]);
|
|
437
|
+
const getChatComponentBlocks = useCallback(async () => {
|
|
438
|
+
if (!componentIds?.length) {
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
const maybeComponentBlocks = await Promise.all(componentIds.map(async (componentId) => {
|
|
442
|
+
try {
|
|
443
|
+
const block = await blocksApiService.getBlock(componentId);
|
|
444
|
+
const id = block?.id ?? componentId;
|
|
445
|
+
const name = typeof block?.name === "string" ? block.name.trim() : "";
|
|
446
|
+
const code = typeof block?.data?.code === "string" ? block.data.code.trim() : "";
|
|
447
|
+
const description = typeof block?.data?.description === "string" ? block.data.description.trim() : "";
|
|
448
|
+
if (!id || !name || !code || !description) {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
id,
|
|
453
|
+
name,
|
|
454
|
+
code,
|
|
455
|
+
input: block?.data?.input,
|
|
456
|
+
description,
|
|
457
|
+
toolName: getAgentChatComponentToolName(name),
|
|
458
|
+
userInterrupt: Boolean(block?.data?.userInterrupt),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
}));
|
|
465
|
+
return maybeComponentBlocks.filter((component) => Boolean(component));
|
|
466
|
+
}, [blocksApiService, componentIds]);
|
|
467
|
+
useEffect(() => {
|
|
468
|
+
getAgentChatBlock().then((agentChatBlock) => {
|
|
469
|
+
setAgentChatBlock(agentChatBlock);
|
|
470
|
+
const effectiveAgentId = agentId ?? agentChatBlock?.data?.agentBlockId;
|
|
471
|
+
getAgentBlock(effectiveAgentId).then((agentBlock) => {
|
|
472
|
+
setAgentBlock(agentBlock);
|
|
473
|
+
});
|
|
474
|
+
getChatComponentBlocks().then((chatComponentBlocks) => {
|
|
475
|
+
setComponents(chatComponentBlocks);
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
}, [getAgentChatBlock, getAgentBlock, getChatComponentBlocks, agentId]);
|
|
479
|
+
if (!appId || !agentBlock || !agentChatBlock) {
|
|
463
480
|
return null;
|
|
464
481
|
}
|
|
465
482
|
return (_jsxs(CopilotKit, { runtimeUrl: `${getApiHost()}/agent-chat-stream`, agent: "default", headers: headers, threadId: currentThreadId,
|
|
466
483
|
// debug={true}
|
|
467
484
|
properties: {
|
|
468
485
|
appId,
|
|
469
|
-
agentId,
|
|
486
|
+
agentId: agentBlock.id,
|
|
470
487
|
agentHarness,
|
|
471
488
|
useAgentBlockDirectChat,
|
|
472
|
-
agentChatId,
|
|
489
|
+
agentChatId: agentChatBlock.id,
|
|
473
490
|
chatId,
|
|
474
491
|
noPersistency,
|
|
475
492
|
chatContext: chatContextStr,
|
|
476
493
|
chatContextFiles,
|
|
477
|
-
}, children: [_jsx(SessionReadables, {}), _jsx(ChatInitializer, {
|
|
494
|
+
}, children: [_jsx(SessionReadables, {}), _jsx(ChatInitializer, { agentBlock: agentBlock, agentChatBlock: agentChatBlock, chatId: chatId, noPersistency: noPersistency, token: token, appId: appId, components: components, currentThreadId: currentThreadId, setCurrentThreadId: setCurrentThreadId, children: children })] }));
|
|
478
495
|
};
|
|
479
496
|
export function AgentChatMessage({ message, index, ...props }) {
|
|
480
497
|
if (message.role === "user" && message.name === HIDDEN_INITIAL_PROMPT_MESSAGE_NAME) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocksdiy/react-common",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React common",
|
|
6
6
|
"keywords": [],
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"penpal": "^7.0.6",
|
|
39
39
|
"react": "^19.2.4",
|
|
40
40
|
"use-stick-to-bottom": "1.1.4",
|
|
41
|
-
"@blocksdiy/blocks-client-api": "1.
|
|
41
|
+
"@blocksdiy/blocks-client-api": "1.12.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/react": "^19.2.14",
|