@blocksdiy/react-common 1.26.0 → 1.27.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Message, type UserMessage } from "@ag-ui/client";
|
|
2
2
|
import { ReactNode, SetStateAction } from "react";
|
|
3
|
-
export { type Message } from "@ag-ui/client";
|
|
4
|
-
export { useRenderTool, useRenderToolCall, useDefaultRenderTool, useHumanInTheLoop, ToolCallStatus, } from "@copilotkit/react-core/v2";
|
|
3
|
+
export { type Message, type AssistantMessage } from "@ag-ui/client";
|
|
4
|
+
export { useRenderTool, useRenderToolCall, useDefaultRenderTool, useHumanInTheLoop, useFrontendTool, ToolCallStatus, } from "@copilotkit/react-core/v2";
|
|
5
5
|
export interface Attachment {
|
|
6
6
|
url: string;
|
|
7
7
|
fileType: string;
|
|
@@ -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,MAAM,eAAe,CAAC;
|
|
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,cA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AAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,8BAA8B,2CAcjE"}
|
|
@@ -5,7 +5,7 @@ import { CopilotKit, useCopilotChatInternal } from "@copilotkit/react-core";
|
|
|
5
5
|
import { useCopilotKit } from "@copilotkit/react-core/v2";
|
|
6
6
|
import { Slot } from "@radix-ui/react-slot";
|
|
7
7
|
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
8
|
-
export { useRenderTool, useRenderToolCall, useDefaultRenderTool, useHumanInTheLoop, ToolCallStatus, } from "@copilotkit/react-core/v2";
|
|
8
|
+
export { useRenderTool, useRenderToolCall, useDefaultRenderTool, useHumanInTheLoop, useFrontendTool, ToolCallStatus, } from "@copilotkit/react-core/v2";
|
|
9
9
|
import { useStickToBottom } from "use-stick-to-bottom";
|
|
10
10
|
// Client-only `useLayoutEffect`, falls back to `useEffect` during SSR.
|
|
11
11
|
// Needed so the `agent.threadId` mirror commits before CopilotKit's
|
|
@@ -30,10 +30,10 @@ const generateId = (length = 10) => {
|
|
|
30
30
|
* Walk the conversation and return every assistant-emitted tool call
|
|
31
31
|
* that has no matching ToolMessage (i.e. is awaiting a result). With
|
|
32
32
|
* our current setup, the only tool that ends up in this state is the
|
|
33
|
-
* frontend
|
|
34
|
-
* run and never appear pending in the UI. Used by `sendFromInputs`
|
|
35
|
-
*
|
|
36
|
-
* instead of
|
|
33
|
+
* frontend user-choice tool; backend tools resolve in the same agent
|
|
34
|
+
* run and never appear pending in the UI. Used by `sendFromInputs` to
|
|
35
|
+
* auto-skip dangling answer UIs when the user types a new message
|
|
36
|
+
* instead of choosing an answer.
|
|
37
37
|
*/
|
|
38
38
|
const _collectPendingToolCalls = (messages) => {
|
|
39
39
|
const toolMessageIds = new Set();
|
|
@@ -155,16 +155,18 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
155
155
|
try {
|
|
156
156
|
const block = await blocksApiService.getBlock(componentId);
|
|
157
157
|
const id = block?.id ?? componentId;
|
|
158
|
-
const name = block?.name;
|
|
159
|
-
|
|
158
|
+
const name = typeof block?.name === "string" ? block.name.trim() : "";
|
|
159
|
+
const code = typeof block?.data?.code === "string" ? block.data.code.trim() : "";
|
|
160
|
+
const description = typeof block?.data?.description === "string" ? block.data.description.trim() : "";
|
|
161
|
+
if (!id || !name || !code || !description) {
|
|
160
162
|
return null;
|
|
161
163
|
}
|
|
162
164
|
return {
|
|
163
165
|
id,
|
|
164
166
|
name,
|
|
165
|
-
code
|
|
167
|
+
code,
|
|
166
168
|
input: block?.data?.input,
|
|
167
|
-
description
|
|
169
|
+
description,
|
|
168
170
|
toolName: getAgentChatComponentToolName(name),
|
|
169
171
|
};
|
|
170
172
|
}
|
|
@@ -307,14 +309,14 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
307
309
|
// const currentAttachments = attachments;
|
|
308
310
|
setPrompt("");
|
|
309
311
|
setAttachments([]);
|
|
310
|
-
// Auto-skip any
|
|
312
|
+
// Auto-skip any frontend user-choice tool call that's still waiting.
|
|
311
313
|
//
|
|
312
314
|
// If the user types a new message instead of clicking an answer on
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
// * `executingToolCallIds` keeps the toolCallId (the parked
|
|
317
|
-
//
|
|
315
|
+
// the inline form, the agent had returned an assistant message with
|
|
316
|
+
// a tool call and is parked awaiting a ToolMessage that never arrives.
|
|
317
|
+
// Without intervention here:
|
|
318
|
+
// * `executingToolCallIds` keeps the toolCallId (the parked Promise
|
|
319
|
+
// from useHumanInTheLoop never resolves, so
|
|
318
320
|
// onToolExecutionEnd never fires).
|
|
319
321
|
// * No ToolMessage is ever added, so the render code stays on
|
|
320
322
|
// "executing" → the form looks live forever, the next refresh
|
|
@@ -330,10 +332,10 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, component
|
|
|
330
332
|
// (assistant_tool_call → skip_result → new user turn) so the
|
|
331
333
|
// agent can respond coherently.
|
|
332
334
|
//
|
|
333
|
-
// Caveat: we don't (and can't, with the current useHumanInTheLoop
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
//
|
|
335
|
+
// Caveat: we don't (and can't, with the current useHumanInTheLoop API)
|
|
336
|
+
// resolve the parked Promise itself — it lingers in memory until page
|
|
337
|
+
// reload. Acceptable: one closure per skip, cleared on refresh, no
|
|
338
|
+
// functional impact.
|
|
337
339
|
if (copilotAgent) {
|
|
338
340
|
const pending = _collectPendingToolCalls(copilotAgent.messages);
|
|
339
341
|
for (const toolCall of pending) {
|