@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.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('reflect-metadata');
|
|
4
|
-
var OpenAI = require('openai');
|
|
5
4
|
var shared = require('@copilotkit/shared');
|
|
6
5
|
var messages = require('@langchain/core/messages');
|
|
7
6
|
var tools = require('@langchain/core/tools');
|
|
8
|
-
var promises = require('@langchain/core/callbacks/promises');
|
|
9
|
-
var googleGauth = require('@langchain/google-gauth');
|
|
10
|
-
var groqSdk = require('groq-sdk');
|
|
11
7
|
var typeGraphql = require('type-graphql');
|
|
12
8
|
var rxjs = require('rxjs');
|
|
13
9
|
var graphqlScalars = require('graphql-scalars');
|
|
@@ -16,25 +12,17 @@ var classTransformer = require('class-transformer');
|
|
|
16
12
|
var graphql = require('graphql');
|
|
17
13
|
var crypto = require('crypto');
|
|
18
14
|
var runtime = require('@copilotkitnext/runtime');
|
|
19
|
-
var client = require('@ag-ui/client');
|
|
20
|
-
var langgraph = require('@ag-ui/langgraph');
|
|
21
15
|
var agent = require('@copilotkitnext/agent');
|
|
22
16
|
var pluginDeferStream = require('@graphql-yoga/plugin-defer-stream');
|
|
23
17
|
var createPinoLogger = require('pino');
|
|
24
18
|
var pretty = require('pino-pretty');
|
|
25
19
|
var vercel = require('hono/vercel');
|
|
26
20
|
var stream = require('stream');
|
|
27
|
-
var remote = require('langchain/runnables/remote');
|
|
28
|
-
var Anthropic = require('@anthropic-ai/sdk');
|
|
29
|
-
var ollama = require('@langchain/community/llms/ollama');
|
|
30
|
-
var aws = require('@langchain/aws');
|
|
31
21
|
|
|
32
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
33
23
|
|
|
34
|
-
var OpenAI__default = /*#__PURE__*/_interopDefault(OpenAI);
|
|
35
24
|
var createPinoLogger__default = /*#__PURE__*/_interopDefault(createPinoLogger);
|
|
36
25
|
var pretty__default = /*#__PURE__*/_interopDefault(pretty);
|
|
37
|
-
var Anthropic__default = /*#__PURE__*/_interopDefault(Anthropic);
|
|
38
26
|
|
|
39
27
|
var __create = Object.create;
|
|
40
28
|
var __defProp = Object.defineProperty;
|
|
@@ -43,7 +31,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
43
31
|
var __getProtoOf = Object.getPrototypeOf;
|
|
44
32
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
45
33
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
46
|
-
var
|
|
34
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
35
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
36
|
+
}) : x)(function(x) {
|
|
37
|
+
if (typeof require !== "undefined")
|
|
38
|
+
return require.apply(this, arguments);
|
|
39
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
40
|
+
});
|
|
41
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
47
42
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
48
43
|
};
|
|
49
44
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -77,7 +72,7 @@ var require_package = __commonJS({
|
|
|
77
72
|
publishConfig: {
|
|
78
73
|
access: "public"
|
|
79
74
|
},
|
|
80
|
-
version: "1.50.0-beta.
|
|
75
|
+
version: "1.50.0-beta.2",
|
|
81
76
|
sideEffects: false,
|
|
82
77
|
main: "./dist/index.js",
|
|
83
78
|
module: "./dist/index.mjs",
|
|
@@ -91,6 +86,11 @@ var require_package = __commonJS({
|
|
|
91
86
|
import: "./dist/v2/index.mjs",
|
|
92
87
|
require: "./dist/v2/index.js",
|
|
93
88
|
types: "./dist/v2/index.d.ts"
|
|
89
|
+
},
|
|
90
|
+
"./langgraph": {
|
|
91
|
+
import: "./dist/langgraph.mjs",
|
|
92
|
+
require: "./dist/langgraph.js",
|
|
93
|
+
types: "./dist/langgraph.d.ts"
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
types: "./dist/index.d.ts",
|
|
@@ -120,29 +120,21 @@ var require_package = __commonJS({
|
|
|
120
120
|
tsconfig: "workspace:*",
|
|
121
121
|
tsup: "^6.7.0",
|
|
122
122
|
typescript: "^5.2.3",
|
|
123
|
-
vitest: "^3.2.4"
|
|
124
|
-
"zod-to-json-schema": "^3.23.5"
|
|
123
|
+
vitest: "^3.2.4"
|
|
125
124
|
},
|
|
126
125
|
dependencies: {
|
|
127
|
-
"@anthropic-ai/sdk": "^0.57.0",
|
|
128
126
|
"@copilotkit/shared": "workspace:*",
|
|
129
|
-
"@copilotkitnext/agent": "0.0.
|
|
130
|
-
"@copilotkitnext/runtime": "0.0.
|
|
127
|
+
"@copilotkitnext/agent": "0.0.23",
|
|
128
|
+
"@copilotkitnext/runtime": "0.0.23",
|
|
131
129
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
132
|
-
"@
|
|
133
|
-
"@langchain/community": "^0.3.29",
|
|
130
|
+
"@hono/node-server": "^1.13.5",
|
|
134
131
|
"@langchain/core": "^0.3.38",
|
|
135
|
-
"@langchain/google-gauth": "^0.1.0",
|
|
136
|
-
"@langchain/langgraph-sdk": "^0.0.70",
|
|
137
|
-
"@langchain/openai": "^0.4.2",
|
|
138
132
|
"@scarf/scarf": "^1.3.0",
|
|
139
133
|
"class-transformer": "^0.5.1",
|
|
140
134
|
"class-validator": "^0.14.1",
|
|
141
135
|
graphql: "^16.8.1",
|
|
142
136
|
"graphql-scalars": "^1.23.0",
|
|
143
137
|
"graphql-yoga": "^5.3.1",
|
|
144
|
-
"groq-sdk": "^0.5.0",
|
|
145
|
-
"@hono/node-server": "^1.13.5",
|
|
146
138
|
hono: "^4.10.3",
|
|
147
139
|
langchain: "^0.3.3",
|
|
148
140
|
openai: "^4.85.1",
|
|
@@ -155,11 +147,52 @@ var require_package = __commonJS({
|
|
|
155
147
|
zod: "^3.23.3"
|
|
156
148
|
},
|
|
157
149
|
peerDependencies: {
|
|
158
|
-
"@
|
|
150
|
+
"@anthropic-ai/sdk": "^0.57.0",
|
|
151
|
+
"@ag-ui/client": "^0.0.41",
|
|
159
152
|
"@ag-ui/core": ">=0.0.39",
|
|
160
153
|
"@ag-ui/encoder": ">=0.0.39",
|
|
161
154
|
"@ag-ui/langgraph": ">=0.0.18",
|
|
162
|
-
"@ag-ui/proto": ">=0.0.39"
|
|
155
|
+
"@ag-ui/proto": ">=0.0.39",
|
|
156
|
+
"@langchain/aws": "^0.1.9",
|
|
157
|
+
"@langchain/community": "^0.3.58",
|
|
158
|
+
"@langchain/google-gauth": "^0.1.0",
|
|
159
|
+
"@langchain/langgraph-sdk": "^0.0.70",
|
|
160
|
+
"@langchain/openai": "^0.4.2",
|
|
161
|
+
"groq-sdk": "^0.5.0",
|
|
162
|
+
langchain: "^0.3.3",
|
|
163
|
+
openai: "^4.85.1"
|
|
164
|
+
},
|
|
165
|
+
peerDependenciesMeta: {
|
|
166
|
+
"@anthropic-ai/sdk": {
|
|
167
|
+
optional: true
|
|
168
|
+
},
|
|
169
|
+
"@ag-ui/langgraph": {
|
|
170
|
+
optional: true
|
|
171
|
+
},
|
|
172
|
+
"@langchain/aws": {
|
|
173
|
+
optional: true
|
|
174
|
+
},
|
|
175
|
+
"@langchain/community": {
|
|
176
|
+
optional: true
|
|
177
|
+
},
|
|
178
|
+
"@langchain/google-gauth": {
|
|
179
|
+
optional: true
|
|
180
|
+
},
|
|
181
|
+
"@langchain/langgraph-sdk": {
|
|
182
|
+
optional: true
|
|
183
|
+
},
|
|
184
|
+
"@langchain/openai": {
|
|
185
|
+
optional: true
|
|
186
|
+
},
|
|
187
|
+
"groq-sdk": {
|
|
188
|
+
optional: true
|
|
189
|
+
},
|
|
190
|
+
langchain: {
|
|
191
|
+
optional: true
|
|
192
|
+
},
|
|
193
|
+
openai: {
|
|
194
|
+
optional: true
|
|
195
|
+
}
|
|
163
196
|
},
|
|
164
197
|
keywords: [
|
|
165
198
|
"copilotkit",
|
|
@@ -410,13 +443,22 @@ var OpenAIAdapter = class {
|
|
|
410
443
|
return "OpenAIAdapter";
|
|
411
444
|
}
|
|
412
445
|
constructor(params) {
|
|
413
|
-
|
|
446
|
+
if (params == null ? void 0 : params.openai) {
|
|
447
|
+
this._openai = params.openai;
|
|
448
|
+
}
|
|
414
449
|
if (params == null ? void 0 : params.model) {
|
|
415
450
|
this.model = params.model;
|
|
416
451
|
}
|
|
417
452
|
this.disableParallelToolCalls = (params == null ? void 0 : params.disableParallelToolCalls) || false;
|
|
418
453
|
this.keepSystemRole = (params == null ? void 0 : params.keepSystemRole) ?? false;
|
|
419
454
|
}
|
|
455
|
+
ensureOpenAI() {
|
|
456
|
+
if (!this._openai) {
|
|
457
|
+
const OpenAI = __require("openai").default;
|
|
458
|
+
this._openai = new OpenAI();
|
|
459
|
+
}
|
|
460
|
+
return this._openai;
|
|
461
|
+
}
|
|
420
462
|
async process(request) {
|
|
421
463
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
422
464
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
@@ -451,7 +493,8 @@ var OpenAIAdapter = class {
|
|
|
451
493
|
};
|
|
452
494
|
}
|
|
453
495
|
try {
|
|
454
|
-
const
|
|
496
|
+
const openai = this.ensureOpenAI();
|
|
497
|
+
const stream = openai.beta.chat.completions.stream({
|
|
455
498
|
model,
|
|
456
499
|
stream: true,
|
|
457
500
|
messages: openaiMessages,
|
|
@@ -811,26 +854,32 @@ var LangChainAdapter = class {
|
|
|
811
854
|
threadId
|
|
812
855
|
};
|
|
813
856
|
} finally {
|
|
814
|
-
|
|
857
|
+
const { awaitAllCallbacks } = __require("@langchain/core/callbacks/promises");
|
|
858
|
+
await awaitAllCallbacks();
|
|
815
859
|
}
|
|
816
860
|
}
|
|
817
861
|
};
|
|
818
862
|
__name(LangChainAdapter, "LangChainAdapter");
|
|
863
|
+
|
|
864
|
+
// src/service-adapters/google/google-genai-adapter.ts
|
|
819
865
|
var DEFAULT_MODEL2 = "gemini-1.5-pro";
|
|
820
866
|
var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
821
867
|
provider = "google";
|
|
822
868
|
model = DEFAULT_MODEL2;
|
|
823
869
|
constructor(options) {
|
|
824
870
|
super({
|
|
825
|
-
chainFn: async ({ messages
|
|
826
|
-
const
|
|
827
|
-
|
|
871
|
+
chainFn: async ({ messages, tools, threadId }) => {
|
|
872
|
+
const { ChatGoogle } = __require("@langchain/google-gauth");
|
|
873
|
+
const { AIMessage: AIMessage2 } = __require("@langchain/core/messages");
|
|
874
|
+
const filteredMessages = messages.filter((message) => {
|
|
875
|
+
if (!(message instanceof AIMessage2)) {
|
|
828
876
|
return true;
|
|
829
877
|
}
|
|
830
|
-
|
|
878
|
+
const aiMsg = message;
|
|
879
|
+
return aiMsg.content && String(aiMsg.content).trim().length > 0 || aiMsg.tool_calls && aiMsg.tool_calls.length > 0;
|
|
831
880
|
});
|
|
832
881
|
this.model = (options == null ? void 0 : options.model) ?? "gemini-1.5-pro";
|
|
833
|
-
const model = new
|
|
882
|
+
const model = new ChatGoogle({
|
|
834
883
|
apiKey: (options == null ? void 0 : options.apiKey) ?? process.env.GOOGLE_API_KEY,
|
|
835
884
|
modelName: this.model,
|
|
836
885
|
apiVersion: "v1beta"
|
|
@@ -845,8 +894,10 @@ var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
|
845
894
|
}
|
|
846
895
|
};
|
|
847
896
|
__name(GoogleGenerativeAIAdapter, "GoogleGenerativeAIAdapter");
|
|
897
|
+
|
|
898
|
+
// src/service-adapters/openai/openai-assistant-adapter.ts
|
|
848
899
|
var OpenAIAssistantAdapter = class {
|
|
849
|
-
|
|
900
|
+
_openai;
|
|
850
901
|
codeInterpreterEnabled;
|
|
851
902
|
assistantId;
|
|
852
903
|
fileSearchEnabled;
|
|
@@ -856,19 +907,29 @@ var OpenAIAssistantAdapter = class {
|
|
|
856
907
|
return "OpenAIAssistantAdapter";
|
|
857
908
|
}
|
|
858
909
|
constructor(params) {
|
|
859
|
-
|
|
910
|
+
if (params.openai) {
|
|
911
|
+
this._openai = params.openai;
|
|
912
|
+
}
|
|
860
913
|
this.codeInterpreterEnabled = params.codeInterpreterEnabled === false || true;
|
|
861
914
|
this.fileSearchEnabled = params.fileSearchEnabled === false || true;
|
|
862
915
|
this.assistantId = params.assistantId;
|
|
863
916
|
this.disableParallelToolCalls = (params == null ? void 0 : params.disableParallelToolCalls) || false;
|
|
864
917
|
this.keepSystemRole = (params == null ? void 0 : params.keepSystemRole) ?? false;
|
|
865
918
|
}
|
|
919
|
+
ensureOpenAI() {
|
|
920
|
+
if (!this._openai) {
|
|
921
|
+
const OpenAI = __require("openai").default;
|
|
922
|
+
this._openai = new OpenAI({});
|
|
923
|
+
}
|
|
924
|
+
return this._openai;
|
|
925
|
+
}
|
|
866
926
|
async process(request) {
|
|
867
927
|
var _a, _b;
|
|
868
928
|
const { messages, actions, eventSource, runId, forwardedParameters } = request;
|
|
869
929
|
let threadId = (_b = (_a = request.extensions) == null ? void 0 : _a.openaiAssistantAPI) == null ? void 0 : _b.threadId;
|
|
930
|
+
const openai = this.ensureOpenAI();
|
|
870
931
|
if (!threadId) {
|
|
871
|
-
threadId = (await
|
|
932
|
+
threadId = (await openai.beta.threads.create()).id;
|
|
872
933
|
}
|
|
873
934
|
const lastMessage = messages.at(-1);
|
|
874
935
|
let nextRunId = void 0;
|
|
@@ -892,7 +953,8 @@ var OpenAIAssistantAdapter = class {
|
|
|
892
953
|
};
|
|
893
954
|
}
|
|
894
955
|
async submitToolOutputs(threadId, runId, messages, eventSource) {
|
|
895
|
-
|
|
956
|
+
const openai = this.ensureOpenAI();
|
|
957
|
+
let run = await openai.beta.threads.runs.retrieve(threadId, runId);
|
|
896
958
|
if (!run.required_action) {
|
|
897
959
|
throw new Error("No tool outputs required");
|
|
898
960
|
}
|
|
@@ -907,7 +969,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
907
969
|
output: message.result
|
|
908
970
|
};
|
|
909
971
|
});
|
|
910
|
-
const stream =
|
|
972
|
+
const stream = openai.beta.threads.runs.submitToolOutputsStream(threadId, runId, {
|
|
911
973
|
tool_outputs: toolOutputs,
|
|
912
974
|
...this.disableParallelToolCalls && {
|
|
913
975
|
parallel_tool_calls: false
|
|
@@ -917,6 +979,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
917
979
|
return runId;
|
|
918
980
|
}
|
|
919
981
|
async submitUserMessage(threadId, messages, actions, eventSource, forwardedParameters) {
|
|
982
|
+
const openai = this.ensureOpenAI();
|
|
920
983
|
messages = [
|
|
921
984
|
...messages
|
|
922
985
|
];
|
|
@@ -928,7 +991,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
928
991
|
if (userMessage.role !== "user") {
|
|
929
992
|
throw new Error("No user message found");
|
|
930
993
|
}
|
|
931
|
-
await
|
|
994
|
+
await openai.beta.threads.messages.create(threadId, {
|
|
932
995
|
role: "user",
|
|
933
996
|
content: userMessage.content
|
|
934
997
|
});
|
|
@@ -946,7 +1009,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
946
1009
|
}
|
|
947
1010
|
] : []
|
|
948
1011
|
];
|
|
949
|
-
let stream =
|
|
1012
|
+
let stream = openai.beta.threads.runs.stream(threadId, {
|
|
950
1013
|
assistant_id: this.assistantId,
|
|
951
1014
|
instructions,
|
|
952
1015
|
tools,
|
|
@@ -1065,7 +1128,8 @@ var UnifyAdapter = class {
|
|
|
1065
1128
|
}
|
|
1066
1129
|
async process(request) {
|
|
1067
1130
|
const tools = request.actions.map(convertActionInputToOpenAITool);
|
|
1068
|
-
const
|
|
1131
|
+
const OpenAI = __require("openai").default;
|
|
1132
|
+
const openai = new OpenAI({
|
|
1069
1133
|
apiKey: this.apiKey,
|
|
1070
1134
|
baseURL: "https://api.unify.ai/v0/"
|
|
1071
1135
|
});
|
|
@@ -1176,12 +1240,21 @@ var GroqAdapter = class {
|
|
|
1176
1240
|
return "GroqAdapter";
|
|
1177
1241
|
}
|
|
1178
1242
|
constructor(params) {
|
|
1179
|
-
|
|
1243
|
+
if (params == null ? void 0 : params.groq) {
|
|
1244
|
+
this._groq = params.groq;
|
|
1245
|
+
}
|
|
1180
1246
|
if (params == null ? void 0 : params.model) {
|
|
1181
1247
|
this.model = params.model;
|
|
1182
1248
|
}
|
|
1183
1249
|
this.disableParallelToolCalls = (params == null ? void 0 : params.disableParallelToolCalls) || false;
|
|
1184
1250
|
}
|
|
1251
|
+
ensureGroq() {
|
|
1252
|
+
if (!this._groq) {
|
|
1253
|
+
const { Groq } = __require("groq-sdk");
|
|
1254
|
+
this._groq = new Groq({});
|
|
1255
|
+
}
|
|
1256
|
+
return this._groq;
|
|
1257
|
+
}
|
|
1185
1258
|
async process(request) {
|
|
1186
1259
|
const { threadId, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
1187
1260
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
@@ -1200,7 +1273,8 @@ var GroqAdapter = class {
|
|
|
1200
1273
|
}
|
|
1201
1274
|
let stream;
|
|
1202
1275
|
try {
|
|
1203
|
-
|
|
1276
|
+
const groq = this.ensureGroq();
|
|
1277
|
+
stream = await groq.chat.completions.create({
|
|
1204
1278
|
model,
|
|
1205
1279
|
stream: true,
|
|
1206
1280
|
messages: openaiMessages,
|
|
@@ -3309,199 +3383,6 @@ When using these tools:
|
|
|
3309
3383
|
7. Always check tool responses to determine your next action`;
|
|
3310
3384
|
}
|
|
3311
3385
|
__name(generateMcpToolInstructions, "generateMcpToolInstructions");
|
|
3312
|
-
|
|
3313
|
-
// src/agents/langgraph/events.ts
|
|
3314
|
-
var LangGraphEventTypes;
|
|
3315
|
-
(function(LangGraphEventTypes2) {
|
|
3316
|
-
LangGraphEventTypes2["OnChainStart"] = "on_chain_start";
|
|
3317
|
-
LangGraphEventTypes2["OnChainStream"] = "on_chain_stream";
|
|
3318
|
-
LangGraphEventTypes2["OnChainEnd"] = "on_chain_end";
|
|
3319
|
-
LangGraphEventTypes2["OnChatModelStart"] = "on_chat_model_start";
|
|
3320
|
-
LangGraphEventTypes2["OnChatModelStream"] = "on_chat_model_stream";
|
|
3321
|
-
LangGraphEventTypes2["OnChatModelEnd"] = "on_chat_model_end";
|
|
3322
|
-
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
3323
|
-
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
3324
|
-
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
3325
|
-
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
3326
|
-
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
3327
|
-
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
3328
|
-
LangGraphEventTypes2["OnInterrupt"] = "on_interrupt";
|
|
3329
|
-
LangGraphEventTypes2["OnCopilotKitInterrupt"] = "on_copilotkit_interrupt";
|
|
3330
|
-
LangGraphEventTypes2["OnCopilotKitError"] = "on_copilotkit_error";
|
|
3331
|
-
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
3332
|
-
var MetaEventNames;
|
|
3333
|
-
(function(MetaEventNames2) {
|
|
3334
|
-
MetaEventNames2["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
|
|
3335
|
-
MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
3336
|
-
})(MetaEventNames || (MetaEventNames = {}));
|
|
3337
|
-
var CustomEventNames;
|
|
3338
|
-
(function(CustomEventNames3) {
|
|
3339
|
-
CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3340
|
-
CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3341
|
-
CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3342
|
-
CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
|
|
3343
|
-
})(CustomEventNames || (CustomEventNames = {}));
|
|
3344
|
-
exports.CustomEventNames = void 0;
|
|
3345
|
-
(function(CustomEventNames3) {
|
|
3346
|
-
CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3347
|
-
CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3348
|
-
CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3349
|
-
CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
|
|
3350
|
-
})(exports.CustomEventNames || (exports.CustomEventNames = {}));
|
|
3351
|
-
var LangGraphAgent = class extends langgraph.LangGraphAgent {
|
|
3352
|
-
constructor(config2) {
|
|
3353
|
-
super(config2);
|
|
3354
|
-
}
|
|
3355
|
-
// @ts-ignore
|
|
3356
|
-
clone() {
|
|
3357
|
-
return new LangGraphAgent(this.config);
|
|
3358
|
-
}
|
|
3359
|
-
dispatchEvent(event) {
|
|
3360
|
-
if (event.type === client.EventType.CUSTOM) {
|
|
3361
|
-
const customEvent = event;
|
|
3362
|
-
if (customEvent.name === "copilotkit_manually_emit_message") {
|
|
3363
|
-
this.subscriber.next({
|
|
3364
|
-
type: client.EventType.TEXT_MESSAGE_START,
|
|
3365
|
-
role: "assistant",
|
|
3366
|
-
messageId: customEvent.value.message_id,
|
|
3367
|
-
rawEvent: event
|
|
3368
|
-
});
|
|
3369
|
-
this.subscriber.next({
|
|
3370
|
-
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
3371
|
-
messageId: customEvent.value.message_id,
|
|
3372
|
-
delta: customEvent.value.message,
|
|
3373
|
-
rawEvent: event
|
|
3374
|
-
});
|
|
3375
|
-
this.subscriber.next({
|
|
3376
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
3377
|
-
messageId: customEvent.value.message_id,
|
|
3378
|
-
rawEvent: event
|
|
3379
|
-
});
|
|
3380
|
-
return true;
|
|
3381
|
-
}
|
|
3382
|
-
if (customEvent.name === "copilotkit_manually_emit_tool_call") {
|
|
3383
|
-
this.subscriber.next({
|
|
3384
|
-
type: client.EventType.TOOL_CALL_START,
|
|
3385
|
-
toolCallId: customEvent.value.id,
|
|
3386
|
-
toolCallName: customEvent.value.name,
|
|
3387
|
-
parentMessageId: customEvent.value.id,
|
|
3388
|
-
rawEvent: event
|
|
3389
|
-
});
|
|
3390
|
-
this.subscriber.next({
|
|
3391
|
-
type: client.EventType.TOOL_CALL_ARGS,
|
|
3392
|
-
toolCallId: customEvent.value.id,
|
|
3393
|
-
delta: customEvent.value.args,
|
|
3394
|
-
rawEvent: event
|
|
3395
|
-
});
|
|
3396
|
-
this.subscriber.next({
|
|
3397
|
-
type: client.EventType.TOOL_CALL_END,
|
|
3398
|
-
toolCallId: customEvent.value.id,
|
|
3399
|
-
rawEvent: event
|
|
3400
|
-
});
|
|
3401
|
-
return true;
|
|
3402
|
-
}
|
|
3403
|
-
if (customEvent.name === "copilotkit_manually_emit_intermediate_state") {
|
|
3404
|
-
this.activeRun.manuallyEmittedState = customEvent.value;
|
|
3405
|
-
this.dispatchEvent({
|
|
3406
|
-
type: client.EventType.STATE_SNAPSHOT,
|
|
3407
|
-
snapshot: this.getStateSnapshot({
|
|
3408
|
-
values: this.activeRun.manuallyEmittedState
|
|
3409
|
-
}),
|
|
3410
|
-
rawEvent: event
|
|
3411
|
-
});
|
|
3412
|
-
return true;
|
|
3413
|
-
}
|
|
3414
|
-
if (customEvent.name === "copilotkit_exit") {
|
|
3415
|
-
this.subscriber.next({
|
|
3416
|
-
type: client.EventType.CUSTOM,
|
|
3417
|
-
name: "Exit",
|
|
3418
|
-
value: true
|
|
3419
|
-
});
|
|
3420
|
-
return true;
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
const rawEvent = event.rawEvent;
|
|
3424
|
-
if (!rawEvent) {
|
|
3425
|
-
this.subscriber.next(event);
|
|
3426
|
-
return true;
|
|
3427
|
-
}
|
|
3428
|
-
const isMessageEvent = event.type === client.EventType.TEXT_MESSAGE_START || event.type === client.EventType.TEXT_MESSAGE_CONTENT || event.type === client.EventType.TEXT_MESSAGE_END;
|
|
3429
|
-
const isToolEvent = event.type === client.EventType.TOOL_CALL_START || event.type === client.EventType.TOOL_CALL_ARGS || event.type === client.EventType.TOOL_CALL_END;
|
|
3430
|
-
if ("copilotkit:emit-tool-calls" in (rawEvent.metadata || {})) {
|
|
3431
|
-
if (rawEvent.metadata["copilotkit:emit-tool-calls"] === false && isToolEvent) {
|
|
3432
|
-
return false;
|
|
3433
|
-
}
|
|
3434
|
-
}
|
|
3435
|
-
if ("copilotkit:emit-messages" in (rawEvent.metadata || {})) {
|
|
3436
|
-
if (rawEvent.metadata["copilotkit:emit-messages"] === false && isMessageEvent) {
|
|
3437
|
-
return false;
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3440
|
-
this.subscriber.next(event);
|
|
3441
|
-
return true;
|
|
3442
|
-
}
|
|
3443
|
-
// @ts-ignore
|
|
3444
|
-
run(input) {
|
|
3445
|
-
return super.run(input).pipe(rxjs.map((processedEvent) => {
|
|
3446
|
-
var _a, _b, _c, _d, _e;
|
|
3447
|
-
if (processedEvent.type === client.EventType.RAW) {
|
|
3448
|
-
const event = processedEvent.event ?? processedEvent.rawEvent;
|
|
3449
|
-
const eventType = event.event;
|
|
3450
|
-
const toolCallData = (_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.tool_call_chunks) == null ? void 0 : _c[0];
|
|
3451
|
-
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));
|
|
3452
|
-
if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {
|
|
3453
|
-
return {
|
|
3454
|
-
type: client.EventType.CUSTOM,
|
|
3455
|
-
name: "PredictState",
|
|
3456
|
-
value: event.metadata["copilotkit:emit-intermediate-state"]
|
|
3457
|
-
};
|
|
3458
|
-
}
|
|
3459
|
-
}
|
|
3460
|
-
return processedEvent;
|
|
3461
|
-
}));
|
|
3462
|
-
}
|
|
3463
|
-
langGraphDefaultMergeState(state, messages, input) {
|
|
3464
|
-
const aguiMergedState = super.langGraphDefaultMergeState(state, messages, input);
|
|
3465
|
-
const { tools: returnedTools, "ag-ui": agui } = aguiMergedState;
|
|
3466
|
-
const rawCombinedTools = [
|
|
3467
|
-
...returnedTools ?? [],
|
|
3468
|
-
...(agui == null ? void 0 : agui.tools) ?? []
|
|
3469
|
-
];
|
|
3470
|
-
const combinedTools = Array.from(new Map(rawCombinedTools.map((t) => [
|
|
3471
|
-
(t == null ? void 0 : t.id) ?? (t == null ? void 0 : t.name) ?? (t == null ? void 0 : t.key) ?? JSON.stringify(t),
|
|
3472
|
-
t
|
|
3473
|
-
])).values());
|
|
3474
|
-
return {
|
|
3475
|
-
...aguiMergedState,
|
|
3476
|
-
copilotkit: {
|
|
3477
|
-
actions: combinedTools,
|
|
3478
|
-
context: (agui == null ? void 0 : agui.context) ?? []
|
|
3479
|
-
}
|
|
3480
|
-
};
|
|
3481
|
-
}
|
|
3482
|
-
async getSchemaKeys() {
|
|
3483
|
-
const CONSTANT_KEYS = [
|
|
3484
|
-
"copilotkit"
|
|
3485
|
-
];
|
|
3486
|
-
const schemaKeys = await super.getSchemaKeys();
|
|
3487
|
-
return {
|
|
3488
|
-
config: schemaKeys.config,
|
|
3489
|
-
input: schemaKeys.input ? [
|
|
3490
|
-
...schemaKeys.input,
|
|
3491
|
-
...CONSTANT_KEYS
|
|
3492
|
-
] : null,
|
|
3493
|
-
output: schemaKeys.output ? [
|
|
3494
|
-
...schemaKeys.output,
|
|
3495
|
-
...CONSTANT_KEYS
|
|
3496
|
-
] : null,
|
|
3497
|
-
context: schemaKeys.context ? [
|
|
3498
|
-
...schemaKeys.context,
|
|
3499
|
-
...CONSTANT_KEYS
|
|
3500
|
-
] : null
|
|
3501
|
-
};
|
|
3502
|
-
}
|
|
3503
|
-
};
|
|
3504
|
-
__name(LangGraphAgent, "LangGraphAgent");
|
|
3505
3386
|
var CopilotRuntime = class {
|
|
3506
3387
|
params;
|
|
3507
3388
|
observability;
|
|
@@ -3511,9 +3392,10 @@ var CopilotRuntime = class {
|
|
|
3511
3392
|
_instance;
|
|
3512
3393
|
constructor(params) {
|
|
3513
3394
|
const agents = (params == null ? void 0 : params.agents) ?? {};
|
|
3395
|
+
const endpointAgents = this.assignEndpointsToAgents((params == null ? void 0 : params.remoteEndpoints) ?? []);
|
|
3514
3396
|
this.runtimeArgs = {
|
|
3515
3397
|
agents: {
|
|
3516
|
-
...
|
|
3398
|
+
...endpointAgents,
|
|
3517
3399
|
...agents
|
|
3518
3400
|
},
|
|
3519
3401
|
runner: (params == null ? void 0 : params.runner) ?? new runtime.InMemoryAgentRunner(),
|
|
@@ -3532,29 +3414,16 @@ var CopilotRuntime = class {
|
|
|
3532
3414
|
return this._instance;
|
|
3533
3415
|
}
|
|
3534
3416
|
assignEndpointsToAgents(endpoints) {
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
deploymentUrl: lgEndpoint.deploymentUrl,
|
|
3543
|
-
langsmithApiKey: lgEndpoint.langsmithApiKey,
|
|
3544
|
-
graphId
|
|
3545
|
-
});
|
|
3546
|
-
});
|
|
3547
|
-
return {
|
|
3548
|
-
...acc,
|
|
3549
|
-
...lgAgents
|
|
3550
|
-
};
|
|
3551
|
-
}
|
|
3552
|
-
return acc;
|
|
3553
|
-
}, {});
|
|
3417
|
+
let result = {};
|
|
3418
|
+
if (endpoints.some((endpoint) => resolveEndpointType(endpoint) == EndpointType.LangGraphPlatform)) {
|
|
3419
|
+
throw new shared.CopilotKitMisuseError({
|
|
3420
|
+
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: "..." }) }'
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
return result;
|
|
3554
3424
|
}
|
|
3555
3425
|
handleServiceAdapter(serviceAdapter) {
|
|
3556
3426
|
this.runtimeArgs.agents = Promise.resolve(this.runtimeArgs.agents ?? {}).then(async (agents) => {
|
|
3557
|
-
var _a;
|
|
3558
3427
|
let agentsList = agents;
|
|
3559
3428
|
const isAgentsListEmpty = !Object.keys(agents).length;
|
|
3560
3429
|
const hasServiceAdapter = Boolean(serviceAdapter);
|
|
@@ -3572,7 +3441,7 @@ var CopilotRuntime = class {
|
|
|
3572
3441
|
model: `${serviceAdapter.provider}/${serviceAdapter.model}`
|
|
3573
3442
|
});
|
|
3574
3443
|
}
|
|
3575
|
-
if (
|
|
3444
|
+
if (this.params.actions) {
|
|
3576
3445
|
const mcpTools = await this.getToolsFromMCP();
|
|
3577
3446
|
agentsList = this.assignToolsToAgents(agents, [
|
|
3578
3447
|
...this.getToolsFromActions(this.params.actions),
|
|
@@ -3895,6 +3764,38 @@ _ts_decorate19([
|
|
|
3895
3764
|
AgentsResponse = _ts_decorate19([
|
|
3896
3765
|
typeGraphql.ObjectType()
|
|
3897
3766
|
], AgentsResponse);
|
|
3767
|
+
|
|
3768
|
+
// src/agents/langgraph/events.ts
|
|
3769
|
+
var LangGraphEventTypes;
|
|
3770
|
+
(function(LangGraphEventTypes2) {
|
|
3771
|
+
LangGraphEventTypes2["OnChainStart"] = "on_chain_start";
|
|
3772
|
+
LangGraphEventTypes2["OnChainStream"] = "on_chain_stream";
|
|
3773
|
+
LangGraphEventTypes2["OnChainEnd"] = "on_chain_end";
|
|
3774
|
+
LangGraphEventTypes2["OnChatModelStart"] = "on_chat_model_start";
|
|
3775
|
+
LangGraphEventTypes2["OnChatModelStream"] = "on_chat_model_stream";
|
|
3776
|
+
LangGraphEventTypes2["OnChatModelEnd"] = "on_chat_model_end";
|
|
3777
|
+
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
3778
|
+
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
3779
|
+
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
3780
|
+
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
3781
|
+
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
3782
|
+
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
3783
|
+
LangGraphEventTypes2["OnInterrupt"] = "on_interrupt";
|
|
3784
|
+
LangGraphEventTypes2["OnCopilotKitInterrupt"] = "on_copilotkit_interrupt";
|
|
3785
|
+
LangGraphEventTypes2["OnCopilotKitError"] = "on_copilotkit_error";
|
|
3786
|
+
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
3787
|
+
var MetaEventNames;
|
|
3788
|
+
(function(MetaEventNames2) {
|
|
3789
|
+
MetaEventNames2["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
|
|
3790
|
+
MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
3791
|
+
})(MetaEventNames || (MetaEventNames = {}));
|
|
3792
|
+
var CustomEventNames;
|
|
3793
|
+
(function(CustomEventNames2) {
|
|
3794
|
+
CustomEventNames2["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3795
|
+
CustomEventNames2["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3796
|
+
CustomEventNames2["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3797
|
+
CustomEventNames2["CopilotKitExit"] = "copilotkit_exit";
|
|
3798
|
+
})(CustomEventNames || (CustomEventNames = {}));
|
|
3898
3799
|
function _ts_decorate20(decorators, target, key, desc) {
|
|
3899
3800
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3900
3801
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4726,7 +4627,9 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
|
4726
4627
|
const logger2 = commonConfig.logging;
|
|
4727
4628
|
logger2.debug("Creating NextJS App Router endpoint");
|
|
4728
4629
|
const serviceAdapter = options.serviceAdapter;
|
|
4729
|
-
|
|
4630
|
+
if (serviceAdapter) {
|
|
4631
|
+
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
4632
|
+
}
|
|
4730
4633
|
const copilotRoute = runtime.createCopilotEndpointSingleRoute({
|
|
4731
4634
|
runtime: options.runtime.instance,
|
|
4732
4635
|
basePath: options.baseUrl ?? options.endpoint
|
|
@@ -4756,12 +4659,59 @@ function readableStreamToNodeStream(webStream) {
|
|
|
4756
4659
|
}
|
|
4757
4660
|
__name(readableStreamToNodeStream, "readableStreamToNodeStream");
|
|
4758
4661
|
function getFullUrl(req) {
|
|
4759
|
-
const
|
|
4662
|
+
const expressPath = req.originalUrl ?? (req.baseUrl ? `${req.baseUrl}${req.url ?? ""}` : void 0);
|
|
4663
|
+
const path = expressPath || req.url || "/";
|
|
4760
4664
|
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
4761
4665
|
const proto = req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http");
|
|
4762
4666
|
return `${proto}://${host}${path}`;
|
|
4763
4667
|
}
|
|
4764
4668
|
__name(getFullUrl, "getFullUrl");
|
|
4669
|
+
function toHeaders(rawHeaders) {
|
|
4670
|
+
const headers = new Headers();
|
|
4671
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
4672
|
+
if (value === void 0)
|
|
4673
|
+
continue;
|
|
4674
|
+
if (Array.isArray(value)) {
|
|
4675
|
+
value.forEach((entry) => headers.append(key, entry));
|
|
4676
|
+
continue;
|
|
4677
|
+
}
|
|
4678
|
+
headers.append(key, value);
|
|
4679
|
+
}
|
|
4680
|
+
return headers;
|
|
4681
|
+
}
|
|
4682
|
+
__name(toHeaders, "toHeaders");
|
|
4683
|
+
function isStreamConsumed(req) {
|
|
4684
|
+
const readableState = req._readableState;
|
|
4685
|
+
return Boolean(req.readableEnded || req.complete || (readableState == null ? void 0 : readableState.ended) || (readableState == null ? void 0 : readableState.endEmitted));
|
|
4686
|
+
}
|
|
4687
|
+
__name(isStreamConsumed, "isStreamConsumed");
|
|
4688
|
+
function synthesizeBodyFromParsedBody(parsedBody, headers) {
|
|
4689
|
+
if (parsedBody === null || parsedBody === void 0) {
|
|
4690
|
+
return {
|
|
4691
|
+
body: null
|
|
4692
|
+
};
|
|
4693
|
+
}
|
|
4694
|
+
if (parsedBody instanceof Buffer || parsedBody instanceof Uint8Array) {
|
|
4695
|
+
return {
|
|
4696
|
+
body: parsedBody
|
|
4697
|
+
};
|
|
4698
|
+
}
|
|
4699
|
+
if (typeof parsedBody === "string") {
|
|
4700
|
+
return {
|
|
4701
|
+
body: parsedBody,
|
|
4702
|
+
contentType: headers.get("content-type") ?? "text/plain"
|
|
4703
|
+
};
|
|
4704
|
+
}
|
|
4705
|
+
return {
|
|
4706
|
+
body: JSON.stringify(parsedBody),
|
|
4707
|
+
contentType: "application/json"
|
|
4708
|
+
};
|
|
4709
|
+
}
|
|
4710
|
+
__name(synthesizeBodyFromParsedBody, "synthesizeBodyFromParsedBody");
|
|
4711
|
+
function isDisturbedOrLockedError(error) {
|
|
4712
|
+
return error instanceof TypeError && typeof error.message === "string" && (error.message.includes("disturbed") || error.message.includes("locked"));
|
|
4713
|
+
}
|
|
4714
|
+
__name(isDisturbedOrLockedError, "isDisturbedOrLockedError");
|
|
4765
4715
|
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
4766
4716
|
var _a;
|
|
4767
4717
|
const commonConfig = getCommonConfig(options);
|
|
@@ -4779,7 +4729,9 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4779
4729
|
const logger2 = commonConfig.logging;
|
|
4780
4730
|
logger2.debug("Creating Node HTTP endpoint");
|
|
4781
4731
|
const serviceAdapter = options.serviceAdapter;
|
|
4782
|
-
|
|
4732
|
+
if (serviceAdapter) {
|
|
4733
|
+
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
4734
|
+
}
|
|
4783
4735
|
const honoApp = runtime.createCopilotEndpointSingleRoute({
|
|
4784
4736
|
runtime: options.runtime.instance,
|
|
4785
4737
|
basePath: options.baseUrl ?? options.endpoint
|
|
@@ -4787,14 +4739,59 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4787
4739
|
return /* @__PURE__ */ __name(async function handler(req, res) {
|
|
4788
4740
|
const url = getFullUrl(req);
|
|
4789
4741
|
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
4790
|
-
const
|
|
4742
|
+
const baseHeaders = toHeaders(req.headers);
|
|
4743
|
+
const parsedBody = req.body;
|
|
4744
|
+
const streamConsumed = isStreamConsumed(req) || parsedBody !== void 0;
|
|
4745
|
+
const canStream = hasBody && !streamConsumed;
|
|
4746
|
+
let requestBody = void 0;
|
|
4747
|
+
let useDuplex = false;
|
|
4748
|
+
if (hasBody && canStream) {
|
|
4749
|
+
requestBody = req;
|
|
4750
|
+
useDuplex = true;
|
|
4751
|
+
}
|
|
4752
|
+
if (hasBody && streamConsumed) {
|
|
4753
|
+
if (parsedBody !== void 0) {
|
|
4754
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, baseHeaders);
|
|
4755
|
+
requestBody = synthesized.body ?? void 0;
|
|
4756
|
+
baseHeaders.delete("content-length");
|
|
4757
|
+
if (synthesized.contentType) {
|
|
4758
|
+
baseHeaders.set("content-type", synthesized.contentType);
|
|
4759
|
+
}
|
|
4760
|
+
logger2.debug("Request stream already consumed; using parsed req.body to rebuild request.");
|
|
4761
|
+
} else {
|
|
4762
|
+
logger2.warn("Request stream consumed with no available body; sending empty payload.");
|
|
4763
|
+
requestBody = void 0;
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
const buildRequest = /* @__PURE__ */ __name((body, headers, duplex) => new Request(url, {
|
|
4791
4767
|
method: req.method,
|
|
4792
|
-
headers
|
|
4793
|
-
body
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4768
|
+
headers,
|
|
4769
|
+
body,
|
|
4770
|
+
duplex: duplex ? "half" : void 0
|
|
4771
|
+
}), "buildRequest");
|
|
4772
|
+
let response;
|
|
4773
|
+
try {
|
|
4774
|
+
response = await honoApp.fetch(buildRequest(requestBody, baseHeaders, useDuplex));
|
|
4775
|
+
} catch (error) {
|
|
4776
|
+
if (isDisturbedOrLockedError(error) && hasBody) {
|
|
4777
|
+
logger2.warn("Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.");
|
|
4778
|
+
const fallbackHeaders = new Headers(baseHeaders);
|
|
4779
|
+
let fallbackBody;
|
|
4780
|
+
if (parsedBody !== void 0) {
|
|
4781
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, fallbackHeaders);
|
|
4782
|
+
fallbackBody = synthesized.body ?? void 0;
|
|
4783
|
+
fallbackHeaders.delete("content-length");
|
|
4784
|
+
if (synthesized.contentType) {
|
|
4785
|
+
fallbackHeaders.set("content-type", synthesized.contentType);
|
|
4786
|
+
}
|
|
4787
|
+
} else {
|
|
4788
|
+
fallbackBody = void 0;
|
|
4789
|
+
}
|
|
4790
|
+
response = await honoApp.fetch(buildRequest(fallbackBody, fallbackHeaders, false));
|
|
4791
|
+
} else {
|
|
4792
|
+
throw error;
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4798
4795
|
res.statusCode = response.status;
|
|
4799
4796
|
response.headers.forEach((value, key) => {
|
|
4800
4797
|
res.setHeader(key, value);
|
|
@@ -4857,6 +4854,22 @@ function copilotRuntimeNestEndpoint(options) {
|
|
|
4857
4854
|
return copilotRuntimeNodeHttpEndpoint(options);
|
|
4858
4855
|
}
|
|
4859
4856
|
__name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
4857
|
+
|
|
4858
|
+
// src/lib/index.ts
|
|
4859
|
+
var LangGraphAgent = class {
|
|
4860
|
+
constructor() {
|
|
4861
|
+
throw new Error("LangGraphAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead");
|
|
4862
|
+
}
|
|
4863
|
+
};
|
|
4864
|
+
__name(LangGraphAgent, "LangGraphAgent");
|
|
4865
|
+
var LangGraphHttpAgent = class {
|
|
4866
|
+
constructor() {
|
|
4867
|
+
throw new Error("LangGraphHttpAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead");
|
|
4868
|
+
}
|
|
4869
|
+
};
|
|
4870
|
+
__name(LangGraphHttpAgent, "LangGraphHttpAgent");
|
|
4871
|
+
|
|
4872
|
+
// src/service-adapters/langchain/langserve.ts
|
|
4860
4873
|
var RemoteChain = class {
|
|
4861
4874
|
name;
|
|
4862
4875
|
description;
|
|
@@ -4879,7 +4892,8 @@ var RemoteChain = class {
|
|
|
4879
4892
|
description: this.description,
|
|
4880
4893
|
parameters: this.parameters,
|
|
4881
4894
|
handler: async (args) => {
|
|
4882
|
-
const
|
|
4895
|
+
const { RemoteRunnable } = __require("langchain/runnables/remote");
|
|
4896
|
+
const runnable = new RemoteRunnable({
|
|
4883
4897
|
url: this.chainUrl
|
|
4884
4898
|
});
|
|
4885
4899
|
let input;
|
|
@@ -5091,7 +5105,9 @@ var AnthropicAdapter = class {
|
|
|
5091
5105
|
return "AnthropicAdapter";
|
|
5092
5106
|
}
|
|
5093
5107
|
constructor(params) {
|
|
5094
|
-
|
|
5108
|
+
if (params == null ? void 0 : params.anthropic) {
|
|
5109
|
+
this._anthropic = params.anthropic;
|
|
5110
|
+
}
|
|
5095
5111
|
if (params == null ? void 0 : params.model) {
|
|
5096
5112
|
this.model = params.model;
|
|
5097
5113
|
}
|
|
@@ -5099,6 +5115,13 @@ var AnthropicAdapter = class {
|
|
|
5099
5115
|
enabled: false
|
|
5100
5116
|
};
|
|
5101
5117
|
}
|
|
5118
|
+
ensureAnthropic() {
|
|
5119
|
+
if (!this._anthropic) {
|
|
5120
|
+
const Anthropic = __require("@anthropic-ai/sdk").default;
|
|
5121
|
+
this._anthropic = new Anthropic({});
|
|
5122
|
+
}
|
|
5123
|
+
return this._anthropic;
|
|
5124
|
+
}
|
|
5102
5125
|
/**
|
|
5103
5126
|
* Adds cache control to system prompt
|
|
5104
5127
|
*/
|
|
@@ -5239,7 +5262,8 @@ var AnthropicAdapter = class {
|
|
|
5239
5262
|
},
|
|
5240
5263
|
stream: true
|
|
5241
5264
|
};
|
|
5242
|
-
const
|
|
5265
|
+
const anthropic = this.ensureAnthropic();
|
|
5266
|
+
const stream = await anthropic.messages.create(createParams);
|
|
5243
5267
|
eventSource.stream(async (eventStream$) => {
|
|
5244
5268
|
let mode = null;
|
|
5245
5269
|
let didOutputText = false;
|
|
@@ -5384,11 +5408,12 @@ var ExperimentalOllamaAdapter = class {
|
|
|
5384
5408
|
}
|
|
5385
5409
|
async process(request) {
|
|
5386
5410
|
const { messages, actions, eventSource } = request;
|
|
5387
|
-
const
|
|
5411
|
+
const { Ollama } = __require("@langchain/community/llms/ollama");
|
|
5412
|
+
const ollama = new Ollama({
|
|
5388
5413
|
model: this.model
|
|
5389
5414
|
});
|
|
5390
5415
|
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
5391
|
-
const _stream = await ollama
|
|
5416
|
+
const _stream = await ollama.stream(contents);
|
|
5392
5417
|
eventSource.stream(async (eventStream$) => {
|
|
5393
5418
|
const currentMessageId = shared.randomId();
|
|
5394
5419
|
eventStream$.sendTextMessageStart({
|
|
@@ -5411,6 +5436,8 @@ var ExperimentalOllamaAdapter = class {
|
|
|
5411
5436
|
}
|
|
5412
5437
|
};
|
|
5413
5438
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
5439
|
+
|
|
5440
|
+
// src/service-adapters/bedrock/bedrock-adapter.ts
|
|
5414
5441
|
var DEFAULT_MODEL6 = "amazon.nova-lite-v1:0";
|
|
5415
5442
|
var BedrockAdapter = class extends LangChainAdapter {
|
|
5416
5443
|
provider = "bedrock";
|
|
@@ -5418,8 +5445,9 @@ var BedrockAdapter = class extends LangChainAdapter {
|
|
|
5418
5445
|
constructor(options) {
|
|
5419
5446
|
super({
|
|
5420
5447
|
chainFn: async ({ messages, tools, threadId }) => {
|
|
5448
|
+
const { ChatBedrockConverse } = __require("@langchain/aws");
|
|
5421
5449
|
this.model = (options == null ? void 0 : options.model) ?? "amazon.nova-lite-v1:0";
|
|
5422
|
-
const model = new
|
|
5450
|
+
const model = new ChatBedrockConverse({
|
|
5423
5451
|
model: this.model,
|
|
5424
5452
|
region: (options == null ? void 0 : options.region) ?? "us-east-1",
|
|
5425
5453
|
credentials: (options == null ? void 0 : options.credentials) ? {
|
|
@@ -5446,10 +5474,6 @@ var EmptyAdapter = class {
|
|
|
5446
5474
|
__name(EmptyAdapter, "EmptyAdapter");
|
|
5447
5475
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
5448
5476
|
|
|
5449
|
-
Object.defineProperty(exports, 'LangGraphHttpAgent', {
|
|
5450
|
-
enumerable: true,
|
|
5451
|
-
get: function () { return langgraph.LangGraphHttpAgent; }
|
|
5452
|
-
});
|
|
5453
5477
|
exports.AnthropicAdapter = AnthropicAdapter;
|
|
5454
5478
|
exports.BedrockAdapter = BedrockAdapter;
|
|
5455
5479
|
exports.CopilotRuntime = CopilotRuntime;
|
|
@@ -5461,6 +5485,7 @@ exports.GroqAdapter = GroqAdapter;
|
|
|
5461
5485
|
exports.GuardrailsValidationFailureResponse = GuardrailsValidationFailureResponse;
|
|
5462
5486
|
exports.LangChainAdapter = LangChainAdapter;
|
|
5463
5487
|
exports.LangGraphAgent = LangGraphAgent;
|
|
5488
|
+
exports.LangGraphHttpAgent = LangGraphHttpAgent;
|
|
5464
5489
|
exports.MessageStreamInterruptedResponse = MessageStreamInterruptedResponse;
|
|
5465
5490
|
exports.OpenAIAdapter = OpenAIAdapter;
|
|
5466
5491
|
exports.OpenAIAssistantAdapter = OpenAIAssistantAdapter;
|