@yourgpt/copilot-sdk 1.4.1 → 1.4.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkI623CRO4_cjs = require('./chunk-I623CRO4.cjs');
3
+ var chunkCVKN4H62_cjs = require('./chunk-CVKN4H62.cjs');
4
4
  var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var z = require('zod');
@@ -438,6 +438,7 @@ var AbstractChat = class {
438
438
  * Dynamic context from useAIContext hook
439
439
  */
440
440
  this.dynamicContext = "";
441
+ this.isDisposed = false;
441
442
  this.config = {
442
443
  runtimeUrl: init.runtimeUrl,
443
444
  llm: init.llm,
@@ -674,6 +675,10 @@ var AbstractChat = class {
674
675
  */
675
676
  emit(type, data) {
676
677
  const event = { type, ...data };
678
+ const handlers = this.eventHandlers.get(type);
679
+ if (type === "toolCalls") {
680
+ this.debug(`emit(toolCalls): ${handlers?.size || 0} handlers registered`);
681
+ }
677
682
  this.eventHandlers.get(type)?.forEach((handler) => handler(event));
678
683
  }
679
684
  // ============================================
@@ -716,7 +721,7 @@ var AbstractChat = class {
716
721
  * Build the request payload
717
722
  */
718
723
  buildRequest() {
719
- const tools = this.config.tools?.map((tool) => ({
724
+ const tools = this.config.tools?.filter((tool) => tool.available !== false).map((tool) => ({
720
725
  name: tool.name,
721
726
  description: tool.description,
722
727
  inputSchema: tool.inputSchema
@@ -905,6 +910,12 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
905
910
  * Dispose and cleanup
906
911
  */
907
912
  dispose() {
913
+ if (this.isDisposed) {
914
+ this.debug("dispose() called but already disposed - ignoring");
915
+ return;
916
+ }
917
+ this.debug("dispose() - clearing event handlers");
918
+ this.isDisposed = true;
908
919
  this.stop();
909
920
  this.eventHandlers.clear();
910
921
  }
@@ -1339,9 +1350,14 @@ var ChatWithTools = class {
1339
1350
  * Wire up internal events between chat and agent loop
1340
1351
  */
1341
1352
  wireEvents() {
1353
+ this.debug("Wiring up toolCalls event handler");
1342
1354
  this.chat.on("toolCalls", async (event) => {
1355
+ this.debug("\u{1F3AF} toolCalls event handler FIRED", event);
1343
1356
  const toolCalls = event.toolCalls;
1344
- if (!toolCalls?.length) return;
1357
+ if (!toolCalls?.length) {
1358
+ this.debug("No tool calls in event");
1359
+ return;
1360
+ }
1345
1361
  this.debug("Tool calls received:", toolCalls);
1346
1362
  const toolCallInfos = toolCalls.map((tc) => {
1347
1363
  const tcAny = tc;
@@ -2148,17 +2164,17 @@ function useAITools(options = {}) {
2148
2164
  const rememberedConsentRef = react.useRef(/* @__PURE__ */ new Set());
2149
2165
  react.useEffect(() => {
2150
2166
  if (!autoStart || !isEnabled) return;
2151
- if (consoleCapture && !chunkI623CRO4_cjs.isConsoleCaptureActive()) {
2152
- chunkI623CRO4_cjs.startConsoleCapture(consoleOptions);
2167
+ if (consoleCapture && !chunkCVKN4H62_cjs.isConsoleCaptureActive()) {
2168
+ chunkCVKN4H62_cjs.startConsoleCapture(consoleOptions);
2153
2169
  setActiveCaptures((prev) => ({ ...prev, console: true }));
2154
2170
  }
2155
- if (network && !chunkI623CRO4_cjs.isNetworkCaptureActive()) {
2156
- chunkI623CRO4_cjs.startNetworkCapture(networkOptions);
2171
+ if (network && !chunkCVKN4H62_cjs.isNetworkCaptureActive()) {
2172
+ chunkCVKN4H62_cjs.startNetworkCapture(networkOptions);
2157
2173
  setActiveCaptures((prev) => ({ ...prev, network: true }));
2158
2174
  }
2159
2175
  return () => {
2160
- chunkI623CRO4_cjs.stopConsoleCapture();
2161
- chunkI623CRO4_cjs.stopNetworkCapture();
2176
+ chunkCVKN4H62_cjs.stopConsoleCapture();
2177
+ chunkCVKN4H62_cjs.stopNetworkCapture();
2162
2178
  };
2163
2179
  }, [
2164
2180
  autoStart,
@@ -2173,12 +2189,12 @@ function useAITools(options = {}) {
2173
2189
  if (!screenshot) {
2174
2190
  throw new Error("Screenshot capture is not enabled");
2175
2191
  }
2176
- if (!chunkI623CRO4_cjs.isScreenshotSupported()) {
2192
+ if (!chunkCVKN4H62_cjs.isScreenshotSupported()) {
2177
2193
  throw new Error(
2178
2194
  "Screenshot capture is not supported in this environment"
2179
2195
  );
2180
2196
  }
2181
- return chunkI623CRO4_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
2197
+ return chunkCVKN4H62_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
2182
2198
  },
2183
2199
  [screenshot, screenshotOptions]
2184
2200
  );
@@ -2187,7 +2203,7 @@ function useAITools(options = {}) {
2187
2203
  if (!consoleCapture) {
2188
2204
  return { logs: [], totalCaptured: 0 };
2189
2205
  }
2190
- return chunkI623CRO4_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
2206
+ return chunkCVKN4H62_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
2191
2207
  },
2192
2208
  [consoleCapture, consoleOptions]
2193
2209
  );
@@ -2196,7 +2212,7 @@ function useAITools(options = {}) {
2196
2212
  if (!network) {
2197
2213
  return { requests: [], totalCaptured: 0 };
2198
2214
  }
2199
- return chunkI623CRO4_cjs.getNetworkRequests({ ...networkOptions, ...opts });
2215
+ return chunkCVKN4H62_cjs.getNetworkRequests({ ...networkOptions, ...opts });
2200
2216
  },
2201
2217
  [network, networkOptions]
2202
2218
  );
@@ -2289,23 +2305,23 @@ function useAITools(options = {}) {
2289
2305
  ]
2290
2306
  );
2291
2307
  const startCapturing = react.useCallback(() => {
2292
- if (consoleCapture && !chunkI623CRO4_cjs.isConsoleCaptureActive()) {
2293
- chunkI623CRO4_cjs.startConsoleCapture(consoleOptions);
2308
+ if (consoleCapture && !chunkCVKN4H62_cjs.isConsoleCaptureActive()) {
2309
+ chunkCVKN4H62_cjs.startConsoleCapture(consoleOptions);
2294
2310
  setActiveCaptures((prev) => ({ ...prev, console: true }));
2295
2311
  }
2296
- if (network && !chunkI623CRO4_cjs.isNetworkCaptureActive()) {
2297
- chunkI623CRO4_cjs.startNetworkCapture(networkOptions);
2312
+ if (network && !chunkCVKN4H62_cjs.isNetworkCaptureActive()) {
2313
+ chunkCVKN4H62_cjs.startNetworkCapture(networkOptions);
2298
2314
  setActiveCaptures((prev) => ({ ...prev, network: true }));
2299
2315
  }
2300
2316
  }, [consoleCapture, network, consoleOptions, networkOptions]);
2301
2317
  const stopCapturing = react.useCallback(() => {
2302
- chunkI623CRO4_cjs.stopConsoleCapture();
2303
- chunkI623CRO4_cjs.stopNetworkCapture();
2318
+ chunkCVKN4H62_cjs.stopConsoleCapture();
2319
+ chunkCVKN4H62_cjs.stopNetworkCapture();
2304
2320
  setActiveCaptures({ console: false, network: false });
2305
2321
  }, []);
2306
2322
  const clearCaptured = react.useCallback(() => {
2307
- chunkI623CRO4_cjs.clearConsoleLogs();
2308
- chunkI623CRO4_cjs.clearNetworkRequests();
2323
+ chunkCVKN4H62_cjs.clearConsoleLogs();
2324
+ chunkCVKN4H62_cjs.clearNetworkRequests();
2309
2325
  }, []);
2310
2326
  const formatForAI = react.useCallback((context) => {
2311
2327
  const parts = [];
@@ -2315,16 +2331,16 @@ function useAITools(options = {}) {
2315
2331
  );
2316
2332
  }
2317
2333
  if (context.consoleLogs && context.consoleLogs.logs.length > 0) {
2318
- parts.push(chunkI623CRO4_cjs.formatLogsForAI(context.consoleLogs.logs));
2334
+ parts.push(chunkCVKN4H62_cjs.formatLogsForAI(context.consoleLogs.logs));
2319
2335
  }
2320
2336
  if (context.networkRequests && context.networkRequests.requests.length > 0) {
2321
- parts.push(chunkI623CRO4_cjs.formatRequestsForAI(context.networkRequests.requests));
2337
+ parts.push(chunkCVKN4H62_cjs.formatRequestsForAI(context.networkRequests.requests));
2322
2338
  }
2323
2339
  return parts.length > 0 ? parts.join("\n\n---\n\n") : "No context captured.";
2324
2340
  }, []);
2325
2341
  const detectIntentFn = react.useCallback(
2326
2342
  (message) => {
2327
- const result = chunkI623CRO4_cjs.detectIntent(message);
2343
+ const result = chunkCVKN4H62_cjs.detectIntent(message);
2328
2344
  result.suggestedTools = result.suggestedTools.filter((tool) => {
2329
2345
  if (tool === "screenshot") return screenshot;
2330
2346
  if (tool === "console") return consoleCapture;
@@ -2448,7 +2464,7 @@ function convertZodSchema(schema, _toolName) {
2448
2464
  }
2449
2465
  } catch {
2450
2466
  }
2451
- return chunkI623CRO4_cjs.zodObjectToInputSchema(schema);
2467
+ return chunkCVKN4H62_cjs.zodObjectToInputSchema(schema);
2452
2468
  }
2453
2469
  function useToolWithSchema(config, dependencies = []) {
2454
2470
  const { registerTool, unregisterTool } = useCopilotContext();
@@ -2746,7 +2762,7 @@ function useAgent(options) {
2746
2762
  if (!response.ok) {
2747
2763
  throw new Error(`Agent error: ${response.status}`);
2748
2764
  }
2749
- for await (const event of chunkI623CRO4_cjs.streamSSE(response)) {
2765
+ for await (const event of chunkCVKN4H62_cjs.streamSSE(response)) {
2750
2766
  handleAgentEvent(event);
2751
2767
  }
2752
2768
  } catch (err) {
@@ -3240,7 +3256,7 @@ function createReactThreadManagerState(initialThreads) {
3240
3256
  }
3241
3257
 
3242
3258
  // src/react/internal/ReactThreadManager.ts
3243
- var _ReactThreadManager = class _ReactThreadManager extends chunkI623CRO4_cjs.ThreadManager {
3259
+ var _ReactThreadManager = class _ReactThreadManager extends chunkCVKN4H62_cjs.ThreadManager {
3244
3260
  constructor(config = {}, callbacks = {}) {
3245
3261
  const reactState = new ReactThreadManagerState();
3246
3262
  super({ ...config, state: reactState }, callbacks);
@@ -3800,5 +3816,5 @@ exports.useToolExecutor = useToolExecutor;
3800
3816
  exports.useToolWithSchema = useToolWithSchema;
3801
3817
  exports.useTools = useTools;
3802
3818
  exports.useToolsWithSchema = useToolsWithSchema;
3803
- //# sourceMappingURL=chunk-KRZXN5KV.cjs.map
3804
- //# sourceMappingURL=chunk-KRZXN5KV.cjs.map
3819
+ //# sourceMappingURL=chunk-N24PPVNQ.cjs.map
3820
+ //# sourceMappingURL=chunk-N24PPVNQ.cjs.map