@copilotkit/runtime 1.50.0-beta.0 → 1.50.0-beta.10
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 +74 -0
- package/dist/chunk-2OZAGFV3.mjs +43 -0
- package/dist/chunk-2OZAGFV3.mjs.map +1 -0
- package/dist/chunk-62NE5S6M.mjs +226 -0
- package/dist/chunk-62NE5S6M.mjs.map +1 -0
- package/dist/chunk-6XRUR5UK.mjs +1 -0
- package/dist/chunk-6XRUR5UK.mjs.map +1 -0
- package/dist/chunk-AMUJQ6IR.mjs +50 -0
- package/dist/chunk-AMUJQ6IR.mjs.map +1 -0
- package/dist/chunk-BJEYMRDD.mjs +25 -0
- package/dist/chunk-BJEYMRDD.mjs.map +1 -0
- package/dist/chunk-DZV4ZIAR.mjs +3063 -0
- package/dist/chunk-DZV4ZIAR.mjs.map +1 -0
- package/dist/chunk-FHD4JECV.mjs +33 -0
- package/dist/chunk-FHD4JECV.mjs.map +1 -0
- package/dist/chunk-FMU55SEU.mjs +25 -0
- package/dist/chunk-FMU55SEU.mjs.map +1 -0
- package/dist/chunk-OWIGJONH.mjs +275 -0
- package/dist/chunk-OWIGJONH.mjs.map +1 -0
- package/dist/chunk-SBCOROE4.mjs +1112 -0
- package/dist/chunk-SBCOROE4.mjs.map +1 -0
- package/dist/chunk-TTUAEJLD.mjs +617 -0
- package/dist/chunk-TTUAEJLD.mjs.map +1 -0
- package/dist/chunk-XWBDEXDA.mjs +153 -0
- package/dist/chunk-XWBDEXDA.mjs.map +1 -0
- package/dist/chunk-Z752VE75.mjs +74 -0
- package/dist/chunk-Z752VE75.mjs.map +1 -0
- package/dist/graphql/message-conversion/index.d.ts +18 -0
- package/dist/graphql/message-conversion/index.js +725 -0
- package/dist/graphql/message-conversion/index.js.map +1 -0
- package/dist/graphql/message-conversion/index.mjs +245 -0
- package/dist/graphql/message-conversion/index.mjs.map +1 -0
- package/dist/graphql/types/base/index.d.ts +6 -0
- package/dist/graphql/types/base/index.js +63 -0
- package/dist/graphql/types/base/index.js.map +1 -0
- package/dist/graphql/types/base/index.mjs +8 -0
- package/dist/graphql/types/base/index.mjs.map +1 -0
- package/dist/graphql/types/converted/index.d.ts +2 -0
- package/dist/graphql/types/converted/index.js +294 -0
- package/dist/graphql/types/converted/index.js.map +1 -0
- package/dist/graphql/types/converted/index.mjs +20 -0
- package/dist/graphql/types/converted/index.mjs.map +1 -0
- package/dist/groq-adapter-50bc6e4a.d.ts +326 -0
- package/dist/index-adbd78f1.d.ts +154 -0
- package/dist/index.d.ts +136 -287
- package/dist/index.js +393 -287
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +385 -276
- 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/langserve-74a52292.d.ts +242 -0
- package/dist/lib/cloud/index.d.ts +6 -0
- package/dist/lib/cloud/index.js +18 -0
- package/dist/lib/cloud/index.js.map +1 -0
- package/dist/lib/cloud/index.mjs +1 -0
- package/dist/lib/cloud/index.mjs.map +1 -0
- package/dist/lib/index.d.ts +266 -0
- package/dist/lib/index.js +4944 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +74 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/integrations/index.d.ts +28 -0
- package/dist/lib/integrations/index.js +3024 -0
- package/dist/lib/integrations/index.js.map +1 -0
- package/dist/lib/integrations/index.mjs +36 -0
- package/dist/lib/integrations/index.mjs.map +1 -0
- package/dist/lib/integrations/nest/index.d.ts +16 -0
- package/dist/lib/integrations/nest/index.js +2937 -0
- package/dist/lib/integrations/nest/index.js.map +1 -0
- package/dist/lib/integrations/nest/index.mjs +13 -0
- package/dist/lib/integrations/nest/index.mjs.map +1 -0
- package/dist/lib/integrations/node-express/index.d.ts +16 -0
- package/dist/lib/integrations/node-express/index.js +2937 -0
- package/dist/lib/integrations/node-express/index.js.map +1 -0
- package/dist/lib/integrations/node-express/index.mjs +13 -0
- package/dist/lib/integrations/node-express/index.mjs.map +1 -0
- package/dist/lib/integrations/node-http/index.d.ts +16 -0
- package/dist/lib/integrations/node-http/index.js +2923 -0
- package/dist/lib/integrations/node-http/index.js.map +1 -0
- package/dist/lib/integrations/node-http/index.mjs +12 -0
- package/dist/lib/integrations/node-http/index.mjs.map +1 -0
- package/dist/service-adapters/index.d.ts +166 -0
- package/dist/service-adapters/index.js +1800 -0
- package/dist/service-adapters/index.js.map +1 -0
- package/dist/service-adapters/index.mjs +36 -0
- package/dist/service-adapters/index.mjs.map +1 -0
- package/dist/service-adapters/shared/index.d.ts +9 -0
- package/dist/service-adapters/shared/index.js +72 -0
- package/dist/service-adapters/shared/index.js.map +1 -0
- package/dist/service-adapters/shared/index.mjs +8 -0
- package/dist/service-adapters/shared/index.mjs.map +1 -0
- package/dist/shared-f6d43ef8.d.ts +446 -0
- package/dist/utils/index.d.ts +65 -0
- package/dist/utils/index.js +175 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/index.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 +71 -33
- 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 +42 -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 +51 -68
- package/src/lib/runtime/telemetry-agent-runner.ts +134 -0
- 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 { tap, catchError, finalize, ReplaySubject, shareReplay, firstValueFrom, skipWhile, takeWhile, filter, Subject, take } 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.9",
|
|
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.28",
|
|
121
|
+
"@copilotkitnext/runtime": "0.0.28",
|
|
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
|
-
"@
|
|
151
|
-
"@ag-ui/
|
|
152
|
-
"@ag-ui/
|
|
153
|
-
"@ag-ui/
|
|
154
|
-
"@ag-ui/
|
|
143
|
+
"@anthropic-ai/sdk": "^0.57.0",
|
|
144
|
+
"@ag-ui/client": "^0.0.42",
|
|
145
|
+
"@ag-ui/core": ">=0.0.42",
|
|
146
|
+
"@ag-ui/encoder": ">=0.0.42",
|
|
147
|
+
"@ag-ui/langgraph": ">=0.0.20",
|
|
148
|
+
"@ag-ui/proto": ">=0.0.42",
|
|
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.3.0 <1.0.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,
|
|
@@ -3158,6 +3233,82 @@ function aguiMessageWithImageToGQLMessage(message) {
|
|
|
3158
3233
|
});
|
|
3159
3234
|
}
|
|
3160
3235
|
__name(aguiMessageWithImageToGQLMessage, "aguiMessageWithImageToGQLMessage");
|
|
3236
|
+
var TelemetryAgentRunner = class {
|
|
3237
|
+
_runner;
|
|
3238
|
+
hashedLgcKey;
|
|
3239
|
+
constructor(config2) {
|
|
3240
|
+
this._runner = (config2 == null ? void 0 : config2.runner) ?? new InMemoryAgentRunner();
|
|
3241
|
+
this.hashedLgcKey = (config2 == null ? void 0 : config2.langsmithApiKey) ? createHash("sha256").update(config2.langsmithApiKey).digest("hex") : void 0;
|
|
3242
|
+
}
|
|
3243
|
+
/**
|
|
3244
|
+
* Runs an agent with telemetry tracking.
|
|
3245
|
+
* Wraps the underlying runner's Observable stream with telemetry events.
|
|
3246
|
+
*/
|
|
3247
|
+
run(...args) {
|
|
3248
|
+
const streamInfo = {
|
|
3249
|
+
hashedLgcKey: this.hashedLgcKey
|
|
3250
|
+
};
|
|
3251
|
+
let streamErrored = false;
|
|
3252
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
3253
|
+
hashedLgcKey: this.hashedLgcKey
|
|
3254
|
+
});
|
|
3255
|
+
return this._runner.run(...args).pipe(
|
|
3256
|
+
// Extract metadata from events if available
|
|
3257
|
+
tap((event) => {
|
|
3258
|
+
var _a;
|
|
3259
|
+
const rawEvent = event.rawEvent;
|
|
3260
|
+
if (rawEvent == null ? void 0 : rawEvent.data) {
|
|
3261
|
+
const data = rawEvent.data;
|
|
3262
|
+
if ((_a = data == null ? void 0 : data.output) == null ? void 0 : _a.model) {
|
|
3263
|
+
streamInfo.model = data.output.model;
|
|
3264
|
+
streamInfo.provider = data.output.model;
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
if (rawEvent == null ? void 0 : rawEvent.metadata) {
|
|
3268
|
+
const metadata = rawEvent.metadata;
|
|
3269
|
+
if (metadata == null ? void 0 : metadata.langgraph_host) {
|
|
3270
|
+
streamInfo.langGraphHost = metadata.langgraph_host;
|
|
3271
|
+
}
|
|
3272
|
+
if (metadata == null ? void 0 : metadata.langgraph_version) {
|
|
3273
|
+
streamInfo.langGraphVersion = metadata.langgraph_version;
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
}),
|
|
3277
|
+
catchError((error) => {
|
|
3278
|
+
streamErrored = true;
|
|
3279
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
3280
|
+
...streamInfo,
|
|
3281
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3282
|
+
});
|
|
3283
|
+
throw error;
|
|
3284
|
+
}),
|
|
3285
|
+
finalize(() => {
|
|
3286
|
+
if (!streamErrored) {
|
|
3287
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
|
|
3288
|
+
}
|
|
3289
|
+
})
|
|
3290
|
+
);
|
|
3291
|
+
}
|
|
3292
|
+
/**
|
|
3293
|
+
* Delegates to the underlying runner's connect method
|
|
3294
|
+
*/
|
|
3295
|
+
connect(...args) {
|
|
3296
|
+
return this._runner.connect(...args);
|
|
3297
|
+
}
|
|
3298
|
+
/**
|
|
3299
|
+
* Delegates to the underlying runner's isRunning method
|
|
3300
|
+
*/
|
|
3301
|
+
isRunning(...args) {
|
|
3302
|
+
return this._runner.isRunning(...args);
|
|
3303
|
+
}
|
|
3304
|
+
/**
|
|
3305
|
+
* Delegates to the underlying runner's stop method
|
|
3306
|
+
*/
|
|
3307
|
+
stop(...args) {
|
|
3308
|
+
return this._runner.stop(...args);
|
|
3309
|
+
}
|
|
3310
|
+
};
|
|
3311
|
+
__name(TelemetryAgentRunner, "TelemetryAgentRunner");
|
|
3161
3312
|
|
|
3162
3313
|
// src/lib/runtime/types.ts
|
|
3163
3314
|
var EndpointType;
|
|
@@ -3301,199 +3452,6 @@ When using these tools:
|
|
|
3301
3452
|
7. Always check tool responses to determine your next action`;
|
|
3302
3453
|
}
|
|
3303
3454
|
__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
3455
|
var CopilotRuntime = class {
|
|
3498
3456
|
params;
|
|
3499
3457
|
observability;
|
|
@@ -3503,12 +3461,15 @@ var CopilotRuntime = class {
|
|
|
3503
3461
|
_instance;
|
|
3504
3462
|
constructor(params) {
|
|
3505
3463
|
const agents = (params == null ? void 0 : params.agents) ?? {};
|
|
3464
|
+
const endpointAgents = this.assignEndpointsToAgents((params == null ? void 0 : params.remoteEndpoints) ?? []);
|
|
3506
3465
|
this.runtimeArgs = {
|
|
3507
3466
|
agents: {
|
|
3508
|
-
...
|
|
3467
|
+
...endpointAgents,
|
|
3509
3468
|
...agents
|
|
3510
3469
|
},
|
|
3511
|
-
|
|
3470
|
+
// Use TelemetryAgentRunner by default to track agent execution telemetry
|
|
3471
|
+
// Users can pass their own runner which will be wrapped for telemetry
|
|
3472
|
+
runner: (params == null ? void 0 : params.runner) ?? new TelemetryAgentRunner(),
|
|
3512
3473
|
// TODO: add support for transcriptionService from CopilotRuntimeOptionsVNext once it is ready
|
|
3513
3474
|
// transcriptionService: params?.transcriptionService,
|
|
3514
3475
|
beforeRequestMiddleware: this.createOnBeforeRequestHandler(params).bind(this),
|
|
@@ -3524,29 +3485,16 @@ var CopilotRuntime = class {
|
|
|
3524
3485
|
return this._instance;
|
|
3525
3486
|
}
|
|
3526
3487
|
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
|
-
}, {});
|
|
3488
|
+
let result = {};
|
|
3489
|
+
if (endpoints.some((endpoint) => resolveEndpointType(endpoint) == EndpointType.LangGraphPlatform)) {
|
|
3490
|
+
throw new CopilotKitMisuseError({
|
|
3491
|
+
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: "..." }) }'
|
|
3492
|
+
});
|
|
3493
|
+
}
|
|
3494
|
+
return result;
|
|
3546
3495
|
}
|
|
3547
3496
|
handleServiceAdapter(serviceAdapter) {
|
|
3548
3497
|
this.runtimeArgs.agents = Promise.resolve(this.runtimeArgs.agents ?? {}).then(async (agents) => {
|
|
3549
|
-
var _a;
|
|
3550
3498
|
let agentsList = agents;
|
|
3551
3499
|
const isAgentsListEmpty = !Object.keys(agents).length;
|
|
3552
3500
|
const hasServiceAdapter = Boolean(serviceAdapter);
|
|
@@ -3564,7 +3512,7 @@ var CopilotRuntime = class {
|
|
|
3564
3512
|
model: `${serviceAdapter.provider}/${serviceAdapter.model}`
|
|
3565
3513
|
});
|
|
3566
3514
|
}
|
|
3567
|
-
if (
|
|
3515
|
+
if (this.params.actions) {
|
|
3568
3516
|
const mcpTools = await this.getToolsFromMCP();
|
|
3569
3517
|
agentsList = this.assignToolsToAgents(agents, [
|
|
3570
3518
|
...this.getToolsFromActions(this.params.actions),
|
|
@@ -3585,7 +3533,8 @@ var CopilotRuntime = class {
|
|
|
3585
3533
|
return {
|
|
3586
3534
|
name: action.name,
|
|
3587
3535
|
description: action.description || "",
|
|
3588
|
-
parameters: zodSchema
|
|
3536
|
+
parameters: zodSchema,
|
|
3537
|
+
execute: () => Promise.resolve()
|
|
3589
3538
|
};
|
|
3590
3539
|
});
|
|
3591
3540
|
}
|
|
@@ -3736,7 +3685,8 @@ var CopilotRuntime = class {
|
|
|
3736
3685
|
return {
|
|
3737
3686
|
name: toolName,
|
|
3738
3687
|
description: tool.description || `MCP tool: ${toolName} (from ${endpointUrl})`,
|
|
3739
|
-
parameters: zodSchema
|
|
3688
|
+
parameters: zodSchema,
|
|
3689
|
+
execute: () => Promise.resolve()
|
|
3740
3690
|
};
|
|
3741
3691
|
});
|
|
3742
3692
|
this.mcpToolsCache.set(endpointUrl, toolDefs);
|
|
@@ -3887,6 +3837,38 @@ _ts_decorate19([
|
|
|
3887
3837
|
AgentsResponse = _ts_decorate19([
|
|
3888
3838
|
ObjectType()
|
|
3889
3839
|
], AgentsResponse);
|
|
3840
|
+
|
|
3841
|
+
// src/agents/langgraph/events.ts
|
|
3842
|
+
var LangGraphEventTypes;
|
|
3843
|
+
(function(LangGraphEventTypes2) {
|
|
3844
|
+
LangGraphEventTypes2["OnChainStart"] = "on_chain_start";
|
|
3845
|
+
LangGraphEventTypes2["OnChainStream"] = "on_chain_stream";
|
|
3846
|
+
LangGraphEventTypes2["OnChainEnd"] = "on_chain_end";
|
|
3847
|
+
LangGraphEventTypes2["OnChatModelStart"] = "on_chat_model_start";
|
|
3848
|
+
LangGraphEventTypes2["OnChatModelStream"] = "on_chat_model_stream";
|
|
3849
|
+
LangGraphEventTypes2["OnChatModelEnd"] = "on_chat_model_end";
|
|
3850
|
+
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
3851
|
+
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
3852
|
+
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
3853
|
+
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
3854
|
+
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
3855
|
+
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
3856
|
+
LangGraphEventTypes2["OnInterrupt"] = "on_interrupt";
|
|
3857
|
+
LangGraphEventTypes2["OnCopilotKitInterrupt"] = "on_copilotkit_interrupt";
|
|
3858
|
+
LangGraphEventTypes2["OnCopilotKitError"] = "on_copilotkit_error";
|
|
3859
|
+
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
3860
|
+
var MetaEventNames;
|
|
3861
|
+
(function(MetaEventNames2) {
|
|
3862
|
+
MetaEventNames2["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
|
|
3863
|
+
MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
3864
|
+
})(MetaEventNames || (MetaEventNames = {}));
|
|
3865
|
+
var CustomEventNames;
|
|
3866
|
+
(function(CustomEventNames2) {
|
|
3867
|
+
CustomEventNames2["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
3868
|
+
CustomEventNames2["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
3869
|
+
CustomEventNames2["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
3870
|
+
CustomEventNames2["CopilotKitExit"] = "copilotkit_exit";
|
|
3871
|
+
})(CustomEventNames || (CustomEventNames = {}));
|
|
3890
3872
|
function _ts_decorate20(decorators, target, key, desc) {
|
|
3891
3873
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3892
3874
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4718,7 +4700,9 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
|
4718
4700
|
const logger2 = commonConfig.logging;
|
|
4719
4701
|
logger2.debug("Creating NextJS App Router endpoint");
|
|
4720
4702
|
const serviceAdapter = options.serviceAdapter;
|
|
4721
|
-
|
|
4703
|
+
if (serviceAdapter) {
|
|
4704
|
+
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
4705
|
+
}
|
|
4722
4706
|
const copilotRoute = createCopilotEndpointSingleRoute({
|
|
4723
4707
|
runtime: options.runtime.instance,
|
|
4724
4708
|
basePath: options.baseUrl ?? options.endpoint
|
|
@@ -4748,12 +4732,59 @@ function readableStreamToNodeStream(webStream) {
|
|
|
4748
4732
|
}
|
|
4749
4733
|
__name(readableStreamToNodeStream, "readableStreamToNodeStream");
|
|
4750
4734
|
function getFullUrl(req) {
|
|
4751
|
-
const
|
|
4735
|
+
const expressPath = req.originalUrl ?? (req.baseUrl ? `${req.baseUrl}${req.url ?? ""}` : void 0);
|
|
4736
|
+
const path = expressPath || req.url || "/";
|
|
4752
4737
|
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
4753
4738
|
const proto = req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http");
|
|
4754
4739
|
return `${proto}://${host}${path}`;
|
|
4755
4740
|
}
|
|
4756
4741
|
__name(getFullUrl, "getFullUrl");
|
|
4742
|
+
function toHeaders(rawHeaders) {
|
|
4743
|
+
const headers = new Headers();
|
|
4744
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
4745
|
+
if (value === void 0)
|
|
4746
|
+
continue;
|
|
4747
|
+
if (Array.isArray(value)) {
|
|
4748
|
+
value.forEach((entry) => headers.append(key, entry));
|
|
4749
|
+
continue;
|
|
4750
|
+
}
|
|
4751
|
+
headers.append(key, value);
|
|
4752
|
+
}
|
|
4753
|
+
return headers;
|
|
4754
|
+
}
|
|
4755
|
+
__name(toHeaders, "toHeaders");
|
|
4756
|
+
function isStreamConsumed(req) {
|
|
4757
|
+
const readableState = req._readableState;
|
|
4758
|
+
return Boolean(req.readableEnded || req.complete || (readableState == null ? void 0 : readableState.ended) || (readableState == null ? void 0 : readableState.endEmitted));
|
|
4759
|
+
}
|
|
4760
|
+
__name(isStreamConsumed, "isStreamConsumed");
|
|
4761
|
+
function synthesizeBodyFromParsedBody(parsedBody, headers) {
|
|
4762
|
+
if (parsedBody === null || parsedBody === void 0) {
|
|
4763
|
+
return {
|
|
4764
|
+
body: null
|
|
4765
|
+
};
|
|
4766
|
+
}
|
|
4767
|
+
if (parsedBody instanceof Buffer || parsedBody instanceof Uint8Array) {
|
|
4768
|
+
return {
|
|
4769
|
+
body: parsedBody
|
|
4770
|
+
};
|
|
4771
|
+
}
|
|
4772
|
+
if (typeof parsedBody === "string") {
|
|
4773
|
+
return {
|
|
4774
|
+
body: parsedBody,
|
|
4775
|
+
contentType: headers.get("content-type") ?? "text/plain"
|
|
4776
|
+
};
|
|
4777
|
+
}
|
|
4778
|
+
return {
|
|
4779
|
+
body: JSON.stringify(parsedBody),
|
|
4780
|
+
contentType: "application/json"
|
|
4781
|
+
};
|
|
4782
|
+
}
|
|
4783
|
+
__name(synthesizeBodyFromParsedBody, "synthesizeBodyFromParsedBody");
|
|
4784
|
+
function isDisturbedOrLockedError(error) {
|
|
4785
|
+
return error instanceof TypeError && typeof error.message === "string" && (error.message.includes("disturbed") || error.message.includes("locked"));
|
|
4786
|
+
}
|
|
4787
|
+
__name(isDisturbedOrLockedError, "isDisturbedOrLockedError");
|
|
4757
4788
|
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
4758
4789
|
var _a;
|
|
4759
4790
|
const commonConfig = getCommonConfig(options);
|
|
@@ -4771,7 +4802,9 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4771
4802
|
const logger2 = commonConfig.logging;
|
|
4772
4803
|
logger2.debug("Creating Node HTTP endpoint");
|
|
4773
4804
|
const serviceAdapter = options.serviceAdapter;
|
|
4774
|
-
|
|
4805
|
+
if (serviceAdapter) {
|
|
4806
|
+
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
4807
|
+
}
|
|
4775
4808
|
const honoApp = createCopilotEndpointSingleRoute({
|
|
4776
4809
|
runtime: options.runtime.instance,
|
|
4777
4810
|
basePath: options.baseUrl ?? options.endpoint
|
|
@@ -4779,14 +4812,59 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4779
4812
|
return /* @__PURE__ */ __name(async function handler(req, res) {
|
|
4780
4813
|
const url = getFullUrl(req);
|
|
4781
4814
|
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
4782
|
-
const
|
|
4815
|
+
const baseHeaders = toHeaders(req.headers);
|
|
4816
|
+
const parsedBody = req.body;
|
|
4817
|
+
const streamConsumed = isStreamConsumed(req) || parsedBody !== void 0;
|
|
4818
|
+
const canStream = hasBody && !streamConsumed;
|
|
4819
|
+
let requestBody = void 0;
|
|
4820
|
+
let useDuplex = false;
|
|
4821
|
+
if (hasBody && canStream) {
|
|
4822
|
+
requestBody = req;
|
|
4823
|
+
useDuplex = true;
|
|
4824
|
+
}
|
|
4825
|
+
if (hasBody && streamConsumed) {
|
|
4826
|
+
if (parsedBody !== void 0) {
|
|
4827
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, baseHeaders);
|
|
4828
|
+
requestBody = synthesized.body ?? void 0;
|
|
4829
|
+
baseHeaders.delete("content-length");
|
|
4830
|
+
if (synthesized.contentType) {
|
|
4831
|
+
baseHeaders.set("content-type", synthesized.contentType);
|
|
4832
|
+
}
|
|
4833
|
+
logger2.debug("Request stream already consumed; using parsed req.body to rebuild request.");
|
|
4834
|
+
} else {
|
|
4835
|
+
logger2.warn("Request stream consumed with no available body; sending empty payload.");
|
|
4836
|
+
requestBody = void 0;
|
|
4837
|
+
}
|
|
4838
|
+
}
|
|
4839
|
+
const buildRequest = /* @__PURE__ */ __name((body, headers, duplex) => new Request(url, {
|
|
4783
4840
|
method: req.method,
|
|
4784
|
-
headers
|
|
4785
|
-
body
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4841
|
+
headers,
|
|
4842
|
+
body,
|
|
4843
|
+
duplex: duplex ? "half" : void 0
|
|
4844
|
+
}), "buildRequest");
|
|
4845
|
+
let response;
|
|
4846
|
+
try {
|
|
4847
|
+
response = await honoApp.fetch(buildRequest(requestBody, baseHeaders, useDuplex));
|
|
4848
|
+
} catch (error) {
|
|
4849
|
+
if (isDisturbedOrLockedError(error) && hasBody) {
|
|
4850
|
+
logger2.warn("Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.");
|
|
4851
|
+
const fallbackHeaders = new Headers(baseHeaders);
|
|
4852
|
+
let fallbackBody;
|
|
4853
|
+
if (parsedBody !== void 0) {
|
|
4854
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, fallbackHeaders);
|
|
4855
|
+
fallbackBody = synthesized.body ?? void 0;
|
|
4856
|
+
fallbackHeaders.delete("content-length");
|
|
4857
|
+
if (synthesized.contentType) {
|
|
4858
|
+
fallbackHeaders.set("content-type", synthesized.contentType);
|
|
4859
|
+
}
|
|
4860
|
+
} else {
|
|
4861
|
+
fallbackBody = void 0;
|
|
4862
|
+
}
|
|
4863
|
+
response = await honoApp.fetch(buildRequest(fallbackBody, fallbackHeaders, false));
|
|
4864
|
+
} else {
|
|
4865
|
+
throw error;
|
|
4866
|
+
}
|
|
4867
|
+
}
|
|
4790
4868
|
res.statusCode = response.status;
|
|
4791
4869
|
response.headers.forEach((value, key) => {
|
|
4792
4870
|
res.setHeader(key, value);
|
|
@@ -4849,6 +4927,22 @@ function copilotRuntimeNestEndpoint(options) {
|
|
|
4849
4927
|
return copilotRuntimeNodeHttpEndpoint(options);
|
|
4850
4928
|
}
|
|
4851
4929
|
__name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
4930
|
+
|
|
4931
|
+
// src/lib/index.ts
|
|
4932
|
+
var LangGraphAgent = class {
|
|
4933
|
+
constructor() {
|
|
4934
|
+
throw new Error("LangGraphAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead");
|
|
4935
|
+
}
|
|
4936
|
+
};
|
|
4937
|
+
__name(LangGraphAgent, "LangGraphAgent");
|
|
4938
|
+
var LangGraphHttpAgent = class {
|
|
4939
|
+
constructor() {
|
|
4940
|
+
throw new Error("LangGraphHttpAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead");
|
|
4941
|
+
}
|
|
4942
|
+
};
|
|
4943
|
+
__name(LangGraphHttpAgent, "LangGraphHttpAgent");
|
|
4944
|
+
|
|
4945
|
+
// src/service-adapters/langchain/langserve.ts
|
|
4852
4946
|
var RemoteChain = class {
|
|
4853
4947
|
name;
|
|
4854
4948
|
description;
|
|
@@ -4871,6 +4965,7 @@ var RemoteChain = class {
|
|
|
4871
4965
|
description: this.description,
|
|
4872
4966
|
parameters: this.parameters,
|
|
4873
4967
|
handler: async (args) => {
|
|
4968
|
+
const { RemoteRunnable } = __require("langchain/runnables/remote");
|
|
4874
4969
|
const runnable = new RemoteRunnable({
|
|
4875
4970
|
url: this.chainUrl
|
|
4876
4971
|
});
|
|
@@ -5083,7 +5178,9 @@ var AnthropicAdapter = class {
|
|
|
5083
5178
|
return "AnthropicAdapter";
|
|
5084
5179
|
}
|
|
5085
5180
|
constructor(params) {
|
|
5086
|
-
|
|
5181
|
+
if (params == null ? void 0 : params.anthropic) {
|
|
5182
|
+
this._anthropic = params.anthropic;
|
|
5183
|
+
}
|
|
5087
5184
|
if (params == null ? void 0 : params.model) {
|
|
5088
5185
|
this.model = params.model;
|
|
5089
5186
|
}
|
|
@@ -5091,6 +5188,13 @@ var AnthropicAdapter = class {
|
|
|
5091
5188
|
enabled: false
|
|
5092
5189
|
};
|
|
5093
5190
|
}
|
|
5191
|
+
ensureAnthropic() {
|
|
5192
|
+
if (!this._anthropic) {
|
|
5193
|
+
const Anthropic = __require("@anthropic-ai/sdk").default;
|
|
5194
|
+
this._anthropic = new Anthropic({});
|
|
5195
|
+
}
|
|
5196
|
+
return this._anthropic;
|
|
5197
|
+
}
|
|
5094
5198
|
/**
|
|
5095
5199
|
* Adds cache control to system prompt
|
|
5096
5200
|
*/
|
|
@@ -5231,7 +5335,8 @@ var AnthropicAdapter = class {
|
|
|
5231
5335
|
},
|
|
5232
5336
|
stream: true
|
|
5233
5337
|
};
|
|
5234
|
-
const
|
|
5338
|
+
const anthropic = this.ensureAnthropic();
|
|
5339
|
+
const stream = await anthropic.messages.create(createParams);
|
|
5235
5340
|
eventSource.stream(async (eventStream$) => {
|
|
5236
5341
|
let mode = null;
|
|
5237
5342
|
let didOutputText = false;
|
|
@@ -5376,6 +5481,7 @@ var ExperimentalOllamaAdapter = class {
|
|
|
5376
5481
|
}
|
|
5377
5482
|
async process(request) {
|
|
5378
5483
|
const { messages, actions, eventSource } = request;
|
|
5484
|
+
const { Ollama } = __require("@langchain/community/llms/ollama");
|
|
5379
5485
|
const ollama = new Ollama({
|
|
5380
5486
|
model: this.model
|
|
5381
5487
|
});
|
|
@@ -5403,6 +5509,8 @@ var ExperimentalOllamaAdapter = class {
|
|
|
5403
5509
|
}
|
|
5404
5510
|
};
|
|
5405
5511
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
5512
|
+
|
|
5513
|
+
// src/service-adapters/bedrock/bedrock-adapter.ts
|
|
5406
5514
|
var DEFAULT_MODEL6 = "amazon.nova-lite-v1:0";
|
|
5407
5515
|
var BedrockAdapter = class extends LangChainAdapter {
|
|
5408
5516
|
provider = "bedrock";
|
|
@@ -5410,6 +5518,7 @@ var BedrockAdapter = class extends LangChainAdapter {
|
|
|
5410
5518
|
constructor(options) {
|
|
5411
5519
|
super({
|
|
5412
5520
|
chainFn: async ({ messages, tools, threadId }) => {
|
|
5521
|
+
const { ChatBedrockConverse } = __require("@langchain/aws");
|
|
5413
5522
|
this.model = (options == null ? void 0 : options.model) ?? "amazon.nova-lite-v1:0";
|
|
5414
5523
|
const model = new ChatBedrockConverse({
|
|
5415
5524
|
model: this.model,
|
|
@@ -5438,6 +5547,6 @@ var EmptyAdapter = class {
|
|
|
5438
5547
|
__name(EmptyAdapter, "EmptyAdapter");
|
|
5439
5548
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
5440
5549
|
|
|
5441
|
-
export { AnthropicAdapter, BedrockAdapter, CopilotRuntime,
|
|
5550
|
+
export { AnthropicAdapter, BedrockAdapter, CopilotRuntime, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter, GoogleGenerativeAIAdapter, GroqAdapter, GuardrailsValidationFailureResponse, LangChainAdapter, LangGraphAgent, LangGraphHttpAgent, MessageStreamInterruptedResponse, OpenAIAdapter, OpenAIAssistantAdapter, RemoteChain, TelemetryAgentRunner, UnifyAdapter, UnknownErrorResponse, addCustomHeaderPlugin, buildSchema, config, convertMCPToolsToActions, convertServiceAdapterError, copilotKitEndpoint, copilotRuntimeNestEndpoint, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint, copilotRuntimeNodeExpressEndpoint, copilotRuntimeNodeHttpEndpoint, createContext, createLogger, extractParametersFromSchema, generateMcpToolInstructions, getCommonConfig, langGraphPlatformEndpoint, readableStreamToNodeStream, resolveEndpointType };
|
|
5442
5551
|
//# sourceMappingURL=out.js.map
|
|
5443
5552
|
//# sourceMappingURL=index.mjs.map
|