@copilotkit/runtime 1.3.16-mme-lgc-langgraph-package.10 → 1.3.16-mme-reset-chat.10
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 +45 -63
- package/dist/{chunk-JE2DM46O.mjs → chunk-2S6JGN2A.mjs} +4 -3
- package/dist/chunk-2S6JGN2A.mjs.map +1 -0
- package/dist/{chunk-SM3JAVXQ.mjs → chunk-3XICZ4K2.mjs} +5 -4
- package/dist/chunk-3XICZ4K2.mjs.map +1 -0
- package/dist/chunk-DFOKBSIS.mjs +1 -0
- package/dist/chunk-DFOKBSIS.mjs.map +1 -0
- package/dist/{chunk-PGK7SFLR.mjs → chunk-ODOSADGH.mjs} +376 -28
- package/dist/chunk-ODOSADGH.mjs.map +1 -0
- package/dist/{chunk-JCC4W3AU.mjs → chunk-TBNMKEWV.mjs} +4 -3
- package/dist/chunk-TBNMKEWV.mjs.map +1 -0
- package/dist/{chunk-BNQDVBQH.mjs → chunk-WHJ3DAYL.mjs} +251 -34
- package/dist/chunk-WHJ3DAYL.mjs.map +1 -0
- package/dist/{copilot-runtime-8d3f40c7.d.ts → copilot-runtime-b9715bd4.d.ts} +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +141 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -22
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +141 -45
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +21 -21
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +152 -85
- 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 +149 -82
- 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 +149 -82
- 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 +148 -81
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.js +31 -18
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -2
- package/package.json +4 -4
- package/src/agents/langgraph/events.ts +2 -0
- package/src/lib/integrations/nest/index.ts +5 -2
- package/src/lib/integrations/nextjs/app-router.ts +5 -2
- package/src/lib/integrations/nextjs/pages-router.ts +5 -2
- package/src/lib/integrations/node-express/index.ts +5 -2
- package/src/lib/integrations/node-http/index.ts +5 -2
- package/src/lib/runtime/copilot-runtime.ts +14 -15
- package/src/lib/runtime/remote-action-constructors.ts +17 -3
- package/src/lib/runtime/remote-lg-cloud-action.ts +25 -2
- package/src/lib/telemetry-client.ts +43 -0
- package/src/service-adapters/google/google-genai-adapter.ts +2 -2
- package/src/service-adapters/langchain/langchain-adapter.ts +22 -16
- package/src/service-adapters/openai/openai-adapter.ts +5 -0
- package/dist/chunk-BNQDVBQH.mjs.map +0 -1
- package/dist/chunk-H3C6UCKB.mjs +0 -288
- package/dist/chunk-H3C6UCKB.mjs.map +0 -1
- package/dist/chunk-JCC4W3AU.mjs.map +0 -1
- package/dist/chunk-JE2DM46O.mjs.map +0 -1
- package/dist/chunk-MXXPWWBF.mjs +0 -218
- package/dist/chunk-MXXPWWBF.mjs.map +0 -1
- package/dist/chunk-PGK7SFLR.mjs.map +0 -1
- package/dist/chunk-SM3JAVXQ.mjs.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
RemoteChain,
|
|
2
3
|
streamLangChainResponse
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WHJ3DAYL.mjs";
|
|
4
5
|
import {
|
|
5
6
|
GuardrailsValidationFailureResponse,
|
|
6
7
|
MessageStreamInterruptedResponse,
|
|
@@ -36,7 +37,7 @@ var require_package = __commonJS({
|
|
|
36
37
|
publishConfig: {
|
|
37
38
|
access: "public"
|
|
38
39
|
},
|
|
39
|
-
version: "1.3.16-mme-
|
|
40
|
+
version: "1.3.16-mme-reset-chat.10",
|
|
40
41
|
sideEffects: false,
|
|
41
42
|
main: "./dist/index.js",
|
|
42
43
|
module: "./dist/index.mjs",
|
|
@@ -1023,16 +1024,13 @@ CopilotResponse = _ts_decorate11([
|
|
|
1023
1024
|
import { Repeater } from "graphql-yoga";
|
|
1024
1025
|
|
|
1025
1026
|
// src/service-adapters/events.ts
|
|
1026
|
-
import { of, concat, map, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from } from "rxjs";
|
|
1027
|
+
import { of, concat, map, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
|
|
1027
1028
|
|
|
1028
1029
|
// src/lib/telemetry-client.ts
|
|
1029
1030
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
packageVersion: packageJson.version
|
|
1034
|
-
});
|
|
1035
|
-
var telemetry_client_default = telemetryClient;
|
|
1031
|
+
|
|
1032
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
1033
|
+
import { createHash as createHash2 } from "crypto";
|
|
1036
1034
|
|
|
1037
1035
|
// src/agents/langgraph/event-source.ts
|
|
1038
1036
|
import { ReplaySubject, scan, mergeMap, catchError } from "rxjs";
|
|
@@ -1049,6 +1047,8 @@ var LangGraphEventTypes;
|
|
|
1049
1047
|
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
1050
1048
|
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
1051
1049
|
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
1050
|
+
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
1051
|
+
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
1052
1052
|
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
1053
1053
|
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
1054
1054
|
var CustomEventNames;
|
|
@@ -1266,7 +1266,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1266
1266
|
|
|
1267
1267
|
// src/lib/runtime/remote-lg-cloud-action.ts
|
|
1268
1268
|
import { Client } from "@langchain/langgraph-sdk";
|
|
1269
|
-
import { randomUUID } from "crypto";
|
|
1269
|
+
import { createHash, randomUUID } from "crypto";
|
|
1270
1270
|
import { parse as parsePartialJson } from "partial-json";
|
|
1271
1271
|
async function execute(args) {
|
|
1272
1272
|
return new ReadableStream({
|
|
@@ -1281,6 +1281,7 @@ async function execute(args) {
|
|
|
1281
1281
|
}
|
|
1282
1282
|
__name(execute, "execute");
|
|
1283
1283
|
async function streamEvents(controller, args) {
|
|
1284
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1284
1285
|
const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions, logger: logger2 } = args;
|
|
1285
1286
|
let nodeName = initialNodeName;
|
|
1286
1287
|
let state = initialState;
|
|
@@ -1354,7 +1355,13 @@ async function streamEvents(controller, args) {
|
|
|
1354
1355
|
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
1355
1356
|
let latestStateValues = {};
|
|
1356
1357
|
let updatedState = state;
|
|
1358
|
+
let streamInfo = {
|
|
1359
|
+
hashedLgcKey: createHash("sha256").update(langsmithApiKey).digest("hex")
|
|
1360
|
+
};
|
|
1357
1361
|
try {
|
|
1362
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1363
|
+
hashedLgcKey: streamInfo.hashedLgcKey
|
|
1364
|
+
});
|
|
1358
1365
|
for await (const chunk of streamResponse2) {
|
|
1359
1366
|
if (![
|
|
1360
1367
|
"events",
|
|
@@ -1376,6 +1383,15 @@ async function streamEvents(controller, args) {
|
|
|
1376
1383
|
const runId = event.metadata.run_id;
|
|
1377
1384
|
externalRunId = runId;
|
|
1378
1385
|
const metadata = event.metadata;
|
|
1386
|
+
if (((_b = (_a = event.data) == null ? void 0 : _a.output) == null ? void 0 : _b.model) != null && ((_d = (_c = event.data) == null ? void 0 : _c.output) == null ? void 0 : _d.model) != "") {
|
|
1387
|
+
streamInfo.provider = (_f = (_e = event.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
|
|
1388
|
+
}
|
|
1389
|
+
if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
|
|
1390
|
+
streamInfo.langGraphHost = metadata.langgraph_host;
|
|
1391
|
+
}
|
|
1392
|
+
if (metadata.langgraph_version != null && metadata.langgraph_version != "") {
|
|
1393
|
+
streamInfo.langGraphVersion = metadata.langgraph_version;
|
|
1394
|
+
}
|
|
1379
1395
|
shouldExit = shouldExit || eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitExit;
|
|
1380
1396
|
const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
|
|
1381
1397
|
const manuallyEmitIntermediateState = eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState;
|
|
@@ -1438,6 +1454,7 @@ async function streamEvents(controller, args) {
|
|
|
1438
1454
|
state = await client.threads.getState(threadId);
|
|
1439
1455
|
const isEndNode = state.next.length === 0;
|
|
1440
1456
|
nodeName = Object.keys(state.metadata.writes)[0];
|
|
1457
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
|
|
1441
1458
|
emit(getStateSyncEvent({
|
|
1442
1459
|
threadId,
|
|
1443
1460
|
runId: externalRunId,
|
|
@@ -1685,7 +1702,12 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1685
1702
|
logger2.debug({
|
|
1686
1703
|
actionName: agent.name
|
|
1687
1704
|
}, "Executing LangGraph Cloud agent");
|
|
1688
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1705
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1706
|
+
agentExecution: true,
|
|
1707
|
+
type: "langgraph-cloud",
|
|
1708
|
+
agentsAmount: endpoint.agents.length,
|
|
1709
|
+
hashedLgcKey: createHash2("sha256").update(endpoint.langsmithApiKey).digest("hex")
|
|
1710
|
+
});
|
|
1689
1711
|
let state = {};
|
|
1690
1712
|
if (agentStates) {
|
|
1691
1713
|
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
@@ -1739,7 +1761,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1739
1761
|
args
|
|
1740
1762
|
}, "Executing remote action");
|
|
1741
1763
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1742
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1764
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1765
|
+
agentExecution: false,
|
|
1766
|
+
type: "self-hosted",
|
|
1767
|
+
agentsAmount: json["agents"].length
|
|
1768
|
+
});
|
|
1743
1769
|
try {
|
|
1744
1770
|
const response = await fetch(`${url}/actions/execute`, {
|
|
1745
1771
|
method: "POST",
|
|
@@ -1785,7 +1811,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1785
1811
|
actionName: agent.name
|
|
1786
1812
|
}, "Executing remote agent");
|
|
1787
1813
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1788
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1814
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1815
|
+
agentExecution: true,
|
|
1816
|
+
type: "self-hosted",
|
|
1817
|
+
agentsAmount: json["agents"].length
|
|
1818
|
+
});
|
|
1789
1819
|
let state = {};
|
|
1790
1820
|
if (agentStates) {
|
|
1791
1821
|
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
@@ -1996,6 +2026,322 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
|
|
|
1996
2026
|
}
|
|
1997
2027
|
__name(setupRemoteActions, "setupRemoteActions");
|
|
1998
2028
|
|
|
2029
|
+
// src/lib/telemetry-client.ts
|
|
2030
|
+
import { createHash as createHash3 } from "crypto";
|
|
2031
|
+
|
|
2032
|
+
// src/lib/runtime/copilot-runtime.ts
|
|
2033
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
2034
|
+
|
|
2035
|
+
// src/service-adapters/conversion.ts
|
|
2036
|
+
import { plainToInstance } from "class-transformer";
|
|
2037
|
+
function convertGqlInputToMessages(inputMessages) {
|
|
2038
|
+
const messages = [];
|
|
2039
|
+
for (const message of inputMessages) {
|
|
2040
|
+
if (message.textMessage) {
|
|
2041
|
+
messages.push(plainToInstance(TextMessage, {
|
|
2042
|
+
id: message.id,
|
|
2043
|
+
createdAt: message.createdAt,
|
|
2044
|
+
role: message.textMessage.role,
|
|
2045
|
+
content: message.textMessage.content
|
|
2046
|
+
}));
|
|
2047
|
+
} else if (message.actionExecutionMessage) {
|
|
2048
|
+
messages.push(plainToInstance(ActionExecutionMessage, {
|
|
2049
|
+
id: message.id,
|
|
2050
|
+
createdAt: message.createdAt,
|
|
2051
|
+
name: message.actionExecutionMessage.name,
|
|
2052
|
+
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2053
|
+
scope: message.actionExecutionMessage.scope
|
|
2054
|
+
}));
|
|
2055
|
+
} else if (message.resultMessage) {
|
|
2056
|
+
messages.push(plainToInstance(ResultMessage, {
|
|
2057
|
+
id: message.id,
|
|
2058
|
+
createdAt: message.createdAt,
|
|
2059
|
+
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
2060
|
+
actionName: message.resultMessage.actionName,
|
|
2061
|
+
result: message.resultMessage.result
|
|
2062
|
+
}));
|
|
2063
|
+
} else if (message.agentStateMessage) {
|
|
2064
|
+
messages.push(plainToInstance(AgentStateMessage, {
|
|
2065
|
+
id: message.id,
|
|
2066
|
+
threadId: message.agentStateMessage.threadId,
|
|
2067
|
+
createdAt: message.createdAt,
|
|
2068
|
+
agentName: message.agentStateMessage.agentName,
|
|
2069
|
+
nodeName: message.agentStateMessage.nodeName,
|
|
2070
|
+
runId: message.agentStateMessage.runId,
|
|
2071
|
+
active: message.agentStateMessage.active,
|
|
2072
|
+
role: message.agentStateMessage.role,
|
|
2073
|
+
state: JSON.parse(message.agentStateMessage.state),
|
|
2074
|
+
running: message.agentStateMessage.running
|
|
2075
|
+
}));
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return messages;
|
|
2079
|
+
}
|
|
2080
|
+
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
2081
|
+
|
|
2082
|
+
// src/lib/runtime/copilot-runtime.ts
|
|
2083
|
+
import { from } from "rxjs";
|
|
2084
|
+
var CopilotRuntime = class {
|
|
2085
|
+
actions;
|
|
2086
|
+
remoteEndpointDefinitions;
|
|
2087
|
+
langserve = [];
|
|
2088
|
+
onBeforeRequest;
|
|
2089
|
+
onAfterRequest;
|
|
2090
|
+
constructor(params) {
|
|
2091
|
+
var _a, _b;
|
|
2092
|
+
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
2093
|
+
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
2094
|
+
const remoteChain = new RemoteChain(chain);
|
|
2095
|
+
this.langserve.push(remoteChain.toAction());
|
|
2096
|
+
}
|
|
2097
|
+
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
|
|
2098
|
+
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
2099
|
+
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2100
|
+
}
|
|
2101
|
+
async processRuntimeRequest(request) {
|
|
2102
|
+
var _a;
|
|
2103
|
+
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, agentSession, url } = request;
|
|
2104
|
+
if (agentSession) {
|
|
2105
|
+
return this.processAgentRequest(request);
|
|
2106
|
+
}
|
|
2107
|
+
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2108
|
+
const inputMessages = convertGqlInputToMessages(messages);
|
|
2109
|
+
const serverSideActions = await this.getServerSideActions(request);
|
|
2110
|
+
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2111
|
+
name: action.name,
|
|
2112
|
+
description: action.description,
|
|
2113
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters))
|
|
2114
|
+
}));
|
|
2115
|
+
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2116
|
+
...serverSideActionsInput,
|
|
2117
|
+
...clientSideActionsInput
|
|
2118
|
+
]);
|
|
2119
|
+
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
2120
|
+
threadId,
|
|
2121
|
+
runId,
|
|
2122
|
+
inputMessages,
|
|
2123
|
+
properties: graphqlContext.properties,
|
|
2124
|
+
url
|
|
2125
|
+
}));
|
|
2126
|
+
try {
|
|
2127
|
+
const eventSource = new RuntimeEventSource();
|
|
2128
|
+
const result = await serviceAdapter.process({
|
|
2129
|
+
messages: inputMessages,
|
|
2130
|
+
actions: actionInputs,
|
|
2131
|
+
threadId,
|
|
2132
|
+
runId,
|
|
2133
|
+
eventSource,
|
|
2134
|
+
forwardedParameters
|
|
2135
|
+
});
|
|
2136
|
+
outputMessagesPromise.then((outputMessages) => {
|
|
2137
|
+
var _a2;
|
|
2138
|
+
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
2139
|
+
threadId: result.threadId,
|
|
2140
|
+
runId: result.runId,
|
|
2141
|
+
inputMessages,
|
|
2142
|
+
outputMessages,
|
|
2143
|
+
properties: graphqlContext.properties,
|
|
2144
|
+
url
|
|
2145
|
+
});
|
|
2146
|
+
}).catch((_error) => {
|
|
2147
|
+
});
|
|
2148
|
+
return {
|
|
2149
|
+
threadId: result.threadId,
|
|
2150
|
+
runId: result.runId,
|
|
2151
|
+
eventSource,
|
|
2152
|
+
serverSideActions,
|
|
2153
|
+
actionInputsWithoutAgents: actionInputs.filter((action) => (
|
|
2154
|
+
// TODO-AGENTS: do not exclude ALL server side actions
|
|
2155
|
+
!serverSideActions.find((serverSideAction) => serverSideAction.name == action.name)
|
|
2156
|
+
))
|
|
2157
|
+
};
|
|
2158
|
+
} catch (error) {
|
|
2159
|
+
console.error("Error getting response:", error);
|
|
2160
|
+
throw error;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
async processAgentRequest(request) {
|
|
2164
|
+
var _a;
|
|
2165
|
+
const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
|
|
2166
|
+
const { threadId, agentName, nodeName } = agentSession;
|
|
2167
|
+
const serverSideActions = await this.getServerSideActions(request);
|
|
2168
|
+
const messages = convertGqlInputToMessages(rawMessages);
|
|
2169
|
+
const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
2170
|
+
if (!agent) {
|
|
2171
|
+
throw new Error(`Agent ${agentName} not found`);
|
|
2172
|
+
}
|
|
2173
|
+
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2174
|
+
name: action.name,
|
|
2175
|
+
description: action.description,
|
|
2176
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters))
|
|
2177
|
+
}));
|
|
2178
|
+
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
2179
|
+
...serverSideActionsInput,
|
|
2180
|
+
...request.actions
|
|
2181
|
+
]);
|
|
2182
|
+
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
2183
|
+
threadId,
|
|
2184
|
+
runId: void 0,
|
|
2185
|
+
inputMessages: messages,
|
|
2186
|
+
properties: graphqlContext.properties
|
|
2187
|
+
}));
|
|
2188
|
+
try {
|
|
2189
|
+
const eventSource = new RuntimeEventSource();
|
|
2190
|
+
const stream = await agent.langGraphAgentHandler({
|
|
2191
|
+
name: agentName,
|
|
2192
|
+
threadId,
|
|
2193
|
+
nodeName,
|
|
2194
|
+
actionInputsWithoutAgents
|
|
2195
|
+
});
|
|
2196
|
+
eventSource.stream(async (eventStream$) => {
|
|
2197
|
+
from(stream).subscribe({
|
|
2198
|
+
next: (event) => eventStream$.next(event),
|
|
2199
|
+
error: (err) => console.error("Error in stream", err),
|
|
2200
|
+
complete: () => eventStream$.complete()
|
|
2201
|
+
});
|
|
2202
|
+
});
|
|
2203
|
+
outputMessagesPromise.then((outputMessages) => {
|
|
2204
|
+
var _a2;
|
|
2205
|
+
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
2206
|
+
threadId,
|
|
2207
|
+
runId: void 0,
|
|
2208
|
+
inputMessages: messages,
|
|
2209
|
+
outputMessages,
|
|
2210
|
+
properties: graphqlContext.properties
|
|
2211
|
+
});
|
|
2212
|
+
}).catch((_error) => {
|
|
2213
|
+
});
|
|
2214
|
+
return {
|
|
2215
|
+
threadId,
|
|
2216
|
+
runId: void 0,
|
|
2217
|
+
eventSource,
|
|
2218
|
+
serverSideActions: [],
|
|
2219
|
+
actionInputsWithoutAgents
|
|
2220
|
+
};
|
|
2221
|
+
} catch (error) {
|
|
2222
|
+
console.error("Error getting response:", error);
|
|
2223
|
+
throw error;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
async getServerSideActions(request) {
|
|
2227
|
+
const { messages: rawMessages, graphqlContext, agentStates, url } = request;
|
|
2228
|
+
const inputMessages = convertGqlInputToMessages(rawMessages);
|
|
2229
|
+
const langserveFunctions = [];
|
|
2230
|
+
for (const chainPromise of this.langserve) {
|
|
2231
|
+
try {
|
|
2232
|
+
const chain = await chainPromise;
|
|
2233
|
+
langserveFunctions.push(chain);
|
|
2234
|
+
} catch (error) {
|
|
2235
|
+
console.error("Error loading langserve chain:", error);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
|
|
2239
|
+
...endpoint,
|
|
2240
|
+
type: resolveEndpointType(endpoint)
|
|
2241
|
+
}));
|
|
2242
|
+
const remoteActions = await setupRemoteActions({
|
|
2243
|
+
remoteEndpointDefinitions,
|
|
2244
|
+
graphqlContext,
|
|
2245
|
+
messages: inputMessages,
|
|
2246
|
+
agentStates,
|
|
2247
|
+
frontendUrl: url
|
|
2248
|
+
});
|
|
2249
|
+
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
2250
|
+
properties: graphqlContext.properties,
|
|
2251
|
+
url
|
|
2252
|
+
}) : this.actions;
|
|
2253
|
+
return [
|
|
2254
|
+
...configuredActions,
|
|
2255
|
+
...langserveFunctions,
|
|
2256
|
+
...remoteActions
|
|
2257
|
+
];
|
|
2258
|
+
}
|
|
2259
|
+
};
|
|
2260
|
+
__name(CopilotRuntime, "CopilotRuntime");
|
|
2261
|
+
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
2262
|
+
let allTools = [];
|
|
2263
|
+
const allToolNames = [];
|
|
2264
|
+
for (const tool of toolsByPriority) {
|
|
2265
|
+
if (!allToolNames.includes(tool.name)) {
|
|
2266
|
+
allTools.push(tool);
|
|
2267
|
+
allToolNames.push(tool.name);
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
return allTools;
|
|
2271
|
+
}
|
|
2272
|
+
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
2273
|
+
function copilotKitEndpoint(config) {
|
|
2274
|
+
return {
|
|
2275
|
+
...config,
|
|
2276
|
+
type: EndpointType.CopilotKit
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2279
|
+
__name(copilotKitEndpoint, "copilotKitEndpoint");
|
|
2280
|
+
function langGraphCloudEndpoint(config) {
|
|
2281
|
+
return {
|
|
2282
|
+
...config,
|
|
2283
|
+
type: EndpointType.LangGraphCloud
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
__name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
|
|
2287
|
+
function resolveEndpointType(endpoint) {
|
|
2288
|
+
if (!endpoint.type) {
|
|
2289
|
+
if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
2290
|
+
return EndpointType.LangGraphCloud;
|
|
2291
|
+
} else {
|
|
2292
|
+
return EndpointType.CopilotKit;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
return endpoint.type;
|
|
2296
|
+
}
|
|
2297
|
+
__name(resolveEndpointType, "resolveEndpointType");
|
|
2298
|
+
|
|
2299
|
+
// src/lib/telemetry-client.ts
|
|
2300
|
+
var packageJson = require_package();
|
|
2301
|
+
var telemetryClient = new TelemetryClient({
|
|
2302
|
+
packageName: packageJson.name,
|
|
2303
|
+
packageVersion: packageJson.version
|
|
2304
|
+
});
|
|
2305
|
+
function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
2306
|
+
const endpointsInfo = runtime.remoteEndpointDefinitions.reduce((acc, endpoint) => {
|
|
2307
|
+
let info = {
|
|
2308
|
+
...acc
|
|
2309
|
+
};
|
|
2310
|
+
const endpointType = resolveEndpointType(endpoint);
|
|
2311
|
+
if (!info.endpointTypes.includes(endpointType)) {
|
|
2312
|
+
info = {
|
|
2313
|
+
...info,
|
|
2314
|
+
endpointTypes: [
|
|
2315
|
+
...info.endpointTypes,
|
|
2316
|
+
endpointType
|
|
2317
|
+
]
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
if (endpointType === EndpointType.LangGraphCloud) {
|
|
2321
|
+
const ep = endpoint;
|
|
2322
|
+
info = {
|
|
2323
|
+
...info,
|
|
2324
|
+
agentsAmount: ep.agents.length,
|
|
2325
|
+
hashedKey: createHash3("sha256").update(ep.langsmithApiKey).digest("hex")
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
return info;
|
|
2329
|
+
}, {
|
|
2330
|
+
endpointTypes: [],
|
|
2331
|
+
agentsAmount: null,
|
|
2332
|
+
hashedKey: null
|
|
2333
|
+
});
|
|
2334
|
+
return {
|
|
2335
|
+
actionsAmount: runtime.actions.length,
|
|
2336
|
+
endpointsAmount: runtime.remoteEndpointDefinitions.length,
|
|
2337
|
+
endpointTypes: endpointsInfo.endpointTypes,
|
|
2338
|
+
agentsAmount: endpointsInfo.agentsAmount,
|
|
2339
|
+
hashedLgcKey: endpointsInfo.hashedKey
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2343
|
+
var telemetry_client_default = telemetryClient;
|
|
2344
|
+
|
|
1999
2345
|
// src/service-adapters/events.ts
|
|
2000
2346
|
var RuntimeEventTypes;
|
|
2001
2347
|
(function(RuntimeEventTypes2) {
|
|
@@ -2165,7 +2511,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2165
2511
|
name: action.name,
|
|
2166
2512
|
actionInputsWithoutAgents
|
|
2167
2513
|
});
|
|
2168
|
-
|
|
2514
|
+
from2(stream).subscribe({
|
|
2169
2515
|
next: (event) => eventStream$.next(event),
|
|
2170
2516
|
error: (err) => console.error("Error in stream", err),
|
|
2171
2517
|
complete: () => eventStream$.complete()
|
|
@@ -2186,7 +2532,7 @@ __name(executeAction, "executeAction");
|
|
|
2186
2532
|
|
|
2187
2533
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2188
2534
|
import { GraphQLJSONObject } from "graphql-scalars";
|
|
2189
|
-
import { plainToInstance } from "class-transformer";
|
|
2535
|
+
import { plainToInstance as plainToInstance2 } from "class-transformer";
|
|
2190
2536
|
import { GraphQLError } from "graphql";
|
|
2191
2537
|
import { randomId as randomId2 } from "@copilotkit/shared";
|
|
2192
2538
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
@@ -2349,7 +2695,7 @@ var CopilotResolver = class {
|
|
|
2349
2695
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2350
2696
|
});
|
|
2351
2697
|
outputMessages = [
|
|
2352
|
-
|
|
2698
|
+
plainToInstance2(TextMessage, {
|
|
2353
2699
|
id: randomId2(),
|
|
2354
2700
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2355
2701
|
content: result.reason,
|
|
@@ -2416,7 +2762,7 @@ var CopilotResolver = class {
|
|
|
2416
2762
|
reason,
|
|
2417
2763
|
messageId: messageId2
|
|
2418
2764
|
}, "Text streaming interrupted");
|
|
2419
|
-
streamingTextStatus.next(
|
|
2765
|
+
streamingTextStatus.next(plainToInstance2(FailedMessageStatus, {
|
|
2420
2766
|
reason
|
|
2421
2767
|
}));
|
|
2422
2768
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -2449,7 +2795,7 @@ var CopilotResolver = class {
|
|
|
2449
2795
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2450
2796
|
stopStreamingText();
|
|
2451
2797
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2452
|
-
outputMessages.push(
|
|
2798
|
+
outputMessages.push(plainToInstance2(TextMessage, {
|
|
2453
2799
|
id: messageId,
|
|
2454
2800
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2455
2801
|
content: textChunks.join(""),
|
|
@@ -2485,7 +2831,7 @@ var CopilotResolver = class {
|
|
|
2485
2831
|
logger2.error({
|
|
2486
2832
|
err
|
|
2487
2833
|
}, "Error in action execution argument stream");
|
|
2488
|
-
streamingArgumentsStatus.next(
|
|
2834
|
+
streamingArgumentsStatus.next(plainToInstance2(FailedMessageStatus, {
|
|
2489
2835
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
2490
2836
|
}));
|
|
2491
2837
|
stopStreamingArguments();
|
|
@@ -2496,7 +2842,7 @@ var CopilotResolver = class {
|
|
|
2496
2842
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2497
2843
|
stopStreamingArguments();
|
|
2498
2844
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
2499
|
-
outputMessages.push(
|
|
2845
|
+
outputMessages.push(plainToInstance2(ActionExecutionMessage, {
|
|
2500
2846
|
id: event.actionExecutionId,
|
|
2501
2847
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2502
2848
|
name: event.actionName,
|
|
@@ -2520,7 +2866,7 @@ var CopilotResolver = class {
|
|
|
2520
2866
|
actionName: event.actionName,
|
|
2521
2867
|
result: event.result
|
|
2522
2868
|
});
|
|
2523
|
-
outputMessages.push(
|
|
2869
|
+
outputMessages.push(plainToInstance2(ResultMessage, {
|
|
2524
2870
|
id: randomId2(),
|
|
2525
2871
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2526
2872
|
actionExecutionId: event.actionExecutionId,
|
|
@@ -2545,7 +2891,7 @@ var CopilotResolver = class {
|
|
|
2545
2891
|
role: MessageRole.assistant,
|
|
2546
2892
|
createdAt: /* @__PURE__ */ new Date()
|
|
2547
2893
|
});
|
|
2548
|
-
outputMessages.push(
|
|
2894
|
+
outputMessages.push(plainToInstance2(AgentStateMessage, {
|
|
2549
2895
|
id: randomId2(),
|
|
2550
2896
|
threadId: event.threadId,
|
|
2551
2897
|
agentName: event.agentName,
|
|
@@ -2733,7 +3079,7 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
2733
3079
|
_copilotkit: options.properties._copilotkit
|
|
2734
3080
|
});
|
|
2735
3081
|
}
|
|
2736
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
3082
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
2737
3083
|
const logger2 = commonConfig.logging;
|
|
2738
3084
|
logger2.debug("Creating Node HTTP endpoint");
|
|
2739
3085
|
const yoga = createYoga({
|
|
@@ -2745,14 +3091,16 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
2745
3091
|
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
2746
3092
|
|
|
2747
3093
|
export {
|
|
3094
|
+
getRuntimeInstanceTelemetryInfo,
|
|
2748
3095
|
telemetry_client_default,
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
3096
|
+
CopilotRuntime,
|
|
3097
|
+
flattenToolCallsNoDuplicates,
|
|
3098
|
+
copilotKitEndpoint,
|
|
3099
|
+
langGraphCloudEndpoint,
|
|
3100
|
+
resolveEndpointType,
|
|
2753
3101
|
createContext,
|
|
2754
3102
|
buildSchema,
|
|
2755
3103
|
getCommonConfig,
|
|
2756
3104
|
copilotRuntimeNodeHttpEndpoint
|
|
2757
3105
|
};
|
|
2758
|
-
//# sourceMappingURL=chunk-
|
|
3106
|
+
//# sourceMappingURL=chunk-ODOSADGH.mjs.map
|