@yourgpt/copilot-sdk 2.0.2-beta.2 → 2.1.0
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 +0 -42
- package/dist/{chunk-UOWLKFXK.cjs → chunk-33JSFVGH.cjs} +23 -23
- package/dist/{chunk-UOWLKFXK.cjs.map → chunk-33JSFVGH.cjs.map} +1 -1
- package/dist/{chunk-IXFV6AW6.js → chunk-3SP6V22Y.js} +246 -219
- package/dist/chunk-3SP6V22Y.js.map +1 -0
- package/dist/{chunk-7XFFRV7D.js → chunk-7PJ4GAJR.js} +4 -4
- package/dist/{chunk-7XFFRV7D.js.map → chunk-7PJ4GAJR.js.map} +1 -1
- package/dist/{chunk-ZPYQDMUX.js → chunk-7YZVSG62.js} +3 -3
- package/dist/{chunk-ZPYQDMUX.js.map → chunk-7YZVSG62.js.map} +1 -1
- package/dist/{chunk-BKO7DSPU.js → chunk-BRUDSHCV.js} +2 -2
- package/dist/chunk-BRUDSHCV.js.map +1 -0
- package/dist/{chunk-BH7MNDWW.js → chunk-EWVQWTNV.js} +13 -3
- package/dist/chunk-EWVQWTNV.js.map +1 -0
- package/dist/{chunk-CEKAYA2Q.cjs → chunk-HNRFRNMY.cjs} +2 -2
- package/dist/chunk-HNRFRNMY.cjs.map +1 -0
- package/dist/{chunk-7K7HZMP4.cjs → chunk-JGPDQDY4.cjs} +13 -3
- package/dist/chunk-JGPDQDY4.cjs.map +1 -0
- package/dist/{chunk-H5XMKBBA.cjs → chunk-MUZ2RYS2.cjs} +268 -241
- package/dist/chunk-MUZ2RYS2.cjs.map +1 -0
- package/dist/{chunk-UIWFYMAO.cjs → chunk-O33I4HBL.cjs} +5 -5
- package/dist/{chunk-UIWFYMAO.cjs.map → chunk-O33I4HBL.cjs.map} +1 -1
- package/dist/core/index.cjs +80 -80
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/{index-pWEH7pUE.d.ts → index-25qIYJ21.d.ts} +1 -1
- package/dist/{index-2VtgKM8S.d.cts → index-C261xY-B.d.cts} +1 -1
- package/dist/mcp/index.cjs +47 -47
- package/dist/mcp/index.d.cts +13 -3
- package/dist/mcp/index.d.ts +13 -3
- package/dist/mcp/index.js +2 -2
- package/dist/react/index.cjs +50 -50
- package/dist/react/index.d.cts +18 -5
- package/dist/react/index.d.ts +18 -5
- package/dist/react/index.js +5 -5
- package/dist/tools/anthropic/index.d.cts +1 -1
- package/dist/tools/anthropic/index.d.ts +1 -1
- package/dist/tools/brave/index.cjs +2 -2
- package/dist/tools/brave/index.d.cts +1 -1
- package/dist/tools/brave/index.d.ts +1 -1
- package/dist/tools/brave/index.js +1 -1
- package/dist/tools/exa/index.cjs +2 -2
- package/dist/tools/exa/index.d.cts +1 -1
- package/dist/tools/exa/index.d.ts +1 -1
- package/dist/tools/exa/index.js +1 -1
- package/dist/tools/google/index.cjs +2 -2
- package/dist/tools/google/index.d.cts +1 -1
- package/dist/tools/google/index.d.ts +1 -1
- package/dist/tools/google/index.js +1 -1
- package/dist/tools/openai/index.cjs +2 -2
- package/dist/tools/openai/index.d.cts +1 -1
- package/dist/tools/openai/index.d.ts +1 -1
- package/dist/tools/openai/index.js +1 -1
- package/dist/tools/searxng/index.cjs +2 -2
- package/dist/tools/searxng/index.d.cts +1 -1
- package/dist/tools/searxng/index.d.ts +1 -1
- package/dist/tools/searxng/index.js +1 -1
- package/dist/tools/serper/index.cjs +2 -2
- package/dist/tools/serper/index.d.cts +1 -1
- package/dist/tools/serper/index.d.ts +1 -1
- package/dist/tools/serper/index.js +1 -1
- package/dist/tools/tavily/index.cjs +2 -2
- package/dist/tools/tavily/index.d.cts +1 -1
- package/dist/tools/tavily/index.d.ts +1 -1
- package/dist/tools/tavily/index.js +1 -1
- package/dist/tools/web-search/index.cjs +3 -3
- package/dist/tools/web-search/index.d.cts +2 -2
- package/dist/tools/web-search/index.d.ts +2 -2
- package/dist/tools/web-search/index.js +2 -2
- package/dist/{tools-DDWrco4h.d.cts → tools-Clyufshc.d.cts} +14 -1
- package/dist/{tools-DDWrco4h.d.ts → tools-Clyufshc.d.ts} +14 -1
- package/dist/{types-DjSfYNKj.d.cts → types-DM6M_pv_.d.cts} +43 -2
- package/dist/{types-Cizh9K_f.d.ts → types-wudOhedT.d.ts} +43 -2
- package/dist/ui/index.cjs +56 -26
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +37 -3
- package/dist/ui/index.d.ts +37 -3
- package/dist/ui/index.js +52 -22
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-7K7HZMP4.cjs.map +0 -1
- package/dist/chunk-BH7MNDWW.js.map +0 -1
- package/dist/chunk-BKO7DSPU.js.map +0 -1
- package/dist/chunk-CEKAYA2Q.cjs.map +0 -1
- package/dist/chunk-H5XMKBBA.cjs.map +0 -1
- package/dist/chunk-IXFV6AW6.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk33JSFVGH_cjs = require('./chunk-33JSFVGH.cjs');
|
|
4
|
+
var chunkJGPDQDY4_cjs = require('./chunk-JGPDQDY4.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var z = require('zod');
|
|
@@ -1970,6 +1970,238 @@ function printTree(tree) {
|
|
|
1970
1970
|
});
|
|
1971
1971
|
return output.trim();
|
|
1972
1972
|
}
|
|
1973
|
+
function useMCPClient(config) {
|
|
1974
|
+
const {
|
|
1975
|
+
autoConnect = true,
|
|
1976
|
+
onConnectionStateChange,
|
|
1977
|
+
onToolsChange,
|
|
1978
|
+
onElicitationRequest,
|
|
1979
|
+
onError,
|
|
1980
|
+
onNotification,
|
|
1981
|
+
...clientConfig
|
|
1982
|
+
} = config;
|
|
1983
|
+
const clientRef = react.useRef(null);
|
|
1984
|
+
const mountedRef = react.useRef(true);
|
|
1985
|
+
const [state, setState] = react.useState({
|
|
1986
|
+
connectionState: "disconnected",
|
|
1987
|
+
tools: []
|
|
1988
|
+
});
|
|
1989
|
+
const getClient = react.useCallback(() => {
|
|
1990
|
+
if (!clientRef.current) {
|
|
1991
|
+
clientRef.current = chunkJGPDQDY4_cjs.createMCPClient(clientConfig, {
|
|
1992
|
+
onConnectionStateChange: (newState) => {
|
|
1993
|
+
if (mountedRef.current) {
|
|
1994
|
+
setState((prev) => ({ ...prev, connectionState: newState }));
|
|
1995
|
+
onConnectionStateChange?.(newState);
|
|
1996
|
+
}
|
|
1997
|
+
},
|
|
1998
|
+
onToolsChange: (tools) => {
|
|
1999
|
+
if (mountedRef.current) {
|
|
2000
|
+
setState((prev) => ({ ...prev, tools }));
|
|
2001
|
+
onToolsChange?.(tools);
|
|
2002
|
+
}
|
|
2003
|
+
},
|
|
2004
|
+
onElicitationRequest,
|
|
2005
|
+
onError: (error) => {
|
|
2006
|
+
if (mountedRef.current) {
|
|
2007
|
+
setState((prev) => ({ ...prev, error: error.message }));
|
|
2008
|
+
onError?.(error);
|
|
2009
|
+
}
|
|
2010
|
+
},
|
|
2011
|
+
onNotification
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
return clientRef.current;
|
|
2015
|
+
}, [
|
|
2016
|
+
clientConfig,
|
|
2017
|
+
onConnectionStateChange,
|
|
2018
|
+
onToolsChange,
|
|
2019
|
+
onElicitationRequest,
|
|
2020
|
+
onError,
|
|
2021
|
+
onNotification
|
|
2022
|
+
]);
|
|
2023
|
+
const connect = react.useCallback(async () => {
|
|
2024
|
+
const client = getClient();
|
|
2025
|
+
try {
|
|
2026
|
+
setState((prev) => ({
|
|
2027
|
+
...prev,
|
|
2028
|
+
connectionState: "connecting",
|
|
2029
|
+
error: void 0
|
|
2030
|
+
}));
|
|
2031
|
+
await client.connect();
|
|
2032
|
+
if (mountedRef.current) {
|
|
2033
|
+
const clientState = client.getState();
|
|
2034
|
+
setState({
|
|
2035
|
+
connectionState: "connected",
|
|
2036
|
+
tools: clientState.tools,
|
|
2037
|
+
serverInfo: clientState.serverInfo,
|
|
2038
|
+
serverCapabilities: clientState.serverCapabilities,
|
|
2039
|
+
lastActivity: Date.now()
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
} catch (error) {
|
|
2043
|
+
if (mountedRef.current) {
|
|
2044
|
+
const errorMessage = error instanceof Error ? error.message : "Connection failed";
|
|
2045
|
+
setState((prev) => ({
|
|
2046
|
+
...prev,
|
|
2047
|
+
connectionState: "error",
|
|
2048
|
+
error: errorMessage
|
|
2049
|
+
}));
|
|
2050
|
+
}
|
|
2051
|
+
throw error;
|
|
2052
|
+
}
|
|
2053
|
+
}, [getClient]);
|
|
2054
|
+
const disconnect = react.useCallback(async () => {
|
|
2055
|
+
const client = clientRef.current;
|
|
2056
|
+
if (client) {
|
|
2057
|
+
await client.disconnect();
|
|
2058
|
+
if (mountedRef.current) {
|
|
2059
|
+
setState({
|
|
2060
|
+
connectionState: "disconnected",
|
|
2061
|
+
tools: []
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
}, []);
|
|
2066
|
+
const callTool = react.useCallback(
|
|
2067
|
+
async (name, args) => {
|
|
2068
|
+
const client = clientRef.current;
|
|
2069
|
+
if (!client || !client.isConnected()) {
|
|
2070
|
+
throw new Error("MCP client not connected");
|
|
2071
|
+
}
|
|
2072
|
+
const result = await client.callTool(name, args);
|
|
2073
|
+
if (mountedRef.current) {
|
|
2074
|
+
setState((prev) => ({ ...prev, lastActivity: Date.now() }));
|
|
2075
|
+
}
|
|
2076
|
+
return result;
|
|
2077
|
+
},
|
|
2078
|
+
[]
|
|
2079
|
+
);
|
|
2080
|
+
const refreshTools = react.useCallback(async () => {
|
|
2081
|
+
const client = clientRef.current;
|
|
2082
|
+
if (!client || !client.isConnected()) {
|
|
2083
|
+
throw new Error("MCP client not connected");
|
|
2084
|
+
}
|
|
2085
|
+
const tools = await client.refreshTools();
|
|
2086
|
+
if (mountedRef.current) {
|
|
2087
|
+
setState((prev) => ({ ...prev, tools, lastActivity: Date.now() }));
|
|
2088
|
+
}
|
|
2089
|
+
return tools;
|
|
2090
|
+
}, []);
|
|
2091
|
+
react.useEffect(() => {
|
|
2092
|
+
mountedRef.current = true;
|
|
2093
|
+
if (autoConnect) {
|
|
2094
|
+
connect().catch(() => {
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
return () => {
|
|
2098
|
+
mountedRef.current = false;
|
|
2099
|
+
const client = clientRef.current;
|
|
2100
|
+
if (client) {
|
|
2101
|
+
client.disconnect().catch(() => {
|
|
2102
|
+
});
|
|
2103
|
+
clientRef.current = null;
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
}, []);
|
|
2107
|
+
const isConnected = state.connectionState === "connected";
|
|
2108
|
+
const isLoading = state.connectionState === "connecting";
|
|
2109
|
+
return {
|
|
2110
|
+
state,
|
|
2111
|
+
connect,
|
|
2112
|
+
disconnect,
|
|
2113
|
+
callTool,
|
|
2114
|
+
refreshTools,
|
|
2115
|
+
isConnected,
|
|
2116
|
+
isLoading
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
// src/react/hooks/useMCPTools.ts
|
|
2121
|
+
function useMCPTools(config) {
|
|
2122
|
+
const {
|
|
2123
|
+
prefixToolNames = true,
|
|
2124
|
+
autoRegister = true,
|
|
2125
|
+
hidden = false,
|
|
2126
|
+
source = "mcp",
|
|
2127
|
+
...clientConfig
|
|
2128
|
+
} = config;
|
|
2129
|
+
const { registerTool, unregisterTool } = useCopilot();
|
|
2130
|
+
const registeredToolsRef = react.useRef([]);
|
|
2131
|
+
const mcpClient = useMCPClient(clientConfig);
|
|
2132
|
+
const toolAdapter = react.useMemo(
|
|
2133
|
+
() => new chunkJGPDQDY4_cjs.MCPToolAdapter(clientConfig.name),
|
|
2134
|
+
[clientConfig.name]
|
|
2135
|
+
);
|
|
2136
|
+
const toolDefinitions = react.useMemo(() => {
|
|
2137
|
+
if (!mcpClient.isConnected || mcpClient.state.tools.length === 0) {
|
|
2138
|
+
return [];
|
|
2139
|
+
}
|
|
2140
|
+
return mcpClient.state.tools.map(
|
|
2141
|
+
(tool) => toolAdapter.toToolDefinition(tool, {
|
|
2142
|
+
prefix: prefixToolNames,
|
|
2143
|
+
asServerTool: true,
|
|
2144
|
+
// MCP tools execute remotely
|
|
2145
|
+
callTool: mcpClient.callTool,
|
|
2146
|
+
hidden,
|
|
2147
|
+
// Hide from chat UI
|
|
2148
|
+
source
|
|
2149
|
+
// Tool source for UI differentiation
|
|
2150
|
+
})
|
|
2151
|
+
);
|
|
2152
|
+
}, [
|
|
2153
|
+
mcpClient.isConnected,
|
|
2154
|
+
mcpClient.state.tools,
|
|
2155
|
+
mcpClient.callTool,
|
|
2156
|
+
toolAdapter,
|
|
2157
|
+
prefixToolNames,
|
|
2158
|
+
hidden,
|
|
2159
|
+
source
|
|
2160
|
+
]);
|
|
2161
|
+
react.useEffect(() => {
|
|
2162
|
+
if (!autoRegister) {
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
for (const toolName of registeredToolsRef.current) {
|
|
2166
|
+
unregisterTool(toolName);
|
|
2167
|
+
}
|
|
2168
|
+
registeredToolsRef.current = [];
|
|
2169
|
+
if (mcpClient.isConnected && toolDefinitions.length > 0) {
|
|
2170
|
+
for (const tool of toolDefinitions) {
|
|
2171
|
+
registerTool(tool);
|
|
2172
|
+
registeredToolsRef.current.push(tool.name);
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
return () => {
|
|
2176
|
+
for (const toolName of registeredToolsRef.current) {
|
|
2177
|
+
unregisterTool(toolName);
|
|
2178
|
+
}
|
|
2179
|
+
registeredToolsRef.current = [];
|
|
2180
|
+
};
|
|
2181
|
+
}, [
|
|
2182
|
+
autoRegister,
|
|
2183
|
+
mcpClient.isConnected,
|
|
2184
|
+
toolDefinitions,
|
|
2185
|
+
registerTool,
|
|
2186
|
+
unregisterTool
|
|
2187
|
+
]);
|
|
2188
|
+
return {
|
|
2189
|
+
...mcpClient,
|
|
2190
|
+
toolDefinitions
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
function MCPConnection({ config }) {
|
|
2194
|
+
useMCPTools({
|
|
2195
|
+
name: config.name,
|
|
2196
|
+
transport: config.transport,
|
|
2197
|
+
url: config.url,
|
|
2198
|
+
headers: config.headers,
|
|
2199
|
+
autoConnect: true,
|
|
2200
|
+
prefixToolNames: config.prefixToolNames ?? true,
|
|
2201
|
+
timeout: config.timeout
|
|
2202
|
+
});
|
|
2203
|
+
return null;
|
|
2204
|
+
}
|
|
1973
2205
|
var CopilotContext = react.createContext(null);
|
|
1974
2206
|
function useCopilot() {
|
|
1975
2207
|
const context = react.useContext(CopilotContext);
|
|
@@ -1991,7 +2223,8 @@ function CopilotProvider({
|
|
|
1991
2223
|
headers,
|
|
1992
2224
|
debug = false,
|
|
1993
2225
|
maxIterations,
|
|
1994
|
-
maxIterationsMessage
|
|
2226
|
+
maxIterationsMessage,
|
|
2227
|
+
mcpServers
|
|
1995
2228
|
}) {
|
|
1996
2229
|
const debugLog = react.useCallback(
|
|
1997
2230
|
(...args) => {
|
|
@@ -2251,7 +2484,10 @@ function CopilotProvider({
|
|
|
2251
2484
|
toolsConfig
|
|
2252
2485
|
]
|
|
2253
2486
|
);
|
|
2254
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
2487
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(CopilotContext.Provider, { value: contextValue, children: [
|
|
2488
|
+
mcpServers?.map((config) => /* @__PURE__ */ jsxRuntime.jsx(MCPConnection, { config }, config.name)),
|
|
2489
|
+
children
|
|
2490
|
+
] });
|
|
2255
2491
|
}
|
|
2256
2492
|
function useAIActions(actions) {
|
|
2257
2493
|
const { registerAction, unregisterAction } = useCopilot();
|
|
@@ -2346,17 +2582,17 @@ function useAITools(options = {}) {
|
|
|
2346
2582
|
const rememberedConsentRef = react.useRef(/* @__PURE__ */ new Set());
|
|
2347
2583
|
react.useEffect(() => {
|
|
2348
2584
|
if (!autoStart || !isEnabled) return;
|
|
2349
|
-
if (consoleCapture && !
|
|
2350
|
-
|
|
2585
|
+
if (consoleCapture && !chunk33JSFVGH_cjs.isConsoleCaptureActive()) {
|
|
2586
|
+
chunk33JSFVGH_cjs.startConsoleCapture(consoleOptions);
|
|
2351
2587
|
setActiveCaptures((prev) => ({ ...prev, console: true }));
|
|
2352
2588
|
}
|
|
2353
|
-
if (network && !
|
|
2354
|
-
|
|
2589
|
+
if (network && !chunk33JSFVGH_cjs.isNetworkCaptureActive()) {
|
|
2590
|
+
chunk33JSFVGH_cjs.startNetworkCapture(networkOptions);
|
|
2355
2591
|
setActiveCaptures((prev) => ({ ...prev, network: true }));
|
|
2356
2592
|
}
|
|
2357
2593
|
return () => {
|
|
2358
|
-
|
|
2359
|
-
|
|
2594
|
+
chunk33JSFVGH_cjs.stopConsoleCapture();
|
|
2595
|
+
chunk33JSFVGH_cjs.stopNetworkCapture();
|
|
2360
2596
|
};
|
|
2361
2597
|
}, [
|
|
2362
2598
|
autoStart,
|
|
@@ -2371,12 +2607,12 @@ function useAITools(options = {}) {
|
|
|
2371
2607
|
if (!screenshot) {
|
|
2372
2608
|
throw new Error("Screenshot capture is not enabled");
|
|
2373
2609
|
}
|
|
2374
|
-
if (!
|
|
2610
|
+
if (!chunk33JSFVGH_cjs.isScreenshotSupported()) {
|
|
2375
2611
|
throw new Error(
|
|
2376
2612
|
"Screenshot capture is not supported in this environment"
|
|
2377
2613
|
);
|
|
2378
2614
|
}
|
|
2379
|
-
return
|
|
2615
|
+
return chunk33JSFVGH_cjs.captureScreenshot({ ...screenshotOptions, ...opts });
|
|
2380
2616
|
},
|
|
2381
2617
|
[screenshot, screenshotOptions]
|
|
2382
2618
|
);
|
|
@@ -2385,7 +2621,7 @@ function useAITools(options = {}) {
|
|
|
2385
2621
|
if (!consoleCapture) {
|
|
2386
2622
|
return { logs: [], totalCaptured: 0 };
|
|
2387
2623
|
}
|
|
2388
|
-
return
|
|
2624
|
+
return chunk33JSFVGH_cjs.getConsoleLogs({ ...consoleOptions, ...opts });
|
|
2389
2625
|
},
|
|
2390
2626
|
[consoleCapture, consoleOptions]
|
|
2391
2627
|
);
|
|
@@ -2394,7 +2630,7 @@ function useAITools(options = {}) {
|
|
|
2394
2630
|
if (!network) {
|
|
2395
2631
|
return { requests: [], totalCaptured: 0 };
|
|
2396
2632
|
}
|
|
2397
|
-
return
|
|
2633
|
+
return chunk33JSFVGH_cjs.getNetworkRequests({ ...networkOptions, ...opts });
|
|
2398
2634
|
},
|
|
2399
2635
|
[network, networkOptions]
|
|
2400
2636
|
);
|
|
@@ -2487,23 +2723,23 @@ function useAITools(options = {}) {
|
|
|
2487
2723
|
]
|
|
2488
2724
|
);
|
|
2489
2725
|
const startCapturing = react.useCallback(() => {
|
|
2490
|
-
if (consoleCapture && !
|
|
2491
|
-
|
|
2726
|
+
if (consoleCapture && !chunk33JSFVGH_cjs.isConsoleCaptureActive()) {
|
|
2727
|
+
chunk33JSFVGH_cjs.startConsoleCapture(consoleOptions);
|
|
2492
2728
|
setActiveCaptures((prev) => ({ ...prev, console: true }));
|
|
2493
2729
|
}
|
|
2494
|
-
if (network && !
|
|
2495
|
-
|
|
2730
|
+
if (network && !chunk33JSFVGH_cjs.isNetworkCaptureActive()) {
|
|
2731
|
+
chunk33JSFVGH_cjs.startNetworkCapture(networkOptions);
|
|
2496
2732
|
setActiveCaptures((prev) => ({ ...prev, network: true }));
|
|
2497
2733
|
}
|
|
2498
2734
|
}, [consoleCapture, network, consoleOptions, networkOptions]);
|
|
2499
2735
|
const stopCapturing = react.useCallback(() => {
|
|
2500
|
-
|
|
2501
|
-
|
|
2736
|
+
chunk33JSFVGH_cjs.stopConsoleCapture();
|
|
2737
|
+
chunk33JSFVGH_cjs.stopNetworkCapture();
|
|
2502
2738
|
setActiveCaptures({ console: false, network: false });
|
|
2503
2739
|
}, []);
|
|
2504
2740
|
const clearCaptured = react.useCallback(() => {
|
|
2505
|
-
|
|
2506
|
-
|
|
2741
|
+
chunk33JSFVGH_cjs.clearConsoleLogs();
|
|
2742
|
+
chunk33JSFVGH_cjs.clearNetworkRequests();
|
|
2507
2743
|
}, []);
|
|
2508
2744
|
const formatForAI = react.useCallback((context) => {
|
|
2509
2745
|
const parts = [];
|
|
@@ -2513,16 +2749,16 @@ function useAITools(options = {}) {
|
|
|
2513
2749
|
);
|
|
2514
2750
|
}
|
|
2515
2751
|
if (context.consoleLogs && context.consoleLogs.logs.length > 0) {
|
|
2516
|
-
parts.push(
|
|
2752
|
+
parts.push(chunk33JSFVGH_cjs.formatLogsForAI(context.consoleLogs.logs));
|
|
2517
2753
|
}
|
|
2518
2754
|
if (context.networkRequests && context.networkRequests.requests.length > 0) {
|
|
2519
|
-
parts.push(
|
|
2755
|
+
parts.push(chunk33JSFVGH_cjs.formatRequestsForAI(context.networkRequests.requests));
|
|
2520
2756
|
}
|
|
2521
2757
|
return parts.length > 0 ? parts.join("\n\n---\n\n") : "No context captured.";
|
|
2522
2758
|
}, []);
|
|
2523
2759
|
const detectIntentFn = react.useCallback(
|
|
2524
2760
|
(message) => {
|
|
2525
|
-
const result =
|
|
2761
|
+
const result = chunk33JSFVGH_cjs.detectIntent(message);
|
|
2526
2762
|
result.suggestedTools = result.suggestedTools.filter((tool) => {
|
|
2527
2763
|
if (tool === "screenshot") return screenshot;
|
|
2528
2764
|
if (tool === "console") return consoleCapture;
|
|
@@ -2584,7 +2820,8 @@ function useTool(config, dependencies = []) {
|
|
|
2584
2820
|
render: config.render,
|
|
2585
2821
|
available: config.available ?? true,
|
|
2586
2822
|
needsApproval: config.needsApproval,
|
|
2587
|
-
approvalMessage: config.approvalMessage
|
|
2823
|
+
approvalMessage: config.approvalMessage,
|
|
2824
|
+
hidden: config.hidden
|
|
2588
2825
|
};
|
|
2589
2826
|
registerTool(tool);
|
|
2590
2827
|
return () => {
|
|
@@ -2636,7 +2873,7 @@ function convertZodSchema(schema, _toolName) {
|
|
|
2636
2873
|
}
|
|
2637
2874
|
} catch {
|
|
2638
2875
|
}
|
|
2639
|
-
return
|
|
2876
|
+
return chunk33JSFVGH_cjs.zodObjectToInputSchema(schema);
|
|
2640
2877
|
}
|
|
2641
2878
|
function useToolWithSchema(config, dependencies = []) {
|
|
2642
2879
|
const { registerTool, unregisterTool } = useCopilot();
|
|
@@ -2944,7 +3181,7 @@ function useAgent(options) {
|
|
|
2944
3181
|
if (!response.ok) {
|
|
2945
3182
|
throw new Error(`Agent error: ${response.status}`);
|
|
2946
3183
|
}
|
|
2947
|
-
for await (const event of
|
|
3184
|
+
for await (const event of chunk33JSFVGH_cjs.streamSSE(response)) {
|
|
2948
3185
|
handleAgentEvent(event);
|
|
2949
3186
|
}
|
|
2950
3187
|
} catch (err) {
|
|
@@ -3438,7 +3675,7 @@ function createReactThreadManagerState(initialThreads) {
|
|
|
3438
3675
|
}
|
|
3439
3676
|
|
|
3440
3677
|
// src/react/internal/ReactThreadManager.ts
|
|
3441
|
-
var _ReactThreadManager = class _ReactThreadManager extends
|
|
3678
|
+
var _ReactThreadManager = class _ReactThreadManager extends chunk33JSFVGH_cjs.ThreadManager {
|
|
3442
3679
|
constructor(config = {}, callbacks = {}) {
|
|
3443
3680
|
const reactState = new ReactThreadManagerState();
|
|
3444
3681
|
super({ ...config, state: reactState }, callbacks);
|
|
@@ -3712,216 +3949,6 @@ function useThreadManager(config) {
|
|
|
3712
3949
|
hasPendingChanges
|
|
3713
3950
|
};
|
|
3714
3951
|
}
|
|
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
3952
|
function useMCPUIIntents(config = {}) {
|
|
3926
3953
|
const {
|
|
3927
3954
|
onToolCall,
|
|
@@ -4315,5 +4342,5 @@ exports.useToolExecutor = useToolExecutor;
|
|
|
4315
4342
|
exports.useToolWithSchema = useToolWithSchema;
|
|
4316
4343
|
exports.useTools = useTools;
|
|
4317
4344
|
exports.useToolsWithSchema = useToolsWithSchema;
|
|
4318
|
-
//# sourceMappingURL=chunk-
|
|
4319
|
-
//# sourceMappingURL=chunk-
|
|
4345
|
+
//# sourceMappingURL=chunk-MUZ2RYS2.cjs.map
|
|
4346
|
+
//# sourceMappingURL=chunk-MUZ2RYS2.cjs.map
|