@yourgpt/copilot-sdk 2.0.1 → 2.0.2-beta.2
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.
- package/README.md +42 -0
- package/dist/{ThreadManager-JT0sqSSD.d.ts → ThreadManager-Dkp_eLty.d.ts} +1 -1
- package/dist/{ThreadManager-CUq5Ocu2.d.cts → ThreadManager-LfFRhr4e.d.cts} +1 -1
- package/dist/anthropic-6F5GRE3B.js +4 -0
- package/dist/anthropic-6F5GRE3B.js.map +1 -0
- package/dist/anthropic-DGalr_Fw.d.cts +17 -0
- package/dist/anthropic-DkCEDYOt.d.ts +17 -0
- package/dist/anthropic-NMTRABEH.cjs +21 -0
- package/dist/anthropic-NMTRABEH.cjs.map +1 -0
- package/dist/brave-DdnWb7Gb.d.cts +17 -0
- package/dist/brave-DsI9n7Wr.d.ts +17 -0
- package/dist/brave-OYKCOZEM.cjs +21 -0
- package/dist/brave-OYKCOZEM.cjs.map +1 -0
- package/dist/brave-XSASGGH2.js +4 -0
- package/dist/brave-XSASGGH2.js.map +1 -0
- package/dist/chunk-2FAWEBZS.cjs +88 -0
- package/dist/chunk-2FAWEBZS.cjs.map +1 -0
- package/dist/chunk-53UGJNHN.js +92 -0
- package/dist/chunk-53UGJNHN.js.map +1 -0
- package/dist/chunk-6T5XXJEP.cjs +80 -0
- package/dist/chunk-6T5XXJEP.cjs.map +1 -0
- package/dist/chunk-7K7HZMP4.cjs +1170 -0
- package/dist/chunk-7K7HZMP4.cjs.map +1 -0
- package/dist/chunk-7W7QLZNC.js +72 -0
- package/dist/chunk-7W7QLZNC.js.map +1 -0
- package/dist/{chunk-JM7PB2LP.js → chunk-7XFFRV7D.js} +10 -66
- package/dist/chunk-7XFFRV7D.js.map +1 -0
- package/dist/chunk-ASV6JLYG.cjs +99 -0
- package/dist/chunk-ASV6JLYG.cjs.map +1 -0
- package/dist/chunk-BH7MNDWW.js +1152 -0
- package/dist/chunk-BH7MNDWW.js.map +1 -0
- package/dist/chunk-BKO7DSPU.js +67 -0
- package/dist/chunk-BKO7DSPU.js.map +1 -0
- package/dist/chunk-CBAHCI4R.cjs +76 -0
- package/dist/chunk-CBAHCI4R.cjs.map +1 -0
- package/dist/chunk-CEKAYA2Q.cjs +74 -0
- package/dist/chunk-CEKAYA2Q.cjs.map +1 -0
- package/dist/chunk-CEOMTQTP.js +85 -0
- package/dist/chunk-CEOMTQTP.js.map +1 -0
- package/dist/chunk-DABZYCVX.js +84 -0
- package/dist/chunk-DABZYCVX.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-G4SF2PNQ.js +33 -0
- package/dist/chunk-G4SF2PNQ.js.map +1 -0
- package/dist/chunk-GANCV72Z.cjs +110 -0
- package/dist/chunk-GANCV72Z.cjs.map +1 -0
- package/dist/{chunk-BLSI67J6.cjs → chunk-H5XMKBBA.cjs} +425 -30
- package/dist/chunk-H5XMKBBA.cjs.map +1 -0
- package/dist/{chunk-CJ7UWN2Y.js → chunk-IXFV6AW6.js} +397 -7
- package/dist/chunk-IXFV6AW6.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +12 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/chunk-JO4BHPAD.cjs +40 -0
- package/dist/chunk-JO4BHPAD.cjs.map +1 -0
- package/dist/chunk-MEBXW75C.cjs +89 -0
- package/dist/chunk-MEBXW75C.cjs.map +1 -0
- package/dist/chunk-MNDGIW47.js +76 -0
- package/dist/chunk-MNDGIW47.js.map +1 -0
- package/dist/chunk-PPFHA6IL.js +83 -0
- package/dist/chunk-PPFHA6IL.js.map +1 -0
- package/dist/chunk-RQ74USYU.js +128 -0
- package/dist/chunk-RQ74USYU.js.map +1 -0
- package/dist/chunk-TXLIY7GF.cjs +132 -0
- package/dist/chunk-TXLIY7GF.cjs.map +1 -0
- package/dist/chunk-UIWFYMAO.cjs +82 -0
- package/dist/chunk-UIWFYMAO.cjs.map +1 -0
- package/dist/{chunk-4PRWNAXQ.cjs → chunk-UOWLKFXK.cjs} +27 -89
- package/dist/chunk-UOWLKFXK.cjs.map +1 -0
- package/dist/chunk-VD74IPKB.js +106 -0
- package/dist/chunk-VD74IPKB.js.map +1 -0
- package/dist/chunk-W73FBYIH.cjs +87 -0
- package/dist/chunk-W73FBYIH.cjs.map +1 -0
- package/dist/chunk-XGITAEXU.js +93 -0
- package/dist/chunk-XGITAEXU.js.map +1 -0
- package/dist/chunk-XWOHNY3F.cjs +96 -0
- package/dist/chunk-XWOHNY3F.cjs.map +1 -0
- package/dist/chunk-ZPYQDMUX.js +79 -0
- package/dist/chunk-ZPYQDMUX.js.map +1 -0
- package/dist/core/index.cjs +156 -84
- package/dist/core/index.d.cts +16 -4
- package/dist/core/index.d.ts +16 -4
- package/dist/core/index.js +13 -1
- package/dist/exa-72KFY5A7.cjs +21 -0
- package/dist/exa-72KFY5A7.cjs.map +1 -0
- package/dist/exa-Dp9U-WTc.d.ts +17 -0
- package/dist/exa-NNVPBC2M.js +4 -0
- package/dist/exa-NNVPBC2M.js.map +1 -0
- package/dist/exa-jJSPhyUW.d.cts +17 -0
- package/dist/google-CHU2yycE.d.cts +17 -0
- package/dist/google-CTEK6SV2.js +4 -0
- package/dist/google-CTEK6SV2.js.map +1 -0
- package/dist/google-Da8IQxaI.d.ts +17 -0
- package/dist/google-IIUXFFVF.cjs +21 -0
- package/dist/google-IIUXFFVF.cjs.map +1 -0
- package/dist/index-2VtgKM8S.d.cts +206 -0
- package/dist/index-pWEH7pUE.d.ts +206 -0
- package/dist/mcp/index.cjs +670 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +779 -0
- package/dist/mcp/index.d.ts +779 -0
- package/dist/mcp/index.js +574 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/openai-6KTCQ7PZ.cjs +21 -0
- package/dist/openai-6KTCQ7PZ.cjs.map +1 -0
- package/dist/openai-7W2PCNW5.js +4 -0
- package/dist/openai-7W2PCNW5.js.map +1 -0
- package/dist/openai-Cam8hF4f.d.ts +17 -0
- package/dist/openai-HVSCuXgO.d.cts +17 -0
- package/dist/react/index.cjs +75 -42
- package/dist/react/index.d.cts +270 -45
- package/dist/react/index.d.ts +270 -45
- package/dist/react/index.js +15 -2
- package/dist/searxng-AXLVGY7Z.js +4 -0
- package/dist/searxng-AXLVGY7Z.js.map +1 -0
- package/dist/searxng-EJKNY236.cjs +21 -0
- package/dist/searxng-EJKNY236.cjs.map +1 -0
- package/dist/searxng-K0qtY9vp.d.ts +17 -0
- package/dist/searxng-QGOte_Gq.d.cts +17 -0
- package/dist/serper-3JYJHJX6.js +4 -0
- package/dist/serper-3JYJHJX6.js.map +1 -0
- package/dist/serper-63FT4AOL.cjs +21 -0
- package/dist/serper-63FT4AOL.cjs.map +1 -0
- package/dist/serper-7Czya3PW.d.ts +17 -0
- package/dist/serper-JzdaSnS9.d.cts +17 -0
- package/dist/styles.css +38 -0
- package/dist/tavily-AWFP4RM7.cjs +21 -0
- package/dist/tavily-AWFP4RM7.cjs.map +1 -0
- package/dist/tavily-C8cXXojE.d.cts +17 -0
- package/dist/tavily-CIWAAZPH.js +4 -0
- package/dist/tavily-CIWAAZPH.js.map +1 -0
- package/dist/tavily-DdSGVgkE.d.ts +17 -0
- package/dist/themes/catppuccin.css +2 -0
- package/dist/themes/claude.css +2 -0
- package/dist/themes/linear.css +2 -0
- package/dist/themes/modern-minimal.css +2 -0
- package/dist/themes/posthog.css +2 -0
- package/dist/themes/supabase.css +2 -0
- package/dist/themes/twitter.css +2 -0
- package/dist/themes/vercel.css +2 -0
- package/dist/tools/anthropic/index.cjs +61 -0
- package/dist/tools/anthropic/index.cjs.map +1 -0
- package/dist/tools/anthropic/index.d.cts +67 -0
- package/dist/tools/anthropic/index.d.ts +67 -0
- package/dist/tools/anthropic/index.js +56 -0
- package/dist/tools/anthropic/index.js.map +1 -0
- package/dist/tools/brave/index.cjs +85 -0
- package/dist/tools/brave/index.cjs.map +1 -0
- package/dist/tools/brave/index.d.cts +91 -0
- package/dist/tools/brave/index.d.ts +91 -0
- package/dist/tools/brave/index.js +80 -0
- package/dist/tools/brave/index.js.map +1 -0
- package/dist/tools/exa/index.cjs +90 -0
- package/dist/tools/exa/index.cjs.map +1 -0
- package/dist/tools/exa/index.d.cts +92 -0
- package/dist/tools/exa/index.d.ts +92 -0
- package/dist/tools/exa/index.js +85 -0
- package/dist/tools/exa/index.js.map +1 -0
- package/dist/tools/google/index.cjs +81 -0
- package/dist/tools/google/index.cjs.map +1 -0
- package/dist/tools/google/index.d.cts +81 -0
- package/dist/tools/google/index.d.ts +81 -0
- package/dist/tools/google/index.js +76 -0
- package/dist/tools/google/index.js.map +1 -0
- package/dist/tools/openai/index.cjs +83 -0
- package/dist/tools/openai/index.cjs.map +1 -0
- package/dist/tools/openai/index.d.cts +84 -0
- package/dist/tools/openai/index.d.ts +84 -0
- package/dist/tools/openai/index.js +78 -0
- package/dist/tools/openai/index.js.map +1 -0
- package/dist/tools/searxng/index.cjs +85 -0
- package/dist/tools/searxng/index.cjs.map +1 -0
- package/dist/tools/searxng/index.d.cts +91 -0
- package/dist/tools/searxng/index.d.ts +91 -0
- package/dist/tools/searxng/index.js +80 -0
- package/dist/tools/searxng/index.js.map +1 -0
- package/dist/tools/serper/index.cjs +85 -0
- package/dist/tools/serper/index.cjs.map +1 -0
- package/dist/tools/serper/index.d.cts +91 -0
- package/dist/tools/serper/index.d.ts +91 -0
- package/dist/tools/serper/index.js +80 -0
- package/dist/tools/serper/index.js.map +1 -0
- package/dist/tools/tavily/index.cjs +91 -0
- package/dist/tools/tavily/index.cjs.map +1 -0
- package/dist/tools/tavily/index.d.cts +95 -0
- package/dist/tools/tavily/index.d.ts +95 -0
- package/dist/tools/tavily/index.js +86 -0
- package/dist/tools/tavily/index.js.map +1 -0
- package/dist/tools/web-search/index.cjs +31 -0
- package/dist/tools/web-search/index.cjs.map +1 -0
- package/dist/tools/web-search/index.d.cts +3 -0
- package/dist/tools/web-search/index.d.ts +3 -0
- package/dist/tools/web-search/index.js +14 -0
- package/dist/tools/web-search/index.js.map +1 -0
- package/dist/{types-BtAaOV07.d.cts → tools-DDWrco4h.d.cts} +43 -367
- package/dist/{types-BtAaOV07.d.ts → tools-DDWrco4h.d.ts} +43 -367
- package/dist/types-B20VCJXL.d.cts +347 -0
- package/dist/types-B20VCJXL.d.ts +347 -0
- package/dist/types-Cizh9K_f.d.ts +441 -0
- package/dist/types-DG2ya08y.d.cts +367 -0
- package/dist/types-DG2ya08y.d.ts +367 -0
- package/dist/types-DjSfYNKj.d.cts +441 -0
- package/dist/types-ZguuKEs_.d.cts +127 -0
- package/dist/types-ZguuKEs_.d.ts +127 -0
- package/dist/ui/index.cjs +1075 -148
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +410 -4
- package/dist/ui/index.d.ts +410 -4
- package/dist/ui/index.js +1007 -96
- package/dist/ui/index.js.map +1 -1
- package/package.json +52 -2
- package/dist/chunk-4PRWNAXQ.cjs.map +0 -1
- package/dist/chunk-BLSI67J6.cjs.map +0 -1
- package/dist/chunk-CJ7UWN2Y.js.map +0 -1
- package/dist/chunk-JM7PB2LP.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUOWLKFXK_cjs = require('./chunk-UOWLKFXK.cjs');
|
|
4
|
+
var chunk7K7HZMP4_cjs = require('./chunk-7K7HZMP4.cjs');
|
|
4
5
|
var react = require('react');
|
|
5
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
var z = require('zod');
|
|
@@ -176,6 +177,63 @@ function processStreamChunk(chunk, state) {
|
|
|
176
177
|
toolCalls: parseToolCalls(chunk.toolCalls),
|
|
177
178
|
requiresAction: true
|
|
178
179
|
};
|
|
180
|
+
// Handle tool action events from server
|
|
181
|
+
case "action:start": {
|
|
182
|
+
const newResults = new Map(state.toolResults);
|
|
183
|
+
newResults.set(chunk.id, {
|
|
184
|
+
id: chunk.id,
|
|
185
|
+
name: chunk.name,
|
|
186
|
+
status: "executing"
|
|
187
|
+
});
|
|
188
|
+
return { ...state, toolResults: newResults };
|
|
189
|
+
}
|
|
190
|
+
case "action:args": {
|
|
191
|
+
const existing = state.toolResults.get(chunk.id);
|
|
192
|
+
if (existing) {
|
|
193
|
+
const newResults = new Map(state.toolResults);
|
|
194
|
+
try {
|
|
195
|
+
newResults.set(chunk.id, {
|
|
196
|
+
...existing,
|
|
197
|
+
args: JSON.parse(chunk.args)
|
|
198
|
+
});
|
|
199
|
+
} catch {
|
|
200
|
+
}
|
|
201
|
+
return { ...state, toolResults: newResults };
|
|
202
|
+
}
|
|
203
|
+
return state;
|
|
204
|
+
}
|
|
205
|
+
case "action:end": {
|
|
206
|
+
const existing = state.toolResults.get(chunk.id);
|
|
207
|
+
const newResults = new Map(state.toolResults);
|
|
208
|
+
newResults.set(chunk.id, {
|
|
209
|
+
id: chunk.id,
|
|
210
|
+
name: chunk.name,
|
|
211
|
+
status: chunk.error ? "failed" : "completed",
|
|
212
|
+
args: existing?.args,
|
|
213
|
+
result: chunk.result,
|
|
214
|
+
error: chunk.error
|
|
215
|
+
});
|
|
216
|
+
return { ...state, toolResults: newResults };
|
|
217
|
+
}
|
|
218
|
+
case "tool:result": {
|
|
219
|
+
const existing = state.toolResults.get(chunk.id);
|
|
220
|
+
const newResults = new Map(state.toolResults);
|
|
221
|
+
newResults.set(chunk.id, {
|
|
222
|
+
id: chunk.id,
|
|
223
|
+
name: chunk.name,
|
|
224
|
+
status: chunk.result?.success ? "completed" : "failed",
|
|
225
|
+
args: existing?.args,
|
|
226
|
+
result: chunk.result,
|
|
227
|
+
error: chunk.result?.error
|
|
228
|
+
});
|
|
229
|
+
return { ...state, toolResults: newResults };
|
|
230
|
+
}
|
|
231
|
+
case "citation": {
|
|
232
|
+
return {
|
|
233
|
+
...state,
|
|
234
|
+
citations: [...state.citations, ...chunk.citations]
|
|
235
|
+
};
|
|
236
|
+
}
|
|
179
237
|
case "done":
|
|
180
238
|
return {
|
|
181
239
|
...state,
|
|
@@ -214,6 +272,8 @@ function createStreamState(messageId) {
|
|
|
214
272
|
content: "",
|
|
215
273
|
thinking: "",
|
|
216
274
|
toolCalls: [],
|
|
275
|
+
toolResults: /* @__PURE__ */ new Map(),
|
|
276
|
+
citations: [],
|
|
217
277
|
requiresAction: false,
|
|
218
278
|
finishReason: void 0
|
|
219
279
|
};
|
|
@@ -241,13 +301,31 @@ function streamStateToMessage(state) {
|
|
|
241
301
|
arguments: JSON.stringify(tc.args)
|
|
242
302
|
}
|
|
243
303
|
})) : void 0;
|
|
304
|
+
const toolExecutions = state.toolResults.size > 0 ? Array.from(state.toolResults.values()).map((tr) => ({
|
|
305
|
+
id: tr.id,
|
|
306
|
+
name: tr.name,
|
|
307
|
+
args: tr.args ?? {},
|
|
308
|
+
status: tr.status,
|
|
309
|
+
result: tr.result,
|
|
310
|
+
error: tr.error,
|
|
311
|
+
timestamp: Date.now()
|
|
312
|
+
})) : void 0;
|
|
313
|
+
const metadata = {};
|
|
314
|
+
if (toolExecutions) {
|
|
315
|
+
metadata.toolExecutions = toolExecutions;
|
|
316
|
+
}
|
|
317
|
+
if (state.citations && state.citations.length > 0) {
|
|
318
|
+
metadata.citations = state.citations;
|
|
319
|
+
}
|
|
244
320
|
return {
|
|
245
321
|
id: state.messageId,
|
|
246
322
|
role: "assistant",
|
|
247
323
|
content: state.content,
|
|
248
324
|
thinking: state.thinking || void 0,
|
|
249
325
|
toolCalls,
|
|
250
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
326
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
327
|
+
// Store tool executions and citations in metadata for UI components
|
|
328
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
251
329
|
};
|
|
252
330
|
}
|
|
253
331
|
function createEmptyAssistantMessage(id) {
|
|
@@ -420,11 +498,21 @@ function buildToolResultContentForAI(result, tool, args) {
|
|
|
420
498
|
case "full":
|
|
421
499
|
default:
|
|
422
500
|
if (aiContext) {
|
|
423
|
-
const {
|
|
501
|
+
const {
|
|
502
|
+
_aiResponseMode,
|
|
503
|
+
_aiContext,
|
|
504
|
+
_aiContent,
|
|
505
|
+
_uiResources,
|
|
506
|
+
...dataOnly
|
|
507
|
+
} = typedResult ?? {};
|
|
424
508
|
return `${aiContext}
|
|
425
509
|
|
|
426
510
|
Full data: ${JSON.stringify(dataOnly)}`;
|
|
427
511
|
}
|
|
512
|
+
if (typedResult?._uiResources) {
|
|
513
|
+
const { _uiResources, ...dataOnly } = typedResult;
|
|
514
|
+
return JSON.stringify(dataOnly);
|
|
515
|
+
}
|
|
428
516
|
return JSON.stringify(result);
|
|
429
517
|
}
|
|
430
518
|
}
|
|
@@ -2258,17 +2346,17 @@ function useAITools(options = {}) {
|
|
|
2258
2346
|
const rememberedConsentRef = react.useRef(/* @__PURE__ */ new Set());
|
|
2259
2347
|
react.useEffect(() => {
|
|
2260
2348
|
if (!autoStart || !isEnabled) return;
|
|
2261
|
-
if (consoleCapture && !
|
|
2262
|
-
|
|
2349
|
+
if (consoleCapture && !chunkUOWLKFXK_cjs.isConsoleCaptureActive()) {
|
|
2350
|
+
chunkUOWLKFXK_cjs.startConsoleCapture(consoleOptions);
|
|
2263
2351
|
setActiveCaptures((prev) => ({ ...prev, console: true }));
|
|
2264
2352
|
}
|
|
2265
|
-
if (network && !
|
|
2266
|
-
|
|
2353
|
+
if (network && !chunkUOWLKFXK_cjs.isNetworkCaptureActive()) {
|
|
2354
|
+
chunkUOWLKFXK_cjs.startNetworkCapture(networkOptions);
|
|
2267
2355
|
setActiveCaptures((prev) => ({ ...prev, network: true }));
|
|
2268
2356
|
}
|
|
2269
2357
|
return () => {
|
|
2270
|
-
|
|
2271
|
-
|
|
2358
|
+
chunkUOWLKFXK_cjs.stopConsoleCapture();
|
|
2359
|
+
chunkUOWLKFXK_cjs.stopNetworkCapture();
|
|
2272
2360
|
};
|
|
2273
2361
|
}, [
|
|
2274
2362
|
autoStart,
|
|
@@ -2283,12 +2371,12 @@ function useAITools(options = {}) {
|
|
|
2283
2371
|
if (!screenshot) {
|
|
2284
2372
|
throw new Error("Screenshot capture is not enabled");
|
|
2285
2373
|
}
|
|
2286
|
-
if (!
|
|
2374
|
+
if (!chunkUOWLKFXK_cjs.isScreenshotSupported()) {
|
|
2287
2375
|
throw new Error(
|
|
2288
2376
|
"Screenshot capture is not supported in this environment"
|
|
2289
2377
|
);
|
|
2290
2378
|
}
|
|
2291
|
-
return
|
|
2379
|
+
return chunkUOWLKFXK_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
|
|
2292
2380
|
},
|
|
2293
2381
|
[screenshot, screenshotOptions]
|
|
2294
2382
|
);
|
|
@@ -2297,7 +2385,7 @@ function useAITools(options = {}) {
|
|
|
2297
2385
|
if (!consoleCapture) {
|
|
2298
2386
|
return { logs: [], totalCaptured: 0 };
|
|
2299
2387
|
}
|
|
2300
|
-
return
|
|
2388
|
+
return chunkUOWLKFXK_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
|
|
2301
2389
|
},
|
|
2302
2390
|
[consoleCapture, consoleOptions]
|
|
2303
2391
|
);
|
|
@@ -2306,7 +2394,7 @@ function useAITools(options = {}) {
|
|
|
2306
2394
|
if (!network) {
|
|
2307
2395
|
return { requests: [], totalCaptured: 0 };
|
|
2308
2396
|
}
|
|
2309
|
-
return
|
|
2397
|
+
return chunkUOWLKFXK_cjs.getNetworkRequests({ ...networkOptions, ...opts });
|
|
2310
2398
|
},
|
|
2311
2399
|
[network, networkOptions]
|
|
2312
2400
|
);
|
|
@@ -2399,23 +2487,23 @@ function useAITools(options = {}) {
|
|
|
2399
2487
|
]
|
|
2400
2488
|
);
|
|
2401
2489
|
const startCapturing = react.useCallback(() => {
|
|
2402
|
-
if (consoleCapture && !
|
|
2403
|
-
|
|
2490
|
+
if (consoleCapture && !chunkUOWLKFXK_cjs.isConsoleCaptureActive()) {
|
|
2491
|
+
chunkUOWLKFXK_cjs.startConsoleCapture(consoleOptions);
|
|
2404
2492
|
setActiveCaptures((prev) => ({ ...prev, console: true }));
|
|
2405
2493
|
}
|
|
2406
|
-
if (network && !
|
|
2407
|
-
|
|
2494
|
+
if (network && !chunkUOWLKFXK_cjs.isNetworkCaptureActive()) {
|
|
2495
|
+
chunkUOWLKFXK_cjs.startNetworkCapture(networkOptions);
|
|
2408
2496
|
setActiveCaptures((prev) => ({ ...prev, network: true }));
|
|
2409
2497
|
}
|
|
2410
2498
|
}, [consoleCapture, network, consoleOptions, networkOptions]);
|
|
2411
2499
|
const stopCapturing = react.useCallback(() => {
|
|
2412
|
-
|
|
2413
|
-
|
|
2500
|
+
chunkUOWLKFXK_cjs.stopConsoleCapture();
|
|
2501
|
+
chunkUOWLKFXK_cjs.stopNetworkCapture();
|
|
2414
2502
|
setActiveCaptures({ console: false, network: false });
|
|
2415
2503
|
}, []);
|
|
2416
2504
|
const clearCaptured = react.useCallback(() => {
|
|
2417
|
-
|
|
2418
|
-
|
|
2505
|
+
chunkUOWLKFXK_cjs.clearConsoleLogs();
|
|
2506
|
+
chunkUOWLKFXK_cjs.clearNetworkRequests();
|
|
2419
2507
|
}, []);
|
|
2420
2508
|
const formatForAI = react.useCallback((context) => {
|
|
2421
2509
|
const parts = [];
|
|
@@ -2425,16 +2513,16 @@ function useAITools(options = {}) {
|
|
|
2425
2513
|
);
|
|
2426
2514
|
}
|
|
2427
2515
|
if (context.consoleLogs && context.consoleLogs.logs.length > 0) {
|
|
2428
|
-
parts.push(
|
|
2516
|
+
parts.push(chunkUOWLKFXK_cjs.formatLogsForAI(context.consoleLogs.logs));
|
|
2429
2517
|
}
|
|
2430
2518
|
if (context.networkRequests && context.networkRequests.requests.length > 0) {
|
|
2431
|
-
parts.push(
|
|
2519
|
+
parts.push(chunkUOWLKFXK_cjs.formatRequestsForAI(context.networkRequests.requests));
|
|
2432
2520
|
}
|
|
2433
2521
|
return parts.length > 0 ? parts.join("\n\n---\n\n") : "No context captured.";
|
|
2434
2522
|
}, []);
|
|
2435
2523
|
const detectIntentFn = react.useCallback(
|
|
2436
2524
|
(message) => {
|
|
2437
|
-
const result =
|
|
2525
|
+
const result = chunkUOWLKFXK_cjs.detectIntent(message);
|
|
2438
2526
|
result.suggestedTools = result.suggestedTools.filter((tool) => {
|
|
2439
2527
|
if (tool === "screenshot") return screenshot;
|
|
2440
2528
|
if (tool === "console") return consoleCapture;
|
|
@@ -2548,7 +2636,7 @@ function convertZodSchema(schema, _toolName) {
|
|
|
2548
2636
|
}
|
|
2549
2637
|
} catch {
|
|
2550
2638
|
}
|
|
2551
|
-
return
|
|
2639
|
+
return chunkUOWLKFXK_cjs.zodObjectToInputSchema(schema);
|
|
2552
2640
|
}
|
|
2553
2641
|
function useToolWithSchema(config, dependencies = []) {
|
|
2554
2642
|
const { registerTool, unregisterTool } = useCopilot();
|
|
@@ -2856,7 +2944,7 @@ function useAgent(options) {
|
|
|
2856
2944
|
if (!response.ok) {
|
|
2857
2945
|
throw new Error(`Agent error: ${response.status}`);
|
|
2858
2946
|
}
|
|
2859
|
-
for await (const event of
|
|
2947
|
+
for await (const event of chunkUOWLKFXK_cjs.streamSSE(response)) {
|
|
2860
2948
|
handleAgentEvent(event);
|
|
2861
2949
|
}
|
|
2862
2950
|
} catch (err) {
|
|
@@ -3350,7 +3438,7 @@ function createReactThreadManagerState(initialThreads) {
|
|
|
3350
3438
|
}
|
|
3351
3439
|
|
|
3352
3440
|
// src/react/internal/ReactThreadManager.ts
|
|
3353
|
-
var _ReactThreadManager = class _ReactThreadManager extends
|
|
3441
|
+
var _ReactThreadManager = class _ReactThreadManager extends chunkUOWLKFXK_cjs.ThreadManager {
|
|
3354
3442
|
constructor(config = {}, callbacks = {}) {
|
|
3355
3443
|
const reactState = new ReactThreadManagerState();
|
|
3356
3444
|
super({ ...config, state: reactState }, callbacks);
|
|
@@ -3493,7 +3581,6 @@ function useThreadManager(config) {
|
|
|
3493
3581
|
if (!config.adapter) {
|
|
3494
3582
|
return getInternalManager(config);
|
|
3495
3583
|
}
|
|
3496
|
-
console.log("[useThreadManager] Creating new manager with custom adapter");
|
|
3497
3584
|
return createReactThreadManager(
|
|
3498
3585
|
{
|
|
3499
3586
|
adapter: config.adapter,
|
|
@@ -3625,6 +3712,309 @@ function useThreadManager(config) {
|
|
|
3625
3712
|
hasPendingChanges
|
|
3626
3713
|
};
|
|
3627
3714
|
}
|
|
3715
|
+
function useMCPClient(config) {
|
|
3716
|
+
const {
|
|
3717
|
+
autoConnect = true,
|
|
3718
|
+
onConnectionStateChange,
|
|
3719
|
+
onToolsChange,
|
|
3720
|
+
onElicitationRequest,
|
|
3721
|
+
onError,
|
|
3722
|
+
onNotification,
|
|
3723
|
+
...clientConfig
|
|
3724
|
+
} = config;
|
|
3725
|
+
const clientRef = react.useRef(null);
|
|
3726
|
+
const mountedRef = react.useRef(true);
|
|
3727
|
+
const [state, setState] = react.useState({
|
|
3728
|
+
connectionState: "disconnected",
|
|
3729
|
+
tools: []
|
|
3730
|
+
});
|
|
3731
|
+
const getClient = react.useCallback(() => {
|
|
3732
|
+
if (!clientRef.current) {
|
|
3733
|
+
clientRef.current = chunk7K7HZMP4_cjs.createMCPClient(clientConfig, {
|
|
3734
|
+
onConnectionStateChange: (newState) => {
|
|
3735
|
+
if (mountedRef.current) {
|
|
3736
|
+
setState((prev) => ({ ...prev, connectionState: newState }));
|
|
3737
|
+
onConnectionStateChange?.(newState);
|
|
3738
|
+
}
|
|
3739
|
+
},
|
|
3740
|
+
onToolsChange: (tools) => {
|
|
3741
|
+
if (mountedRef.current) {
|
|
3742
|
+
setState((prev) => ({ ...prev, tools }));
|
|
3743
|
+
onToolsChange?.(tools);
|
|
3744
|
+
}
|
|
3745
|
+
},
|
|
3746
|
+
onElicitationRequest,
|
|
3747
|
+
onError: (error) => {
|
|
3748
|
+
if (mountedRef.current) {
|
|
3749
|
+
setState((prev) => ({ ...prev, error: error.message }));
|
|
3750
|
+
onError?.(error);
|
|
3751
|
+
}
|
|
3752
|
+
},
|
|
3753
|
+
onNotification
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
return clientRef.current;
|
|
3757
|
+
}, [
|
|
3758
|
+
clientConfig,
|
|
3759
|
+
onConnectionStateChange,
|
|
3760
|
+
onToolsChange,
|
|
3761
|
+
onElicitationRequest,
|
|
3762
|
+
onError,
|
|
3763
|
+
onNotification
|
|
3764
|
+
]);
|
|
3765
|
+
const connect = react.useCallback(async () => {
|
|
3766
|
+
const client = getClient();
|
|
3767
|
+
try {
|
|
3768
|
+
setState((prev) => ({
|
|
3769
|
+
...prev,
|
|
3770
|
+
connectionState: "connecting",
|
|
3771
|
+
error: void 0
|
|
3772
|
+
}));
|
|
3773
|
+
await client.connect();
|
|
3774
|
+
if (mountedRef.current) {
|
|
3775
|
+
const clientState = client.getState();
|
|
3776
|
+
setState({
|
|
3777
|
+
connectionState: "connected",
|
|
3778
|
+
tools: clientState.tools,
|
|
3779
|
+
serverInfo: clientState.serverInfo,
|
|
3780
|
+
serverCapabilities: clientState.serverCapabilities,
|
|
3781
|
+
lastActivity: Date.now()
|
|
3782
|
+
});
|
|
3783
|
+
}
|
|
3784
|
+
} catch (error) {
|
|
3785
|
+
if (mountedRef.current) {
|
|
3786
|
+
const errorMessage = error instanceof Error ? error.message : "Connection failed";
|
|
3787
|
+
setState((prev) => ({
|
|
3788
|
+
...prev,
|
|
3789
|
+
connectionState: "error",
|
|
3790
|
+
error: errorMessage
|
|
3791
|
+
}));
|
|
3792
|
+
}
|
|
3793
|
+
throw error;
|
|
3794
|
+
}
|
|
3795
|
+
}, [getClient]);
|
|
3796
|
+
const disconnect = react.useCallback(async () => {
|
|
3797
|
+
const client = clientRef.current;
|
|
3798
|
+
if (client) {
|
|
3799
|
+
await client.disconnect();
|
|
3800
|
+
if (mountedRef.current) {
|
|
3801
|
+
setState({
|
|
3802
|
+
connectionState: "disconnected",
|
|
3803
|
+
tools: []
|
|
3804
|
+
});
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
}, []);
|
|
3808
|
+
const callTool = react.useCallback(
|
|
3809
|
+
async (name, args) => {
|
|
3810
|
+
const client = clientRef.current;
|
|
3811
|
+
if (!client || !client.isConnected()) {
|
|
3812
|
+
throw new Error("MCP client not connected");
|
|
3813
|
+
}
|
|
3814
|
+
const result = await client.callTool(name, args);
|
|
3815
|
+
if (mountedRef.current) {
|
|
3816
|
+
setState((prev) => ({ ...prev, lastActivity: Date.now() }));
|
|
3817
|
+
}
|
|
3818
|
+
return result;
|
|
3819
|
+
},
|
|
3820
|
+
[]
|
|
3821
|
+
);
|
|
3822
|
+
const refreshTools = react.useCallback(async () => {
|
|
3823
|
+
const client = clientRef.current;
|
|
3824
|
+
if (!client || !client.isConnected()) {
|
|
3825
|
+
throw new Error("MCP client not connected");
|
|
3826
|
+
}
|
|
3827
|
+
const tools = await client.refreshTools();
|
|
3828
|
+
if (mountedRef.current) {
|
|
3829
|
+
setState((prev) => ({ ...prev, tools, lastActivity: Date.now() }));
|
|
3830
|
+
}
|
|
3831
|
+
return tools;
|
|
3832
|
+
}, []);
|
|
3833
|
+
react.useEffect(() => {
|
|
3834
|
+
mountedRef.current = true;
|
|
3835
|
+
if (autoConnect) {
|
|
3836
|
+
connect().catch(() => {
|
|
3837
|
+
});
|
|
3838
|
+
}
|
|
3839
|
+
return () => {
|
|
3840
|
+
mountedRef.current = false;
|
|
3841
|
+
const client = clientRef.current;
|
|
3842
|
+
if (client) {
|
|
3843
|
+
client.disconnect().catch(() => {
|
|
3844
|
+
});
|
|
3845
|
+
clientRef.current = null;
|
|
3846
|
+
}
|
|
3847
|
+
};
|
|
3848
|
+
}, []);
|
|
3849
|
+
const isConnected = state.connectionState === "connected";
|
|
3850
|
+
const isLoading = state.connectionState === "connecting";
|
|
3851
|
+
return {
|
|
3852
|
+
state,
|
|
3853
|
+
connect,
|
|
3854
|
+
disconnect,
|
|
3855
|
+
callTool,
|
|
3856
|
+
refreshTools,
|
|
3857
|
+
isConnected,
|
|
3858
|
+
isLoading
|
|
3859
|
+
};
|
|
3860
|
+
}
|
|
3861
|
+
function useMCPTools(config) {
|
|
3862
|
+
const {
|
|
3863
|
+
prefixToolNames = true,
|
|
3864
|
+
autoRegister = true,
|
|
3865
|
+
...clientConfig
|
|
3866
|
+
} = config;
|
|
3867
|
+
const { registerTool, unregisterTool } = useCopilot();
|
|
3868
|
+
const registeredToolsRef = react.useRef([]);
|
|
3869
|
+
const mcpClient = useMCPClient(clientConfig);
|
|
3870
|
+
const toolAdapter = react.useMemo(
|
|
3871
|
+
() => new chunk7K7HZMP4_cjs.MCPToolAdapter(clientConfig.name),
|
|
3872
|
+
[clientConfig.name]
|
|
3873
|
+
);
|
|
3874
|
+
const toolDefinitions = react.useMemo(() => {
|
|
3875
|
+
if (!mcpClient.isConnected || mcpClient.state.tools.length === 0) {
|
|
3876
|
+
return [];
|
|
3877
|
+
}
|
|
3878
|
+
return mcpClient.state.tools.map(
|
|
3879
|
+
(tool) => toolAdapter.toToolDefinition(tool, {
|
|
3880
|
+
prefix: prefixToolNames,
|
|
3881
|
+
asServerTool: true,
|
|
3882
|
+
// MCP tools execute remotely
|
|
3883
|
+
callTool: mcpClient.callTool
|
|
3884
|
+
})
|
|
3885
|
+
);
|
|
3886
|
+
}, [
|
|
3887
|
+
mcpClient.isConnected,
|
|
3888
|
+
mcpClient.state.tools,
|
|
3889
|
+
mcpClient.callTool,
|
|
3890
|
+
toolAdapter,
|
|
3891
|
+
prefixToolNames
|
|
3892
|
+
]);
|
|
3893
|
+
react.useEffect(() => {
|
|
3894
|
+
if (!autoRegister) {
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
for (const toolName of registeredToolsRef.current) {
|
|
3898
|
+
unregisterTool(toolName);
|
|
3899
|
+
}
|
|
3900
|
+
registeredToolsRef.current = [];
|
|
3901
|
+
if (mcpClient.isConnected && toolDefinitions.length > 0) {
|
|
3902
|
+
for (const tool of toolDefinitions) {
|
|
3903
|
+
registerTool(tool);
|
|
3904
|
+
registeredToolsRef.current.push(tool.name);
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
return () => {
|
|
3908
|
+
for (const toolName of registeredToolsRef.current) {
|
|
3909
|
+
unregisterTool(toolName);
|
|
3910
|
+
}
|
|
3911
|
+
registeredToolsRef.current = [];
|
|
3912
|
+
};
|
|
3913
|
+
}, [
|
|
3914
|
+
autoRegister,
|
|
3915
|
+
mcpClient.isConnected,
|
|
3916
|
+
toolDefinitions,
|
|
3917
|
+
registerTool,
|
|
3918
|
+
unregisterTool
|
|
3919
|
+
]);
|
|
3920
|
+
return {
|
|
3921
|
+
...mcpClient,
|
|
3922
|
+
toolDefinitions
|
|
3923
|
+
};
|
|
3924
|
+
}
|
|
3925
|
+
function useMCPUIIntents(config = {}) {
|
|
3926
|
+
const {
|
|
3927
|
+
onToolCall,
|
|
3928
|
+
onIntent,
|
|
3929
|
+
onPrompt,
|
|
3930
|
+
onNotify,
|
|
3931
|
+
onLink,
|
|
3932
|
+
requireConsent = { tool: false, link: true }
|
|
3933
|
+
} = config;
|
|
3934
|
+
const handleIntent = react.useCallback(
|
|
3935
|
+
async (intent, context) => {
|
|
3936
|
+
switch (intent.type) {
|
|
3937
|
+
case "tool": {
|
|
3938
|
+
if (requireConsent.tool) ;
|
|
3939
|
+
await onToolCall?.(intent.name, intent.arguments, context);
|
|
3940
|
+
break;
|
|
3941
|
+
}
|
|
3942
|
+
case "intent": {
|
|
3943
|
+
await onIntent?.(intent.action, intent.data, context);
|
|
3944
|
+
break;
|
|
3945
|
+
}
|
|
3946
|
+
case "prompt": {
|
|
3947
|
+
onPrompt?.(intent.text, context);
|
|
3948
|
+
break;
|
|
3949
|
+
}
|
|
3950
|
+
case "notify": {
|
|
3951
|
+
onNotify?.(intent.message, intent.level, context);
|
|
3952
|
+
break;
|
|
3953
|
+
}
|
|
3954
|
+
case "link": {
|
|
3955
|
+
const shouldContinue = onLink?.(intent.url, intent.newTab, context);
|
|
3956
|
+
if (shouldContinue === false) {
|
|
3957
|
+
break;
|
|
3958
|
+
}
|
|
3959
|
+
if (requireConsent.link) {
|
|
3960
|
+
const isSafeUrl = intent.url.startsWith("https://") || intent.url.startsWith("http://localhost");
|
|
3961
|
+
if (!isSafeUrl) {
|
|
3962
|
+
console.warn(
|
|
3963
|
+
"[MCP-UI] Blocked potentially unsafe link:",
|
|
3964
|
+
intent.url
|
|
3965
|
+
);
|
|
3966
|
+
break;
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
if (typeof window !== "undefined") {
|
|
3970
|
+
if (intent.newTab !== false) {
|
|
3971
|
+
window.open(intent.url, "_blank", "noopener,noreferrer");
|
|
3972
|
+
} else {
|
|
3973
|
+
window.location.href = intent.url;
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
break;
|
|
3977
|
+
}
|
|
3978
|
+
default: {
|
|
3979
|
+
console.warn(
|
|
3980
|
+
"[MCP-UI] Unknown intent type:",
|
|
3981
|
+
intent.type
|
|
3982
|
+
);
|
|
3983
|
+
}
|
|
3984
|
+
}
|
|
3985
|
+
},
|
|
3986
|
+
[onToolCall, onIntent, onPrompt, onNotify, onLink, requireConsent]
|
|
3987
|
+
);
|
|
3988
|
+
return react.useMemo(
|
|
3989
|
+
() => ({
|
|
3990
|
+
handleIntent
|
|
3991
|
+
}),
|
|
3992
|
+
[handleIntent]
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
function createMessageIntentHandler(sendMessage) {
|
|
3996
|
+
return {
|
|
3997
|
+
onIntent: async (action, data) => {
|
|
3998
|
+
const dataStr = data ? ` with ${JSON.stringify(data)}` : "";
|
|
3999
|
+
await sendMessage(`User action: ${action}${dataStr}`);
|
|
4000
|
+
},
|
|
4001
|
+
onPrompt: (text) => {
|
|
4002
|
+
sendMessage(text);
|
|
4003
|
+
},
|
|
4004
|
+
onNotify: (message, level) => {
|
|
4005
|
+
if (level === "error") {
|
|
4006
|
+
sendMessage(`Error: ${message}`);
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
};
|
|
4010
|
+
}
|
|
4011
|
+
function createToolIntentHandler(callTool) {
|
|
4012
|
+
return {
|
|
4013
|
+
onToolCall: async (name, args) => {
|
|
4014
|
+
await callTool(name, args);
|
|
4015
|
+
}
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
3628
4018
|
|
|
3629
4019
|
// src/react/utils/permission-storage.ts
|
|
3630
4020
|
var DEFAULT_KEY_PREFIX = "yourgpt-permissions";
|
|
@@ -3891,12 +4281,14 @@ exports.ReactChat = ReactChat;
|
|
|
3891
4281
|
exports.ReactChatState = ReactChatState;
|
|
3892
4282
|
exports.ReactThreadManager = ReactThreadManager;
|
|
3893
4283
|
exports.ReactThreadManagerState = ReactThreadManagerState;
|
|
4284
|
+
exports.createMessageIntentHandler = createMessageIntentHandler;
|
|
3894
4285
|
exports.createPermissionStorage = createPermissionStorage;
|
|
3895
4286
|
exports.createReactChat = createReactChat;
|
|
3896
4287
|
exports.createReactChatState = createReactChatState;
|
|
3897
4288
|
exports.createReactThreadManager = createReactThreadManager;
|
|
3898
4289
|
exports.createReactThreadManagerState = createReactThreadManagerState;
|
|
3899
4290
|
exports.createSessionPermissionCache = createSessionPermissionCache;
|
|
4291
|
+
exports.createToolIntentHandler = createToolIntentHandler;
|
|
3900
4292
|
exports.formatKnowledgeResultsForAI = formatKnowledgeResultsForAI;
|
|
3901
4293
|
exports.initialAgentLoopState = initialAgentLoopState;
|
|
3902
4294
|
exports.searchKnowledgeBase = searchKnowledgeBase;
|
|
@@ -3912,6 +4304,9 @@ exports.useCopilot = useCopilot;
|
|
|
3912
4304
|
exports.useDevLogger = useDevLogger;
|
|
3913
4305
|
exports.useFeatureSupport = useFeatureSupport;
|
|
3914
4306
|
exports.useKnowledgeBase = useKnowledgeBase;
|
|
4307
|
+
exports.useMCPClient = useMCPClient;
|
|
4308
|
+
exports.useMCPTools = useMCPTools;
|
|
4309
|
+
exports.useMCPUIIntents = useMCPUIIntents;
|
|
3915
4310
|
exports.useSuggestions = useSuggestions;
|
|
3916
4311
|
exports.useSupportedMediaTypes = useSupportedMediaTypes;
|
|
3917
4312
|
exports.useThreadManager = useThreadManager;
|
|
@@ -3920,5 +4315,5 @@ exports.useToolExecutor = useToolExecutor;
|
|
|
3920
4315
|
exports.useToolWithSchema = useToolWithSchema;
|
|
3921
4316
|
exports.useTools = useTools;
|
|
3922
4317
|
exports.useToolsWithSchema = useToolsWithSchema;
|
|
3923
|
-
//# sourceMappingURL=chunk-
|
|
3924
|
-
//# sourceMappingURL=chunk-
|
|
4318
|
+
//# sourceMappingURL=chunk-H5XMKBBA.cjs.map
|
|
4319
|
+
//# sourceMappingURL=chunk-H5XMKBBA.cjs.map
|