@yourgpt/copilot-sdk 2.1.2 → 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 (73) hide show
  1. package/dist/{chunk-VXT2O6R6.js → chunk-DMBFN7KO.js} +265 -80
  2. package/dist/chunk-DMBFN7KO.js.map +1 -0
  3. package/dist/{chunk-VUHP6TAN.js → chunk-LZMBBGWH.js} +3 -3
  4. package/dist/{chunk-VUHP6TAN.js.map → chunk-LZMBBGWH.js.map} +1 -1
  5. package/dist/{chunk-CSEZZ5DX.cjs → chunk-POZNNKNJ.cjs} +2 -2
  6. package/dist/{chunk-CSEZZ5DX.cjs.map → chunk-POZNNKNJ.cjs.map} +1 -1
  7. package/dist/{chunk-BMYNG3WM.js → chunk-QLH6TSCC.js} +2 -2
  8. package/dist/{chunk-BMYNG3WM.js.map → chunk-QLH6TSCC.js.map} +1 -1
  9. package/dist/{chunk-BNBEKK3U.cjs → chunk-R6LKHKAI.cjs} +289 -104
  10. package/dist/chunk-R6LKHKAI.cjs.map +1 -0
  11. package/dist/{chunk-XAC7NTIO.js → chunk-VFV5FVVI.js} +4 -4
  12. package/dist/{chunk-XAC7NTIO.js.map → chunk-VFV5FVVI.js.map} +1 -1
  13. package/dist/{chunk-GSTTJ46F.cjs → chunk-WAPGTQDR.cjs} +5 -5
  14. package/dist/{chunk-GSTTJ46F.cjs.map → chunk-WAPGTQDR.cjs.map} +1 -1
  15. package/dist/{chunk-7MZLBGFQ.cjs → chunk-WQSK3Z4K.cjs} +23 -23
  16. package/dist/{chunk-7MZLBGFQ.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-jwRcC2QD.d.cts → index-BHkRA0mM.d.cts} +1 -1
  22. package/dist/{index-Du3Akr_E.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 +48 -6
  27. package/dist/react/index.d.ts +48 -6
  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-BHQRB_YT.d.cts → tools-coIcskZ4.d.cts} +18 -4
  64. package/dist/{tools-BHQRB_YT.d.ts → tools-coIcskZ4.d.ts} +18 -4
  65. package/dist/{types-8_Hp2rmm.d.cts → types-C8t4Ut8f.d.cts} +1 -1
  66. package/dist/{types-OYi-iUVY.d.ts → types-rjaSVmEF.d.ts} +1 -1
  67. package/dist/ui/index.cjs +8 -8
  68. package/dist/ui/index.d.cts +1 -1
  69. package/dist/ui/index.d.ts +1 -1
  70. package/dist/ui/index.js +4 -4
  71. package/package.json +1 -1
  72. package/dist/chunk-BNBEKK3U.cjs.map +0 -1
  73. package/dist/chunk-VXT2O6R6.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-XAC7NTIO.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';
@@ -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, tool, args) {
525
+ function buildToolResultContentForAI(result, tool2, args) {
532
526
  if (typeof result === "string") return result;
533
527
  const typedResult = result;
534
- const responseMode = typedResult?._aiResponseMode ?? tool?.aiResponseMode ?? "full";
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 && tool?.aiContext) {
540
- 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;
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((tool) => tool.available !== false).map((tool) => ({
897
- name: tool.name,
898
- description: tool.description,
899
- 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
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 tool of this.config.tools) {
917
- toolDefMap.set(tool.name, {
918
- name: tool.name,
919
- aiResponseMode: tool.aiResponseMode,
920
- 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
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" && !msg.tool_calls?.length && msg.content) {
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
- const finalMessage = streamStateToMessage(this.streamState);
1032
- this.state.updateMessageById(
1033
- this.streamState.messageId,
1034
- () => finalMessage
1035
- );
1036
- if (!finalMessage.content && (!finalMessage.toolCalls || finalMessage.toolCalls.length === 0)) {
1037
- 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
+ }
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 tool of config.tools) {
1185
- this.registerTool(tool);
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(tool) {
1266
- const existing = this.registeredTools.get(tool.name);
1361
+ registerTool(tool2) {
1362
+ const existing = this.registeredTools.get(tool2.name);
1267
1363
  if (existing) {
1268
- existing.tool = tool;
1364
+ existing.tool = tool2;
1269
1365
  existing.refCount++;
1270
1366
  existing.active = true;
1271
1367
  } else {
1272
- this.registeredTools.set(tool.name, {
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 tool = this.getTool(toolCall.name);
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: tool?.hidden
1444
+ hidden: tool2?.hidden
1349
1445
  };
1350
1446
  this.addToolExecution(execution);
1351
1447
  this.callbacks.onToolStart?.(execution);
1352
- if (!tool) {
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 (tool.needsApproval && !this.config.autoApprove) {
1367
- 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;
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 (!tool.handler) {
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 tool.handler(toolCall.args, {
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(tool) {
1823
- this.agentLoop.registerTool(tool);
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
- (tool) => toolAdapter.toToolDefinition(tool, {
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 tool of toolDefinitions) {
2321
- registerTool(tool);
2322
- registeredToolsRef.current.push(tool.name);
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((tool) => {
2480
- chatRef.current?.registerTool(tool);
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((tool) => {
2810
- if (tool === "screenshot") return screenshot;
2811
- if (tool === "console") return consoleCapture;
2812
- 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;
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
- (tool) => !rememberedConsentRef.current.has(tool)
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
- (tool) => rememberedConsentRef.current.add(tool)
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
- (tool) => rememberedConsentRef.current.add(tool)
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((tool) => {
2933
- if (tool === "screenshot") return screenshot;
2934
- if (tool === "console") return consoleCapture;
2935
- 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;
2936
3121
  return false;
2937
3122
  });
2938
3123
  return result;
@@ -2979,7 +3164,7 @@ function useTool(config, dependencies = []) {
2979
3164
  const configRef = useRef(config);
2980
3165
  configRef.current = config;
2981
3166
  useEffect(() => {
2982
- const tool = {
3167
+ const tool2 = {
2983
3168
  name: config.name,
2984
3169
  description: config.description,
2985
3170
  location: "client",
@@ -2993,7 +3178,7 @@ function useTool(config, dependencies = []) {
2993
3178
  approvalMessage: config.approvalMessage,
2994
3179
  hidden: config.hidden
2995
3180
  };
2996
- registerTool(tool);
3181
+ registerTool(tool2);
2997
3182
  return () => {
2998
3183
  unregisterTool(config.name);
2999
3184
  };
@@ -3064,7 +3249,7 @@ function useToolWithSchema(config, dependencies = []) {
3064
3249
  }
3065
3250
  }, [config.schema, config.name]);
3066
3251
  useEffect(() => {
3067
- const tool = {
3252
+ const tool2 = {
3068
3253
  name: config.name,
3069
3254
  description: config.description,
3070
3255
  location: "client",
@@ -3075,7 +3260,7 @@ function useToolWithSchema(config, dependencies = []) {
3075
3260
  render: config.render,
3076
3261
  available: config.available ?? true
3077
3262
  };
3078
- registerTool(tool);
3263
+ registerTool(tool2);
3079
3264
  return () => {
3080
3265
  unregisterTool(config.name);
3081
3266
  };
@@ -3098,7 +3283,7 @@ function useToolsWithSchema(tools, dependencies = []) {
3098
3283
  );
3099
3284
  inputSchema = { type: "object", properties: {} };
3100
3285
  }
3101
- const tool = {
3286
+ const tool2 = {
3102
3287
  name: config.name,
3103
3288
  description: config.description,
3104
3289
  location: "client",
@@ -3114,7 +3299,7 @@ function useToolsWithSchema(tools, dependencies = []) {
3114
3299
  },
3115
3300
  available: config.available ?? true
3116
3301
  };
3117
- registerTool(tool);
3302
+ registerTool(tool2);
3118
3303
  toolNames.push(config.name);
3119
3304
  }
3120
3305
  return () => {
@@ -3146,14 +3331,14 @@ function useToolExecutor() {
3146
3331
  toolsRef.current = registeredTools;
3147
3332
  const executeTool = useCallback(
3148
3333
  async (toolCall) => {
3149
- const tool = toolsRef.current.find((t) => t.name === toolCall.name);
3150
- if (!tool) {
3334
+ const tool2 = toolsRef.current.find((t) => t.name === toolCall.name);
3335
+ if (!tool2) {
3151
3336
  return {
3152
3337
  success: false,
3153
3338
  error: `Unknown tool: ${toolCall.name}`
3154
3339
  };
3155
3340
  }
3156
- if (!tool.handler) {
3341
+ if (!tool2.handler) {
3157
3342
  return {
3158
3343
  success: false,
3159
3344
  error: `Tool "${toolCall.name}" has no handler`
@@ -3166,12 +3351,12 @@ function useToolExecutor() {
3166
3351
  status: "executing",
3167
3352
  timestamp: Date.now(),
3168
3353
  approvalStatus: "none",
3169
- hidden: tool.hidden
3354
+ hidden: tool2.hidden
3170
3355
  };
3171
3356
  addToolExecution?.(execution);
3172
3357
  try {
3173
3358
  const startTime = Date.now();
3174
- const result = await tool.handler(toolCall.input);
3359
+ const result = await tool2.handler(toolCall.input);
3175
3360
  const duration = Date.now() - startTime;
3176
3361
  updateToolExecution?.(toolCall.id, {
3177
3362
  status: result.success ? "completed" : "error",
@@ -3646,9 +3831,9 @@ function useDevLogger() {
3646
3831
  })
3647
3832
  );
3648
3833
  const pendingApprovalsCount = ctx.pendingApprovals?.length || 0;
3649
- const registeredTools = (ctx.registeredTools || []).map((tool) => ({
3650
- name: tool.name,
3651
- location: tool.location || "client"
3834
+ const registeredTools = (ctx.registeredTools || []).map((tool2) => ({
3835
+ name: tool2.name,
3836
+ location: tool2.location || "client"
3652
3837
  }));
3653
3838
  const registeredActions = (ctx.registeredActions || []).map((action) => ({
3654
3839
  name: action.name
@@ -4473,5 +4658,5 @@ function useChat(config) {
4473
4658
  }
4474
4659
 
4475
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 };
4476
- //# sourceMappingURL=chunk-VXT2O6R6.js.map
4477
- //# sourceMappingURL=chunk-VXT2O6R6.js.map
4661
+ //# sourceMappingURL=chunk-DMBFN7KO.js.map
4662
+ //# sourceMappingURL=chunk-DMBFN7KO.js.map