@copilotkitnext/agent 0.0.13-alpha.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/.turbo/turbo-build.log +23 -0
- package/LICENSE +11 -0
- package/dist/index.d.mts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +554 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +532 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
- package/src/__tests__/basic-agent.test.ts +499 -0
- package/src/__tests__/property-overrides.test.ts +559 -0
- package/src/__tests__/state-tools.test.ts +391 -0
- package/src/__tests__/test-helpers.ts +117 -0
- package/src/__tests__/utils.test.ts +438 -0
- package/src/index.ts +894 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.ts +13 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
AbstractAgent,
|
|
4
|
+
EventType
|
|
5
|
+
} from "@ag-ui/client";
|
|
6
|
+
import {
|
|
7
|
+
streamText,
|
|
8
|
+
tool as createVercelAISDKTool,
|
|
9
|
+
experimental_createMCPClient as createMCPClient
|
|
10
|
+
} from "ai";
|
|
11
|
+
import { Observable } from "rxjs";
|
|
12
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
13
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
14
|
+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
15
|
+
import { randomUUID } from "crypto";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import {
|
|
18
|
+
StreamableHTTPClientTransport
|
|
19
|
+
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
20
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
21
|
+
function resolveModel(spec) {
|
|
22
|
+
if (typeof spec !== "string") {
|
|
23
|
+
return spec;
|
|
24
|
+
}
|
|
25
|
+
const normalized = spec.replace("/", ":").trim();
|
|
26
|
+
const parts = normalized.split(":");
|
|
27
|
+
const rawProvider = parts[0];
|
|
28
|
+
const rest = parts.slice(1);
|
|
29
|
+
if (!rawProvider) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Invalid model string "${spec}". Use "openai/gpt-5", "anthropic/claude-sonnet-4.5", or "google/gemini-2.5-pro".`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const provider = rawProvider.toLowerCase();
|
|
35
|
+
const model = rest.join(":").trim();
|
|
36
|
+
if (!model) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Invalid model string "${spec}". Use "openai/gpt-5", "anthropic/claude-sonnet-4.5", or "google/gemini-2.5-pro".`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
switch (provider) {
|
|
42
|
+
case "openai": {
|
|
43
|
+
const openai = createOpenAI({
|
|
44
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
45
|
+
});
|
|
46
|
+
return openai(model);
|
|
47
|
+
}
|
|
48
|
+
case "anthropic": {
|
|
49
|
+
const anthropic = createAnthropic({
|
|
50
|
+
apiKey: process.env.ANTHROPIC_API_KEY
|
|
51
|
+
});
|
|
52
|
+
return anthropic(model);
|
|
53
|
+
}
|
|
54
|
+
case "google":
|
|
55
|
+
case "gemini":
|
|
56
|
+
case "google-gemini": {
|
|
57
|
+
const google = createGoogleGenerativeAI({
|
|
58
|
+
apiKey: process.env.GOOGLE_API_KEY
|
|
59
|
+
});
|
|
60
|
+
return google(model);
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unknown provider "${provider}" in "${spec}". Supported: openai, anthropic, google (gemini).`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function defineTool(config) {
|
|
67
|
+
return {
|
|
68
|
+
name: config.name,
|
|
69
|
+
description: config.description,
|
|
70
|
+
parameters: config.parameters
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function convertMessagesToVercelAISDKMessages(messages) {
|
|
74
|
+
const result = [];
|
|
75
|
+
for (const message of messages) {
|
|
76
|
+
if (message.role === "assistant") {
|
|
77
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
78
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
79
|
+
const toolCallPart = {
|
|
80
|
+
type: "tool-call",
|
|
81
|
+
toolCallId: toolCall.id,
|
|
82
|
+
toolName: toolCall.function.name,
|
|
83
|
+
input: JSON.parse(toolCall.function.arguments)
|
|
84
|
+
};
|
|
85
|
+
parts.push(toolCallPart);
|
|
86
|
+
}
|
|
87
|
+
const assistantMsg = {
|
|
88
|
+
role: "assistant",
|
|
89
|
+
content: parts
|
|
90
|
+
};
|
|
91
|
+
result.push(assistantMsg);
|
|
92
|
+
} else if (message.role === "user") {
|
|
93
|
+
const userMsg = {
|
|
94
|
+
role: "user",
|
|
95
|
+
content: message.content || ""
|
|
96
|
+
};
|
|
97
|
+
result.push(userMsg);
|
|
98
|
+
} else if (message.role === "tool") {
|
|
99
|
+
let toolName = "unknown";
|
|
100
|
+
for (const msg of messages) {
|
|
101
|
+
if (msg.role === "assistant") {
|
|
102
|
+
for (const toolCall of msg.toolCalls ?? []) {
|
|
103
|
+
if (toolCall.id === message.toolCallId) {
|
|
104
|
+
toolName = toolCall.function.name;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const toolResultPart = {
|
|
111
|
+
type: "tool-result",
|
|
112
|
+
toolCallId: message.toolCallId,
|
|
113
|
+
toolName,
|
|
114
|
+
output: {
|
|
115
|
+
type: "text",
|
|
116
|
+
value: message.content
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const toolMsg = {
|
|
120
|
+
role: "tool",
|
|
121
|
+
content: [toolResultPart]
|
|
122
|
+
};
|
|
123
|
+
result.push(toolMsg);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
function convertJsonSchemaToZodSchema(jsonSchema, required) {
|
|
129
|
+
if (jsonSchema.type === "object") {
|
|
130
|
+
const spec = {};
|
|
131
|
+
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
132
|
+
return !required ? z.object(spec).optional() : z.object(spec);
|
|
133
|
+
}
|
|
134
|
+
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
135
|
+
spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
|
|
136
|
+
}
|
|
137
|
+
let schema = z.object(spec).describe(jsonSchema.description ?? "");
|
|
138
|
+
return required ? schema : schema.optional();
|
|
139
|
+
} else if (jsonSchema.type === "string") {
|
|
140
|
+
let schema = z.string().describe(jsonSchema.description ?? "");
|
|
141
|
+
return required ? schema : schema.optional();
|
|
142
|
+
} else if (jsonSchema.type === "number") {
|
|
143
|
+
let schema = z.number().describe(jsonSchema.description ?? "");
|
|
144
|
+
return required ? schema : schema.optional();
|
|
145
|
+
} else if (jsonSchema.type === "boolean") {
|
|
146
|
+
let schema = z.boolean().describe(jsonSchema.description ?? "");
|
|
147
|
+
return required ? schema : schema.optional();
|
|
148
|
+
} else if (jsonSchema.type === "array") {
|
|
149
|
+
if (!jsonSchema.items) {
|
|
150
|
+
throw new Error("Array type must have items property");
|
|
151
|
+
}
|
|
152
|
+
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
153
|
+
let schema = z.array(itemSchema).describe(jsonSchema.description ?? "");
|
|
154
|
+
return required ? schema : schema.optional();
|
|
155
|
+
}
|
|
156
|
+
throw new Error("Invalid JSON schema");
|
|
157
|
+
}
|
|
158
|
+
function isJsonSchema(obj) {
|
|
159
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
160
|
+
const schema = obj;
|
|
161
|
+
return typeof schema.type === "string" && ["object", "string", "number", "boolean", "array"].includes(schema.type);
|
|
162
|
+
}
|
|
163
|
+
function convertToolsToVercelAITools(tools) {
|
|
164
|
+
const result = {};
|
|
165
|
+
for (const tool of tools) {
|
|
166
|
+
if (!isJsonSchema(tool.parameters)) {
|
|
167
|
+
throw new Error(`Invalid JSON schema for tool ${tool.name}`);
|
|
168
|
+
}
|
|
169
|
+
const zodSchema = convertJsonSchemaToZodSchema(tool.parameters, true);
|
|
170
|
+
result[tool.name] = createVercelAISDKTool({
|
|
171
|
+
description: tool.description,
|
|
172
|
+
inputSchema: zodSchema
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
function convertToolDefinitionsToVercelAITools(tools) {
|
|
178
|
+
const result = {};
|
|
179
|
+
for (const tool of tools) {
|
|
180
|
+
result[tool.name] = createVercelAISDKTool({
|
|
181
|
+
description: tool.description,
|
|
182
|
+
inputSchema: tool.parameters
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
var BasicAgent = class _BasicAgent extends AbstractAgent {
|
|
188
|
+
constructor(config) {
|
|
189
|
+
super();
|
|
190
|
+
this.config = config;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Check if a property can be overridden by forwardedProps
|
|
194
|
+
*/
|
|
195
|
+
canOverride(property) {
|
|
196
|
+
return this.config?.overridableProperties?.includes(property) ?? false;
|
|
197
|
+
}
|
|
198
|
+
run(input) {
|
|
199
|
+
return new Observable((subscriber) => {
|
|
200
|
+
const startEvent = {
|
|
201
|
+
type: EventType.RUN_STARTED,
|
|
202
|
+
threadId: input.threadId,
|
|
203
|
+
runId: input.runId
|
|
204
|
+
};
|
|
205
|
+
subscriber.next(startEvent);
|
|
206
|
+
const model = resolveModel(this.config.model);
|
|
207
|
+
let systemPrompt = void 0;
|
|
208
|
+
const hasPrompt = !!this.config.prompt;
|
|
209
|
+
const hasContext = input.context && input.context.length > 0;
|
|
210
|
+
const hasState = input.state !== void 0 && input.state !== null && !(typeof input.state === "object" && Object.keys(input.state).length === 0);
|
|
211
|
+
if (hasPrompt || hasContext || hasState) {
|
|
212
|
+
const parts = [];
|
|
213
|
+
if (hasPrompt) {
|
|
214
|
+
parts.push(this.config.prompt);
|
|
215
|
+
}
|
|
216
|
+
if (hasContext) {
|
|
217
|
+
parts.push("\n## Context from the application\n");
|
|
218
|
+
for (const ctx of input.context) {
|
|
219
|
+
parts.push(`${ctx.description}:
|
|
220
|
+
${ctx.value}
|
|
221
|
+
`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (hasState) {
|
|
225
|
+
parts.push(
|
|
226
|
+
`
|
|
227
|
+
## Application State
|
|
228
|
+
This is state from the application that you can edit by calling AGUISendStateSnapshot or AGUISendStateDelta.
|
|
229
|
+
\`\`\`json
|
|
230
|
+
${JSON.stringify(input.state, null, 2)}
|
|
231
|
+
\`\`\`
|
|
232
|
+
`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
systemPrompt = parts.join("");
|
|
236
|
+
}
|
|
237
|
+
const messages = convertMessagesToVercelAISDKMessages(input.messages);
|
|
238
|
+
if (systemPrompt) {
|
|
239
|
+
messages.unshift({
|
|
240
|
+
role: "system",
|
|
241
|
+
content: systemPrompt
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
let allTools = convertToolsToVercelAITools(input.tools);
|
|
245
|
+
if (this.config.tools && this.config.tools.length > 0) {
|
|
246
|
+
const configTools = convertToolDefinitionsToVercelAITools(this.config.tools);
|
|
247
|
+
allTools = { ...allTools, ...configTools };
|
|
248
|
+
}
|
|
249
|
+
const streamTextParams = {
|
|
250
|
+
model,
|
|
251
|
+
messages,
|
|
252
|
+
tools: allTools,
|
|
253
|
+
toolChoice: this.config.toolChoice,
|
|
254
|
+
maxOutputTokens: this.config.maxOutputTokens,
|
|
255
|
+
temperature: this.config.temperature,
|
|
256
|
+
topP: this.config.topP,
|
|
257
|
+
topK: this.config.topK,
|
|
258
|
+
presencePenalty: this.config.presencePenalty,
|
|
259
|
+
frequencyPenalty: this.config.frequencyPenalty,
|
|
260
|
+
stopSequences: this.config.stopSequences,
|
|
261
|
+
seed: this.config.seed,
|
|
262
|
+
maxRetries: this.config.maxRetries
|
|
263
|
+
};
|
|
264
|
+
if (input.forwardedProps && typeof input.forwardedProps === "object") {
|
|
265
|
+
const props = input.forwardedProps;
|
|
266
|
+
if (props.model !== void 0 && this.canOverride("model")) {
|
|
267
|
+
if (typeof props.model === "string" || typeof props.model === "object") {
|
|
268
|
+
streamTextParams.model = resolveModel(props.model);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (props.toolChoice !== void 0 && this.canOverride("toolChoice")) {
|
|
272
|
+
const toolChoice = props.toolChoice;
|
|
273
|
+
if (toolChoice === "auto" || toolChoice === "required" || toolChoice === "none" || typeof toolChoice === "object" && toolChoice !== null && "type" in toolChoice && toolChoice.type === "tool") {
|
|
274
|
+
streamTextParams.toolChoice = toolChoice;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (typeof props.maxOutputTokens === "number" && this.canOverride("maxOutputTokens")) {
|
|
278
|
+
streamTextParams.maxOutputTokens = props.maxOutputTokens;
|
|
279
|
+
}
|
|
280
|
+
if (typeof props.temperature === "number" && this.canOverride("temperature")) {
|
|
281
|
+
streamTextParams.temperature = props.temperature;
|
|
282
|
+
}
|
|
283
|
+
if (typeof props.topP === "number" && this.canOverride("topP")) {
|
|
284
|
+
streamTextParams.topP = props.topP;
|
|
285
|
+
}
|
|
286
|
+
if (typeof props.topK === "number" && this.canOverride("topK")) {
|
|
287
|
+
streamTextParams.topK = props.topK;
|
|
288
|
+
}
|
|
289
|
+
if (typeof props.presencePenalty === "number" && this.canOverride("presencePenalty")) {
|
|
290
|
+
streamTextParams.presencePenalty = props.presencePenalty;
|
|
291
|
+
}
|
|
292
|
+
if (typeof props.frequencyPenalty === "number" && this.canOverride("frequencyPenalty")) {
|
|
293
|
+
streamTextParams.frequencyPenalty = props.frequencyPenalty;
|
|
294
|
+
}
|
|
295
|
+
if (Array.isArray(props.stopSequences) && this.canOverride("stopSequences")) {
|
|
296
|
+
if (props.stopSequences.every((item) => typeof item === "string")) {
|
|
297
|
+
streamTextParams.stopSequences = props.stopSequences;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (typeof props.seed === "number" && this.canOverride("seed")) {
|
|
301
|
+
streamTextParams.seed = props.seed;
|
|
302
|
+
}
|
|
303
|
+
if (typeof props.maxRetries === "number" && this.canOverride("maxRetries")) {
|
|
304
|
+
streamTextParams.maxRetries = props.maxRetries;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const mcpClients = [];
|
|
308
|
+
(async () => {
|
|
309
|
+
try {
|
|
310
|
+
streamTextParams.tools = {
|
|
311
|
+
...streamTextParams.tools,
|
|
312
|
+
AGUISendStateSnapshot: createVercelAISDKTool({
|
|
313
|
+
description: "Replace the entire application state with a new snapshot",
|
|
314
|
+
inputSchema: z.object({
|
|
315
|
+
snapshot: z.any().describe("The complete new state object")
|
|
316
|
+
}),
|
|
317
|
+
execute: async ({ snapshot }) => {
|
|
318
|
+
return { success: true, snapshot };
|
|
319
|
+
}
|
|
320
|
+
}),
|
|
321
|
+
AGUISendStateDelta: createVercelAISDKTool({
|
|
322
|
+
description: "Apply incremental updates to application state using JSON Patch operations",
|
|
323
|
+
inputSchema: z.object({
|
|
324
|
+
delta: z.array(
|
|
325
|
+
z.object({
|
|
326
|
+
op: z.enum(["add", "replace", "remove"]).describe("The operation to perform"),
|
|
327
|
+
path: z.string().describe("JSON Pointer path (e.g., '/foo/bar')"),
|
|
328
|
+
value: z.any().optional().describe(
|
|
329
|
+
"The value to set. Required for 'add' and 'replace' operations, ignored for 'remove'."
|
|
330
|
+
)
|
|
331
|
+
})
|
|
332
|
+
).describe("Array of JSON Patch operations")
|
|
333
|
+
}),
|
|
334
|
+
execute: async ({ delta }) => {
|
|
335
|
+
return { success: true, delta };
|
|
336
|
+
}
|
|
337
|
+
})
|
|
338
|
+
};
|
|
339
|
+
if (this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
340
|
+
for (const serverConfig of this.config.mcpServers) {
|
|
341
|
+
let transport;
|
|
342
|
+
if (serverConfig.type === "http") {
|
|
343
|
+
const url = new URL(serverConfig.url);
|
|
344
|
+
transport = new StreamableHTTPClientTransport(url, serverConfig.options);
|
|
345
|
+
} else if (serverConfig.type === "sse") {
|
|
346
|
+
transport = new SSEClientTransport(new URL(serverConfig.url), serverConfig.headers);
|
|
347
|
+
}
|
|
348
|
+
if (transport) {
|
|
349
|
+
const mcpClient = await createMCPClient({ transport });
|
|
350
|
+
mcpClients.push(mcpClient);
|
|
351
|
+
const mcpTools = await mcpClient.tools();
|
|
352
|
+
streamTextParams.tools = { ...streamTextParams.tools, ...mcpTools };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const response = streamText(streamTextParams);
|
|
357
|
+
let messageId = randomUUID();
|
|
358
|
+
const toolCallStates = /* @__PURE__ */ new Map();
|
|
359
|
+
const ensureToolCallState = (toolCallId) => {
|
|
360
|
+
let state = toolCallStates.get(toolCallId);
|
|
361
|
+
if (!state) {
|
|
362
|
+
state = { started: false, hasArgsDelta: false, ended: false };
|
|
363
|
+
toolCallStates.set(toolCallId, state);
|
|
364
|
+
}
|
|
365
|
+
return state;
|
|
366
|
+
};
|
|
367
|
+
for await (const part of response.fullStream) {
|
|
368
|
+
switch (part.type) {
|
|
369
|
+
case "tool-input-start": {
|
|
370
|
+
const toolCallId = part.id;
|
|
371
|
+
const state = ensureToolCallState(toolCallId);
|
|
372
|
+
state.toolName = part.toolName;
|
|
373
|
+
if (!state.started) {
|
|
374
|
+
state.started = true;
|
|
375
|
+
const startEvent2 = {
|
|
376
|
+
type: EventType.TOOL_CALL_START,
|
|
377
|
+
parentMessageId: messageId,
|
|
378
|
+
toolCallId,
|
|
379
|
+
toolCallName: part.toolName
|
|
380
|
+
};
|
|
381
|
+
subscriber.next(startEvent2);
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case "tool-input-delta": {
|
|
386
|
+
const toolCallId = part.id;
|
|
387
|
+
const state = ensureToolCallState(toolCallId);
|
|
388
|
+
state.hasArgsDelta = true;
|
|
389
|
+
const argsEvent = {
|
|
390
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
391
|
+
toolCallId,
|
|
392
|
+
delta: part.delta
|
|
393
|
+
};
|
|
394
|
+
subscriber.next(argsEvent);
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
case "tool-input-end": {
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "text-delta": {
|
|
401
|
+
const textDelta = "text" in part ? part.text : "";
|
|
402
|
+
const textEvent = {
|
|
403
|
+
type: EventType.TEXT_MESSAGE_CHUNK,
|
|
404
|
+
role: "assistant",
|
|
405
|
+
messageId,
|
|
406
|
+
delta: textDelta
|
|
407
|
+
};
|
|
408
|
+
subscriber.next(textEvent);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
case "tool-call": {
|
|
412
|
+
const toolCallId = part.toolCallId;
|
|
413
|
+
const state = ensureToolCallState(toolCallId);
|
|
414
|
+
state.toolName = part.toolName ?? state.toolName;
|
|
415
|
+
if (!state.started) {
|
|
416
|
+
state.started = true;
|
|
417
|
+
const startEvent2 = {
|
|
418
|
+
type: EventType.TOOL_CALL_START,
|
|
419
|
+
parentMessageId: messageId,
|
|
420
|
+
toolCallId,
|
|
421
|
+
toolCallName: part.toolName
|
|
422
|
+
};
|
|
423
|
+
subscriber.next(startEvent2);
|
|
424
|
+
}
|
|
425
|
+
if (!state.hasArgsDelta && "input" in part && part.input !== void 0) {
|
|
426
|
+
let serializedInput = "";
|
|
427
|
+
if (typeof part.input === "string") {
|
|
428
|
+
serializedInput = part.input;
|
|
429
|
+
} else {
|
|
430
|
+
try {
|
|
431
|
+
serializedInput = JSON.stringify(part.input);
|
|
432
|
+
} catch {
|
|
433
|
+
serializedInput = String(part.input);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (serializedInput.length > 0) {
|
|
437
|
+
const argsEvent = {
|
|
438
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
439
|
+
toolCallId,
|
|
440
|
+
delta: serializedInput
|
|
441
|
+
};
|
|
442
|
+
subscriber.next(argsEvent);
|
|
443
|
+
state.hasArgsDelta = true;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!state.ended) {
|
|
447
|
+
state.ended = true;
|
|
448
|
+
const endEvent = {
|
|
449
|
+
type: EventType.TOOL_CALL_END,
|
|
450
|
+
toolCallId
|
|
451
|
+
};
|
|
452
|
+
subscriber.next(endEvent);
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
case "tool-result": {
|
|
457
|
+
const toolResult = "output" in part ? part.output : null;
|
|
458
|
+
const toolName = "toolName" in part ? part.toolName : "";
|
|
459
|
+
toolCallStates.delete(part.toolCallId);
|
|
460
|
+
if (toolName === "AGUISendStateSnapshot" && toolResult && typeof toolResult === "object") {
|
|
461
|
+
const stateSnapshotEvent = {
|
|
462
|
+
type: EventType.STATE_SNAPSHOT,
|
|
463
|
+
snapshot: toolResult.snapshot
|
|
464
|
+
};
|
|
465
|
+
subscriber.next(stateSnapshotEvent);
|
|
466
|
+
} else if (toolName === "AGUISendStateDelta" && toolResult && typeof toolResult === "object") {
|
|
467
|
+
const stateDeltaEvent = {
|
|
468
|
+
type: EventType.STATE_DELTA,
|
|
469
|
+
delta: toolResult.delta
|
|
470
|
+
};
|
|
471
|
+
subscriber.next(stateDeltaEvent);
|
|
472
|
+
}
|
|
473
|
+
const resultEvent = {
|
|
474
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
475
|
+
role: "tool",
|
|
476
|
+
messageId: randomUUID(),
|
|
477
|
+
toolCallId: part.toolCallId,
|
|
478
|
+
content: JSON.stringify(toolResult)
|
|
479
|
+
};
|
|
480
|
+
subscriber.next(resultEvent);
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
case "finish":
|
|
484
|
+
const finishedEvent = {
|
|
485
|
+
type: EventType.RUN_FINISHED,
|
|
486
|
+
threadId: input.threadId,
|
|
487
|
+
runId: input.runId
|
|
488
|
+
};
|
|
489
|
+
subscriber.next(finishedEvent);
|
|
490
|
+
subscriber.complete();
|
|
491
|
+
break;
|
|
492
|
+
case "error":
|
|
493
|
+
const runErrorEvent = {
|
|
494
|
+
type: EventType.RUN_ERROR,
|
|
495
|
+
message: part.error + ""
|
|
496
|
+
};
|
|
497
|
+
subscriber.next(runErrorEvent);
|
|
498
|
+
subscriber.error(part.error);
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
} catch (error) {
|
|
503
|
+
const runErrorEvent = {
|
|
504
|
+
type: EventType.RUN_ERROR,
|
|
505
|
+
message: error + ""
|
|
506
|
+
};
|
|
507
|
+
subscriber.next(runErrorEvent);
|
|
508
|
+
subscriber.error(error);
|
|
509
|
+
} finally {
|
|
510
|
+
await Promise.all(mcpClients.map((client) => client.close()));
|
|
511
|
+
}
|
|
512
|
+
})();
|
|
513
|
+
return () => {
|
|
514
|
+
Promise.all(mcpClients.map((client) => client.close())).catch(() => {
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
clone() {
|
|
520
|
+
return new _BasicAgent(this.config);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
export {
|
|
524
|
+
BasicAgent,
|
|
525
|
+
convertJsonSchemaToZodSchema,
|
|
526
|
+
convertMessagesToVercelAISDKMessages,
|
|
527
|
+
convertToolDefinitionsToVercelAITools,
|
|
528
|
+
convertToolsToVercelAITools,
|
|
529
|
+
defineTool,
|
|
530
|
+
resolveModel
|
|
531
|
+
};
|
|
532
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n AbstractAgent,\n BaseEvent,\n RunAgentInput,\n EventType,\n Message,\n RunFinishedEvent,\n RunStartedEvent,\n TextMessageChunkEvent,\n ToolCallArgsEvent,\n ToolCallEndEvent,\n ToolCallStartEvent,\n ToolCallResultEvent,\n RunErrorEvent,\n StateSnapshotEvent,\n StateDeltaEvent,\n} from \"@ag-ui/client\";\nimport {\n streamText,\n LanguageModel,\n ModelMessage,\n AssistantModelMessage,\n UserModelMessage,\n ToolModelMessage,\n ToolCallPart,\n ToolResultPart,\n TextPart,\n tool as createVercelAISDKTool,\n ToolChoice,\n ToolSet,\n experimental_createMCPClient as createMCPClient,\n} from \"ai\";\nimport { Observable } from \"rxjs\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport { randomUUID } from \"crypto\";\nimport { z } from \"zod\";\nimport {\n StreamableHTTPClientTransport,\n StreamableHTTPClientTransportOptions,\n} from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { u } from \"vitest/dist/chunks/reporters.d.BFLkQcL6.js\";\n\n/**\n * Properties that can be overridden by forwardedProps\n * These match the exact parameter names in streamText\n */\nexport type OverridableProperty =\n | \"model\"\n | \"toolChoice\"\n | \"maxOutputTokens\"\n | \"temperature\"\n | \"topP\"\n | \"topK\"\n | \"presencePenalty\"\n | \"frequencyPenalty\"\n | \"stopSequences\"\n | \"seed\"\n | \"maxRetries\"\n | \"prompt\";\n\n/**\n * Supported model identifiers for BasicAgent\n */\nexport type BasicAgentModel =\n // OpenAI models\n | \"openai/gpt-5\"\n | \"openai/gpt-5-mini\"\n | \"openai/gpt-4.1\"\n | \"openai/gpt-4.1-mini\"\n | \"openai/gpt-4.1-nano\"\n | \"openai/gpt-4o\"\n | \"openai/gpt-4o-mini\"\n // OpenAI reasoning series\n | \"openai/o3\"\n | \"openai/o3-mini\"\n | \"openai/o4-mini\"\n // Anthropic (Claude) models\n | \"anthropic/claude-sonnet-4.5\"\n | \"anthropic/claude-sonnet-4\"\n | \"anthropic/claude-3.7-sonnet\"\n | \"anthropic/claude-opus-4.1\"\n | \"anthropic/claude-opus-4\"\n | \"anthropic/claude-3.5-haiku\"\n // Google (Gemini) models\n | \"google/gemini-2.5-pro\"\n | \"google/gemini-2.5-flash\"\n | \"google/gemini-2.5-flash-lite\"\n // Allow any LanguageModel instance\n | (string & {});\n\n/**\n * Model specifier - can be a string like \"openai/gpt-4o\" or a LanguageModel instance\n */\nexport type ModelSpecifier = string | LanguageModel;\n\n/**\n * MCP Client configuration for HTTP transport\n */\nexport interface MCPClientConfigHTTP {\n /**\n * Type of MCP client\n */\n type: \"http\";\n /**\n * URL of the MCP server\n */\n url: string;\n /**\n * Optional transport options for HTTP client\n */\n options?: StreamableHTTPClientTransportOptions;\n}\n\n/**\n * MCP Client configuration for SSE transport\n */\nexport interface MCPClientConfigSSE {\n /**\n * Type of MCP client\n */\n type: \"sse\";\n /**\n * URL of the MCP server\n */\n url: string;\n /**\n * Optional HTTP headers (e.g., for authentication)\n */\n headers?: Record<string, string>;\n}\n\n/**\n * MCP Client configuration\n */\nexport type MCPClientConfig = MCPClientConfigHTTP | MCPClientConfigSSE;\n\n/**\n * Resolves a model specifier to a LanguageModel instance\n * @param spec - Model string (e.g., \"openai/gpt-4o\") or LanguageModel instance\n * @returns LanguageModel instance\n */\nexport function resolveModel(spec: ModelSpecifier): LanguageModel {\n // If already a LanguageModel instance, pass through\n if (typeof spec !== \"string\") {\n return spec;\n }\n\n // Normalize \"provider/model\" or \"provider:model\" format\n const normalized = spec.replace(\"/\", \":\").trim();\n const parts = normalized.split(\":\");\n const rawProvider = parts[0];\n const rest = parts.slice(1);\n\n if (!rawProvider) {\n throw new Error(\n `Invalid model string \"${spec}\". Use \"openai/gpt-5\", \"anthropic/claude-sonnet-4.5\", or \"google/gemini-2.5-pro\".`,\n );\n }\n\n const provider = rawProvider.toLowerCase();\n const model = rest.join(\":\").trim();\n\n if (!model) {\n throw new Error(\n `Invalid model string \"${spec}\". Use \"openai/gpt-5\", \"anthropic/claude-sonnet-4.5\", or \"google/gemini-2.5-pro\".`,\n );\n }\n\n switch (provider) {\n case \"openai\": {\n // Lazily create OpenAI provider\n const openai = createOpenAI({\n apiKey: process.env.OPENAI_API_KEY!,\n });\n // Accepts any OpenAI model id, e.g. \"gpt-4o\", \"gpt-4.1-mini\", \"o3-mini\"\n return openai(model);\n }\n\n case \"anthropic\": {\n // Lazily create Anthropic provider\n const anthropic = createAnthropic({\n apiKey: process.env.ANTHROPIC_API_KEY!,\n });\n // Accepts any Claude id, e.g. \"claude-3.7-sonnet\", \"claude-3.5-haiku\"\n return anthropic(model);\n }\n\n case \"google\":\n case \"gemini\":\n case \"google-gemini\": {\n // Lazily create Google provider\n const google = createGoogleGenerativeAI({\n apiKey: process.env.GOOGLE_API_KEY!,\n });\n // Accepts any Gemini id, e.g. \"gemini-2.5-pro\", \"gemini-2.5-flash\"\n return google(model);\n }\n\n default:\n throw new Error(`Unknown provider \"${provider}\" in \"${spec}\". Supported: openai, anthropic, google (gemini).`);\n }\n}\n\n/**\n * Tool definition for BasicAgent\n */\nexport interface ToolDefinition<TParameters extends z.ZodTypeAny = z.ZodTypeAny> {\n name: string;\n description: string;\n parameters: TParameters;\n}\n\n/**\n * Define a tool for use with BasicAgent\n * @param name - The name of the tool\n * @param description - Description of what the tool does\n * @param parameters - Zod schema for the tool's input parameters\n * @returns Tool definition\n */\nexport function defineTool<TParameters extends z.ZodTypeAny>(config: {\n name: string;\n description: string;\n parameters: TParameters;\n}): ToolDefinition<TParameters> {\n return {\n name: config.name,\n description: config.description,\n parameters: config.parameters,\n };\n}\n\n/**\n * Converts AG-UI messages to Vercel AI SDK ModelMessage format\n */\nexport function convertMessagesToVercelAISDKMessages(messages: Message[]): ModelMessage[] {\n const result: ModelMessage[] = [];\n\n for (const message of messages) {\n if (message.role === \"assistant\") {\n const parts: Array<TextPart | ToolCallPart> = message.content ? [{ type: \"text\", text: message.content }] : [];\n\n for (const toolCall of message.toolCalls ?? []) {\n const toolCallPart: ToolCallPart = {\n type: \"tool-call\",\n toolCallId: toolCall.id,\n toolName: toolCall.function.name,\n input: JSON.parse(toolCall.function.arguments),\n };\n parts.push(toolCallPart);\n }\n\n const assistantMsg: AssistantModelMessage = {\n role: \"assistant\",\n content: parts,\n };\n result.push(assistantMsg);\n } else if (message.role === \"user\") {\n const userMsg: UserModelMessage = {\n role: \"user\",\n content: message.content || \"\",\n };\n result.push(userMsg);\n } else if (message.role === \"tool\") {\n let toolName = \"unknown\";\n // Find the tool name from the corresponding tool call\n for (const msg of messages) {\n if (msg.role === \"assistant\") {\n for (const toolCall of msg.toolCalls ?? []) {\n if (toolCall.id === message.toolCallId) {\n toolName = toolCall.function.name;\n break;\n }\n }\n }\n }\n\n const toolResultPart: ToolResultPart = {\n type: \"tool-result\",\n toolCallId: message.toolCallId,\n toolName: toolName,\n output: {\n type: \"text\",\n value: message.content,\n },\n };\n\n const toolMsg: ToolModelMessage = {\n role: \"tool\",\n content: [toolResultPart],\n };\n result.push(toolMsg);\n }\n }\n\n return result;\n}\n\n/**\n * JSON Schema type definition\n */\ninterface JsonSchema {\n type: \"object\" | \"string\" | \"number\" | \"boolean\" | \"array\";\n description?: string;\n properties?: Record<string, JsonSchema>;\n required?: string[];\n items?: JsonSchema;\n}\n\n/**\n * Converts JSON Schema to Zod schema\n */\nexport function convertJsonSchemaToZodSchema(jsonSchema: JsonSchema, required: boolean): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);\n }\n let schema = z.object(spec).describe(jsonSchema.description ?? \"\");\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description ?? \"\");\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description ?? \"\");\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description ?? \"\");\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n if (!jsonSchema.items) {\n throw new Error(\"Array type must have items property\");\n }\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description ?? \"\");\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\n}\n\n/**\n * Converts AG-UI tools to Vercel AI SDK ToolSet\n */\nfunction isJsonSchema(obj: unknown): obj is JsonSchema {\n if (typeof obj !== \"object\" || obj === null) return false;\n const schema = obj as Record<string, unknown>;\n return typeof schema.type === \"string\" && [\"object\", \"string\", \"number\", \"boolean\", \"array\"].includes(schema.type);\n}\n\nexport function convertToolsToVercelAITools(tools: RunAgentInput[\"tools\"]): ToolSet {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n\n for (const tool of tools) {\n if (!isJsonSchema(tool.parameters)) {\n throw new Error(`Invalid JSON schema for tool ${tool.name}`);\n }\n const zodSchema = convertJsonSchemaToZodSchema(tool.parameters, true);\n result[tool.name] = createVercelAISDKTool({\n description: tool.description,\n inputSchema: zodSchema,\n });\n }\n\n return result;\n}\n\n/**\n * Converts ToolDefinition array to Vercel AI SDK ToolSet\n */\nexport function convertToolDefinitionsToVercelAITools(tools: ToolDefinition[]): ToolSet {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n\n for (const tool of tools) {\n result[tool.name] = createVercelAISDKTool({\n description: tool.description,\n inputSchema: tool.parameters,\n });\n }\n\n return result;\n}\n\n/**\n * Configuration for BasicAgent\n */\nexport interface BasicAgentConfiguration {\n /**\n * The model to use\n */\n model: BasicAgentModel | LanguageModel;\n /**\n * Maximum number of steps/iterations for tool calling (default: 1)\n */\n maxSteps?: number;\n /**\n * Tool choice setting - how tools are selected for execution (default: \"auto\")\n */\n toolChoice?: ToolChoice<Record<string, unknown>>;\n /**\n * Maximum number of tokens to generate\n */\n maxOutputTokens?: number;\n /**\n * Temperature setting (range depends on provider)\n */\n temperature?: number;\n /**\n * Nucleus sampling (topP)\n */\n topP?: number;\n /**\n * Top K sampling\n */\n topK?: number;\n /**\n * Presence penalty\n */\n presencePenalty?: number;\n /**\n * Frequency penalty\n */\n frequencyPenalty?: number;\n /**\n * Sequences that will stop the generation\n */\n stopSequences?: string[];\n /**\n * Seed for deterministic results\n */\n seed?: number;\n /**\n * Maximum number of retries\n */\n maxRetries?: number;\n /**\n * Prompt for the agent\n */\n prompt?: string;\n /**\n * List of properties that can be overridden by forwardedProps.\n */\n overridableProperties?: OverridableProperty[];\n /**\n * Optional list of MCP server configurations\n */\n mcpServers?: MCPClientConfig[];\n /**\n * Optional tools available to the agent\n */\n tools?: ToolDefinition[];\n}\n\nexport class BasicAgent extends AbstractAgent {\n constructor(private config: BasicAgentConfiguration) {\n super();\n }\n\n /**\n * Check if a property can be overridden by forwardedProps\n */\n canOverride(property: OverridableProperty): boolean {\n return this.config?.overridableProperties?.includes(property) ?? false;\n }\n\n protected run(input: RunAgentInput): Observable<BaseEvent> {\n return new Observable<BaseEvent>((subscriber) => {\n // Emit RUN_STARTED event\n const startEvent: RunStartedEvent = {\n type: EventType.RUN_STARTED,\n threadId: input.threadId,\n runId: input.runId,\n };\n subscriber.next(startEvent);\n\n // Resolve the model\n const model = resolveModel(this.config.model);\n\n // Build prompt based on conditions\n let systemPrompt: string | undefined = undefined;\n\n // Check if we should build a prompt:\n // - config.prompt is set, OR\n // - input.context is non-empty, OR\n // - input.state is non-empty and not an empty object\n const hasPrompt = !!this.config.prompt;\n const hasContext = input.context && input.context.length > 0;\n const hasState =\n input.state !== undefined &&\n input.state !== null &&\n !(typeof input.state === \"object\" && Object.keys(input.state).length === 0);\n\n if (hasPrompt || hasContext || hasState) {\n const parts: string[] = [];\n\n // First: the prompt if any\n if (hasPrompt) {\n parts.push(this.config.prompt!);\n }\n\n // Second: context from the application\n if (hasContext) {\n parts.push(\"\\n## Context from the application\\n\");\n for (const ctx of input.context) {\n parts.push(`${ctx.description}:\\n${ctx.value}\\n`);\n }\n }\n\n // Third: state from the application that can be edited\n if (hasState) {\n parts.push(\n \"\\n## Application State\\n\" +\n \"This is state from the application that you can edit by calling AGUISendStateSnapshot or AGUISendStateDelta.\\n\" +\n `\\`\\`\\`json\\n${JSON.stringify(input.state, null, 2)}\\n\\`\\`\\`\\n`,\n );\n }\n\n systemPrompt = parts.join(\"\");\n }\n\n // Convert messages and prepend system message if we have a prompt\n const messages = convertMessagesToVercelAISDKMessages(input.messages);\n if (systemPrompt) {\n messages.unshift({\n role: \"system\",\n content: systemPrompt,\n });\n }\n\n // Merge tools from input and config\n let allTools: ToolSet = convertToolsToVercelAITools(input.tools);\n if (this.config.tools && this.config.tools.length > 0) {\n const configTools = convertToolDefinitionsToVercelAITools(this.config.tools);\n allTools = { ...allTools, ...configTools };\n }\n\n const streamTextParams: Parameters<typeof streamText>[0] = {\n model,\n messages,\n tools: allTools,\n toolChoice: this.config.toolChoice,\n maxOutputTokens: this.config.maxOutputTokens,\n temperature: this.config.temperature,\n topP: this.config.topP,\n topK: this.config.topK,\n presencePenalty: this.config.presencePenalty,\n frequencyPenalty: this.config.frequencyPenalty,\n stopSequences: this.config.stopSequences,\n seed: this.config.seed,\n maxRetries: this.config.maxRetries,\n };\n\n // Apply forwardedProps overrides (if allowed)\n if (input.forwardedProps && typeof input.forwardedProps === \"object\") {\n const props = input.forwardedProps as Record<string, unknown>;\n\n // Check and apply each overridable property\n if (props.model !== undefined && this.canOverride(\"model\")) {\n if (typeof props.model === \"string\" || typeof props.model === \"object\") {\n // Accept any string or LanguageModel instance for model override\n streamTextParams.model = resolveModel(props.model as string | LanguageModel);\n }\n }\n if (props.toolChoice !== undefined && this.canOverride(\"toolChoice\")) {\n // ToolChoice can be 'auto', 'required', 'none', or { type: 'tool', toolName: string }\n const toolChoice = props.toolChoice;\n if (\n toolChoice === \"auto\" ||\n toolChoice === \"required\" ||\n toolChoice === \"none\" ||\n (typeof toolChoice === \"object\" &&\n toolChoice !== null &&\n \"type\" in toolChoice &&\n toolChoice.type === \"tool\")\n ) {\n streamTextParams.toolChoice = toolChoice as ToolChoice<Record<string, unknown>>;\n }\n }\n if (typeof props.maxOutputTokens === \"number\" && this.canOverride(\"maxOutputTokens\")) {\n streamTextParams.maxOutputTokens = props.maxOutputTokens;\n }\n if (typeof props.temperature === \"number\" && this.canOverride(\"temperature\")) {\n streamTextParams.temperature = props.temperature;\n }\n if (typeof props.topP === \"number\" && this.canOverride(\"topP\")) {\n streamTextParams.topP = props.topP;\n }\n if (typeof props.topK === \"number\" && this.canOverride(\"topK\")) {\n streamTextParams.topK = props.topK;\n }\n if (typeof props.presencePenalty === \"number\" && this.canOverride(\"presencePenalty\")) {\n streamTextParams.presencePenalty = props.presencePenalty;\n }\n if (typeof props.frequencyPenalty === \"number\" && this.canOverride(\"frequencyPenalty\")) {\n streamTextParams.frequencyPenalty = props.frequencyPenalty;\n }\n if (Array.isArray(props.stopSequences) && this.canOverride(\"stopSequences\")) {\n // Validate all elements are strings\n if (props.stopSequences.every((item): item is string => typeof item === \"string\")) {\n streamTextParams.stopSequences = props.stopSequences;\n }\n }\n if (typeof props.seed === \"number\" && this.canOverride(\"seed\")) {\n streamTextParams.seed = props.seed;\n }\n if (typeof props.maxRetries === \"number\" && this.canOverride(\"maxRetries\")) {\n streamTextParams.maxRetries = props.maxRetries;\n }\n }\n\n // Set up MCP clients if configured and process the stream\n const mcpClients: Array<{ close: () => Promise<void> }> = [];\n\n (async () => {\n try {\n // Add AG-UI state update tools\n streamTextParams.tools = {\n ...streamTextParams.tools,\n AGUISendStateSnapshot: createVercelAISDKTool({\n description: \"Replace the entire application state with a new snapshot\",\n inputSchema: z.object({\n snapshot: z.any().describe(\"The complete new state object\"),\n }),\n execute: async ({ snapshot }) => {\n return { success: true, snapshot };\n },\n }),\n AGUISendStateDelta: createVercelAISDKTool({\n description: \"Apply incremental updates to application state using JSON Patch operations\",\n inputSchema: z.object({\n delta: z\n .array(\n z.object({\n op: z.enum([\"add\", \"replace\", \"remove\"]).describe(\"The operation to perform\"),\n path: z.string().describe(\"JSON Pointer path (e.g., '/foo/bar')\"),\n value: z\n .any()\n .optional()\n .describe(\n \"The value to set. Required for 'add' and 'replace' operations, ignored for 'remove'.\",\n ),\n }),\n )\n .describe(\"Array of JSON Patch operations\"),\n }),\n execute: async ({ delta }) => {\n return { success: true, delta };\n },\n }),\n };\n\n // Initialize MCP clients and get their tools\n if (this.config.mcpServers && this.config.mcpServers.length > 0) {\n for (const serverConfig of this.config.mcpServers) {\n let transport;\n\n if (serverConfig.type === \"http\") {\n const url = new URL(serverConfig.url);\n transport = new StreamableHTTPClientTransport(url, serverConfig.options);\n } else if (serverConfig.type === \"sse\") {\n transport = new SSEClientTransport(new URL(serverConfig.url), serverConfig.headers);\n }\n\n if (transport) {\n const mcpClient = await createMCPClient({ transport });\n mcpClients.push(mcpClient);\n\n // Get tools from this MCP server and merge with existing tools\n const mcpTools = await mcpClient.tools();\n streamTextParams.tools = { ...streamTextParams.tools, ...mcpTools };\n }\n }\n }\n\n // Call streamText and process the stream\n const response = streamText(streamTextParams);\n\n let messageId = randomUUID();\n\n const toolCallStates = new Map<\n string,\n {\n started: boolean;\n hasArgsDelta: boolean;\n ended: boolean;\n toolName?: string;\n }\n >();\n\n const ensureToolCallState = (toolCallId: string) => {\n let state = toolCallStates.get(toolCallId);\n if (!state) {\n state = { started: false, hasArgsDelta: false, ended: false };\n toolCallStates.set(toolCallId, state);\n }\n return state;\n };\n\n // Process fullStream events\n for await (const part of response.fullStream) {\n switch (part.type) {\n case \"tool-input-start\": {\n const toolCallId = part.id;\n const state = ensureToolCallState(toolCallId);\n state.toolName = part.toolName;\n if (!state.started) {\n state.started = true;\n const startEvent: ToolCallStartEvent = {\n type: EventType.TOOL_CALL_START,\n parentMessageId: messageId,\n toolCallId,\n toolCallName: part.toolName,\n };\n subscriber.next(startEvent);\n }\n break;\n }\n\n case \"tool-input-delta\": {\n const toolCallId = part.id;\n const state = ensureToolCallState(toolCallId);\n state.hasArgsDelta = true;\n const argsEvent: ToolCallArgsEvent = {\n type: EventType.TOOL_CALL_ARGS,\n toolCallId,\n delta: part.delta,\n };\n subscriber.next(argsEvent);\n break;\n }\n\n case \"tool-input-end\": {\n // No direct event – the subsequent \"tool-call\" part marks completion.\n break;\n }\n\n case \"text-delta\": {\n // Accumulate text content - in AI SDK 5.0, the property is 'text'\n const textDelta = \"text\" in part ? part.text : \"\";\n // Emit text chunk event\n const textEvent: TextMessageChunkEvent = {\n type: EventType.TEXT_MESSAGE_CHUNK,\n role: \"assistant\",\n messageId,\n delta: textDelta,\n };\n subscriber.next(textEvent);\n break;\n }\n\n case \"tool-call\": {\n const toolCallId = part.toolCallId;\n const state = ensureToolCallState(toolCallId);\n state.toolName = part.toolName ?? state.toolName;\n\n if (!state.started) {\n state.started = true;\n const startEvent: ToolCallStartEvent = {\n type: EventType.TOOL_CALL_START,\n parentMessageId: messageId,\n toolCallId,\n toolCallName: part.toolName,\n };\n subscriber.next(startEvent);\n }\n\n if (!state.hasArgsDelta && \"input\" in part && part.input !== undefined) {\n let serializedInput = \"\";\n if (typeof part.input === \"string\") {\n serializedInput = part.input;\n } else {\n try {\n serializedInput = JSON.stringify(part.input);\n } catch {\n serializedInput = String(part.input);\n }\n }\n\n if (serializedInput.length > 0) {\n const argsEvent: ToolCallArgsEvent = {\n type: EventType.TOOL_CALL_ARGS,\n toolCallId,\n delta: serializedInput,\n };\n subscriber.next(argsEvent);\n state.hasArgsDelta = true;\n }\n }\n\n if (!state.ended) {\n state.ended = true;\n const endEvent: ToolCallEndEvent = {\n type: EventType.TOOL_CALL_END,\n toolCallId,\n };\n subscriber.next(endEvent);\n }\n break;\n }\n\n case \"tool-result\": {\n const toolResult = \"output\" in part ? part.output : null;\n const toolName = \"toolName\" in part ? part.toolName : \"\";\n toolCallStates.delete(part.toolCallId);\n\n // Check if this is a state update tool\n if (toolName === \"AGUISendStateSnapshot\" && toolResult && typeof toolResult === \"object\") {\n // Emit StateSnapshotEvent\n const stateSnapshotEvent: StateSnapshotEvent = {\n type: EventType.STATE_SNAPSHOT,\n snapshot: toolResult.snapshot,\n };\n subscriber.next(stateSnapshotEvent);\n } else if (toolName === \"AGUISendStateDelta\" && toolResult && typeof toolResult === \"object\") {\n // Emit StateDeltaEvent\n const stateDeltaEvent: StateDeltaEvent = {\n type: EventType.STATE_DELTA,\n delta: toolResult.delta,\n };\n subscriber.next(stateDeltaEvent);\n }\n\n // Always emit the tool result event for the LLM\n const resultEvent: ToolCallResultEvent = {\n type: EventType.TOOL_CALL_RESULT,\n role: \"tool\",\n messageId: randomUUID(),\n toolCallId: part.toolCallId,\n content: JSON.stringify(toolResult),\n };\n subscriber.next(resultEvent);\n break;\n }\n\n case \"finish\":\n // Emit run finished event\n const finishedEvent: RunFinishedEvent = {\n type: EventType.RUN_FINISHED,\n threadId: input.threadId,\n runId: input.runId,\n };\n subscriber.next(finishedEvent);\n\n // Complete the observable\n subscriber.complete();\n break;\n\n case \"error\":\n const runErrorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: part.error + \"\",\n };\n subscriber.next(runErrorEvent);\n\n // Handle error\n subscriber.error(part.error);\n break;\n }\n }\n } catch (error) {\n const runErrorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: error + \"\",\n };\n subscriber.next(runErrorEvent);\n\n subscriber.error(error);\n } finally {\n await Promise.all(mcpClients.map((client) => client.close()));\n }\n })();\n\n // Cleanup function\n return () => {\n // Cleanup MCP clients if stream is unsubscribed\n Promise.all(mcpClients.map((client) => client.close())).catch(() => {\n // Ignore cleanup errors\n });\n };\n });\n }\n\n clone() {\n return new BasicAgent(this.config);\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAGA;AAAA,OAYK;AACP;AAAA,EACE;AAAA,EASA,QAAQ;AAAA,EAGR,gCAAgC;AAAA,OAC3B;AACP,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AACzC,SAAS,kBAAkB;AAC3B,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,OAEK;AACP,SAAS,0BAA0B;AAsG5B,SAAS,aAAa,MAAqC;AAEhE,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO;AAAA,EACT;AAGA,QAAM,aAAa,KAAK,QAAQ,KAAK,GAAG,EAAE,KAAK;AAC/C,QAAM,QAAQ,WAAW,MAAM,GAAG;AAClC,QAAM,cAAc,MAAM,CAAC;AAC3B,QAAM,OAAO,MAAM,MAAM,CAAC;AAE1B,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR,yBAAyB,IAAI;AAAA,IAC/B;AAAA,EACF;AAEA,QAAM,WAAW,YAAY,YAAY;AACzC,QAAM,QAAQ,KAAK,KAAK,GAAG,EAAE,KAAK;AAElC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR,yBAAyB,IAAI;AAAA,IAC/B;AAAA,EACF;AAEA,UAAQ,UAAU;AAAA,IAChB,KAAK,UAAU;AAEb,YAAM,SAAS,aAAa;AAAA,QAC1B,QAAQ,QAAQ,IAAI;AAAA,MACtB,CAAC;AAED,aAAO,OAAO,KAAK;AAAA,IACrB;AAAA,IAEA,KAAK,aAAa;AAEhB,YAAM,YAAY,gBAAgB;AAAA,QAChC,QAAQ,QAAQ,IAAI;AAAA,MACtB,CAAC;AAED,aAAO,UAAU,KAAK;AAAA,IACxB;AAAA,IAEA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,iBAAiB;A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