@yourgpt/copilot-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk2ZCWVAAK_cjs = require('./chunk-2ZCWVAAK.cjs');
3
+ var chunkIH7WXWX4_cjs = require('./chunk-IH7WXWX4.cjs');
4
4
  var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var z = require('zod');
@@ -844,7 +844,7 @@ var AbstractAgentLoop = class {
844
844
  this._isProcessing = false;
845
845
  // Registered tools
846
846
  this.registeredTools = /* @__PURE__ */ new Map();
847
- // Pending approvals
847
+ // Pending approvals - resolve with approval result including extraData
848
848
  this.pendingApprovals = /* @__PURE__ */ new Map();
849
849
  this.config = config;
850
850
  this.callbacks = callbacks;
@@ -990,15 +990,18 @@ var AbstractAgentLoop = class {
990
990
  });
991
991
  return errorResult;
992
992
  }
993
+ let approvalData;
993
994
  if (tool.needsApproval && !this.config.autoApprove) {
994
- typeof tool.approvalMessage === "function" ? tool.approvalMessage(toolCall.args) : tool.approvalMessage;
995
+ const approvalMessage = typeof tool.approvalMessage === "function" ? tool.approvalMessage(toolCall.args) : tool.approvalMessage;
995
996
  execution.approvalStatus = "required";
997
+ execution.approvalMessage = approvalMessage;
996
998
  this.updateToolExecution(toolCall.id, {
997
- approvalStatus: "required"
999
+ approvalStatus: "required",
1000
+ approvalMessage
998
1001
  });
999
1002
  this.callbacks.onApprovalRequired?.(execution);
1000
- const approved = await this.waitForApproval(toolCall.id, execution);
1001
- if (!approved) {
1003
+ const approvalResult = await this.waitForApproval(toolCall.id, execution);
1004
+ if (!approvalResult.approved) {
1002
1005
  const rejectedResult = {
1003
1006
  toolCallId: toolCall.id,
1004
1007
  success: false,
@@ -1012,9 +1015,7 @@ var AbstractAgentLoop = class {
1012
1015
  });
1013
1016
  return rejectedResult;
1014
1017
  }
1015
- this.updateToolExecution(toolCall.id, {
1016
- approvalStatus: "approved"
1017
- });
1018
+ approvalData = approvalResult.extraData;
1018
1019
  }
1019
1020
  this.updateToolExecution(toolCall.id, { status: "executing" });
1020
1021
  try {
@@ -1022,7 +1023,8 @@ var AbstractAgentLoop = class {
1022
1023
  throw new Error(`Tool "${toolCall.name}" has no handler`);
1023
1024
  }
1024
1025
  const result = await tool.handler(toolCall.args, {
1025
- data: { toolCallId: toolCall.id }
1026
+ data: { toolCallId: toolCall.id },
1027
+ approvalData
1026
1028
  });
1027
1029
  this.updateToolExecution(toolCall.id, {
1028
1030
  status: "completed",
@@ -1056,6 +1058,7 @@ var AbstractAgentLoop = class {
1056
1058
  }
1057
1059
  /**
1058
1060
  * Wait for user approval
1061
+ * Returns approval result with optional extraData from user's action
1059
1062
  */
1060
1063
  waitForApproval(executionId, execution) {
1061
1064
  return new Promise((resolve) => {
@@ -1066,13 +1069,17 @@ var AbstractAgentLoop = class {
1066
1069
  // Actions (implements AgentLoopActions)
1067
1070
  // ============================================
1068
1071
  /**
1069
- * Approve a tool execution
1072
+ * Approve a tool execution with optional extra data
1070
1073
  */
1071
- approveToolExecution(executionId, _permissionLevel) {
1074
+ approveToolExecution(executionId, extraData, _permissionLevel) {
1072
1075
  const pending = this.pendingApprovals.get(executionId);
1073
1076
  if (pending) {
1074
- pending.resolve(true);
1077
+ pending.resolve({ approved: true, extraData });
1075
1078
  this.pendingApprovals.delete(executionId);
1079
+ this.updateToolExecution(executionId, {
1080
+ approvalStatus: "approved",
1081
+ approvalData: extraData
1082
+ });
1076
1083
  }
1077
1084
  }
1078
1085
  /**
@@ -1086,7 +1093,7 @@ var AbstractAgentLoop = class {
1086
1093
  error: reason
1087
1094
  });
1088
1095
  }
1089
- pending.resolve(false);
1096
+ pending.resolve({ approved: false });
1090
1097
  this.pendingApprovals.delete(executionId);
1091
1098
  }
1092
1099
  }
@@ -1130,8 +1137,8 @@ var AbstractAgentLoop = class {
1130
1137
  * Dispose of resources
1131
1138
  */
1132
1139
  dispose() {
1133
- for (const [id, pending] of this.pendingApprovals) {
1134
- pending.resolve(false);
1140
+ for (const [_id, pending] of this.pendingApprovals) {
1141
+ pending.resolve({ approved: false });
1135
1142
  }
1136
1143
  this.pendingApprovals.clear();
1137
1144
  this.registeredTools.clear();
@@ -1321,10 +1328,10 @@ var ChatWithTools = class {
1321
1328
  // Tool Approval
1322
1329
  // ============================================
1323
1330
  /**
1324
- * Approve a tool execution
1331
+ * Approve a tool execution with optional extra data
1325
1332
  */
1326
- approveToolExecution(id, permissionLevel) {
1327
- this.agentLoop.approveToolExecution(id, permissionLevel);
1333
+ approveToolExecution(id, extraData, permissionLevel) {
1334
+ this.agentLoop.approveToolExecution(id, extraData, permissionLevel);
1328
1335
  }
1329
1336
  /**
1330
1337
  * Reject a tool execution
@@ -1667,8 +1674,8 @@ function CopilotProvider({
1667
1674
  chatRef.current?.unregisterTool(name);
1668
1675
  }, []);
1669
1676
  const approveToolExecution = react.useCallback(
1670
- (id, permissionLevel) => {
1671
- chatRef.current?.approveToolExecution(id, permissionLevel);
1677
+ (id, extraData, permissionLevel) => {
1678
+ chatRef.current?.approveToolExecution(id, extraData, permissionLevel);
1672
1679
  },
1673
1680
  []
1674
1681
  );
@@ -1918,17 +1925,17 @@ function useAITools(options = {}) {
1918
1925
  const rememberedConsentRef = react.useRef(/* @__PURE__ */ new Set());
1919
1926
  react.useEffect(() => {
1920
1927
  if (!autoStart || !isEnabled) return;
1921
- if (consoleCapture && !chunk2ZCWVAAK_cjs.isConsoleCaptureActive()) {
1922
- chunk2ZCWVAAK_cjs.startConsoleCapture(consoleOptions);
1928
+ if (consoleCapture && !chunkIH7WXWX4_cjs.isConsoleCaptureActive()) {
1929
+ chunkIH7WXWX4_cjs.startConsoleCapture(consoleOptions);
1923
1930
  setActiveCaptures((prev) => ({ ...prev, console: true }));
1924
1931
  }
1925
- if (network && !chunk2ZCWVAAK_cjs.isNetworkCaptureActive()) {
1926
- chunk2ZCWVAAK_cjs.startNetworkCapture(networkOptions);
1932
+ if (network && !chunkIH7WXWX4_cjs.isNetworkCaptureActive()) {
1933
+ chunkIH7WXWX4_cjs.startNetworkCapture(networkOptions);
1927
1934
  setActiveCaptures((prev) => ({ ...prev, network: true }));
1928
1935
  }
1929
1936
  return () => {
1930
- chunk2ZCWVAAK_cjs.stopConsoleCapture();
1931
- chunk2ZCWVAAK_cjs.stopNetworkCapture();
1937
+ chunkIH7WXWX4_cjs.stopConsoleCapture();
1938
+ chunkIH7WXWX4_cjs.stopNetworkCapture();
1932
1939
  };
1933
1940
  }, [
1934
1941
  autoStart,
@@ -1943,12 +1950,12 @@ function useAITools(options = {}) {
1943
1950
  if (!screenshot) {
1944
1951
  throw new Error("Screenshot capture is not enabled");
1945
1952
  }
1946
- if (!chunk2ZCWVAAK_cjs.isScreenshotSupported()) {
1953
+ if (!chunkIH7WXWX4_cjs.isScreenshotSupported()) {
1947
1954
  throw new Error(
1948
1955
  "Screenshot capture is not supported in this environment"
1949
1956
  );
1950
1957
  }
1951
- return chunk2ZCWVAAK_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
1958
+ return chunkIH7WXWX4_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
1952
1959
  },
1953
1960
  [screenshot, screenshotOptions]
1954
1961
  );
@@ -1957,7 +1964,7 @@ function useAITools(options = {}) {
1957
1964
  if (!consoleCapture) {
1958
1965
  return { logs: [], totalCaptured: 0 };
1959
1966
  }
1960
- return chunk2ZCWVAAK_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
1967
+ return chunkIH7WXWX4_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
1961
1968
  },
1962
1969
  [consoleCapture, consoleOptions]
1963
1970
  );
@@ -1966,7 +1973,7 @@ function useAITools(options = {}) {
1966
1973
  if (!network) {
1967
1974
  return { requests: [], totalCaptured: 0 };
1968
1975
  }
1969
- return chunk2ZCWVAAK_cjs.getNetworkRequests({ ...networkOptions, ...opts });
1976
+ return chunkIH7WXWX4_cjs.getNetworkRequests({ ...networkOptions, ...opts });
1970
1977
  },
1971
1978
  [network, networkOptions]
1972
1979
  );
@@ -2059,23 +2066,23 @@ function useAITools(options = {}) {
2059
2066
  ]
2060
2067
  );
2061
2068
  const startCapturing = react.useCallback(() => {
2062
- if (consoleCapture && !chunk2ZCWVAAK_cjs.isConsoleCaptureActive()) {
2063
- chunk2ZCWVAAK_cjs.startConsoleCapture(consoleOptions);
2069
+ if (consoleCapture && !chunkIH7WXWX4_cjs.isConsoleCaptureActive()) {
2070
+ chunkIH7WXWX4_cjs.startConsoleCapture(consoleOptions);
2064
2071
  setActiveCaptures((prev) => ({ ...prev, console: true }));
2065
2072
  }
2066
- if (network && !chunk2ZCWVAAK_cjs.isNetworkCaptureActive()) {
2067
- chunk2ZCWVAAK_cjs.startNetworkCapture(networkOptions);
2073
+ if (network && !chunkIH7WXWX4_cjs.isNetworkCaptureActive()) {
2074
+ chunkIH7WXWX4_cjs.startNetworkCapture(networkOptions);
2068
2075
  setActiveCaptures((prev) => ({ ...prev, network: true }));
2069
2076
  }
2070
2077
  }, [consoleCapture, network, consoleOptions, networkOptions]);
2071
2078
  const stopCapturing = react.useCallback(() => {
2072
- chunk2ZCWVAAK_cjs.stopConsoleCapture();
2073
- chunk2ZCWVAAK_cjs.stopNetworkCapture();
2079
+ chunkIH7WXWX4_cjs.stopConsoleCapture();
2080
+ chunkIH7WXWX4_cjs.stopNetworkCapture();
2074
2081
  setActiveCaptures({ console: false, network: false });
2075
2082
  }, []);
2076
2083
  const clearCaptured = react.useCallback(() => {
2077
- chunk2ZCWVAAK_cjs.clearConsoleLogs();
2078
- chunk2ZCWVAAK_cjs.clearNetworkRequests();
2084
+ chunkIH7WXWX4_cjs.clearConsoleLogs();
2085
+ chunkIH7WXWX4_cjs.clearNetworkRequests();
2079
2086
  }, []);
2080
2087
  const formatForAI = react.useCallback((context) => {
2081
2088
  const parts = [];
@@ -2085,16 +2092,16 @@ function useAITools(options = {}) {
2085
2092
  );
2086
2093
  }
2087
2094
  if (context.consoleLogs && context.consoleLogs.logs.length > 0) {
2088
- parts.push(chunk2ZCWVAAK_cjs.formatLogsForAI(context.consoleLogs.logs));
2095
+ parts.push(chunkIH7WXWX4_cjs.formatLogsForAI(context.consoleLogs.logs));
2089
2096
  }
2090
2097
  if (context.networkRequests && context.networkRequests.requests.length > 0) {
2091
- parts.push(chunk2ZCWVAAK_cjs.formatRequestsForAI(context.networkRequests.requests));
2098
+ parts.push(chunkIH7WXWX4_cjs.formatRequestsForAI(context.networkRequests.requests));
2092
2099
  }
2093
2100
  return parts.length > 0 ? parts.join("\n\n---\n\n") : "No context captured.";
2094
2101
  }, []);
2095
2102
  const detectIntentFn = react.useCallback(
2096
2103
  (message) => {
2097
- const result = chunk2ZCWVAAK_cjs.detectIntent(message);
2104
+ const result = chunkIH7WXWX4_cjs.detectIntent(message);
2098
2105
  result.suggestedTools = result.suggestedTools.filter((tool) => {
2099
2106
  if (tool === "screenshot") return screenshot;
2100
2107
  if (tool === "console") return consoleCapture;
@@ -2218,7 +2225,7 @@ function convertZodSchema(schema, _toolName) {
2218
2225
  }
2219
2226
  } catch {
2220
2227
  }
2221
- return chunk2ZCWVAAK_cjs.zodObjectToInputSchema(schema);
2228
+ return chunkIH7WXWX4_cjs.zodObjectToInputSchema(schema);
2222
2229
  }
2223
2230
  function useToolWithSchema(config, dependencies = []) {
2224
2231
  const { registerTool, unregisterTool } = useCopilotContext();
@@ -2516,7 +2523,7 @@ function useAgent(options) {
2516
2523
  if (!response.ok) {
2517
2524
  throw new Error(`Agent error: ${response.status}`);
2518
2525
  }
2519
- for await (const event of chunk2ZCWVAAK_cjs.streamSSE(response)) {
2526
+ for await (const event of chunkIH7WXWX4_cjs.streamSSE(response)) {
2520
2527
  handleAgentEvent(event);
2521
2528
  }
2522
2529
  } catch (err) {
@@ -3148,5 +3155,5 @@ exports.useToolExecutor = useToolExecutor;
3148
3155
  exports.useToolWithSchema = useToolWithSchema;
3149
3156
  exports.useTools = useTools;
3150
3157
  exports.useToolsWithSchema = useToolsWithSchema;
3151
- //# sourceMappingURL=chunk-W6KQT7YZ.cjs.map
3152
- //# sourceMappingURL=chunk-W6KQT7YZ.cjs.map
3158
+ //# sourceMappingURL=chunk-R452HH3J.cjs.map
3159
+ //# sourceMappingURL=chunk-R452HH3J.cjs.map