@copilotkit/runtime 1.3.12-lgc-alpha-1.0 → 1.3.13

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 (56) hide show
  1. package/CHANGELOG.md +12 -3
  2. package/dist/{chunk-6HXQC7IT.mjs → chunk-3LFBIWWK.mjs} +9 -36
  3. package/dist/chunk-3LFBIWWK.mjs.map +1 -0
  4. package/dist/{chunk-E6ZFCM3B.mjs → chunk-76K222WC.mjs} +133 -561
  5. package/dist/chunk-76K222WC.mjs.map +1 -0
  6. package/dist/{chunk-V7SK6QZN.mjs → chunk-CPAHDRLS.mjs} +36 -9
  7. package/dist/chunk-CPAHDRLS.mjs.map +1 -0
  8. package/dist/{chunk-TM7ZRU3M.mjs → chunk-DEZQR4EM.mjs} +2 -2
  9. package/dist/{chunk-XMDH5MKI.mjs → chunk-MCUYYSCJ.mjs} +2 -2
  10. package/dist/{chunk-6B3NPPSR.mjs → chunk-SPZSO3T3.mjs} +2 -2
  11. package/dist/{chunk-7MQDBRXJ.mjs → chunk-Y6RQG5HF.mjs} +2 -2
  12. package/dist/{copilot-runtime-aba7d4b4.d.ts → copilot-runtime-df3527ad.d.ts} +5 -27
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +213 -641
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +9 -13
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/lib/index.d.ts +1 -1
  19. package/dist/lib/index.js +213 -641
  20. package/dist/lib/index.js.map +1 -1
  21. package/dist/lib/index.mjs +9 -13
  22. package/dist/lib/integrations/index.d.ts +2 -2
  23. package/dist/lib/integrations/index.js +4 -5
  24. package/dist/lib/integrations/index.js.map +1 -1
  25. package/dist/lib/integrations/index.mjs +5 -5
  26. package/dist/lib/integrations/nest/index.d.ts +1 -1
  27. package/dist/lib/integrations/nest/index.js +4 -5
  28. package/dist/lib/integrations/nest/index.js.map +1 -1
  29. package/dist/lib/integrations/nest/index.mjs +3 -3
  30. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  31. package/dist/lib/integrations/node-express/index.js +4 -5
  32. package/dist/lib/integrations/node-express/index.js.map +1 -1
  33. package/dist/lib/integrations/node-express/index.mjs +3 -3
  34. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  35. package/dist/lib/integrations/node-http/index.js +4 -5
  36. package/dist/lib/integrations/node-http/index.js.map +1 -1
  37. package/dist/lib/integrations/node-http/index.mjs +2 -2
  38. package/dist/service-adapters/index.js +35 -8
  39. package/dist/service-adapters/index.js.map +1 -1
  40. package/dist/service-adapters/index.mjs +2 -2
  41. package/package.json +6 -7
  42. package/src/agents/langgraph/event-source.ts +67 -22
  43. package/src/lib/runtime/copilot-runtime.ts +11 -58
  44. package/src/lib/runtime/remote-actions.ts +159 -65
  45. package/src/service-adapters/events.ts +5 -1
  46. package/src/service-adapters/langchain/utils.test.ts +169 -0
  47. package/src/service-adapters/langchain/utils.ts +41 -8
  48. package/dist/chunk-6HXQC7IT.mjs.map +0 -1
  49. package/dist/chunk-E6ZFCM3B.mjs.map +0 -1
  50. package/dist/chunk-V7SK6QZN.mjs.map +0 -1
  51. package/src/lib/runtime/remote-action-constructors.ts +0 -283
  52. package/src/lib/runtime/remote-lg-cloud-action.ts +0 -441
  53. /package/dist/{chunk-TM7ZRU3M.mjs.map → chunk-DEZQR4EM.mjs.map} +0 -0
  54. /package/dist/{chunk-XMDH5MKI.mjs.map → chunk-MCUYYSCJ.mjs.map} +0 -0
  55. /package/dist/{chunk-6B3NPPSR.mjs.map → chunk-SPZSO3T3.mjs.map} +0 -0
  56. /package/dist/{chunk-7MQDBRXJ.mjs.map → chunk-Y6RQG5HF.mjs.map} +0 -0
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.3.12-lgc-alpha-1.0",
47
+ version: "1.3.13",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -77,16 +77,16 @@ var require_package = __commonJS({
77
77
  "ts-node": "^10.9.2",
78
78
  tsconfig: "workspace:*",
79
79
  tsup: "^6.7.0",
80
- typescript: "^5.2.3"
80
+ typescript: "^5.2.3",
81
+ "zod-to-json-schema": "^3.23.5"
81
82
  },
82
83
  dependencies: {
83
84
  "@anthropic-ai/sdk": "^0.27.3",
84
85
  "@copilotkit/shared": "workspace:*",
85
- "@langchain/google-gauth": "^0.1.0",
86
86
  "@graphql-yoga/plugin-defer-stream": "^3.3.1",
87
87
  "@langchain/community": "^0.0.53",
88
88
  "@langchain/core": "^0.3.13",
89
- "@langchain/langgraph-sdk": "^0.0.16",
89
+ "@langchain/google-gauth": "^0.1.0",
90
90
  "@langchain/openai": "^0.0.28",
91
91
  "class-transformer": "^0.5.1",
92
92
  express: "^4.19.2",
@@ -96,7 +96,6 @@ var require_package = __commonJS({
96
96
  "groq-sdk": "^0.5.0",
97
97
  langchain: "^0.3.3",
98
98
  openai: "^4.50.0",
99
- "partial-json": "^0.1.7",
100
99
  pino: "^9.2.0",
101
100
  "pino-pretty": "^11.2.1",
102
101
  "reflect-metadata": "^0.2.2",
@@ -137,7 +136,6 @@ __export(src_exports, {
137
136
  UnknownErrorResponse: () => UnknownErrorResponse,
138
137
  buildSchema: () => buildSchema,
139
138
  config: () => config,
140
- copilotKitEndpoint: () => copilotKitEndpoint,
141
139
  copilotRuntimeNestEndpoint: () => copilotRuntimeNestEndpoint,
142
140
  copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
143
141
  copilotRuntimeNextJSPagesRouterEndpoint: () => copilotRuntimeNextJSPagesRouterEndpoint,
@@ -145,8 +143,7 @@ __export(src_exports, {
145
143
  copilotRuntimeNodeHttpEndpoint: () => copilotRuntimeNodeHttpEndpoint,
146
144
  createContext: () => createContext,
147
145
  flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
148
- getCommonConfig: () => getCommonConfig,
149
- langGraphCloudEndpoint: () => langGraphCloudEndpoint
146
+ getCommonConfig: () => getCommonConfig
150
147
  });
151
148
  module.exports = __toCommonJS(src_exports);
152
149
  var import_reflect_metadata = require("reflect-metadata");
@@ -503,24 +500,27 @@ __name(convertMessageToLangChainMessage, "convertMessageToLangChainMessage");
503
500
  function convertJsonSchemaToZodSchema(jsonSchema, required) {
504
501
  if (jsonSchema.type === "object") {
505
502
  const spec = {};
503
+ if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
504
+ return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
505
+ }
506
506
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
507
507
  spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
508
508
  }
509
509
  let schema = import_zod.z.object(spec);
510
- return !required ? schema.optional() : schema;
510
+ return required ? schema : schema.optional();
511
511
  } else if (jsonSchema.type === "string") {
512
512
  let schema = import_zod.z.string().describe(jsonSchema.description);
513
- return !required ? schema.optional() : schema;
513
+ return required ? schema : schema.optional();
514
514
  } else if (jsonSchema.type === "number") {
515
515
  let schema = import_zod.z.number().describe(jsonSchema.description);
516
- return !required ? schema.optional() : schema;
516
+ return required ? schema : schema.optional();
517
517
  } else if (jsonSchema.type === "boolean") {
518
518
  let schema = import_zod.z.boolean().describe(jsonSchema.description);
519
- return !required ? schema.optional() : schema;
519
+ return required ? schema : schema.optional();
520
520
  } else if (jsonSchema.type === "array") {
521
521
  let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
522
522
  let schema = import_zod.z.array(itemSchema);
523
- return !required ? schema.optional() : schema;
523
+ return required ? schema : schema.optional();
524
524
  }
525
525
  }
526
526
  __name(convertJsonSchemaToZodSchema, "convertJsonSchemaToZodSchema");
@@ -583,20 +583,39 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
583
583
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
584
584
  let reader = result.getReader();
585
585
  let mode = null;
586
+ const toolCallDetails = {
587
+ name: null,
588
+ id: null,
589
+ index: null,
590
+ prevIndex: null
591
+ };
586
592
  while (true) {
587
593
  try {
588
594
  const { done, value } = await reader.read();
589
595
  let toolCallName = void 0;
590
596
  let toolCallId = void 0;
591
597
  let toolCallArgs = void 0;
598
+ let toolCallIndex = void 0;
599
+ let toolCallPrevIndex = void 0;
592
600
  let hasToolCall = false;
593
601
  let content = value == null ? void 0 : value.content;
594
602
  if (isAIMessageChunk(value)) {
595
603
  let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
596
- toolCallName = chunk == null ? void 0 : chunk.name;
597
- toolCallId = chunk == null ? void 0 : chunk.id;
598
604
  toolCallArgs = chunk == null ? void 0 : chunk.args;
599
605
  hasToolCall = chunk != void 0;
606
+ if (chunk == null ? void 0 : chunk.name)
607
+ toolCallDetails.name = chunk.name;
608
+ if ((chunk == null ? void 0 : chunk.index) != null) {
609
+ toolCallDetails.index = chunk.index;
610
+ if (toolCallDetails.prevIndex == null)
611
+ toolCallDetails.prevIndex = chunk.index;
612
+ }
613
+ if (chunk == null ? void 0 : chunk.id)
614
+ toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;
615
+ toolCallName = toolCallDetails.name;
616
+ toolCallId = toolCallDetails.id;
617
+ toolCallIndex = toolCallDetails.index;
618
+ toolCallPrevIndex = toolCallDetails.prevIndex;
600
619
  } else if (isBaseMessageChunk(value)) {
601
620
  let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
602
621
  toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
@@ -615,7 +634,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
615
634
  break;
616
635
  }
617
636
  if (mode === null) {
618
- if (hasToolCall) {
637
+ if (hasToolCall && toolCallId && toolCallName) {
619
638
  mode = "function";
620
639
  eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
621
640
  } else if (content) {
@@ -626,6 +645,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
626
645
  if (mode === "message" && content) {
627
646
  eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
628
647
  } else if (mode === "function" && toolCallArgs) {
648
+ if (toolCallIndex !== toolCallPrevIndex) {
649
+ eventStream$.sendActionExecutionEnd();
650
+ eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
651
+ toolCallDetails.prevIndex = toolCallDetails.index;
652
+ }
629
653
  eventStream$.sendActionExecutionArgs(toolCallArgs);
630
654
  }
631
655
  } catch (error) {
@@ -1338,6 +1362,50 @@ var LangGraphEventTypes;
1338
1362
  var import_shared8 = require("@copilotkit/shared");
1339
1363
  var RemoteLangGraphEventSource = class {
1340
1364
  eventStream$ = new import_rxjs.ReplaySubject();
1365
+ async streamResponse(response) {
1366
+ const reader = response.body.getReader();
1367
+ const decoder = new TextDecoder();
1368
+ let buffer = [];
1369
+ const eventStream$ = this.eventStream$;
1370
+ function flushBuffer() {
1371
+ const currentBuffer = buffer.join("");
1372
+ if (currentBuffer.trim().length === 0) {
1373
+ return;
1374
+ }
1375
+ const parts = currentBuffer.split("\n");
1376
+ if (parts.length === 0) {
1377
+ return;
1378
+ }
1379
+ const lastPartIsComplete = currentBuffer.endsWith("\n");
1380
+ buffer = [];
1381
+ if (!lastPartIsComplete) {
1382
+ buffer.push(parts.pop());
1383
+ }
1384
+ parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
1385
+ eventStream$.next(JSON.parse(part));
1386
+ });
1387
+ }
1388
+ __name(flushBuffer, "flushBuffer");
1389
+ try {
1390
+ while (true) {
1391
+ const { done, value } = await reader.read();
1392
+ if (!done) {
1393
+ buffer.push(decoder.decode(value, {
1394
+ stream: true
1395
+ }));
1396
+ }
1397
+ flushBuffer();
1398
+ if (done) {
1399
+ break;
1400
+ }
1401
+ }
1402
+ } catch (error) {
1403
+ console.error("Error in stream", error);
1404
+ eventStream$.error(error);
1405
+ return;
1406
+ }
1407
+ eventStream$.complete();
1408
+ }
1341
1409
  shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
1342
1410
  if (typeof shouldEmitToolCalls === "boolean") {
1343
1411
  return shouldEmitToolCalls;
@@ -1360,25 +1428,20 @@ var RemoteLangGraphEventSource = class {
1360
1428
  } else {
1361
1429
  acc.content = null;
1362
1430
  }
1363
- const toolCallChunks = (
1364
- // @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
1365
- ((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) ?? ((_j = (_i = event.data) == null ? void 0 : _i.chunk) == null ? void 0 : _j.tool_call_chunks)
1366
- );
1367
- const toolCallMessageId = ((_m = (_l = (_k = event.data) == null ? void 0 : _k.chunk) == null ? void 0 : _l.kwargs) == null ? void 0 : _m.id) ?? ((_o = (_n = event.data) == null ? void 0 : _n.chunk) == null ? void 0 : _o.id);
1368
- if (toolCallChunks && toolCallChunks.length > 0) {
1431
+ if ((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) {
1369
1432
  acc.prevToolCallMessageId = acc.toolCallMessageId;
1370
- acc.toolCallMessageId = toolCallMessageId;
1371
- if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
1372
- acc.toolCallName = toolCallChunks[0].name;
1433
+ acc.toolCallMessageId = (_i = event.data.chunk.kwargs) == null ? void 0 : _i.id;
1434
+ if ((_j = event.data.chunk.kwargs.tool_call_chunks[0]) == null ? void 0 : _j.name) {
1435
+ acc.toolCallName = event.data.chunk.kwargs.tool_call_chunks[0].name;
1373
1436
  }
1374
- if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
1375
- acc.toolCallId = toolCallChunks[0].id;
1437
+ if ((_k = event.data.chunk.kwargs.tool_call_chunks[0]) == null ? void 0 : _k.id) {
1438
+ acc.toolCallId = event.data.chunk.kwargs.tool_call_chunks[0].id;
1376
1439
  }
1377
1440
  acc.prevMessageId = acc.messageId;
1378
- acc.messageId = toolCallMessageId;
1441
+ acc.messageId = (_n = (_m = (_l = event.data) == null ? void 0 : _l.chunk) == null ? void 0 : _m.kwargs) == null ? void 0 : _n.id;
1379
1442
  } else if (acc.content && acc.content != "") {
1380
1443
  acc.prevMessageId = acc.messageId;
1381
- acc.messageId = toolCallMessageId;
1444
+ acc.messageId = (_q = (_p = (_o = event.data) == null ? void 0 : _o.chunk) == null ? void 0 : _p.kwargs) == null ? void 0 : _q.id;
1382
1445
  } else {
1383
1446
  acc.prevToolCallMessageId = acc.toolCallMessageId;
1384
1447
  acc.prevMessageId = acc.messageId;
@@ -1403,7 +1466,7 @@ var RemoteLangGraphEventSource = class {
1403
1466
  prevMessageId: null,
1404
1467
  content: null
1405
1468
  }), (0, import_rxjs.mergeMap)((eventWithState) => {
1406
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1469
+ var _a, _b, _c, _d, _e;
1407
1470
  const events = [];
1408
1471
  let shouldEmitMessages = true;
1409
1472
  let shouldEmitToolCalls = false;
@@ -1486,8 +1549,7 @@ var RemoteLangGraphEventSource = class {
1486
1549
  });
1487
1550
  }
1488
1551
  }
1489
- const args = ((_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args) ?? // @ts-expect-error -- sdf
1490
- ((_i = (_h = (_g = (_f = eventWithState.event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.tool_call_chunks) == null ? void 0 : _h[0]) == null ? void 0 : _i.args);
1552
+ const args = (_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args;
1491
1553
  const content = eventWithState.content;
1492
1554
  if (args) {
1493
1555
  if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
@@ -1538,446 +1600,70 @@ var RemoteLangGraphEventSource = class {
1538
1600
  };
1539
1601
  __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
1540
1602
 
1541
- // src/lib/runtime/remote-lg-cloud-action.ts
1542
- var import_langgraph_sdk = require("@langchain/langgraph-sdk");
1543
- var import_node_crypto = require("crypto");
1544
- var import_partial_json = require("partial-json");
1545
-
1546
- // src/graphql/types/enums.ts
1547
- var import_type_graphql = require("type-graphql");
1548
- var MessageRole;
1549
- (function(MessageRole2) {
1550
- MessageRole2["user"] = "user";
1551
- MessageRole2["assistant"] = "assistant";
1552
- MessageRole2["system"] = "system";
1553
- })(MessageRole || (MessageRole = {}));
1554
- var ActionExecutionScope;
1555
- (function(ActionExecutionScope2) {
1556
- ActionExecutionScope2["server"] = "server";
1557
- ActionExecutionScope2["client"] = "client";
1558
- ActionExecutionScope2["passThrough"] = "passThrough";
1559
- })(ActionExecutionScope || (ActionExecutionScope = {}));
1560
- var CopilotRequestType;
1561
- (function(CopilotRequestType2) {
1562
- CopilotRequestType2["Chat"] = "Chat";
1563
- CopilotRequestType2["Task"] = "Task";
1564
- CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
1565
- CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
1566
- CopilotRequestType2["Suggestion"] = "Suggestion";
1567
- })(CopilotRequestType || (CopilotRequestType = {}));
1568
- (0, import_type_graphql.registerEnumType)(MessageRole, {
1569
- name: "MessageRole",
1570
- description: "The role of the message"
1571
- });
1572
- (0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
1573
- name: "ActionExecutionScope",
1574
- description: "The scope of the action"
1575
- });
1576
- (0, import_type_graphql.registerEnumType)(CopilotRequestType, {
1577
- name: "CopilotRequestType",
1578
- description: "The type of Copilot request"
1579
- });
1580
-
1581
- // src/lib/runtime/remote-lg-cloud-action.ts
1582
- async function execute(args) {
1583
- return new ReadableStream({
1584
- async start(controller) {
1585
- try {
1586
- await streamEvents(controller, args);
1587
- controller.close();
1588
- } catch (err) {
1589
- }
1590
- }
1591
- });
1592
- }
1593
- __name(execute, "execute");
1594
- async function streamEvents(controller, args) {
1595
- const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions } = args;
1596
- let nodeName = initialNodeName;
1597
- let state = initialState;
1598
- const { name, assistantId: initialAssistantId } = agent;
1599
- const client = new import_langgraph_sdk.Client({
1600
- apiUrl: deploymentUrl,
1601
- apiKey: langsmithApiKey
1602
- });
1603
- let initialThreadId = agrsInitialThreadId;
1604
- const wasInitiatedWithExistingThread = !!initialThreadId;
1605
- if (initialThreadId && initialThreadId.startsWith("ck-")) {
1606
- initialThreadId = initialThreadId.substring(3);
1607
- }
1608
- const assistants = await client.assistants.search();
1609
- const retrievedAssistant = assistants.find((a) => a.name === name);
1610
- const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
1611
- if (initialThreadId === threadId) {
1612
- await client.threads.get(threadId);
1613
- } else {
1614
- await client.threads.create({
1615
- threadId
1616
- });
1617
- }
1618
- let agentState = {
1619
- values: {}
1620
- };
1621
- if (wasInitiatedWithExistingThread) {
1622
- agentState = await client.threads.getState(threadId);
1623
- }
1624
- const agentStateValues = agentState.values;
1625
- state.messages = agentStateValues.messages;
1626
- const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
1627
- state = langGraphDefaultMergeState(state, formatMessages(messages), actions);
1628
- if (mode === "continue") {
1629
- await client.threads.updateState(threadId, {
1630
- values: state,
1631
- asNode: nodeName
1632
- });
1633
- }
1634
- const assistantId = initialAssistantId ?? retrievedAssistant.assistant_id;
1635
- const graphInfo = await client.assistants.getGraph(assistantId);
1636
- const streamInput = mode === "start" ? state : null;
1637
- let streamingStateExtractor = new StreamingStateExtractor([]);
1638
- let prevNodeName = null;
1639
- let emitIntermediateStateUntilEnd = null;
1640
- let shouldExit = null;
1641
- let externalRunId = null;
1642
- const streamResponse2 = client.runs.stream(threadId, assistantId, {
1643
- input: streamInput,
1644
- streamMode: [
1645
- "events",
1646
- "values"
1647
- ]
1648
- });
1649
- const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
1650
- let latestStateValues = {};
1651
- for await (const chunk of streamResponse2) {
1652
- if (![
1653
- "events",
1654
- "values"
1655
- ].includes(chunk.event))
1656
- continue;
1657
- if (chunk.event === "values") {
1658
- latestStateValues = chunk.data;
1659
- continue;
1660
- }
1661
- const event = chunk.data;
1662
- const currentNodeName = event.name;
1663
- const eventType = event.event;
1664
- const runId = event.metadata.run_id;
1665
- externalRunId = runId;
1666
- const metadata = event.metadata;
1667
- shouldExit = shouldExit != null ? shouldExit : metadata["copilotkit:exit"];
1668
- const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
1669
- const forceEmitIntermediateState = metadata["copilotkit:force-emit-intermediate-state"];
1670
- const manuallyEmitMessage = metadata["copilotkit:manually-emit-messages"];
1671
- const manuallyEmitToolCall = metadata["copilotkit:manually-emit-tool-calls"];
1672
- if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
1673
- nodeName = currentNodeName;
1674
- }
1675
- if (!nodeName) {
1676
- continue;
1677
- }
1678
- if (forceEmitIntermediateState) {
1679
- if (eventType === "on_chain_end") {
1680
- state = event.data.output;
1681
- emit(getStateSyncEvent({
1682
- threadId,
1683
- runId,
1684
- agentName: agent.name,
1685
- nodeName,
1686
- state: event.data.output,
1687
- running: true,
1688
- active: true
1689
- }));
1690
- }
1691
- continue;
1692
- }
1693
- if (manuallyEmitMessage) {
1694
- if (eventType === "on_chain_end") {
1695
- state = event.data.output;
1696
- emit(JSON.stringify({
1697
- event: "on_copilotkit_emit_message",
1698
- message: event.data.output,
1699
- messageId: (0, import_node_crypto.randomUUID)(),
1700
- role: MessageRole.assistant
1701
- }) + "\n");
1702
- }
1703
- continue;
1704
- }
1705
- if (manuallyEmitToolCall) {
1706
- if (eventType === "on_chain_end") {
1707
- state = event.data.output;
1708
- emit(JSON.stringify({
1709
- event: "on_copilotkit_emit_tool_call",
1710
- name: event.data.output.name,
1711
- args: event.data.output.args,
1712
- id: event.data.output.id
1713
- }) + "\n");
1714
- }
1715
- continue;
1716
- }
1717
- if (emitIntermediateState && emitIntermediateStateUntilEnd == null) {
1718
- emitIntermediateStateUntilEnd = nodeName;
1719
- }
1720
- if (emitIntermediateState && eventType === "on_chat_model_start") {
1721
- streamingStateExtractor = new StreamingStateExtractor(emitIntermediateState);
1722
- }
1723
- let updatedState = latestStateValues;
1724
- if (emitIntermediateState && eventType === "on_chat_model_stream") {
1725
- streamingStateExtractor.bufferToolCalls(event);
1726
- }
1727
- if (emitIntermediateStateUntilEnd !== null) {
1728
- updatedState = {
1729
- ...updatedState,
1730
- ...streamingStateExtractor.extractState()
1731
- };
1732
- }
1733
- if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === "on_chain_end") {
1734
- emitIntermediateStateUntilEnd = null;
1735
- }
1736
- const exitingNode = nodeName === currentNodeName && eventType === "on_chain_end";
1737
- if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
1738
- state = updatedState;
1739
- prevNodeName = nodeName;
1740
- emit(getStateSyncEvent({
1741
- threadId,
1742
- runId,
1743
- agentName: agent.name,
1744
- nodeName,
1745
- state,
1746
- running: true,
1747
- active: !exitingNode
1748
- }));
1749
- }
1750
- emit(JSON.stringify(event) + "\n");
1751
- }
1752
- state = await client.threads.getState(threadId);
1753
- const isEndNode = state.next.length === 0;
1754
- nodeName = Object.keys(state.metadata.writes)[0];
1755
- emit(getStateSyncEvent({
1756
- threadId,
1757
- runId: externalRunId,
1758
- agentName: agent.name,
1759
- nodeName: isEndNode ? "__end__" : nodeName,
1760
- state: state.values,
1761
- running: !shouldExit,
1762
- active: false
1763
- }));
1764
- return Promise.resolve();
1765
- }
1766
- __name(streamEvents, "streamEvents");
1767
- function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
1768
- const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
1769
- if (key !== "messages") {
1770
- acc[key] = state[key];
1771
- }
1772
- return acc;
1773
- }, {});
1774
- return JSON.stringify({
1775
- event: "on_copilotkit_state_sync",
1776
- thread_id: threadId,
1777
- run_id: runId,
1778
- agent_name: agentName,
1779
- node_name: nodeName,
1780
- active,
1781
- state: stateWithoutMessages,
1782
- running,
1783
- role: "assistant"
1784
- }) + "\n";
1785
- }
1786
- __name(getStateSyncEvent, "getStateSyncEvent");
1787
- var StreamingStateExtractor = /* @__PURE__ */ __name(class StreamingStateExtractor2 {
1788
- emitIntermediateState;
1789
- toolCallBuffer;
1790
- currentToolCall;
1791
- previouslyParsableState;
1792
- constructor(emitIntermediateState) {
1793
- this.emitIntermediateState = emitIntermediateState;
1794
- this.toolCallBuffer = {};
1795
- this.currentToolCall = null;
1796
- this.previouslyParsableState = {};
1797
- }
1798
- bufferToolCalls(event) {
1799
- if (event.data.chunk.tool_call_chunks.length > 0) {
1800
- const chunk = event.data.chunk.tool_call_chunks[0];
1801
- if (chunk.name !== null) {
1802
- this.currentToolCall = chunk.name;
1803
- this.toolCallBuffer[this.currentToolCall] = chunk.args;
1804
- } else if (this.currentToolCall !== null) {
1805
- this.toolCallBuffer[this.currentToolCall] += chunk.args;
1806
- }
1807
- }
1808
- }
1809
- getEmitStateConfig(currentToolName) {
1810
- for (const config2 of this.emitIntermediateState) {
1811
- const stateKey = config2["state_key"];
1812
- const tool = config2["tool"];
1813
- const toolArgument = config2["tool_argument"];
1814
- if (currentToolName === tool) {
1815
- return [
1816
- toolArgument,
1817
- stateKey
1818
- ];
1819
- }
1820
- }
1821
- return [
1822
- null,
1823
- null
1824
- ];
1825
- }
1826
- extractState() {
1827
- const state = {};
1828
- for (const [key, value] of Object.entries(this.toolCallBuffer)) {
1829
- const [argumentName, stateKey] = this.getEmitStateConfig(key);
1830
- if (stateKey === null) {
1831
- continue;
1832
- }
1833
- let parsedValue;
1834
- try {
1835
- parsedValue = (0, import_partial_json.parse)(value);
1836
- } catch (error) {
1837
- if (key in this.previouslyParsableState) {
1838
- parsedValue = this.previouslyParsableState[key];
1839
- } else {
1840
- continue;
1841
- }
1842
- }
1843
- this.previouslyParsableState[key] = parsedValue;
1844
- if (!argumentName) {
1845
- state[stateKey] = parsedValue;
1846
- } else {
1847
- state[stateKey] = parsedValue[argumentName];
1848
- }
1849
- }
1850
- return state;
1851
- }
1852
- }, "StreamingStateExtractor");
1853
- function langGraphDefaultMergeState(state, messages, actions) {
1854
- if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
1855
- messages = messages.slice(1);
1856
- }
1857
- const mergedMessages = state.messages || [];
1858
- const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
1859
- for (const message of messages) {
1860
- if (!existingMessageIds.has(message.id)) {
1861
- mergedMessages.push(message);
1862
- }
1603
+ // src/lib/runtime/remote-actions.ts
1604
+ function isLangGraphAgentAction(action) {
1605
+ if (!action) {
1606
+ return false;
1863
1607
  }
1864
- return deepMerge(state, {
1865
- messages: mergedMessages,
1866
- copilotkit: {
1867
- actions
1868
- }
1869
- });
1608
+ return typeof action.langGraphAgentHandler === "function";
1870
1609
  }
1871
- __name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
1872
- function deepMerge(obj1, obj2) {
1873
- let result = {
1874
- ...obj1
1610
+ __name(isLangGraphAgentAction, "isLangGraphAgentAction");
1611
+ function createHeaders(onBeforeRequest, graphqlContext) {
1612
+ const headers = {
1613
+ "Content-Type": "application/json"
1875
1614
  };
1876
- for (let key in obj2) {
1877
- if (typeof obj2[key] === "object" && !Array.isArray(obj2[key])) {
1878
- if (obj1[key]) {
1879
- result[key] = deepMerge(obj1[key], obj2[key]);
1880
- } else {
1881
- result[key] = {
1882
- ...obj2[key]
1883
- };
1884
- }
1885
- } else {
1886
- result[key] = obj2[key];
1615
+ if (onBeforeRequest) {
1616
+ const { headers: additionalHeaders } = onBeforeRequest({
1617
+ ctx: graphqlContext
1618
+ });
1619
+ if (additionalHeaders) {
1620
+ Object.assign(headers, additionalHeaders);
1887
1621
  }
1888
1622
  }
1889
- return result;
1623
+ return headers;
1890
1624
  }
1891
- __name(deepMerge, "deepMerge");
1892
- function formatMessages(messages) {
1893
- return messages.map((message) => {
1894
- if ("content" in message) {
1895
- return message;
1896
- }
1897
- if ("arguments" in message) {
1898
- const toolCall = {
1899
- name: message["name"],
1900
- args: message["arguments"],
1901
- id: message["id"]
1902
- };
1903
- return {
1904
- ...message,
1905
- content: "",
1906
- tool_calls: [
1907
- toolCall
1908
- ],
1909
- role: message["role"] ?? MessageRole.assistant
1910
- };
1911
- }
1912
- if ("actionExecutionId" in message) {
1625
+ __name(createHeaders, "createHeaders");
1626
+ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
1627
+ logger2.debug({
1628
+ url
1629
+ }, "Fetching actions from url");
1630
+ const headers = createHeaders(onBeforeRequest, graphqlContext);
1631
+ try {
1632
+ const response = await fetch(`${url}/info`, {
1633
+ method: "POST",
1634
+ headers,
1635
+ body: JSON.stringify({
1636
+ properties: graphqlContext.properties,
1637
+ frontendUrl
1638
+ })
1639
+ });
1640
+ if (!response.ok) {
1641
+ logger2.error({
1642
+ url,
1643
+ status: response.status,
1644
+ body: await response.text()
1645
+ }, "Failed to fetch actions from url");
1913
1646
  return {
1914
- ...message,
1915
- content: message["result"],
1916
- name: message["actionName"],
1917
- tool_call_id: message["actionExecutionId"],
1918
- role: message["role"] ?? MessageRole.user
1647
+ actions: [],
1648
+ agents: []
1919
1649
  };
1920
1650
  }
1921
- return message;
1922
- });
1923
- }
1924
- __name(formatMessages, "formatMessages");
1925
-
1926
- // src/lib/runtime/remote-action-constructors.ts
1927
- function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
1928
- const agents = endpoint.agents.map((agent) => ({
1929
- name: agent.name,
1930
- description: agent.description,
1931
- parameters: [],
1932
- handler: async (_args) => {
1933
- },
1934
- langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
1935
- var _a;
1936
- logger2.debug({
1937
- actionName: agent.name
1938
- }, "Executing LangGraph Cloud agent");
1939
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1940
- let state = {};
1941
- if (agentStates) {
1942
- const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
1943
- if (jsonState) {
1944
- state = JSON.parse(jsonState);
1945
- }
1946
- }
1947
- try {
1948
- const response = await execute({
1949
- deploymentUrl: endpoint.deploymentUrl,
1950
- langsmithApiKey: endpoint.langsmithApiKey,
1951
- agent,
1952
- threadId,
1953
- nodeName,
1954
- messages,
1955
- state,
1956
- properties: graphqlContext.properties,
1957
- actions: actionInputsWithoutAgents.map((action) => ({
1958
- name: action.name,
1959
- description: action.description,
1960
- parameters: JSON.parse(action.jsonSchema)
1961
- }))
1962
- });
1963
- const eventSource = new RemoteLangGraphEventSource();
1964
- streamResponse(response, eventSource.eventStream$);
1965
- return eventSource.processLangGraphEvents();
1966
- } catch (error) {
1967
- logger2.error({
1968
- url: endpoint.deploymentUrl,
1969
- status: 500,
1970
- body: error.message
1971
- }, "Failed to execute LangGraph Cloud agent");
1972
- throw new Error("Failed to execute LangGraph Cloud agent");
1973
- }
1974
- }
1975
- }));
1976
- return [
1977
- ...agents
1978
- ];
1651
+ const json = await response.json();
1652
+ logger2.debug({
1653
+ json
1654
+ }, "Fetched actions from url");
1655
+ return json;
1656
+ } catch (error) {
1657
+ logger2.error({
1658
+ error: error.message ? error.message : error + ""
1659
+ }, "Failed to fetch actions from url");
1660
+ return {
1661
+ actions: [],
1662
+ agents: []
1663
+ };
1664
+ }
1979
1665
  }
1980
- __name(constructLGCRemoteAction, "constructLGCRemoteAction");
1666
+ __name(fetchRemoteInfo, "fetchRemoteInfo");
1981
1667
  function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
1982
1668
  const actions = json["actions"].map((action) => ({
1983
1669
  name: action.name,
@@ -2069,7 +1755,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2069
1755
  throw new Error("Failed to execute remote agent");
2070
1756
  }
2071
1757
  const eventSource = new RemoteLangGraphEventSource();
2072
- streamResponse(response.body, eventSource.eventStream$);
1758
+ eventSource.streamResponse(response);
2073
1759
  return eventSource.processLangGraphEvents();
2074
1760
  }
2075
1761
  }));
@@ -2079,165 +1765,34 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2079
1765
  ];
2080
1766
  }
2081
1767
  __name(constructRemoteActions, "constructRemoteActions");
2082
- async function streamResponse(response, eventStream$) {
2083
- const reader = response.getReader();
2084
- const decoder = new TextDecoder();
2085
- let buffer = [];
2086
- function flushBuffer() {
2087
- const currentBuffer = buffer.join("");
2088
- if (currentBuffer.trim().length === 0) {
2089
- return;
2090
- }
2091
- const parts = currentBuffer.split("\n");
2092
- if (parts.length === 0) {
2093
- return;
2094
- }
2095
- const lastPartIsComplete = currentBuffer.endsWith("\n");
2096
- buffer = [];
2097
- if (!lastPartIsComplete) {
2098
- buffer.push(parts.pop());
2099
- }
2100
- parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
2101
- eventStream$.next(JSON.parse(part));
2102
- });
2103
- }
2104
- __name(flushBuffer, "flushBuffer");
2105
- try {
2106
- while (true) {
2107
- const { done, value } = await reader.read();
2108
- if (!done) {
2109
- buffer.push(decoder.decode(value, {
2110
- stream: true
2111
- }));
2112
- }
2113
- flushBuffer();
2114
- if (done) {
2115
- break;
2116
- }
2117
- }
2118
- } catch (error) {
2119
- console.error("Error in stream", error);
2120
- eventStream$.error(error);
2121
- return;
2122
- }
2123
- eventStream$.complete();
2124
- }
2125
- __name(streamResponse, "streamResponse");
2126
- function createHeaders(onBeforeRequest, graphqlContext) {
2127
- const headers = {
2128
- "Content-Type": "application/json"
2129
- };
2130
- if (onBeforeRequest) {
2131
- const { headers: additionalHeaders } = onBeforeRequest({
2132
- ctx: graphqlContext
2133
- });
2134
- if (additionalHeaders) {
2135
- Object.assign(headers, additionalHeaders);
2136
- }
2137
- }
2138
- return headers;
2139
- }
2140
- __name(createHeaders, "createHeaders");
2141
-
2142
- // src/lib/runtime/remote-actions.ts
2143
- var EndpointType;
2144
- (function(EndpointType2) {
2145
- EndpointType2["CopilotKit"] = "copilotKit";
2146
- EndpointType2["LangGraphCloud"] = "langgraph-cloud";
2147
- })(EndpointType || (EndpointType = {}));
2148
- function isLangGraphAgentAction(action) {
2149
- if (!action) {
2150
- return false;
2151
- }
2152
- return typeof action.langGraphAgentHandler === "function";
2153
- }
2154
- __name(isLangGraphAgentAction, "isLangGraphAgentAction");
2155
- async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
2156
- logger2.debug({
2157
- url
2158
- }, "Fetching actions from url");
2159
- const headers = createHeaders(onBeforeRequest, graphqlContext);
2160
- try {
2161
- const response = await fetch(`${url}/info`, {
2162
- method: "POST",
2163
- headers,
2164
- body: JSON.stringify({
2165
- properties: graphqlContext.properties,
2166
- frontendUrl
2167
- })
2168
- });
2169
- if (!response.ok) {
2170
- logger2.error({
2171
- url,
2172
- status: response.status,
2173
- body: await response.text()
2174
- }, "Failed to fetch actions from url");
2175
- return {
2176
- actions: [],
2177
- agents: []
2178
- };
2179
- }
2180
- const json = await response.json();
2181
- logger2.debug({
2182
- json
2183
- }, "Fetched actions from url");
2184
- return json;
2185
- } catch (error) {
2186
- logger2.error({
2187
- error: error.message ? error.message : error + ""
2188
- }, "Failed to fetch actions from url");
2189
- return {
2190
- actions: [],
2191
- agents: []
2192
- };
2193
- }
2194
- }
2195
- __name(fetchRemoteInfo, "fetchRemoteInfo");
2196
- async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
1768
+ async function setupRemoteActions({ remoteActionDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
2197
1769
  const logger2 = graphqlContext.logger.child({
2198
1770
  component: "remote-actions.fetchRemoteActions"
2199
1771
  });
2200
1772
  logger2.debug({
2201
- remoteEndpointDefinitions
2202
- }, "Fetching from remote endpoints");
2203
- const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
2204
- if (value.type === "langgraph-cloud") {
2205
- return value;
2206
- }
2207
- return index === self.findIndex((t) => t.url === value.url);
2208
- });
2209
- const result = await Promise.all(filtered.map(async (endpoint) => {
2210
- if (endpoint.type === "langgraph-cloud") {
2211
- return constructLGCRemoteAction({
2212
- endpoint,
2213
- messages,
2214
- graphqlContext,
2215
- logger: logger2.child({
2216
- component: "remote-actions.constructLGCRemoteAction",
2217
- endpoint
2218
- }),
2219
- agentStates
2220
- });
2221
- }
1773
+ remoteActionDefinitions
1774
+ }, "Fetching remote actions");
1775
+ const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
1776
+ const result = await Promise.all(filtered.map(async (actionDefinition) => {
2222
1777
  const json = await fetchRemoteInfo({
2223
- url: endpoint.url,
2224
- onBeforeRequest: endpoint.onBeforeRequest,
1778
+ url: actionDefinition.url,
1779
+ onBeforeRequest: actionDefinition.onBeforeRequest,
2225
1780
  graphqlContext,
2226
1781
  logger: logger2.child({
2227
1782
  component: "remote-actions.fetchActionsFromUrl",
2228
- endpoint
1783
+ actionDefinition
2229
1784
  }),
2230
1785
  frontendUrl
2231
1786
  });
2232
1787
  return constructRemoteActions({
2233
1788
  json,
2234
1789
  messages,
2235
- url: endpoint.url,
2236
- onBeforeRequest: endpoint.onBeforeRequest,
1790
+ url: actionDefinition.url,
1791
+ onBeforeRequest: actionDefinition.onBeforeRequest,
2237
1792
  graphqlContext,
2238
1793
  logger: logger2.child({
2239
1794
  component: "remote-actions.constructActions",
2240
- endpoint
1795
+ actionDefinition
2241
1796
  }),
2242
1797
  agentStates
2243
1798
  });
@@ -2401,7 +1956,13 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
2401
1956
  }
2402
1957
  let args = [];
2403
1958
  if (actionArguments) {
2404
- args = JSON.parse(actionArguments);
1959
+ try {
1960
+ args = JSON.parse(actionArguments);
1961
+ } catch (e) {
1962
+ console.warn("Action argument unparsable", {
1963
+ actionArguments
1964
+ });
1965
+ }
2405
1966
  }
2406
1967
  if (isLangGraphAgentAction(action)) {
2407
1968
  eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
@@ -2429,7 +1990,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
2429
1990
  __name(executeAction, "executeAction");
2430
1991
 
2431
1992
  // src/graphql/types/base/index.ts
2432
- var import_type_graphql2 = require("type-graphql");
1993
+ var import_type_graphql = require("type-graphql");
2433
1994
  function _ts_decorate(decorators, target, key, desc) {
2434
1995
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2435
1996
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2452,15 +2013,15 @@ var BaseMessageInput = class {
2452
2013
  };
2453
2014
  __name(BaseMessageInput, "BaseMessageInput");
2454
2015
  _ts_decorate([
2455
- (0, import_type_graphql2.Field)(() => String),
2016
+ (0, import_type_graphql.Field)(() => String),
2456
2017
  _ts_metadata("design:type", String)
2457
2018
  ], BaseMessageInput.prototype, "id", void 0);
2458
2019
  _ts_decorate([
2459
- (0, import_type_graphql2.Field)(() => Date),
2020
+ (0, import_type_graphql.Field)(() => Date),
2460
2021
  _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
2461
2022
  ], BaseMessageInput.prototype, "createdAt", void 0);
2462
2023
  BaseMessageInput = _ts_decorate([
2463
- (0, import_type_graphql2.InputType)()
2024
+ (0, import_type_graphql.InputType)()
2464
2025
  ], BaseMessageInput);
2465
2026
 
2466
2027
  // src/graphql/types/converted/index.ts
@@ -2564,7 +2125,7 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
2564
2125
  var import_rxjs3 = require("rxjs");
2565
2126
  var CopilotRuntime = class {
2566
2127
  actions;
2567
- remoteEndpointDefinitions;
2128
+ remoteActionDefinitions;
2568
2129
  langserve = [];
2569
2130
  onBeforeRequest;
2570
2131
  onAfterRequest;
@@ -2575,7 +2136,7 @@ var CopilotRuntime = class {
2575
2136
  const remoteChain = new RemoteChain(chain);
2576
2137
  this.langserve.push(remoteChain.toAction());
2577
2138
  }
2578
- this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
2139
+ this.remoteActionDefinitions = (params == null ? void 0 : params.remoteActions) || [];
2579
2140
  this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
2580
2141
  this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
2581
2142
  }
@@ -2644,7 +2205,7 @@ var CopilotRuntime = class {
2644
2205
  async processAgentRequest(request) {
2645
2206
  var _a;
2646
2207
  const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
2647
- const { threadId, agentName, nodeName } = agentSession;
2208
+ const { threadId = (0, import_shared9.randomId)(), agentName, nodeName } = agentSession;
2648
2209
  const serverSideActions = await this.getServerSideActions(request);
2649
2210
  const messages = convertGqlInputToMessages(rawMessages);
2650
2211
  const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
@@ -2716,12 +2277,8 @@ var CopilotRuntime = class {
2716
2277
  console.error("Error loading langserve chain:", error);
2717
2278
  }
2718
2279
  }
2719
- const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
2720
- ...endpoint,
2721
- type: this.resolveEndpointType(endpoint)
2722
- }));
2723
2280
  const remoteActions = await setupRemoteActions({
2724
- remoteEndpointDefinitions,
2281
+ remoteActionDefinitions: this.remoteActionDefinitions,
2725
2282
  graphqlContext,
2726
2283
  messages: inputMessages,
2727
2284
  agentStates,
@@ -2737,12 +2294,6 @@ var CopilotRuntime = class {
2737
2294
  ...remoteActions
2738
2295
  ];
2739
2296
  }
2740
- resolveEndpointType(endpoint) {
2741
- if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
2742
- return EndpointType.LangGraphCloud;
2743
- }
2744
- return endpoint.type;
2745
- }
2746
2297
  };
2747
2298
  __name(CopilotRuntime, "CopilotRuntime");
2748
2299
  function flattenToolCallsNoDuplicates(toolsByPriority) {
@@ -2757,20 +2308,6 @@ function flattenToolCallsNoDuplicates(toolsByPriority) {
2757
2308
  return allTools;
2758
2309
  }
2759
2310
  __name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
2760
- function copilotKitEndpoint(config2) {
2761
- return {
2762
- ...config2,
2763
- type: EndpointType.CopilotKit
2764
- };
2765
- }
2766
- __name(copilotKitEndpoint, "copilotKitEndpoint");
2767
- function langGraphCloudEndpoint(config2) {
2768
- return {
2769
- ...config2,
2770
- type: EndpointType.LangGraphCloud
2771
- };
2772
- }
2773
- __name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
2774
2311
 
2775
2312
  // src/lib/integrations/shared.ts
2776
2313
  var import_type_graphql16 = require("type-graphql");
@@ -2784,6 +2321,43 @@ var import_type_graphql11 = require("type-graphql");
2784
2321
 
2785
2322
  // src/graphql/inputs/message.input.ts
2786
2323
  var import_type_graphql3 = require("type-graphql");
2324
+
2325
+ // src/graphql/types/enums.ts
2326
+ var import_type_graphql2 = require("type-graphql");
2327
+ var MessageRole;
2328
+ (function(MessageRole2) {
2329
+ MessageRole2["user"] = "user";
2330
+ MessageRole2["assistant"] = "assistant";
2331
+ MessageRole2["system"] = "system";
2332
+ })(MessageRole || (MessageRole = {}));
2333
+ var ActionExecutionScope;
2334
+ (function(ActionExecutionScope2) {
2335
+ ActionExecutionScope2["server"] = "server";
2336
+ ActionExecutionScope2["client"] = "client";
2337
+ ActionExecutionScope2["passThrough"] = "passThrough";
2338
+ })(ActionExecutionScope || (ActionExecutionScope = {}));
2339
+ var CopilotRequestType;
2340
+ (function(CopilotRequestType2) {
2341
+ CopilotRequestType2["Chat"] = "Chat";
2342
+ CopilotRequestType2["Task"] = "Task";
2343
+ CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
2344
+ CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
2345
+ CopilotRequestType2["Suggestion"] = "Suggestion";
2346
+ })(CopilotRequestType || (CopilotRequestType = {}));
2347
+ (0, import_type_graphql2.registerEnumType)(MessageRole, {
2348
+ name: "MessageRole",
2349
+ description: "The role of the message"
2350
+ });
2351
+ (0, import_type_graphql2.registerEnumType)(ActionExecutionScope, {
2352
+ name: "ActionExecutionScope",
2353
+ description: "The scope of the action"
2354
+ });
2355
+ (0, import_type_graphql2.registerEnumType)(CopilotRequestType, {
2356
+ name: "CopilotRequestType",
2357
+ description: "The type of Copilot request"
2358
+ });
2359
+
2360
+ // src/graphql/inputs/message.input.ts
2787
2361
  function _ts_decorate2(decorators, target, key, desc) {
2788
2362
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2789
2363
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4445,7 +4019,6 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
4445
4019
  UnknownErrorResponse,
4446
4020
  buildSchema,
4447
4021
  config,
4448
- copilotKitEndpoint,
4449
4022
  copilotRuntimeNestEndpoint,
4450
4023
  copilotRuntimeNextJSAppRouterEndpoint,
4451
4024
  copilotRuntimeNextJSPagesRouterEndpoint,
@@ -4453,7 +4026,6 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
4453
4026
  copilotRuntimeNodeHttpEndpoint,
4454
4027
  createContext,
4455
4028
  flattenToolCallsNoDuplicates,
4456
- getCommonConfig,
4457
- langGraphCloudEndpoint
4029
+ getCommonConfig
4458
4030
  });
4459
4031
  //# sourceMappingURL=index.js.map