@copilotkit/runtime 1.9.2-next.4 → 1.9.2-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 +13 -0
- package/dist/{chunk-NK2XARWT.mjs → chunk-6AD7VT26.mjs} +2 -2
- package/dist/{chunk-5FNEYAWH.mjs → chunk-6FLO2QTT.mjs} +2 -2
- package/dist/{chunk-6W7TKZNY.mjs → chunk-JZWHLURE.mjs} +2 -2
- package/dist/{chunk-CJ44W4R2.mjs → chunk-K4JQLKXK.mjs} +2 -2
- package/dist/{chunk-ZUF3A5TW.mjs → chunk-RCIYK6YJ.mjs} +107 -53
- package/dist/chunk-RCIYK6YJ.mjs.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +101 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +101 -47
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +4 -4
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +4 -4
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +4 -4
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +4 -4
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/{shared-ba062831.d.ts → shared-941d59dc.d.ts} +2 -0
- package/package.json +2 -2
- package/src/graphql/resolvers/state.resolver.ts +3 -3
- package/src/lib/runtime/copilot-runtime.ts +114 -41
- package/dist/chunk-ZUF3A5TW.mjs.map +0 -1
- /package/dist/{chunk-NK2XARWT.mjs.map → chunk-6AD7VT26.mjs.map} +0 -0
- /package/dist/{chunk-5FNEYAWH.mjs.map → chunk-6FLO2QTT.mjs.map} +0 -0
- /package/dist/{chunk-6W7TKZNY.mjs.map → chunk-JZWHLURE.mjs.map} +0 -0
- /package/dist/{chunk-CJ44W4R2.mjs.map → chunk-K4JQLKXK.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CustomEventNames,
|
|
3
3
|
LangGraphAgent
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6FLO2QTT.mjs";
|
|
5
5
|
import {
|
|
6
6
|
config,
|
|
7
7
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
8
8
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6AD7VT26.mjs";
|
|
10
10
|
import {
|
|
11
11
|
copilotRuntimeNestEndpoint
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-K4JQLKXK.mjs";
|
|
13
13
|
import {
|
|
14
14
|
copilotRuntimeNodeExpressEndpoint
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-JZWHLURE.mjs";
|
|
16
16
|
import {
|
|
17
17
|
CopilotRuntime,
|
|
18
18
|
addCustomHeaderPlugin,
|
|
@@ -28,7 +28,12 @@ import {
|
|
|
28
28
|
getCommonConfig,
|
|
29
29
|
langGraphPlatformEndpoint,
|
|
30
30
|
resolveEndpointType
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-RCIYK6YJ.mjs";
|
|
32
|
+
import {
|
|
33
|
+
GuardrailsValidationFailureResponse,
|
|
34
|
+
MessageStreamInterruptedResponse,
|
|
35
|
+
UnknownErrorResponse
|
|
36
|
+
} from "./chunk-5BIEM2UU.mjs";
|
|
32
37
|
import {
|
|
33
38
|
AnthropicAdapter,
|
|
34
39
|
BedrockAdapter,
|
|
@@ -43,11 +48,6 @@ import {
|
|
|
43
48
|
RemoteChain,
|
|
44
49
|
UnifyAdapter
|
|
45
50
|
} from "./chunk-IIXJVVTV.mjs";
|
|
46
|
-
import {
|
|
47
|
-
GuardrailsValidationFailureResponse,
|
|
48
|
-
MessageStreamInterruptedResponse,
|
|
49
|
-
UnknownErrorResponse
|
|
50
|
-
} from "./chunk-5BIEM2UU.mjs";
|
|
51
51
|
import "./chunk-SHBDMA63.mjs";
|
|
52
52
|
import "./chunk-2OZAGFV3.mjs";
|
|
53
53
|
import "./chunk-FHD4JECV.mjs";
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-25a2bd35.js';
|
|
2
|
-
export { e as CommonConfig, C as CopilotRequestContextProperties, k as CopilotRuntime, j as CopilotRuntimeConstructorParams, f as CopilotRuntimeLogger, i as CopilotRuntimeRequest, b as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, o as MCPClient, p as MCPEndpointConfig, M as MCPTool, a as addCustomHeaderPlugin, d as buildSchema, s as convertMCPToolsToActions, m as copilotKitEndpoint, c as createContext, h as createLogger, q as extractParametersFromSchema, l as flattenToolCallsNoDuplicates, t as generateMcpToolInstructions, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from '../shared-
|
|
2
|
+
export { e as CommonConfig, C as CopilotRequestContextProperties, k as CopilotRuntime, j as CopilotRuntimeConstructorParams, f as CopilotRuntimeLogger, i as CopilotRuntimeRequest, b as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, o as MCPClient, p as MCPEndpointConfig, M as MCPTool, a as addCustomHeaderPlugin, d as buildSchema, s as convertMCPToolsToActions, m as copilotKitEndpoint, c as createContext, h as createLogger, q as extractParametersFromSchema, l as flattenToolCallsNoDuplicates, t as generateMcpToolInstructions, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from '../shared-941d59dc.js';
|
|
3
3
|
export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint } from './integrations/index.js';
|
|
4
4
|
export { copilotRuntimeNodeHttpEndpoint } from './integrations/node-http/index.js';
|
|
5
5
|
export { copilotRuntimeNodeExpressEndpoint } from './integrations/node-express/index.js';
|
package/dist/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.9.2-next.
|
|
47
|
+
version: "1.9.2-next.6",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -4695,6 +4695,7 @@ var CopilotRuntime = class {
|
|
|
4695
4695
|
var _a, _b, _c, _d;
|
|
4696
4696
|
if ((params == null ? void 0 : params.actions) && (params == null ? void 0 : params.remoteEndpoints) && (params == null ? void 0 : params.remoteEndpoints.some((e) => e.type === EndpointType.LangGraphPlatform))) {
|
|
4697
4697
|
console.warn("Actions set in runtime instance will not be available for the agent");
|
|
4698
|
+
console.warn(`LangGraph Platform remote endpoints are deprecated in favor of the "agents" property`);
|
|
4698
4699
|
}
|
|
4699
4700
|
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
4700
4701
|
this.availableAgents = [];
|
|
@@ -5009,6 +5010,23 @@ please use an LLM adapter instead.`
|
|
|
5009
5010
|
throw structuredError;
|
|
5010
5011
|
}
|
|
5011
5012
|
}
|
|
5013
|
+
async getAllAgents(graphqlContext) {
|
|
5014
|
+
const [agentsWithEndpoints, aguiAgents] = await Promise.all([
|
|
5015
|
+
this.discoverAgentsFromEndpoints(graphqlContext),
|
|
5016
|
+
this.discoverAgentsFromAgui()
|
|
5017
|
+
]);
|
|
5018
|
+
this.availableAgents = [
|
|
5019
|
+
...agentsWithEndpoints,
|
|
5020
|
+
...aguiAgents
|
|
5021
|
+
].map((a) => ({
|
|
5022
|
+
name: a.name,
|
|
5023
|
+
id: a.id
|
|
5024
|
+
}));
|
|
5025
|
+
return [
|
|
5026
|
+
...agentsWithEndpoints,
|
|
5027
|
+
...aguiAgents
|
|
5028
|
+
];
|
|
5029
|
+
}
|
|
5012
5030
|
async discoverAgentsFromEndpoints(graphqlContext) {
|
|
5013
5031
|
const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
|
|
5014
5032
|
const agents2 = await acc;
|
|
@@ -5094,53 +5112,49 @@ please use an LLM adapter instead.`
|
|
|
5094
5112
|
});
|
|
5095
5113
|
}
|
|
5096
5114
|
}, Promise.resolve([]));
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5115
|
+
return agents;
|
|
5116
|
+
}
|
|
5117
|
+
async discoverAgentsFromAgui() {
|
|
5118
|
+
const agents = Object.values(this.agents ?? []).reduce(async (acc, agent) => {
|
|
5119
|
+
const agents2 = await acc;
|
|
5120
|
+
const client = agent.client;
|
|
5121
|
+
let data = [];
|
|
5122
|
+
try {
|
|
5123
|
+
data = await client.assistants.search();
|
|
5124
|
+
if (data && "detail" in data && data.detail.toLowerCase() === "not found") {
|
|
5125
|
+
throw new import_shared19.CopilotKitAgentDiscoveryError({
|
|
5126
|
+
availableAgents: this.availableAgents
|
|
5127
|
+
});
|
|
5128
|
+
}
|
|
5129
|
+
} catch (e) {
|
|
5130
|
+
throw new import_shared19.CopilotKitMisuseError({
|
|
5131
|
+
message: `
|
|
5132
|
+
Failed to find or contact agent ${agent.graphId}.
|
|
5133
|
+
Make sure the LangGraph API is running and the agent is defined in langgraph.json
|
|
5134
|
+
|
|
5135
|
+
See more: https://docs.copilotkit.ai/troubleshooting/common-issues`
|
|
5136
|
+
});
|
|
5137
|
+
}
|
|
5138
|
+
const endpointAgents = data.map((entry) => ({
|
|
5139
|
+
name: entry.graph_id,
|
|
5140
|
+
id: entry.assistant_id,
|
|
5141
|
+
description: ""
|
|
5142
|
+
}));
|
|
5143
|
+
return [
|
|
5144
|
+
...agents2,
|
|
5145
|
+
...endpointAgents
|
|
5146
|
+
];
|
|
5147
|
+
}, Promise.resolve([]));
|
|
5101
5148
|
return agents;
|
|
5102
5149
|
}
|
|
5103
5150
|
async loadAgentState(graphqlContext, threadId, agentName) {
|
|
5104
|
-
const
|
|
5105
|
-
const
|
|
5106
|
-
if (!
|
|
5151
|
+
const agents = await this.getAllAgents(graphqlContext);
|
|
5152
|
+
const agent = agents.find((agent2) => agent2.name === agentName);
|
|
5153
|
+
if (!agent) {
|
|
5107
5154
|
throw new Error("Agent not found");
|
|
5108
5155
|
}
|
|
5109
|
-
if (
|
|
5110
|
-
const
|
|
5111
|
-
authorization: `Bearer ${graphqlContext.properties.authorization}`
|
|
5112
|
-
} : null;
|
|
5113
|
-
const client = new import_langgraph_sdk2.Client({
|
|
5114
|
-
apiUrl: agentWithEndpoint.endpoint.deploymentUrl,
|
|
5115
|
-
apiKey: agentWithEndpoint.endpoint.langsmithApiKey,
|
|
5116
|
-
defaultHeaders: {
|
|
5117
|
-
...propertyHeaders
|
|
5118
|
-
}
|
|
5119
|
-
});
|
|
5120
|
-
let state = {};
|
|
5121
|
-
try {
|
|
5122
|
-
state = (await client.threads.getState(threadId)).values;
|
|
5123
|
-
} catch (error) {
|
|
5124
|
-
}
|
|
5125
|
-
if (Object.keys(state).length === 0) {
|
|
5126
|
-
return {
|
|
5127
|
-
threadId: threadId || "",
|
|
5128
|
-
threadExists: false,
|
|
5129
|
-
state: JSON.stringify({}),
|
|
5130
|
-
messages: JSON.stringify([])
|
|
5131
|
-
};
|
|
5132
|
-
} else {
|
|
5133
|
-
const { messages, ...stateWithoutMessages } = state;
|
|
5134
|
-
const copilotkitMessages = langchainMessagesToCopilotKit(messages);
|
|
5135
|
-
return {
|
|
5136
|
-
threadId: threadId || "",
|
|
5137
|
-
threadExists: true,
|
|
5138
|
-
state: JSON.stringify(stateWithoutMessages),
|
|
5139
|
-
messages: JSON.stringify(copilotkitMessages)
|
|
5140
|
-
};
|
|
5141
|
-
}
|
|
5142
|
-
} else if (agentWithEndpoint.endpoint.type === EndpointType.CopilotKit || !("type" in agentWithEndpoint.endpoint)) {
|
|
5143
|
-
const cpkEndpoint = agentWithEndpoint.endpoint;
|
|
5156
|
+
if ("endpoint" in agent && (agent.endpoint.type === EndpointType.CopilotKit || !("type" in agent.endpoint))) {
|
|
5157
|
+
const cpkEndpoint = agent.endpoint;
|
|
5144
5158
|
const fetchUrl = `${cpkEndpoint.url}/agents/state`;
|
|
5145
5159
|
try {
|
|
5146
5160
|
const response = await fetchWithRetry(fetchUrl, {
|
|
@@ -5179,9 +5193,49 @@ please use an LLM adapter instead.`
|
|
|
5179
5193
|
url: fetchUrl
|
|
5180
5194
|
});
|
|
5181
5195
|
}
|
|
5196
|
+
}
|
|
5197
|
+
const propertyHeaders = graphqlContext.properties.authorization ? {
|
|
5198
|
+
authorization: `Bearer ${graphqlContext.properties.authorization}`
|
|
5199
|
+
} : null;
|
|
5200
|
+
let client;
|
|
5201
|
+
if ("endpoint" in agent && agent.endpoint.type === EndpointType.LangGraphPlatform) {
|
|
5202
|
+
client = new import_langgraph_sdk2.Client({
|
|
5203
|
+
apiUrl: agent.endpoint.deploymentUrl,
|
|
5204
|
+
apiKey: agent.endpoint.langsmithApiKey,
|
|
5205
|
+
defaultHeaders: {
|
|
5206
|
+
...propertyHeaders
|
|
5207
|
+
}
|
|
5208
|
+
});
|
|
5209
|
+
} else {
|
|
5210
|
+
const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name];
|
|
5211
|
+
if (!aguiAgent) {
|
|
5212
|
+
throw new Error(`Agent: ${agent.name} could not be resolved`);
|
|
5213
|
+
}
|
|
5214
|
+
client = aguiAgent.client;
|
|
5215
|
+
}
|
|
5216
|
+
let state = {};
|
|
5217
|
+
try {
|
|
5218
|
+
state = (await client.threads.getState(threadId)).values;
|
|
5219
|
+
} catch (error) {
|
|
5220
|
+
}
|
|
5221
|
+
if (Object.keys(state).length === 0) {
|
|
5222
|
+
return {
|
|
5223
|
+
threadId: threadId || "",
|
|
5224
|
+
threadExists: false,
|
|
5225
|
+
state: JSON.stringify({}),
|
|
5226
|
+
messages: JSON.stringify([])
|
|
5227
|
+
};
|
|
5182
5228
|
} else {
|
|
5183
|
-
|
|
5229
|
+
const { messages, ...stateWithoutMessages } = state;
|
|
5230
|
+
const copilotkitMessages = langchainMessagesToCopilotKit(messages);
|
|
5231
|
+
return {
|
|
5232
|
+
threadId: threadId || "",
|
|
5233
|
+
threadExists: true,
|
|
5234
|
+
state: JSON.stringify(stateWithoutMessages),
|
|
5235
|
+
messages: JSON.stringify(copilotkitMessages)
|
|
5236
|
+
};
|
|
5184
5237
|
}
|
|
5238
|
+
throw new Error(`Agent: ${agent.name} could not be resolved`);
|
|
5185
5239
|
}
|
|
5186
5240
|
async processAgentRequest(request) {
|
|
5187
5241
|
var _a, _b, _c, _d, _e;
|
|
@@ -6848,9 +6902,9 @@ function _ts_param2(paramIndex, decorator) {
|
|
|
6848
6902
|
__name(_ts_param2, "_ts_param");
|
|
6849
6903
|
var StateResolver = class {
|
|
6850
6904
|
async loadAgentState(ctx, data) {
|
|
6851
|
-
const agents = await ctx._copilotkit.runtime.
|
|
6852
|
-
const
|
|
6853
|
-
if (!
|
|
6905
|
+
const agents = await ctx._copilotkit.runtime.getAllAgents(ctx);
|
|
6906
|
+
const hasAgent = agents.some((agent) => agent.name === data.agentName);
|
|
6907
|
+
if (!hasAgent) {
|
|
6854
6908
|
throw new import_shared24.CopilotKitAgentDiscoveryError({
|
|
6855
6909
|
agentName: data.agentName,
|
|
6856
6910
|
availableAgents: agents.map((a) => ({
|