@copilotkit/runtime 1.5.12-next.5 → 1.5.12-next.6
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/CHANGELOG.md +10 -0
- package/dist/{chunk-QDMAQO2C.mjs → chunk-BKIGYRXE.mjs} +2 -2
- package/dist/{chunk-MFDRA3BJ.mjs → chunk-ON4AESON.mjs} +125 -77
- package/dist/chunk-ON4AESON.mjs.map +1 -0
- package/dist/{chunk-NORCONUM.mjs → chunk-XM2VJFL6.mjs} +2 -2
- package/dist/{chunk-XRW7ZSWJ.mjs → chunk-YGXAWYRB.mjs} +2 -2
- package/dist/{copilot-runtime-1a224a0f.d.ts → copilot-runtime-da917bd5.d.ts} +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +136 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +136 -88
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +12 -10
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +12 -10
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +2 -2
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +12 -10
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +2 -2
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +12 -10
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/package.json +2 -2
- package/src/lib/runtime/copilot-runtime.ts +61 -27
- package/src/lib/runtime/remote-action-constructors.ts +42 -33
- package/src/lib/runtime/remote-actions.ts +12 -7
- package/dist/chunk-MFDRA3BJ.mjs.map +0 -1
- /package/dist/{chunk-QDMAQO2C.mjs.map → chunk-BKIGYRXE.mjs.map} +0 -0
- /package/dist/{chunk-NORCONUM.mjs.map → chunk-XM2VJFL6.mjs.map} +0 -0
- /package/dist/{chunk-XRW7ZSWJ.mjs.map → chunk-YGXAWYRB.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @copilotkit/runtime
|
|
2
2
|
|
|
3
|
+
## 1.5.12-next.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6136a57: - fix(errors): add custom error classes to better describe library errors
|
|
8
|
+
- fix(errors): use new errors in error handling
|
|
9
|
+
- chore: add documentation and links to respective errors
|
|
10
|
+
- Updated dependencies [6136a57]
|
|
11
|
+
- @copilotkit/shared@1.5.12-next.6
|
|
12
|
+
|
|
3
13
|
## 1.5.12-next.5
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ON4AESON.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-44O2JGUY.mjs";
|
|
@@ -77,4 +77,4 @@ export {
|
|
|
77
77
|
config,
|
|
78
78
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-BKIGYRXE.mjs.map
|
|
@@ -38,7 +38,7 @@ var require_package = __commonJS({
|
|
|
38
38
|
publishConfig: {
|
|
39
39
|
access: "public"
|
|
40
40
|
},
|
|
41
|
-
version: "1.5.12-next.
|
|
41
|
+
version: "1.5.12-next.6",
|
|
42
42
|
sideEffects: false,
|
|
43
43
|
main: "./dist/index.js",
|
|
44
44
|
module: "./dist/index.mjs",
|
|
@@ -1796,6 +1796,7 @@ function copilotkitMessagesToLangChain(messages) {
|
|
|
1796
1796
|
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
1797
1797
|
|
|
1798
1798
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1799
|
+
import { CopilotKitError, CopilotKitLowLevelError } from "@copilotkit/shared";
|
|
1799
1800
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1800
1801
|
const agents = endpoint.agents.map((agent) => ({
|
|
1801
1802
|
name: agent.name,
|
|
@@ -1876,8 +1877,9 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1876
1877
|
type: "self-hosted",
|
|
1877
1878
|
agentsAmount: totalAgents
|
|
1878
1879
|
});
|
|
1880
|
+
const fetchUrl = `${url}/actions/execute`;
|
|
1879
1881
|
try {
|
|
1880
|
-
const response = await fetch(
|
|
1882
|
+
const response = await fetch(fetchUrl, {
|
|
1881
1883
|
method: "POST",
|
|
1882
1884
|
headers,
|
|
1883
1885
|
body: JSON.stringify({
|
|
@@ -1902,10 +1904,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1902
1904
|
}, "Executed remote action");
|
|
1903
1905
|
return result;
|
|
1904
1906
|
} catch (error) {
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1907
|
+
if (error instanceof CopilotKitError) {
|
|
1908
|
+
throw error;
|
|
1909
|
+
}
|
|
1910
|
+
throw new CopilotKitLowLevelError({
|
|
1911
|
+
error,
|
|
1912
|
+
url: fetchUrl
|
|
1913
|
+
});
|
|
1909
1914
|
}
|
|
1910
1915
|
}
|
|
1911
1916
|
}));
|
|
@@ -1933,37 +1938,48 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1933
1938
|
state = JSON.parse(jsonState);
|
|
1934
1939
|
}
|
|
1935
1940
|
}
|
|
1936
|
-
const
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1941
|
+
const fetchUrl = `${url}/agents/execute`;
|
|
1942
|
+
try {
|
|
1943
|
+
const response = await fetch(fetchUrl, {
|
|
1944
|
+
method: "POST",
|
|
1945
|
+
headers,
|
|
1946
|
+
body: JSON.stringify({
|
|
1947
|
+
name,
|
|
1948
|
+
threadId,
|
|
1949
|
+
nodeName,
|
|
1950
|
+
messages: [
|
|
1951
|
+
...messages,
|
|
1952
|
+
...additionalMessages
|
|
1953
|
+
],
|
|
1954
|
+
state,
|
|
1955
|
+
properties: graphqlContext.properties,
|
|
1956
|
+
actions: actionInputsWithoutAgents.map((action) => ({
|
|
1957
|
+
name: action.name,
|
|
1958
|
+
description: action.description,
|
|
1959
|
+
parameters: JSON.parse(action.jsonSchema)
|
|
1960
|
+
}))
|
|
1961
|
+
})
|
|
1962
|
+
});
|
|
1963
|
+
if (!response.ok) {
|
|
1964
|
+
logger2.error({
|
|
1965
|
+
url,
|
|
1966
|
+
status: response.status,
|
|
1967
|
+
body: await response.text()
|
|
1968
|
+
}, "Failed to execute remote agent");
|
|
1969
|
+
throw new Error("Failed to execute remote agent");
|
|
1970
|
+
}
|
|
1971
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
1972
|
+
streamResponse(response.body, eventSource.eventStream$);
|
|
1973
|
+
return eventSource.processLangGraphEvents();
|
|
1974
|
+
} catch (error) {
|
|
1975
|
+
if (error instanceof CopilotKitError) {
|
|
1976
|
+
throw error;
|
|
1977
|
+
}
|
|
1978
|
+
throw new CopilotKitLowLevelError({
|
|
1979
|
+
error,
|
|
1980
|
+
url: fetchUrl
|
|
1981
|
+
});
|
|
1963
1982
|
}
|
|
1964
|
-
const eventSource = new RemoteLangGraphEventSource();
|
|
1965
|
-
streamResponse(response.body, eventSource.eventStream$);
|
|
1966
|
-
return eventSource.processLangGraphEvents();
|
|
1967
1983
|
}
|
|
1968
1984
|
})) : [];
|
|
1969
1985
|
return [
|
|
@@ -2033,6 +2049,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
2033
2049
|
__name(createHeaders, "createHeaders");
|
|
2034
2050
|
|
|
2035
2051
|
// src/lib/runtime/remote-actions.ts
|
|
2052
|
+
import { CopilotKitLowLevelError as CopilotKitLowLevelError2, ResolvedCopilotKitError, CopilotKitError as CopilotKitError2 } from "@copilotkit/shared";
|
|
2036
2053
|
var EndpointType;
|
|
2037
2054
|
(function(EndpointType2) {
|
|
2038
2055
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -2050,8 +2067,9 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2050
2067
|
url
|
|
2051
2068
|
}, "Fetching actions from url");
|
|
2052
2069
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
2070
|
+
const fetchUrl = `${url}/info`;
|
|
2053
2071
|
try {
|
|
2054
|
-
const response = await fetch(
|
|
2072
|
+
const response = await fetch(fetchUrl, {
|
|
2055
2073
|
method: "POST",
|
|
2056
2074
|
headers,
|
|
2057
2075
|
body: JSON.stringify({
|
|
@@ -2065,10 +2083,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2065
2083
|
status: response.status,
|
|
2066
2084
|
body: await response.text()
|
|
2067
2085
|
}, "Failed to fetch actions from url");
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
};
|
|
2086
|
+
throw new ResolvedCopilotKitError({
|
|
2087
|
+
status: response.status,
|
|
2088
|
+
isRemoteEndpoint: true
|
|
2089
|
+
});
|
|
2072
2090
|
}
|
|
2073
2091
|
const json = await response.json();
|
|
2074
2092
|
logger2.debug({
|
|
@@ -2076,13 +2094,13 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2076
2094
|
}, "Fetched actions from url");
|
|
2077
2095
|
return json;
|
|
2078
2096
|
} catch (error) {
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
};
|
|
2097
|
+
if (error instanceof CopilotKitError2) {
|
|
2098
|
+
throw error;
|
|
2099
|
+
}
|
|
2100
|
+
throw new CopilotKitLowLevelError2({
|
|
2101
|
+
error,
|
|
2102
|
+
url: fetchUrl
|
|
2103
|
+
});
|
|
2086
2104
|
}
|
|
2087
2105
|
}
|
|
2088
2106
|
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
@@ -2143,7 +2161,8 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2143
2161
|
import { createHash as createHash3 } from "crypto";
|
|
2144
2162
|
|
|
2145
2163
|
// src/lib/runtime/copilot-runtime.ts
|
|
2146
|
-
import { actionParametersToJsonSchema, randomId as randomId2 } from "@copilotkit/shared";
|
|
2164
|
+
import { actionParametersToJsonSchema, ResolvedCopilotKitError as ResolvedCopilotKitError2, CopilotKitApiDiscoveryError, randomId as randomId2, CopilotKitError as CopilotKitError3, CopilotKitLowLevelError as CopilotKitLowLevelError3, CopilotKitAgentDiscoveryError, CopilotKitMisuseError } from "@copilotkit/shared";
|
|
2165
|
+
import { Client as LangGraphClient } from "@langchain/langgraph-sdk";
|
|
2147
2166
|
|
|
2148
2167
|
// src/service-adapters/conversion.ts
|
|
2149
2168
|
import { plainToInstance } from "class-transformer";
|
|
@@ -2221,9 +2240,11 @@ var CopilotRuntime = class {
|
|
|
2221
2240
|
return await this.processAgentRequest(request);
|
|
2222
2241
|
}
|
|
2223
2242
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
2224
|
-
throw new
|
|
2243
|
+
throw new CopilotKitMisuseError({
|
|
2244
|
+
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
2225
2245
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
2226
|
-
please use an LLM adapter instead.`
|
|
2246
|
+
please use an LLM adapter instead.`
|
|
2247
|
+
});
|
|
2227
2248
|
}
|
|
2228
2249
|
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2229
2250
|
const inputMessages = convertGqlInputToMessages(messages);
|
|
@@ -2278,6 +2299,9 @@ please use an LLM adapter instead.`);
|
|
|
2278
2299
|
))
|
|
2279
2300
|
};
|
|
2280
2301
|
} catch (error) {
|
|
2302
|
+
if (error instanceof CopilotKitError3) {
|
|
2303
|
+
throw error;
|
|
2304
|
+
}
|
|
2281
2305
|
console.error("Error getting response:", error);
|
|
2282
2306
|
eventSource.sendErrorMessageToChat();
|
|
2283
2307
|
throw error;
|
|
@@ -2288,37 +2312,59 @@ please use an LLM adapter instead.`);
|
|
|
2288
2312
|
const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
|
|
2289
2313
|
const agents2 = await acc;
|
|
2290
2314
|
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2293
|
-
|
|
2315
|
+
const client = new LangGraphClient({
|
|
2316
|
+
apiUrl: endpoint.deploymentUrl,
|
|
2317
|
+
apiKey: endpoint.langsmithApiKey
|
|
2294
2318
|
});
|
|
2295
|
-
const
|
|
2296
|
-
const
|
|
2319
|
+
const data = await client.assistants.search();
|
|
2320
|
+
const endpointAgents = (data ?? []).map((entry) => ({
|
|
2297
2321
|
name: entry.graph_id,
|
|
2298
|
-
id: entry.assistant_id
|
|
2322
|
+
id: entry.assistant_id,
|
|
2323
|
+
description: "",
|
|
2324
|
+
endpoint
|
|
2299
2325
|
}));
|
|
2300
2326
|
return [
|
|
2301
2327
|
...agents2,
|
|
2302
|
-
...
|
|
2328
|
+
...endpointAgents
|
|
2303
2329
|
];
|
|
2304
2330
|
}
|
|
2305
|
-
const
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2331
|
+
const fetchUrl = `${endpoint.url}/info`;
|
|
2332
|
+
try {
|
|
2333
|
+
const response = await fetch(fetchUrl, {
|
|
2334
|
+
method: "POST",
|
|
2335
|
+
headers,
|
|
2336
|
+
body: JSON.stringify({
|
|
2337
|
+
properties: graphqlContext.properties
|
|
2338
|
+
})
|
|
2339
|
+
});
|
|
2340
|
+
if (!response.ok) {
|
|
2341
|
+
if (response.status === 404) {
|
|
2342
|
+
throw new CopilotKitApiDiscoveryError();
|
|
2343
|
+
}
|
|
2344
|
+
throw new ResolvedCopilotKitError2({
|
|
2345
|
+
status: response.status,
|
|
2346
|
+
isRemoteEndpoint: true
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
const data = await response.json();
|
|
2350
|
+
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
2351
|
+
name: agent.name,
|
|
2352
|
+
description: agent.description ?? "",
|
|
2353
|
+
id: randomId2()
|
|
2354
|
+
}));
|
|
2355
|
+
return [
|
|
2356
|
+
...agents2,
|
|
2357
|
+
...endpointAgents
|
|
2358
|
+
];
|
|
2359
|
+
} catch (error) {
|
|
2360
|
+
if (error instanceof CopilotKitError3) {
|
|
2361
|
+
throw error;
|
|
2362
|
+
}
|
|
2363
|
+
throw new CopilotKitLowLevelError3({
|
|
2364
|
+
error,
|
|
2365
|
+
url: fetchUrl
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2322
2368
|
}, Promise.resolve([]));
|
|
2323
2369
|
return agents;
|
|
2324
2370
|
}
|
|
@@ -2330,7 +2376,9 @@ please use an LLM adapter instead.`);
|
|
|
2330
2376
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
2331
2377
|
const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
2332
2378
|
if (!agent) {
|
|
2333
|
-
throw new
|
|
2379
|
+
throw new CopilotKitAgentDiscoveryError({
|
|
2380
|
+
agentName
|
|
2381
|
+
});
|
|
2334
2382
|
}
|
|
2335
2383
|
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2336
2384
|
name: action.name,
|
|
@@ -3440,4 +3488,4 @@ export {
|
|
|
3440
3488
|
getCommonConfig,
|
|
3441
3489
|
copilotRuntimeNodeHttpEndpoint
|
|
3442
3490
|
};
|
|
3443
|
-
//# sourceMappingURL=chunk-
|
|
3491
|
+
//# sourceMappingURL=chunk-ON4AESON.mjs.map
|