@copilotkit/runtime 1.79.2-canary.1792172552 → 1.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.mjs +15 -1
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +5 -3
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts +4 -2
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs +25 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs +25 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +17 -3
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +2 -3
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +2 -3
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +18 -4
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/lib/runtime/legacy-service-adapter-agent.cjs +360 -0
- package/dist/lib/runtime/legacy-service-adapter-agent.cjs.map +1 -0
- package/dist/lib/runtime/legacy-service-adapter-agent.mjs +359 -0
- package/dist/lib/runtime/legacy-service-adapter-agent.mjs.map +1 -0
- package/dist/lib/telemetry-client.cjs +12 -1
- package/dist/lib/telemetry-client.cjs.map +1 -1
- package/dist/lib/telemetry-client.mjs +12 -1
- package/dist/lib/telemetry-client.mjs.map +1 -1
- package/dist/package.cjs +6 -6
- package/dist/package.mjs +6 -6
- package/dist/service-adapters/events.cjs +91 -0
- package/dist/service-adapters/events.cjs.map +1 -1
- package/dist/service-adapters/events.d.cts +6 -1
- package/dist/service-adapters/events.d.cts.map +1 -1
- package/dist/service-adapters/events.d.mts +6 -1
- package/dist/service-adapters/events.d.mts.map +1 -1
- package/dist/service-adapters/events.mjs +90 -1
- package/dist/service-adapters/events.mjs.map +1 -1
- package/dist/service-adapters/langchain/langchain-adapter.cjs +1 -1
- package/dist/service-adapters/langchain/langchain-adapter.cjs.map +1 -1
- package/dist/service-adapters/langchain/langchain-adapter.d.cts.map +1 -1
- package/dist/service-adapters/langchain/langchain-adapter.d.mts.map +1 -1
- package/dist/service-adapters/langchain/langchain-adapter.mjs +2 -2
- package/dist/service-adapters/langchain/langchain-adapter.mjs.map +1 -1
- package/dist/service-adapters/langchain/utils.cjs +53 -15
- package/dist/service-adapters/langchain/utils.cjs.map +1 -1
- package/dist/service-adapters/langchain/utils.mjs +53 -16
- package/dist/service-adapters/langchain/utils.mjs.map +1 -1
- package/dist/v2/index.cjs +6 -0
- package/dist/v2/index.d.cts +7 -4
- package/dist/v2/index.d.mts +7 -4
- package/dist/v2/index.mjs +5 -3
- package/dist/v2/runtime/core/middleware-sse-parser.cjs +11 -2
- package/dist/v2/runtime/core/middleware-sse-parser.cjs.map +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.mjs +11 -2
- package/dist/v2/runtime/core/middleware-sse-parser.mjs.map +1 -1
- package/dist/v2/runtime/core/package-info.cjs +1 -1
- package/dist/v2/runtime/core/package-info.mjs +1 -1
- package/dist/v2/runtime/core/runtime.cjs +6 -3
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +15 -3
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +15 -3
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +6 -3
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.cjs +2 -2
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.mjs +2 -2
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/node-fetch-handler.cjs +51 -1
- package/dist/v2/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/node-fetch-handler.mjs +52 -2
- package/dist/v2/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.cjs +394 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.d.cts +21 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.d.cts.map +1 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.d.mts +21 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.d.mts.map +1 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.mjs +393 -0
- package/dist/v2/runtime/generative-ui/generative-ui-middleware.mjs.map +1 -0
- package/dist/v2/runtime/generative-ui/index.d.cts +3 -0
- package/dist/v2/runtime/generative-ui/index.d.mts +3 -0
- package/dist/v2/runtime/generative-ui/surface-writer.cjs +86 -0
- package/dist/v2/runtime/generative-ui/surface-writer.cjs.map +1 -0
- package/dist/v2/runtime/generative-ui/surface-writer.d.cts +33 -0
- package/dist/v2/runtime/generative-ui/surface-writer.d.cts.map +1 -0
- package/dist/v2/runtime/generative-ui/surface-writer.d.mts +33 -0
- package/dist/v2/runtime/generative-ui/surface-writer.d.mts.map +1 -0
- package/dist/v2/runtime/generative-ui/surface-writer.mjs +85 -0
- package/dist/v2/runtime/generative-ui/surface-writer.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-run.cjs +8 -3
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +5 -1
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs +2 -3
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs +2 -3
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +7 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +7 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.cjs +39 -0
- package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.mjs +39 -0
- package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/v2/runtime/index.d.cts +7 -3
- package/dist/v2/runtime/index.d.cts.map +1 -1
- package/dist/v2/runtime/index.d.mts +7 -3
- package/dist/v2/runtime/index.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs +100 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +33 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +33 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +100 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/experimental.d.cts +27 -0
- package/dist/v2/runtime/intelligence-platform/experimental.d.cts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/experimental.d.mts +27 -0
- package/dist/v2/runtime/intelligence-platform/experimental.d.mts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/index.d.cts +2 -1
- package/dist/v2/runtime/intelligence-platform/index.d.mts +2 -1
- package/dist/v2/runtime/intelligence-platform/learning-management.cjs +204 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.cjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.d.cts +112 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.d.cts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.d.mts +112 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.d.mts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.mjs +194 -0
- package/dist/v2/runtime/intelligence-platform/learning-management.mjs.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.cjs +16 -0
- package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.d.cts +11 -1
- package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.d.mts +11 -1
- package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.mjs +16 -1
- package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.cjs +1 -1
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.mjs +2 -2
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
- package/dist/v2/runtime/runner/index.d.cts +2 -2
- package/dist/v2/runtime/runner/index.d.mts +2 -2
- package/dist/v2/runtime/runner/index.mjs +1 -1
- package/dist/v2/runtime/runner/intelligence.cjs +25 -85
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts +2 -31
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.mts +2 -31
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.mjs +27 -87
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
- package/package.json +8 -8
- package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs +0 -82
- package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs.map +0 -1
- package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs +0 -81
- package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs.map +0 -1
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { RuntimeEventSubject, RuntimeEventTypes } from "../../service-adapters/events.mjs";
|
|
3
|
+
import { aguiToGQL } from "../../graphql/message-conversion/agui-to-gql.mjs";
|
|
4
|
+
import { convertToolsToVercelAITools } from "../../agent/index.mjs";
|
|
5
|
+
import { randomUUID } from "@copilotkit/shared";
|
|
6
|
+
import { Observable } from "rxjs";
|
|
7
|
+
import { AbstractAgent, EventType } from "@ag-ui/client";
|
|
8
|
+
import { InvalidToolInputError, TypeValidationError, asSchema } from "ai";
|
|
9
|
+
|
|
10
|
+
//#region src/v1-deprecated/lib/runtime/legacy-service-adapter-agent.ts
|
|
11
|
+
/**
|
|
12
|
+
* More than one step is required: the v2 client starts a follow-up run only
|
|
13
|
+
* after it executes a frontend tool, so a server tool's result reaches the
|
|
14
|
+
* model only if this run calls it again. Ten is the limit BuiltInAgent uses
|
|
15
|
+
* when it loops (with learned skills). Its own default is one step, which
|
|
16
|
+
* stops before answering a server tool (OSS-1232).
|
|
17
|
+
*/
|
|
18
|
+
const MAX_STEPS = 10;
|
|
19
|
+
/** Roles `aguiToGQL` converts. Anything else (e.g. `activity`) has no v1 form. */
|
|
20
|
+
const V1_ROLES = new Set([
|
|
21
|
+
"developer",
|
|
22
|
+
"system",
|
|
23
|
+
"assistant",
|
|
24
|
+
"user",
|
|
25
|
+
"tool"
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* Runs a v1 `CopilotServiceAdapter` through its own `process()` method.
|
|
29
|
+
*
|
|
30
|
+
* Since v1.50.0 the runtime turned a service adapter into a `BuiltInAgent`,
|
|
31
|
+
* which only works when the adapter can name a model. An adapter whose value
|
|
32
|
+
* lives in `process()` -- `LangChainAdapter`'s `chainFn` above all -- had no
|
|
33
|
+
* path to execution at all (#3217). This agent is that path: it converts the
|
|
34
|
+
* AG-UI input to the v1 request shape, calls `process()`, and maps the
|
|
35
|
+
* adapter's runtime events back to AG-UI events.
|
|
36
|
+
*
|
|
37
|
+
* Server-side v1 `actions` and `mcpServers` reach it the same way they reach
|
|
38
|
+
* `BuiltInAgent`, as `config.tools`. They are advertised to the adapter
|
|
39
|
+
* alongside the frontend tools, and executed here when the model calls them,
|
|
40
|
+
* which is what the v1 runtime did before v1.50.0.
|
|
41
|
+
*/
|
|
42
|
+
var LegacyServiceAdapterAgent = class extends AbstractAgent {
|
|
43
|
+
constructor(serviceAdapter) {
|
|
44
|
+
super();
|
|
45
|
+
this.serviceAdapter = serviceAdapter;
|
|
46
|
+
this.config = {};
|
|
47
|
+
}
|
|
48
|
+
clone() {
|
|
49
|
+
const cloned = super.clone();
|
|
50
|
+
Reflect.set(cloned, "serviceAdapter", this.serviceAdapter);
|
|
51
|
+
cloned.config = { ...this.config };
|
|
52
|
+
return cloned;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Stops the current run, which is what the runner calls when the user
|
|
56
|
+
* presses Stop. The adapter's in-flight stream is abandoned, no further
|
|
57
|
+
* `process()` step or server-side tool runs, and the run completes without
|
|
58
|
+
* a terminal event, the same as `BuiltInAgent`.
|
|
59
|
+
*/
|
|
60
|
+
abortRun() {
|
|
61
|
+
this.abortController?.abort();
|
|
62
|
+
}
|
|
63
|
+
run(input) {
|
|
64
|
+
return new Observable((subscriber) => {
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
this.abortController = controller;
|
|
67
|
+
const { signal } = controller;
|
|
68
|
+
const emit = (event) => {
|
|
69
|
+
if (!signal.aborted) subscriber.next(event);
|
|
70
|
+
};
|
|
71
|
+
const release = () => {
|
|
72
|
+
if (this.abortController === controller) this.abortController = void 0;
|
|
73
|
+
};
|
|
74
|
+
this.execute(input, emit, signal).then(() => {
|
|
75
|
+
release();
|
|
76
|
+
if (signal.aborted) {
|
|
77
|
+
subscriber.complete();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
emit({
|
|
81
|
+
type: EventType.RUN_FINISHED,
|
|
82
|
+
threadId: input.threadId,
|
|
83
|
+
runId: input.runId
|
|
84
|
+
});
|
|
85
|
+
subscriber.complete();
|
|
86
|
+
}, (error) => {
|
|
87
|
+
release();
|
|
88
|
+
if (signal.aborted) {
|
|
89
|
+
subscriber.complete();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
emit({
|
|
93
|
+
type: EventType.RUN_ERROR,
|
|
94
|
+
message: error instanceof Error ? error.message : String(error)
|
|
95
|
+
});
|
|
96
|
+
subscriber.error(error);
|
|
97
|
+
});
|
|
98
|
+
return () => {
|
|
99
|
+
controller.abort();
|
|
100
|
+
release();
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async execute(input, emit, signal) {
|
|
105
|
+
emit({
|
|
106
|
+
type: EventType.RUN_STARTED,
|
|
107
|
+
threadId: input.threadId,
|
|
108
|
+
runId: input.runId
|
|
109
|
+
});
|
|
110
|
+
const frontendNames = new Set(input.tools.map((tool) => tool.name));
|
|
111
|
+
const serverTools = /* @__PURE__ */ new Map();
|
|
112
|
+
for (const tool of this.config.tools ?? []) if (tool.execute && !frontendNames.has(tool.name)) serverTools.set(tool.name, tool);
|
|
113
|
+
const actions = [...input.tools.map((tool) => ({
|
|
114
|
+
name: tool.name,
|
|
115
|
+
description: tool.description ?? "",
|
|
116
|
+
jsonSchema: JSON.stringify(tool.parameters ?? {
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: {}
|
|
119
|
+
})
|
|
120
|
+
})), ...await Promise.all([...serverTools.values()].map(async (tool) => ({
|
|
121
|
+
name: tool.name,
|
|
122
|
+
description: tool.description ?? "",
|
|
123
|
+
jsonSchema: JSON.stringify(await asSchema(tool.parameters).jsonSchema)
|
|
124
|
+
})))];
|
|
125
|
+
const messages = [];
|
|
126
|
+
if (input.context?.length) messages.push({
|
|
127
|
+
id: randomUUID(),
|
|
128
|
+
role: "system",
|
|
129
|
+
content: "## Context from the application\n" + input.context.map((ctx) => `${ctx.description}:\n${ctx.value}\n`).join("")
|
|
130
|
+
});
|
|
131
|
+
messages.push(...input.messages.filter((message) => V1_ROLES.has(message.role)));
|
|
132
|
+
for (let step = 0; step < MAX_STEPS; step++) {
|
|
133
|
+
const result = await this.runStep(input, messages, actions, emit, signal);
|
|
134
|
+
if (signal.aborted) return;
|
|
135
|
+
const answered = new Set(result.results.map((r) => r.toolCallId));
|
|
136
|
+
const pending = result.toolCalls.filter((call) => !answered.has(call.id));
|
|
137
|
+
const serverCalls = pending.filter((call) => serverTools.has(call.name));
|
|
138
|
+
if (result.text || result.toolCalls.length) messages.push({
|
|
139
|
+
id: result.textMessageId ?? randomUUID(),
|
|
140
|
+
role: "assistant",
|
|
141
|
+
content: result.text,
|
|
142
|
+
...result.toolCalls.length && { toolCalls: result.toolCalls.map((call) => ({
|
|
143
|
+
id: call.id,
|
|
144
|
+
type: "function",
|
|
145
|
+
function: {
|
|
146
|
+
name: call.name,
|
|
147
|
+
arguments: call.args || "{}"
|
|
148
|
+
}
|
|
149
|
+
})) }
|
|
150
|
+
});
|
|
151
|
+
for (const { toolCallId, content } of result.results) messages.push({
|
|
152
|
+
id: randomUUID(),
|
|
153
|
+
role: "tool",
|
|
154
|
+
toolCallId,
|
|
155
|
+
content
|
|
156
|
+
});
|
|
157
|
+
const rejected = /* @__PURE__ */ new Set();
|
|
158
|
+
for (const call of pending) {
|
|
159
|
+
if (serverTools.has(call.name)) continue;
|
|
160
|
+
const tool = input.tools.find((t) => t.name === call.name);
|
|
161
|
+
if (!tool) continue;
|
|
162
|
+
let schema;
|
|
163
|
+
try {
|
|
164
|
+
schema = convertToolsToVercelAITools([tool])[tool.name]?.inputSchema;
|
|
165
|
+
} catch {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const checked = await validateToolArgs(call, schema);
|
|
169
|
+
if ("error" in checked) {
|
|
170
|
+
rejected.add(call.id);
|
|
171
|
+
emit({
|
|
172
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
173
|
+
messageId: randomUUID(),
|
|
174
|
+
toolCallId: call.id,
|
|
175
|
+
content: checked.error
|
|
176
|
+
});
|
|
177
|
+
messages.push({
|
|
178
|
+
id: randomUUID(),
|
|
179
|
+
role: "tool",
|
|
180
|
+
toolCallId: call.id,
|
|
181
|
+
content: checked.error
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
for (const call of serverCalls) {
|
|
186
|
+
if (signal.aborted) return;
|
|
187
|
+
const content = await this.executeServerTool(serverTools.get(call.name), call);
|
|
188
|
+
emit({
|
|
189
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
190
|
+
messageId: randomUUID(),
|
|
191
|
+
toolCallId: call.id,
|
|
192
|
+
content
|
|
193
|
+
});
|
|
194
|
+
messages.push({
|
|
195
|
+
id: randomUUID(),
|
|
196
|
+
role: "tool",
|
|
197
|
+
toolCallId: call.id,
|
|
198
|
+
content
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const answeredHere = serverCalls.length + rejected.size;
|
|
202
|
+
if (!answeredHere || answeredHere !== pending.length) return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async executeServerTool(tool, call) {
|
|
206
|
+
const checked = await validateToolArgs(call, tool.parameters);
|
|
207
|
+
if ("error" in checked) return checked.error;
|
|
208
|
+
try {
|
|
209
|
+
const output = await tool.execute(checked.value);
|
|
210
|
+
return typeof output === "string" ? output : JSON.stringify(output ?? "");
|
|
211
|
+
} catch (error) {
|
|
212
|
+
return JSON.stringify({
|
|
213
|
+
error: {
|
|
214
|
+
code: "ERROR",
|
|
215
|
+
message: error instanceof Error ? error.message : String(error)
|
|
216
|
+
},
|
|
217
|
+
result: ""
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** One call to `process()`, with its runtime events forwarded as AG-UI. */
|
|
222
|
+
async runStep(input, messages, actions, emit, signal) {
|
|
223
|
+
let streamCallback;
|
|
224
|
+
await this.serviceAdapter.process({
|
|
225
|
+
eventSource: { stream: async (callback) => {
|
|
226
|
+
streamCallback = callback;
|
|
227
|
+
} },
|
|
228
|
+
messages: aguiToGQL(messages),
|
|
229
|
+
actions,
|
|
230
|
+
threadId: input.threadId,
|
|
231
|
+
runId: input.runId
|
|
232
|
+
});
|
|
233
|
+
const result = {
|
|
234
|
+
text: "",
|
|
235
|
+
toolCalls: [],
|
|
236
|
+
results: []
|
|
237
|
+
};
|
|
238
|
+
if (!streamCallback || signal.aborted) return result;
|
|
239
|
+
const subject = new RuntimeEventSubject(signal);
|
|
240
|
+
const done = new Promise((resolve, reject) => {
|
|
241
|
+
subject.subscribe({
|
|
242
|
+
next: (event) => {
|
|
243
|
+
try {
|
|
244
|
+
this.forward(event, result, emit);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
reject(error);
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
error: reject,
|
|
250
|
+
complete: resolve
|
|
251
|
+
});
|
|
252
|
+
signal.addEventListener("abort", () => resolve(), { once: true });
|
|
253
|
+
});
|
|
254
|
+
streamCallback(subject).then(() => subject.complete(), (error) => subject.error(error));
|
|
255
|
+
await done;
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
forward(event, step, emit) {
|
|
259
|
+
switch (event.type) {
|
|
260
|
+
case RuntimeEventTypes.TextMessageStart:
|
|
261
|
+
step.textMessageId ??= event.messageId;
|
|
262
|
+
emit({
|
|
263
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
264
|
+
messageId: event.messageId,
|
|
265
|
+
role: "assistant"
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
case RuntimeEventTypes.TextMessageContent:
|
|
269
|
+
if (!event.content) return;
|
|
270
|
+
step.text += event.content;
|
|
271
|
+
emit({
|
|
272
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
273
|
+
messageId: event.messageId,
|
|
274
|
+
delta: event.content
|
|
275
|
+
});
|
|
276
|
+
return;
|
|
277
|
+
case RuntimeEventTypes.TextMessageEnd:
|
|
278
|
+
emit({
|
|
279
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
280
|
+
messageId: event.messageId
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
case RuntimeEventTypes.ActionExecutionStart:
|
|
284
|
+
step.toolCalls.push({
|
|
285
|
+
id: event.actionExecutionId,
|
|
286
|
+
name: event.actionName,
|
|
287
|
+
args: ""
|
|
288
|
+
});
|
|
289
|
+
emit({
|
|
290
|
+
type: EventType.TOOL_CALL_START,
|
|
291
|
+
toolCallId: event.actionExecutionId,
|
|
292
|
+
toolCallName: event.actionName,
|
|
293
|
+
parentMessageId: event.parentMessageId
|
|
294
|
+
});
|
|
295
|
+
return;
|
|
296
|
+
case RuntimeEventTypes.ActionExecutionArgs: {
|
|
297
|
+
if (!event.args) return;
|
|
298
|
+
const call = step.toolCalls.find((c) => c.id === event.actionExecutionId);
|
|
299
|
+
if (call) call.args += event.args;
|
|
300
|
+
emit({
|
|
301
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
302
|
+
toolCallId: event.actionExecutionId,
|
|
303
|
+
delta: event.args
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
case RuntimeEventTypes.ActionExecutionEnd:
|
|
308
|
+
emit({
|
|
309
|
+
type: EventType.TOOL_CALL_END,
|
|
310
|
+
toolCallId: event.actionExecutionId
|
|
311
|
+
});
|
|
312
|
+
return;
|
|
313
|
+
case RuntimeEventTypes.ActionExecutionResult:
|
|
314
|
+
step.results.push({
|
|
315
|
+
toolCallId: event.actionExecutionId,
|
|
316
|
+
content: event.result
|
|
317
|
+
});
|
|
318
|
+
emit({
|
|
319
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
320
|
+
messageId: randomUUID(),
|
|
321
|
+
toolCallId: event.actionExecutionId,
|
|
322
|
+
content: event.result
|
|
323
|
+
});
|
|
324
|
+
return;
|
|
325
|
+
case RuntimeEventTypes.RunError: throw new Error(event.message);
|
|
326
|
+
default: return;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Parses a tool call's arguments and checks them against `schema`, with the
|
|
332
|
+
* AI SDK's own error, so a failure reads exactly as it does on BuiltInAgent.
|
|
333
|
+
* Returns the validated value (undeclared keys stripped by a Zod schema) or
|
|
334
|
+
* the text of the error result to send back.
|
|
335
|
+
*/
|
|
336
|
+
async function validateToolArgs(call, schema) {
|
|
337
|
+
let args = {};
|
|
338
|
+
try {
|
|
339
|
+
args = call.args ? JSON.parse(call.args) : {};
|
|
340
|
+
} catch {
|
|
341
|
+
return { error: `The tool "${call.name}" received arguments that are not valid JSON.` };
|
|
342
|
+
}
|
|
343
|
+
const validate = asSchema(schema).validate;
|
|
344
|
+
if (!validate) return { value: args };
|
|
345
|
+
const result = await validate(args);
|
|
346
|
+
if ("error" in result) return { error: `Error: ${new InvalidToolInputError({
|
|
347
|
+
toolName: call.name,
|
|
348
|
+
toolInput: call.args,
|
|
349
|
+
cause: TypeValidationError.wrap({
|
|
350
|
+
value: args,
|
|
351
|
+
cause: result.error
|
|
352
|
+
})
|
|
353
|
+
}).message}` };
|
|
354
|
+
return { value: result.value };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
//#endregion
|
|
358
|
+
export { LegacyServiceAdapterAgent };
|
|
359
|
+
//# sourceMappingURL=legacy-service-adapter-agent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-service-adapter-agent.mjs","names":[],"sources":["../../../../src/v1-deprecated/lib/runtime/legacy-service-adapter-agent.ts"],"sourcesContent":["import { AbstractAgent, EventType } from \"@ag-ui/client\";\nimport type {\n BaseEvent,\n Message as AguiMessage,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\nimport { asSchema, InvalidToolInputError, TypeValidationError } from \"ai\";\nimport type { FlexibleSchema } from \"ai\";\nimport { randomUUID } from \"@copilotkit/shared\";\nimport type * as SharedAgui from \"@copilotkit/shared\";\nimport { convertToolsToVercelAITools } from \"../../../agent\";\nimport type { BuiltInAgentClassicConfig } from \"../../../agent\";\nimport type { CopilotServiceAdapter } from \"../../service-adapters/service-adapter\";\nimport {\n RuntimeEventSubject,\n RuntimeEventTypes,\n} from \"../../service-adapters/events\";\nimport type {\n RuntimeEvent,\n RuntimeEventSource,\n} from \"../../service-adapters/events\";\nimport { aguiToGQL } from \"../../graphql/message-conversion/agui-to-gql\";\nimport type { ActionInput } from \"../../graphql/inputs/action.input\";\n\n/**\n * More than one step is required: the v2 client starts a follow-up run only\n * after it executes a frontend tool, so a server tool's result reaches the\n * model only if this run calls it again. Ten is the limit BuiltInAgent uses\n * when it loops (with learned skills). Its own default is one step, which\n * stops before answering a server tool (OSS-1232).\n */\nconst MAX_STEPS = 10;\n\n/** Roles `aguiToGQL` converts. Anything else (e.g. `activity`) has no v1 form. */\nconst V1_ROLES = new Set([\"developer\", \"system\", \"assistant\", \"user\", \"tool\"]);\n\ntype ServerTool = NonNullable<BuiltInAgentClassicConfig[\"tools\"]>[number];\n\ninterface StepToolCall {\n id: string;\n name: string;\n args: string;\n}\n\ninterface StepResult {\n text: string;\n textMessageId?: string;\n toolCalls: StepToolCall[];\n results: { toolCallId: string; content: string }[];\n}\n\n/**\n * Runs a v1 `CopilotServiceAdapter` through its own `process()` method.\n *\n * Since v1.50.0 the runtime turned a service adapter into a `BuiltInAgent`,\n * which only works when the adapter can name a model. An adapter whose value\n * lives in `process()` -- `LangChainAdapter`'s `chainFn` above all -- had no\n * path to execution at all (#3217). This agent is that path: it converts the\n * AG-UI input to the v1 request shape, calls `process()`, and maps the\n * adapter's runtime events back to AG-UI events.\n *\n * Server-side v1 `actions` and `mcpServers` reach it the same way they reach\n * `BuiltInAgent`, as `config.tools`. They are advertised to the adapter\n * alongside the frontend tools, and executed here when the model calls them,\n * which is what the v1 runtime did before v1.50.0.\n */\nexport class LegacyServiceAdapterAgent extends AbstractAgent {\n /** Written by `assignToolsToAgents`, the same as on `BuiltInAgent`. */\n config: { tools?: BuiltInAgentClassicConfig[\"tools\"] } = {};\n\n private abortController?: AbortController;\n\n constructor(private readonly serviceAdapter: CopilotServiceAdapter) {\n super();\n }\n\n clone(): LegacyServiceAdapterAgent {\n const cloned = super.clone() as LegacyServiceAdapterAgent;\n Reflect.set(cloned, \"serviceAdapter\", this.serviceAdapter);\n cloned.config = { ...this.config };\n return cloned;\n }\n\n /**\n * Stops the current run, which is what the runner calls when the user\n * presses Stop. The adapter's in-flight stream is abandoned, no further\n * `process()` step or server-side tool runs, and the run completes without\n * a terminal event, the same as `BuiltInAgent`.\n */\n abortRun(): void {\n this.abortController?.abort();\n }\n\n run(input: RunAgentInput): Observable<BaseEvent> {\n return new Observable<BaseEvent>((subscriber) => {\n const controller = new AbortController();\n this.abortController = controller;\n const { signal } = controller;\n const emit = (event: BaseEvent) => {\n if (!signal.aborted) subscriber.next(event);\n };\n const release = () => {\n if (this.abortController === controller) {\n this.abortController = undefined;\n }\n };\n\n this.execute(input, emit, signal).then(\n () => {\n release();\n if (signal.aborted) {\n subscriber.complete();\n return;\n }\n emit({\n type: EventType.RUN_FINISHED,\n threadId: input.threadId,\n runId: input.runId,\n } as BaseEvent);\n subscriber.complete();\n },\n (error: unknown) => {\n release();\n if (signal.aborted) {\n subscriber.complete();\n return;\n }\n emit({\n type: EventType.RUN_ERROR,\n message: error instanceof Error ? error.message : String(error),\n } as BaseEvent);\n subscriber.error(error);\n },\n );\n\n return () => {\n controller.abort();\n release();\n };\n });\n }\n\n private async execute(\n input: RunAgentInput,\n emit: (event: BaseEvent) => void,\n signal: AbortSignal,\n ): Promise<void> {\n emit({\n type: EventType.RUN_STARTED,\n threadId: input.threadId,\n runId: input.runId,\n } as BaseEvent);\n\n const frontendNames = new Set(input.tools.map((tool) => tool.name));\n const serverTools = new Map<string, ServerTool>();\n for (const tool of this.config.tools ?? []) {\n // A frontend tool of the same name wins, as it does on BuiltInAgent.\n if (tool.execute && !frontendNames.has(tool.name)) {\n serverTools.set(tool.name, tool);\n }\n }\n\n const actions = [\n ...input.tools.map((tool) => ({\n name: tool.name,\n description: tool.description ?? \"\",\n jsonSchema: JSON.stringify(\n tool.parameters ?? { type: \"object\", properties: {} },\n ),\n })),\n ...(await Promise.all(\n [...serverTools.values()].map(async (tool) => ({\n name: tool.name,\n description: tool.description ?? \"\",\n // v1 actions and MCP tools arrive here with Zod parameters; the AI\n // SDK is what converts those for BuiltInAgent too.\n jsonSchema: JSON.stringify(\n await asSchema(tool.parameters as FlexibleSchema<unknown>)\n .jsonSchema,\n ),\n })),\n )),\n ] as ActionInput[];\n\n const messages: AguiMessage[] = [];\n if (input.context?.length) {\n // The v1 frontend folded readable context into the system message. The\n // v2 frontend sends it separately, so put it back where the adapter\n // expects it.\n messages.push({\n id: randomUUID(),\n role: \"system\",\n content:\n \"## Context from the application\\n\" +\n input.context\n .map((ctx) => `${ctx.description}:\\n${ctx.value}\\n`)\n .join(\"\"),\n });\n }\n messages.push(\n ...input.messages.filter((message) => V1_ROLES.has(message.role)),\n );\n\n for (let step = 0; step < MAX_STEPS; step++) {\n const result = await this.runStep(input, messages, actions, emit, signal);\n if (signal.aborted) return;\n\n const answered = new Set(result.results.map((r) => r.toolCallId));\n const pending = result.toolCalls.filter((call) => !answered.has(call.id));\n const serverCalls = pending.filter((call) => serverTools.has(call.name));\n\n if (result.text || result.toolCalls.length) {\n messages.push({\n id: result.textMessageId ?? randomUUID(),\n role: \"assistant\",\n content: result.text,\n ...(result.toolCalls.length && {\n toolCalls: result.toolCalls.map((call) => ({\n id: call.id,\n type: \"function\" as const,\n function: { name: call.name, arguments: call.args || \"{}\" },\n })),\n }),\n });\n }\n for (const { toolCallId, content } of result.results) {\n messages.push({ id: randomUUID(), role: \"tool\", toolCallId, content });\n }\n\n // BuiltInAgent checks frontend tool calls against their JSON Schema on\n // the server too, and answers a failing call with an error result\n // instead of sending it to the browser. Do the same, so the client never\n // runs a handler with arguments its own schema rejects.\n const rejected = new Set<string>();\n for (const call of pending) {\n if (serverTools.has(call.name)) continue;\n const tool = input.tools.find((t) => t.name === call.name);\n if (!tool) continue;\n let schema: FlexibleSchema<unknown> | undefined;\n try {\n schema = convertToolsToVercelAITools([tool])[tool.name]?.inputSchema;\n } catch {\n // Not a JSON Schema the validator accepts: leave the call as it was.\n continue;\n }\n const checked = await validateToolArgs(call, schema);\n if (\"error\" in checked) {\n rejected.add(call.id);\n emit({\n type: EventType.TOOL_CALL_RESULT,\n messageId: randomUUID(),\n toolCallId: call.id,\n content: checked.error,\n } as BaseEvent);\n messages.push({\n id: randomUUID(),\n role: \"tool\",\n toolCallId: call.id,\n content: checked.error,\n });\n }\n }\n\n for (const call of serverCalls) {\n if (signal.aborted) return;\n const content = await this.executeServerTool(\n serverTools.get(call.name)!,\n call,\n );\n emit({\n type: EventType.TOOL_CALL_RESULT,\n messageId: randomUUID(),\n toolCallId: call.id,\n content,\n } as BaseEvent);\n messages.push({\n id: randomUUID(),\n role: \"tool\",\n toolCallId: call.id,\n content,\n });\n }\n\n // Another step only makes sense when every open call has a result. A\n // frontend tool call ends the run; the client executes it and starts\n // the next one. A rejected call already has its (error) result.\n const answeredHere = serverCalls.length + rejected.size;\n if (!answeredHere || answeredHere !== pending.length) {\n return;\n }\n }\n }\n\n private async executeServerTool(\n tool: ServerTool,\n call: StepToolCall,\n ): Promise<string> {\n // Validate against the tool's schema, as the AI SDK does for BuiltInAgent,\n // so one action behaves the same whichever adapter runs it. Arguments that\n // fail go back to the model as an error result it can correct, and never\n // reach the handler. Unknown keys are stripped. v1 itself (<= 1.10) passed\n // the raw parsed JSON to the handler; this follows BuiltInAgent instead.\n const checked = await validateToolArgs(\n call,\n tool.parameters as FlexibleSchema<unknown> | undefined,\n );\n if (\"error\" in checked) return checked.error;\n try {\n const output = await tool.execute!(checked.value as never);\n return typeof output === \"string\" ? output : JSON.stringify(output ?? \"\");\n } catch (error) {\n return JSON.stringify({\n error: {\n code: \"ERROR\",\n message: error instanceof Error ? error.message : String(error),\n },\n result: \"\",\n });\n }\n }\n\n /** One call to `process()`, with its runtime events forwarded as AG-UI. */\n private async runStep(\n input: RunAgentInput,\n messages: AguiMessage[],\n actions: ActionInput[],\n emit: (event: BaseEvent) => void,\n signal: AbortSignal,\n ): Promise<StepResult> {\n let streamCallback:\n | ((eventStream$: RuntimeEventSubject) => Promise<void>)\n | undefined;\n // `RuntimeEventSource.stream` only stores the callback; the code that\n // consumed it was deleted in v1.50.0. Capture it and consume it here.\n const eventSource = {\n stream: async (\n callback: (eventStream$: RuntimeEventSubject) => Promise<void>,\n ) => {\n streamCallback = callback;\n },\n } as unknown as RuntimeEventSource;\n\n await this.serviceAdapter.process({\n eventSource,\n messages: aguiToGQL(messages as SharedAgui.Message[]),\n actions,\n threadId: input.threadId,\n runId: input.runId,\n });\n\n const result: StepResult = { text: \"\", toolCalls: [], results: [] };\n if (!streamCallback || signal.aborted) {\n return result;\n }\n\n const subject = new RuntimeEventSubject(signal);\n const done = new Promise<void>((resolve, reject) => {\n subject.subscribe({\n next: (event) => {\n try {\n this.forward(event, result, emit);\n } catch (error) {\n reject(error);\n }\n },\n error: reject,\n complete: resolve,\n });\n // Nothing can cancel an adapter's stream from outside, so on abort stop\n // waiting for it; `emit` already drops anything it sends afterwards.\n signal.addEventListener(\"abort\", () => resolve(), { once: true });\n });\n // An adapter that returns without completing its stream is finished too.\n streamCallback(subject).then(\n () => subject.complete(),\n (error) => subject.error(error),\n );\n await done;\n return result;\n }\n\n private forward(\n event: RuntimeEvent,\n step: StepResult,\n emit: (event: BaseEvent) => void,\n ): void {\n switch (event.type) {\n case RuntimeEventTypes.TextMessageStart:\n step.textMessageId ??= event.messageId;\n emit({\n type: EventType.TEXT_MESSAGE_START,\n messageId: event.messageId,\n role: \"assistant\",\n } as BaseEvent);\n return;\n case RuntimeEventTypes.TextMessageContent:\n // AG-UI rejects an empty delta.\n if (!event.content) return;\n step.text += event.content;\n emit({\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId: event.messageId,\n delta: event.content,\n } as BaseEvent);\n return;\n case RuntimeEventTypes.TextMessageEnd:\n emit({\n type: EventType.TEXT_MESSAGE_END,\n messageId: event.messageId,\n } as BaseEvent);\n return;\n case RuntimeEventTypes.ActionExecutionStart:\n step.toolCalls.push({\n id: event.actionExecutionId,\n name: event.actionName,\n args: \"\",\n });\n emit({\n type: EventType.TOOL_CALL_START,\n toolCallId: event.actionExecutionId,\n toolCallName: event.actionName,\n parentMessageId: event.parentMessageId,\n } as BaseEvent);\n return;\n case RuntimeEventTypes.ActionExecutionArgs: {\n if (!event.args) return;\n const call = step.toolCalls.find(\n (c) => c.id === event.actionExecutionId,\n );\n if (call) call.args += event.args;\n emit({\n type: EventType.TOOL_CALL_ARGS,\n toolCallId: event.actionExecutionId,\n delta: event.args,\n } as BaseEvent);\n return;\n }\n case RuntimeEventTypes.ActionExecutionEnd:\n emit({\n type: EventType.TOOL_CALL_END,\n toolCallId: event.actionExecutionId,\n } as BaseEvent);\n return;\n case RuntimeEventTypes.ActionExecutionResult:\n step.results.push({\n toolCallId: event.actionExecutionId,\n content: event.result,\n });\n emit({\n type: EventType.TOOL_CALL_RESULT,\n messageId: randomUUID(),\n toolCallId: event.actionExecutionId,\n content: event.result,\n } as BaseEvent);\n return;\n case RuntimeEventTypes.RunError:\n throw new Error(event.message);\n default:\n // Agent-state and LangGraph meta events came only from remote agent\n // endpoints, which do not run through a service adapter.\n return;\n }\n }\n}\n\n/**\n * Parses a tool call's arguments and checks them against `schema`, with the\n * AI SDK's own error, so a failure reads exactly as it does on BuiltInAgent.\n * Returns the validated value (undeclared keys stripped by a Zod schema) or\n * the text of the error result to send back.\n */\nasync function validateToolArgs(\n call: StepToolCall,\n schema: FlexibleSchema<unknown> | undefined,\n): Promise<{ value: unknown } | { error: string }> {\n let args: unknown = {};\n try {\n args = call.args ? JSON.parse(call.args) : {};\n } catch {\n return {\n error: `The tool \"${call.name}\" received arguments that are not valid JSON.`,\n };\n }\n const validate = asSchema(schema).validate;\n if (!validate) return { value: args };\n const result = await validate(args);\n // `in`, not `!result.success`: this package compiles with `strict: false`,\n // which does not narrow on a boolean discriminant.\n if (\"error\" in result) {\n const error = new InvalidToolInputError({\n toolName: call.name,\n toolInput: call.args,\n cause: TypeValidationError.wrap({ value: args, cause: result.error }),\n });\n return { error: `Error: ${error.message}` };\n }\n return { value: result.value };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAM,YAAY;;AAGlB,MAAM,WAAW,IAAI,IAAI;CAAC;CAAa;CAAU;CAAa;CAAQ;CAAO,CAAC;;;;;;;;;;;;;;;;AAgC9E,IAAa,4BAAb,cAA+C,cAAc;CAM3D,YAAY,AAAiB,gBAAuC;AAClE,SAAO;EADoB;gBAJ4B,EAAE;;CAQ3D,QAAmC;EACjC,MAAM,SAAS,MAAM,OAAO;AAC5B,UAAQ,IAAI,QAAQ,kBAAkB,KAAK,eAAe;AAC1D,SAAO,SAAS,EAAE,GAAG,KAAK,QAAQ;AAClC,SAAO;;;;;;;;CAST,WAAiB;AACf,OAAK,iBAAiB,OAAO;;CAG/B,IAAI,OAA6C;AAC/C,SAAO,IAAI,YAAuB,eAAe;GAC/C,MAAM,aAAa,IAAI,iBAAiB;AACxC,QAAK,kBAAkB;GACvB,MAAM,EAAE,WAAW;GACnB,MAAM,QAAQ,UAAqB;AACjC,QAAI,CAAC,OAAO,QAAS,YAAW,KAAK,MAAM;;GAE7C,MAAM,gBAAgB;AACpB,QAAI,KAAK,oBAAoB,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+12,17 @@ const telemetryClient = new _copilotkit_shared_telemetry.TelemetryClient({
|
|
|
12
12
|
packageName: packageJson.name,
|
|
13
13
|
packageVersion: packageJson.version
|
|
14
14
|
});
|
|
15
|
+
/**
|
|
16
|
+
* The configured agents, counted without touching `runtime.instance`. Every
|
|
17
|
+
* v1 endpoint captures telemetry before it calls `handleServiceAdapter`, and
|
|
18
|
+
* reading the instance there builds the v2 runtime with these agents, so the
|
|
19
|
+
* per-request factory `handleServiceAdapter` installs afterwards was never
|
|
20
|
+
* used and no v1 `actions` or `mcpServers` tool reached an agent.
|
|
21
|
+
*/
|
|
22
|
+
function countConfiguredAgents(agents) {
|
|
23
|
+
if (!agents || typeof agents !== "object" || "then" in agents) return 0;
|
|
24
|
+
return Object.keys(agents).length;
|
|
25
|
+
}
|
|
15
26
|
function getRuntimeInstanceTelemetryInfo(options) {
|
|
16
27
|
const runtime = options.runtime;
|
|
17
28
|
const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];
|
|
@@ -42,7 +53,7 @@ function getRuntimeInstanceTelemetryInfo(options) {
|
|
|
42
53
|
actionsAmount: runtime.params?.actions?.length ?? 0,
|
|
43
54
|
endpointsAmount: remoteEndpoints.length,
|
|
44
55
|
endpointTypes: endpointsInfo.endpointTypes,
|
|
45
|
-
agentsAmount:
|
|
56
|
+
agentsAmount: countConfiguredAgents(runtime.params?.agents),
|
|
46
57
|
hashedLgcKey: endpointsInfo.hashedKey,
|
|
47
58
|
"cloud.api_key_provided": apiKeyProvided,
|
|
48
59
|
...apiKeyProvided ? { "cloud.public_api_key": publicApiKey } : {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-client.cjs","names":["TelemetryClient","resolveEndpointType","EndpointType"],"sources":["../../../src/v1-deprecated/lib/telemetry-client.ts"],"sourcesContent":["import { TelemetryClient } from \"@copilotkit/shared/telemetry\";\nimport { createHash } from \"node:crypto\";\nimport { CopilotRuntime, resolveEndpointType } from \"./runtime/copilot-runtime\";\nimport type { RuntimeInstanceCreatedInfo } from \"@copilotkit/shared/src/telemetry/events\";\nimport type { CreateCopilotRuntimeServerOptions } from \"./integrations/shared\";\nimport type { LangGraphPlatformEndpoint } from \"./runtime/types\";\nimport { EndpointType } from \"./runtime/types\";\nconst packageJson = require(\"../../../package.json\");\n\nconst telemetryClient = new TelemetryClient({\n packageName: packageJson.name,\n packageVersion: packageJson.version,\n});\n\nexport function getRuntimeInstanceTelemetryInfo(\n options: CreateCopilotRuntimeServerOptions,\n): RuntimeInstanceCreatedInfo {\n const runtime = options.runtime;\n const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];\n const endpointsInfo = remoteEndpoints.reduce(\n (acc, endpoint) => {\n let info = { ...acc };\n\n const endpointType = resolveEndpointType(endpoint);\n if (!info.endpointTypes.includes(endpointType)) {\n info = {\n ...info,\n endpointTypes: [...info.endpointTypes, endpointType],\n };\n }\n\n if (endpointType === EndpointType.LangGraphPlatform) {\n // When type is resolved, recreating a const with casting of type\n const ep = endpoint as LangGraphPlatformEndpoint;\n info = {\n ...info,\n agentsAmount: ep.agents.length,\n hashedKey: ep.langsmithApiKey\n ? createHash(\"sha256\").update(ep.langsmithApiKey).digest(\"hex\")\n : null,\n };\n }\n\n return info;\n },\n { endpointTypes: [], agentsAmount: null, hashedKey: null },\n );\n\n // Get public API key from options.cloud.publicApiKey\n const publicApiKey = options.cloud?.publicApiKey;\n const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;\n\n return {\n actionsAmount: runtime.params?.actions?.length ?? 0,\n endpointsAmount: remoteEndpoints.length,\n endpointTypes: endpointsInfo.endpointTypes,\n agentsAmount:
|
|
1
|
+
{"version":3,"file":"telemetry-client.cjs","names":["TelemetryClient","resolveEndpointType","EndpointType"],"sources":["../../../src/v1-deprecated/lib/telemetry-client.ts"],"sourcesContent":["import { TelemetryClient } from \"@copilotkit/shared/telemetry\";\nimport { createHash } from \"node:crypto\";\nimport { CopilotRuntime, resolveEndpointType } from \"./runtime/copilot-runtime\";\nimport type { RuntimeInstanceCreatedInfo } from \"@copilotkit/shared/src/telemetry/events\";\nimport type { CreateCopilotRuntimeServerOptions } from \"./integrations/shared\";\nimport type { LangGraphPlatformEndpoint } from \"./runtime/types\";\nimport { EndpointType } from \"./runtime/types\";\nconst packageJson = require(\"../../../package.json\");\n\nconst telemetryClient = new TelemetryClient({\n packageName: packageJson.name,\n packageVersion: packageJson.version,\n});\n\n/**\n * The configured agents, counted without touching `runtime.instance`. Every\n * v1 endpoint captures telemetry before it calls `handleServiceAdapter`, and\n * reading the instance there builds the v2 runtime with these agents, so the\n * per-request factory `handleServiceAdapter` installs afterwards was never\n * used and no v1 `actions` or `mcpServers` tool reached an agent.\n */\nfunction countConfiguredAgents(agents: unknown): number {\n if (!agents || typeof agents !== \"object\" || \"then\" in agents) {\n return 0;\n }\n return Object.keys(agents).length;\n}\n\nexport function getRuntimeInstanceTelemetryInfo(\n options: CreateCopilotRuntimeServerOptions,\n): RuntimeInstanceCreatedInfo {\n const runtime = options.runtime;\n const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];\n const endpointsInfo = remoteEndpoints.reduce(\n (acc, endpoint) => {\n let info = { ...acc };\n\n const endpointType = resolveEndpointType(endpoint);\n if (!info.endpointTypes.includes(endpointType)) {\n info = {\n ...info,\n endpointTypes: [...info.endpointTypes, endpointType],\n };\n }\n\n if (endpointType === EndpointType.LangGraphPlatform) {\n // When type is resolved, recreating a const with casting of type\n const ep = endpoint as LangGraphPlatformEndpoint;\n info = {\n ...info,\n agentsAmount: ep.agents.length,\n hashedKey: ep.langsmithApiKey\n ? createHash(\"sha256\").update(ep.langsmithApiKey).digest(\"hex\")\n : null,\n };\n }\n\n return info;\n },\n { endpointTypes: [], agentsAmount: null, hashedKey: null },\n );\n\n // Get public API key from options.cloud.publicApiKey\n const publicApiKey = options.cloud?.publicApiKey;\n const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;\n\n return {\n actionsAmount: runtime.params?.actions?.length ?? 0,\n endpointsAmount: remoteEndpoints.length,\n endpointTypes: endpointsInfo.endpointTypes,\n agentsAmount: countConfiguredAgents(runtime.params?.agents),\n hashedLgcKey: endpointsInfo.hashedKey,\n \"cloud.api_key_provided\": apiKeyProvided,\n ...(apiKeyProvided ? { \"cloud.public_api_key\": publicApiKey } : {}),\n ...(options.cloud?.baseUrl\n ? { \"cloud.base_url\": options.cloud.baseUrl }\n : {}),\n } as RuntimeInstanceCreatedInfo;\n}\n\nexport default telemetryClient;\n"],"mappings":";;;;;;;;;AAOA,MAAM;AAEN,MAAM,kBAAkB,IAAIA,6CAAgB;CAC1C,aAAa,YAAY;CACzB,gBAAgB,YAAY;CAC7B,CAAC;;;;;;;;AASF,SAAS,sBAAsB,QAAyB;AACtD,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,UAAU,OACrD,QAAO;AAET,QAAO,OAAO,KAAK,OAAO,CAAC;;AAG7B,SAAgB,gCACd,SAC4B;CAC5B,MAAM,UAAU,QAAQ;CACxB,MAAM,kBAAkB,QAAQ,QAAQ,mBAAmB,EAAE;CAC7D,MAAM,gBAAgB,gBAAgB,QACnC,KAAK,aAAa;EACjB,IAAI,OAAO,EAAE,GAAG,KAAK;EAErB,MAAM,eAAeC,4CAAoB,SAAS;AAClD,MAAI,CAAC,KAAK,cAAc,SAAS,aAAa,CAC5C,QAAO;GACL,GAAG;GACH,eAAe,CAAC,GAAG,KAAK,eAAe,aAAa;GACrD;AAGH,MAAI,iBAAiBC,2BAAa,mBAAmB;GAEnD,MAAM,KAAK;AACX,UAAO;IACL,GAAG;IACH,cAAc,GAAG,OAAO;IACxB,WAAW,GAAG,8CACC,SAAS,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,MAAM,GAC7D;IACL;;AAGH,SAAO;IAET;EAAE,eAAe,EAAE;EAAE,cAAc;EAAM,WAAW;EAAM,CAC3D;CAGD,MAAM,eAAe,QAAQ,OAAO;CACpC,MAAM,iBAAiB,CAAC,CAAC,gBAAgB,aAAa,MAAM,CAAC,SAAS;AAEtE,QAAO;EACL,eAAe,QAAQ,QAAQ,SAAS,UAAU;EAClD,iBAAiB,gBAAgB;EACjC,eAAe,cAAc;EAC7B,cAAc,sBAAsB,QAAQ,QAAQ,OAAO;EAC3D,cAAc,cAAc;EAC5B,0BAA0B;EAC1B,GAAI,iBAAiB,EAAE,wBAAwB,cAAc,GAAG,EAAE;EAClE,GAAI,QAAQ,OAAO,UACf,EAAE,kBAAkB,QAAQ,MAAM,SAAS,GAC3C,EAAE;EACP"}
|
|
@@ -11,6 +11,17 @@ const telemetryClient = new TelemetryClient({
|
|
|
11
11
|
packageName: packageJson.name,
|
|
12
12
|
packageVersion: packageJson.version
|
|
13
13
|
});
|
|
14
|
+
/**
|
|
15
|
+
* The configured agents, counted without touching `runtime.instance`. Every
|
|
16
|
+
* v1 endpoint captures telemetry before it calls `handleServiceAdapter`, and
|
|
17
|
+
* reading the instance there builds the v2 runtime with these agents, so the
|
|
18
|
+
* per-request factory `handleServiceAdapter` installs afterwards was never
|
|
19
|
+
* used and no v1 `actions` or `mcpServers` tool reached an agent.
|
|
20
|
+
*/
|
|
21
|
+
function countConfiguredAgents(agents) {
|
|
22
|
+
if (!agents || typeof agents !== "object" || "then" in agents) return 0;
|
|
23
|
+
return Object.keys(agents).length;
|
|
24
|
+
}
|
|
14
25
|
function getRuntimeInstanceTelemetryInfo(options) {
|
|
15
26
|
const runtime = options.runtime;
|
|
16
27
|
const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];
|
|
@@ -41,7 +52,7 @@ function getRuntimeInstanceTelemetryInfo(options) {
|
|
|
41
52
|
actionsAmount: runtime.params?.actions?.length ?? 0,
|
|
42
53
|
endpointsAmount: remoteEndpoints.length,
|
|
43
54
|
endpointTypes: endpointsInfo.endpointTypes,
|
|
44
|
-
agentsAmount:
|
|
55
|
+
agentsAmount: countConfiguredAgents(runtime.params?.agents),
|
|
45
56
|
hashedLgcKey: endpointsInfo.hashedKey,
|
|
46
57
|
"cloud.api_key_provided": apiKeyProvided,
|
|
47
58
|
...apiKeyProvided ? { "cloud.public_api_key": publicApiKey } : {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-client.mjs","names":[],"sources":["../../../src/v1-deprecated/lib/telemetry-client.ts"],"sourcesContent":["import { TelemetryClient } from \"@copilotkit/shared/telemetry\";\nimport { createHash } from \"node:crypto\";\nimport { CopilotRuntime, resolveEndpointType } from \"./runtime/copilot-runtime\";\nimport type { RuntimeInstanceCreatedInfo } from \"@copilotkit/shared/src/telemetry/events\";\nimport type { CreateCopilotRuntimeServerOptions } from \"./integrations/shared\";\nimport type { LangGraphPlatformEndpoint } from \"./runtime/types\";\nimport { EndpointType } from \"./runtime/types\";\nconst packageJson = require(\"../../../package.json\");\n\nconst telemetryClient = new TelemetryClient({\n packageName: packageJson.name,\n packageVersion: packageJson.version,\n});\n\nexport function getRuntimeInstanceTelemetryInfo(\n options: CreateCopilotRuntimeServerOptions,\n): RuntimeInstanceCreatedInfo {\n const runtime = options.runtime;\n const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];\n const endpointsInfo = remoteEndpoints.reduce(\n (acc, endpoint) => {\n let info = { ...acc };\n\n const endpointType = resolveEndpointType(endpoint);\n if (!info.endpointTypes.includes(endpointType)) {\n info = {\n ...info,\n endpointTypes: [...info.endpointTypes, endpointType],\n };\n }\n\n if (endpointType === EndpointType.LangGraphPlatform) {\n // When type is resolved, recreating a const with casting of type\n const ep = endpoint as LangGraphPlatformEndpoint;\n info = {\n ...info,\n agentsAmount: ep.agents.length,\n hashedKey: ep.langsmithApiKey\n ? createHash(\"sha256\").update(ep.langsmithApiKey).digest(\"hex\")\n : null,\n };\n }\n\n return info;\n },\n { endpointTypes: [], agentsAmount: null, hashedKey: null },\n );\n\n // Get public API key from options.cloud.publicApiKey\n const publicApiKey = options.cloud?.publicApiKey;\n const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;\n\n return {\n actionsAmount: runtime.params?.actions?.length ?? 0,\n endpointsAmount: remoteEndpoints.length,\n endpointTypes: endpointsInfo.endpointTypes,\n agentsAmount:
|
|
1
|
+
{"version":3,"file":"telemetry-client.mjs","names":[],"sources":["../../../src/v1-deprecated/lib/telemetry-client.ts"],"sourcesContent":["import { TelemetryClient } from \"@copilotkit/shared/telemetry\";\nimport { createHash } from \"node:crypto\";\nimport { CopilotRuntime, resolveEndpointType } from \"./runtime/copilot-runtime\";\nimport type { RuntimeInstanceCreatedInfo } from \"@copilotkit/shared/src/telemetry/events\";\nimport type { CreateCopilotRuntimeServerOptions } from \"./integrations/shared\";\nimport type { LangGraphPlatformEndpoint } from \"./runtime/types\";\nimport { EndpointType } from \"./runtime/types\";\nconst packageJson = require(\"../../../package.json\");\n\nconst telemetryClient = new TelemetryClient({\n packageName: packageJson.name,\n packageVersion: packageJson.version,\n});\n\n/**\n * The configured agents, counted without touching `runtime.instance`. Every\n * v1 endpoint captures telemetry before it calls `handleServiceAdapter`, and\n * reading the instance there builds the v2 runtime with these agents, so the\n * per-request factory `handleServiceAdapter` installs afterwards was never\n * used and no v1 `actions` or `mcpServers` tool reached an agent.\n */\nfunction countConfiguredAgents(agents: unknown): number {\n if (!agents || typeof agents !== \"object\" || \"then\" in agents) {\n return 0;\n }\n return Object.keys(agents).length;\n}\n\nexport function getRuntimeInstanceTelemetryInfo(\n options: CreateCopilotRuntimeServerOptions,\n): RuntimeInstanceCreatedInfo {\n const runtime = options.runtime;\n const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];\n const endpointsInfo = remoteEndpoints.reduce(\n (acc, endpoint) => {\n let info = { ...acc };\n\n const endpointType = resolveEndpointType(endpoint);\n if (!info.endpointTypes.includes(endpointType)) {\n info = {\n ...info,\n endpointTypes: [...info.endpointTypes, endpointType],\n };\n }\n\n if (endpointType === EndpointType.LangGraphPlatform) {\n // When type is resolved, recreating a const with casting of type\n const ep = endpoint as LangGraphPlatformEndpoint;\n info = {\n ...info,\n agentsAmount: ep.agents.length,\n hashedKey: ep.langsmithApiKey\n ? createHash(\"sha256\").update(ep.langsmithApiKey).digest(\"hex\")\n : null,\n };\n }\n\n return info;\n },\n { endpointTypes: [], agentsAmount: null, hashedKey: null },\n );\n\n // Get public API key from options.cloud.publicApiKey\n const publicApiKey = options.cloud?.publicApiKey;\n const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;\n\n return {\n actionsAmount: runtime.params?.actions?.length ?? 0,\n endpointsAmount: remoteEndpoints.length,\n endpointTypes: endpointsInfo.endpointTypes,\n agentsAmount: countConfiguredAgents(runtime.params?.agents),\n hashedLgcKey: endpointsInfo.hashedKey,\n \"cloud.api_key_provided\": apiKeyProvided,\n ...(apiKeyProvided ? { \"cloud.public_api_key\": publicApiKey } : {}),\n ...(options.cloud?.baseUrl\n ? { \"cloud.base_url\": options.cloud.baseUrl }\n : {}),\n } as RuntimeInstanceCreatedInfo;\n}\n\nexport default telemetryClient;\n"],"mappings":";;;;;;;;AAOA,MAAM;AAEN,MAAM,kBAAkB,IAAI,gBAAgB;CAC1C,aAAa,YAAY;CACzB,gBAAgB,YAAY;CAC7B,CAAC;;;;;;;;AASF,SAAS,sBAAsB,QAAyB;AACtD,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,UAAU,OACrD,QAAO;AAET,QAAO,OAAO,KAAK,OAAO,CAAC;;AAG7B,SAAgB,gCACd,SAC4B;CAC5B,MAAM,UAAU,QAAQ;CACxB,MAAM,kBAAkB,QAAQ,QAAQ,mBAAmB,EAAE;CAC7D,MAAM,gBAAgB,gBAAgB,QACnC,KAAK,aAAa;EACjB,IAAI,OAAO,EAAE,GAAG,KAAK;EAErB,MAAM,eAAe,oBAAoB,SAAS;AAClD,MAAI,CAAC,KAAK,cAAc,SAAS,aAAa,CAC5C,QAAO;GACL,GAAG;GACH,eAAe,CAAC,GAAG,KAAK,eAAe,aAAa;GACrD;AAGH,MAAI,iBAAiB,aAAa,mBAAmB;GAEnD,MAAM,KAAK;AACX,UAAO;IACL,GAAG;IACH,cAAc,GAAG,OAAO;IACxB,WAAW,GAAG,kBACV,WAAW,SAAS,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,MAAM,GAC7D;IACL;;AAGH,SAAO;IAET;EAAE,eAAe,EAAE;EAAE,cAAc;EAAM,WAAW;EAAM,CAC3D;CAGD,MAAM,eAAe,QAAQ,OAAO;CACpC,MAAM,iBAAiB,CAAC,CAAC,gBAAgB,aAAa,MAAM,CAAC,SAAS;AAEtE,QAAO;EACL,eAAe,QAAQ,QAAQ,SAAS,UAAU;EAClD,iBAAiB,gBAAgB;EACjC,eAAe,cAAc;EAC7B,cAAc,sBAAsB,QAAQ,QAAQ,OAAO;EAC3D,cAAc,cAAc;EAC5B,0BAA0B;EAC1B,GAAI,iBAAiB,EAAE,wBAAwB,cAAc,GAAG,EAAE;EAClE,GAAI,QAAQ,OAAO,UACf,EAAE,kBAAkB,QAAQ,MAAM,SAAS,GAC3C,EAAE;EACP"}
|
package/dist/package.cjs
CHANGED
|
@@ -5,7 +5,7 @@ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
|
5
5
|
var require_package = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
6
6
|
module.exports = {
|
|
7
7
|
"name": "@copilotkit/runtime",
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.81.0",
|
|
9
9
|
"private": false,
|
|
10
10
|
"keywords": [
|
|
11
11
|
"ai",
|
|
@@ -77,16 +77,16 @@ var require_package = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, m
|
|
|
77
77
|
"generate-graphql-schema": "node -e \"const fs=require('fs');fs.rmSync('__snapshots__',{recursive:true,force:true})\" && ts-node --transpile-only ./scripts/generate-gql-schema.ts",
|
|
78
78
|
"link:global": "pnpm link --global",
|
|
79
79
|
"unlink:global": "pnpm unlink --global",
|
|
80
|
-
"check-dts": "tsx ../../scripts/validate-dts-ambient.ts dist && tsx ../../scripts/validate-dts-imports.ts dist && tsx ../../scripts/validate-optional-peer-entries.ts . && tsx ../../scripts/validate-module-scope-create-require.ts . && tsc --noEmit -p type-fixtures/express4/tsconfig.json && tsc --noEmit -p type-fixtures/express5/tsconfig.json",
|
|
80
|
+
"check-dts": "tsx ../../scripts/validate-dts-ambient.ts dist && tsx ../../scripts/validate-dts-imports.ts dist && tsx ../../scripts/validate-optional-peer-entries.ts . && tsx ../../scripts/validate-module-scope-create-require.ts . && tsc --noEmit -p type-fixtures/express4/tsconfig.json && tsc --noEmit -p type-fixtures/express5/tsconfig.json && tsc --noEmit -p type-fixtures/learning-management/tsconfig.json",
|
|
81
81
|
"publint": "publint .",
|
|
82
82
|
"attw": "attw --pack . --profile node16"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@ag-ui/a2ui-middleware": "0.0.10",
|
|
86
|
-
"@ag-ui/client": "1.0.
|
|
87
|
-
"@ag-ui/core": "1.0.
|
|
88
|
-
"@ag-ui/encoder": "1.0.
|
|
89
|
-
"@ag-ui/langgraph": "0.0.
|
|
86
|
+
"@ag-ui/client": "1.0.2",
|
|
87
|
+
"@ag-ui/core": "1.0.2",
|
|
88
|
+
"@ag-ui/encoder": "1.0.2",
|
|
89
|
+
"@ag-ui/langgraph": "0.0.44",
|
|
90
90
|
"@ag-ui/mcp-apps-middleware": "^0.1.1",
|
|
91
91
|
"@ag-ui/mcp-middleware": "0.0.2",
|
|
92
92
|
"@ai-sdk/anthropic": "^3.0.49",
|
package/dist/package.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { __commonJSMin } from "./_virtual/_rolldown/runtime.mjs";
|
|
|
5
5
|
var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
6
6
|
module.exports = {
|
|
7
7
|
"name": "@copilotkit/runtime",
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.81.0",
|
|
9
9
|
"private": false,
|
|
10
10
|
"keywords": [
|
|
11
11
|
"ai",
|
|
@@ -77,16 +77,16 @@ var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
77
77
|
"generate-graphql-schema": "node -e \"const fs=require('fs');fs.rmSync('__snapshots__',{recursive:true,force:true})\" && ts-node --transpile-only ./scripts/generate-gql-schema.ts",
|
|
78
78
|
"link:global": "pnpm link --global",
|
|
79
79
|
"unlink:global": "pnpm unlink --global",
|
|
80
|
-
"check-dts": "tsx ../../scripts/validate-dts-ambient.ts dist && tsx ../../scripts/validate-dts-imports.ts dist && tsx ../../scripts/validate-optional-peer-entries.ts . && tsx ../../scripts/validate-module-scope-create-require.ts . && tsc --noEmit -p type-fixtures/express4/tsconfig.json && tsc --noEmit -p type-fixtures/express5/tsconfig.json",
|
|
80
|
+
"check-dts": "tsx ../../scripts/validate-dts-ambient.ts dist && tsx ../../scripts/validate-dts-imports.ts dist && tsx ../../scripts/validate-optional-peer-entries.ts . && tsx ../../scripts/validate-module-scope-create-require.ts . && tsc --noEmit -p type-fixtures/express4/tsconfig.json && tsc --noEmit -p type-fixtures/express5/tsconfig.json && tsc --noEmit -p type-fixtures/learning-management/tsconfig.json",
|
|
81
81
|
"publint": "publint .",
|
|
82
82
|
"attw": "attw --pack . --profile node16"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@ag-ui/a2ui-middleware": "0.0.10",
|
|
86
|
-
"@ag-ui/client": "1.0.
|
|
87
|
-
"@ag-ui/core": "1.0.
|
|
88
|
-
"@ag-ui/encoder": "1.0.
|
|
89
|
-
"@ag-ui/langgraph": "0.0.
|
|
86
|
+
"@ag-ui/client": "1.0.2",
|
|
87
|
+
"@ag-ui/core": "1.0.2",
|
|
88
|
+
"@ag-ui/encoder": "1.0.2",
|
|
89
|
+
"@ag-ui/langgraph": "0.0.44",
|
|
90
90
|
"@ag-ui/mcp-apps-middleware": "^0.1.1",
|
|
91
91
|
"@ag-ui/mcp-middleware": "0.0.2",
|
|
92
92
|
"@ai-sdk/anthropic": "^3.0.49",
|