@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.
Files changed (75) hide show
  1. package/dist/{chunk-XAC7NTIO.js → chunk-37KEHUCE.js} +14 -10
  2. package/dist/chunk-37KEHUCE.js.map +1 -0
  3. package/dist/{chunk-VXT2O6R6.js → chunk-7PKGRYHY.js} +278 -82
  4. package/dist/chunk-7PKGRYHY.js.map +1 -0
  5. package/dist/{chunk-VUHP6TAN.js → chunk-LZMBBGWH.js} +3 -3
  6. package/dist/{chunk-VUHP6TAN.js.map → chunk-LZMBBGWH.js.map} +1 -1
  7. package/dist/{chunk-BNBEKK3U.cjs → chunk-N6VZ7FOW.cjs} +302 -106
  8. package/dist/chunk-N6VZ7FOW.cjs.map +1 -0
  9. package/dist/{chunk-7MZLBGFQ.cjs → chunk-OQPRIB73.cjs} +33 -29
  10. package/dist/chunk-OQPRIB73.cjs.map +1 -0
  11. package/dist/{chunk-CSEZZ5DX.cjs → chunk-POZNNKNJ.cjs} +2 -2
  12. package/dist/{chunk-CSEZZ5DX.cjs.map → chunk-POZNNKNJ.cjs.map} +1 -1
  13. package/dist/{chunk-BMYNG3WM.js → chunk-QLH6TSCC.js} +2 -2
  14. package/dist/{chunk-BMYNG3WM.js.map → chunk-QLH6TSCC.js.map} +1 -1
  15. package/dist/{chunk-GSTTJ46F.cjs → chunk-WAPGTQDR.cjs} +5 -5
  16. package/dist/{chunk-GSTTJ46F.cjs.map → chunk-WAPGTQDR.cjs.map} +1 -1
  17. package/dist/core/index.cjs +80 -80
  18. package/dist/core/index.d.cts +17 -6
  19. package/dist/core/index.d.ts +17 -6
  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 +78 -19
  27. package/dist/react/index.d.ts +78 -19
  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-7MZLBGFQ.cjs.map +0 -1
  73. package/dist/chunk-BNBEKK3U.cjs.map +0 -1
  74. package/dist/chunk-VXT2O6R6.js.map +0 -1
  75. package/dist/chunk-XAC7NTIO.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk7MZLBGFQ_cjs = require('./chunk-7MZLBGFQ.cjs');
3
+ var chunkOQPRIB73_cjs = require('./chunk-OQPRIB73.cjs');
4
4
  var chunkJGPDQDY4_cjs = require('./chunk-JGPDQDY4.cjs');
5
5
  var react = require('react');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -384,17 +384,11 @@ var HttpTransport = class {
384
384
  this.abortController = new AbortController();
385
385
  this.streaming = true;
386
386
  try {
387
- console.log(
388
- "[HttpTransport] Config headers type:",
389
- typeof this.config.headers
390
- );
391
- console.log("[HttpTransport] Config headers:", this.config.headers);
392
387
  const resolved = await resolveValues({
393
388
  url: this.config.url,
394
389
  headers: this.config.headers ?? {},
395
390
  configBody: this.config.body ?? {}
396
391
  });
397
- console.log("[HttpTransport] Resolved headers:", resolved.headers);
398
392
  const response = await fetch(resolved.url, {
399
393
  method: "POST",
400
394
  headers: {
@@ -550,16 +544,16 @@ var HttpTransport = class {
550
544
  };
551
545
 
552
546
  // src/chat/classes/AbstractChat.ts
553
- function buildToolResultContentForAI(result, tool, args) {
547
+ function buildToolResultContentForAI(result, tool2, args) {
554
548
  if (typeof result === "string") return result;
555
549
  const typedResult = result;
556
- const responseMode = typedResult?._aiResponseMode ?? tool?.aiResponseMode ?? "full";
550
+ const responseMode = typedResult?._aiResponseMode ?? tool2?.aiResponseMode ?? "full";
557
551
  if (typedResult?._aiContent) {
558
552
  return JSON.stringify(typedResult._aiContent);
559
553
  }
560
554
  let aiContext = typedResult?._aiContext;
561
- if (!aiContext && tool?.aiContext) {
562
- aiContext = typeof tool.aiContext === "function" ? tool.aiContext(typedResult, args ?? {}) : tool.aiContext;
555
+ if (!aiContext && tool2?.aiContext) {
556
+ aiContext = typeof tool2.aiContext === "function" ? tool2.aiContext(typedResult, args ?? {}) : tool2.aiContext;
563
557
  }
564
558
  switch (responseMode) {
565
559
  case "none":
@@ -915,10 +909,10 @@ var AbstractChat = class {
915
909
  * Build the request payload
916
910
  */
917
911
  buildRequest() {
918
- const tools = this.config.tools?.filter((tool) => tool.available !== false).map((tool) => ({
919
- name: tool.name,
920
- description: tool.description,
921
- inputSchema: tool.inputSchema
912
+ const tools = this.config.tools?.filter((tool2) => tool2.available !== false).map((tool2) => ({
913
+ name: tool2.name,
914
+ description: tool2.description,
915
+ inputSchema: tool2.inputSchema
922
916
  }));
923
917
  const toolCallMap = /* @__PURE__ */ new Map();
924
918
  for (const msg of this.state.messages) {
@@ -935,11 +929,11 @@ var AbstractChat = class {
935
929
  }
936
930
  const toolDefMap = /* @__PURE__ */ new Map();
937
931
  if (this.config.tools) {
938
- for (const tool of this.config.tools) {
939
- toolDefMap.set(tool.name, {
940
- name: tool.name,
941
- aiResponseMode: tool.aiResponseMode,
942
- aiContext: tool.aiContext
932
+ for (const tool2 of this.config.tools) {
933
+ toolDefMap.set(tool2.name, {
934
+ name: tool2.name,
935
+ aiResponseMode: tool2.aiResponseMode,
936
+ aiContext: tool2.aiContext
943
937
  });
944
938
  }
945
939
  }
@@ -1011,7 +1005,70 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
1011
1005
  this.handleError(error);
1012
1006
  return;
1013
1007
  }
1008
+ if (chunk.type === "message:end" && this.streamState?.content) {
1009
+ this.debug("message:end mid-stream - finalizing current turn");
1010
+ const turnMessage = streamStateToMessage(this.streamState);
1011
+ const toolCallsHidden = {};
1012
+ for (const [id, result] of this.streamState.toolResults) {
1013
+ if (result.hidden !== void 0) {
1014
+ toolCallsHidden[id] = result.hidden;
1015
+ }
1016
+ }
1017
+ if (turnMessage.toolCalls?.length && Object.keys(toolCallsHidden).length > 0) {
1018
+ turnMessage.metadata = {
1019
+ ...turnMessage.metadata,
1020
+ toolCallsHidden
1021
+ };
1022
+ }
1023
+ this.state.updateMessageById(
1024
+ this.streamState.messageId,
1025
+ () => turnMessage
1026
+ );
1027
+ this.callbacks.onMessageFinish?.(turnMessage);
1028
+ this.streamState = null;
1029
+ continue;
1030
+ }
1031
+ if (chunk.type === "message:start" && this.streamState === null) {
1032
+ this.debug("message:start after mid-stream end - creating new message");
1033
+ const newMessage = createEmptyAssistantMessage();
1034
+ this.state.pushMessage(newMessage);
1035
+ this.streamState = createStreamState(newMessage.id);
1036
+ this.callbacks.onMessageStart?.(newMessage.id);
1037
+ continue;
1038
+ }
1039
+ if (!this.streamState) {
1040
+ this.debug("warning", "streamState is null, skipping chunk");
1041
+ continue;
1042
+ }
1014
1043
  this.streamState = processStreamChunk(chunk, this.streamState);
1044
+ if (chunk.type === "action:start") {
1045
+ this.callbacks.onServerToolStart?.({
1046
+ id: chunk.id,
1047
+ name: chunk.name,
1048
+ hidden: chunk.hidden
1049
+ });
1050
+ } else if (chunk.type === "action:args") {
1051
+ let args = {};
1052
+ try {
1053
+ args = JSON.parse(chunk.args);
1054
+ } catch {
1055
+ }
1056
+ const existingResult = this.streamState?.toolResults.get(chunk.id);
1057
+ if (existingResult) {
1058
+ this.callbacks.onServerToolArgs?.({
1059
+ id: chunk.id,
1060
+ name: existingResult.name,
1061
+ args
1062
+ });
1063
+ }
1064
+ } else if (chunk.type === "action:end") {
1065
+ this.callbacks.onServerToolEnd?.({
1066
+ id: chunk.id,
1067
+ name: chunk.name,
1068
+ result: chunk.result,
1069
+ error: chunk.error
1070
+ });
1071
+ }
1015
1072
  const updatedMessage = streamStateToMessage(this.streamState);
1016
1073
  this.state.updateMessageById(
1017
1074
  this.streamState.messageId,
@@ -1031,17 +1088,30 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
1031
1088
  this.debug("processDoneMessages", {
1032
1089
  count: chunk.messages.length
1033
1090
  });
1091
+ const toolCallsHidden = {};
1092
+ if (this.streamState?.toolResults) {
1093
+ for (const [id, result] of this.streamState.toolResults) {
1094
+ if (result.hidden !== void 0) {
1095
+ toolCallsHidden[id] = result.hidden;
1096
+ }
1097
+ }
1098
+ }
1034
1099
  for (const msg of chunk.messages) {
1035
- if (msg.role === "assistant" && !msg.tool_calls?.length && msg.content) {
1100
+ if (msg.role === "assistant") {
1036
1101
  continue;
1037
1102
  }
1103
+ let metadata;
1104
+ if (msg.role === "assistant" && msg.tool_calls?.length && Object.keys(toolCallsHidden).length > 0) {
1105
+ metadata = { toolCallsHidden };
1106
+ }
1038
1107
  const message = {
1039
1108
  id: generateMessageId(),
1040
1109
  role: msg.role,
1041
1110
  content: msg.content ?? "",
1042
1111
  toolCalls: msg.tool_calls,
1043
1112
  toolCallId: msg.tool_call_id,
1044
- createdAt: /* @__PURE__ */ new Date()
1113
+ createdAt: /* @__PURE__ */ new Date(),
1114
+ metadata
1045
1115
  };
1046
1116
  this.state.pushMessage(message);
1047
1117
  }
@@ -1050,15 +1120,32 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
1050
1120
  }
1051
1121
  }
1052
1122
  this.debug("handleStreamResponse", `Processed ${chunkCount} chunks`);
1053
- const finalMessage = streamStateToMessage(this.streamState);
1054
- this.state.updateMessageById(
1055
- this.streamState.messageId,
1056
- () => finalMessage
1057
- );
1058
- if (!finalMessage.content && (!finalMessage.toolCalls || finalMessage.toolCalls.length === 0)) {
1059
- this.debug("warning", "Empty response - no content and no tool calls");
1123
+ if (!this.streamState) {
1124
+ this.debug("streamState already finalized via message:end");
1125
+ } else {
1126
+ const toolCallsHidden = {};
1127
+ if (this.streamState.toolResults) {
1128
+ for (const [id, result] of this.streamState.toolResults) {
1129
+ if (result.hidden !== void 0) {
1130
+ toolCallsHidden[id] = result.hidden;
1131
+ }
1132
+ }
1133
+ }
1134
+ const finalMessage = streamStateToMessage(this.streamState);
1135
+ if (finalMessage.toolCalls?.length && Object.keys(toolCallsHidden).length > 0) {
1136
+ finalMessage.metadata = {
1137
+ ...finalMessage.metadata,
1138
+ toolCallsHidden
1139
+ };
1140
+ }
1141
+ this.state.updateMessageById(
1142
+ this.streamState.messageId,
1143
+ () => finalMessage
1144
+ );
1145
+ if (!finalMessage.content && (!finalMessage.toolCalls || finalMessage.toolCalls.length === 0)) {
1146
+ this.debug("warning", "Empty response - no content and no tool calls");
1147
+ }
1060
1148
  }
1061
- this.callbacks.onMessageFinish?.(finalMessage);
1062
1149
  this.callbacks.onMessagesChange?.(this.state.messages);
1063
1150
  if (!toolCallsEmitted) {
1064
1151
  this.state.status = "ready";
@@ -1203,8 +1290,8 @@ var AbstractAgentLoop = class {
1203
1290
  this._maxIterations = config.maxIterations ?? 20;
1204
1291
  this._maxExecutionHistory = config.maxExecutionHistory ?? 100;
1205
1292
  if (config.tools) {
1206
- for (const tool of config.tools) {
1207
- this.registerTool(tool);
1293
+ for (const tool2 of config.tools) {
1294
+ this.registerTool(tool2);
1208
1295
  }
1209
1296
  }
1210
1297
  }
@@ -1263,6 +1350,12 @@ var AbstractAgentLoop = class {
1263
1350
  this._isProcessing = processing;
1264
1351
  }
1265
1352
  addToolExecution(execution) {
1353
+ const existingIndex = this._toolExecutions.findIndex(
1354
+ (e) => e.id === execution.id
1355
+ );
1356
+ if (existingIndex !== -1) {
1357
+ return;
1358
+ }
1266
1359
  this._toolExecutions = [...this._toolExecutions, execution];
1267
1360
  if (this._toolExecutions.length > this._maxExecutionHistory) {
1268
1361
  this._toolExecutions = this._toolExecutions.slice(
@@ -1271,6 +1364,9 @@ var AbstractAgentLoop = class {
1271
1364
  }
1272
1365
  this.callbacks.onExecutionsChange?.(this._toolExecutions);
1273
1366
  }
1367
+ /**
1368
+ * Update a tool execution with partial data
1369
+ */
1274
1370
  updateToolExecution(id, update) {
1275
1371
  this._toolExecutions = this._toolExecutions.map(
1276
1372
  (exec) => exec.id === id ? { ...exec, ...update } : exec
@@ -1284,15 +1380,15 @@ var AbstractAgentLoop = class {
1284
1380
  * Register a tool (reference counted for React StrictMode compatibility)
1285
1381
  * Tools are never fully removed - ref counting ensures StrictMode works correctly
1286
1382
  */
1287
- registerTool(tool) {
1288
- const existing = this.registeredTools.get(tool.name);
1383
+ registerTool(tool2) {
1384
+ const existing = this.registeredTools.get(tool2.name);
1289
1385
  if (existing) {
1290
- existing.tool = tool;
1386
+ existing.tool = tool2;
1291
1387
  existing.refCount++;
1292
1388
  existing.active = true;
1293
1389
  } else {
1294
- this.registeredTools.set(tool.name, {
1295
- tool,
1390
+ this.registeredTools.set(tool2.name, {
1391
+ tool: tool2,
1296
1392
  refCount: 1,
1297
1393
  active: true
1298
1394
  });
@@ -1358,7 +1454,7 @@ var AbstractAgentLoop = class {
1358
1454
  * Execute a single tool
1359
1455
  */
1360
1456
  async executeSingleTool(toolCall) {
1361
- const tool = this.getTool(toolCall.name);
1457
+ const tool2 = this.getTool(toolCall.name);
1362
1458
  const execution = {
1363
1459
  id: toolCall.id,
1364
1460
  toolCallId: toolCall.id,
@@ -1367,11 +1463,11 @@ var AbstractAgentLoop = class {
1367
1463
  status: "pending",
1368
1464
  approvalStatus: "none",
1369
1465
  startedAt: /* @__PURE__ */ new Date(),
1370
- hidden: tool?.hidden
1466
+ hidden: tool2?.hidden
1371
1467
  };
1372
1468
  this.addToolExecution(execution);
1373
1469
  this.callbacks.onToolStart?.(execution);
1374
- if (!tool) {
1470
+ if (!tool2) {
1375
1471
  const errorResult = {
1376
1472
  toolCallId: toolCall.id,
1377
1473
  success: false,
@@ -1385,8 +1481,8 @@ var AbstractAgentLoop = class {
1385
1481
  return errorResult;
1386
1482
  }
1387
1483
  let approvalData;
1388
- if (tool.needsApproval && !this.config.autoApprove) {
1389
- const approvalMessage = typeof tool.approvalMessage === "function" ? tool.approvalMessage(toolCall.args) : tool.approvalMessage;
1484
+ if (tool2.needsApproval && !this.config.autoApprove) {
1485
+ const approvalMessage = typeof tool2.approvalMessage === "function" ? tool2.approvalMessage(toolCall.args) : tool2.approvalMessage;
1390
1486
  execution.approvalStatus = "required";
1391
1487
  execution.approvalMessage = approvalMessage;
1392
1488
  this.updateToolExecution(toolCall.id, {
@@ -1413,13 +1509,13 @@ var AbstractAgentLoop = class {
1413
1509
  }
1414
1510
  this.updateToolExecution(toolCall.id, { status: "executing" });
1415
1511
  try {
1416
- if (!tool.handler) {
1512
+ if (!tool2.handler) {
1417
1513
  throw new Error(`Tool "${toolCall.name}" has no handler`);
1418
1514
  }
1419
1515
  if (this._isCancelled || this.abortController?.signal.aborted) {
1420
1516
  throw new Error("Tool execution cancelled");
1421
1517
  }
1422
- const result = await tool.handler(toolCall.args, {
1518
+ const result = await tool2.handler(toolCall.args, {
1423
1519
  signal: this.abortController?.signal,
1424
1520
  data: { toolCallId: toolCall.id },
1425
1521
  approvalData
@@ -1503,6 +1599,43 @@ var AbstractAgentLoop = class {
1503
1599
  this.setIteration(0);
1504
1600
  this._maxIterationsReached = false;
1505
1601
  }
1602
+ // ============================================
1603
+ // Server-Side Tool Tracking
1604
+ // ============================================
1605
+ /**
1606
+ * Add a server-side tool execution (from streaming action:start event)
1607
+ * Used to track tools executed on the server (not client-side)
1608
+ */
1609
+ addServerToolExecution(info) {
1610
+ const execution = {
1611
+ id: info.id,
1612
+ toolCallId: info.id,
1613
+ name: info.name,
1614
+ args: {},
1615
+ status: "executing",
1616
+ approvalStatus: "none",
1617
+ startedAt: /* @__PURE__ */ new Date(),
1618
+ hidden: info.hidden
1619
+ };
1620
+ this.addToolExecution(execution);
1621
+ }
1622
+ /**
1623
+ * Update a server-side tool execution with args (from action:args event)
1624
+ */
1625
+ updateServerToolArgs(id, args) {
1626
+ this.updateToolExecution(id, { args });
1627
+ }
1628
+ /**
1629
+ * Complete a server-side tool execution (from action:end event)
1630
+ */
1631
+ completeServerToolExecution(info) {
1632
+ this.updateToolExecution(info.id, {
1633
+ status: info.error ? "failed" : "completed",
1634
+ result: info.result,
1635
+ error: info.error,
1636
+ completedAt: /* @__PURE__ */ new Date()
1637
+ });
1638
+ }
1506
1639
  /**
1507
1640
  * Cancel all pending and executing tools
1508
1641
  * This will:
@@ -1644,7 +1777,59 @@ var ChatWithTools = class {
1644
1777
  onMessageDelta: callbacks.onMessageDelta,
1645
1778
  onMessageFinish: callbacks.onMessageFinish,
1646
1779
  onToolCalls: callbacks.onToolCalls,
1647
- onFinish: callbacks.onFinish
1780
+ onFinish: callbacks.onFinish,
1781
+ // Server-side tool callbacks - track in agentLoop for UI display
1782
+ // IMPORTANT: Only track tools that are NOT registered client-side
1783
+ // Client-side tools are tracked via executeToolCalls() path
1784
+ onServerToolStart: (info) => {
1785
+ const existingExecution = this.agentLoop.toolExecutions.find(
1786
+ (e) => e.id === info.id
1787
+ );
1788
+ if (existingExecution) {
1789
+ if (info.hidden !== void 0 && existingExecution.hidden !== info.hidden) {
1790
+ this.debug(
1791
+ "Updating hidden flag for existing execution:",
1792
+ info.name,
1793
+ info.hidden
1794
+ );
1795
+ this.agentLoop.updateToolExecution(info.id, {
1796
+ hidden: info.hidden
1797
+ });
1798
+ }
1799
+ return;
1800
+ }
1801
+ const isClientTool = this.agentLoop.tools.some(
1802
+ (t) => t.name === info.name && t.location === "client"
1803
+ );
1804
+ if (isClientTool) {
1805
+ this.debug("Skipping server tracking for client tool:", info.name);
1806
+ return;
1807
+ }
1808
+ this.debug("Server tool started:", info.name, {
1809
+ hidden: info.hidden,
1810
+ id: info.id
1811
+ });
1812
+ this.agentLoop.addServerToolExecution(info);
1813
+ },
1814
+ onServerToolArgs: (info) => {
1815
+ const isClientTool = this.agentLoop.tools.some(
1816
+ (t) => t.name === info.name && t.location === "client"
1817
+ );
1818
+ if (isClientTool) return;
1819
+ this.debug("Server tool args:", info.name, info.args);
1820
+ this.agentLoop.updateServerToolArgs(info.id, info.args ?? {});
1821
+ },
1822
+ onServerToolEnd: (info) => {
1823
+ const isClientTool = this.agentLoop.tools.some(
1824
+ (t) => t.name === info.name && t.location === "client"
1825
+ );
1826
+ if (isClientTool) return;
1827
+ this.debug("Server tool ended:", info.name, {
1828
+ error: info.error,
1829
+ hasResult: !!info.result
1830
+ });
1831
+ this.agentLoop.completeServerToolExecution(info);
1832
+ }
1648
1833
  }
1649
1834
  });
1650
1835
  this.wireEvents();
@@ -1841,8 +2026,8 @@ var ChatWithTools = class {
1841
2026
  /**
1842
2027
  * Register a tool
1843
2028
  */
1844
- registerTool(tool) {
1845
- this.agentLoop.registerTool(tool);
2029
+ registerTool(tool2) {
2030
+ this.agentLoop.registerTool(tool2);
1846
2031
  this.chat.setTools(this.agentLoop.tools);
1847
2032
  }
1848
2033
  /**
@@ -2310,7 +2495,7 @@ function useMCPTools(config) {
2310
2495
  return [];
2311
2496
  }
2312
2497
  return mcpClient.state.tools.map(
2313
- (tool) => toolAdapter.toToolDefinition(tool, {
2498
+ (tool2) => toolAdapter.toToolDefinition(tool2, {
2314
2499
  prefix: prefixToolNames,
2315
2500
  asServerTool: true,
2316
2501
  // MCP tools execute remotely
@@ -2339,9 +2524,9 @@ function useMCPTools(config) {
2339
2524
  }
2340
2525
  registeredToolsRef.current = [];
2341
2526
  if (mcpClient.isConnected && toolDefinitions.length > 0) {
2342
- for (const tool of toolDefinitions) {
2343
- registerTool(tool);
2344
- registeredToolsRef.current.push(tool.name);
2527
+ for (const tool2 of toolDefinitions) {
2528
+ registerTool(tool2);
2529
+ registeredToolsRef.current.push(tool2.name);
2345
2530
  }
2346
2531
  }
2347
2532
  return () => {
@@ -2498,8 +2683,8 @@ function CopilotProvider({
2498
2683
  );
2499
2684
  const error = errorFromChat ?? null;
2500
2685
  const isLoading = status === "streaming" || status === "submitted";
2501
- const registerTool = react.useCallback((tool) => {
2502
- chatRef.current?.registerTool(tool);
2686
+ const registerTool = react.useCallback((tool2) => {
2687
+ chatRef.current?.registerTool(tool2);
2503
2688
  }, []);
2504
2689
  const unregisterTool = react.useCallback((name) => {
2505
2690
  chatRef.current?.unregisterTool(name);
@@ -2774,17 +2959,17 @@ function useAITools(options = {}) {
2774
2959
  const rememberedConsentRef = react.useRef(/* @__PURE__ */ new Set());
2775
2960
  react.useEffect(() => {
2776
2961
  if (!autoStart || !isEnabled) return;
2777
- if (consoleCapture && !chunk7MZLBGFQ_cjs.isConsoleCaptureActive()) {
2778
- chunk7MZLBGFQ_cjs.startConsoleCapture(consoleOptions);
2962
+ if (consoleCapture && !chunkOQPRIB73_cjs.isConsoleCaptureActive()) {
2963
+ chunkOQPRIB73_cjs.startConsoleCapture(consoleOptions);
2779
2964
  setActiveCaptures((prev) => ({ ...prev, console: true }));
2780
2965
  }
2781
- if (network && !chunk7MZLBGFQ_cjs.isNetworkCaptureActive()) {
2782
- chunk7MZLBGFQ_cjs.startNetworkCapture(networkOptions);
2966
+ if (network && !chunkOQPRIB73_cjs.isNetworkCaptureActive()) {
2967
+ chunkOQPRIB73_cjs.startNetworkCapture(networkOptions);
2783
2968
  setActiveCaptures((prev) => ({ ...prev, network: true }));
2784
2969
  }
2785
2970
  return () => {
2786
- chunk7MZLBGFQ_cjs.stopConsoleCapture();
2787
- chunk7MZLBGFQ_cjs.stopNetworkCapture();
2971
+ chunkOQPRIB73_cjs.stopConsoleCapture();
2972
+ chunkOQPRIB73_cjs.stopNetworkCapture();
2788
2973
  };
2789
2974
  }, [
2790
2975
  autoStart,
@@ -2799,12 +2984,12 @@ function useAITools(options = {}) {
2799
2984
  if (!screenshot) {
2800
2985
  throw new Error("Screenshot capture is not enabled");
2801
2986
  }
2802
- if (!chunk7MZLBGFQ_cjs.isScreenshotSupported()) {
2987
+ if (!chunkOQPRIB73_cjs.isScreenshotSupported()) {
2803
2988
  throw new Error(
2804
2989
  "Screenshot capture is not supported in this environment"
2805
2990
  );
2806
2991
  }
2807
- return chunk7MZLBGFQ_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
2992
+ return chunkOQPRIB73_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
2808
2993
  },
2809
2994
  [screenshot, screenshotOptions]
2810
2995
  );
@@ -2813,7 +2998,7 @@ function useAITools(options = {}) {
2813
2998
  if (!consoleCapture) {
2814
2999
  return { logs: [], totalCaptured: 0 };
2815
3000
  }
2816
- return chunk7MZLBGFQ_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
3001
+ return chunkOQPRIB73_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
2817
3002
  },
2818
3003
  [consoleCapture, consoleOptions]
2819
3004
  );
@@ -2822,16 +3007,16 @@ function useAITools(options = {}) {
2822
3007
  if (!network) {
2823
3008
  return { requests: [], totalCaptured: 0 };
2824
3009
  }
2825
- return chunk7MZLBGFQ_cjs.getNetworkRequests({ ...networkOptions, ...opts });
3010
+ return chunkOQPRIB73_cjs.getNetworkRequests({ ...networkOptions, ...opts });
2826
3011
  },
2827
3012
  [network, networkOptions]
2828
3013
  );
2829
3014
  const requestConsent = react.useCallback(
2830
3015
  async (tools, reason = "") => {
2831
- const enabledTools = tools.filter((tool) => {
2832
- if (tool === "screenshot") return screenshot;
2833
- if (tool === "console") return consoleCapture;
2834
- if (tool === "network") return network;
3016
+ const enabledTools = tools.filter((tool2) => {
3017
+ if (tool2 === "screenshot") return screenshot;
3018
+ if (tool2 === "console") return consoleCapture;
3019
+ if (tool2 === "network") return network;
2835
3020
  return false;
2836
3021
  });
2837
3022
  if (enabledTools.length === 0) {
@@ -2841,7 +3026,7 @@ function useAITools(options = {}) {
2841
3026
  return { approved: enabledTools, denied: [] };
2842
3027
  }
2843
3028
  const needsConsent = enabledTools.filter(
2844
- (tool) => !rememberedConsentRef.current.has(tool)
3029
+ (tool2) => !rememberedConsentRef.current.has(tool2)
2845
3030
  );
2846
3031
  if (needsConsent.length === 0) {
2847
3032
  return { approved: enabledTools, denied: [] };
@@ -2855,7 +3040,7 @@ function useAITools(options = {}) {
2855
3040
  const response = await onConsentRequest(request);
2856
3041
  if (response.remember) {
2857
3042
  response.approved.forEach(
2858
- (tool) => rememberedConsentRef.current.add(tool)
3043
+ (tool2) => rememberedConsentRef.current.add(tool2)
2859
3044
  );
2860
3045
  }
2861
3046
  return response;
@@ -2865,7 +3050,7 @@ function useAITools(options = {}) {
2865
3050
  consentResolverRef.current = (response) => {
2866
3051
  if (response.remember) {
2867
3052
  response.approved.forEach(
2868
- (tool) => rememberedConsentRef.current.add(tool)
3053
+ (tool2) => rememberedConsentRef.current.add(tool2)
2869
3054
  );
2870
3055
  }
2871
3056
  resolve(response);
@@ -2915,23 +3100,23 @@ function useAITools(options = {}) {
2915
3100
  ]
2916
3101
  );
2917
3102
  const startCapturing = react.useCallback(() => {
2918
- if (consoleCapture && !chunk7MZLBGFQ_cjs.isConsoleCaptureActive()) {
2919
- chunk7MZLBGFQ_cjs.startConsoleCapture(consoleOptions);
3103
+ if (consoleCapture && !chunkOQPRIB73_cjs.isConsoleCaptureActive()) {
3104
+ chunkOQPRIB73_cjs.startConsoleCapture(consoleOptions);
2920
3105
  setActiveCaptures((prev) => ({ ...prev, console: true }));
2921
3106
  }
2922
- if (network && !chunk7MZLBGFQ_cjs.isNetworkCaptureActive()) {
2923
- chunk7MZLBGFQ_cjs.startNetworkCapture(networkOptions);
3107
+ if (network && !chunkOQPRIB73_cjs.isNetworkCaptureActive()) {
3108
+ chunkOQPRIB73_cjs.startNetworkCapture(networkOptions);
2924
3109
  setActiveCaptures((prev) => ({ ...prev, network: true }));
2925
3110
  }
2926
3111
  }, [consoleCapture, network, consoleOptions, networkOptions]);
2927
3112
  const stopCapturing = react.useCallback(() => {
2928
- chunk7MZLBGFQ_cjs.stopConsoleCapture();
2929
- chunk7MZLBGFQ_cjs.stopNetworkCapture();
3113
+ chunkOQPRIB73_cjs.stopConsoleCapture();
3114
+ chunkOQPRIB73_cjs.stopNetworkCapture();
2930
3115
  setActiveCaptures({ console: false, network: false });
2931
3116
  }, []);
2932
3117
  const clearCaptured = react.useCallback(() => {
2933
- chunk7MZLBGFQ_cjs.clearConsoleLogs();
2934
- chunk7MZLBGFQ_cjs.clearNetworkRequests();
3118
+ chunkOQPRIB73_cjs.clearConsoleLogs();
3119
+ chunkOQPRIB73_cjs.clearNetworkRequests();
2935
3120
  }, []);
2936
3121
  const formatForAI = react.useCallback((context) => {
2937
3122
  const parts = [];
@@ -2941,20 +3126,20 @@ function useAITools(options = {}) {
2941
3126
  );
2942
3127
  }
2943
3128
  if (context.consoleLogs && context.consoleLogs.logs.length > 0) {
2944
- parts.push(chunk7MZLBGFQ_cjs.formatLogsForAI(context.consoleLogs.logs));
3129
+ parts.push(chunkOQPRIB73_cjs.formatLogsForAI(context.consoleLogs.logs));
2945
3130
  }
2946
3131
  if (context.networkRequests && context.networkRequests.requests.length > 0) {
2947
- parts.push(chunk7MZLBGFQ_cjs.formatRequestsForAI(context.networkRequests.requests));
3132
+ parts.push(chunkOQPRIB73_cjs.formatRequestsForAI(context.networkRequests.requests));
2948
3133
  }
2949
3134
  return parts.length > 0 ? parts.join("\n\n---\n\n") : "No context captured.";
2950
3135
  }, []);
2951
3136
  const detectIntentFn = react.useCallback(
2952
3137
  (message) => {
2953
- const result = chunk7MZLBGFQ_cjs.detectIntent(message);
2954
- result.suggestedTools = result.suggestedTools.filter((tool) => {
2955
- if (tool === "screenshot") return screenshot;
2956
- if (tool === "console") return consoleCapture;
2957
- if (tool === "network") return network;
3138
+ const result = chunkOQPRIB73_cjs.detectIntent(message);
3139
+ result.suggestedTools = result.suggestedTools.filter((tool2) => {
3140
+ if (tool2 === "screenshot") return screenshot;
3141
+ if (tool2 === "console") return consoleCapture;
3142
+ if (tool2 === "network") return network;
2958
3143
  return false;
2959
3144
  });
2960
3145
  return result;
@@ -2996,16 +3181,27 @@ function useAITools(options = {}) {
2996
3181
  ]
2997
3182
  );
2998
3183
  }
3184
+ function isZodSchema(value) {
3185
+ if (value === null || typeof value !== "object") return false;
3186
+ const obj = value;
3187
+ return "_def" in obj && typeof obj._def === "object" || "_zod" in obj && typeof obj._zod === "object" || "~standard" in obj;
3188
+ }
2999
3189
  function useTool(config, dependencies = []) {
3000
3190
  const { registerTool, unregisterTool } = useCopilot();
3001
3191
  const configRef = react.useRef(config);
3002
3192
  configRef.current = config;
3193
+ const inputSchema = react.useMemo(() => {
3194
+ if (isZodSchema(config.inputSchema)) {
3195
+ return chunkOQPRIB73_cjs.zodToJsonSchema(config.inputSchema);
3196
+ }
3197
+ return config.inputSchema;
3198
+ }, [config.inputSchema]);
3003
3199
  react.useEffect(() => {
3004
- const tool = {
3200
+ const tool2 = {
3005
3201
  name: config.name,
3006
3202
  description: config.description,
3007
3203
  location: "client",
3008
- inputSchema: config.inputSchema,
3204
+ inputSchema,
3009
3205
  handler: async (params, context) => {
3010
3206
  return configRef.current.handler(params, context);
3011
3207
  },
@@ -3015,11 +3211,11 @@ function useTool(config, dependencies = []) {
3015
3211
  approvalMessage: config.approvalMessage,
3016
3212
  hidden: config.hidden
3017
3213
  };
3018
- registerTool(tool);
3214
+ registerTool(tool2);
3019
3215
  return () => {
3020
3216
  unregisterTool(config.name);
3021
3217
  };
3022
- }, [config.name, ...dependencies]);
3218
+ }, [config.name, inputSchema, ...dependencies]);
3023
3219
  }
3024
3220
  function useTools(tools) {
3025
3221
  const { registerTool, unregisterTool } = useCopilot();
@@ -3065,7 +3261,7 @@ function convertZodSchema(schema, _toolName) {
3065
3261
  }
3066
3262
  } catch {
3067
3263
  }
3068
- return chunk7MZLBGFQ_cjs.zodObjectToInputSchema(schema);
3264
+ return chunkOQPRIB73_cjs.zodObjectToInputSchema(schema);
3069
3265
  }
3070
3266
  function useToolWithSchema(config, dependencies = []) {
3071
3267
  const { registerTool, unregisterTool } = useCopilot();
@@ -3086,7 +3282,7 @@ function useToolWithSchema(config, dependencies = []) {
3086
3282
  }
3087
3283
  }, [config.schema, config.name]);
3088
3284
  react.useEffect(() => {
3089
- const tool = {
3285
+ const tool2 = {
3090
3286
  name: config.name,
3091
3287
  description: config.description,
3092
3288
  location: "client",
@@ -3097,7 +3293,7 @@ function useToolWithSchema(config, dependencies = []) {
3097
3293
  render: config.render,
3098
3294
  available: config.available ?? true
3099
3295
  };
3100
- registerTool(tool);
3296
+ registerTool(tool2);
3101
3297
  return () => {
3102
3298
  unregisterTool(config.name);
3103
3299
  };
@@ -3120,7 +3316,7 @@ function useToolsWithSchema(tools, dependencies = []) {
3120
3316
  );
3121
3317
  inputSchema = { type: "object", properties: {} };
3122
3318
  }
3123
- const tool = {
3319
+ const tool2 = {
3124
3320
  name: config.name,
3125
3321
  description: config.description,
3126
3322
  location: "client",
@@ -3136,7 +3332,7 @@ function useToolsWithSchema(tools, dependencies = []) {
3136
3332
  },
3137
3333
  available: config.available ?? true
3138
3334
  };
3139
- registerTool(tool);
3335
+ registerTool(tool2);
3140
3336
  toolNames.push(config.name);
3141
3337
  }
3142
3338
  return () => {
@@ -3168,14 +3364,14 @@ function useToolExecutor() {
3168
3364
  toolsRef.current = registeredTools;
3169
3365
  const executeTool = react.useCallback(
3170
3366
  async (toolCall) => {
3171
- const tool = toolsRef.current.find((t) => t.name === toolCall.name);
3172
- if (!tool) {
3367
+ const tool2 = toolsRef.current.find((t) => t.name === toolCall.name);
3368
+ if (!tool2) {
3173
3369
  return {
3174
3370
  success: false,
3175
3371
  error: `Unknown tool: ${toolCall.name}`
3176
3372
  };
3177
3373
  }
3178
- if (!tool.handler) {
3374
+ if (!tool2.handler) {
3179
3375
  return {
3180
3376
  success: false,
3181
3377
  error: `Tool "${toolCall.name}" has no handler`
@@ -3188,12 +3384,12 @@ function useToolExecutor() {
3188
3384
  status: "executing",
3189
3385
  timestamp: Date.now(),
3190
3386
  approvalStatus: "none",
3191
- hidden: tool.hidden
3387
+ hidden: tool2.hidden
3192
3388
  };
3193
3389
  addToolExecution?.(execution);
3194
3390
  try {
3195
3391
  const startTime = Date.now();
3196
- const result = await tool.handler(toolCall.input);
3392
+ const result = await tool2.handler(toolCall.input);
3197
3393
  const duration = Date.now() - startTime;
3198
3394
  updateToolExecution?.(toolCall.id, {
3199
3395
  status: result.success ? "completed" : "error",
@@ -3374,7 +3570,7 @@ function useAgent(options) {
3374
3570
  if (!response.ok) {
3375
3571
  throw new Error(`Agent error: ${response.status}`);
3376
3572
  }
3377
- for await (const event of chunk7MZLBGFQ_cjs.streamSSE(response)) {
3573
+ for await (const event of chunkOQPRIB73_cjs.streamSSE(response)) {
3378
3574
  handleAgentEvent(event);
3379
3575
  }
3380
3576
  } catch (err) {
@@ -3668,9 +3864,9 @@ function useDevLogger() {
3668
3864
  })
3669
3865
  );
3670
3866
  const pendingApprovalsCount = ctx.pendingApprovals?.length || 0;
3671
- const registeredTools = (ctx.registeredTools || []).map((tool) => ({
3672
- name: tool.name,
3673
- location: tool.location || "client"
3867
+ const registeredTools = (ctx.registeredTools || []).map((tool2) => ({
3868
+ name: tool2.name,
3869
+ location: tool2.location || "client"
3674
3870
  }));
3675
3871
  const registeredActions = (ctx.registeredActions || []).map((action) => ({
3676
3872
  name: action.name
@@ -3868,7 +4064,7 @@ function createReactThreadManagerState(initialThreads) {
3868
4064
  }
3869
4065
 
3870
4066
  // src/react/internal/ReactThreadManager.ts
3871
- var _ReactThreadManager = class _ReactThreadManager extends chunk7MZLBGFQ_cjs.ThreadManager {
4067
+ var _ReactThreadManager = class _ReactThreadManager extends chunkOQPRIB73_cjs.ThreadManager {
3872
4068
  constructor(config = {}, callbacks = {}) {
3873
4069
  const reactState = new ReactThreadManagerState();
3874
4070
  super({ ...config, state: reactState }, callbacks);
@@ -4535,5 +4731,5 @@ exports.useToolExecutor = useToolExecutor;
4535
4731
  exports.useToolWithSchema = useToolWithSchema;
4536
4732
  exports.useTools = useTools;
4537
4733
  exports.useToolsWithSchema = useToolsWithSchema;
4538
- //# sourceMappingURL=chunk-BNBEKK3U.cjs.map
4539
- //# sourceMappingURL=chunk-BNBEKK3U.cjs.map
4734
+ //# sourceMappingURL=chunk-N6VZ7FOW.cjs.map
4735
+ //# sourceMappingURL=chunk-N6VZ7FOW.cjs.map