@copilotkit/runtime 1.9.2-next.5 → 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 +7 -0
- package/dist/{chunk-T4U5EWYD.mjs → chunk-6AD7VT26.mjs} +2 -2
- package/dist/{chunk-BLBS3CQH.mjs → chunk-6FLO2QTT.mjs} +2 -2
- package/dist/{chunk-5WRXYU4R.mjs → chunk-JZWHLURE.mjs} +2 -2
- package/dist/{chunk-RK7WRNH6.mjs → chunk-K4JQLKXK.mjs} +2 -2
- package/dist/{chunk-ZVJSUAD7.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-ZVJSUAD7.mjs.map +0 -1
- /package/dist/{chunk-T4U5EWYD.mjs.map → chunk-6AD7VT26.mjs.map} +0 -0
- /package/dist/{chunk-BLBS3CQH.mjs.map → chunk-6FLO2QTT.mjs.map} +0 -0
- /package/dist/{chunk-5WRXYU4R.mjs.map → chunk-JZWHLURE.mjs.map} +0 -0
- /package/dist/{chunk-RK7WRNH6.mjs.map → chunk-K4JQLKXK.mjs.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-IIXJVVTV.mjs";
|
|
3
|
+
} from "../../../chunk-RCIYK6YJ.mjs";
|
|
5
4
|
import "../../../chunk-5BIEM2UU.mjs";
|
|
5
|
+
import "../../../chunk-IIXJVVTV.mjs";
|
|
6
6
|
import "../../../chunk-SHBDMA63.mjs";
|
|
7
7
|
import "../../../chunk-2OZAGFV3.mjs";
|
|
8
8
|
import "../../../chunk-FHD4JECV.mjs";
|
|
@@ -375,7 +375,9 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
375
375
|
constructor(params?: CopilotRuntimeConstructorParams<T>);
|
|
376
376
|
private injectMCPToolInstructions;
|
|
377
377
|
processRuntimeRequest(request: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
|
|
378
|
+
getAllAgents(graphqlContext: GraphQLContext): Promise<(AgentWithEndpoint | Agent)[]>;
|
|
378
379
|
discoverAgentsFromEndpoints(graphqlContext: GraphQLContext): Promise<AgentWithEndpoint[]>;
|
|
380
|
+
discoverAgentsFromAgui(): Promise<AgentWithEndpoint[]>;
|
|
379
381
|
loadAgentState(graphqlContext: GraphQLContext, threadId: string, agentName: string): Promise<LoadAgentStateResponse>;
|
|
380
382
|
private processAgentRequest;
|
|
381
383
|
private getServerSideActions;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.9.2-next.
|
|
12
|
+
"version": "1.9.2-next.6",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"rxjs": "7.8.1",
|
|
67
67
|
"type-graphql": "2.0.0-rc.1",
|
|
68
68
|
"zod": "^3.23.3",
|
|
69
|
-
"@copilotkit/shared": "1.9.2-next.
|
|
69
|
+
"@copilotkit/shared": "1.9.2-next.6"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@ag-ui/client": ">=0.0.28",
|
|
@@ -10,9 +10,9 @@ import { CopilotKitAgentDiscoveryError } from "@copilotkit/shared";
|
|
|
10
10
|
export class StateResolver {
|
|
11
11
|
@Query(() => LoadAgentStateResponse)
|
|
12
12
|
async loadAgentState(@Ctx() ctx: GraphQLContext, @Arg("data") data: LoadAgentStateInput) {
|
|
13
|
-
const agents = await ctx._copilotkit.runtime.
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
13
|
+
const agents = await ctx._copilotkit.runtime.getAllAgents(ctx);
|
|
14
|
+
const hasAgent = agents.some((agent) => agent.name === data.agentName);
|
|
15
|
+
if (!hasAgent) {
|
|
16
16
|
throw new CopilotKitAgentDiscoveryError({
|
|
17
17
|
agentName: data.agentName,
|
|
18
18
|
availableAgents: agents.map((a) => ({ name: a.name, id: a.name })),
|
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
convertMCPToolsToActions,
|
|
85
85
|
generateMcpToolInstructions,
|
|
86
86
|
} from "./mcp-tools-utils";
|
|
87
|
+
import { LangGraphAgent } from "./langgraph/langgraph-agent";
|
|
87
88
|
// Define the function type alias here or import if defined elsewhere
|
|
88
89
|
type CreateMCPClientFunction = (config: MCPEndpointConfig) => Promise<MCPClient>;
|
|
89
90
|
// --- MCP Imports ---
|
|
@@ -327,7 +328,21 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
327
328
|
params?.remoteEndpoints.some((e) => e.type === EndpointType.LangGraphPlatform)
|
|
328
329
|
) {
|
|
329
330
|
console.warn("Actions set in runtime instance will not be available for the agent");
|
|
331
|
+
console.warn(
|
|
332
|
+
`LangGraph Platform remote endpoints are deprecated in favor of the "agents" property`,
|
|
333
|
+
);
|
|
330
334
|
}
|
|
335
|
+
|
|
336
|
+
// TODO: finalize
|
|
337
|
+
// if (
|
|
338
|
+
// params?.agents &&
|
|
339
|
+
// Object.values(params.agents).some((agent) => {
|
|
340
|
+
// return agent instanceof AguiLangGraphAgent && !(agent instanceof LangGraphAgent);
|
|
341
|
+
// })
|
|
342
|
+
// ) {
|
|
343
|
+
// console.warn('LangGraph Agent class should be imported from @copilotkit/runtime. ')
|
|
344
|
+
// }
|
|
345
|
+
|
|
331
346
|
this.actions = params?.actions || [];
|
|
332
347
|
this.availableAgents = [];
|
|
333
348
|
|
|
@@ -767,6 +782,20 @@ please use an LLM adapter instead.`,
|
|
|
767
782
|
}
|
|
768
783
|
}
|
|
769
784
|
|
|
785
|
+
async getAllAgents(graphqlContext: GraphQLContext): Promise<(AgentWithEndpoint | Agent)[]> {
|
|
786
|
+
const [agentsWithEndpoints, aguiAgents] = await Promise.all([
|
|
787
|
+
this.discoverAgentsFromEndpoints(graphqlContext),
|
|
788
|
+
this.discoverAgentsFromAgui(),
|
|
789
|
+
]);
|
|
790
|
+
|
|
791
|
+
this.availableAgents = [...agentsWithEndpoints, ...aguiAgents].map((a) => ({
|
|
792
|
+
name: a.name,
|
|
793
|
+
id: a.id,
|
|
794
|
+
}));
|
|
795
|
+
|
|
796
|
+
return [...agentsWithEndpoints, ...aguiAgents];
|
|
797
|
+
}
|
|
798
|
+
|
|
770
799
|
async discoverAgentsFromEndpoints(graphqlContext: GraphQLContext): Promise<AgentWithEndpoint[]> {
|
|
771
800
|
const agents: Promise<AgentWithEndpoint[]> = this.remoteEndpointDefinitions.reduce(
|
|
772
801
|
async (acc: Promise<Agent[]>, endpoint) => {
|
|
@@ -848,7 +877,41 @@ please use an LLM adapter instead.`,
|
|
|
848
877
|
},
|
|
849
878
|
Promise.resolve([]),
|
|
850
879
|
);
|
|
851
|
-
|
|
880
|
+
|
|
881
|
+
return agents;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
async discoverAgentsFromAgui(): Promise<AgentWithEndpoint[]> {
|
|
885
|
+
const agents: Promise<AgentWithEndpoint[]> = Object.values(this.agents ?? []).reduce(
|
|
886
|
+
async (acc: Promise<Agent[]>, agent: LangGraphAgent) => {
|
|
887
|
+
const agents = await acc;
|
|
888
|
+
|
|
889
|
+
const client = agent.client;
|
|
890
|
+
let data: Array<{ assistant_id: string; graph_id: string }> | { detail: string } = [];
|
|
891
|
+
try {
|
|
892
|
+
data = await client.assistants.search();
|
|
893
|
+
|
|
894
|
+
if (data && "detail" in data && (data.detail as string).toLowerCase() === "not found") {
|
|
895
|
+
throw new CopilotKitAgentDiscoveryError({ availableAgents: this.availableAgents });
|
|
896
|
+
}
|
|
897
|
+
} catch (e) {
|
|
898
|
+
throw new CopilotKitMisuseError({
|
|
899
|
+
message: `
|
|
900
|
+
Failed to find or contact agent ${agent.graphId}.
|
|
901
|
+
Make sure the LangGraph API is running and the agent is defined in langgraph.json
|
|
902
|
+
|
|
903
|
+
See more: https://docs.copilotkit.ai/troubleshooting/common-issues`,
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
const endpointAgents = data.map((entry) => ({
|
|
907
|
+
name: entry.graph_id,
|
|
908
|
+
id: entry.assistant_id,
|
|
909
|
+
description: "",
|
|
910
|
+
}));
|
|
911
|
+
return [...agents, ...endpointAgents];
|
|
912
|
+
},
|
|
913
|
+
Promise.resolve([]),
|
|
914
|
+
);
|
|
852
915
|
|
|
853
916
|
return agents;
|
|
854
917
|
}
|
|
@@ -858,50 +921,18 @@ please use an LLM adapter instead.`,
|
|
|
858
921
|
threadId: string,
|
|
859
922
|
agentName: string,
|
|
860
923
|
): Promise<LoadAgentStateResponse> {
|
|
861
|
-
const
|
|
924
|
+
const agents = await this.getAllAgents(graphqlContext);
|
|
862
925
|
|
|
863
|
-
const
|
|
864
|
-
if (!
|
|
926
|
+
const agent = agents.find((agent) => agent.name === agentName);
|
|
927
|
+
if (!agent) {
|
|
865
928
|
throw new Error("Agent not found");
|
|
866
929
|
}
|
|
867
930
|
|
|
868
|
-
if (
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
: null;
|
|
872
|
-
|
|
873
|
-
const client = new LangGraphClient({
|
|
874
|
-
apiUrl: agentWithEndpoint.endpoint.deploymentUrl,
|
|
875
|
-
apiKey: agentWithEndpoint.endpoint.langsmithApiKey,
|
|
876
|
-
defaultHeaders: { ...propertyHeaders },
|
|
877
|
-
});
|
|
878
|
-
let state: any = {};
|
|
879
|
-
try {
|
|
880
|
-
state = (await client.threads.getState(threadId)).values as any;
|
|
881
|
-
} catch (error) {}
|
|
882
|
-
|
|
883
|
-
if (Object.keys(state).length === 0) {
|
|
884
|
-
return {
|
|
885
|
-
threadId: threadId || "",
|
|
886
|
-
threadExists: false,
|
|
887
|
-
state: JSON.stringify({}),
|
|
888
|
-
messages: JSON.stringify([]),
|
|
889
|
-
};
|
|
890
|
-
} else {
|
|
891
|
-
const { messages, ...stateWithoutMessages } = state;
|
|
892
|
-
const copilotkitMessages = langchainMessagesToCopilotKit(messages);
|
|
893
|
-
return {
|
|
894
|
-
threadId: threadId || "",
|
|
895
|
-
threadExists: true,
|
|
896
|
-
state: JSON.stringify(stateWithoutMessages),
|
|
897
|
-
messages: JSON.stringify(copilotkitMessages),
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
} else if (
|
|
901
|
-
agentWithEndpoint.endpoint.type === EndpointType.CopilotKit ||
|
|
902
|
-
!("type" in agentWithEndpoint.endpoint)
|
|
931
|
+
if (
|
|
932
|
+
"endpoint" in agent &&
|
|
933
|
+
(agent.endpoint.type === EndpointType.CopilotKit || !("type" in agent.endpoint))
|
|
903
934
|
) {
|
|
904
|
-
const cpkEndpoint =
|
|
935
|
+
const cpkEndpoint = agent.endpoint as CopilotKitEndpoint;
|
|
905
936
|
const fetchUrl = `${cpkEndpoint.url}/agents/state`;
|
|
906
937
|
try {
|
|
907
938
|
const response = await fetchWithRetry(fetchUrl, {
|
|
@@ -937,9 +968,51 @@ please use an LLM adapter instead.`,
|
|
|
937
968
|
}
|
|
938
969
|
throw new CopilotKitLowLevelError({ error, url: fetchUrl });
|
|
939
970
|
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
const propertyHeaders = graphqlContext.properties.authorization
|
|
974
|
+
? { authorization: `Bearer ${graphqlContext.properties.authorization}` }
|
|
975
|
+
: null;
|
|
976
|
+
|
|
977
|
+
let client: LangGraphClient;
|
|
978
|
+
if ("endpoint" in agent && agent.endpoint.type === EndpointType.LangGraphPlatform) {
|
|
979
|
+
client = new LangGraphClient({
|
|
980
|
+
apiUrl: agent.endpoint.deploymentUrl,
|
|
981
|
+
apiKey: agent.endpoint.langsmithApiKey,
|
|
982
|
+
defaultHeaders: { ...propertyHeaders },
|
|
983
|
+
});
|
|
984
|
+
} else {
|
|
985
|
+
const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name] as LangGraphAgent;
|
|
986
|
+
if (!aguiAgent) {
|
|
987
|
+
throw new Error(`Agent: ${agent.name} could not be resolved`);
|
|
988
|
+
}
|
|
989
|
+
// @ts-expect-error -- both clients are the same
|
|
990
|
+
client = aguiAgent.client;
|
|
991
|
+
}
|
|
992
|
+
let state: any = {};
|
|
993
|
+
try {
|
|
994
|
+
state = (await client.threads.getState(threadId)).values as any;
|
|
995
|
+
} catch (error) {}
|
|
996
|
+
|
|
997
|
+
if (Object.keys(state).length === 0) {
|
|
998
|
+
return {
|
|
999
|
+
threadId: threadId || "",
|
|
1000
|
+
threadExists: false,
|
|
1001
|
+
state: JSON.stringify({}),
|
|
1002
|
+
messages: JSON.stringify([]),
|
|
1003
|
+
};
|
|
940
1004
|
} else {
|
|
941
|
-
|
|
1005
|
+
const { messages, ...stateWithoutMessages } = state;
|
|
1006
|
+
const copilotkitMessages = langchainMessagesToCopilotKit(messages);
|
|
1007
|
+
return {
|
|
1008
|
+
threadId: threadId || "",
|
|
1009
|
+
threadExists: true,
|
|
1010
|
+
state: JSON.stringify(stateWithoutMessages),
|
|
1011
|
+
messages: JSON.stringify(copilotkitMessages),
|
|
1012
|
+
};
|
|
942
1013
|
}
|
|
1014
|
+
|
|
1015
|
+
throw new Error(`Agent: ${agent.name} could not be resolved`);
|
|
943
1016
|
}
|
|
944
1017
|
|
|
945
1018
|
private async processAgentRequest(
|