@copilotkit/runtime 1.6.0-next.9 → 1.7.0-next.0
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 +59 -0
- package/dist/{chunk-5ZBUMQE2.mjs → chunk-2BN7NZNC.mjs} +2 -2
- package/dist/{chunk-L7OTGCAG.mjs → chunk-34Y5DNNJ.mjs} +104 -74
- package/dist/chunk-34Y5DNNJ.mjs.map +1 -0
- package/dist/{chunk-7BCFHZLY.mjs → chunk-PH24IU7T.mjs} +2 -2
- package/dist/{chunk-4HQ5OZXN.mjs → chunk-ZYFN76KV.mjs} +2 -2
- package/dist/index.js +103 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/lib/index.js +103 -73
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/integrations/index.js +6 -3
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.js +6 -3
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +2 -2
- package/dist/lib/integrations/node-express/index.js +6 -3
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +2 -2
- package/dist/lib/integrations/node-http/index.js +6 -3
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +11 -4
- package/src/graphql/resolvers/copilot.resolver.ts +4 -0
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +45 -35
- package/src/lib/runtime/copilot-runtime.ts +23 -17
- package/src/lib/runtime/remote-action-constructors.ts +28 -68
- package/src/lib/runtime/remote-actions.ts +5 -5
- package/src/lib/streaming.ts +59 -0
- package/src/lib/telemetry-client.ts +3 -1
- package/src/service-adapters/events.ts +3 -3
- package/dist/chunk-L7OTGCAG.mjs.map +0 -1
- /package/dist/{chunk-5ZBUMQE2.mjs.map → chunk-2BN7NZNC.mjs.map} +0 -0
- /package/dist/{chunk-7BCFHZLY.mjs.map → chunk-PH24IU7T.mjs.map} +0 -0
- /package/dist/{chunk-4HQ5OZXN.mjs.map → chunk-ZYFN76KV.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
config,
|
|
4
4
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
5
5
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PH24IU7T.mjs";
|
|
7
7
|
import {
|
|
8
8
|
copilotRuntimeNestEndpoint
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2BN7NZNC.mjs";
|
|
10
10
|
import {
|
|
11
11
|
copilotRuntimeNodeExpressEndpoint
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZYFN76KV.mjs";
|
|
13
13
|
import {
|
|
14
14
|
CopilotRuntime,
|
|
15
15
|
addCustomHeaderPlugin,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
getCommonConfig,
|
|
22
22
|
langGraphPlatformEndpoint,
|
|
23
23
|
resolveEndpointType
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-34Y5DNNJ.mjs";
|
|
25
25
|
import {
|
|
26
26
|
AnthropicAdapter,
|
|
27
27
|
EmptyAdapter,
|
package/dist/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.
|
|
47
|
+
version: "1.7.0-next.0",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -1361,10 +1361,11 @@ var RemoteLangGraphEventSource = class {
|
|
|
1361
1361
|
let isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1362
1362
|
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1363
1363
|
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1364
|
-
|
|
1364
|
+
let previousRoundHadToolCall = acc.isToolCall;
|
|
1365
|
+
acc.isToolCall = toolCallCheck;
|
|
1366
|
+
if (previousRoundHadToolCall && !toolCallCheck) {
|
|
1365
1367
|
isToolCallEnd = true;
|
|
1366
1368
|
}
|
|
1367
|
-
acc.isToolCall = toolCallCheck;
|
|
1368
1369
|
acc.isToolCallEnd = isToolCallEnd;
|
|
1369
1370
|
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1370
1371
|
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
@@ -1385,7 +1386,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1385
1386
|
lastMessageId: null,
|
|
1386
1387
|
lastToolCallId: null,
|
|
1387
1388
|
lastToolCallName: null,
|
|
1388
|
-
currentContent: null
|
|
1389
|
+
currentContent: null,
|
|
1390
|
+
processedToolCallIds: /* @__PURE__ */ new Set()
|
|
1389
1391
|
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1390
1392
|
const events = [];
|
|
1391
1393
|
let shouldEmitMessages = true;
|
|
@@ -1413,7 +1415,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1413
1415
|
});
|
|
1414
1416
|
}
|
|
1415
1417
|
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1416
|
-
if (acc.isToolCallEnd && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1418
|
+
if (acc.isToolCallEnd && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName) && acc.lastToolCallId && !acc.processedToolCallIds.has(acc.lastToolCallId)) {
|
|
1419
|
+
acc.processedToolCallIds.add(acc.lastToolCallId);
|
|
1417
1420
|
events.push({
|
|
1418
1421
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1419
1422
|
actionExecutionId: acc.lastToolCallId
|
|
@@ -1480,6 +1483,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1480
1483
|
parentMessageId: acc.lastMessageId
|
|
1481
1484
|
});
|
|
1482
1485
|
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1486
|
+
acc.processedToolCallIds.clear();
|
|
1483
1487
|
events.push({
|
|
1484
1488
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1485
1489
|
messageId: acc.lastMessageId
|
|
@@ -2297,7 +2301,7 @@ async function streamEvents(controller, args) {
|
|
|
2297
2301
|
let emitIntermediateStateUntilEnd = null;
|
|
2298
2302
|
let shouldExit = false;
|
|
2299
2303
|
let externalRunId = null;
|
|
2300
|
-
const
|
|
2304
|
+
const streamResponse = client.runs.stream(threadId, assistantId, payload);
|
|
2301
2305
|
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
2302
2306
|
let latestStateValues = {};
|
|
2303
2307
|
let updatedState = state;
|
|
@@ -2307,7 +2311,7 @@ async function streamEvents(controller, args) {
|
|
|
2307
2311
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
2308
2312
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
2309
2313
|
});
|
|
2310
|
-
for await (const chunk of
|
|
2314
|
+
for await (const chunk of streamResponse) {
|
|
2311
2315
|
if (![
|
|
2312
2316
|
"events",
|
|
2313
2317
|
"values",
|
|
@@ -2722,6 +2726,54 @@ __name(getSchemaKeys, "getSchemaKeys");
|
|
|
2722
2726
|
|
|
2723
2727
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2724
2728
|
var import_shared11 = require("@copilotkit/shared");
|
|
2729
|
+
|
|
2730
|
+
// src/lib/streaming.ts
|
|
2731
|
+
async function writeJsonLineResponseToEventStream(response, eventStream$) {
|
|
2732
|
+
const reader = response.getReader();
|
|
2733
|
+
const decoder = new TextDecoder();
|
|
2734
|
+
let buffer = [];
|
|
2735
|
+
function flushBuffer() {
|
|
2736
|
+
const currentBuffer = buffer.join("");
|
|
2737
|
+
if (currentBuffer.trim().length === 0) {
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
const parts = currentBuffer.split("\n");
|
|
2741
|
+
if (parts.length === 0) {
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
2745
|
+
buffer = [];
|
|
2746
|
+
if (!lastPartIsComplete) {
|
|
2747
|
+
buffer.push(parts.pop());
|
|
2748
|
+
}
|
|
2749
|
+
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
2750
|
+
eventStream$.next(JSON.parse(part));
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
__name(flushBuffer, "flushBuffer");
|
|
2754
|
+
try {
|
|
2755
|
+
while (true) {
|
|
2756
|
+
const { done, value } = await reader.read();
|
|
2757
|
+
if (!done) {
|
|
2758
|
+
buffer.push(decoder.decode(value, {
|
|
2759
|
+
stream: true
|
|
2760
|
+
}));
|
|
2761
|
+
}
|
|
2762
|
+
flushBuffer();
|
|
2763
|
+
if (done) {
|
|
2764
|
+
break;
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
} catch (error) {
|
|
2768
|
+
console.error("Error in stream", error);
|
|
2769
|
+
eventStream$.error(error);
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2772
|
+
eventStream$.complete();
|
|
2773
|
+
}
|
|
2774
|
+
__name(writeJsonLineResponseToEventStream, "writeJsonLineResponseToEventStream");
|
|
2775
|
+
|
|
2776
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
2725
2777
|
var import_shared12 = require("@copilotkit/shared");
|
|
2726
2778
|
var import_shared13 = require("@copilotkit/shared");
|
|
2727
2779
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -2731,7 +2783,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2731
2783
|
parameters: [],
|
|
2732
2784
|
handler: async (_args) => {
|
|
2733
2785
|
},
|
|
2734
|
-
|
|
2786
|
+
remoteAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [], metaEvents }) => {
|
|
2735
2787
|
logger2.debug({
|
|
2736
2788
|
actionName: agent.name
|
|
2737
2789
|
}, "Executing LangGraph Platform agent");
|
|
@@ -2775,7 +2827,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2775
2827
|
metaEvents
|
|
2776
2828
|
});
|
|
2777
2829
|
const eventSource = new RemoteLangGraphEventSource();
|
|
2778
|
-
|
|
2830
|
+
writeJsonLineResponseToEventStream(response, eventSource.eventStream$);
|
|
2779
2831
|
return eventSource.processLangGraphEvents();
|
|
2780
2832
|
} catch (error) {
|
|
2781
2833
|
logger2.error({
|
|
@@ -2792,6 +2844,11 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2792
2844
|
];
|
|
2793
2845
|
}
|
|
2794
2846
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2847
|
+
var RemoteAgentType;
|
|
2848
|
+
(function(RemoteAgentType2) {
|
|
2849
|
+
RemoteAgentType2["LangGraph"] = "langgraph";
|
|
2850
|
+
RemoteAgentType2["CrewAI"] = "crewai";
|
|
2851
|
+
})(RemoteAgentType || (RemoteAgentType = {}));
|
|
2795
2852
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2796
2853
|
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2797
2854
|
const actions = json["actions"].map((action) => ({
|
|
@@ -2861,7 +2918,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2861
2918
|
parameters: [],
|
|
2862
2919
|
handler: async (_args) => {
|
|
2863
2920
|
},
|
|
2864
|
-
|
|
2921
|
+
remoteAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [], metaEvents }) => {
|
|
2865
2922
|
logger2.debug({
|
|
2866
2923
|
actionName: agent.name
|
|
2867
2924
|
}, "Executing remote agent");
|
|
@@ -2921,9 +2978,17 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2921
2978
|
isRemoteEndpoint: true
|
|
2922
2979
|
});
|
|
2923
2980
|
}
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2981
|
+
if (agent.type === "langgraph") {
|
|
2982
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
2983
|
+
writeJsonLineResponseToEventStream(response.body, eventSource.eventStream$);
|
|
2984
|
+
return eventSource.processLangGraphEvents();
|
|
2985
|
+
} else if (agent.type === "crewai") {
|
|
2986
|
+
const eventStream$ = new RuntimeEventSubject();
|
|
2987
|
+
writeJsonLineResponseToEventStream(response.body, eventStream$);
|
|
2988
|
+
return eventStream$;
|
|
2989
|
+
} else {
|
|
2990
|
+
throw new Error("Unsupported agent type");
|
|
2991
|
+
}
|
|
2927
2992
|
} catch (error) {
|
|
2928
2993
|
if (error instanceof import_shared11.CopilotKitError) {
|
|
2929
2994
|
throw error;
|
|
@@ -2941,50 +3006,6 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2941
3006
|
];
|
|
2942
3007
|
}
|
|
2943
3008
|
__name(constructRemoteActions, "constructRemoteActions");
|
|
2944
|
-
async function streamResponse(response, eventStream$) {
|
|
2945
|
-
const reader = response.getReader();
|
|
2946
|
-
const decoder = new TextDecoder();
|
|
2947
|
-
let buffer = [];
|
|
2948
|
-
function flushBuffer() {
|
|
2949
|
-
const currentBuffer = buffer.join("");
|
|
2950
|
-
if (currentBuffer.trim().length === 0) {
|
|
2951
|
-
return;
|
|
2952
|
-
}
|
|
2953
|
-
const parts = currentBuffer.split("\n");
|
|
2954
|
-
if (parts.length === 0) {
|
|
2955
|
-
return;
|
|
2956
|
-
}
|
|
2957
|
-
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
2958
|
-
buffer = [];
|
|
2959
|
-
if (!lastPartIsComplete) {
|
|
2960
|
-
buffer.push(parts.pop());
|
|
2961
|
-
}
|
|
2962
|
-
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
2963
|
-
eventStream$.next(JSON.parse(part));
|
|
2964
|
-
});
|
|
2965
|
-
}
|
|
2966
|
-
__name(flushBuffer, "flushBuffer");
|
|
2967
|
-
try {
|
|
2968
|
-
while (true) {
|
|
2969
|
-
const { done, value } = await reader.read();
|
|
2970
|
-
if (!done) {
|
|
2971
|
-
buffer.push(decoder.decode(value, {
|
|
2972
|
-
stream: true
|
|
2973
|
-
}));
|
|
2974
|
-
}
|
|
2975
|
-
flushBuffer();
|
|
2976
|
-
if (done) {
|
|
2977
|
-
break;
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
} catch (error) {
|
|
2981
|
-
console.error("Error in stream", error);
|
|
2982
|
-
eventStream$.error(error);
|
|
2983
|
-
return;
|
|
2984
|
-
}
|
|
2985
|
-
eventStream$.complete();
|
|
2986
|
-
}
|
|
2987
|
-
__name(streamResponse, "streamResponse");
|
|
2988
3009
|
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
2989
3010
|
const headers = {
|
|
2990
3011
|
"Content-Type": "application/json"
|
|
@@ -3008,13 +3029,13 @@ var EndpointType;
|
|
|
3008
3029
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
3009
3030
|
EndpointType2["LangGraphPlatform"] = "langgraph-platform";
|
|
3010
3031
|
})(EndpointType || (EndpointType = {}));
|
|
3011
|
-
function
|
|
3032
|
+
function isRemoteAgentAction(action) {
|
|
3012
3033
|
if (!action) {
|
|
3013
3034
|
return false;
|
|
3014
3035
|
}
|
|
3015
|
-
return typeof action.
|
|
3036
|
+
return typeof action.remoteAgentHandler === "function";
|
|
3016
3037
|
}
|
|
3017
|
-
__name(
|
|
3038
|
+
__name(isRemoteAgentAction, "isRemoteAgentAction");
|
|
3018
3039
|
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
|
|
3019
3040
|
logger2.debug({
|
|
3020
3041
|
url
|
|
@@ -3138,7 +3159,7 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
3138
3159
|
info = {
|
|
3139
3160
|
...info,
|
|
3140
3161
|
agentsAmount: ep.agents.length,
|
|
3141
|
-
hashedKey: (0, import_node_crypto3.createHash)("sha256").update(ep.langsmithApiKey).digest("hex")
|
|
3162
|
+
hashedKey: ep.langsmithApiKey ? (0, import_node_crypto3.createHash)("sha256").update(ep.langsmithApiKey).digest("hex") : null
|
|
3142
3163
|
};
|
|
3143
3164
|
}
|
|
3144
3165
|
return info;
|
|
@@ -3518,7 +3539,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
3518
3539
|
return;
|
|
3519
3540
|
}
|
|
3520
3541
|
}
|
|
3521
|
-
if (
|
|
3542
|
+
if (isRemoteAgentAction(action)) {
|
|
3522
3543
|
const result = `${action.name} agent started`;
|
|
3523
3544
|
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
3524
3545
|
id: actionExecutionId,
|
|
@@ -3539,7 +3560,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
3539
3560
|
actionName: action.name,
|
|
3540
3561
|
result
|
|
3541
3562
|
});
|
|
3542
|
-
const stream = await action.
|
|
3563
|
+
const stream = await action.remoteAgentHandler({
|
|
3543
3564
|
name: action.name,
|
|
3544
3565
|
threadId,
|
|
3545
3566
|
actionInputsWithoutAgents,
|
|
@@ -3653,7 +3674,12 @@ var CopilotRuntime = class {
|
|
|
3653
3674
|
delegateAgentProcessingToServiceAdapter;
|
|
3654
3675
|
constructor(params) {
|
|
3655
3676
|
var _a, _b;
|
|
3656
|
-
|
|
3677
|
+
if ((params == null ? void 0 : params.actions) && (params == null ? void 0 : params.remoteEndpoints)) {
|
|
3678
|
+
console.warn("Actions set in runtime instance will be ignored when remote endpoints are set");
|
|
3679
|
+
this.actions = [];
|
|
3680
|
+
} else {
|
|
3681
|
+
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
3682
|
+
}
|
|
3657
3683
|
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
3658
3684
|
const remoteChain = new RemoteChain(chain);
|
|
3659
3685
|
this.langserve.push(remoteChain.toAction());
|
|
@@ -3745,7 +3771,6 @@ please use an LLM adapter instead.`
|
|
|
3745
3771
|
}
|
|
3746
3772
|
}
|
|
3747
3773
|
async discoverAgentsFromEndpoints(graphqlContext) {
|
|
3748
|
-
const headers = createHeaders(null, graphqlContext);
|
|
3749
3774
|
const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
|
|
3750
3775
|
const agents2 = await acc;
|
|
3751
3776
|
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
@@ -3771,11 +3796,12 @@ please use an LLM adapter instead.`
|
|
|
3771
3796
|
...endpointAgents
|
|
3772
3797
|
];
|
|
3773
3798
|
}
|
|
3799
|
+
const cpkEndpoint = endpoint;
|
|
3774
3800
|
const fetchUrl = `${endpoint.url}/info`;
|
|
3775
3801
|
try {
|
|
3776
3802
|
const response = await fetch(fetchUrl, {
|
|
3777
3803
|
method: "POST",
|
|
3778
|
-
headers,
|
|
3804
|
+
headers: createHeaders(cpkEndpoint.onBeforeRequest, graphqlContext),
|
|
3779
3805
|
body: JSON.stringify({
|
|
3780
3806
|
properties: graphqlContext.properties
|
|
3781
3807
|
})
|
|
@@ -3856,11 +3882,12 @@ please use an LLM adapter instead.`
|
|
|
3856
3882
|
};
|
|
3857
3883
|
}
|
|
3858
3884
|
} else if (agentWithEndpoint.endpoint.type === EndpointType.CopilotKit || !("type" in agentWithEndpoint.endpoint)) {
|
|
3859
|
-
const
|
|
3885
|
+
const cpkEndpoint = agentWithEndpoint.endpoint;
|
|
3886
|
+
const fetchUrl = `${cpkEndpoint.url}/agents/state`;
|
|
3860
3887
|
try {
|
|
3861
3888
|
const response = await fetch(fetchUrl, {
|
|
3862
3889
|
method: "POST",
|
|
3863
|
-
headers,
|
|
3890
|
+
headers: createHeaders(cpkEndpoint.onBeforeRequest, graphqlContext),
|
|
3864
3891
|
body: JSON.stringify({
|
|
3865
3892
|
properties: graphqlContext.properties,
|
|
3866
3893
|
threadId,
|
|
@@ -3905,7 +3932,7 @@ please use an LLM adapter instead.`
|
|
|
3905
3932
|
const threadId = threadIdFromRequest ?? agentSession.threadId;
|
|
3906
3933
|
const serverSideActions = await this.getServerSideActions(request);
|
|
3907
3934
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
3908
|
-
const currentAgent = serverSideActions.find((action) => action.name === agentName &&
|
|
3935
|
+
const currentAgent = serverSideActions.find((action) => action.name === agentName && isRemoteAgentAction(action));
|
|
3909
3936
|
if (!currentAgent) {
|
|
3910
3937
|
throw new import_shared18.CopilotKitAgentDiscoveryError({
|
|
3911
3938
|
agentName
|
|
@@ -3913,8 +3940,8 @@ please use an LLM adapter instead.`
|
|
|
3913
3940
|
}
|
|
3914
3941
|
const availableActionsForCurrentAgent = serverSideActions.filter((action) => (
|
|
3915
3942
|
// Case 1: Keep all regular (non-agent) actions
|
|
3916
|
-
!
|
|
3917
|
-
|
|
3943
|
+
!isRemoteAgentAction(action) || // Case 2: For agent actions, keep all except self (prevent infinite loops)
|
|
3944
|
+
isRemoteAgentAction(action) && action.name !== agentName
|
|
3918
3945
|
)).map((action) => ({
|
|
3919
3946
|
name: action.name,
|
|
3920
3947
|
description: action.description,
|
|
@@ -3932,7 +3959,7 @@ please use an LLM adapter instead.`
|
|
|
3932
3959
|
}));
|
|
3933
3960
|
try {
|
|
3934
3961
|
const eventSource = new RuntimeEventSource();
|
|
3935
|
-
const stream = await currentAgent.
|
|
3962
|
+
const stream = await currentAgent.remoteAgentHandler({
|
|
3936
3963
|
name: agentName,
|
|
3937
3964
|
threadId,
|
|
3938
3965
|
nodeName,
|
|
@@ -4036,7 +4063,7 @@ function langGraphPlatformEndpoint(config2) {
|
|
|
4036
4063
|
__name(langGraphPlatformEndpoint, "langGraphPlatformEndpoint");
|
|
4037
4064
|
function resolveEndpointType(endpoint) {
|
|
4038
4065
|
if (!endpoint.type) {
|
|
4039
|
-
if ("
|
|
4066
|
+
if ("deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
4040
4067
|
return EndpointType.LangGraphPlatform;
|
|
4041
4068
|
} else {
|
|
4042
4069
|
return EndpointType.CopilotKit;
|
|
@@ -5025,6 +5052,9 @@ var CopilotResolver = class {
|
|
|
5025
5052
|
resolveOutputMessagesPromise = resolve;
|
|
5026
5053
|
rejectOutputMessagesPromise = reject;
|
|
5027
5054
|
});
|
|
5055
|
+
if (copilotCloudPublicApiKey) {
|
|
5056
|
+
ctx.properties["copilotCloudPublicApiKey"] = copilotCloudPublicApiKey;
|
|
5057
|
+
}
|
|
5028
5058
|
logger2.debug("Processing");
|
|
5029
5059
|
const { eventSource, threadId = (0, import_shared19.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5030
5060
|
serviceAdapter,
|