@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/{chunk-NK2XARWT.mjs → chunk-6AD7VT26.mjs} +2 -2
  3. package/dist/{chunk-5FNEYAWH.mjs → chunk-6FLO2QTT.mjs} +2 -2
  4. package/dist/{chunk-6W7TKZNY.mjs → chunk-JZWHLURE.mjs} +2 -2
  5. package/dist/{chunk-CJ44W4R2.mjs → chunk-K4JQLKXK.mjs} +2 -2
  6. package/dist/{chunk-ZUF3A5TW.mjs → chunk-RCIYK6YJ.mjs} +107 -53
  7. package/dist/chunk-RCIYK6YJ.mjs.map +1 -0
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +101 -47
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +10 -10
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/index.js +101 -47
  14. package/dist/lib/index.js.map +1 -1
  15. package/dist/lib/index.mjs +6 -6
  16. package/dist/lib/integrations/index.d.ts +2 -2
  17. package/dist/lib/integrations/index.js +4 -4
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +5 -5
  20. package/dist/lib/integrations/nest/index.d.ts +1 -1
  21. package/dist/lib/integrations/nest/index.js +4 -4
  22. package/dist/lib/integrations/nest/index.js.map +1 -1
  23. package/dist/lib/integrations/nest/index.mjs +3 -3
  24. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  25. package/dist/lib/integrations/node-express/index.js +4 -4
  26. package/dist/lib/integrations/node-express/index.js.map +1 -1
  27. package/dist/lib/integrations/node-express/index.mjs +3 -3
  28. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  29. package/dist/lib/integrations/node-http/index.js +4 -4
  30. package/dist/lib/integrations/node-http/index.js.map +1 -1
  31. package/dist/lib/integrations/node-http/index.mjs +2 -2
  32. package/dist/{shared-ba062831.d.ts → shared-941d59dc.d.ts} +2 -0
  33. package/package.json +2 -2
  34. package/src/graphql/resolvers/state.resolver.ts +3 -3
  35. package/src/lib/runtime/copilot-runtime.ts +114 -41
  36. package/dist/chunk-ZUF3A5TW.mjs.map +0 -1
  37. /package/dist/{chunk-NK2XARWT.mjs.map → chunk-6AD7VT26.mjs.map} +0 -0
  38. /package/dist/{chunk-5FNEYAWH.mjs.map → chunk-6FLO2QTT.mjs.map} +0 -0
  39. /package/dist/{chunk-6W7TKZNY.mjs.map → chunk-JZWHLURE.mjs.map} +0 -0
  40. /package/dist/{chunk-CJ44W4R2.mjs.map → chunk-K4JQLKXK.mjs.map} +0 -0
package/dist/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-ba062831.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-941d59dc.js';
3
3
  export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint } from './lib/integrations/index.js';
4
4
  export { copilotRuntimeNodeHttpEndpoint } from './lib/integrations/node-http/index.js';
5
5
  export { copilotRuntimeNodeExpressEndpoint } from './lib/integrations/node-express/index.js';
package/dist/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.4",
47
+ version: "1.9.2-next.6",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -5107,6 +5107,7 @@ var CopilotRuntime = class {
5107
5107
  var _a, _b, _c, _d;
5108
5108
  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))) {
5109
5109
  console.warn("Actions set in runtime instance will not be available for the agent");
5110
+ console.warn(`LangGraph Platform remote endpoints are deprecated in favor of the "agents" property`);
5110
5111
  }
5111
5112
  this.actions = (params == null ? void 0 : params.actions) || [];
5112
5113
  this.availableAgents = [];
@@ -5421,6 +5422,23 @@ please use an LLM adapter instead.`
5421
5422
  throw structuredError;
5422
5423
  }
5423
5424
  }
5425
+ async getAllAgents(graphqlContext) {
5426
+ const [agentsWithEndpoints, aguiAgents] = await Promise.all([
5427
+ this.discoverAgentsFromEndpoints(graphqlContext),
5428
+ this.discoverAgentsFromAgui()
5429
+ ]);
5430
+ this.availableAgents = [
5431
+ ...agentsWithEndpoints,
5432
+ ...aguiAgents
5433
+ ].map((a) => ({
5434
+ name: a.name,
5435
+ id: a.id
5436
+ }));
5437
+ return [
5438
+ ...agentsWithEndpoints,
5439
+ ...aguiAgents
5440
+ ];
5441
+ }
5424
5442
  async discoverAgentsFromEndpoints(graphqlContext) {
5425
5443
  const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
5426
5444
  const agents2 = await acc;
@@ -5506,53 +5524,49 @@ please use an LLM adapter instead.`
5506
5524
  });
5507
5525
  }
5508
5526
  }, Promise.resolve([]));
5509
- this.availableAgents = (await agents ?? []).map((a) => ({
5510
- name: a.name,
5511
- id: a.id
5512
- }));
5527
+ return agents;
5528
+ }
5529
+ async discoverAgentsFromAgui() {
5530
+ const agents = Object.values(this.agents ?? []).reduce(async (acc, agent) => {
5531
+ const agents2 = await acc;
5532
+ const client = agent.client;
5533
+ let data = [];
5534
+ try {
5535
+ data = await client.assistants.search();
5536
+ if (data && "detail" in data && data.detail.toLowerCase() === "not found") {
5537
+ throw new import_shared21.CopilotKitAgentDiscoveryError({
5538
+ availableAgents: this.availableAgents
5539
+ });
5540
+ }
5541
+ } catch (e) {
5542
+ throw new import_shared21.CopilotKitMisuseError({
5543
+ message: `
5544
+ Failed to find or contact agent ${agent.graphId}.
5545
+ Make sure the LangGraph API is running and the agent is defined in langgraph.json
5546
+
5547
+ See more: https://docs.copilotkit.ai/troubleshooting/common-issues`
5548
+ });
5549
+ }
5550
+ const endpointAgents = data.map((entry) => ({
5551
+ name: entry.graph_id,
5552
+ id: entry.assistant_id,
5553
+ description: ""
5554
+ }));
5555
+ return [
5556
+ ...agents2,
5557
+ ...endpointAgents
5558
+ ];
5559
+ }, Promise.resolve([]));
5513
5560
  return agents;
5514
5561
  }
5515
5562
  async loadAgentState(graphqlContext, threadId, agentName) {
5516
- const agentsWithEndpoints = await this.discoverAgentsFromEndpoints(graphqlContext);
5517
- const agentWithEndpoint = agentsWithEndpoints.find((agent) => agent.name === agentName);
5518
- if (!agentWithEndpoint) {
5563
+ const agents = await this.getAllAgents(graphqlContext);
5564
+ const agent = agents.find((agent2) => agent2.name === agentName);
5565
+ if (!agent) {
5519
5566
  throw new Error("Agent not found");
5520
5567
  }
5521
- if (agentWithEndpoint.endpoint.type === EndpointType.LangGraphPlatform) {
5522
- const propertyHeaders = graphqlContext.properties.authorization ? {
5523
- authorization: `Bearer ${graphqlContext.properties.authorization}`
5524
- } : null;
5525
- const client = new import_langgraph_sdk2.Client({
5526
- apiUrl: agentWithEndpoint.endpoint.deploymentUrl,
5527
- apiKey: agentWithEndpoint.endpoint.langsmithApiKey,
5528
- defaultHeaders: {
5529
- ...propertyHeaders
5530
- }
5531
- });
5532
- let state = {};
5533
- try {
5534
- state = (await client.threads.getState(threadId)).values;
5535
- } catch (error) {
5536
- }
5537
- if (Object.keys(state).length === 0) {
5538
- return {
5539
- threadId: threadId || "",
5540
- threadExists: false,
5541
- state: JSON.stringify({}),
5542
- messages: JSON.stringify([])
5543
- };
5544
- } else {
5545
- const { messages, ...stateWithoutMessages } = state;
5546
- const copilotkitMessages = langchainMessagesToCopilotKit(messages);
5547
- return {
5548
- threadId: threadId || "",
5549
- threadExists: true,
5550
- state: JSON.stringify(stateWithoutMessages),
5551
- messages: JSON.stringify(copilotkitMessages)
5552
- };
5553
- }
5554
- } else if (agentWithEndpoint.endpoint.type === EndpointType.CopilotKit || !("type" in agentWithEndpoint.endpoint)) {
5555
- const cpkEndpoint = agentWithEndpoint.endpoint;
5568
+ if ("endpoint" in agent && (agent.endpoint.type === EndpointType.CopilotKit || !("type" in agent.endpoint))) {
5569
+ const cpkEndpoint = agent.endpoint;
5556
5570
  const fetchUrl = `${cpkEndpoint.url}/agents/state`;
5557
5571
  try {
5558
5572
  const response = await fetchWithRetry(fetchUrl, {
@@ -5591,9 +5605,49 @@ please use an LLM adapter instead.`
5591
5605
  url: fetchUrl
5592
5606
  });
5593
5607
  }
5608
+ }
5609
+ const propertyHeaders = graphqlContext.properties.authorization ? {
5610
+ authorization: `Bearer ${graphqlContext.properties.authorization}`
5611
+ } : null;
5612
+ let client;
5613
+ if ("endpoint" in agent && agent.endpoint.type === EndpointType.LangGraphPlatform) {
5614
+ client = new import_langgraph_sdk2.Client({
5615
+ apiUrl: agent.endpoint.deploymentUrl,
5616
+ apiKey: agent.endpoint.langsmithApiKey,
5617
+ defaultHeaders: {
5618
+ ...propertyHeaders
5619
+ }
5620
+ });
5621
+ } else {
5622
+ const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name];
5623
+ if (!aguiAgent) {
5624
+ throw new Error(`Agent: ${agent.name} could not be resolved`);
5625
+ }
5626
+ client = aguiAgent.client;
5627
+ }
5628
+ let state = {};
5629
+ try {
5630
+ state = (await client.threads.getState(threadId)).values;
5631
+ } catch (error) {
5632
+ }
5633
+ if (Object.keys(state).length === 0) {
5634
+ return {
5635
+ threadId: threadId || "",
5636
+ threadExists: false,
5637
+ state: JSON.stringify({}),
5638
+ messages: JSON.stringify([])
5639
+ };
5594
5640
  } else {
5595
- throw new Error(`Unknown endpoint type: ${agentWithEndpoint.endpoint.type}`);
5641
+ const { messages, ...stateWithoutMessages } = state;
5642
+ const copilotkitMessages = langchainMessagesToCopilotKit(messages);
5643
+ return {
5644
+ threadId: threadId || "",
5645
+ threadExists: true,
5646
+ state: JSON.stringify(stateWithoutMessages),
5647
+ messages: JSON.stringify(copilotkitMessages)
5648
+ };
5596
5649
  }
5650
+ throw new Error(`Agent: ${agent.name} could not be resolved`);
5597
5651
  }
5598
5652
  async processAgentRequest(request) {
5599
5653
  var _a, _b, _c, _d, _e;
@@ -7260,9 +7314,9 @@ function _ts_param2(paramIndex, decorator) {
7260
7314
  __name(_ts_param2, "_ts_param");
7261
7315
  var StateResolver = class {
7262
7316
  async loadAgentState(ctx, data) {
7263
- const agents = await ctx._copilotkit.runtime.discoverAgentsFromEndpoints(ctx);
7264
- const agent = agents.find((agent2) => agent2.name === data.agentName);
7265
- if (!agent) {
7317
+ const agents = await ctx._copilotkit.runtime.getAllAgents(ctx);
7318
+ const hasAgent = agents.some((agent) => agent.name === data.agentName);
7319
+ if (!hasAgent) {
7266
7320
  throw new import_shared26.CopilotKitAgentDiscoveryError({
7267
7321
  agentName: data.agentName,
7268
7322
  availableAgents: agents.map((a) => ({