@yourgpt/copilot-sdk 2.1.1 → 2.1.3

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.
Files changed (75) hide show
  1. package/dist/{chunk-SNI7VN2U.js → chunk-DMBFN7KO.js} +311 -80
  2. package/dist/chunk-DMBFN7KO.js.map +1 -0
  3. package/dist/{chunk-7YZVSG62.js → chunk-LZMBBGWH.js} +3 -3
  4. package/dist/{chunk-7YZVSG62.js.map → chunk-LZMBBGWH.js.map} +1 -1
  5. package/dist/{chunk-HNRFRNMY.cjs → chunk-POZNNKNJ.cjs} +2 -2
  6. package/dist/{chunk-HNRFRNMY.cjs.map → chunk-POZNNKNJ.cjs.map} +1 -1
  7. package/dist/{chunk-BRUDSHCV.js → chunk-QLH6TSCC.js} +2 -2
  8. package/dist/{chunk-BRUDSHCV.js.map → chunk-QLH6TSCC.js.map} +1 -1
  9. package/dist/{chunk-5UMM5VYB.cjs → chunk-R6LKHKAI.cjs} +335 -104
  10. package/dist/chunk-R6LKHKAI.cjs.map +1 -0
  11. package/dist/{chunk-7PJ4GAJR.js → chunk-VFV5FVVI.js} +4 -4
  12. package/dist/{chunk-7PJ4GAJR.js.map → chunk-VFV5FVVI.js.map} +1 -1
  13. package/dist/{chunk-O33I4HBL.cjs → chunk-WAPGTQDR.cjs} +5 -5
  14. package/dist/{chunk-O33I4HBL.cjs.map → chunk-WAPGTQDR.cjs.map} +1 -1
  15. package/dist/{chunk-33JSFVGH.cjs → chunk-WQSK3Z4K.cjs} +23 -23
  16. package/dist/{chunk-33JSFVGH.cjs.map → chunk-WQSK3Z4K.cjs.map} +1 -1
  17. package/dist/core/index.cjs +80 -80
  18. package/dist/core/index.d.cts +3 -3
  19. package/dist/core/index.d.ts +3 -3
  20. package/dist/core/index.js +3 -3
  21. package/dist/{index-C261xY-B.d.cts → index-BHkRA0mM.d.cts} +1 -1
  22. package/dist/{index-25qIYJ21.d.ts → index-tB0qI8my.d.ts} +1 -1
  23. package/dist/mcp/index.d.cts +3 -3
  24. package/dist/mcp/index.d.ts +3 -3
  25. package/dist/react/index.cjs +53 -49
  26. package/dist/react/index.d.cts +69 -7
  27. package/dist/react/index.d.ts +69 -7
  28. package/dist/react/index.js +4 -4
  29. package/dist/tools/anthropic/index.d.cts +1 -1
  30. package/dist/tools/anthropic/index.d.ts +1 -1
  31. package/dist/tools/brave/index.cjs +2 -2
  32. package/dist/tools/brave/index.d.cts +1 -1
  33. package/dist/tools/brave/index.d.ts +1 -1
  34. package/dist/tools/brave/index.js +1 -1
  35. package/dist/tools/exa/index.cjs +2 -2
  36. package/dist/tools/exa/index.d.cts +1 -1
  37. package/dist/tools/exa/index.d.ts +1 -1
  38. package/dist/tools/exa/index.js +1 -1
  39. package/dist/tools/google/index.cjs +2 -2
  40. package/dist/tools/google/index.d.cts +1 -1
  41. package/dist/tools/google/index.d.ts +1 -1
  42. package/dist/tools/google/index.js +1 -1
  43. package/dist/tools/openai/index.cjs +2 -2
  44. package/dist/tools/openai/index.d.cts +1 -1
  45. package/dist/tools/openai/index.d.ts +1 -1
  46. package/dist/tools/openai/index.js +1 -1
  47. package/dist/tools/searxng/index.cjs +2 -2
  48. package/dist/tools/searxng/index.d.cts +1 -1
  49. package/dist/tools/searxng/index.d.ts +1 -1
  50. package/dist/tools/searxng/index.js +1 -1
  51. package/dist/tools/serper/index.cjs +2 -2
  52. package/dist/tools/serper/index.d.cts +1 -1
  53. package/dist/tools/serper/index.d.ts +1 -1
  54. package/dist/tools/serper/index.js +1 -1
  55. package/dist/tools/tavily/index.cjs +2 -2
  56. package/dist/tools/tavily/index.d.cts +1 -1
  57. package/dist/tools/tavily/index.d.ts +1 -1
  58. package/dist/tools/tavily/index.js +1 -1
  59. package/dist/tools/web-search/index.cjs +3 -3
  60. package/dist/tools/web-search/index.d.cts +2 -2
  61. package/dist/tools/web-search/index.d.ts +2 -2
  62. package/dist/tools/web-search/index.js +2 -2
  63. package/dist/{tools-Clyufshc.d.cts → tools-coIcskZ4.d.cts} +23 -4
  64. package/dist/{tools-Clyufshc.d.ts → tools-coIcskZ4.d.ts} +23 -4
  65. package/dist/{types-DM6M_pv_.d.cts → types-C8t4Ut8f.d.cts} +1 -1
  66. package/dist/{types-wudOhedT.d.ts → types-rjaSVmEF.d.ts} +1 -1
  67. package/dist/ui/index.cjs +39 -18
  68. package/dist/ui/index.cjs.map +1 -1
  69. package/dist/ui/index.d.cts +6 -1
  70. package/dist/ui/index.d.ts +6 -1
  71. package/dist/ui/index.js +35 -14
  72. package/dist/ui/index.js.map +1 -1
  73. package/package.json +1 -1
  74. package/dist/chunk-5UMM5VYB.cjs.map +0 -1
  75. package/dist/chunk-SNI7VN2U.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-7PJ4GAJR.js';
1
+ import { ThreadManager, isConsoleCaptureActive, startConsoleCapture, isNetworkCaptureActive, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, isScreenshotSupported, captureScreenshot, getConsoleLogs, getNetworkRequests, clearConsoleLogs, clearNetworkRequests, formatLogsForAI, formatRequestsForAI, detectIntent, streamSSE, zodObjectToInputSchema } from './chunk-VFV5FVVI.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';
@@ -161,7 +161,8 @@ function processStreamChunk(chunk, state) {
161
161
  newResults.set(chunk.id, {
162
162
  id: chunk.id,
163
163
  name: chunk.name,
164
- status: "executing"
164
+ status: "executing",
165
+ hidden: chunk.hidden
165
166
  });
166
167
  return { ...state, toolResults: newResults };
167
168
  }
@@ -361,17 +362,11 @@ var HttpTransport = class {
361
362
  this.abortController = new AbortController();
362
363
  this.streaming = true;
363
364
  try {
364
- console.log(
365
- "[HttpTransport] Config headers type:",
366
- typeof this.config.headers
367
- );
368
- console.log("[HttpTransport] Config headers:", this.config.headers);
369
365
  const resolved = await resolveValues({
370
366
  url: this.config.url,
371
367
  headers: this.config.headers ?? {},
372
368
  configBody: this.config.body ?? {}
373
369
  });
374
- console.log("[HttpTransport] Resolved headers:", resolved.headers);
375
370
  const response = await fetch(resolved.url, {
376
371
  method: "POST",
377
372
  headers: {
@@ -527,16 +522,16 @@ var HttpTransport = class {
527
522
  };
528
523
 
529
524
  // src/chat/classes/AbstractChat.ts
530
- function buildToolResultContentForAI(result, tool, args) {
525
+ function buildToolResultContentForAI(result, tool2, args) {
531
526
  if (typeof result === "string") return result;
532
527
  const typedResult = result;
533
- const responseMode = typedResult?._aiResponseMode ?? tool?.aiResponseMode ?? "full";
528
+ const responseMode = typedResult?._aiResponseMode ?? tool2?.aiResponseMode ?? "full";
534
529
  if (typedResult?._aiContent) {
535
530
  return JSON.stringify(typedResult._aiContent);
536
531
  }
537
532
  let aiContext = typedResult?._aiContext;
538
- if (!aiContext && tool?.aiContext) {
539
- aiContext = typeof tool.aiContext === "function" ? tool.aiContext(typedResult, args ?? {}) : tool.aiContext;
533
+ if (!aiContext && tool2?.aiContext) {
534
+ aiContext = typeof tool2.aiContext === "function" ? tool2.aiContext(typedResult, args ?? {}) : tool2.aiContext;
540
535
  }
541
536
  switch (responseMode) {
542
537
  case "none":
@@ -892,10 +887,10 @@ var AbstractChat = class {
892
887
  * Build the request payload
893
888
  */
894
889
  buildRequest() {
895
- const tools = this.config.tools?.filter((tool) => tool.available !== false).map((tool) => ({
896
- name: tool.name,
897
- description: tool.description,
898
- inputSchema: tool.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
899
894
  }));
900
895
  const toolCallMap = /* @__PURE__ */ new Map();
901
896
  for (const msg of this.state.messages) {
@@ -912,11 +907,11 @@ var AbstractChat = class {
912
907
  }
913
908
  const toolDefMap = /* @__PURE__ */ new Map();
914
909
  if (this.config.tools) {
915
- for (const tool of this.config.tools) {
916
- toolDefMap.set(tool.name, {
917
- name: tool.name,
918
- aiResponseMode: tool.aiResponseMode,
919
- aiContext: tool.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
920
915
  });
921
916
  }
922
917
  }
@@ -988,7 +983,70 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
988
983
  this.handleError(error);
989
984
  return;
990
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
+ }
991
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
+ }
992
1050
  const updatedMessage = streamStateToMessage(this.streamState);
993
1051
  this.state.updateMessageById(
994
1052
  this.streamState.messageId,
@@ -1004,19 +1062,68 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
1004
1062
  }
1005
1063
  if (isStreamDone(chunk)) {
1006
1064
  this.debug("streamDone", { chunk });
1065
+ if (chunk.type === "done" && chunk.messages?.length) {
1066
+ this.debug("processDoneMessages", {
1067
+ count: chunk.messages.length
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
+ }
1077
+ for (const msg of chunk.messages) {
1078
+ if (msg.role === "assistant") {
1079
+ continue;
1080
+ }
1081
+ let metadata;
1082
+ if (msg.role === "assistant" && msg.tool_calls?.length && Object.keys(toolCallsHidden).length > 0) {
1083
+ metadata = { toolCallsHidden };
1084
+ }
1085
+ const message = {
1086
+ id: generateMessageId(),
1087
+ role: msg.role,
1088
+ content: msg.content ?? "",
1089
+ toolCalls: msg.tool_calls,
1090
+ toolCallId: msg.tool_call_id,
1091
+ createdAt: /* @__PURE__ */ new Date(),
1092
+ metadata
1093
+ };
1094
+ this.state.pushMessage(message);
1095
+ }
1096
+ }
1007
1097
  break;
1008
1098
  }
1009
1099
  }
1010
1100
  this.debug("handleStreamResponse", `Processed ${chunkCount} chunks`);
1011
- const finalMessage = streamStateToMessage(this.streamState);
1012
- this.state.updateMessageById(
1013
- this.streamState.messageId,
1014
- () => finalMessage
1015
- );
1016
- if (!finalMessage.content && (!finalMessage.toolCalls || finalMessage.toolCalls.length === 0)) {
1017
- this.debug("warning", "Empty response - no content and no tool calls");
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
+ }
1018
1126
  }
1019
- this.callbacks.onMessageFinish?.(finalMessage);
1020
1127
  this.callbacks.onMessagesChange?.(this.state.messages);
1021
1128
  if (!toolCallsEmitted) {
1022
1129
  this.state.status = "ready";
@@ -1030,13 +1137,37 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
1030
1137
  * Handle JSON (non-streaming) response
1031
1138
  */
1032
1139
  handleJsonResponse(response) {
1140
+ const toolCallHiddenMap = /* @__PURE__ */ new Map();
1141
+ if (response.toolCalls) {
1142
+ for (const tc of response.toolCalls) {
1143
+ if (tc.hidden !== void 0) {
1144
+ toolCallHiddenMap.set(tc.id, tc.hidden);
1145
+ }
1146
+ }
1147
+ }
1033
1148
  for (const msg of response.messages ?? []) {
1149
+ let metadata;
1150
+ if (msg.role === "assistant" && msg.tool_calls && toolCallHiddenMap.size > 0) {
1151
+ const toolCallsHidden = {};
1152
+ for (const tc of msg.tool_calls) {
1153
+ const hidden = toolCallHiddenMap.get(tc.id);
1154
+ if (hidden !== void 0) {
1155
+ toolCallsHidden[tc.id] = hidden;
1156
+ }
1157
+ }
1158
+ if (Object.keys(toolCallsHidden).length > 0) {
1159
+ metadata = { toolCallsHidden };
1160
+ }
1161
+ }
1034
1162
  const message = {
1035
1163
  id: generateMessageId(),
1036
1164
  role: msg.role,
1037
1165
  content: msg.content ?? "",
1038
1166
  toolCalls: msg.tool_calls,
1039
- createdAt: /* @__PURE__ */ new Date()
1167
+ // CRITICAL: Preserve toolCallId for tool messages (fixes Anthropic API errors)
1168
+ toolCallId: msg.tool_call_id,
1169
+ createdAt: /* @__PURE__ */ new Date(),
1170
+ metadata
1040
1171
  };
1041
1172
  this.state.pushMessage(message);
1042
1173
  }
@@ -1137,8 +1268,8 @@ var AbstractAgentLoop = class {
1137
1268
  this._maxIterations = config.maxIterations ?? 20;
1138
1269
  this._maxExecutionHistory = config.maxExecutionHistory ?? 100;
1139
1270
  if (config.tools) {
1140
- for (const tool of config.tools) {
1141
- this.registerTool(tool);
1271
+ for (const tool2 of config.tools) {
1272
+ this.registerTool(tool2);
1142
1273
  }
1143
1274
  }
1144
1275
  }
@@ -1197,6 +1328,12 @@ var AbstractAgentLoop = class {
1197
1328
  this._isProcessing = processing;
1198
1329
  }
1199
1330
  addToolExecution(execution) {
1331
+ const existingIndex = this._toolExecutions.findIndex(
1332
+ (e) => e.id === execution.id
1333
+ );
1334
+ if (existingIndex !== -1) {
1335
+ return;
1336
+ }
1200
1337
  this._toolExecutions = [...this._toolExecutions, execution];
1201
1338
  if (this._toolExecutions.length > this._maxExecutionHistory) {
1202
1339
  this._toolExecutions = this._toolExecutions.slice(
@@ -1205,6 +1342,9 @@ var AbstractAgentLoop = class {
1205
1342
  }
1206
1343
  this.callbacks.onExecutionsChange?.(this._toolExecutions);
1207
1344
  }
1345
+ /**
1346
+ * Update a tool execution with partial data
1347
+ */
1208
1348
  updateToolExecution(id, update) {
1209
1349
  this._toolExecutions = this._toolExecutions.map(
1210
1350
  (exec) => exec.id === id ? { ...exec, ...update } : exec
@@ -1218,15 +1358,15 @@ var AbstractAgentLoop = class {
1218
1358
  * Register a tool (reference counted for React StrictMode compatibility)
1219
1359
  * Tools are never fully removed - ref counting ensures StrictMode works correctly
1220
1360
  */
1221
- registerTool(tool) {
1222
- const existing = this.registeredTools.get(tool.name);
1361
+ registerTool(tool2) {
1362
+ const existing = this.registeredTools.get(tool2.name);
1223
1363
  if (existing) {
1224
- existing.tool = tool;
1364
+ existing.tool = tool2;
1225
1365
  existing.refCount++;
1226
1366
  existing.active = true;
1227
1367
  } else {
1228
- this.registeredTools.set(tool.name, {
1229
- tool,
1368
+ this.registeredTools.set(tool2.name, {
1369
+ tool: tool2,
1230
1370
  refCount: 1,
1231
1371
  active: true
1232
1372
  });
@@ -1292,7 +1432,7 @@ var AbstractAgentLoop = class {
1292
1432
  * Execute a single tool
1293
1433
  */
1294
1434
  async executeSingleTool(toolCall) {
1295
- const tool = this.getTool(toolCall.name);
1435
+ const tool2 = this.getTool(toolCall.name);
1296
1436
  const execution = {
1297
1437
  id: toolCall.id,
1298
1438
  toolCallId: toolCall.id,
@@ -1300,11 +1440,12 @@ var AbstractAgentLoop = class {
1300
1440
  args: toolCall.args,
1301
1441
  status: "pending",
1302
1442
  approvalStatus: "none",
1303
- startedAt: /* @__PURE__ */ new Date()
1443
+ startedAt: /* @__PURE__ */ new Date(),
1444
+ hidden: tool2?.hidden
1304
1445
  };
1305
1446
  this.addToolExecution(execution);
1306
1447
  this.callbacks.onToolStart?.(execution);
1307
- if (!tool) {
1448
+ if (!tool2) {
1308
1449
  const errorResult = {
1309
1450
  toolCallId: toolCall.id,
1310
1451
  success: false,
@@ -1318,8 +1459,8 @@ var AbstractAgentLoop = class {
1318
1459
  return errorResult;
1319
1460
  }
1320
1461
  let approvalData;
1321
- if (tool.needsApproval && !this.config.autoApprove) {
1322
- const approvalMessage = typeof tool.approvalMessage === "function" ? tool.approvalMessage(toolCall.args) : tool.approvalMessage;
1462
+ if (tool2.needsApproval && !this.config.autoApprove) {
1463
+ const approvalMessage = typeof tool2.approvalMessage === "function" ? tool2.approvalMessage(toolCall.args) : tool2.approvalMessage;
1323
1464
  execution.approvalStatus = "required";
1324
1465
  execution.approvalMessage = approvalMessage;
1325
1466
  this.updateToolExecution(toolCall.id, {
@@ -1346,13 +1487,13 @@ var AbstractAgentLoop = class {
1346
1487
  }
1347
1488
  this.updateToolExecution(toolCall.id, { status: "executing" });
1348
1489
  try {
1349
- if (!tool.handler) {
1490
+ if (!tool2.handler) {
1350
1491
  throw new Error(`Tool "${toolCall.name}" has no handler`);
1351
1492
  }
1352
1493
  if (this._isCancelled || this.abortController?.signal.aborted) {
1353
1494
  throw new Error("Tool execution cancelled");
1354
1495
  }
1355
- const result = await tool.handler(toolCall.args, {
1496
+ const result = await tool2.handler(toolCall.args, {
1356
1497
  signal: this.abortController?.signal,
1357
1498
  data: { toolCallId: toolCall.id },
1358
1499
  approvalData
@@ -1436,6 +1577,43 @@ var AbstractAgentLoop = class {
1436
1577
  this.setIteration(0);
1437
1578
  this._maxIterationsReached = false;
1438
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
+ }
1439
1617
  /**
1440
1618
  * Cancel all pending and executing tools
1441
1619
  * This will:
@@ -1577,7 +1755,59 @@ var ChatWithTools = class {
1577
1755
  onMessageDelta: callbacks.onMessageDelta,
1578
1756
  onMessageFinish: callbacks.onMessageFinish,
1579
1757
  onToolCalls: callbacks.onToolCalls,
1580
- 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
+ }
1581
1811
  }
1582
1812
  });
1583
1813
  this.wireEvents();
@@ -1774,8 +2004,8 @@ var ChatWithTools = class {
1774
2004
  /**
1775
2005
  * Register a tool
1776
2006
  */
1777
- registerTool(tool) {
1778
- this.agentLoop.registerTool(tool);
2007
+ registerTool(tool2) {
2008
+ this.agentLoop.registerTool(tool2);
1779
2009
  this.chat.setTools(this.agentLoop.tools);
1780
2010
  }
1781
2011
  /**
@@ -2243,7 +2473,7 @@ function useMCPTools(config) {
2243
2473
  return [];
2244
2474
  }
2245
2475
  return mcpClient.state.tools.map(
2246
- (tool) => toolAdapter.toToolDefinition(tool, {
2476
+ (tool2) => toolAdapter.toToolDefinition(tool2, {
2247
2477
  prefix: prefixToolNames,
2248
2478
  asServerTool: true,
2249
2479
  // MCP tools execute remotely
@@ -2272,9 +2502,9 @@ function useMCPTools(config) {
2272
2502
  }
2273
2503
  registeredToolsRef.current = [];
2274
2504
  if (mcpClient.isConnected && toolDefinitions.length > 0) {
2275
- for (const tool of toolDefinitions) {
2276
- registerTool(tool);
2277
- registeredToolsRef.current.push(tool.name);
2505
+ for (const tool2 of toolDefinitions) {
2506
+ registerTool(tool2);
2507
+ registeredToolsRef.current.push(tool2.name);
2278
2508
  }
2279
2509
  }
2280
2510
  return () => {
@@ -2431,8 +2661,8 @@ function CopilotProvider({
2431
2661
  );
2432
2662
  const error = errorFromChat ?? null;
2433
2663
  const isLoading = status === "streaming" || status === "submitted";
2434
- const registerTool = useCallback((tool) => {
2435
- chatRef.current?.registerTool(tool);
2664
+ const registerTool = useCallback((tool2) => {
2665
+ chatRef.current?.registerTool(tool2);
2436
2666
  }, []);
2437
2667
  const unregisterTool = useCallback((name) => {
2438
2668
  chatRef.current?.unregisterTool(name);
@@ -2761,10 +2991,10 @@ function useAITools(options = {}) {
2761
2991
  );
2762
2992
  const requestConsent = useCallback(
2763
2993
  async (tools, reason = "") => {
2764
- const enabledTools = tools.filter((tool) => {
2765
- if (tool === "screenshot") return screenshot;
2766
- if (tool === "console") return consoleCapture;
2767
- if (tool === "network") return network;
2994
+ const enabledTools = tools.filter((tool2) => {
2995
+ if (tool2 === "screenshot") return screenshot;
2996
+ if (tool2 === "console") return consoleCapture;
2997
+ if (tool2 === "network") return network;
2768
2998
  return false;
2769
2999
  });
2770
3000
  if (enabledTools.length === 0) {
@@ -2774,7 +3004,7 @@ function useAITools(options = {}) {
2774
3004
  return { approved: enabledTools, denied: [] };
2775
3005
  }
2776
3006
  const needsConsent = enabledTools.filter(
2777
- (tool) => !rememberedConsentRef.current.has(tool)
3007
+ (tool2) => !rememberedConsentRef.current.has(tool2)
2778
3008
  );
2779
3009
  if (needsConsent.length === 0) {
2780
3010
  return { approved: enabledTools, denied: [] };
@@ -2788,7 +3018,7 @@ function useAITools(options = {}) {
2788
3018
  const response = await onConsentRequest(request);
2789
3019
  if (response.remember) {
2790
3020
  response.approved.forEach(
2791
- (tool) => rememberedConsentRef.current.add(tool)
3021
+ (tool2) => rememberedConsentRef.current.add(tool2)
2792
3022
  );
2793
3023
  }
2794
3024
  return response;
@@ -2798,7 +3028,7 @@ function useAITools(options = {}) {
2798
3028
  consentResolverRef.current = (response) => {
2799
3029
  if (response.remember) {
2800
3030
  response.approved.forEach(
2801
- (tool) => rememberedConsentRef.current.add(tool)
3031
+ (tool2) => rememberedConsentRef.current.add(tool2)
2802
3032
  );
2803
3033
  }
2804
3034
  resolve(response);
@@ -2884,10 +3114,10 @@ function useAITools(options = {}) {
2884
3114
  const detectIntentFn = useCallback(
2885
3115
  (message) => {
2886
3116
  const result = detectIntent(message);
2887
- result.suggestedTools = result.suggestedTools.filter((tool) => {
2888
- if (tool === "screenshot") return screenshot;
2889
- if (tool === "console") return consoleCapture;
2890
- if (tool === "network") return network;
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;
2891
3121
  return false;
2892
3122
  });
2893
3123
  return result;
@@ -2934,7 +3164,7 @@ function useTool(config, dependencies = []) {
2934
3164
  const configRef = useRef(config);
2935
3165
  configRef.current = config;
2936
3166
  useEffect(() => {
2937
- const tool = {
3167
+ const tool2 = {
2938
3168
  name: config.name,
2939
3169
  description: config.description,
2940
3170
  location: "client",
@@ -2948,7 +3178,7 @@ function useTool(config, dependencies = []) {
2948
3178
  approvalMessage: config.approvalMessage,
2949
3179
  hidden: config.hidden
2950
3180
  };
2951
- registerTool(tool);
3181
+ registerTool(tool2);
2952
3182
  return () => {
2953
3183
  unregisterTool(config.name);
2954
3184
  };
@@ -3019,7 +3249,7 @@ function useToolWithSchema(config, dependencies = []) {
3019
3249
  }
3020
3250
  }, [config.schema, config.name]);
3021
3251
  useEffect(() => {
3022
- const tool = {
3252
+ const tool2 = {
3023
3253
  name: config.name,
3024
3254
  description: config.description,
3025
3255
  location: "client",
@@ -3030,7 +3260,7 @@ function useToolWithSchema(config, dependencies = []) {
3030
3260
  render: config.render,
3031
3261
  available: config.available ?? true
3032
3262
  };
3033
- registerTool(tool);
3263
+ registerTool(tool2);
3034
3264
  return () => {
3035
3265
  unregisterTool(config.name);
3036
3266
  };
@@ -3053,7 +3283,7 @@ function useToolsWithSchema(tools, dependencies = []) {
3053
3283
  );
3054
3284
  inputSchema = { type: "object", properties: {} };
3055
3285
  }
3056
- const tool = {
3286
+ const tool2 = {
3057
3287
  name: config.name,
3058
3288
  description: config.description,
3059
3289
  location: "client",
@@ -3069,7 +3299,7 @@ function useToolsWithSchema(tools, dependencies = []) {
3069
3299
  },
3070
3300
  available: config.available ?? true
3071
3301
  };
3072
- registerTool(tool);
3302
+ registerTool(tool2);
3073
3303
  toolNames.push(config.name);
3074
3304
  }
3075
3305
  return () => {
@@ -3101,14 +3331,14 @@ function useToolExecutor() {
3101
3331
  toolsRef.current = registeredTools;
3102
3332
  const executeTool = useCallback(
3103
3333
  async (toolCall) => {
3104
- const tool = toolsRef.current.find((t) => t.name === toolCall.name);
3105
- if (!tool) {
3334
+ const tool2 = toolsRef.current.find((t) => t.name === toolCall.name);
3335
+ if (!tool2) {
3106
3336
  return {
3107
3337
  success: false,
3108
3338
  error: `Unknown tool: ${toolCall.name}`
3109
3339
  };
3110
3340
  }
3111
- if (!tool.handler) {
3341
+ if (!tool2.handler) {
3112
3342
  return {
3113
3343
  success: false,
3114
3344
  error: `Tool "${toolCall.name}" has no handler`
@@ -3120,12 +3350,13 @@ function useToolExecutor() {
3120
3350
  args: toolCall.input,
3121
3351
  status: "executing",
3122
3352
  timestamp: Date.now(),
3123
- approvalStatus: "none"
3353
+ approvalStatus: "none",
3354
+ hidden: tool2.hidden
3124
3355
  };
3125
3356
  addToolExecution?.(execution);
3126
3357
  try {
3127
3358
  const startTime = Date.now();
3128
- const result = await tool.handler(toolCall.input);
3359
+ const result = await tool2.handler(toolCall.input);
3129
3360
  const duration = Date.now() - startTime;
3130
3361
  updateToolExecution?.(toolCall.id, {
3131
3362
  status: result.success ? "completed" : "error",
@@ -3600,9 +3831,9 @@ function useDevLogger() {
3600
3831
  })
3601
3832
  );
3602
3833
  const pendingApprovalsCount = ctx.pendingApprovals?.length || 0;
3603
- const registeredTools = (ctx.registeredTools || []).map((tool) => ({
3604
- name: tool.name,
3605
- location: tool.location || "client"
3834
+ const registeredTools = (ctx.registeredTools || []).map((tool2) => ({
3835
+ name: tool2.name,
3836
+ location: tool2.location || "client"
3606
3837
  }));
3607
3838
  const registeredActions = (ctx.registeredActions || []).map((action) => ({
3608
3839
  name: action.name
@@ -4427,5 +4658,5 @@ function useChat(config) {
4427
4658
  }
4428
4659
 
4429
4660
  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 };
4430
- //# sourceMappingURL=chunk-SNI7VN2U.js.map
4431
- //# sourceMappingURL=chunk-SNI7VN2U.js.map
4661
+ //# sourceMappingURL=chunk-DMBFN7KO.js.map
4662
+ //# sourceMappingURL=chunk-DMBFN7KO.js.map