@blocksdiy/react-common 1.23.0 → 1.24.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.
- package/dist/components/agent-chat.d.ts +3 -118
- package/dist/components/agent-chat.d.ts.map +1 -1
- package/dist/components/agent-chat.js +14 -619
- package/dist/components/new-agent-chat.d.ts +13 -1
- package/dist/components/new-agent-chat.d.ts.map +1 -1
- package/dist/components/new-agent-chat.js +101 -21
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReactNode, SetStateAction } from "react";
|
|
2
2
|
import { type VoiceCallMessage } from "../hooks/use-voice-call.js";
|
|
3
|
-
export declare const ASK_USER_TOOL_NAME = "ask_user";
|
|
4
3
|
export interface Attachment {
|
|
5
4
|
url: string;
|
|
6
5
|
fileType: string;
|
|
@@ -25,73 +24,7 @@ export interface LegacyMessagePayload {
|
|
|
25
24
|
payload: Record<string, any>;
|
|
26
25
|
hiddenContent?: string;
|
|
27
26
|
}
|
|
28
|
-
export type
|
|
29
|
-
export interface AskUserQuestionOption {
|
|
30
|
-
id: string;
|
|
31
|
-
label: string;
|
|
32
|
-
description?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface AskUserQuestion {
|
|
35
|
-
id: string;
|
|
36
|
-
label: string;
|
|
37
|
-
type: AskUserQuestionType;
|
|
38
|
-
required?: boolean;
|
|
39
|
-
placeholder?: string;
|
|
40
|
-
options?: AskUserQuestionOption[];
|
|
41
|
-
choices?: string[];
|
|
42
|
-
allowOther?: boolean;
|
|
43
|
-
otherLabel?: string;
|
|
44
|
-
presentation?: "chips" | "cards";
|
|
45
|
-
}
|
|
46
|
-
export interface AskUserPayload {
|
|
47
|
-
questions?: AskUserQuestion[];
|
|
48
|
-
}
|
|
49
|
-
export interface AskUserSubmittedAnswer {
|
|
50
|
-
questionId: string;
|
|
51
|
-
question: string;
|
|
52
|
-
type: AskUserQuestionType;
|
|
53
|
-
value?: string;
|
|
54
|
-
values?: string[];
|
|
55
|
-
label?: string;
|
|
56
|
-
labels?: string[];
|
|
57
|
-
other?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface ToolResumeInput {
|
|
60
|
-
toolCallId?: string;
|
|
61
|
-
toolName?: string;
|
|
62
|
-
type?: string;
|
|
63
|
-
skipped?: boolean;
|
|
64
|
-
[key: string]: unknown;
|
|
65
|
-
}
|
|
66
|
-
export interface SubmitAskUserAnswersInput extends ToolResumeInput {
|
|
67
|
-
type?: "ask_user";
|
|
68
|
-
answers: AskUserSubmittedAnswer[];
|
|
69
|
-
}
|
|
70
|
-
type CopilotMessageMetadata = {
|
|
71
|
-
version?: 1;
|
|
72
|
-
hiddenPrompt?: string;
|
|
73
|
-
kind?: "tool-resume";
|
|
74
|
-
};
|
|
75
|
-
type CopilotToolCall = {
|
|
76
|
-
id?: string;
|
|
77
|
-
name?: string;
|
|
78
|
-
args?: unknown;
|
|
79
|
-
input?: unknown;
|
|
80
|
-
function?: {
|
|
81
|
-
name?: string;
|
|
82
|
-
arguments?: unknown;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
type CopilotMessage = {
|
|
86
|
-
id?: string;
|
|
87
|
-
role?: string;
|
|
88
|
-
content?: string;
|
|
89
|
-
metadata?: CopilotMessageMetadata;
|
|
90
|
-
toolCalls?: CopilotToolCall[];
|
|
91
|
-
toolCallId?: string;
|
|
92
|
-
name?: string;
|
|
93
|
-
};
|
|
94
|
-
export type PersistedMessagePayload = LegacyMessagePayload | CopilotMessage;
|
|
27
|
+
export type PersistedMessagePayload = LegacyMessagePayload;
|
|
95
28
|
interface MessageItemBase {
|
|
96
29
|
createdAt: string;
|
|
97
30
|
createdBy?: string;
|
|
@@ -105,7 +38,6 @@ export type LegacyMessageItem = MessageItemBase & {
|
|
|
105
38
|
export type MessageItem = LegacyMessageItem;
|
|
106
39
|
export interface AgentChatContextValue {
|
|
107
40
|
messages: MessageItem[];
|
|
108
|
-
initialAgentMessages: MessageItem[];
|
|
109
41
|
attachments: Attachment[];
|
|
110
42
|
prompt: string;
|
|
111
43
|
isThinking: boolean;
|
|
@@ -115,8 +47,6 @@ export interface AgentChatContextValue {
|
|
|
115
47
|
threadIds: string[];
|
|
116
48
|
agentChatData?: AgentChatData;
|
|
117
49
|
sendMessage: (message: Omit<LegacyMessagePayload, "id" | "role" | "type" | "payload">) => Promise<void>;
|
|
118
|
-
submitToolResume: (input: ToolResumeInput) => Promise<void>;
|
|
119
|
-
submitAskUserAnswers: (input: SubmitAskUserAnswersInput) => Promise<void>;
|
|
120
50
|
sendFromInputs: () => Promise<void>;
|
|
121
51
|
addMessages: (newMessages: MessageItem[]) => void;
|
|
122
52
|
addAttachments: (attachments: Attachment[]) => void;
|
|
@@ -129,15 +59,11 @@ export interface AgentChatContextValue {
|
|
|
129
59
|
setThreadIds: React.Dispatch<SetStateAction<string[]>>;
|
|
130
60
|
appId: string;
|
|
131
61
|
token?: string;
|
|
132
|
-
agentBlockId?: string;
|
|
133
62
|
agentChatId?: string;
|
|
134
63
|
chatId?: string;
|
|
135
64
|
noPersistency?: boolean;
|
|
136
65
|
}
|
|
137
66
|
export declare const AgentChatContext: import("react").Context<AgentChatContextValue | null>;
|
|
138
|
-
export declare const formatAskUserAnswerSummary: (answers: AskUserSubmittedAnswer[]) => string;
|
|
139
|
-
export declare const buildToolResumeHiddenContent: ({ toolName, type, skipped, ...resumePayload }: ToolResumeInput) => string;
|
|
140
|
-
export declare const buildAskUserAnswersHiddenContent: (input: SubmitAskUserAnswersInput) => string;
|
|
141
67
|
export declare const useAgentChat: () => AgentChatContextValue;
|
|
142
68
|
export interface ToolCardContextValue {
|
|
143
69
|
open: boolean;
|
|
@@ -193,12 +119,6 @@ export interface AgentChatData {
|
|
|
193
119
|
export interface AgentChatRootProps {
|
|
194
120
|
appId: string;
|
|
195
121
|
token?: string;
|
|
196
|
-
/** Agent/persona block id used by the Python DeepAgent chat runtime. */
|
|
197
|
-
agentBlockId?: string;
|
|
198
|
-
/** Agent harness saved on the agent block. `deep_agent` implies the direct AI SDK transport. */
|
|
199
|
-
agentHarness?: string;
|
|
200
|
-
/** When true with `agentBlockId`, route direct Deep Agent chat through the AI SDK UI-message stream. */
|
|
201
|
-
useAgentBlockDirectChat?: boolean;
|
|
202
122
|
agentChatId?: string;
|
|
203
123
|
defaultThreadId?: string;
|
|
204
124
|
noPersistency?: boolean;
|
|
@@ -214,43 +134,8 @@ export interface AgentChatRootProps {
|
|
|
214
134
|
};
|
|
215
135
|
useDynamicUI?: boolean;
|
|
216
136
|
}
|
|
217
|
-
export type ResolvedAgentChatConfig = Pick<AgentChatRootProps, "
|
|
218
|
-
|
|
219
|
-
appId: string;
|
|
220
|
-
agentBlockId?: string;
|
|
221
|
-
agentChatId?: string;
|
|
222
|
-
chatId?: string;
|
|
223
|
-
currentThreadId?: string;
|
|
224
|
-
noPersistency?: boolean;
|
|
225
|
-
shortTermMemory: {
|
|
226
|
-
isEnabled: boolean;
|
|
227
|
-
isPersistent?: boolean;
|
|
228
|
-
};
|
|
229
|
-
chatContextFiles?: Attachment[];
|
|
230
|
-
chatContext: unknown;
|
|
231
|
-
requestMessages: CopilotMessage[];
|
|
232
|
-
messageId: string;
|
|
233
|
-
input: ToolResumeInput;
|
|
234
|
-
}
|
|
235
|
-
export declare const buildHitlResumeRequestBody: ({ appId, agentBlockId, agentChatId, chatId, currentThreadId, noPersistency, shortTermMemory, chatContextFiles, chatContext, requestMessages, messageId, input, }: HitlResumeRequestBodyInput) => {
|
|
236
|
-
appId: string;
|
|
237
|
-
agentBlockId: string | undefined;
|
|
238
|
-
agentChatId: string | undefined;
|
|
239
|
-
chatId: string | undefined;
|
|
240
|
-
threadId: string | undefined;
|
|
241
|
-
noPersistency: boolean | undefined;
|
|
242
|
-
shortTermMemory: {
|
|
243
|
-
isEnabled: boolean;
|
|
244
|
-
isPersistent?: boolean;
|
|
245
|
-
};
|
|
246
|
-
chatContextFiles: Attachment[] | undefined;
|
|
247
|
-
chatContext: string | undefined;
|
|
248
|
-
files: never[];
|
|
249
|
-
messages: CopilotMessage[];
|
|
250
|
-
messageId: string;
|
|
251
|
-
hitlResume: ToolResumeInput;
|
|
252
|
-
};
|
|
253
|
-
export declare const AgentChatRoot: ({ appId, token, agentBlockId, agentHarness, useAgentBlockDirectChat, agentChatId, children, chatId, noPersistency, defaultThreadId, chatContext, chatContextFiles, agentChatData, memoryEnabled, shortTermMemory, useDynamicUI, }: AgentChatRootProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
137
|
+
export type ResolvedAgentChatConfig = Pick<AgentChatRootProps, "agentChatData" | "shortTermMemory" | "useDynamicUI">;
|
|
138
|
+
export declare const AgentChatRoot: ({ appId, token, agentChatId, children, chatId, noPersistency, defaultThreadId, chatContext, chatContextFiles, agentChatData, memoryEnabled, shortTermMemory, useDynamicUI, }: AgentChatRootProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
254
139
|
export interface AgentChatVoiceContextValue {
|
|
255
140
|
isConnected: boolean;
|
|
256
141
|
isConnecting: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/agent-chat.tsx"],"names":[],"mappings":"AAMA,OAAO,EAEL,SAAS,EACT,cAAc,EAOf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAgB,KAAK,gBAAgB,EAA4B,MAAM,yBAAyB,CAAC;AAWxG,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAqBD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,IAAI,CAAC;AACzC,KAAK,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,qBAAqB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WA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AC9C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,0BAA0B,CAAC,EACzC,OAAe,EACf,OAAO,EACP,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,+BAA+B,2CAelE;AAED,MAAM,WAAW,6BAA6B;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,wBAAwB,CAAC,EACvC,OAAe,EACf,OAAO,EACP,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,6BAA6B,2CAehE;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,yBAAyB,CAAC,EACxC,OAAe,EACf,OAAO,EACP,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,8BAA8B,2CAiBjE;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAAC,EACnC,OAAe,EACf,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,yBAAyB,2CAezD;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAAC,EACnC,OAAe,EACf,KAAK,EACL,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,yBAAyB,2CAiBzD"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { HttpAgent } from "@ag-ui/client";
|
|
3
2
|
import { AppVersionService, BlocksApiService, DataApiService, websocketsService } from "@blocksdiy/blocks-client-api";
|
|
4
3
|
import { getApiHost } from "@blocksdiy/blocks-client-api/envService";
|
|
5
4
|
import { WorkflowRequest } from "@blocksdiy/blocks-client-api/workflowService";
|
|
6
|
-
import { CopilotKit, useCopilotChatInternal } from "@copilotkit/react-core";
|
|
7
5
|
import { Slot } from "@radix-ui/react-slot";
|
|
8
|
-
import { createContext, useCallback, useContext, useEffect,
|
|
6
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
9
7
|
import { useVoiceCall } from "../hooks/use-voice-call.js";
|
|
10
8
|
/* public decouple - blocks common */
|
|
11
9
|
const CHAT_AGENT_HISTORY_TABLE_BLOCK_ID = "688ed13adefd8b565c779b8e";
|
|
@@ -15,7 +13,6 @@ const CHAT_AGENT_CALL_ACTION_BLOCK_ID = "688ed4d77b454b1fdaf5cf2d";
|
|
|
15
13
|
const MAX_FILE_SIZE_MB = 5;
|
|
16
14
|
const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
|
|
17
15
|
const DEFAULT_SHORT_TERM_MEMORY = { isEnabled: true, isPersistent: true };
|
|
18
|
-
export const ASK_USER_TOOL_NAME = "ask_user";
|
|
19
16
|
const validateAndConvertFiles = (files) => {
|
|
20
17
|
if (files.length === 0) {
|
|
21
18
|
return null;
|
|
@@ -37,235 +34,12 @@ const generateId = (length = 10) => {
|
|
|
37
34
|
.toString(36)
|
|
38
35
|
.substring(2, 2 + length);
|
|
39
36
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const value = selectedValues || answer.other || answer.label || answer.value || "No answer";
|
|
44
|
-
return `- ${answer.question}: ${value}`;
|
|
45
|
-
});
|
|
46
|
-
return lines.join("\n");
|
|
47
|
-
};
|
|
48
|
-
export const buildToolResumeHiddenContent = ({ toolName = "tool", type = "tool", skipped, ...resumePayload }) => [
|
|
49
|
-
`The user submitted a resume payload to ${toolName}.`,
|
|
50
|
-
JSON.stringify({
|
|
51
|
-
type: "tool_resume",
|
|
52
|
-
status: skipped ? "skipped" : "answered",
|
|
53
|
-
resumeType: type,
|
|
54
|
-
toolName,
|
|
55
|
-
skipped,
|
|
56
|
-
...resumePayload,
|
|
57
|
-
}, null, 2),
|
|
58
|
-
].join("\n\n");
|
|
59
|
-
export const buildAskUserAnswersHiddenContent = (input) => buildToolResumeHiddenContent({
|
|
60
|
-
...input,
|
|
61
|
-
toolName: input.toolName ?? ASK_USER_TOOL_NAME,
|
|
62
|
-
type: "ask_user",
|
|
63
|
-
});
|
|
64
|
-
const isToolResumeHiddenContent = (hiddenContent) => typeof hiddenContent === "string" && hiddenContent.includes('"tool_resume"');
|
|
65
|
-
const isToolResumeCopilotMessage = (message) => message.metadata?.kind === "tool-resume" || isToolResumeHiddenContent(message.metadata?.hiddenPrompt);
|
|
66
|
-
/**
|
|
67
|
-
* Suppress the synthetic `TOOL_CALL_START` / `TOOL_CALL_ARGS` / `TOOL_CALL_END`
|
|
68
|
-
* events that the AGUI LangGraph agent re-emits when a previously-streamed
|
|
69
|
-
* tool resumes from a LangGraph `interrupt()` (e.g. the `ask_user` HITL flow).
|
|
70
|
-
*
|
|
71
|
-
* On resume the model is NOT re-invoked for the tool args — it just continues
|
|
72
|
-
* from the checkpoint — so `has_function_streaming` resets to False and the
|
|
73
|
-
* AGUI agent dispatches a synthetic START/ARGS/END pair before the real
|
|
74
|
-
* `TOOL_CALL_RESULT`. Applied client-side by `@ag-ui/client`'s default reducer
|
|
75
|
-
* those events:
|
|
76
|
-
* 1. Create a synthetic empty assistant message (parent_message_id maps to
|
|
77
|
-
* the new ToolMessage's id, which doesn't exist yet → new bubble pushed).
|
|
78
|
-
* 2. Append the full args JSON onto the original assistant message's
|
|
79
|
-
* already-complete tool call args (corrupting them so `parseMaybeJson`
|
|
80
|
-
* fails and the `AskUserPart` can't render the form input).
|
|
81
|
-
*
|
|
82
|
-
* Both effects flash as empty bubbles in the chat until the run-end
|
|
83
|
-
* `MESSAGES_SNAPSHOT` reconciles them. Suppressing the duplicate START (and
|
|
84
|
-
* its paired ARGS/END) at the subscriber layer keeps the original tool call
|
|
85
|
-
* intact and lets `TOOL_CALL_RESULT` resolve it cleanly through the existing
|
|
86
|
-
* `normalizeCopilotToolCall` pairing logic.
|
|
87
|
-
*/
|
|
88
|
-
const createDuplicateToolCallSuppressor = () => {
|
|
89
|
-
const suppressedToolCallIds = new Set();
|
|
90
|
-
return {
|
|
91
|
-
onToolCallStartEvent: ({ event, messages }) => {
|
|
92
|
-
const toolCallId = event.toolCallId;
|
|
93
|
-
if (!toolCallId) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
const alreadyPresent = messages.some((message) => message.role === "assistant" &&
|
|
97
|
-
Array.isArray(message.toolCalls) &&
|
|
98
|
-
message.toolCalls.some((tc) => tc.id === toolCallId));
|
|
99
|
-
if (alreadyPresent) {
|
|
100
|
-
suppressedToolCallIds.add(toolCallId);
|
|
101
|
-
return { stopPropagation: true };
|
|
102
|
-
}
|
|
103
|
-
return undefined;
|
|
104
|
-
},
|
|
105
|
-
onToolCallArgsEvent: ({ event }) => {
|
|
106
|
-
if (event.toolCallId && suppressedToolCallIds.has(event.toolCallId)) {
|
|
107
|
-
return { stopPropagation: true };
|
|
108
|
-
}
|
|
109
|
-
return undefined;
|
|
110
|
-
},
|
|
111
|
-
onToolCallEndEvent: ({ event }) => {
|
|
112
|
-
if (event.toolCallId && suppressedToolCallIds.has(event.toolCallId)) {
|
|
113
|
-
suppressedToolCallIds.delete(event.toolCallId);
|
|
114
|
-
return { stopPropagation: true };
|
|
115
|
-
}
|
|
116
|
-
return undefined;
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
class BlocksCopilotHttpAgent extends HttpAgent {
|
|
121
|
-
requestHeaders = {};
|
|
122
|
-
requestBody = {};
|
|
123
|
-
constructor({ url }) {
|
|
124
|
-
super({ url, headers: {} });
|
|
125
|
-
this.subscribe(createDuplicateToolCallSuppressor());
|
|
126
|
-
}
|
|
127
|
-
setRequestOptions({ headers, body }) {
|
|
128
|
-
this.requestHeaders = headers;
|
|
129
|
-
this.requestBody = body;
|
|
130
|
-
}
|
|
131
|
-
clearRequestOptions() {
|
|
132
|
-
this.requestHeaders = {};
|
|
133
|
-
this.requestBody = {};
|
|
134
|
-
}
|
|
135
|
-
requestInit(input) {
|
|
136
|
-
const init = super.requestInit({ ...input, ...this.requestBody });
|
|
137
|
-
return {
|
|
138
|
-
...init,
|
|
139
|
-
headers: {
|
|
140
|
-
...init.headers,
|
|
141
|
-
...this.requestHeaders,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const parseMaybeJson = (value) => {
|
|
147
|
-
if (typeof value !== "string") {
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
return JSON.parse(value);
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
return value;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const legacyPayloadToCopilotMessage = (message) => ({
|
|
158
|
-
id: message.id,
|
|
159
|
-
role: message.role === "human" ? "user" : "assistant",
|
|
160
|
-
content: message.content ?? "",
|
|
161
|
-
metadata: {
|
|
162
|
-
version: 1,
|
|
163
|
-
hiddenPrompt: message.hiddenContent,
|
|
164
|
-
},
|
|
165
|
-
...(Array.isArray(message.payload?.toolCalls) ? { toolCalls: message.payload.toolCalls } : {}),
|
|
166
|
-
});
|
|
167
|
-
const messageItemToCopilotMessage = (message) => {
|
|
168
|
-
if (isToolResumeHiddenContent(message.msg.hiddenContent)) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
return legacyPayloadToCopilotMessage(message.msg);
|
|
172
|
-
};
|
|
173
|
-
const normalizeCopilotToolCall = (toolCall, allMessages) => {
|
|
174
|
-
const toolCallId = toolCall.id;
|
|
175
|
-
const toolName = toolCall.function?.name ?? toolCall.name ?? "tool";
|
|
176
|
-
const toolResult = toolCallId
|
|
177
|
-
? allMessages.find((candidate) => candidate.role === "tool" && candidate.toolCallId === toolCallId)
|
|
178
|
-
: undefined;
|
|
179
|
-
return {
|
|
180
|
-
...toolCall,
|
|
181
|
-
type: `tool-${toolName}`,
|
|
182
|
-
toolCallId,
|
|
183
|
-
toolName,
|
|
184
|
-
state: toolResult ? "output-available" : "input-available",
|
|
185
|
-
input: parseMaybeJson(toolCall.function?.arguments ?? toolCall.args ?? toolCall.input),
|
|
186
|
-
...(toolResult ? { output: parseMaybeJson(toolResult.content) } : {}),
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
const copilotMessageToLegacyPayload = (message, allMessages = []) => {
|
|
190
|
-
if (isToolResumeCopilotMessage(message)) {
|
|
37
|
+
const messageItemToLegacyPayload = (message) => message.msg;
|
|
38
|
+
const storedMessageToLegacyView = (message) => {
|
|
39
|
+
if (message.msg.role !== "human" && message.msg.role !== "ai") {
|
|
191
40
|
return null;
|
|
192
41
|
}
|
|
193
|
-
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
if (message.role === "user" && !message.content && message.metadata?.hiddenPrompt) {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
const toolCalls = message.toolCalls?.map((toolCall) => normalizeCopilotToolCall(toolCall, allMessages)) ?? [];
|
|
200
|
-
return {
|
|
201
|
-
id: message.id,
|
|
202
|
-
role: message.role === "user" ? "human" : "ai",
|
|
203
|
-
type: "text",
|
|
204
|
-
content: message.content ?? "",
|
|
205
|
-
hiddenContent: message.metadata?.hiddenPrompt,
|
|
206
|
-
payload: toolCalls.length ? { toolCalls } : {},
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
const messageItemToLegacyPayload = (message) => isToolResumeHiddenContent(message.msg.hiddenContent) ? null : message.msg;
|
|
210
|
-
const getToolCallName = (toolCall) => toolCall.toolName ||
|
|
211
|
-
toolCall.function?.name ||
|
|
212
|
-
toolCall.name ||
|
|
213
|
-
(typeof toolCall.type === "string" ? toolCall.type.replace(/^tool-/, "") : undefined);
|
|
214
|
-
const getToolCallId = (toolCall) => toolCall.toolCallId || toolCall.id;
|
|
215
|
-
const isResolvedToolCall = (toolCall) => toolCall.state === "output-available" || toolCall.output !== undefined;
|
|
216
|
-
const findPendingAskUserToolCall = (messages) => {
|
|
217
|
-
for (let messageIndex = messages.length - 1; messageIndex >= 0; messageIndex -= 1) {
|
|
218
|
-
const toolCalls = messages[messageIndex].msg.payload?.toolCalls;
|
|
219
|
-
if (!Array.isArray(toolCalls)) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
for (let toolIndex = toolCalls.length - 1; toolIndex >= 0; toolIndex -= 1) {
|
|
223
|
-
const toolCall = toolCalls[toolIndex];
|
|
224
|
-
if (!toolCall || typeof toolCall !== "object") {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (getToolCallName(toolCall) === ASK_USER_TOOL_NAME && !isResolvedToolCall(toolCall)) {
|
|
228
|
-
return {
|
|
229
|
-
toolCallId: getToolCallId(toolCall),
|
|
230
|
-
toolName: ASK_USER_TOOL_NAME,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return null;
|
|
236
|
-
};
|
|
237
|
-
const appendCopilotErrorMessage = (messages, error) => {
|
|
238
|
-
const text = "Error: " + (error instanceof Error ? error.message : "Unknown error");
|
|
239
|
-
const lastMessage = messages[messages.length - 1];
|
|
240
|
-
if (lastMessage?.role === "assistant" && lastMessage.content === text) {
|
|
241
|
-
return messages;
|
|
242
|
-
}
|
|
243
|
-
return [
|
|
244
|
-
...messages,
|
|
245
|
-
{
|
|
246
|
-
id: generateId(10),
|
|
247
|
-
role: "assistant",
|
|
248
|
-
content: text,
|
|
249
|
-
metadata: { version: 1 },
|
|
250
|
-
},
|
|
251
|
-
];
|
|
252
|
-
};
|
|
253
|
-
const storedMessageToLegacyView = (message, allMessages = []) => {
|
|
254
|
-
if ("type" in message.msg) {
|
|
255
|
-
if (message.msg.role !== "human" && message.msg.role !== "ai") {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
return message;
|
|
259
|
-
}
|
|
260
|
-
const legacyPayload = copilotMessageToLegacyPayload(message.msg, allMessages);
|
|
261
|
-
if (legacyPayload) {
|
|
262
|
-
return {
|
|
263
|
-
...message,
|
|
264
|
-
createdAt: message.createdAt,
|
|
265
|
-
msg: legacyPayload,
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
return null;
|
|
42
|
+
return message;
|
|
269
43
|
};
|
|
270
44
|
export const useAgentChat = () => {
|
|
271
45
|
const context = useContext(AgentChatContext);
|
|
@@ -421,10 +195,7 @@ const resolveAgentChatConfig = async ({ agentChatId, token, }) => {
|
|
|
421
195
|
const agentBlock = await blocksApiService.getBlock(agentBlockId);
|
|
422
196
|
agentBlockData = agentBlock?.data;
|
|
423
197
|
}
|
|
424
|
-
const agentHarness = typeof agentBlockData?.harness === "string" ? agentBlockData.harness : undefined;
|
|
425
198
|
return {
|
|
426
|
-
agentBlockId: agentHarness ? agentBlockId : undefined,
|
|
427
|
-
agentHarness,
|
|
428
199
|
shortTermMemory: agentChatBlockData?.shortTermMemory ?? DEFAULT_SHORT_TERM_MEMORY,
|
|
429
200
|
useDynamicUI: agentChatBlockData?.useDynamicUI,
|
|
430
201
|
agentChatData: {
|
|
@@ -450,36 +221,7 @@ const createInitialAgentMessages = (initialMessages = []) => initialMessages
|
|
|
450
221
|
msg: { id, role: "ai", type: "text", content: initialMessage.content, payload: {} },
|
|
451
222
|
};
|
|
452
223
|
});
|
|
453
|
-
const mergeMessageItemsById = (currentMessages, incomingMessages) => {
|
|
454
|
-
const nextMessages = [...currentMessages];
|
|
455
|
-
for (const incomingMessage of incomingMessages) {
|
|
456
|
-
const existingIndex = nextMessages.findIndex((message) => message.msg.id === incomingMessage.msg.id);
|
|
457
|
-
if (existingIndex !== -1) {
|
|
458
|
-
nextMessages[existingIndex] = incomingMessage;
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
nextMessages.push(incomingMessage);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
nextMessages.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
|
|
465
|
-
return nextMessages;
|
|
466
|
-
};
|
|
467
224
|
const formatChatContext = (chatContext) => (chatContext ? `Context: \n${JSON.stringify(chatContext)}` : undefined);
|
|
468
|
-
export const buildHitlResumeRequestBody = ({ appId, agentBlockId, agentChatId, chatId, currentThreadId, noPersistency, shortTermMemory, chatContextFiles, chatContext, requestMessages, messageId, input, }) => ({
|
|
469
|
-
appId,
|
|
470
|
-
agentBlockId,
|
|
471
|
-
agentChatId,
|
|
472
|
-
chatId,
|
|
473
|
-
threadId: currentThreadId,
|
|
474
|
-
noPersistency,
|
|
475
|
-
shortTermMemory,
|
|
476
|
-
chatContextFiles,
|
|
477
|
-
chatContext: formatChatContext(chatContext),
|
|
478
|
-
files: [],
|
|
479
|
-
messages: requestMessages,
|
|
480
|
-
messageId,
|
|
481
|
-
hitlResume: input,
|
|
482
|
-
});
|
|
483
225
|
function useAgentChatInputState({ isThinking, isFetchingMessages, sendMessage, }) {
|
|
484
226
|
const [prompt, setPrompt] = useState("");
|
|
485
227
|
const [attachments, setAttachments] = useState([]);
|
|
@@ -518,42 +260,32 @@ function useAgentChatInputState({ isThinking, isFetchingMessages, sendMessage, }
|
|
|
518
260
|
setThreadIds,
|
|
519
261
|
};
|
|
520
262
|
}
|
|
521
|
-
function useAgentChatDataInitialization({ agentChatData, addMessages, sendMessage,
|
|
263
|
+
function useAgentChatDataInitialization({ agentChatData, addMessages, sendMessage, }) {
|
|
522
264
|
const initializedAgentChatDataRef = useRef(false);
|
|
523
265
|
useEffect(() => {
|
|
524
266
|
if (!agentChatData || initializedAgentChatDataRef.current) {
|
|
525
267
|
return;
|
|
526
268
|
}
|
|
527
|
-
if (!isAgentReady) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
269
|
const { initialMessages, initialPrompt } = agentChatData;
|
|
531
|
-
|
|
532
|
-
if (!isPersistentFlow && initialMessages && initialMessages.length > 0) {
|
|
270
|
+
if (initialMessages && initialMessages.length > 0) {
|
|
533
271
|
addMessages(createInitialAgentMessages(initialMessages));
|
|
534
272
|
}
|
|
535
273
|
if (initialPrompt?.content || initialPrompt?.hiddenContent) {
|
|
536
274
|
sendMessage({ content: initialPrompt?.content, hiddenContent: initialPrompt?.hiddenContent });
|
|
537
275
|
}
|
|
538
276
|
initializedAgentChatDataRef.current = true;
|
|
539
|
-
}, [agentChatData, sendMessage, addMessages
|
|
277
|
+
}, [agentChatData, sendMessage, addMessages]);
|
|
540
278
|
}
|
|
541
279
|
function AgentChatContextProvider({ children, ...value }) {
|
|
542
280
|
return _jsx(AgentChatContext.Provider, { value: value, children: children });
|
|
543
281
|
}
|
|
544
|
-
export const AgentChatRoot = ({ appId, token,
|
|
282
|
+
export const AgentChatRoot = ({ appId, token, agentChatId, children, chatId, noPersistency, defaultThreadId, chatContext, chatContextFiles, agentChatData, memoryEnabled = false, shortTermMemory, useDynamicUI, }) => {
|
|
545
283
|
const [resolvedAgentChatConfig, setResolvedAgentChatConfig] = useState(null);
|
|
546
284
|
const isResolvingAgentChatConfig = Boolean(agentChatId && !resolvedAgentChatConfig);
|
|
547
|
-
const effectiveAgentBlockId = resolvedAgentChatConfig?.agentBlockId ?? agentBlockId;
|
|
548
|
-
const effectiveAgentHarness = resolvedAgentChatConfig?.agentHarness ?? agentHarness;
|
|
549
285
|
const effectiveAgentChatData = agentChatData ?? resolvedAgentChatConfig?.agentChatData;
|
|
550
286
|
const effectiveShortTermMemory = shortTermMemory ?? resolvedAgentChatConfig?.shortTermMemory ?? DEFAULT_SHORT_TERM_MEMORY;
|
|
551
287
|
const effectiveUseDynamicUI = useDynamicUI ?? resolvedAgentChatConfig?.useDynamicUI;
|
|
552
|
-
const
|
|
553
|
-
const isNewAgent = Boolean(effectiveAgentBlockId && shouldUseAgentBlockDirectChat);
|
|
554
|
-
// isPersistent supersedes noPersistency on the new direct-chat path.
|
|
555
|
-
const isPersistentFlow = isNewAgent && Boolean(effectiveShortTermMemory?.isPersistent);
|
|
556
|
-
const effectiveNoPersistency = isNewAgent ? !effectiveShortTermMemory?.isPersistent : Boolean(noPersistency);
|
|
288
|
+
const effectiveNoPersistency = Boolean(noPersistency);
|
|
557
289
|
const [isFetchingMessages, setIsFetchingMessages] = useState(!effectiveNoPersistency);
|
|
558
290
|
const [currentThreadId, setCurrentThreadId] = useState(defaultThreadId);
|
|
559
291
|
const [fetchedMessages, setFetchedMessages] = useState([]);
|
|
@@ -607,81 +339,13 @@ export const AgentChatRoot = ({ appId, token, agentBlockId, agentHarness, useAge
|
|
|
607
339
|
return () => {
|
|
608
340
|
cancelled = true;
|
|
609
341
|
};
|
|
610
|
-
}, [appId, token, chatId, currentThreadId, effectiveNoPersistency, effectiveAgentChatData
|
|
611
|
-
// Stable ids per (chatId, threadId) — must match the ids the backend
|
|
612
|
-
// persists so the stream echo merges by id in the UI.
|
|
613
|
-
const initialAgentMessageIdsRef = useRef({});
|
|
614
|
-
const initialAgentMessages = useMemo(() => {
|
|
615
|
-
if (!isPersistentFlow || isFetchingMessages || fetchedMessages.length > 0) {
|
|
616
|
-
return [];
|
|
617
|
-
}
|
|
618
|
-
const initialMessages = effectiveAgentChatData?.initialMessages;
|
|
619
|
-
if (!initialMessages || initialMessages.length === 0) {
|
|
620
|
-
return [];
|
|
621
|
-
}
|
|
622
|
-
const validMessages = initialMessages.filter((im) => typeof im?.content === "string" && im.content.length > 0);
|
|
623
|
-
if (validMessages.length === 0) {
|
|
624
|
-
return [];
|
|
625
|
-
}
|
|
626
|
-
const cacheKey = `${chatId ?? "_"}|${currentThreadId ?? "_"}`;
|
|
627
|
-
const cached = initialAgentMessageIdsRef.current[cacheKey] ?? [];
|
|
628
|
-
const ids = [];
|
|
629
|
-
for (let i = 0; i < validMessages.length; i++) {
|
|
630
|
-
ids.push(cached[i] ?? generateId());
|
|
631
|
-
}
|
|
632
|
-
initialAgentMessageIdsRef.current[cacheKey] = ids;
|
|
633
|
-
return validMessages.map((initialMessage, i) => ({
|
|
634
|
-
id: ids[i],
|
|
635
|
-
createdAt: new Date(1).toISOString(),
|
|
636
|
-
msg: {
|
|
637
|
-
id: ids[i],
|
|
638
|
-
role: "ai",
|
|
639
|
-
type: "text",
|
|
640
|
-
content: initialMessage.content,
|
|
641
|
-
payload: {},
|
|
642
|
-
},
|
|
643
|
-
}));
|
|
644
|
-
}, [
|
|
645
|
-
isPersistentFlow,
|
|
646
|
-
isFetchingMessages,
|
|
647
|
-
fetchedMessages.length,
|
|
648
|
-
effectiveAgentChatData?.initialMessages,
|
|
649
|
-
chatId,
|
|
650
|
-
currentThreadId,
|
|
651
|
-
]);
|
|
342
|
+
}, [appId, token, chatId, currentThreadId, effectiveNoPersistency, effectiveAgentChatData]);
|
|
652
343
|
if (isResolvingAgentChatConfig) {
|
|
653
344
|
return null;
|
|
654
345
|
}
|
|
655
|
-
|
|
656
|
-
appId,
|
|
657
|
-
token,
|
|
658
|
-
agentBlockId: effectiveAgentBlockId,
|
|
659
|
-
agentHarness: effectiveAgentHarness,
|
|
660
|
-
useAgentBlockDirectChat,
|
|
661
|
-
agentChatId,
|
|
662
|
-
children,
|
|
663
|
-
chatId,
|
|
664
|
-
noPersistency,
|
|
665
|
-
defaultThreadId,
|
|
666
|
-
chatContext,
|
|
667
|
-
chatContextFiles,
|
|
668
|
-
agentChatData: effectiveAgentChatData,
|
|
669
|
-
memoryEnabled,
|
|
670
|
-
shortTermMemory: effectiveShortTermMemory,
|
|
671
|
-
useDynamicUI: effectiveUseDynamicUI,
|
|
672
|
-
isFetchingMessages,
|
|
673
|
-
currentThreadId,
|
|
674
|
-
setCurrentThreadId,
|
|
675
|
-
fetchedMessages,
|
|
676
|
-
initialAgentMessages,
|
|
677
|
-
isPersistentFlow,
|
|
678
|
-
};
|
|
679
|
-
if (isNewAgent) {
|
|
680
|
-
return _jsx(CopilotAgentChatRootProvider, { ...commonProps });
|
|
681
|
-
}
|
|
682
|
-
return _jsx(LegacyAgentChatProvider, { ...commonProps });
|
|
346
|
+
return (_jsx(LegacyAgentChatProvider, { appId: appId, token: token, agentChatId: agentChatId, chatId: chatId, noPersistency: noPersistency, defaultThreadId: defaultThreadId, chatContext: chatContext, chatContextFiles: chatContextFiles, agentChatData: effectiveAgentChatData, memoryEnabled: memoryEnabled, shortTermMemory: effectiveShortTermMemory, useDynamicUI: effectiveUseDynamicUI, isFetchingMessages: isFetchingMessages, currentThreadId: currentThreadId, setCurrentThreadId: setCurrentThreadId, fetchedMessages: fetchedMessages, children: children }));
|
|
683
347
|
};
|
|
684
|
-
function LegacyAgentChatProvider({ appId, token, agentChatId, children, chatId, noPersistency, currentThreadId, chatContext, chatContextFiles, agentChatData, memoryEnabled = false, shortTermMemory = { isEnabled: true, isPersistent: true }, isFetchingMessages, setCurrentThreadId, fetchedMessages,
|
|
348
|
+
function LegacyAgentChatProvider({ appId, token, agentChatId, children, chatId, noPersistency, currentThreadId, chatContext, chatContextFiles, agentChatData, memoryEnabled = false, shortTermMemory = { isEnabled: true, isPersistent: true }, isFetchingMessages, setCurrentThreadId, fetchedMessages, }) {
|
|
685
349
|
const [messages, setMessages] = useState([]);
|
|
686
350
|
const [isThinking, setIsThinking] = useState(false);
|
|
687
351
|
const addMessages = useCallback((messagesToAdd) => {
|
|
@@ -803,282 +467,13 @@ function LegacyAgentChatProvider({ appId, token, agentChatId, children, chatId,
|
|
|
803
467
|
memoryEnabled,
|
|
804
468
|
shortTermMemory,
|
|
805
469
|
]);
|
|
806
|
-
const submitToolResume = useCallback(async (input) => {
|
|
807
|
-
await sendMessage({
|
|
808
|
-
content: "",
|
|
809
|
-
hiddenContent: buildToolResumeHiddenContent(input),
|
|
810
|
-
});
|
|
811
|
-
}, [sendMessage]);
|
|
812
|
-
const submitAskUserAnswers = useCallback(async (input) => {
|
|
813
|
-
await sendMessage({
|
|
814
|
-
content: formatAskUserAnswerSummary(input.answers),
|
|
815
|
-
hiddenContent: buildAskUserAnswersHiddenContent(input),
|
|
816
|
-
});
|
|
817
|
-
}, [sendMessage]);
|
|
818
470
|
useAgentChatDataInitialization({
|
|
819
471
|
agentChatData,
|
|
820
472
|
addMessages,
|
|
821
473
|
sendMessage,
|
|
822
|
-
isPersistentFlow,
|
|
823
|
-
});
|
|
824
|
-
const inputState = useAgentChatInputState({ isThinking, isFetchingMessages, sendMessage });
|
|
825
|
-
return (_jsx(AgentChatContextProvider, { ...inputState, messages: flattenLegacyMessages(messages), initialAgentMessages: initialAgentMessages, isThinking: isThinking, isFetchingMessages: isFetchingMessages, currentThreadId: currentThreadId, agentChatData: agentChatData, sendMessage: sendMessage, submitToolResume: submitToolResume, submitAskUserAnswers: submitAskUserAnswers, addMessages: addMessages, setCurrentThreadId: setCurrentThreadId, appId: appId, token: token, agentChatId: agentChatId, chatId: chatId, noPersistency: noPersistency, children: children }));
|
|
826
|
-
}
|
|
827
|
-
function CopilotAgentChatRootProvider({ appId, token, ...props }) {
|
|
828
|
-
const copilotRuntimeUrl = `${getApiHost()}/agent-chat-stream`;
|
|
829
|
-
const agent = useMemo(() => new BlocksCopilotHttpAgent({ url: copilotRuntimeUrl }), [copilotRuntimeUrl]);
|
|
830
|
-
const agents = useMemo(() => ({ default: agent }), [agent]);
|
|
831
|
-
return (_jsx(CopilotKit, { runtimeUrl: copilotRuntimeUrl, agents__unsafe_dev_only: agents, children: _jsx(CopilotAgentChatProvider, { ...props, appId: appId, token: token, copilotAgent: agent }) }));
|
|
832
|
-
}
|
|
833
|
-
function CopilotAgentChatProvider({ appId, token, agentBlockId, agentChatId, children, chatId, noPersistency, currentThreadId, chatContext, chatContextFiles, agentChatData, shortTermMemory = { isEnabled: true, isPersistent: true }, useDynamicUI, isFetchingMessages, setCurrentThreadId, fetchedMessages, initialAgentMessages, isPersistentFlow, copilotAgent, }) {
|
|
834
|
-
const [externalMessages, setExternalMessages] = useState([]);
|
|
835
|
-
const copilotMessageCreatedAtByIdRef = useRef({});
|
|
836
|
-
const previousCopilotChatIdRef = useRef(undefined);
|
|
837
|
-
// Latest snapshot of public `messages` for callbacks that read it after an
|
|
838
|
-
// await. The closure value goes stale after `runHitlResume` resolves — the
|
|
839
|
-
// resume's stream events update copilotMessages → messages, but the callback
|
|
840
|
-
// still sees the value captured at invocation time.
|
|
841
|
-
const messagesRef = useRef([]);
|
|
842
|
-
const copilotChatId = useMemo(() => [appId, agentChatId, chatId, currentThreadId].filter(Boolean).join(":"), [appId, agentChatId, chatId, currentThreadId]);
|
|
843
|
-
const { messages: copilotMessages, sendMessage: sendCopilotMessage, setMessages: setCopilotMessages, isLoading: isCopilotLoading, } = useCopilotChatInternal();
|
|
844
|
-
// Wait one commit before firing the init send: CopilotKit's setup effect aborts the
|
|
845
|
-
// HttpAgent's AbortController on cleanup, killing any in-flight stream started before
|
|
846
|
-
// its `runtimeConnectionStatus` settles.
|
|
847
|
-
const [hasMounted, setHasMounted] = useState(false);
|
|
848
|
-
useEffect(() => {
|
|
849
|
-
setHasMounted(true);
|
|
850
|
-
}, []);
|
|
851
|
-
useEffect(() => {
|
|
852
|
-
if (previousCopilotChatIdRef.current === copilotChatId) {
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
previousCopilotChatIdRef.current = copilotChatId;
|
|
856
|
-
copilotMessageCreatedAtByIdRef.current = {};
|
|
857
|
-
setExternalMessages([]);
|
|
858
|
-
setCopilotMessages([]);
|
|
859
|
-
}, [copilotChatId, setCopilotMessages]);
|
|
860
|
-
const copilotMessageItems = useMemo(() => copilotMessages
|
|
861
|
-
.map((message) => {
|
|
862
|
-
const legacyPayload = copilotMessageToLegacyPayload(message, copilotMessages);
|
|
863
|
-
if (!legacyPayload) {
|
|
864
|
-
return null;
|
|
865
|
-
}
|
|
866
|
-
copilotMessageCreatedAtByIdRef.current[legacyPayload.id] ??= new Date().toISOString();
|
|
867
|
-
return {
|
|
868
|
-
createdAt: copilotMessageCreatedAtByIdRef.current[legacyPayload.id],
|
|
869
|
-
msg: legacyPayload,
|
|
870
|
-
};
|
|
871
|
-
})
|
|
872
|
-
.filter((message) => Boolean(message)), [copilotMessages]);
|
|
873
|
-
const messages = useMemo(() => {
|
|
874
|
-
const fetchedCopilotMessages = fetchedMessages
|
|
875
|
-
.map((message) => message.msg)
|
|
876
|
-
.filter((message) => !("type" in message));
|
|
877
|
-
const fetchedMessageItems = fetchedMessages
|
|
878
|
-
.map((message) => storedMessageToLegacyView(message, fetchedCopilotMessages))
|
|
879
|
-
.filter((message) => Boolean(message));
|
|
880
|
-
// Seed initial agent messages so the stream echo merges by id and keeps the early createdAt.
|
|
881
|
-
const nextMessages = mergeMessageItemsById(mergeMessageItemsById(initialAgentMessages, fetchedMessageItems), externalMessages);
|
|
882
|
-
for (const messageItem of copilotMessageItems) {
|
|
883
|
-
const existingIndex = nextMessages.findIndex((message) => message.msg.id === messageItem.msg.id);
|
|
884
|
-
if (existingIndex !== -1) {
|
|
885
|
-
nextMessages[existingIndex] = {
|
|
886
|
-
...nextMessages[existingIndex],
|
|
887
|
-
...messageItem,
|
|
888
|
-
createdAt: nextMessages[existingIndex].createdAt,
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
nextMessages.push(messageItem);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
nextMessages.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
|
|
896
|
-
return nextMessages;
|
|
897
|
-
}, [copilotMessageItems, externalMessages, fetchedMessages, initialAgentMessages]);
|
|
898
|
-
const isThinking = isCopilotLoading;
|
|
899
|
-
useEffect(() => {
|
|
900
|
-
messagesRef.current = messages;
|
|
901
|
-
}, [messages]);
|
|
902
|
-
const addExternalMessages = useCallback((messagesToAdd) => {
|
|
903
|
-
const copilotMessagesToAdd = messagesToAdd
|
|
904
|
-
.map((message) => message.msg)
|
|
905
|
-
.filter((message) => !("type" in message));
|
|
906
|
-
const normalizedMessages = messagesToAdd
|
|
907
|
-
.map((message) => storedMessageToLegacyView(message, copilotMessagesToAdd))
|
|
908
|
-
.filter((message) => Boolean(message));
|
|
909
|
-
setExternalMessages((prevMessages) => mergeMessageItemsById(prevMessages, normalizedMessages));
|
|
910
|
-
}, []);
|
|
911
|
-
const addCopilotErrorMessage = useCallback((error) => {
|
|
912
|
-
setCopilotMessages(appendCopilotErrorMessage(copilotMessages, error));
|
|
913
|
-
}, [copilotMessages, setCopilotMessages]);
|
|
914
|
-
const runHitlResume = useCallback(async (input) => {
|
|
915
|
-
const messageId = generateId();
|
|
916
|
-
const hiddenContent = buildToolResumeHiddenContent(input);
|
|
917
|
-
const userCopilotMessage = {
|
|
918
|
-
id: messageId,
|
|
919
|
-
role: "user",
|
|
920
|
-
content: "",
|
|
921
|
-
metadata: { version: 1, hiddenPrompt: hiddenContent, kind: "tool-resume" },
|
|
922
|
-
};
|
|
923
|
-
// Always read the latest snapshot — the resume flow can be invoked from
|
|
924
|
-
// sendMessage's skipped path right after another awaited resume settled.
|
|
925
|
-
const latestMessages = messagesRef.current;
|
|
926
|
-
const requestMessages = latestMessages
|
|
927
|
-
.map(messageItemToCopilotMessage)
|
|
928
|
-
.filter((requestMessage) => Boolean(requestMessage));
|
|
929
|
-
setCopilotMessages(requestMessages);
|
|
930
|
-
copilotAgent.setRequestOptions({
|
|
931
|
-
headers: {
|
|
932
|
-
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
933
|
-
...(AppVersionService.getCurrentVersionNumber()
|
|
934
|
-
? { "x-app-version": String(AppVersionService.getCurrentVersionNumber()) }
|
|
935
|
-
: {}),
|
|
936
|
-
...(websocketsService.getSocketId() ? { "x-socket-id": websocketsService.getSocketId() } : {}),
|
|
937
|
-
...(appId ? { "x-app-id": appId } : {}),
|
|
938
|
-
},
|
|
939
|
-
body: buildHitlResumeRequestBody({
|
|
940
|
-
appId,
|
|
941
|
-
agentBlockId,
|
|
942
|
-
agentChatId,
|
|
943
|
-
chatId,
|
|
944
|
-
currentThreadId,
|
|
945
|
-
noPersistency,
|
|
946
|
-
shortTermMemory,
|
|
947
|
-
chatContextFiles,
|
|
948
|
-
chatContext,
|
|
949
|
-
requestMessages,
|
|
950
|
-
messageId,
|
|
951
|
-
input,
|
|
952
|
-
}),
|
|
953
|
-
});
|
|
954
|
-
try {
|
|
955
|
-
await sendCopilotMessage(userCopilotMessage);
|
|
956
|
-
}
|
|
957
|
-
finally {
|
|
958
|
-
copilotAgent.clearRequestOptions();
|
|
959
|
-
}
|
|
960
|
-
}, [
|
|
961
|
-
agentBlockId,
|
|
962
|
-
agentChatId,
|
|
963
|
-
appId,
|
|
964
|
-
chatId,
|
|
965
|
-
chatContext,
|
|
966
|
-
chatContextFiles,
|
|
967
|
-
copilotAgent,
|
|
968
|
-
currentThreadId,
|
|
969
|
-
noPersistency,
|
|
970
|
-
sendCopilotMessage,
|
|
971
|
-
setCopilotMessages,
|
|
972
|
-
shortTermMemory,
|
|
973
|
-
token,
|
|
974
|
-
]);
|
|
975
|
-
const sendMessage = useCallback(async ({ content, hiddenContent, ...message }) => {
|
|
976
|
-
try {
|
|
977
|
-
const pendingAskUser = findPendingAskUserToolCall(messages);
|
|
978
|
-
if (pendingAskUser?.toolCallId) {
|
|
979
|
-
await runHitlResume({
|
|
980
|
-
toolCallId: pendingAskUser.toolCallId,
|
|
981
|
-
toolName: ASK_USER_TOOL_NAME,
|
|
982
|
-
type: "ask_user",
|
|
983
|
-
answers: [],
|
|
984
|
-
skipped: true,
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
const messageId = generateId();
|
|
988
|
-
const uploadedAttachments = await uploadAttachments({ attachments: message.attachments, appId, token });
|
|
989
|
-
const userCopilotMessage = {
|
|
990
|
-
id: messageId,
|
|
991
|
-
role: "user",
|
|
992
|
-
content: content ?? "",
|
|
993
|
-
metadata: { version: 1, hiddenPrompt: hiddenContent ?? undefined },
|
|
994
|
-
};
|
|
995
|
-
// Read the latest messages snapshot (the closure value is stale after
|
|
996
|
-
// the awaited skipped resume — it still reflects the state before the
|
|
997
|
-
// resume's stream populated copilotMessages with the resolved tool
|
|
998
|
-
// result and any AI follow-up).
|
|
999
|
-
const latestMessages = messagesRef.current;
|
|
1000
|
-
const requestMessages = latestMessages
|
|
1001
|
-
.map(messageItemToCopilotMessage)
|
|
1002
|
-
.filter((requestMessage) => Boolean(requestMessage));
|
|
1003
|
-
setCopilotMessages(requestMessages);
|
|
1004
|
-
copilotAgent.setRequestOptions({
|
|
1005
|
-
headers: {
|
|
1006
|
-
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
1007
|
-
...(AppVersionService.getCurrentVersionNumber()
|
|
1008
|
-
? { "x-app-version": String(AppVersionService.getCurrentVersionNumber()) }
|
|
1009
|
-
: {}),
|
|
1010
|
-
...(websocketsService.getSocketId() ? { "x-socket-id": websocketsService.getSocketId() } : {}),
|
|
1011
|
-
...(appId ? { "x-app-id": appId } : {}),
|
|
1012
|
-
},
|
|
1013
|
-
body: {
|
|
1014
|
-
appId,
|
|
1015
|
-
agentBlockId,
|
|
1016
|
-
agentChatId,
|
|
1017
|
-
chatId,
|
|
1018
|
-
threadId: currentThreadId,
|
|
1019
|
-
noPersistency,
|
|
1020
|
-
shortTermMemory,
|
|
1021
|
-
useDynamicUI,
|
|
1022
|
-
chatContextFiles,
|
|
1023
|
-
chatContext: formatChatContext(chatContext),
|
|
1024
|
-
files: uploadedAttachments,
|
|
1025
|
-
messages: [...requestMessages, userCopilotMessage],
|
|
1026
|
-
messageId,
|
|
1027
|
-
initialMessageIds: initialAgentMessages.map((m) => m.msg.id),
|
|
1028
|
-
},
|
|
1029
|
-
});
|
|
1030
|
-
await sendCopilotMessage(userCopilotMessage);
|
|
1031
|
-
}
|
|
1032
|
-
catch (error) {
|
|
1033
|
-
addCopilotErrorMessage(error);
|
|
1034
|
-
}
|
|
1035
|
-
finally {
|
|
1036
|
-
copilotAgent.clearRequestOptions();
|
|
1037
|
-
}
|
|
1038
|
-
}, [
|
|
1039
|
-
addCopilotErrorMessage,
|
|
1040
|
-
agentBlockId,
|
|
1041
|
-
agentChatId,
|
|
1042
|
-
appId,
|
|
1043
|
-
chatId,
|
|
1044
|
-
chatContext,
|
|
1045
|
-
chatContextFiles,
|
|
1046
|
-
copilotAgent,
|
|
1047
|
-
currentThreadId,
|
|
1048
|
-
messages,
|
|
1049
|
-
noPersistency,
|
|
1050
|
-
runHitlResume,
|
|
1051
|
-
sendCopilotMessage,
|
|
1052
|
-
setCopilotMessages,
|
|
1053
|
-
shortTermMemory,
|
|
1054
|
-
token,
|
|
1055
|
-
initialAgentMessages,
|
|
1056
|
-
useDynamicUI,
|
|
1057
|
-
]);
|
|
1058
|
-
const submitToolResume = useCallback(async (input) => {
|
|
1059
|
-
try {
|
|
1060
|
-
await runHitlResume(input);
|
|
1061
|
-
}
|
|
1062
|
-
catch (error) {
|
|
1063
|
-
addCopilotErrorMessage(error);
|
|
1064
|
-
}
|
|
1065
|
-
}, [addCopilotErrorMessage, runHitlResume]);
|
|
1066
|
-
const submitAskUserAnswers = useCallback(async (input) => {
|
|
1067
|
-
await submitToolResume({
|
|
1068
|
-
...input,
|
|
1069
|
-
toolName: input.toolName ?? ASK_USER_TOOL_NAME,
|
|
1070
|
-
type: "ask_user",
|
|
1071
|
-
});
|
|
1072
|
-
}, [submitToolResume]);
|
|
1073
|
-
useAgentChatDataInitialization({
|
|
1074
|
-
agentChatData,
|
|
1075
|
-
addMessages: addExternalMessages,
|
|
1076
|
-
sendMessage,
|
|
1077
|
-
isPersistentFlow,
|
|
1078
|
-
isAgentReady: hasMounted && (!isPersistentFlow || (!isFetchingMessages && fetchedMessages.length === 0)),
|
|
1079
474
|
});
|
|
1080
475
|
const inputState = useAgentChatInputState({ isThinking, isFetchingMessages, sendMessage });
|
|
1081
|
-
return (_jsx(AgentChatContextProvider, { ...inputState, messages: messages,
|
|
476
|
+
return (_jsx(AgentChatContextProvider, { ...inputState, messages: flattenLegacyMessages(messages), isThinking: isThinking, isFetchingMessages: isFetchingMessages, currentThreadId: currentThreadId, agentChatData: agentChatData, sendMessage: sendMessage, addMessages: addMessages, setCurrentThreadId: setCurrentThreadId, appId: appId, token: token, agentChatId: agentChatId, chatId: chatId, noPersistency: noPersistency, children: children }));
|
|
1082
477
|
}
|
|
1083
478
|
const AgentChatVoiceContext = createContext(null);
|
|
1084
479
|
const noopVoice = {
|
|
@@ -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"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAK/D,OAAO,EAEL,SAAS,EACT,cAAc,EAQf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAOtH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;
|
|
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;AAK/D,OAAO,EAEL,SAAS,EACT,cAAc,EAQf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAOtH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,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f,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,16 +135,44 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
123
135
|
}
|
|
124
136
|
return agentChatBlock;
|
|
125
137
|
}, [agentChatId, blocksApiService]);
|
|
126
|
-
const
|
|
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]);
|
|
165
|
+
const componentIdsKey = componentIds?.join(",") ?? "";
|
|
166
|
+
const sendAgentInitialPrompt = useCallback(async (agentInitialPrompt) => {
|
|
127
167
|
if (!agentInitialPrompt) {
|
|
128
168
|
return;
|
|
129
169
|
}
|
|
130
170
|
const { content, hiddenContent } = agentInitialPrompt;
|
|
131
171
|
if (content) {
|
|
132
|
-
sendMessage({ content });
|
|
172
|
+
await sendMessage({ content });
|
|
133
173
|
}
|
|
134
174
|
if (hiddenContent) {
|
|
135
|
-
sendMessage({ content: hiddenContent });
|
|
175
|
+
await sendMessage({ content: hiddenContent });
|
|
136
176
|
}
|
|
137
177
|
}, [sendMessage]);
|
|
138
178
|
const initKeyRef = useRef(null);
|
|
@@ -146,6 +186,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
146
186
|
currentThreadId ?? "",
|
|
147
187
|
agentId ?? "",
|
|
148
188
|
agentChatId ?? "",
|
|
189
|
+
componentIdsKey,
|
|
149
190
|
token ?? "",
|
|
150
191
|
appId ?? "",
|
|
151
192
|
].join("|");
|
|
@@ -160,7 +201,10 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
160
201
|
try {
|
|
161
202
|
const agentChatBlock = await getAgentChatBlock();
|
|
162
203
|
const effectiveAgentId = agentId ?? agentChatBlock?.data?.agentBlockId;
|
|
163
|
-
const agentBlock =
|
|
204
|
+
const [agentBlock, chatComponentBlocks] = await Promise.all([
|
|
205
|
+
effectiveAgentId ? blocksApiService.getBlock(effectiveAgentId) : null,
|
|
206
|
+
getChatComponentBlocks(),
|
|
207
|
+
]);
|
|
164
208
|
if (ac.signal.aborted) {
|
|
165
209
|
return;
|
|
166
210
|
}
|
|
@@ -172,6 +216,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
172
216
|
disableGeneratingDynamicChatComponent: agentChatBlock.data.disableGeneratingDynamicChatComponent,
|
|
173
217
|
hideToolsUi: agentChatBlock.data.hideToolsUi,
|
|
174
218
|
});
|
|
219
|
+
setComponents(chatComponentBlocks);
|
|
175
220
|
setAgent({
|
|
176
221
|
id: agentBlock.id,
|
|
177
222
|
title: agentBlock?.data?.title,
|
|
@@ -198,7 +243,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
198
243
|
initialPromptSentRef.current = false;
|
|
199
244
|
};
|
|
200
245
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
201
|
-
}, [chatId, currentThreadId, agentId, agentChatId, token, appId]);
|
|
246
|
+
}, [chatId, currentThreadId, agentId, agentChatId, componentIdsKey, token, appId]);
|
|
202
247
|
// After CopilotKit's `connectAgent` resolves, the agent's message list
|
|
203
248
|
// already reflects whatever the backend replayed (history + any
|
|
204
249
|
// seeded initial messages). If the thread is still empty AND the
|
|
@@ -211,8 +256,18 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
211
256
|
// a render-order race where `isAgentReady` flips true before the
|
|
212
257
|
// mirrored React state catches up, which would otherwise double-send
|
|
213
258
|
// the prompt on top of replayed history.
|
|
259
|
+
//
|
|
260
|
+
// `canSendMessage` is also part of the gate: `sendMessage` silently
|
|
261
|
+
// no-ops when its closed-over `canSendMessage` is false (e.g. while
|
|
262
|
+
// the `agent` mirror is committing or CopilotKit briefly reports
|
|
263
|
+
// `isLoading`). Without this guard the optimistic `initialPromptSentRef`
|
|
264
|
+
// flip below would lock the prompt out forever after a single
|
|
265
|
+
// dropped call. Re-runs as soon as the gate opens.
|
|
214
266
|
useEffect(() => {
|
|
215
|
-
if (
|
|
267
|
+
if (initialPromptSentRef.current) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (!isAgentReady || !isConfigLoaded) {
|
|
216
271
|
return;
|
|
217
272
|
}
|
|
218
273
|
if (!agentChat?.initialPrompt) {
|
|
@@ -222,10 +277,16 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
222
277
|
initialPromptSentRef.current = true;
|
|
223
278
|
return;
|
|
224
279
|
}
|
|
280
|
+
if (!canSendMessage) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
225
283
|
initialPromptSentRef.current = true;
|
|
226
|
-
sendAgentInitialPrompt(agentChat.initialPrompt);
|
|
227
|
-
}, [isAgentReady, isConfigLoaded, agentChat, copilotAgent, sendAgentInitialPrompt]);
|
|
284
|
+
void sendAgentInitialPrompt(agentChat.initialPrompt);
|
|
285
|
+
}, [isAgentReady, isConfigLoaded, agentChat, copilotAgent, canSendMessage, sendAgentInitialPrompt]);
|
|
228
286
|
const sendFromInputs = async () => {
|
|
287
|
+
if (!canSendMessage) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
229
290
|
const currentPrompt = prompt;
|
|
230
291
|
// const currentAttachments = attachments;
|
|
231
292
|
setPrompt("");
|
|
@@ -285,6 +346,7 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
285
346
|
attachments,
|
|
286
347
|
sendMessage,
|
|
287
348
|
sendFromInputs,
|
|
349
|
+
stopGeneration,
|
|
288
350
|
addAttachments,
|
|
289
351
|
removeAttachment,
|
|
290
352
|
clearAttachments,
|
|
@@ -298,18 +360,16 @@ const ChatInitializer = ({ agentId, agentChatId, chatId, token, appId, currentTh
|
|
|
298
360
|
isAgentReady,
|
|
299
361
|
agentChat,
|
|
300
362
|
agent,
|
|
363
|
+
components,
|
|
301
364
|
currentThreadId,
|
|
302
365
|
}, children: children }));
|
|
303
366
|
};
|
|
304
367
|
export const AgentChatRoot = ({ ...props
|
|
305
|
-
// agentHarness,
|
|
306
|
-
// useAgentBlockDirectChat,
|
|
307
|
-
// chatContextFiles,
|
|
308
368
|
// agentChatData,
|
|
309
369
|
// memoryEnabled = false,
|
|
310
370
|
// shortTermMemory,
|
|
311
371
|
}) => {
|
|
312
|
-
const { appId, token, children, agentId, agentChatId, chatId, defaultThreadId, noPersistency, chatContext } = props;
|
|
372
|
+
const { appId, token, children, agentId, agentHarness, useAgentBlockDirectChat, agentChatId, componentIds, chatId, defaultThreadId, noPersistency, chatContext, chatContextFiles, } = props;
|
|
313
373
|
const currentAppVersion = AppVersionService.getCurrentVersionNumber();
|
|
314
374
|
const socketId = websocketsService.getSocketId();
|
|
315
375
|
const headers = useMemo(() => ({
|
|
@@ -320,15 +380,22 @@ export const AgentChatRoot = ({ ...props
|
|
|
320
380
|
}), [token, currentAppVersion, socketId, appId]);
|
|
321
381
|
const [currentThreadId, setCurrentThreadId] = useState(() => defaultThreadId ?? (noPersistency ? crypto.randomUUID() : DEFAULT_CHAT_THREAD_ID));
|
|
322
382
|
const chatContextStr = chatContext == null ? undefined : typeof chatContext === "string" ? chatContext : JSON.stringify(chatContext);
|
|
383
|
+
if (!appId || !agentChatId) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
323
386
|
return (_jsxs(CopilotKit, { runtimeUrl: `${getApiHost()}/agent-chat-stream`, agent: "default", headers: headers, threadId: currentThreadId,
|
|
324
387
|
// debug={true}
|
|
325
388
|
properties: {
|
|
326
389
|
appId,
|
|
327
390
|
agentId,
|
|
391
|
+
agentHarness,
|
|
392
|
+
useAgentBlockDirectChat,
|
|
328
393
|
agentChatId,
|
|
329
394
|
chatId,
|
|
395
|
+
noPersistency,
|
|
330
396
|
chatContext: chatContextStr,
|
|
331
|
-
|
|
397
|
+
chatContextFiles,
|
|
398
|
+
}, 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
399
|
};
|
|
333
400
|
export function AgentChatMessage({ message, index, ...props }) {
|
|
334
401
|
return _jsx("div", { "data-message-index": index, "data-message-role": message.role, ...props });
|
|
@@ -367,7 +434,8 @@ export function AgentChatFetching({ asChild = false, ...props }) {
|
|
|
367
434
|
return _jsx(Comp, { "data-slot": "agent-chat-fetching", ...props });
|
|
368
435
|
}
|
|
369
436
|
export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste, onDragOver, onDragLeave, onDrop, onSubmit, acceptFiles = true, ...props }) {
|
|
370
|
-
const { setIsDraggingFiles, addAttachments, prompt, setPrompt, sendFromInputs } = useAgentChat();
|
|
437
|
+
const { setIsDraggingFiles, addAttachments, prompt, setPrompt, sendFromInputs, isThinking, isAgentReady, isFetchingMessages, } = useAgentChat();
|
|
438
|
+
const isDisabled = props.disabled || isThinking || !isAgentReady || isFetchingMessages;
|
|
371
439
|
const handleDragOver = useCallback((e) => {
|
|
372
440
|
if (!acceptFiles) {
|
|
373
441
|
return;
|
|
@@ -402,10 +470,13 @@ export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste,
|
|
|
402
470
|
const handleKeyDown = useCallback((e) => {
|
|
403
471
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
404
472
|
e.preventDefault();
|
|
473
|
+
if (isDisabled) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
405
476
|
onSubmit?.(e);
|
|
406
477
|
sendFromInputs();
|
|
407
478
|
}
|
|
408
|
-
}, [
|
|
479
|
+
}, [isDisabled, onSubmit, sendFromInputs]);
|
|
409
480
|
const handleChange = useCallback((e) => {
|
|
410
481
|
setPrompt(e.target.value);
|
|
411
482
|
}, [setPrompt]);
|
|
@@ -455,11 +526,20 @@ export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste,
|
|
|
455
526
|
: onDrop, "data-slot": "agent-chat-input", ...props }));
|
|
456
527
|
}
|
|
457
528
|
export function AgentChatSendTrigger({ asChild = false, onClick, disabled, ...props }) {
|
|
458
|
-
const { isThinking, isAgentReady, isFetchingMessages, sendFromInputs } = useAgentChat();
|
|
529
|
+
const { isThinking, isAgentReady, isFetchingMessages, sendFromInputs, stopGeneration } = useAgentChat();
|
|
459
530
|
const Comp = asChild ? Slot : "button";
|
|
460
|
-
const isDisabled = disabled ?? (isThinking
|
|
531
|
+
const isDisabled = disabled ?? (!isThinking && (!isAgentReady || isFetchingMessages));
|
|
461
532
|
return (_jsx(Comp, { onClick: (e) => {
|
|
462
|
-
|
|
533
|
+
if (isDisabled) {
|
|
534
|
+
e.preventDefault();
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
if (isThinking) {
|
|
538
|
+
stopGeneration();
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
sendFromInputs();
|
|
542
|
+
}
|
|
463
543
|
onClick?.(e);
|
|
464
544
|
}, disabled: isDisabled, "data-slot": "agent-chat-send-trigger", ...props }));
|
|
465
545
|
}
|