@copilotkit/runtime 1.6.0 → 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 +21 -0
- package/dist/{chunk-MPI4JZZR.mjs → chunk-2BN7NZNC.mjs} +2 -2
- package/dist/{chunk-DUW72ZZB.mjs → chunk-34Y5DNNJ.mjs} +88 -67
- package/dist/chunk-34Y5DNNJ.mjs.map +1 -0
- package/dist/{chunk-WUMAYJP3.mjs → chunk-PH24IU7T.mjs} +2 -2
- package/dist/{chunk-2RP2NR4F.mjs → chunk-ZYFN76KV.mjs} +2 -2
- package/dist/index.js +87 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/lib/index.js +87 -66
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/integrations/index.js +4 -1
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.js +4 -1
- 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 +4 -1
- 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 +4 -1
- 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/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 +14 -14
- 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/service-adapters/events.ts +3 -3
- package/dist/chunk-DUW72ZZB.mjs.map +0 -1
- /package/dist/{chunk-MPI4JZZR.mjs.map → chunk-2BN7NZNC.mjs.map} +0 -0
- /package/dist/{chunk-WUMAYJP3.mjs.map → chunk-PH24IU7T.mjs.map} +0 -0
- /package/dist/{chunk-2RP2NR4F.mjs.map → chunk-ZYFN76KV.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-34Y5DNNJ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -77,4 +77,4 @@ export {
|
|
|
77
77
|
config,
|
|
78
78
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-PH24IU7T.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-34Y5DNNJ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNodeExpressEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-ZYFN76KV.mjs.map
|
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.
|
|
47
|
+
version: "1.7.0-next.0",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -2637,7 +2637,7 @@ async function streamEvents(controller, args) {
|
|
|
2637
2637
|
let emitIntermediateStateUntilEnd = null;
|
|
2638
2638
|
let shouldExit = false;
|
|
2639
2639
|
let externalRunId = null;
|
|
2640
|
-
const
|
|
2640
|
+
const streamResponse = client.runs.stream(threadId, assistantId, payload);
|
|
2641
2641
|
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
2642
2642
|
let latestStateValues = {};
|
|
2643
2643
|
let updatedState = state;
|
|
@@ -2647,7 +2647,7 @@ async function streamEvents(controller, args) {
|
|
|
2647
2647
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
2648
2648
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
2649
2649
|
});
|
|
2650
|
-
for await (const chunk of
|
|
2650
|
+
for await (const chunk of streamResponse) {
|
|
2651
2651
|
if (![
|
|
2652
2652
|
"events",
|
|
2653
2653
|
"values",
|
|
@@ -3062,6 +3062,54 @@ __name(getSchemaKeys, "getSchemaKeys");
|
|
|
3062
3062
|
|
|
3063
3063
|
// src/lib/runtime/remote-action-constructors.ts
|
|
3064
3064
|
var import_shared13 = require("@copilotkit/shared");
|
|
3065
|
+
|
|
3066
|
+
// src/lib/streaming.ts
|
|
3067
|
+
async function writeJsonLineResponseToEventStream(response, eventStream$) {
|
|
3068
|
+
const reader = response.getReader();
|
|
3069
|
+
const decoder = new TextDecoder();
|
|
3070
|
+
let buffer = [];
|
|
3071
|
+
function flushBuffer() {
|
|
3072
|
+
const currentBuffer = buffer.join("");
|
|
3073
|
+
if (currentBuffer.trim().length === 0) {
|
|
3074
|
+
return;
|
|
3075
|
+
}
|
|
3076
|
+
const parts = currentBuffer.split("\n");
|
|
3077
|
+
if (parts.length === 0) {
|
|
3078
|
+
return;
|
|
3079
|
+
}
|
|
3080
|
+
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
3081
|
+
buffer = [];
|
|
3082
|
+
if (!lastPartIsComplete) {
|
|
3083
|
+
buffer.push(parts.pop());
|
|
3084
|
+
}
|
|
3085
|
+
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
3086
|
+
eventStream$.next(JSON.parse(part));
|
|
3087
|
+
});
|
|
3088
|
+
}
|
|
3089
|
+
__name(flushBuffer, "flushBuffer");
|
|
3090
|
+
try {
|
|
3091
|
+
while (true) {
|
|
3092
|
+
const { done, value } = await reader.read();
|
|
3093
|
+
if (!done) {
|
|
3094
|
+
buffer.push(decoder.decode(value, {
|
|
3095
|
+
stream: true
|
|
3096
|
+
}));
|
|
3097
|
+
}
|
|
3098
|
+
flushBuffer();
|
|
3099
|
+
if (done) {
|
|
3100
|
+
break;
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
} catch (error) {
|
|
3104
|
+
console.error("Error in stream", error);
|
|
3105
|
+
eventStream$.error(error);
|
|
3106
|
+
return;
|
|
3107
|
+
}
|
|
3108
|
+
eventStream$.complete();
|
|
3109
|
+
}
|
|
3110
|
+
__name(writeJsonLineResponseToEventStream, "writeJsonLineResponseToEventStream");
|
|
3111
|
+
|
|
3112
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
3065
3113
|
var import_shared14 = require("@copilotkit/shared");
|
|
3066
3114
|
var import_shared15 = require("@copilotkit/shared");
|
|
3067
3115
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -3071,7 +3119,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3071
3119
|
parameters: [],
|
|
3072
3120
|
handler: async (_args) => {
|
|
3073
3121
|
},
|
|
3074
|
-
|
|
3122
|
+
remoteAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [], metaEvents }) => {
|
|
3075
3123
|
logger2.debug({
|
|
3076
3124
|
actionName: agent.name
|
|
3077
3125
|
}, "Executing LangGraph Platform agent");
|
|
@@ -3115,7 +3163,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3115
3163
|
metaEvents
|
|
3116
3164
|
});
|
|
3117
3165
|
const eventSource = new RemoteLangGraphEventSource();
|
|
3118
|
-
|
|
3166
|
+
writeJsonLineResponseToEventStream(response, eventSource.eventStream$);
|
|
3119
3167
|
return eventSource.processLangGraphEvents();
|
|
3120
3168
|
} catch (error) {
|
|
3121
3169
|
logger2.error({
|
|
@@ -3132,6 +3180,11 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3132
3180
|
];
|
|
3133
3181
|
}
|
|
3134
3182
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
3183
|
+
var RemoteAgentType;
|
|
3184
|
+
(function(RemoteAgentType2) {
|
|
3185
|
+
RemoteAgentType2["LangGraph"] = "langgraph";
|
|
3186
|
+
RemoteAgentType2["CrewAI"] = "crewai";
|
|
3187
|
+
})(RemoteAgentType || (RemoteAgentType = {}));
|
|
3135
3188
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
3136
3189
|
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
3137
3190
|
const actions = json["actions"].map((action) => ({
|
|
@@ -3201,7 +3254,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3201
3254
|
parameters: [],
|
|
3202
3255
|
handler: async (_args) => {
|
|
3203
3256
|
},
|
|
3204
|
-
|
|
3257
|
+
remoteAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [], metaEvents }) => {
|
|
3205
3258
|
logger2.debug({
|
|
3206
3259
|
actionName: agent.name
|
|
3207
3260
|
}, "Executing remote agent");
|
|
@@ -3261,9 +3314,17 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3261
3314
|
isRemoteEndpoint: true
|
|
3262
3315
|
});
|
|
3263
3316
|
}
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3317
|
+
if (agent.type === "langgraph") {
|
|
3318
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
3319
|
+
writeJsonLineResponseToEventStream(response.body, eventSource.eventStream$);
|
|
3320
|
+
return eventSource.processLangGraphEvents();
|
|
3321
|
+
} else if (agent.type === "crewai") {
|
|
3322
|
+
const eventStream$ = new RuntimeEventSubject();
|
|
3323
|
+
writeJsonLineResponseToEventStream(response.body, eventStream$);
|
|
3324
|
+
return eventStream$;
|
|
3325
|
+
} else {
|
|
3326
|
+
throw new Error("Unsupported agent type");
|
|
3327
|
+
}
|
|
3267
3328
|
} catch (error) {
|
|
3268
3329
|
if (error instanceof import_shared13.CopilotKitError) {
|
|
3269
3330
|
throw error;
|
|
@@ -3281,50 +3342,6 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3281
3342
|
];
|
|
3282
3343
|
}
|
|
3283
3344
|
__name(constructRemoteActions, "constructRemoteActions");
|
|
3284
|
-
async function streamResponse(response, eventStream$) {
|
|
3285
|
-
const reader = response.getReader();
|
|
3286
|
-
const decoder = new TextDecoder();
|
|
3287
|
-
let buffer = [];
|
|
3288
|
-
function flushBuffer() {
|
|
3289
|
-
const currentBuffer = buffer.join("");
|
|
3290
|
-
if (currentBuffer.trim().length === 0) {
|
|
3291
|
-
return;
|
|
3292
|
-
}
|
|
3293
|
-
const parts = currentBuffer.split("\n");
|
|
3294
|
-
if (parts.length === 0) {
|
|
3295
|
-
return;
|
|
3296
|
-
}
|
|
3297
|
-
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
3298
|
-
buffer = [];
|
|
3299
|
-
if (!lastPartIsComplete) {
|
|
3300
|
-
buffer.push(parts.pop());
|
|
3301
|
-
}
|
|
3302
|
-
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
3303
|
-
eventStream$.next(JSON.parse(part));
|
|
3304
|
-
});
|
|
3305
|
-
}
|
|
3306
|
-
__name(flushBuffer, "flushBuffer");
|
|
3307
|
-
try {
|
|
3308
|
-
while (true) {
|
|
3309
|
-
const { done, value } = await reader.read();
|
|
3310
|
-
if (!done) {
|
|
3311
|
-
buffer.push(decoder.decode(value, {
|
|
3312
|
-
stream: true
|
|
3313
|
-
}));
|
|
3314
|
-
}
|
|
3315
|
-
flushBuffer();
|
|
3316
|
-
if (done) {
|
|
3317
|
-
break;
|
|
3318
|
-
}
|
|
3319
|
-
}
|
|
3320
|
-
} catch (error) {
|
|
3321
|
-
console.error("Error in stream", error);
|
|
3322
|
-
eventStream$.error(error);
|
|
3323
|
-
return;
|
|
3324
|
-
}
|
|
3325
|
-
eventStream$.complete();
|
|
3326
|
-
}
|
|
3327
|
-
__name(streamResponse, "streamResponse");
|
|
3328
3345
|
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
3329
3346
|
const headers = {
|
|
3330
3347
|
"Content-Type": "application/json"
|
|
@@ -3348,13 +3365,13 @@ var EndpointType;
|
|
|
3348
3365
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
3349
3366
|
EndpointType2["LangGraphPlatform"] = "langgraph-platform";
|
|
3350
3367
|
})(EndpointType || (EndpointType = {}));
|
|
3351
|
-
function
|
|
3368
|
+
function isRemoteAgentAction(action) {
|
|
3352
3369
|
if (!action) {
|
|
3353
3370
|
return false;
|
|
3354
3371
|
}
|
|
3355
|
-
return typeof action.
|
|
3372
|
+
return typeof action.remoteAgentHandler === "function";
|
|
3356
3373
|
}
|
|
3357
|
-
__name(
|
|
3374
|
+
__name(isRemoteAgentAction, "isRemoteAgentAction");
|
|
3358
3375
|
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
|
|
3359
3376
|
logger2.debug({
|
|
3360
3377
|
url
|
|
@@ -3858,7 +3875,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
3858
3875
|
return;
|
|
3859
3876
|
}
|
|
3860
3877
|
}
|
|
3861
|
-
if (
|
|
3878
|
+
if (isRemoteAgentAction(action)) {
|
|
3862
3879
|
const result = `${action.name} agent started`;
|
|
3863
3880
|
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
3864
3881
|
id: actionExecutionId,
|
|
@@ -3879,7 +3896,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
3879
3896
|
actionName: action.name,
|
|
3880
3897
|
result
|
|
3881
3898
|
});
|
|
3882
|
-
const stream = await action.
|
|
3899
|
+
const stream = await action.remoteAgentHandler({
|
|
3883
3900
|
name: action.name,
|
|
3884
3901
|
threadId,
|
|
3885
3902
|
actionInputsWithoutAgents,
|
|
@@ -4090,7 +4107,6 @@ please use an LLM adapter instead.`
|
|
|
4090
4107
|
}
|
|
4091
4108
|
}
|
|
4092
4109
|
async discoverAgentsFromEndpoints(graphqlContext) {
|
|
4093
|
-
const headers = createHeaders(null, graphqlContext);
|
|
4094
4110
|
const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
|
|
4095
4111
|
const agents2 = await acc;
|
|
4096
4112
|
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
@@ -4116,11 +4132,12 @@ please use an LLM adapter instead.`
|
|
|
4116
4132
|
...endpointAgents
|
|
4117
4133
|
];
|
|
4118
4134
|
}
|
|
4135
|
+
const cpkEndpoint = endpoint;
|
|
4119
4136
|
const fetchUrl = `${endpoint.url}/info`;
|
|
4120
4137
|
try {
|
|
4121
4138
|
const response = await fetch(fetchUrl, {
|
|
4122
4139
|
method: "POST",
|
|
4123
|
-
headers,
|
|
4140
|
+
headers: createHeaders(cpkEndpoint.onBeforeRequest, graphqlContext),
|
|
4124
4141
|
body: JSON.stringify({
|
|
4125
4142
|
properties: graphqlContext.properties
|
|
4126
4143
|
})
|
|
@@ -4201,11 +4218,12 @@ please use an LLM adapter instead.`
|
|
|
4201
4218
|
};
|
|
4202
4219
|
}
|
|
4203
4220
|
} else if (agentWithEndpoint.endpoint.type === EndpointType.CopilotKit || !("type" in agentWithEndpoint.endpoint)) {
|
|
4204
|
-
const
|
|
4221
|
+
const cpkEndpoint = agentWithEndpoint.endpoint;
|
|
4222
|
+
const fetchUrl = `${cpkEndpoint.url}/agents/state`;
|
|
4205
4223
|
try {
|
|
4206
4224
|
const response = await fetch(fetchUrl, {
|
|
4207
4225
|
method: "POST",
|
|
4208
|
-
headers,
|
|
4226
|
+
headers: createHeaders(cpkEndpoint.onBeforeRequest, graphqlContext),
|
|
4209
4227
|
body: JSON.stringify({
|
|
4210
4228
|
properties: graphqlContext.properties,
|
|
4211
4229
|
threadId,
|
|
@@ -4250,7 +4268,7 @@ please use an LLM adapter instead.`
|
|
|
4250
4268
|
const threadId = threadIdFromRequest ?? agentSession.threadId;
|
|
4251
4269
|
const serverSideActions = await this.getServerSideActions(request);
|
|
4252
4270
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
4253
|
-
const currentAgent = serverSideActions.find((action) => action.name === agentName &&
|
|
4271
|
+
const currentAgent = serverSideActions.find((action) => action.name === agentName && isRemoteAgentAction(action));
|
|
4254
4272
|
if (!currentAgent) {
|
|
4255
4273
|
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4256
4274
|
agentName
|
|
@@ -4258,8 +4276,8 @@ please use an LLM adapter instead.`
|
|
|
4258
4276
|
}
|
|
4259
4277
|
const availableActionsForCurrentAgent = serverSideActions.filter((action) => (
|
|
4260
4278
|
// Case 1: Keep all regular (non-agent) actions
|
|
4261
|
-
!
|
|
4262
|
-
|
|
4279
|
+
!isRemoteAgentAction(action) || // Case 2: For agent actions, keep all except self (prevent infinite loops)
|
|
4280
|
+
isRemoteAgentAction(action) && action.name !== agentName
|
|
4263
4281
|
)).map((action) => ({
|
|
4264
4282
|
name: action.name,
|
|
4265
4283
|
description: action.description,
|
|
@@ -4277,7 +4295,7 @@ please use an LLM adapter instead.`
|
|
|
4277
4295
|
}));
|
|
4278
4296
|
try {
|
|
4279
4297
|
const eventSource = new RuntimeEventSource();
|
|
4280
|
-
const stream = await currentAgent.
|
|
4298
|
+
const stream = await currentAgent.remoteAgentHandler({
|
|
4281
4299
|
name: agentName,
|
|
4282
4300
|
threadId,
|
|
4283
4301
|
nodeName,
|
|
@@ -5370,6 +5388,9 @@ var CopilotResolver = class {
|
|
|
5370
5388
|
resolveOutputMessagesPromise = resolve;
|
|
5371
5389
|
rejectOutputMessagesPromise = reject;
|
|
5372
5390
|
});
|
|
5391
|
+
if (copilotCloudPublicApiKey) {
|
|
5392
|
+
ctx.properties["copilotCloudPublicApiKey"] = copilotCloudPublicApiKey;
|
|
5393
|
+
}
|
|
5373
5394
|
logger2.debug("Processing");
|
|
5374
5395
|
const { eventSource, threadId = (0, import_shared21.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5375
5396
|
serviceAdapter,
|