@yourgpt/copilot-sdk 2.1.2 → 2.1.4
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/{chunk-XAC7NTIO.js → chunk-37KEHUCE.js} +14 -10
- package/dist/chunk-37KEHUCE.js.map +1 -0
- package/dist/{chunk-VXT2O6R6.js → chunk-7PKGRYHY.js} +278 -82
- package/dist/chunk-7PKGRYHY.js.map +1 -0
- package/dist/{chunk-VUHP6TAN.js → chunk-LZMBBGWH.js} +3 -3
- package/dist/{chunk-VUHP6TAN.js.map → chunk-LZMBBGWH.js.map} +1 -1
- package/dist/{chunk-BNBEKK3U.cjs → chunk-N6VZ7FOW.cjs} +302 -106
- package/dist/chunk-N6VZ7FOW.cjs.map +1 -0
- package/dist/{chunk-7MZLBGFQ.cjs → chunk-OQPRIB73.cjs} +33 -29
- package/dist/chunk-OQPRIB73.cjs.map +1 -0
- package/dist/{chunk-CSEZZ5DX.cjs → chunk-POZNNKNJ.cjs} +2 -2
- package/dist/{chunk-CSEZZ5DX.cjs.map → chunk-POZNNKNJ.cjs.map} +1 -1
- package/dist/{chunk-BMYNG3WM.js → chunk-QLH6TSCC.js} +2 -2
- package/dist/{chunk-BMYNG3WM.js.map → chunk-QLH6TSCC.js.map} +1 -1
- package/dist/{chunk-GSTTJ46F.cjs → chunk-WAPGTQDR.cjs} +5 -5
- package/dist/{chunk-GSTTJ46F.cjs.map → chunk-WAPGTQDR.cjs.map} +1 -1
- package/dist/core/index.cjs +80 -80
- package/dist/core/index.d.cts +17 -6
- package/dist/core/index.d.ts +17 -6
- package/dist/core/index.js +3 -3
- package/dist/{index-jwRcC2QD.d.cts → index-BHkRA0mM.d.cts} +1 -1
- package/dist/{index-Du3Akr_E.d.ts → index-tB0qI8my.d.ts} +1 -1
- package/dist/mcp/index.d.cts +3 -3
- package/dist/mcp/index.d.ts +3 -3
- package/dist/react/index.cjs +53 -49
- package/dist/react/index.d.cts +78 -19
- package/dist/react/index.d.ts +78 -19
- package/dist/react/index.js +4 -4
- package/dist/tools/anthropic/index.d.cts +1 -1
- package/dist/tools/anthropic/index.d.ts +1 -1
- package/dist/tools/brave/index.cjs +2 -2
- package/dist/tools/brave/index.d.cts +1 -1
- package/dist/tools/brave/index.d.ts +1 -1
- package/dist/tools/brave/index.js +1 -1
- package/dist/tools/exa/index.cjs +2 -2
- package/dist/tools/exa/index.d.cts +1 -1
- package/dist/tools/exa/index.d.ts +1 -1
- package/dist/tools/exa/index.js +1 -1
- package/dist/tools/google/index.cjs +2 -2
- package/dist/tools/google/index.d.cts +1 -1
- package/dist/tools/google/index.d.ts +1 -1
- package/dist/tools/google/index.js +1 -1
- package/dist/tools/openai/index.cjs +2 -2
- package/dist/tools/openai/index.d.cts +1 -1
- package/dist/tools/openai/index.d.ts +1 -1
- package/dist/tools/openai/index.js +1 -1
- package/dist/tools/searxng/index.cjs +2 -2
- package/dist/tools/searxng/index.d.cts +1 -1
- package/dist/tools/searxng/index.d.ts +1 -1
- package/dist/tools/searxng/index.js +1 -1
- package/dist/tools/serper/index.cjs +2 -2
- package/dist/tools/serper/index.d.cts +1 -1
- package/dist/tools/serper/index.d.ts +1 -1
- package/dist/tools/serper/index.js +1 -1
- package/dist/tools/tavily/index.cjs +2 -2
- package/dist/tools/tavily/index.d.cts +1 -1
- package/dist/tools/tavily/index.d.ts +1 -1
- package/dist/tools/tavily/index.js +1 -1
- package/dist/tools/web-search/index.cjs +3 -3
- package/dist/tools/web-search/index.d.cts +2 -2
- package/dist/tools/web-search/index.d.ts +2 -2
- package/dist/tools/web-search/index.js +2 -2
- package/dist/{tools-BHQRB_YT.d.cts → tools-coIcskZ4.d.cts} +18 -4
- package/dist/{tools-BHQRB_YT.d.ts → tools-coIcskZ4.d.ts} +18 -4
- package/dist/{types-8_Hp2rmm.d.cts → types-C8t4Ut8f.d.cts} +1 -1
- package/dist/{types-OYi-iUVY.d.ts → types-rjaSVmEF.d.ts} +1 -1
- package/dist/ui/index.cjs +8 -8
- package/dist/ui/index.d.cts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-7MZLBGFQ.cjs.map +0 -1
- package/dist/chunk-BNBEKK3U.cjs.map +0 -1
- package/dist/chunk-VXT2O6R6.js.map +0 -1
- package/dist/chunk-XAC7NTIO.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThreadManager, isConsoleCaptureActive, startConsoleCapture, isNetworkCaptureActive, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, isScreenshotSupported, captureScreenshot, getConsoleLogs, getNetworkRequests, clearConsoleLogs, clearNetworkRequests, formatLogsForAI, formatRequestsForAI, detectIntent, streamSSE, zodObjectToInputSchema } from './chunk-
|
|
1
|
+
import { ThreadManager, isConsoleCaptureActive, startConsoleCapture, isNetworkCaptureActive, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, isScreenshotSupported, captureScreenshot, getConsoleLogs, getNetworkRequests, clearConsoleLogs, clearNetworkRequests, formatLogsForAI, formatRequestsForAI, detectIntent, zodToJsonSchema, streamSSE, zodObjectToInputSchema } from './chunk-37KEHUCE.js';
|
|
2
2
|
import { createMCPClient, MCPToolAdapter } from './chunk-EWVQWTNV.js';
|
|
3
3
|
import { createContext, useRef, useState, useCallback, useEffect, useMemo, useContext, useSyncExternalStore } from 'react';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
@@ -362,17 +362,11 @@ var HttpTransport = class {
|
|
|
362
362
|
this.abortController = new AbortController();
|
|
363
363
|
this.streaming = true;
|
|
364
364
|
try {
|
|
365
|
-
console.log(
|
|
366
|
-
"[HttpTransport] Config headers type:",
|
|
367
|
-
typeof this.config.headers
|
|
368
|
-
);
|
|
369
|
-
console.log("[HttpTransport] Config headers:", this.config.headers);
|
|
370
365
|
const resolved = await resolveValues({
|
|
371
366
|
url: this.config.url,
|
|
372
367
|
headers: this.config.headers ?? {},
|
|
373
368
|
configBody: this.config.body ?? {}
|
|
374
369
|
});
|
|
375
|
-
console.log("[HttpTransport] Resolved headers:", resolved.headers);
|
|
376
370
|
const response = await fetch(resolved.url, {
|
|
377
371
|
method: "POST",
|
|
378
372
|
headers: {
|
|
@@ -528,16 +522,16 @@ var HttpTransport = class {
|
|
|
528
522
|
};
|
|
529
523
|
|
|
530
524
|
// src/chat/classes/AbstractChat.ts
|
|
531
|
-
function buildToolResultContentForAI(result,
|
|
525
|
+
function buildToolResultContentForAI(result, tool2, args) {
|
|
532
526
|
if (typeof result === "string") return result;
|
|
533
527
|
const typedResult = result;
|
|
534
|
-
const responseMode = typedResult?._aiResponseMode ??
|
|
528
|
+
const responseMode = typedResult?._aiResponseMode ?? tool2?.aiResponseMode ?? "full";
|
|
535
529
|
if (typedResult?._aiContent) {
|
|
536
530
|
return JSON.stringify(typedResult._aiContent);
|
|
537
531
|
}
|
|
538
532
|
let aiContext = typedResult?._aiContext;
|
|
539
|
-
if (!aiContext &&
|
|
540
|
-
aiContext = typeof
|
|
533
|
+
if (!aiContext && tool2?.aiContext) {
|
|
534
|
+
aiContext = typeof tool2.aiContext === "function" ? tool2.aiContext(typedResult, args ?? {}) : tool2.aiContext;
|
|
541
535
|
}
|
|
542
536
|
switch (responseMode) {
|
|
543
537
|
case "none":
|
|
@@ -893,10 +887,10 @@ var AbstractChat = class {
|
|
|
893
887
|
* Build the request payload
|
|
894
888
|
*/
|
|
895
889
|
buildRequest() {
|
|
896
|
-
const tools = this.config.tools?.filter((
|
|
897
|
-
name:
|
|
898
|
-
description:
|
|
899
|
-
inputSchema:
|
|
890
|
+
const tools = this.config.tools?.filter((tool2) => tool2.available !== false).map((tool2) => ({
|
|
891
|
+
name: tool2.name,
|
|
892
|
+
description: tool2.description,
|
|
893
|
+
inputSchema: tool2.inputSchema
|
|
900
894
|
}));
|
|
901
895
|
const toolCallMap = /* @__PURE__ */ new Map();
|
|
902
896
|
for (const msg of this.state.messages) {
|
|
@@ -913,11 +907,11 @@ var AbstractChat = class {
|
|
|
913
907
|
}
|
|
914
908
|
const toolDefMap = /* @__PURE__ */ new Map();
|
|
915
909
|
if (this.config.tools) {
|
|
916
|
-
for (const
|
|
917
|
-
toolDefMap.set(
|
|
918
|
-
name:
|
|
919
|
-
aiResponseMode:
|
|
920
|
-
aiContext:
|
|
910
|
+
for (const tool2 of this.config.tools) {
|
|
911
|
+
toolDefMap.set(tool2.name, {
|
|
912
|
+
name: tool2.name,
|
|
913
|
+
aiResponseMode: tool2.aiResponseMode,
|
|
914
|
+
aiContext: tool2.aiContext
|
|
921
915
|
});
|
|
922
916
|
}
|
|
923
917
|
}
|
|
@@ -989,7 +983,70 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
|
|
|
989
983
|
this.handleError(error);
|
|
990
984
|
return;
|
|
991
985
|
}
|
|
986
|
+
if (chunk.type === "message:end" && this.streamState?.content) {
|
|
987
|
+
this.debug("message:end mid-stream - finalizing current turn");
|
|
988
|
+
const turnMessage = streamStateToMessage(this.streamState);
|
|
989
|
+
const toolCallsHidden = {};
|
|
990
|
+
for (const [id, result] of this.streamState.toolResults) {
|
|
991
|
+
if (result.hidden !== void 0) {
|
|
992
|
+
toolCallsHidden[id] = result.hidden;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (turnMessage.toolCalls?.length && Object.keys(toolCallsHidden).length > 0) {
|
|
996
|
+
turnMessage.metadata = {
|
|
997
|
+
...turnMessage.metadata,
|
|
998
|
+
toolCallsHidden
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
this.state.updateMessageById(
|
|
1002
|
+
this.streamState.messageId,
|
|
1003
|
+
() => turnMessage
|
|
1004
|
+
);
|
|
1005
|
+
this.callbacks.onMessageFinish?.(turnMessage);
|
|
1006
|
+
this.streamState = null;
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
if (chunk.type === "message:start" && this.streamState === null) {
|
|
1010
|
+
this.debug("message:start after mid-stream end - creating new message");
|
|
1011
|
+
const newMessage = createEmptyAssistantMessage();
|
|
1012
|
+
this.state.pushMessage(newMessage);
|
|
1013
|
+
this.streamState = createStreamState(newMessage.id);
|
|
1014
|
+
this.callbacks.onMessageStart?.(newMessage.id);
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
if (!this.streamState) {
|
|
1018
|
+
this.debug("warning", "streamState is null, skipping chunk");
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
992
1021
|
this.streamState = processStreamChunk(chunk, this.streamState);
|
|
1022
|
+
if (chunk.type === "action:start") {
|
|
1023
|
+
this.callbacks.onServerToolStart?.({
|
|
1024
|
+
id: chunk.id,
|
|
1025
|
+
name: chunk.name,
|
|
1026
|
+
hidden: chunk.hidden
|
|
1027
|
+
});
|
|
1028
|
+
} else if (chunk.type === "action:args") {
|
|
1029
|
+
let args = {};
|
|
1030
|
+
try {
|
|
1031
|
+
args = JSON.parse(chunk.args);
|
|
1032
|
+
} catch {
|
|
1033
|
+
}
|
|
1034
|
+
const existingResult = this.streamState?.toolResults.get(chunk.id);
|
|
1035
|
+
if (existingResult) {
|
|
1036
|
+
this.callbacks.onServerToolArgs?.({
|
|
1037
|
+
id: chunk.id,
|
|
1038
|
+
name: existingResult.name,
|
|
1039
|
+
args
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
} else if (chunk.type === "action:end") {
|
|
1043
|
+
this.callbacks.onServerToolEnd?.({
|
|
1044
|
+
id: chunk.id,
|
|
1045
|
+
name: chunk.name,
|
|
1046
|
+
result: chunk.result,
|
|
1047
|
+
error: chunk.error
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
993
1050
|
const updatedMessage = streamStateToMessage(this.streamState);
|
|
994
1051
|
this.state.updateMessageById(
|
|
995
1052
|
this.streamState.messageId,
|
|
@@ -1009,17 +1066,30 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
|
|
|
1009
1066
|
this.debug("processDoneMessages", {
|
|
1010
1067
|
count: chunk.messages.length
|
|
1011
1068
|
});
|
|
1069
|
+
const toolCallsHidden = {};
|
|
1070
|
+
if (this.streamState?.toolResults) {
|
|
1071
|
+
for (const [id, result] of this.streamState.toolResults) {
|
|
1072
|
+
if (result.hidden !== void 0) {
|
|
1073
|
+
toolCallsHidden[id] = result.hidden;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1012
1077
|
for (const msg of chunk.messages) {
|
|
1013
|
-
if (msg.role === "assistant"
|
|
1078
|
+
if (msg.role === "assistant") {
|
|
1014
1079
|
continue;
|
|
1015
1080
|
}
|
|
1081
|
+
let metadata;
|
|
1082
|
+
if (msg.role === "assistant" && msg.tool_calls?.length && Object.keys(toolCallsHidden).length > 0) {
|
|
1083
|
+
metadata = { toolCallsHidden };
|
|
1084
|
+
}
|
|
1016
1085
|
const message = {
|
|
1017
1086
|
id: generateMessageId(),
|
|
1018
1087
|
role: msg.role,
|
|
1019
1088
|
content: msg.content ?? "",
|
|
1020
1089
|
toolCalls: msg.tool_calls,
|
|
1021
1090
|
toolCallId: msg.tool_call_id,
|
|
1022
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
1091
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1092
|
+
metadata
|
|
1023
1093
|
};
|
|
1024
1094
|
this.state.pushMessage(message);
|
|
1025
1095
|
}
|
|
@@ -1028,15 +1098,32 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
|
|
|
1028
1098
|
}
|
|
1029
1099
|
}
|
|
1030
1100
|
this.debug("handleStreamResponse", `Processed ${chunkCount} chunks`);
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1101
|
+
if (!this.streamState) {
|
|
1102
|
+
this.debug("streamState already finalized via message:end");
|
|
1103
|
+
} else {
|
|
1104
|
+
const toolCallsHidden = {};
|
|
1105
|
+
if (this.streamState.toolResults) {
|
|
1106
|
+
for (const [id, result] of this.streamState.toolResults) {
|
|
1107
|
+
if (result.hidden !== void 0) {
|
|
1108
|
+
toolCallsHidden[id] = result.hidden;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const finalMessage = streamStateToMessage(this.streamState);
|
|
1113
|
+
if (finalMessage.toolCalls?.length && Object.keys(toolCallsHidden).length > 0) {
|
|
1114
|
+
finalMessage.metadata = {
|
|
1115
|
+
...finalMessage.metadata,
|
|
1116
|
+
toolCallsHidden
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
this.state.updateMessageById(
|
|
1120
|
+
this.streamState.messageId,
|
|
1121
|
+
() => finalMessage
|
|
1122
|
+
);
|
|
1123
|
+
if (!finalMessage.content && (!finalMessage.toolCalls || finalMessage.toolCalls.length === 0)) {
|
|
1124
|
+
this.debug("warning", "Empty response - no content and no tool calls");
|
|
1125
|
+
}
|
|
1038
1126
|
}
|
|
1039
|
-
this.callbacks.onMessageFinish?.(finalMessage);
|
|
1040
1127
|
this.callbacks.onMessagesChange?.(this.state.messages);
|
|
1041
1128
|
if (!toolCallsEmitted) {
|
|
1042
1129
|
this.state.status = "ready";
|
|
@@ -1181,8 +1268,8 @@ var AbstractAgentLoop = class {
|
|
|
1181
1268
|
this._maxIterations = config.maxIterations ?? 20;
|
|
1182
1269
|
this._maxExecutionHistory = config.maxExecutionHistory ?? 100;
|
|
1183
1270
|
if (config.tools) {
|
|
1184
|
-
for (const
|
|
1185
|
-
this.registerTool(
|
|
1271
|
+
for (const tool2 of config.tools) {
|
|
1272
|
+
this.registerTool(tool2);
|
|
1186
1273
|
}
|
|
1187
1274
|
}
|
|
1188
1275
|
}
|
|
@@ -1241,6 +1328,12 @@ var AbstractAgentLoop = class {
|
|
|
1241
1328
|
this._isProcessing = processing;
|
|
1242
1329
|
}
|
|
1243
1330
|
addToolExecution(execution) {
|
|
1331
|
+
const existingIndex = this._toolExecutions.findIndex(
|
|
1332
|
+
(e) => e.id === execution.id
|
|
1333
|
+
);
|
|
1334
|
+
if (existingIndex !== -1) {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1244
1337
|
this._toolExecutions = [...this._toolExecutions, execution];
|
|
1245
1338
|
if (this._toolExecutions.length > this._maxExecutionHistory) {
|
|
1246
1339
|
this._toolExecutions = this._toolExecutions.slice(
|
|
@@ -1249,6 +1342,9 @@ var AbstractAgentLoop = class {
|
|
|
1249
1342
|
}
|
|
1250
1343
|
this.callbacks.onExecutionsChange?.(this._toolExecutions);
|
|
1251
1344
|
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Update a tool execution with partial data
|
|
1347
|
+
*/
|
|
1252
1348
|
updateToolExecution(id, update) {
|
|
1253
1349
|
this._toolExecutions = this._toolExecutions.map(
|
|
1254
1350
|
(exec) => exec.id === id ? { ...exec, ...update } : exec
|
|
@@ -1262,15 +1358,15 @@ var AbstractAgentLoop = class {
|
|
|
1262
1358
|
* Register a tool (reference counted for React StrictMode compatibility)
|
|
1263
1359
|
* Tools are never fully removed - ref counting ensures StrictMode works correctly
|
|
1264
1360
|
*/
|
|
1265
|
-
registerTool(
|
|
1266
|
-
const existing = this.registeredTools.get(
|
|
1361
|
+
registerTool(tool2) {
|
|
1362
|
+
const existing = this.registeredTools.get(tool2.name);
|
|
1267
1363
|
if (existing) {
|
|
1268
|
-
existing.tool =
|
|
1364
|
+
existing.tool = tool2;
|
|
1269
1365
|
existing.refCount++;
|
|
1270
1366
|
existing.active = true;
|
|
1271
1367
|
} else {
|
|
1272
|
-
this.registeredTools.set(
|
|
1273
|
-
tool,
|
|
1368
|
+
this.registeredTools.set(tool2.name, {
|
|
1369
|
+
tool: tool2,
|
|
1274
1370
|
refCount: 1,
|
|
1275
1371
|
active: true
|
|
1276
1372
|
});
|
|
@@ -1336,7 +1432,7 @@ var AbstractAgentLoop = class {
|
|
|
1336
1432
|
* Execute a single tool
|
|
1337
1433
|
*/
|
|
1338
1434
|
async executeSingleTool(toolCall) {
|
|
1339
|
-
const
|
|
1435
|
+
const tool2 = this.getTool(toolCall.name);
|
|
1340
1436
|
const execution = {
|
|
1341
1437
|
id: toolCall.id,
|
|
1342
1438
|
toolCallId: toolCall.id,
|
|
@@ -1345,11 +1441,11 @@ var AbstractAgentLoop = class {
|
|
|
1345
1441
|
status: "pending",
|
|
1346
1442
|
approvalStatus: "none",
|
|
1347
1443
|
startedAt: /* @__PURE__ */ new Date(),
|
|
1348
|
-
hidden:
|
|
1444
|
+
hidden: tool2?.hidden
|
|
1349
1445
|
};
|
|
1350
1446
|
this.addToolExecution(execution);
|
|
1351
1447
|
this.callbacks.onToolStart?.(execution);
|
|
1352
|
-
if (!
|
|
1448
|
+
if (!tool2) {
|
|
1353
1449
|
const errorResult = {
|
|
1354
1450
|
toolCallId: toolCall.id,
|
|
1355
1451
|
success: false,
|
|
@@ -1363,8 +1459,8 @@ var AbstractAgentLoop = class {
|
|
|
1363
1459
|
return errorResult;
|
|
1364
1460
|
}
|
|
1365
1461
|
let approvalData;
|
|
1366
|
-
if (
|
|
1367
|
-
const approvalMessage = typeof
|
|
1462
|
+
if (tool2.needsApproval && !this.config.autoApprove) {
|
|
1463
|
+
const approvalMessage = typeof tool2.approvalMessage === "function" ? tool2.approvalMessage(toolCall.args) : tool2.approvalMessage;
|
|
1368
1464
|
execution.approvalStatus = "required";
|
|
1369
1465
|
execution.approvalMessage = approvalMessage;
|
|
1370
1466
|
this.updateToolExecution(toolCall.id, {
|
|
@@ -1391,13 +1487,13 @@ var AbstractAgentLoop = class {
|
|
|
1391
1487
|
}
|
|
1392
1488
|
this.updateToolExecution(toolCall.id, { status: "executing" });
|
|
1393
1489
|
try {
|
|
1394
|
-
if (!
|
|
1490
|
+
if (!tool2.handler) {
|
|
1395
1491
|
throw new Error(`Tool "${toolCall.name}" has no handler`);
|
|
1396
1492
|
}
|
|
1397
1493
|
if (this._isCancelled || this.abortController?.signal.aborted) {
|
|
1398
1494
|
throw new Error("Tool execution cancelled");
|
|
1399
1495
|
}
|
|
1400
|
-
const result = await
|
|
1496
|
+
const result = await tool2.handler(toolCall.args, {
|
|
1401
1497
|
signal: this.abortController?.signal,
|
|
1402
1498
|
data: { toolCallId: toolCall.id },
|
|
1403
1499
|
approvalData
|
|
@@ -1481,6 +1577,43 @@ var AbstractAgentLoop = class {
|
|
|
1481
1577
|
this.setIteration(0);
|
|
1482
1578
|
this._maxIterationsReached = false;
|
|
1483
1579
|
}
|
|
1580
|
+
// ============================================
|
|
1581
|
+
// Server-Side Tool Tracking
|
|
1582
|
+
// ============================================
|
|
1583
|
+
/**
|
|
1584
|
+
* Add a server-side tool execution (from streaming action:start event)
|
|
1585
|
+
* Used to track tools executed on the server (not client-side)
|
|
1586
|
+
*/
|
|
1587
|
+
addServerToolExecution(info) {
|
|
1588
|
+
const execution = {
|
|
1589
|
+
id: info.id,
|
|
1590
|
+
toolCallId: info.id,
|
|
1591
|
+
name: info.name,
|
|
1592
|
+
args: {},
|
|
1593
|
+
status: "executing",
|
|
1594
|
+
approvalStatus: "none",
|
|
1595
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
1596
|
+
hidden: info.hidden
|
|
1597
|
+
};
|
|
1598
|
+
this.addToolExecution(execution);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Update a server-side tool execution with args (from action:args event)
|
|
1602
|
+
*/
|
|
1603
|
+
updateServerToolArgs(id, args) {
|
|
1604
|
+
this.updateToolExecution(id, { args });
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Complete a server-side tool execution (from action:end event)
|
|
1608
|
+
*/
|
|
1609
|
+
completeServerToolExecution(info) {
|
|
1610
|
+
this.updateToolExecution(info.id, {
|
|
1611
|
+
status: info.error ? "failed" : "completed",
|
|
1612
|
+
result: info.result,
|
|
1613
|
+
error: info.error,
|
|
1614
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1484
1617
|
/**
|
|
1485
1618
|
* Cancel all pending and executing tools
|
|
1486
1619
|
* This will:
|
|
@@ -1622,7 +1755,59 @@ var ChatWithTools = class {
|
|
|
1622
1755
|
onMessageDelta: callbacks.onMessageDelta,
|
|
1623
1756
|
onMessageFinish: callbacks.onMessageFinish,
|
|
1624
1757
|
onToolCalls: callbacks.onToolCalls,
|
|
1625
|
-
onFinish: callbacks.onFinish
|
|
1758
|
+
onFinish: callbacks.onFinish,
|
|
1759
|
+
// Server-side tool callbacks - track in agentLoop for UI display
|
|
1760
|
+
// IMPORTANT: Only track tools that are NOT registered client-side
|
|
1761
|
+
// Client-side tools are tracked via executeToolCalls() path
|
|
1762
|
+
onServerToolStart: (info) => {
|
|
1763
|
+
const existingExecution = this.agentLoop.toolExecutions.find(
|
|
1764
|
+
(e) => e.id === info.id
|
|
1765
|
+
);
|
|
1766
|
+
if (existingExecution) {
|
|
1767
|
+
if (info.hidden !== void 0 && existingExecution.hidden !== info.hidden) {
|
|
1768
|
+
this.debug(
|
|
1769
|
+
"Updating hidden flag for existing execution:",
|
|
1770
|
+
info.name,
|
|
1771
|
+
info.hidden
|
|
1772
|
+
);
|
|
1773
|
+
this.agentLoop.updateToolExecution(info.id, {
|
|
1774
|
+
hidden: info.hidden
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
const isClientTool = this.agentLoop.tools.some(
|
|
1780
|
+
(t) => t.name === info.name && t.location === "client"
|
|
1781
|
+
);
|
|
1782
|
+
if (isClientTool) {
|
|
1783
|
+
this.debug("Skipping server tracking for client tool:", info.name);
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
this.debug("Server tool started:", info.name, {
|
|
1787
|
+
hidden: info.hidden,
|
|
1788
|
+
id: info.id
|
|
1789
|
+
});
|
|
1790
|
+
this.agentLoop.addServerToolExecution(info);
|
|
1791
|
+
},
|
|
1792
|
+
onServerToolArgs: (info) => {
|
|
1793
|
+
const isClientTool = this.agentLoop.tools.some(
|
|
1794
|
+
(t) => t.name === info.name && t.location === "client"
|
|
1795
|
+
);
|
|
1796
|
+
if (isClientTool) return;
|
|
1797
|
+
this.debug("Server tool args:", info.name, info.args);
|
|
1798
|
+
this.agentLoop.updateServerToolArgs(info.id, info.args ?? {});
|
|
1799
|
+
},
|
|
1800
|
+
onServerToolEnd: (info) => {
|
|
1801
|
+
const isClientTool = this.agentLoop.tools.some(
|
|
1802
|
+
(t) => t.name === info.name && t.location === "client"
|
|
1803
|
+
);
|
|
1804
|
+
if (isClientTool) return;
|
|
1805
|
+
this.debug("Server tool ended:", info.name, {
|
|
1806
|
+
error: info.error,
|
|
1807
|
+
hasResult: !!info.result
|
|
1808
|
+
});
|
|
1809
|
+
this.agentLoop.completeServerToolExecution(info);
|
|
1810
|
+
}
|
|
1626
1811
|
}
|
|
1627
1812
|
});
|
|
1628
1813
|
this.wireEvents();
|
|
@@ -1819,8 +2004,8 @@ var ChatWithTools = class {
|
|
|
1819
2004
|
/**
|
|
1820
2005
|
* Register a tool
|
|
1821
2006
|
*/
|
|
1822
|
-
registerTool(
|
|
1823
|
-
this.agentLoop.registerTool(
|
|
2007
|
+
registerTool(tool2) {
|
|
2008
|
+
this.agentLoop.registerTool(tool2);
|
|
1824
2009
|
this.chat.setTools(this.agentLoop.tools);
|
|
1825
2010
|
}
|
|
1826
2011
|
/**
|
|
@@ -2288,7 +2473,7 @@ function useMCPTools(config) {
|
|
|
2288
2473
|
return [];
|
|
2289
2474
|
}
|
|
2290
2475
|
return mcpClient.state.tools.map(
|
|
2291
|
-
(
|
|
2476
|
+
(tool2) => toolAdapter.toToolDefinition(tool2, {
|
|
2292
2477
|
prefix: prefixToolNames,
|
|
2293
2478
|
asServerTool: true,
|
|
2294
2479
|
// MCP tools execute remotely
|
|
@@ -2317,9 +2502,9 @@ function useMCPTools(config) {
|
|
|
2317
2502
|
}
|
|
2318
2503
|
registeredToolsRef.current = [];
|
|
2319
2504
|
if (mcpClient.isConnected && toolDefinitions.length > 0) {
|
|
2320
|
-
for (const
|
|
2321
|
-
registerTool(
|
|
2322
|
-
registeredToolsRef.current.push(
|
|
2505
|
+
for (const tool2 of toolDefinitions) {
|
|
2506
|
+
registerTool(tool2);
|
|
2507
|
+
registeredToolsRef.current.push(tool2.name);
|
|
2323
2508
|
}
|
|
2324
2509
|
}
|
|
2325
2510
|
return () => {
|
|
@@ -2476,8 +2661,8 @@ function CopilotProvider({
|
|
|
2476
2661
|
);
|
|
2477
2662
|
const error = errorFromChat ?? null;
|
|
2478
2663
|
const isLoading = status === "streaming" || status === "submitted";
|
|
2479
|
-
const registerTool = useCallback((
|
|
2480
|
-
chatRef.current?.registerTool(
|
|
2664
|
+
const registerTool = useCallback((tool2) => {
|
|
2665
|
+
chatRef.current?.registerTool(tool2);
|
|
2481
2666
|
}, []);
|
|
2482
2667
|
const unregisterTool = useCallback((name) => {
|
|
2483
2668
|
chatRef.current?.unregisterTool(name);
|
|
@@ -2806,10 +2991,10 @@ function useAITools(options = {}) {
|
|
|
2806
2991
|
);
|
|
2807
2992
|
const requestConsent = useCallback(
|
|
2808
2993
|
async (tools, reason = "") => {
|
|
2809
|
-
const enabledTools = tools.filter((
|
|
2810
|
-
if (
|
|
2811
|
-
if (
|
|
2812
|
-
if (
|
|
2994
|
+
const enabledTools = tools.filter((tool2) => {
|
|
2995
|
+
if (tool2 === "screenshot") return screenshot;
|
|
2996
|
+
if (tool2 === "console") return consoleCapture;
|
|
2997
|
+
if (tool2 === "network") return network;
|
|
2813
2998
|
return false;
|
|
2814
2999
|
});
|
|
2815
3000
|
if (enabledTools.length === 0) {
|
|
@@ -2819,7 +3004,7 @@ function useAITools(options = {}) {
|
|
|
2819
3004
|
return { approved: enabledTools, denied: [] };
|
|
2820
3005
|
}
|
|
2821
3006
|
const needsConsent = enabledTools.filter(
|
|
2822
|
-
(
|
|
3007
|
+
(tool2) => !rememberedConsentRef.current.has(tool2)
|
|
2823
3008
|
);
|
|
2824
3009
|
if (needsConsent.length === 0) {
|
|
2825
3010
|
return { approved: enabledTools, denied: [] };
|
|
@@ -2833,7 +3018,7 @@ function useAITools(options = {}) {
|
|
|
2833
3018
|
const response = await onConsentRequest(request);
|
|
2834
3019
|
if (response.remember) {
|
|
2835
3020
|
response.approved.forEach(
|
|
2836
|
-
(
|
|
3021
|
+
(tool2) => rememberedConsentRef.current.add(tool2)
|
|
2837
3022
|
);
|
|
2838
3023
|
}
|
|
2839
3024
|
return response;
|
|
@@ -2843,7 +3028,7 @@ function useAITools(options = {}) {
|
|
|
2843
3028
|
consentResolverRef.current = (response) => {
|
|
2844
3029
|
if (response.remember) {
|
|
2845
3030
|
response.approved.forEach(
|
|
2846
|
-
(
|
|
3031
|
+
(tool2) => rememberedConsentRef.current.add(tool2)
|
|
2847
3032
|
);
|
|
2848
3033
|
}
|
|
2849
3034
|
resolve(response);
|
|
@@ -2929,10 +3114,10 @@ function useAITools(options = {}) {
|
|
|
2929
3114
|
const detectIntentFn = useCallback(
|
|
2930
3115
|
(message) => {
|
|
2931
3116
|
const result = detectIntent(message);
|
|
2932
|
-
result.suggestedTools = result.suggestedTools.filter((
|
|
2933
|
-
if (
|
|
2934
|
-
if (
|
|
2935
|
-
if (
|
|
3117
|
+
result.suggestedTools = result.suggestedTools.filter((tool2) => {
|
|
3118
|
+
if (tool2 === "screenshot") return screenshot;
|
|
3119
|
+
if (tool2 === "console") return consoleCapture;
|
|
3120
|
+
if (tool2 === "network") return network;
|
|
2936
3121
|
return false;
|
|
2937
3122
|
});
|
|
2938
3123
|
return result;
|
|
@@ -2974,16 +3159,27 @@ function useAITools(options = {}) {
|
|
|
2974
3159
|
]
|
|
2975
3160
|
);
|
|
2976
3161
|
}
|
|
3162
|
+
function isZodSchema(value) {
|
|
3163
|
+
if (value === null || typeof value !== "object") return false;
|
|
3164
|
+
const obj = value;
|
|
3165
|
+
return "_def" in obj && typeof obj._def === "object" || "_zod" in obj && typeof obj._zod === "object" || "~standard" in obj;
|
|
3166
|
+
}
|
|
2977
3167
|
function useTool(config, dependencies = []) {
|
|
2978
3168
|
const { registerTool, unregisterTool } = useCopilot();
|
|
2979
3169
|
const configRef = useRef(config);
|
|
2980
3170
|
configRef.current = config;
|
|
3171
|
+
const inputSchema = useMemo(() => {
|
|
3172
|
+
if (isZodSchema(config.inputSchema)) {
|
|
3173
|
+
return zodToJsonSchema(config.inputSchema);
|
|
3174
|
+
}
|
|
3175
|
+
return config.inputSchema;
|
|
3176
|
+
}, [config.inputSchema]);
|
|
2981
3177
|
useEffect(() => {
|
|
2982
|
-
const
|
|
3178
|
+
const tool2 = {
|
|
2983
3179
|
name: config.name,
|
|
2984
3180
|
description: config.description,
|
|
2985
3181
|
location: "client",
|
|
2986
|
-
inputSchema
|
|
3182
|
+
inputSchema,
|
|
2987
3183
|
handler: async (params, context) => {
|
|
2988
3184
|
return configRef.current.handler(params, context);
|
|
2989
3185
|
},
|
|
@@ -2993,11 +3189,11 @@ function useTool(config, dependencies = []) {
|
|
|
2993
3189
|
approvalMessage: config.approvalMessage,
|
|
2994
3190
|
hidden: config.hidden
|
|
2995
3191
|
};
|
|
2996
|
-
registerTool(
|
|
3192
|
+
registerTool(tool2);
|
|
2997
3193
|
return () => {
|
|
2998
3194
|
unregisterTool(config.name);
|
|
2999
3195
|
};
|
|
3000
|
-
}, [config.name, ...dependencies]);
|
|
3196
|
+
}, [config.name, inputSchema, ...dependencies]);
|
|
3001
3197
|
}
|
|
3002
3198
|
function useTools(tools) {
|
|
3003
3199
|
const { registerTool, unregisterTool } = useCopilot();
|
|
@@ -3064,7 +3260,7 @@ function useToolWithSchema(config, dependencies = []) {
|
|
|
3064
3260
|
}
|
|
3065
3261
|
}, [config.schema, config.name]);
|
|
3066
3262
|
useEffect(() => {
|
|
3067
|
-
const
|
|
3263
|
+
const tool2 = {
|
|
3068
3264
|
name: config.name,
|
|
3069
3265
|
description: config.description,
|
|
3070
3266
|
location: "client",
|
|
@@ -3075,7 +3271,7 @@ function useToolWithSchema(config, dependencies = []) {
|
|
|
3075
3271
|
render: config.render,
|
|
3076
3272
|
available: config.available ?? true
|
|
3077
3273
|
};
|
|
3078
|
-
registerTool(
|
|
3274
|
+
registerTool(tool2);
|
|
3079
3275
|
return () => {
|
|
3080
3276
|
unregisterTool(config.name);
|
|
3081
3277
|
};
|
|
@@ -3098,7 +3294,7 @@ function useToolsWithSchema(tools, dependencies = []) {
|
|
|
3098
3294
|
);
|
|
3099
3295
|
inputSchema = { type: "object", properties: {} };
|
|
3100
3296
|
}
|
|
3101
|
-
const
|
|
3297
|
+
const tool2 = {
|
|
3102
3298
|
name: config.name,
|
|
3103
3299
|
description: config.description,
|
|
3104
3300
|
location: "client",
|
|
@@ -3114,7 +3310,7 @@ function useToolsWithSchema(tools, dependencies = []) {
|
|
|
3114
3310
|
},
|
|
3115
3311
|
available: config.available ?? true
|
|
3116
3312
|
};
|
|
3117
|
-
registerTool(
|
|
3313
|
+
registerTool(tool2);
|
|
3118
3314
|
toolNames.push(config.name);
|
|
3119
3315
|
}
|
|
3120
3316
|
return () => {
|
|
@@ -3146,14 +3342,14 @@ function useToolExecutor() {
|
|
|
3146
3342
|
toolsRef.current = registeredTools;
|
|
3147
3343
|
const executeTool = useCallback(
|
|
3148
3344
|
async (toolCall) => {
|
|
3149
|
-
const
|
|
3150
|
-
if (!
|
|
3345
|
+
const tool2 = toolsRef.current.find((t) => t.name === toolCall.name);
|
|
3346
|
+
if (!tool2) {
|
|
3151
3347
|
return {
|
|
3152
3348
|
success: false,
|
|
3153
3349
|
error: `Unknown tool: ${toolCall.name}`
|
|
3154
3350
|
};
|
|
3155
3351
|
}
|
|
3156
|
-
if (!
|
|
3352
|
+
if (!tool2.handler) {
|
|
3157
3353
|
return {
|
|
3158
3354
|
success: false,
|
|
3159
3355
|
error: `Tool "${toolCall.name}" has no handler`
|
|
@@ -3166,12 +3362,12 @@ function useToolExecutor() {
|
|
|
3166
3362
|
status: "executing",
|
|
3167
3363
|
timestamp: Date.now(),
|
|
3168
3364
|
approvalStatus: "none",
|
|
3169
|
-
hidden:
|
|
3365
|
+
hidden: tool2.hidden
|
|
3170
3366
|
};
|
|
3171
3367
|
addToolExecution?.(execution);
|
|
3172
3368
|
try {
|
|
3173
3369
|
const startTime = Date.now();
|
|
3174
|
-
const result = await
|
|
3370
|
+
const result = await tool2.handler(toolCall.input);
|
|
3175
3371
|
const duration = Date.now() - startTime;
|
|
3176
3372
|
updateToolExecution?.(toolCall.id, {
|
|
3177
3373
|
status: result.success ? "completed" : "error",
|
|
@@ -3646,9 +3842,9 @@ function useDevLogger() {
|
|
|
3646
3842
|
})
|
|
3647
3843
|
);
|
|
3648
3844
|
const pendingApprovalsCount = ctx.pendingApprovals?.length || 0;
|
|
3649
|
-
const registeredTools = (ctx.registeredTools || []).map((
|
|
3650
|
-
name:
|
|
3651
|
-
location:
|
|
3845
|
+
const registeredTools = (ctx.registeredTools || []).map((tool2) => ({
|
|
3846
|
+
name: tool2.name,
|
|
3847
|
+
location: tool2.location || "client"
|
|
3652
3848
|
}));
|
|
3653
3849
|
const registeredActions = (ctx.registeredActions || []).map((action) => ({
|
|
3654
3850
|
name: action.name
|
|
@@ -4473,5 +4669,5 @@ function useChat(config) {
|
|
|
4473
4669
|
}
|
|
4474
4670
|
|
|
4475
4671
|
export { AbstractAgentLoop, AbstractChat, CopilotProvider, ReactChat, ReactChatState, ReactThreadManager, ReactThreadManagerState, createMessageIntentHandler, createPermissionStorage, createReactChat, createReactChatState, createReactThreadManager, createReactThreadManagerState, createSessionPermissionCache, createToolIntentHandler, formatKnowledgeResultsForAI, initialAgentLoopState, searchKnowledgeBase, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useCopilot, useDevLogger, useFeatureSupport, useKnowledgeBase, useMCPClient, useMCPTools, useMCPUIIntents, useSuggestions, useSupportedMediaTypes, useThreadManager, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
|
|
4476
|
-
//# sourceMappingURL=chunk-
|
|
4477
|
-
//# sourceMappingURL=chunk-
|
|
4672
|
+
//# sourceMappingURL=chunk-7PKGRYHY.js.map
|
|
4673
|
+
//# sourceMappingURL=chunk-7PKGRYHY.js.map
|