@copilotkit/runtime 1.8.5-next.4 → 1.8.5
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 +86 -0
- package/dist/{chunk-574FKWP5.mjs → chunk-AYW55OHA.mjs} +2 -2
- package/dist/{chunk-PKO7BUPS.mjs → chunk-CTOM2OZ3.mjs} +124 -4
- package/dist/chunk-CTOM2OZ3.mjs.map +1 -0
- package/dist/{chunk-WQZQTGHT.mjs → chunk-IUD7KKAU.mjs} +2 -2
- package/dist/{chunk-GGXHVDCG.mjs → chunk-NPWAEKGB.mjs} +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +166 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +159 -39
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/integrations/index.d.ts +3 -2
- package/dist/lib/integrations/index.js +15 -10
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.d.ts +2 -1
- package/dist/lib/integrations/nest/index.js +15 -10
- 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.d.ts +2 -1
- package/dist/lib/integrations/node-express/index.js +15 -10
- 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.d.ts +2 -1
- package/dist/lib/integrations/node-http/index.js +15 -10
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/dist/{shared-86ec42e7.d.ts → shared-93687488.d.ts} +3 -0
- package/package.json +6 -2
- package/src/lib/runtime/agentwire-action.ts +123 -0
- package/src/lib/runtime/copilot-runtime.ts +9 -1
- package/src/lib/runtime/remote-action-constructors.ts +2 -7
- package/src/lib/runtime/remote-actions.ts +25 -1
- package/dist/chunk-PKO7BUPS.mjs.map +0 -1
- /package/dist/{chunk-574FKWP5.mjs.map → chunk-AYW55OHA.mjs.map} +0 -0
- /package/dist/{chunk-WQZQTGHT.mjs.map → chunk-IUD7KKAU.mjs.map} +0 -0
- /package/dist/{chunk-GGXHVDCG.mjs.map → chunk-NPWAEKGB.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-CTOM2OZ3.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNestEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-IUD7KKAU.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-CTOM2OZ3.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-NPWAEKGB.mjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from './groq-adapter-fb9aa3ab.js';
|
|
2
|
-
export { e as CommonConfig, C as CopilotRequestContextProperties, k as CopilotRuntime, j as CopilotRuntimeConstructorParams, f as CopilotRuntimeLogger, i as CopilotRuntimeRequest, b as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, o as MCPClient, p as MCPEndpointConfig, M as MCPTool, a as addCustomHeaderPlugin, d as buildSchema, s as convertMCPToolsToActions, m as copilotKitEndpoint, c as createContext, h as createLogger, q as extractParametersFromSchema, l as flattenToolCallsNoDuplicates, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from './shared-
|
|
2
|
+
export { e as CommonConfig, C as CopilotRequestContextProperties, k as CopilotRuntime, j as CopilotRuntimeConstructorParams, f as CopilotRuntimeLogger, i as CopilotRuntimeRequest, b as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, o as MCPClient, p as MCPEndpointConfig, M as MCPTool, a as addCustomHeaderPlugin, d as buildSchema, s as convertMCPToolsToActions, m as copilotKitEndpoint, c as createContext, h as createLogger, q as extractParametersFromSchema, l as flattenToolCallsNoDuplicates, g as getCommonConfig, n as langGraphPlatformEndpoint, r as resolveEndpointType } from './shared-93687488.js';
|
|
3
3
|
export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint } from './lib/integrations/index.js';
|
|
4
4
|
export { copilotRuntimeNodeHttpEndpoint } from './lib/integrations/node-http/index.js';
|
|
5
5
|
export { copilotRuntimeNodeExpressEndpoint } from './lib/integrations/node-express/index.js';
|
|
@@ -19,5 +19,6 @@ import '@copilotkit/shared';
|
|
|
19
19
|
import './index-5bec5424.js';
|
|
20
20
|
import './graphql/types/base/index.js';
|
|
21
21
|
import './lib/cloud/index.js';
|
|
22
|
+
import '@agentwire/client';
|
|
22
23
|
import 'rxjs';
|
|
23
24
|
import '@anthropic-ai/sdk';
|
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.8.5
|
|
47
|
+
version: "1.8.5",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -81,6 +81,10 @@ var require_package = __commonJS({
|
|
|
81
81
|
"zod-to-json-schema": "^3.23.5"
|
|
82
82
|
},
|
|
83
83
|
dependencies: {
|
|
84
|
+
"@agentwire/client": "0.0.26",
|
|
85
|
+
"@agentwire/proto": "0.0.26",
|
|
86
|
+
"@agentwire/core": "0.0.26",
|
|
87
|
+
"@agentwire/encoder": "0.0.26",
|
|
84
88
|
"@anthropic-ai/sdk": "^0.27.3",
|
|
85
89
|
"@copilotkit/shared": "workspace:*",
|
|
86
90
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
@@ -2607,11 +2611,14 @@ GenerateCopilotResponseInput = _ts_decorate17([
|
|
|
2607
2611
|
var import_graphql_yoga = require("graphql-yoga");
|
|
2608
2612
|
|
|
2609
2613
|
// src/service-adapters/events.ts
|
|
2610
|
-
var
|
|
2614
|
+
var import_shared22 = require("@copilotkit/shared");
|
|
2611
2615
|
var import_rxjs3 = require("rxjs");
|
|
2612
2616
|
|
|
2613
2617
|
// src/lib/telemetry-client.ts
|
|
2614
|
-
var
|
|
2618
|
+
var import_shared21 = require("@copilotkit/shared");
|
|
2619
|
+
|
|
2620
|
+
// src/lib/runtime/remote-actions.ts
|
|
2621
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2615
2622
|
|
|
2616
2623
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2617
2624
|
var import_node_crypto2 = require("crypto");
|
|
@@ -3781,7 +3788,101 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
3781
3788
|
__name(createHeaders, "createHeaders");
|
|
3782
3789
|
|
|
3783
3790
|
// src/lib/runtime/remote-actions.ts
|
|
3791
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
3792
|
+
|
|
3793
|
+
// src/lib/runtime/agentwire-action.ts
|
|
3784
3794
|
var import_shared13 = require("@copilotkit/shared");
|
|
3795
|
+
function constructAgentWireRemoteAction({ logger: logger2, messages, agentStates, agent }) {
|
|
3796
|
+
const action = {
|
|
3797
|
+
name: agent.agentId,
|
|
3798
|
+
description: agent.description,
|
|
3799
|
+
parameters: [],
|
|
3800
|
+
handler: async (_args) => {
|
|
3801
|
+
},
|
|
3802
|
+
remoteAgentHandler: async ({ actionInputsWithoutAgents, threadId }) => {
|
|
3803
|
+
logger2.debug({
|
|
3804
|
+
actionName: agent.agentId
|
|
3805
|
+
}, "Executing remote agent");
|
|
3806
|
+
const agentWireMessages = convertMessagesToAgentWire(messages);
|
|
3807
|
+
agent.messages = agentWireMessages;
|
|
3808
|
+
agent.threadId = threadId;
|
|
3809
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
3810
|
+
agentExecution: true,
|
|
3811
|
+
type: "self-hosted",
|
|
3812
|
+
agentsAmount: 1
|
|
3813
|
+
});
|
|
3814
|
+
let state = {};
|
|
3815
|
+
if (agentStates) {
|
|
3816
|
+
const jsonState = agentStates.find((state2) => state2.agentName === agent.agentId);
|
|
3817
|
+
if (jsonState) {
|
|
3818
|
+
state = (0, import_shared13.parseJson)(jsonState.state, {});
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
agent.state = state;
|
|
3822
|
+
const tools = actionInputsWithoutAgents.map((input) => {
|
|
3823
|
+
return {
|
|
3824
|
+
name: input.name,
|
|
3825
|
+
description: input.description,
|
|
3826
|
+
parameters: JSON.parse(input.jsonSchema)
|
|
3827
|
+
};
|
|
3828
|
+
});
|
|
3829
|
+
return agent.legacy_to_be_removed_runAgentBridged({
|
|
3830
|
+
tools
|
|
3831
|
+
});
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
return [
|
|
3835
|
+
action
|
|
3836
|
+
];
|
|
3837
|
+
}
|
|
3838
|
+
__name(constructAgentWireRemoteAction, "constructAgentWireRemoteAction");
|
|
3839
|
+
function convertMessagesToAgentWire(messages) {
|
|
3840
|
+
const result = [];
|
|
3841
|
+
for (const message of messages) {
|
|
3842
|
+
if (message.isTextMessage()) {
|
|
3843
|
+
result.push({
|
|
3844
|
+
id: message.id,
|
|
3845
|
+
role: message.role,
|
|
3846
|
+
content: message.content
|
|
3847
|
+
});
|
|
3848
|
+
} else if (message.isActionExecutionMessage()) {
|
|
3849
|
+
const toolCall = {
|
|
3850
|
+
id: message.id,
|
|
3851
|
+
type: "function",
|
|
3852
|
+
function: {
|
|
3853
|
+
name: message.name,
|
|
3854
|
+
arguments: JSON.stringify(message.arguments)
|
|
3855
|
+
}
|
|
3856
|
+
};
|
|
3857
|
+
if (message.parentMessageId && result.some((m) => m.id === message.parentMessageId)) {
|
|
3858
|
+
const parentMessage = result.find((m) => m.id === message.parentMessageId);
|
|
3859
|
+
if (parentMessage.toolCalls === void 0) {
|
|
3860
|
+
parentMessage.toolCalls = [];
|
|
3861
|
+
}
|
|
3862
|
+
parentMessage.toolCalls.push(toolCall);
|
|
3863
|
+
} else {
|
|
3864
|
+
result.push({
|
|
3865
|
+
id: message.parentMessageId ?? message.id,
|
|
3866
|
+
role: "assistant",
|
|
3867
|
+
toolCalls: [
|
|
3868
|
+
toolCall
|
|
3869
|
+
]
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3872
|
+
} else if (message.isResultMessage()) {
|
|
3873
|
+
result.push({
|
|
3874
|
+
id: message.id,
|
|
3875
|
+
role: "tool",
|
|
3876
|
+
content: message.result,
|
|
3877
|
+
toolCallId: message.actionExecutionId
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
return result;
|
|
3882
|
+
}
|
|
3883
|
+
__name(convertMessagesToAgentWire, "convertMessagesToAgentWire");
|
|
3884
|
+
|
|
3885
|
+
// src/lib/runtime/remote-actions.ts
|
|
3785
3886
|
var EndpointType;
|
|
3786
3887
|
(function(EndpointType2) {
|
|
3787
3888
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -3815,7 +3916,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3815
3916
|
status: response.status,
|
|
3816
3917
|
body: await response.text()
|
|
3817
3918
|
}, "Failed to fetch actions from url");
|
|
3818
|
-
throw new
|
|
3919
|
+
throw new import_shared15.ResolvedCopilotKitError({
|
|
3819
3920
|
status: response.status,
|
|
3820
3921
|
url: fetchUrl,
|
|
3821
3922
|
isRemoteEndpoint: true
|
|
@@ -3827,17 +3928,17 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3827
3928
|
}, "Fetched actions from url");
|
|
3828
3929
|
return json;
|
|
3829
3930
|
} catch (error) {
|
|
3830
|
-
if (error instanceof
|
|
3931
|
+
if (error instanceof import_shared15.CopilotKitError) {
|
|
3831
3932
|
throw error;
|
|
3832
3933
|
}
|
|
3833
|
-
throw new
|
|
3934
|
+
throw new import_shared15.CopilotKitLowLevelError({
|
|
3834
3935
|
error,
|
|
3835
3936
|
url: fetchUrl
|
|
3836
3937
|
});
|
|
3837
3938
|
}
|
|
3838
3939
|
}
|
|
3839
3940
|
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
3840
|
-
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
|
|
3941
|
+
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl, agents }) {
|
|
3841
3942
|
const logger2 = graphqlContext.logger.child({
|
|
3842
3943
|
component: "remote-actions.fetchRemoteActions"
|
|
3843
3944
|
});
|
|
@@ -3886,6 +3987,22 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
|
|
|
3886
3987
|
agentStates
|
|
3887
3988
|
});
|
|
3888
3989
|
}));
|
|
3990
|
+
for (const [key, agent] of Object.entries(agents)) {
|
|
3991
|
+
if (agent.agentId !== void 0 && agent.agentId !== key) {
|
|
3992
|
+
throw new import_shared15.CopilotKitError({
|
|
3993
|
+
message: `Agent ${key} has agentId ${agent.agentId} which does not match the key ${key}`,
|
|
3994
|
+
code: import_shared14.CopilotKitErrorCode.UNKNOWN
|
|
3995
|
+
});
|
|
3996
|
+
} else if (agent.agentId === void 0) {
|
|
3997
|
+
agent.agentId = key;
|
|
3998
|
+
}
|
|
3999
|
+
result.push(constructAgentWireRemoteAction({
|
|
4000
|
+
logger: logger2,
|
|
4001
|
+
messages,
|
|
4002
|
+
agentStates,
|
|
4003
|
+
agent
|
|
4004
|
+
}));
|
|
4005
|
+
}
|
|
3889
4006
|
return result.flat();
|
|
3890
4007
|
}
|
|
3891
4008
|
__name(setupRemoteActions, "setupRemoteActions");
|
|
@@ -3894,7 +4011,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
3894
4011
|
var import_node_crypto3 = require("crypto");
|
|
3895
4012
|
|
|
3896
4013
|
// src/lib/runtime/copilot-runtime.ts
|
|
3897
|
-
var
|
|
4014
|
+
var import_shared20 = require("@copilotkit/shared");
|
|
3898
4015
|
|
|
3899
4016
|
// src/service-adapters/langchain/langserve.ts
|
|
3900
4017
|
var import_remote = require("langchain/runnables/remote");
|
|
@@ -4110,7 +4227,7 @@ function groupAnthropicMessagesByRole(messageParams) {
|
|
|
4110
4227
|
__name(groupAnthropicMessagesByRole, "groupAnthropicMessagesByRole");
|
|
4111
4228
|
|
|
4112
4229
|
// src/service-adapters/anthropic/anthropic-adapter.ts
|
|
4113
|
-
var
|
|
4230
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
4114
4231
|
var DEFAULT_MODEL3 = "claude-3-sonnet-20240229";
|
|
4115
4232
|
var AnthropicAdapter = class {
|
|
4116
4233
|
model = DEFAULT_MODEL3;
|
|
@@ -4161,8 +4278,8 @@ var AnthropicAdapter = class {
|
|
|
4161
4278
|
eventSource.stream(async (eventStream$) => {
|
|
4162
4279
|
let mode = null;
|
|
4163
4280
|
let didOutputText = false;
|
|
4164
|
-
let currentMessageId = (0,
|
|
4165
|
-
let currentToolCallId = (0,
|
|
4281
|
+
let currentMessageId = (0, import_shared16.randomId)();
|
|
4282
|
+
let currentToolCallId = (0, import_shared16.randomId)();
|
|
4166
4283
|
let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
|
|
4167
4284
|
for await (const chunk of await stream) {
|
|
4168
4285
|
if (chunk.type === "message_start") {
|
|
@@ -4219,7 +4336,7 @@ var AnthropicAdapter = class {
|
|
|
4219
4336
|
eventStream$.complete();
|
|
4220
4337
|
});
|
|
4221
4338
|
return {
|
|
4222
|
-
threadId: threadId || (0,
|
|
4339
|
+
threadId: threadId || (0, import_shared16.randomUUID)()
|
|
4223
4340
|
};
|
|
4224
4341
|
}
|
|
4225
4342
|
};
|
|
@@ -4259,7 +4376,7 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
4259
4376
|
|
|
4260
4377
|
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
4261
4378
|
var import_ollama = require("@langchain/community/llms/ollama");
|
|
4262
|
-
var
|
|
4379
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
4263
4380
|
var DEFAULT_MODEL4 = "llama3:latest";
|
|
4264
4381
|
var ExperimentalOllamaAdapter = class {
|
|
4265
4382
|
model;
|
|
@@ -4278,7 +4395,7 @@ var ExperimentalOllamaAdapter = class {
|
|
|
4278
4395
|
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
4279
4396
|
const _stream = await ollama.stream(contents);
|
|
4280
4397
|
eventSource.stream(async (eventStream$) => {
|
|
4281
|
-
const currentMessageId = (0,
|
|
4398
|
+
const currentMessageId = (0, import_shared17.randomId)();
|
|
4282
4399
|
eventStream$.sendTextMessageStart({
|
|
4283
4400
|
messageId: currentMessageId
|
|
4284
4401
|
});
|
|
@@ -4294,18 +4411,18 @@ var ExperimentalOllamaAdapter = class {
|
|
|
4294
4411
|
eventStream$.complete();
|
|
4295
4412
|
});
|
|
4296
4413
|
return {
|
|
4297
|
-
threadId: request.threadId || (0,
|
|
4414
|
+
threadId: request.threadId || (0, import_shared17.randomUUID)()
|
|
4298
4415
|
};
|
|
4299
4416
|
}
|
|
4300
4417
|
};
|
|
4301
4418
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
4302
4419
|
|
|
4303
4420
|
// src/service-adapters/empty/empty-adapter.ts
|
|
4304
|
-
var
|
|
4421
|
+
var import_shared18 = require("@copilotkit/shared");
|
|
4305
4422
|
var EmptyAdapter = class {
|
|
4306
4423
|
async process(request) {
|
|
4307
4424
|
return {
|
|
4308
|
-
threadId: request.threadId || (0,
|
|
4425
|
+
threadId: request.threadId || (0, import_shared18.randomUUID)()
|
|
4309
4426
|
};
|
|
4310
4427
|
}
|
|
4311
4428
|
};
|
|
@@ -4428,9 +4545,9 @@ __name(AgentStateMessage, "AgentStateMessage");
|
|
|
4428
4545
|
|
|
4429
4546
|
// src/service-adapters/conversion.ts
|
|
4430
4547
|
var import_class_transformer = require("class-transformer");
|
|
4431
|
-
var
|
|
4548
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
4432
4549
|
function convertGqlInputToMessages(inputMessages) {
|
|
4433
|
-
const messages = (0,
|
|
4550
|
+
const messages = (0, import_shared19.tryMap)(inputMessages, (message) => {
|
|
4434
4551
|
if (message.textMessage) {
|
|
4435
4552
|
return (0, import_class_transformer.plainToInstance)(TextMessage, {
|
|
4436
4553
|
id: message.id,
|
|
@@ -4537,6 +4654,7 @@ __name(convertMCPToolsToActions, "convertMCPToolsToActions");
|
|
|
4537
4654
|
// src/lib/runtime/copilot-runtime.ts
|
|
4538
4655
|
var CopilotRuntime = class {
|
|
4539
4656
|
actions;
|
|
4657
|
+
agents;
|
|
4540
4658
|
remoteEndpointDefinitions;
|
|
4541
4659
|
langserve = [];
|
|
4542
4660
|
onBeforeRequest;
|
|
@@ -4567,10 +4685,11 @@ var CopilotRuntime = class {
|
|
|
4567
4685
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
4568
4686
|
this.delegateAgentProcessingToServiceAdapter = (params == null ? void 0 : params.delegateAgentProcessingToServiceAdapter) || false;
|
|
4569
4687
|
this.observability = params == null ? void 0 : params.observability_c;
|
|
4688
|
+
this.agents = (params == null ? void 0 : params.agents) ?? {};
|
|
4570
4689
|
this.mcpEndpointsConfig = params == null ? void 0 : params.mcpEndpoints;
|
|
4571
4690
|
this.createMCPClientImpl = params == null ? void 0 : params.createMCPClient;
|
|
4572
4691
|
if (this.mcpEndpointsConfig && this.mcpEndpointsConfig.length > 0 && !this.createMCPClientImpl) {
|
|
4573
|
-
throw new
|
|
4692
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
4574
4693
|
message: "MCP Integration Error: `mcpEndpoints` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. Please provide an implementation for `createMCPClient`."
|
|
4575
4694
|
});
|
|
4576
4695
|
}
|
|
@@ -4606,7 +4725,7 @@ var CopilotRuntime = class {
|
|
|
4606
4725
|
}
|
|
4607
4726
|
} else {
|
|
4608
4727
|
newMessages.unshift({
|
|
4609
|
-
id: (0,
|
|
4728
|
+
id: (0, import_shared20.randomId)(),
|
|
4610
4729
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4611
4730
|
textMessage: {
|
|
4612
4731
|
role: MessageRole.system,
|
|
@@ -4631,7 +4750,7 @@ var CopilotRuntime = class {
|
|
|
4631
4750
|
return await this.processAgentRequest(request);
|
|
4632
4751
|
}
|
|
4633
4752
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
4634
|
-
throw new
|
|
4753
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
4635
4754
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
4636
4755
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
4637
4756
|
please use an LLM adapter instead.`
|
|
@@ -4661,7 +4780,7 @@ please use an LLM adapter instead.`
|
|
|
4661
4780
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
4662
4781
|
name: action.name,
|
|
4663
4782
|
description: action.description,
|
|
4664
|
-
jsonSchema: JSON.stringify((0,
|
|
4783
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
4665
4784
|
}));
|
|
4666
4785
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
4667
4786
|
...serverSideActionsInput,
|
|
@@ -4790,7 +4909,7 @@ please use an LLM adapter instead.`
|
|
|
4790
4909
|
console.error("Error logging LLM error:", logError);
|
|
4791
4910
|
}
|
|
4792
4911
|
}
|
|
4793
|
-
if (error instanceof
|
|
4912
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4794
4913
|
throw error;
|
|
4795
4914
|
}
|
|
4796
4915
|
console.error("Error getting response:", error);
|
|
@@ -4816,12 +4935,12 @@ please use an LLM adapter instead.`
|
|
|
4816
4935
|
try {
|
|
4817
4936
|
data = await client.assistants.search();
|
|
4818
4937
|
if (data && "detail" in data && data.detail.toLowerCase() === "not found") {
|
|
4819
|
-
throw new
|
|
4938
|
+
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4820
4939
|
availableAgents: this.availableAgents
|
|
4821
4940
|
});
|
|
4822
4941
|
}
|
|
4823
4942
|
} catch (e) {
|
|
4824
|
-
throw new
|
|
4943
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
4825
4944
|
message: `
|
|
4826
4945
|
Failed to find or contact remote endpoint at url ${endpoint.deploymentUrl}.
|
|
4827
4946
|
Make sure the API is running and that it's indeed a LangGraph platform url.
|
|
@@ -4852,11 +4971,11 @@ please use an LLM adapter instead.`
|
|
|
4852
4971
|
});
|
|
4853
4972
|
if (!response.ok) {
|
|
4854
4973
|
if (response.status === 404) {
|
|
4855
|
-
throw new
|
|
4974
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4856
4975
|
url: fetchUrl
|
|
4857
4976
|
});
|
|
4858
4977
|
}
|
|
4859
|
-
throw new
|
|
4978
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4860
4979
|
status: response.status,
|
|
4861
4980
|
url: fetchUrl,
|
|
4862
4981
|
isRemoteEndpoint: true
|
|
@@ -4866,7 +4985,7 @@ please use an LLM adapter instead.`
|
|
|
4866
4985
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
4867
4986
|
name: agent.name,
|
|
4868
4987
|
description: agent.description ?? "" ?? "",
|
|
4869
|
-
id: (0,
|
|
4988
|
+
id: (0, import_shared20.randomId)(),
|
|
4870
4989
|
endpoint
|
|
4871
4990
|
}));
|
|
4872
4991
|
return [
|
|
@@ -4874,10 +4993,10 @@ please use an LLM adapter instead.`
|
|
|
4874
4993
|
...endpointAgents
|
|
4875
4994
|
];
|
|
4876
4995
|
} catch (error) {
|
|
4877
|
-
if (error instanceof
|
|
4996
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4878
4997
|
throw error;
|
|
4879
4998
|
}
|
|
4880
|
-
throw new
|
|
4999
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4881
5000
|
error,
|
|
4882
5001
|
url: fetchUrl
|
|
4883
5002
|
});
|
|
@@ -4943,11 +5062,11 @@ please use an LLM adapter instead.`
|
|
|
4943
5062
|
});
|
|
4944
5063
|
if (!response.ok) {
|
|
4945
5064
|
if (response.status === 404) {
|
|
4946
|
-
throw new
|
|
5065
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4947
5066
|
url: fetchUrl
|
|
4948
5067
|
});
|
|
4949
5068
|
}
|
|
4950
|
-
throw new
|
|
5069
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4951
5070
|
status: response.status,
|
|
4952
5071
|
url: fetchUrl,
|
|
4953
5072
|
isRemoteEndpoint: true
|
|
@@ -4960,10 +5079,10 @@ please use an LLM adapter instead.`
|
|
|
4960
5079
|
messages: JSON.stringify(data.messages)
|
|
4961
5080
|
};
|
|
4962
5081
|
} catch (error) {
|
|
4963
|
-
if (error instanceof
|
|
5082
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4964
5083
|
throw error;
|
|
4965
5084
|
}
|
|
4966
|
-
throw new
|
|
5085
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4967
5086
|
error,
|
|
4968
5087
|
url: fetchUrl
|
|
4969
5088
|
});
|
|
@@ -4983,7 +5102,7 @@ please use an LLM adapter instead.`
|
|
|
4983
5102
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
4984
5103
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isRemoteAgentAction(action));
|
|
4985
5104
|
if (!currentAgent) {
|
|
4986
|
-
throw new
|
|
5105
|
+
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4987
5106
|
agentName,
|
|
4988
5107
|
availableAgents: this.availableAgents
|
|
4989
5108
|
});
|
|
@@ -4995,7 +5114,7 @@ please use an LLM adapter instead.`
|
|
|
4995
5114
|
)).map((action) => ({
|
|
4996
5115
|
name: action.name,
|
|
4997
5116
|
description: action.description,
|
|
4998
|
-
jsonSchema: JSON.stringify((0,
|
|
5117
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
4999
5118
|
}));
|
|
5000
5119
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
5001
5120
|
...availableActionsForCurrentAgent,
|
|
@@ -5188,7 +5307,8 @@ please use an LLM adapter instead.`
|
|
|
5188
5307
|
graphqlContext,
|
|
5189
5308
|
messages: inputMessages,
|
|
5190
5309
|
agentStates,
|
|
5191
|
-
frontendUrl: url
|
|
5310
|
+
frontendUrl: url,
|
|
5311
|
+
agents: this.agents
|
|
5192
5312
|
});
|
|
5193
5313
|
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
5194
5314
|
properties: graphqlContext.properties,
|
|
@@ -5293,7 +5413,7 @@ __name(resolveEndpointType, "resolveEndpointType");
|
|
|
5293
5413
|
|
|
5294
5414
|
// src/lib/telemetry-client.ts
|
|
5295
5415
|
var packageJson = require_package();
|
|
5296
|
-
var telemetryClient = new
|
|
5416
|
+
var telemetryClient = new import_shared21.TelemetryClient({
|
|
5297
5417
|
packageName: packageJson.name,
|
|
5298
5418
|
packageVersion: packageJson.version
|
|
5299
5419
|
});
|
|
@@ -5461,10 +5581,10 @@ var RuntimeEventSource = class {
|
|
|
5461
5581
|
const errorMessage = `\u274C ${message}`;
|
|
5462
5582
|
if (!this.callback) {
|
|
5463
5583
|
this.stream(async (eventStream$) => {
|
|
5464
|
-
eventStream$.sendTextMessage((0,
|
|
5584
|
+
eventStream$.sendTextMessage((0, import_shared22.randomId)(), errorMessage);
|
|
5465
5585
|
});
|
|
5466
5586
|
} else {
|
|
5467
|
-
this.eventStream$.sendTextMessage((0,
|
|
5587
|
+
this.eventStream$.sendTextMessage((0, import_shared22.randomId)(), errorMessage);
|
|
5468
5588
|
}
|
|
5469
5589
|
}
|
|
5470
5590
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
|
|
@@ -5660,7 +5780,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
5660
5780
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
5661
5781
|
|
|
5662
5782
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
5663
|
-
var
|
|
5783
|
+
var import_shared23 = require("@copilotkit/shared");
|
|
5664
5784
|
|
|
5665
5785
|
// src/graphql/types/agents-response.type.ts
|
|
5666
5786
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -5846,7 +5966,7 @@ var CopilotResolver = class {
|
|
|
5846
5966
|
ctx.properties["copilotCloudPublicApiKey"] = copilotCloudPublicApiKey;
|
|
5847
5967
|
}
|
|
5848
5968
|
logger2.debug("Processing");
|
|
5849
|
-
const { eventSource, threadId = (0,
|
|
5969
|
+
const { eventSource, threadId = (0, import_shared23.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5850
5970
|
serviceAdapter,
|
|
5851
5971
|
messages: data.messages,
|
|
5852
5972
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5979,7 +6099,7 @@ var CopilotResolver = class {
|
|
|
5979
6099
|
});
|
|
5980
6100
|
outputMessages = [
|
|
5981
6101
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5982
|
-
id: (0,
|
|
6102
|
+
id: (0, import_shared23.randomId)(),
|
|
5983
6103
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5984
6104
|
content: result.reason,
|
|
5985
6105
|
role: MessageRole.assistant
|
|
@@ -6157,7 +6277,7 @@ var CopilotResolver = class {
|
|
|
6157
6277
|
event
|
|
6158
6278
|
}, "Agent message event received");
|
|
6159
6279
|
pushMessage({
|
|
6160
|
-
id: (0,
|
|
6280
|
+
id: (0, import_shared23.randomId)(),
|
|
6161
6281
|
status: new SuccessMessageStatus(),
|
|
6162
6282
|
threadId: event.threadId,
|
|
6163
6283
|
agentName: event.agentName,
|
|
@@ -6170,7 +6290,7 @@ var CopilotResolver = class {
|
|
|
6170
6290
|
createdAt: /* @__PURE__ */ new Date()
|
|
6171
6291
|
});
|
|
6172
6292
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
6173
|
-
id: (0,
|
|
6293
|
+
id: (0, import_shared23.randomId)(),
|
|
6174
6294
|
threadId: event.threadId,
|
|
6175
6295
|
agentName: event.agentName,
|
|
6176
6296
|
nodeName: event.nodeName,
|