@copilotkit/runtime 1.50.0-beta.1 → 1.50.0-beta.3
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 +6 -0
- package/dist/index.d.ts +76 -286
- package/dist/index.js +306 -281
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -270
- package/dist/index.mjs.map +1 -1
- package/dist/langgraph.d.ts +284 -0
- package/dist/langgraph.js +211 -0
- package/dist/langgraph.js.map +1 -0
- package/dist/langgraph.mjs +206 -0
- package/dist/langgraph.mjs.map +1 -0
- package/dist/v2/index.d.ts +1 -0
- package/dist/v2/index.js +7 -0
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/index.mjs +1 -0
- package/dist/v2/index.mjs.map +1 -1
- package/package.json +55 -17
- package/src/graphql/message-conversion/agui-to-gql.test.ts +2 -2
- package/src/graphql/message-conversion/gql-to-agui.test.ts +30 -28
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +8 -8
- package/src/langgraph.ts +1 -0
- package/src/lib/index.ts +41 -1
- package/src/lib/integrations/nextjs/app-router.ts +3 -1
- package/src/lib/integrations/node-http/index.ts +132 -11
- package/src/lib/integrations/shared.ts +2 -2
- package/src/lib/runtime/agent-integrations/{langgraph.agent.ts → langgraph/agent.ts} +5 -30
- package/src/lib/runtime/agent-integrations/langgraph/consts.ts +34 -0
- package/src/lib/runtime/agent-integrations/langgraph/index.ts +2 -0
- package/src/lib/runtime/copilot-runtime.ts +25 -46
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -3
- package/src/service-adapters/bedrock/bedrock-adapter.ts +4 -1
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +2 -1
- package/src/service-adapters/google/google-genai-adapter.ts +9 -4
- package/src/service-adapters/groq/groq-adapter.ts +16 -3
- package/src/service-adapters/langchain/langchain-adapter.ts +5 -3
- package/src/service-adapters/langchain/langserve.ts +2 -1
- package/src/service-adapters/openai/openai-adapter.ts +17 -3
- package/src/service-adapters/openai/openai-assistant-adapter.ts +26 -11
- package/src/service-adapters/unify/unify-adapter.ts +3 -1
- package/src/v2/index.ts +1 -0
- package/tsup.config.ts +5 -2
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import OpenAI from 'openai';
|
|
3
2
|
import { TelemetryClient, CopilotKitLowLevelError, CopilotKitErrorCode, randomUUID, randomId, CopilotKitMisuseError, getZodParameters, readBody, CopilotKitError, CopilotKitAgentDiscoveryError, parseJson, convertJsonSchemaToZodSchema } from '@copilotkit/shared';
|
|
4
|
-
import {
|
|
3
|
+
import { HumanMessage, AIMessage, SystemMessage, ToolMessage } from '@langchain/core/messages';
|
|
5
4
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
6
|
-
import { awaitAllCallbacks } from '@langchain/core/callbacks/promises';
|
|
7
|
-
import { ChatGoogle } from '@langchain/google-gauth';
|
|
8
|
-
import { Groq } from 'groq-sdk';
|
|
9
5
|
import { registerEnumType, Field, InputType, ObjectType, createUnionType, InterfaceType, Query, Ctx, Mutation, Arg, Resolver, buildSchemaSync } from 'type-graphql';
|
|
10
|
-
import {
|
|
6
|
+
import { ReplaySubject, shareReplay, finalize, firstValueFrom, skipWhile, takeWhile, filter, Subject, take, tap } from 'rxjs';
|
|
11
7
|
import { GraphQLJSON, GraphQLJSONObject } from 'graphql-scalars';
|
|
12
8
|
import { Repeater } from 'graphql-yoga';
|
|
13
9
|
import { plainToInstance } from 'class-transformer';
|
|
14
10
|
import { GraphQLError } from 'graphql';
|
|
15
11
|
import { createHash } from 'crypto';
|
|
16
12
|
import { InMemoryAgentRunner, CopilotRuntime as CopilotRuntime$1, createCopilotEndpointSingleRoute } from '@copilotkitnext/runtime';
|
|
17
|
-
import { EventType } from '@ag-ui/client';
|
|
18
|
-
import { LangGraphAgent as LangGraphAgent$1 } from '@ag-ui/langgraph';
|
|
19
|
-
export { LangGraphHttpAgent } from '@ag-ui/langgraph';
|
|
20
13
|
import { BasicAgent } from '@copilotkitnext/agent';
|
|
21
14
|
import { useDeferStream } from '@graphql-yoga/plugin-defer-stream';
|
|
22
15
|
import createPinoLogger from 'pino';
|
|
23
16
|
import pretty from 'pino-pretty';
|
|
24
17
|
import { handle } from 'hono/vercel';
|
|
25
18
|
import { Readable } from 'stream';
|
|
26
|
-
import { RemoteRunnable } from 'langchain/runnables/remote';
|
|
27
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
28
|
-
import { Ollama } from '@langchain/community/llms/ollama';
|
|
29
|
-
import { ChatBedrockConverse } from '@langchain/aws';
|
|
30
19
|
|
|
31
20
|
var __create = Object.create;
|
|
32
21
|
var __defProp = Object.defineProperty;
|
|
@@ -35,7 +24,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
35
24
|
var __getProtoOf = Object.getPrototypeOf;
|
|
36
25
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
37
26
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
38
|
-
var
|
|
27
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
28
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
29
|
+
}) : x)(function(x) {
|
|
30
|
+
if (typeof require !== "undefined")
|
|
31
|
+
return require.apply(this, arguments);
|
|
32
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
33
|
+
});
|
|
34
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
39
35
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
40
36
|
};
|
|
41
37
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -69,7 +65,7 @@ var require_package = __commonJS({
|
|
|
69
65
|
publishConfig: {
|
|
70
66
|
access: "public"
|
|
71
67
|
},
|
|
72
|
-
version: "1.50.0-beta.
|
|
68
|
+
version: "1.50.0-beta.2",
|
|
73
69
|
sideEffects: false,
|
|
74
70
|
main: "./dist/index.js",
|
|
75
71
|
module: "./dist/index.mjs",
|
|
@@ -83,6 +79,11 @@ var require_package = __commonJS({
|
|
|
83
79
|
import: "./dist/v2/index.mjs",
|
|
84
80
|
require: "./dist/v2/index.js",
|
|
85
81
|
types: "./dist/v2/index.d.ts"
|
|
82
|
+
},
|
|
83
|
+
"./langgraph": {
|
|
84
|
+
import: "./dist/langgraph.mjs",
|
|
85
|
+
require: "./dist/langgraph.js",
|
|
86
|
+
types: "./dist/langgraph.d.ts"
|
|
86
87
|
}
|
|
87
88
|
},
|
|
88
89
|
types: "./dist/index.d.ts",
|
|
@@ -112,29 +113,21 @@ var require_package = __commonJS({
|
|
|
112
113
|
tsconfig: "workspace:*",
|
|
113
114
|
tsup: "^6.7.0",
|
|
114
115
|
typescript: "^5.2.3",
|
|
115
|
-
vitest: "^3.2.4"
|
|
116
|
-
"zod-to-json-schema": "^3.23.5"
|
|
116
|
+
vitest: "^3.2.4"
|
|
117
117
|
},
|
|
118
118
|
dependencies: {
|
|
119
|
-
"@anthropic-ai/sdk": "^0.57.0",
|
|
120
119
|
"@copilotkit/shared": "workspace:*",
|
|
121
|
-
"@copilotkitnext/agent": "0.0.
|
|
122
|
-
"@copilotkitnext/runtime": "0.0.
|
|
120
|
+
"@copilotkitnext/agent": "0.0.23",
|
|
121
|
+
"@copilotkitnext/runtime": "0.0.23",
|
|
123
122
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
124
|
-
"@
|
|
125
|
-
"@langchain/community": "^0.3.29",
|
|
123
|
+
"@hono/node-server": "^1.13.5",
|
|
126
124
|
"@langchain/core": "^0.3.38",
|
|
127
|
-
"@langchain/google-gauth": "^0.1.0",
|
|
128
|
-
"@langchain/langgraph-sdk": "^0.0.70",
|
|
129
|
-
"@langchain/openai": "^0.4.2",
|
|
130
125
|
"@scarf/scarf": "^1.3.0",
|
|
131
126
|
"class-transformer": "^0.5.1",
|
|
132
127
|
"class-validator": "^0.14.1",
|
|
133
128
|
graphql: "^16.8.1",
|
|
134
129
|
"graphql-scalars": "^1.23.0",
|
|
135
130
|
"graphql-yoga": "^5.3.1",
|
|
136
|
-
"groq-sdk": "^0.5.0",
|
|
137
|
-
"@hono/node-server": "^1.13.5",
|
|
138
131
|
hono: "^4.10.3",
|
|
139
132
|
langchain: "^0.3.3",
|
|
140
133
|
openai: "^4.85.1",
|
|
@@ -147,11 +140,52 @@ var require_package = __commonJS({
|
|
|
147
140
|
zod: "^3.23.3"
|
|
148
141
|
},
|
|
149
142
|
peerDependencies: {
|
|
150
|
-
"@
|
|
143
|
+
"@anthropic-ai/sdk": "^0.57.0",
|
|
144
|
+
"@ag-ui/client": "^0.0.41",
|
|
151
145
|
"@ag-ui/core": ">=0.0.39",
|
|
152
146
|
"@ag-ui/encoder": ">=0.0.39",
|
|
153
147
|
"@ag-ui/langgraph": ">=0.0.18",
|
|
154
|
-
"@ag-ui/proto": ">=0.0.39"
|
|
148
|
+
"@ag-ui/proto": ">=0.0.39",
|
|
149
|
+
"@langchain/aws": "^0.1.9",
|
|
150
|
+
"@langchain/community": "^0.3.58",
|
|
151
|
+
"@langchain/google-gauth": "^0.1.0",
|
|
152
|
+
"@langchain/langgraph-sdk": "^0.0.70",
|
|
153
|
+
"@langchain/openai": "^0.4.2",
|
|
154
|
+
"groq-sdk": "^0.5.0",
|
|
155
|
+
langchain: "^0.3.3",
|
|
156
|
+
openai: "^4.85.1"
|
|
157
|
+
},
|
|
158
|
+
peerDependenciesMeta: {
|
|
159
|
+
"@anthropic-ai/sdk": {
|
|
160
|
+
optional: true
|
|
161
|
+
},
|
|
162
|
+
"@ag-ui/langgraph": {
|
|
163
|
+
optional: true
|
|
164
|
+
},
|
|
165
|
+
"@langchain/aws": {
|
|
166
|
+
optional: true
|
|
167
|
+
},
|
|
168
|
+
"@langchain/community": {
|
|
169
|
+
optional: true
|
|
170
|
+
},
|
|
171
|
+
"@langchain/google-gauth": {
|
|
172
|
+
optional: true
|
|
173
|
+
},
|
|
174
|
+
"@langchain/langgraph-sdk": {
|
|
175
|
+
optional: true
|
|
176
|
+
},
|
|
177
|
+
"@langchain/openai": {
|
|
178
|
+
optional: true
|
|
179
|
+
},
|
|
180
|
+
"groq-sdk": {
|
|
181
|
+
optional: true
|
|
182
|
+
},
|
|
183
|
+
langchain: {
|
|
184
|
+
optional: true
|
|
185
|
+
},
|
|
186
|
+
openai: {
|
|
187
|
+
optional: true
|
|
188
|
+
}
|
|
155
189
|
},
|
|
156
190
|
keywords: [
|
|
157
191
|
"copilotkit",
|
|
@@ -402,13 +436,22 @@ var OpenAIAdapter = class {
|
|
|
402
436
|
return "OpenAIAdapter";
|
|
403
437
|
}
|
|
404
438
|
constructor(params) {
|
|
405
|
-
|
|
439
|
+
if (params == null ? void 0 : params.openai) {
|
|
440
|
+
this._openai = params.openai;
|
|
441
|
+
}
|
|
406
442
|
if (params == null ? void 0 : params.model) {
|
|
407
443
|
this.model = params.model;
|
|
408
444
|
}
|
|
409
445
|
this.disableParallelToolCalls = (params == null ? void 0 : params.disableParallelToolCalls) || false;
|
|
410
446
|
this.keepSystemRole = (params == null ? void 0 : params.keepSystemRole) ?? false;
|
|
411
447
|
}
|
|
448
|
+
ensureOpenAI() {
|
|
449
|
+
if (!this._openai) {
|
|
450
|
+
const OpenAI = __require("openai").default;
|
|
451
|
+
this._openai = new OpenAI();
|
|
452
|
+
}
|
|
453
|
+
return this._openai;
|
|
454
|
+
}
|
|
412
455
|
async process(request) {
|
|
413
456
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
414
457
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
@@ -443,7 +486,8 @@ var OpenAIAdapter = class {
|
|
|
443
486
|
};
|
|
444
487
|
}
|
|
445
488
|
try {
|
|
446
|
-
const
|
|
489
|
+
const openai = this.ensureOpenAI();
|
|
490
|
+
const stream = openai.beta.chat.completions.stream({
|
|
447
491
|
model,
|
|
448
492
|
stream: true,
|
|
449
493
|
messages: openaiMessages,
|
|
@@ -803,11 +847,14 @@ var LangChainAdapter = class {
|
|
|
803
847
|
threadId
|
|
804
848
|
};
|
|
805
849
|
} finally {
|
|
850
|
+
const { awaitAllCallbacks } = __require("@langchain/core/callbacks/promises");
|
|
806
851
|
await awaitAllCallbacks();
|
|
807
852
|
}
|
|
808
853
|
}
|
|
809
854
|
};
|
|
810
855
|
__name(LangChainAdapter, "LangChainAdapter");
|
|
856
|
+
|
|
857
|
+
// src/service-adapters/google/google-genai-adapter.ts
|
|
811
858
|
var DEFAULT_MODEL2 = "gemini-1.5-pro";
|
|
812
859
|
var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
813
860
|
provider = "google";
|
|
@@ -815,11 +862,14 @@ var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
|
815
862
|
constructor(options) {
|
|
816
863
|
super({
|
|
817
864
|
chainFn: async ({ messages, tools, threadId }) => {
|
|
865
|
+
const { ChatGoogle } = __require("@langchain/google-gauth");
|
|
866
|
+
const { AIMessage: AIMessage2 } = __require("@langchain/core/messages");
|
|
818
867
|
const filteredMessages = messages.filter((message) => {
|
|
819
|
-
if (!(message instanceof
|
|
868
|
+
if (!(message instanceof AIMessage2)) {
|
|
820
869
|
return true;
|
|
821
870
|
}
|
|
822
|
-
|
|
871
|
+
const aiMsg = message;
|
|
872
|
+
return aiMsg.content && String(aiMsg.content).trim().length > 0 || aiMsg.tool_calls && aiMsg.tool_calls.length > 0;
|
|
823
873
|
});
|
|
824
874
|
this.model = (options == null ? void 0 : options.model) ?? "gemini-1.5-pro";
|
|
825
875
|
const model = new ChatGoogle({
|
|
@@ -837,8 +887,10 @@ var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
|
837
887
|
}
|
|
838
888
|
};
|
|
839
889
|
__name(GoogleGenerativeAIAdapter, "GoogleGenerativeAIAdapter");
|
|
890
|
+
|
|
891
|
+
// src/service-adapters/openai/openai-assistant-adapter.ts
|
|
840
892
|
var OpenAIAssistantAdapter = class {
|
|
841
|
-
|
|
893
|
+
_openai;
|
|
842
894
|
codeInterpreterEnabled;
|
|
843
895
|
assistantId;
|
|
844
896
|
fileSearchEnabled;
|
|
@@ -848,19 +900,29 @@ var OpenAIAssistantAdapter = class {
|
|
|
848
900
|
return "OpenAIAssistantAdapter";
|
|
849
901
|
}
|
|
850
902
|
constructor(params) {
|
|
851
|
-
|
|
903
|
+
if (params.openai) {
|
|
904
|
+
this._openai = params.openai;
|
|
905
|
+
}
|
|
852
906
|
this.codeInterpreterEnabled = params.codeInterpreterEnabled === false || true;
|
|
853
907
|
this.fileSearchEnabled = params.fileSearchEnabled === false || true;
|
|
854
908
|
this.assistantId = params.assistantId;
|
|
855
909
|
this.disableParallelToolCalls = (params == null ? void 0 : params.disableParallelToolCalls) || false;
|
|
856
910
|
this.keepSystemRole = (params == null ? void 0 : params.keepSystemRole) ?? false;
|
|
857
911
|
}
|
|
912
|
+
ensureOpenAI() {
|
|
913
|
+
if (!this._openai) {
|
|
914
|
+
const OpenAI = __require("openai").default;
|
|
915
|
+
this._openai = new OpenAI({});
|
|
916
|
+
}
|
|
917
|
+
return this._openai;
|
|
918
|
+
}
|
|
858
919
|
async process(request) {
|
|
859
920
|
var _a, _b;
|
|
860
921
|
const { messages, actions, eventSource, runId, forwardedParameters } = request;
|
|
861
922
|
let threadId = (_b = (_a = request.extensions) == null ? void 0 : _a.openaiAssistantAPI) == null ? void 0 : _b.threadId;
|
|
923
|
+
const openai = this.ensureOpenAI();
|
|
862
924
|
if (!threadId) {
|
|
863
|
-
threadId = (await
|
|
925
|
+
threadId = (await openai.beta.threads.create()).id;
|
|
864
926
|
}
|
|
865
927
|
const lastMessage = messages.at(-1);
|
|
866
928
|
let nextRunId = void 0;
|
|
@@ -884,7 +946,8 @@ var OpenAIAssistantAdapter = class {
|
|
|
884
946
|
};
|
|
885
947
|
}
|
|
886
948
|
async submitToolOutputs(threadId, runId, messages, eventSource) {
|
|
887
|
-
|
|
949
|
+
const openai = this.ensureOpenAI();
|
|
950
|
+
let run = await openai.beta.threads.runs.retrieve(threadId, runId);
|
|
888
951
|
if (!run.required_action) {
|
|
889
952
|
throw new Error("No tool outputs required");
|
|
890
953
|
}
|
|
@@ -899,7 +962,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
899
962
|
output: message.result
|
|
900
963
|
};
|
|
901
964
|
});
|
|
902
|
-
const stream =
|
|
965
|
+
const stream = openai.beta.threads.runs.submitToolOutputsStream(threadId, runId, {
|
|
903
966
|
tool_outputs: toolOutputs,
|
|
904
967
|
...this.disableParallelToolCalls && {
|
|
905
968
|
parallel_tool_calls: false
|
|
@@ -909,6 +972,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
909
972
|
return runId;
|
|
910
973
|
}
|
|
911
974
|
async submitUserMessage(threadId, messages, actions, eventSource, forwardedParameters) {
|
|
975
|
+
const openai = this.ensureOpenAI();
|
|
912
976
|
messages = [
|
|
913
977
|
...messages
|
|
914
978
|
];
|
|
@@ -920,7 +984,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
920
984
|
if (userMessage.role !== "user") {
|
|
921
985
|
throw new Error("No user message found");
|
|
922
986
|
}
|
|
923
|
-
await
|
|
987
|
+
await openai.beta.threads.messages.create(threadId, {
|
|
924
988
|
role: "user",
|
|
925
989
|
content: userMessage.content
|
|
926
990
|
});
|
|
@@ -938,7 +1002,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
938
1002
|
}
|
|
939
1003
|
] : []
|
|
940
1004
|
];
|
|
941
|
-
let stream =
|
|
1005
|
+
let stream = openai.beta.threads.runs.stream(threadId, {
|
|
942
1006
|
assistant_id: this.assistantId,
|
|
943
1007
|
instructions,
|
|
944
1008
|
tools,
|
|
@@ -1057,6 +1121,7 @@ var UnifyAdapter = class {
|
|
|
1057
1121
|
}
|
|
1058
1122
|
async process(request) {
|
|
1059
1123
|
const tools = request.actions.map(convertActionInputToOpenAITool);
|
|
1124
|
+
const OpenAI = __require("openai").default;
|
|
1060
1125
|
const openai = new OpenAI({
|
|
1061
1126
|
apiKey: this.apiKey,
|
|
1062
1127
|
baseURL: "https://api.unify.ai/v0/"
|
|
@@ -1168,12 +1233,21 @@ var GroqAdapter = class {
|
|
|
1168
1233
|
return "GroqAdapter";
|
|
1169
1234
|
}
|
|
1170
1235
|
constructor(params) {
|
|
1171
|
-
|
|
1236
|
+
if (params == null ? void 0 : params.groq) {
|
|
1237
|
+
this._groq = params.groq;
|
|
1238
|
+
}
|
|
1172
1239
|
if (params == null ? void 0 : params.model) {
|
|
1173
1240
|
this.model = params.model;
|
|
1174
1241
|
}
|
|
1175
1242
|
this.disableParallelToolCalls = (params == null ? void 0 : params.disableParallelToolCalls) || false;
|
|
1176
1243
|
}
|
|
1244
|
+
ensureGroq() {
|
|
1245
|
+
if (!this._groq) {
|
|
1246
|
+
const { Groq } = __require("groq-sdk");
|
|
1247
|
+
this._groq = new Groq({});
|
|
1248
|
+
}
|
|
1249
|
+
return this._groq;
|
|
1250
|
+
}
|
|
1177
1251
|
async process(request) {
|
|
1178
1252
|
const { threadId, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
1179
1253
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
@@ -1192,7 +1266,8 @@ var GroqAdapter = class {
|
|
|
1192
1266
|
}
|
|
1193
1267
|
let stream;
|
|
1194
1268
|
try {
|
|
1195
|
-
|
|
1269
|
+
const groq = this.ensureGroq();
|
|
1270
|
+
stream = await groq.chat.completions.create({
|
|
1196
1271
|
model,
|
|
1197
1272
|
stream: true,
|
|
1198
1273
|
messages: openaiMessages,
|
|
@@ -3301,199 +3376,6 @@ When using these tools:
|
|
|
3301
3376
|
7. Always check tool responses to determine your next action`;
|
|
3302
3377
|
}
|
|
3303
3378
|
__name(generateMcpToolInstructions, "generateMcpToolInstructions");
|
|
3304
|
-
|
|
3305
|
-
// src/agents/langgraph/events.ts
|
|
3306
|
-
var LangGraphEventTypes;
|
|
3307
|
-
(function(LangGraphEventTypes2) {
|
|
3308
|
-
LangGraphEventTypes2["OnChainStart"] = "on_chain_start";
|
|
3309
|
-
LangGraphEventTypes2["OnChainStream"] = "on_chain_stream";
|
|
3310
|
-
LangGraphEventTypes2["OnChainEnd"] = "on_chain_end";
|
|
3311
|
-
LangGraphEventTypes2["OnChatModelStart"] = "on_chat_model_start";
|
|
3312
|
-
LangGraphEventTypes2["OnChatModelStream"] = "on_chat_model_stream";
|
|
3313
|
-
LangGraphEventTypes2["OnChatModelEnd"] = "on_chat_model_end";
|
|
3314
|
-
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
3315
|
-
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
3316
|
-
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
3317
|
-
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
3318
|
-
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
3319
|
-
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
3320
|
-
LangGraphEventTypes2["OnInterrupt"] = "on_interrupt";
|
|
3321
|
-
LangGraphEventTypes2["OnCopilotKitInterrupt"] = "on_copilotkit_interrupt";
|
|
3322
|
-
LangGraphEventTypes2["OnCopilotKitError"] = "on_copilotkit_error";
|
|
3323
|
-
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
3324
|
-
var MetaEventNames;
|
|
3325
|
-
(function(MetaEventNames2) {
|
|
3326
|
-
MetaEventNames2["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
|
|
3327
|
-
MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
3328
|
-
})(MetaEventNames || (MetaEventNames = {}));
|
|
3329
|
-
var CustomEventNames;
|
|
3330
|
-
(function(CustomEventNames3) {
|
|
3331
|
-
CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3332
|
-
CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3333
|
-
CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3334
|
-
CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
|
|
3335
|
-
})(CustomEventNames || (CustomEventNames = {}));
|
|
3336
|
-
var CustomEventNames2;
|
|
3337
|
-
(function(CustomEventNames3) {
|
|
3338
|
-
CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3339
|
-
CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3340
|
-
CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3341
|
-
CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
|
|
3342
|
-
})(CustomEventNames2 || (CustomEventNames2 = {}));
|
|
3343
|
-
var LangGraphAgent = class extends LangGraphAgent$1 {
|
|
3344
|
-
constructor(config2) {
|
|
3345
|
-
super(config2);
|
|
3346
|
-
}
|
|
3347
|
-
// @ts-ignore
|
|
3348
|
-
clone() {
|
|
3349
|
-
return new LangGraphAgent(this.config);
|
|
3350
|
-
}
|
|
3351
|
-
dispatchEvent(event) {
|
|
3352
|
-
if (event.type === EventType.CUSTOM) {
|
|
3353
|
-
const customEvent = event;
|
|
3354
|
-
if (customEvent.name === "copilotkit_manually_emit_message") {
|
|
3355
|
-
this.subscriber.next({
|
|
3356
|
-
type: EventType.TEXT_MESSAGE_START,
|
|
3357
|
-
role: "assistant",
|
|
3358
|
-
messageId: customEvent.value.message_id,
|
|
3359
|
-
rawEvent: event
|
|
3360
|
-
});
|
|
3361
|
-
this.subscriber.next({
|
|
3362
|
-
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
3363
|
-
messageId: customEvent.value.message_id,
|
|
3364
|
-
delta: customEvent.value.message,
|
|
3365
|
-
rawEvent: event
|
|
3366
|
-
});
|
|
3367
|
-
this.subscriber.next({
|
|
3368
|
-
type: EventType.TEXT_MESSAGE_END,
|
|
3369
|
-
messageId: customEvent.value.message_id,
|
|
3370
|
-
rawEvent: event
|
|
3371
|
-
});
|
|
3372
|
-
return true;
|
|
3373
|
-
}
|
|
3374
|
-
if (customEvent.name === "copilotkit_manually_emit_tool_call") {
|
|
3375
|
-
this.subscriber.next({
|
|
3376
|
-
type: EventType.TOOL_CALL_START,
|
|
3377
|
-
toolCallId: customEvent.value.id,
|
|
3378
|
-
toolCallName: customEvent.value.name,
|
|
3379
|
-
parentMessageId: customEvent.value.id,
|
|
3380
|
-
rawEvent: event
|
|
3381
|
-
});
|
|
3382
|
-
this.subscriber.next({
|
|
3383
|
-
type: EventType.TOOL_CALL_ARGS,
|
|
3384
|
-
toolCallId: customEvent.value.id,
|
|
3385
|
-
delta: customEvent.value.args,
|
|
3386
|
-
rawEvent: event
|
|
3387
|
-
});
|
|
3388
|
-
this.subscriber.next({
|
|
3389
|
-
type: EventType.TOOL_CALL_END,
|
|
3390
|
-
toolCallId: customEvent.value.id,
|
|
3391
|
-
rawEvent: event
|
|
3392
|
-
});
|
|
3393
|
-
return true;
|
|
3394
|
-
}
|
|
3395
|
-
if (customEvent.name === "copilotkit_manually_emit_intermediate_state") {
|
|
3396
|
-
this.activeRun.manuallyEmittedState = customEvent.value;
|
|
3397
|
-
this.dispatchEvent({
|
|
3398
|
-
type: EventType.STATE_SNAPSHOT,
|
|
3399
|
-
snapshot: this.getStateSnapshot({
|
|
3400
|
-
values: this.activeRun.manuallyEmittedState
|
|
3401
|
-
}),
|
|
3402
|
-
rawEvent: event
|
|
3403
|
-
});
|
|
3404
|
-
return true;
|
|
3405
|
-
}
|
|
3406
|
-
if (customEvent.name === "copilotkit_exit") {
|
|
3407
|
-
this.subscriber.next({
|
|
3408
|
-
type: EventType.CUSTOM,
|
|
3409
|
-
name: "Exit",
|
|
3410
|
-
value: true
|
|
3411
|
-
});
|
|
3412
|
-
return true;
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
|
-
const rawEvent = event.rawEvent;
|
|
3416
|
-
if (!rawEvent) {
|
|
3417
|
-
this.subscriber.next(event);
|
|
3418
|
-
return true;
|
|
3419
|
-
}
|
|
3420
|
-
const isMessageEvent = event.type === EventType.TEXT_MESSAGE_START || event.type === EventType.TEXT_MESSAGE_CONTENT || event.type === EventType.TEXT_MESSAGE_END;
|
|
3421
|
-
const isToolEvent = event.type === EventType.TOOL_CALL_START || event.type === EventType.TOOL_CALL_ARGS || event.type === EventType.TOOL_CALL_END;
|
|
3422
|
-
if ("copilotkit:emit-tool-calls" in (rawEvent.metadata || {})) {
|
|
3423
|
-
if (rawEvent.metadata["copilotkit:emit-tool-calls"] === false && isToolEvent) {
|
|
3424
|
-
return false;
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
if ("copilotkit:emit-messages" in (rawEvent.metadata || {})) {
|
|
3428
|
-
if (rawEvent.metadata["copilotkit:emit-messages"] === false && isMessageEvent) {
|
|
3429
|
-
return false;
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
this.subscriber.next(event);
|
|
3433
|
-
return true;
|
|
3434
|
-
}
|
|
3435
|
-
// @ts-ignore
|
|
3436
|
-
run(input) {
|
|
3437
|
-
return super.run(input).pipe(map((processedEvent) => {
|
|
3438
|
-
var _a, _b, _c, _d, _e;
|
|
3439
|
-
if (processedEvent.type === EventType.RAW) {
|
|
3440
|
-
const event = processedEvent.event ?? processedEvent.rawEvent;
|
|
3441
|
-
const eventType = event.event;
|
|
3442
|
-
const toolCallData = (_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.tool_call_chunks) == null ? void 0 : _c[0];
|
|
3443
|
-
const toolCallUsedToPredictState = (_e = (_d = event.metadata) == null ? void 0 : _d["copilotkit:emit-intermediate-state"]) == null ? void 0 : _e.some((predictStateTool) => predictStateTool.tool === (toolCallData == null ? void 0 : toolCallData.name));
|
|
3444
|
-
if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {
|
|
3445
|
-
return {
|
|
3446
|
-
type: EventType.CUSTOM,
|
|
3447
|
-
name: "PredictState",
|
|
3448
|
-
value: event.metadata["copilotkit:emit-intermediate-state"]
|
|
3449
|
-
};
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
3452
|
-
return processedEvent;
|
|
3453
|
-
}));
|
|
3454
|
-
}
|
|
3455
|
-
langGraphDefaultMergeState(state, messages, input) {
|
|
3456
|
-
const aguiMergedState = super.langGraphDefaultMergeState(state, messages, input);
|
|
3457
|
-
const { tools: returnedTools, "ag-ui": agui } = aguiMergedState;
|
|
3458
|
-
const rawCombinedTools = [
|
|
3459
|
-
...returnedTools ?? [],
|
|
3460
|
-
...(agui == null ? void 0 : agui.tools) ?? []
|
|
3461
|
-
];
|
|
3462
|
-
const combinedTools = Array.from(new Map(rawCombinedTools.map((t) => [
|
|
3463
|
-
(t == null ? void 0 : t.id) ?? (t == null ? void 0 : t.name) ?? (t == null ? void 0 : t.key) ?? JSON.stringify(t),
|
|
3464
|
-
t
|
|
3465
|
-
])).values());
|
|
3466
|
-
return {
|
|
3467
|
-
...aguiMergedState,
|
|
3468
|
-
copilotkit: {
|
|
3469
|
-
actions: combinedTools,
|
|
3470
|
-
context: (agui == null ? void 0 : agui.context) ?? []
|
|
3471
|
-
}
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
async getSchemaKeys() {
|
|
3475
|
-
const CONSTANT_KEYS = [
|
|
3476
|
-
"copilotkit"
|
|
3477
|
-
];
|
|
3478
|
-
const schemaKeys = await super.getSchemaKeys();
|
|
3479
|
-
return {
|
|
3480
|
-
config: schemaKeys.config,
|
|
3481
|
-
input: schemaKeys.input ? [
|
|
3482
|
-
...schemaKeys.input,
|
|
3483
|
-
...CONSTANT_KEYS
|
|
3484
|
-
] : null,
|
|
3485
|
-
output: schemaKeys.output ? [
|
|
3486
|
-
...schemaKeys.output,
|
|
3487
|
-
...CONSTANT_KEYS
|
|
3488
|
-
] : null,
|
|
3489
|
-
context: schemaKeys.context ? [
|
|
3490
|
-
...schemaKeys.context,
|
|
3491
|
-
...CONSTANT_KEYS
|
|
3492
|
-
] : null
|
|
3493
|
-
};
|
|
3494
|
-
}
|
|
3495
|
-
};
|
|
3496
|
-
__name(LangGraphAgent, "LangGraphAgent");
|
|
3497
3379
|
var CopilotRuntime = class {
|
|
3498
3380
|
params;
|
|
3499
3381
|
observability;
|
|
@@ -3503,9 +3385,10 @@ var CopilotRuntime = class {
|
|
|
3503
3385
|
_instance;
|
|
3504
3386
|
constructor(params) {
|
|
3505
3387
|
const agents = (params == null ? void 0 : params.agents) ?? {};
|
|
3388
|
+
const endpointAgents = this.assignEndpointsToAgents((params == null ? void 0 : params.remoteEndpoints) ?? []);
|
|
3506
3389
|
this.runtimeArgs = {
|
|
3507
3390
|
agents: {
|
|
3508
|
-
...
|
|
3391
|
+
...endpointAgents,
|
|
3509
3392
|
...agents
|
|
3510
3393
|
},
|
|
3511
3394
|
runner: (params == null ? void 0 : params.runner) ?? new InMemoryAgentRunner(),
|
|
@@ -3524,29 +3407,16 @@ var CopilotRuntime = class {
|
|
|
3524
3407
|
return this._instance;
|
|
3525
3408
|
}
|
|
3526
3409
|
assignEndpointsToAgents(endpoints) {
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
deploymentUrl: lgEndpoint.deploymentUrl,
|
|
3535
|
-
langsmithApiKey: lgEndpoint.langsmithApiKey,
|
|
3536
|
-
graphId
|
|
3537
|
-
});
|
|
3538
|
-
});
|
|
3539
|
-
return {
|
|
3540
|
-
...acc,
|
|
3541
|
-
...lgAgents
|
|
3542
|
-
};
|
|
3543
|
-
}
|
|
3544
|
-
return acc;
|
|
3545
|
-
}, {});
|
|
3410
|
+
let result = {};
|
|
3411
|
+
if (endpoints.some((endpoint) => resolveEndpointType(endpoint) == EndpointType.LangGraphPlatform)) {
|
|
3412
|
+
throw new CopilotKitMisuseError({
|
|
3413
|
+
message: 'LangGraphPlatformEndpoint in remoteEndpoints is deprecated. Please use the "agents" option instead with LangGraphAgent from "@copilotkit/runtime/langgraph". Example: agents: { myAgent: new LangGraphAgent({ deploymentUrl: "...", graphId: "..." }) }'
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
return result;
|
|
3546
3417
|
}
|
|
3547
3418
|
handleServiceAdapter(serviceAdapter) {
|
|
3548
3419
|
this.runtimeArgs.agents = Promise.resolve(this.runtimeArgs.agents ?? {}).then(async (agents) => {
|
|
3549
|
-
var _a;
|
|
3550
3420
|
let agentsList = agents;
|
|
3551
3421
|
const isAgentsListEmpty = !Object.keys(agents).length;
|
|
3552
3422
|
const hasServiceAdapter = Boolean(serviceAdapter);
|
|
@@ -3564,7 +3434,7 @@ var CopilotRuntime = class {
|
|
|
3564
3434
|
model: `${serviceAdapter.provider}/${serviceAdapter.model}`
|
|
3565
3435
|
});
|
|
3566
3436
|
}
|
|
3567
|
-
if (
|
|
3437
|
+
if (this.params.actions) {
|
|
3568
3438
|
const mcpTools = await this.getToolsFromMCP();
|
|
3569
3439
|
agentsList = this.assignToolsToAgents(agents, [
|
|
3570
3440
|
...this.getToolsFromActions(this.params.actions),
|
|
@@ -3887,6 +3757,38 @@ _ts_decorate19([
|
|
|
3887
3757
|
AgentsResponse = _ts_decorate19([
|
|
3888
3758
|
ObjectType()
|
|
3889
3759
|
], AgentsResponse);
|
|
3760
|
+
|
|
3761
|
+
// src/agents/langgraph/events.ts
|
|
3762
|
+
var LangGraphEventTypes;
|
|
3763
|
+
(function(LangGraphEventTypes2) {
|
|
3764
|
+
LangGraphEventTypes2["OnChainStart"] = "on_chain_start";
|
|
3765
|
+
LangGraphEventTypes2["OnChainStream"] = "on_chain_stream";
|
|
3766
|
+
LangGraphEventTypes2["OnChainEnd"] = "on_chain_end";
|
|
3767
|
+
LangGraphEventTypes2["OnChatModelStart"] = "on_chat_model_start";
|
|
3768
|
+
LangGraphEventTypes2["OnChatModelStream"] = "on_chat_model_stream";
|
|
3769
|
+
LangGraphEventTypes2["OnChatModelEnd"] = "on_chat_model_end";
|
|
3770
|
+
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
3771
|
+
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
3772
|
+
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
3773
|
+
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
3774
|
+
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
3775
|
+
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
3776
|
+
LangGraphEventTypes2["OnInterrupt"] = "on_interrupt";
|
|
3777
|
+
LangGraphEventTypes2["OnCopilotKitInterrupt"] = "on_copilotkit_interrupt";
|
|
3778
|
+
LangGraphEventTypes2["OnCopilotKitError"] = "on_copilotkit_error";
|
|
3779
|
+
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
3780
|
+
var MetaEventNames;
|
|
3781
|
+
(function(MetaEventNames2) {
|
|
3782
|
+
MetaEventNames2["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
|
|
3783
|
+
MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
3784
|
+
})(MetaEventNames || (MetaEventNames = {}));
|
|
3785
|
+
var CustomEventNames;
|
|
3786
|
+
(function(CustomEventNames2) {
|
|
3787
|
+
CustomEventNames2["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3788
|
+
CustomEventNames2["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3789
|
+
CustomEventNames2["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3790
|
+
CustomEventNames2["CopilotKitExit"] = "copilotkit_exit";
|
|
3791
|
+
})(CustomEventNames || (CustomEventNames = {}));
|
|
3890
3792
|
function _ts_decorate20(decorators, target, key, desc) {
|
|
3891
3793
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3892
3794
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4718,7 +4620,9 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
|
4718
4620
|
const logger2 = commonConfig.logging;
|
|
4719
4621
|
logger2.debug("Creating NextJS App Router endpoint");
|
|
4720
4622
|
const serviceAdapter = options.serviceAdapter;
|
|
4721
|
-
|
|
4623
|
+
if (serviceAdapter) {
|
|
4624
|
+
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
4625
|
+
}
|
|
4722
4626
|
const copilotRoute = createCopilotEndpointSingleRoute({
|
|
4723
4627
|
runtime: options.runtime.instance,
|
|
4724
4628
|
basePath: options.baseUrl ?? options.endpoint
|
|
@@ -4748,12 +4652,59 @@ function readableStreamToNodeStream(webStream) {
|
|
|
4748
4652
|
}
|
|
4749
4653
|
__name(readableStreamToNodeStream, "readableStreamToNodeStream");
|
|
4750
4654
|
function getFullUrl(req) {
|
|
4751
|
-
const
|
|
4655
|
+
const expressPath = req.originalUrl ?? (req.baseUrl ? `${req.baseUrl}${req.url ?? ""}` : void 0);
|
|
4656
|
+
const path = expressPath || req.url || "/";
|
|
4752
4657
|
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
4753
4658
|
const proto = req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http");
|
|
4754
4659
|
return `${proto}://${host}${path}`;
|
|
4755
4660
|
}
|
|
4756
4661
|
__name(getFullUrl, "getFullUrl");
|
|
4662
|
+
function toHeaders(rawHeaders) {
|
|
4663
|
+
const headers = new Headers();
|
|
4664
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
4665
|
+
if (value === void 0)
|
|
4666
|
+
continue;
|
|
4667
|
+
if (Array.isArray(value)) {
|
|
4668
|
+
value.forEach((entry) => headers.append(key, entry));
|
|
4669
|
+
continue;
|
|
4670
|
+
}
|
|
4671
|
+
headers.append(key, value);
|
|
4672
|
+
}
|
|
4673
|
+
return headers;
|
|
4674
|
+
}
|
|
4675
|
+
__name(toHeaders, "toHeaders");
|
|
4676
|
+
function isStreamConsumed(req) {
|
|
4677
|
+
const readableState = req._readableState;
|
|
4678
|
+
return Boolean(req.readableEnded || req.complete || (readableState == null ? void 0 : readableState.ended) || (readableState == null ? void 0 : readableState.endEmitted));
|
|
4679
|
+
}
|
|
4680
|
+
__name(isStreamConsumed, "isStreamConsumed");
|
|
4681
|
+
function synthesizeBodyFromParsedBody(parsedBody, headers) {
|
|
4682
|
+
if (parsedBody === null || parsedBody === void 0) {
|
|
4683
|
+
return {
|
|
4684
|
+
body: null
|
|
4685
|
+
};
|
|
4686
|
+
}
|
|
4687
|
+
if (parsedBody instanceof Buffer || parsedBody instanceof Uint8Array) {
|
|
4688
|
+
return {
|
|
4689
|
+
body: parsedBody
|
|
4690
|
+
};
|
|
4691
|
+
}
|
|
4692
|
+
if (typeof parsedBody === "string") {
|
|
4693
|
+
return {
|
|
4694
|
+
body: parsedBody,
|
|
4695
|
+
contentType: headers.get("content-type") ?? "text/plain"
|
|
4696
|
+
};
|
|
4697
|
+
}
|
|
4698
|
+
return {
|
|
4699
|
+
body: JSON.stringify(parsedBody),
|
|
4700
|
+
contentType: "application/json"
|
|
4701
|
+
};
|
|
4702
|
+
}
|
|
4703
|
+
__name(synthesizeBodyFromParsedBody, "synthesizeBodyFromParsedBody");
|
|
4704
|
+
function isDisturbedOrLockedError(error) {
|
|
4705
|
+
return error instanceof TypeError && typeof error.message === "string" && (error.message.includes("disturbed") || error.message.includes("locked"));
|
|
4706
|
+
}
|
|
4707
|
+
__name(isDisturbedOrLockedError, "isDisturbedOrLockedError");
|
|
4757
4708
|
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
4758
4709
|
var _a;
|
|
4759
4710
|
const commonConfig = getCommonConfig(options);
|
|
@@ -4771,7 +4722,9 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4771
4722
|
const logger2 = commonConfig.logging;
|
|
4772
4723
|
logger2.debug("Creating Node HTTP endpoint");
|
|
4773
4724
|
const serviceAdapter = options.serviceAdapter;
|
|
4774
|
-
|
|
4725
|
+
if (serviceAdapter) {
|
|
4726
|
+
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
4727
|
+
}
|
|
4775
4728
|
const honoApp = createCopilotEndpointSingleRoute({
|
|
4776
4729
|
runtime: options.runtime.instance,
|
|
4777
4730
|
basePath: options.baseUrl ?? options.endpoint
|
|
@@ -4779,14 +4732,59 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4779
4732
|
return /* @__PURE__ */ __name(async function handler(req, res) {
|
|
4780
4733
|
const url = getFullUrl(req);
|
|
4781
4734
|
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
4782
|
-
const
|
|
4735
|
+
const baseHeaders = toHeaders(req.headers);
|
|
4736
|
+
const parsedBody = req.body;
|
|
4737
|
+
const streamConsumed = isStreamConsumed(req) || parsedBody !== void 0;
|
|
4738
|
+
const canStream = hasBody && !streamConsumed;
|
|
4739
|
+
let requestBody = void 0;
|
|
4740
|
+
let useDuplex = false;
|
|
4741
|
+
if (hasBody && canStream) {
|
|
4742
|
+
requestBody = req;
|
|
4743
|
+
useDuplex = true;
|
|
4744
|
+
}
|
|
4745
|
+
if (hasBody && streamConsumed) {
|
|
4746
|
+
if (parsedBody !== void 0) {
|
|
4747
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, baseHeaders);
|
|
4748
|
+
requestBody = synthesized.body ?? void 0;
|
|
4749
|
+
baseHeaders.delete("content-length");
|
|
4750
|
+
if (synthesized.contentType) {
|
|
4751
|
+
baseHeaders.set("content-type", synthesized.contentType);
|
|
4752
|
+
}
|
|
4753
|
+
logger2.debug("Request stream already consumed; using parsed req.body to rebuild request.");
|
|
4754
|
+
} else {
|
|
4755
|
+
logger2.warn("Request stream consumed with no available body; sending empty payload.");
|
|
4756
|
+
requestBody = void 0;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
const buildRequest = /* @__PURE__ */ __name((body, headers, duplex) => new Request(url, {
|
|
4783
4760
|
method: req.method,
|
|
4784
|
-
headers
|
|
4785
|
-
body
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4761
|
+
headers,
|
|
4762
|
+
body,
|
|
4763
|
+
duplex: duplex ? "half" : void 0
|
|
4764
|
+
}), "buildRequest");
|
|
4765
|
+
let response;
|
|
4766
|
+
try {
|
|
4767
|
+
response = await honoApp.fetch(buildRequest(requestBody, baseHeaders, useDuplex));
|
|
4768
|
+
} catch (error) {
|
|
4769
|
+
if (isDisturbedOrLockedError(error) && hasBody) {
|
|
4770
|
+
logger2.warn("Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.");
|
|
4771
|
+
const fallbackHeaders = new Headers(baseHeaders);
|
|
4772
|
+
let fallbackBody;
|
|
4773
|
+
if (parsedBody !== void 0) {
|
|
4774
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, fallbackHeaders);
|
|
4775
|
+
fallbackBody = synthesized.body ?? void 0;
|
|
4776
|
+
fallbackHeaders.delete("content-length");
|
|
4777
|
+
if (synthesized.contentType) {
|
|
4778
|
+
fallbackHeaders.set("content-type", synthesized.contentType);
|
|
4779
|
+
}
|
|
4780
|
+
} else {
|
|
4781
|
+
fallbackBody = void 0;
|
|
4782
|
+
}
|
|
4783
|
+
response = await honoApp.fetch(buildRequest(fallbackBody, fallbackHeaders, false));
|
|
4784
|
+
} else {
|
|
4785
|
+
throw error;
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4790
4788
|
res.statusCode = response.status;
|
|
4791
4789
|
response.headers.forEach((value, key) => {
|
|
4792
4790
|
res.setHeader(key, value);
|
|
@@ -4849,6 +4847,22 @@ function copilotRuntimeNestEndpoint(options) {
|
|
|
4849
4847
|
return copilotRuntimeNodeHttpEndpoint(options);
|
|
4850
4848
|
}
|
|
4851
4849
|
__name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
4850
|
+
|
|
4851
|
+
// src/lib/index.ts
|
|
4852
|
+
var LangGraphAgent = class {
|
|
4853
|
+
constructor() {
|
|
4854
|
+
throw new Error("LangGraphAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead");
|
|
4855
|
+
}
|
|
4856
|
+
};
|
|
4857
|
+
__name(LangGraphAgent, "LangGraphAgent");
|
|
4858
|
+
var LangGraphHttpAgent = class {
|
|
4859
|
+
constructor() {
|
|
4860
|
+
throw new Error("LangGraphHttpAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead");
|
|
4861
|
+
}
|
|
4862
|
+
};
|
|
4863
|
+
__name(LangGraphHttpAgent, "LangGraphHttpAgent");
|
|
4864
|
+
|
|
4865
|
+
// src/service-adapters/langchain/langserve.ts
|
|
4852
4866
|
var RemoteChain = class {
|
|
4853
4867
|
name;
|
|
4854
4868
|
description;
|
|
@@ -4871,6 +4885,7 @@ var RemoteChain = class {
|
|
|
4871
4885
|
description: this.description,
|
|
4872
4886
|
parameters: this.parameters,
|
|
4873
4887
|
handler: async (args) => {
|
|
4888
|
+
const { RemoteRunnable } = __require("langchain/runnables/remote");
|
|
4874
4889
|
const runnable = new RemoteRunnable({
|
|
4875
4890
|
url: this.chainUrl
|
|
4876
4891
|
});
|
|
@@ -5083,7 +5098,9 @@ var AnthropicAdapter = class {
|
|
|
5083
5098
|
return "AnthropicAdapter";
|
|
5084
5099
|
}
|
|
5085
5100
|
constructor(params) {
|
|
5086
|
-
|
|
5101
|
+
if (params == null ? void 0 : params.anthropic) {
|
|
5102
|
+
this._anthropic = params.anthropic;
|
|
5103
|
+
}
|
|
5087
5104
|
if (params == null ? void 0 : params.model) {
|
|
5088
5105
|
this.model = params.model;
|
|
5089
5106
|
}
|
|
@@ -5091,6 +5108,13 @@ var AnthropicAdapter = class {
|
|
|
5091
5108
|
enabled: false
|
|
5092
5109
|
};
|
|
5093
5110
|
}
|
|
5111
|
+
ensureAnthropic() {
|
|
5112
|
+
if (!this._anthropic) {
|
|
5113
|
+
const Anthropic = __require("@anthropic-ai/sdk").default;
|
|
5114
|
+
this._anthropic = new Anthropic({});
|
|
5115
|
+
}
|
|
5116
|
+
return this._anthropic;
|
|
5117
|
+
}
|
|
5094
5118
|
/**
|
|
5095
5119
|
* Adds cache control to system prompt
|
|
5096
5120
|
*/
|
|
@@ -5231,7 +5255,8 @@ var AnthropicAdapter = class {
|
|
|
5231
5255
|
},
|
|
5232
5256
|
stream: true
|
|
5233
5257
|
};
|
|
5234
|
-
const
|
|
5258
|
+
const anthropic = this.ensureAnthropic();
|
|
5259
|
+
const stream = await anthropic.messages.create(createParams);
|
|
5235
5260
|
eventSource.stream(async (eventStream$) => {
|
|
5236
5261
|
let mode = null;
|
|
5237
5262
|
let didOutputText = false;
|
|
@@ -5376,6 +5401,7 @@ var ExperimentalOllamaAdapter = class {
|
|
|
5376
5401
|
}
|
|
5377
5402
|
async process(request) {
|
|
5378
5403
|
const { messages, actions, eventSource } = request;
|
|
5404
|
+
const { Ollama } = __require("@langchain/community/llms/ollama");
|
|
5379
5405
|
const ollama = new Ollama({
|
|
5380
5406
|
model: this.model
|
|
5381
5407
|
});
|
|
@@ -5403,6 +5429,8 @@ var ExperimentalOllamaAdapter = class {
|
|
|
5403
5429
|
}
|
|
5404
5430
|
};
|
|
5405
5431
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
5432
|
+
|
|
5433
|
+
// src/service-adapters/bedrock/bedrock-adapter.ts
|
|
5406
5434
|
var DEFAULT_MODEL6 = "amazon.nova-lite-v1:0";
|
|
5407
5435
|
var BedrockAdapter = class extends LangChainAdapter {
|
|
5408
5436
|
provider = "bedrock";
|
|
@@ -5410,6 +5438,7 @@ var BedrockAdapter = class extends LangChainAdapter {
|
|
|
5410
5438
|
constructor(options) {
|
|
5411
5439
|
super({
|
|
5412
5440
|
chainFn: async ({ messages, tools, threadId }) => {
|
|
5441
|
+
const { ChatBedrockConverse } = __require("@langchain/aws");
|
|
5413
5442
|
this.model = (options == null ? void 0 : options.model) ?? "amazon.nova-lite-v1:0";
|
|
5414
5443
|
const model = new ChatBedrockConverse({
|
|
5415
5444
|
model: this.model,
|
|
@@ -5438,6 +5467,6 @@ var EmptyAdapter = class {
|
|
|
5438
5467
|
__name(EmptyAdapter, "EmptyAdapter");
|
|
5439
5468
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
5440
5469
|
|
|
5441
|
-
export { AnthropicAdapter, BedrockAdapter, CopilotRuntime,
|
|
5470
|
+
export { AnthropicAdapter, BedrockAdapter, CopilotRuntime, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter, GoogleGenerativeAIAdapter, GroqAdapter, GuardrailsValidationFailureResponse, LangChainAdapter, LangGraphAgent, LangGraphHttpAgent, MessageStreamInterruptedResponse, OpenAIAdapter, OpenAIAssistantAdapter, RemoteChain, UnifyAdapter, UnknownErrorResponse, addCustomHeaderPlugin, buildSchema, config, convertMCPToolsToActions, convertServiceAdapterError, copilotKitEndpoint, copilotRuntimeNestEndpoint, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint, copilotRuntimeNodeExpressEndpoint, copilotRuntimeNodeHttpEndpoint, createContext, createLogger, extractParametersFromSchema, generateMcpToolInstructions, getCommonConfig, langGraphPlatformEndpoint, readableStreamToNodeStream, resolveEndpointType };
|
|
5442
5471
|
//# sourceMappingURL=out.js.map
|
|
5443
5472
|
//# sourceMappingURL=index.mjs.map
|