@copilotkitnext/agent 1.51.5-next.0 → 1.51.5-next.2

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/index.js DELETED
@@ -1,724 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- BasicAgent: () => BasicAgent,
24
- BuiltInAgent: () => BuiltInAgent,
25
- convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
26
- convertMessagesToVercelAISDKMessages: () => convertMessagesToVercelAISDKMessages,
27
- convertToolDefinitionsToVercelAITools: () => convertToolDefinitionsToVercelAITools,
28
- convertToolsToVercelAITools: () => convertToolsToVercelAITools,
29
- defineTool: () => defineTool,
30
- resolveModel: () => resolveModel
31
- });
32
- module.exports = __toCommonJS(index_exports);
33
- var import_client = require("@ag-ui/client");
34
- var import_ai = require("ai");
35
- var import_mcp = require("@ai-sdk/mcp");
36
- var import_rxjs = require("rxjs");
37
- var import_openai = require("@ai-sdk/openai");
38
- var import_anthropic = require("@ai-sdk/anthropic");
39
- var import_google = require("@ai-sdk/google");
40
- var import_crypto = require("crypto");
41
- var import_zod = require("zod");
42
- var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
43
- var import_sse = require("@modelcontextprotocol/sdk/client/sse.js");
44
- function resolveModel(spec, apiKey) {
45
- if (typeof spec !== "string") {
46
- return spec;
47
- }
48
- const normalized = spec.replace("/", ":").trim();
49
- const parts = normalized.split(":");
50
- const rawProvider = parts[0];
51
- const rest = parts.slice(1);
52
- if (!rawProvider) {
53
- throw new Error(
54
- `Invalid model string "${spec}". Use "openai/gpt-5", "anthropic/claude-sonnet-4.5", or "google/gemini-2.5-pro".`
55
- );
56
- }
57
- const provider = rawProvider.toLowerCase();
58
- const model = rest.join(":").trim();
59
- if (!model) {
60
- throw new Error(
61
- `Invalid model string "${spec}". Use "openai/gpt-5", "anthropic/claude-sonnet-4.5", or "google/gemini-2.5-pro".`
62
- );
63
- }
64
- switch (provider) {
65
- case "openai": {
66
- const openai = (0, import_openai.createOpenAI)({
67
- apiKey: apiKey || process.env.OPENAI_API_KEY
68
- });
69
- return openai(model);
70
- }
71
- case "anthropic": {
72
- const anthropic = (0, import_anthropic.createAnthropic)({
73
- apiKey: apiKey || process.env.ANTHROPIC_API_KEY
74
- });
75
- return anthropic(model);
76
- }
77
- case "google":
78
- case "gemini":
79
- case "google-gemini": {
80
- const google = (0, import_google.createGoogleGenerativeAI)({
81
- apiKey: apiKey || process.env.GOOGLE_API_KEY
82
- });
83
- return google(model);
84
- }
85
- default:
86
- throw new Error(
87
- `Unknown provider "${provider}" in "${spec}". Supported: openai, anthropic, google (gemini).`
88
- );
89
- }
90
- }
91
- function defineTool(config) {
92
- return {
93
- name: config.name,
94
- description: config.description,
95
- parameters: config.parameters,
96
- execute: config.execute
97
- };
98
- }
99
- function flattenUserMessageContent(content) {
100
- if (!content) {
101
- return "";
102
- }
103
- if (typeof content === "string") {
104
- return content;
105
- }
106
- return content.map((part) => {
107
- if (part && typeof part === "object" && "type" in part && part.type === "text" && typeof part.text === "string") {
108
- return part.text;
109
- }
110
- return "";
111
- }).filter((text) => text.length > 0).join("\n");
112
- }
113
- function convertMessagesToVercelAISDKMessages(messages, options = {}) {
114
- const result = [];
115
- for (const message of messages) {
116
- if (message.role === "system" && options.forwardSystemMessages) {
117
- const systemMsg = {
118
- role: "system",
119
- content: message.content ?? ""
120
- };
121
- result.push(systemMsg);
122
- } else if (message.role === "developer" && options.forwardDeveloperMessages) {
123
- const systemMsg = {
124
- role: "system",
125
- content: message.content ?? ""
126
- };
127
- result.push(systemMsg);
128
- } else if (message.role === "assistant") {
129
- const parts = message.content ? [{ type: "text", text: message.content }] : [];
130
- for (const toolCall of message.toolCalls ?? []) {
131
- const toolCallPart = {
132
- type: "tool-call",
133
- toolCallId: toolCall.id,
134
- toolName: toolCall.function.name,
135
- input: JSON.parse(toolCall.function.arguments)
136
- };
137
- parts.push(toolCallPart);
138
- }
139
- const assistantMsg = {
140
- role: "assistant",
141
- content: parts
142
- };
143
- result.push(assistantMsg);
144
- } else if (message.role === "user") {
145
- const userMsg = {
146
- role: "user",
147
- content: flattenUserMessageContent(message.content)
148
- };
149
- result.push(userMsg);
150
- } else if (message.role === "tool") {
151
- let toolName = "unknown";
152
- for (const msg of messages) {
153
- if (msg.role === "assistant") {
154
- for (const toolCall of msg.toolCalls ?? []) {
155
- if (toolCall.id === message.toolCallId) {
156
- toolName = toolCall.function.name;
157
- break;
158
- }
159
- }
160
- }
161
- }
162
- const toolResultPart = {
163
- type: "tool-result",
164
- toolCallId: message.toolCallId,
165
- toolName,
166
- output: {
167
- type: "text",
168
- value: message.content
169
- }
170
- };
171
- const toolMsg = {
172
- role: "tool",
173
- content: [toolResultPart]
174
- };
175
- result.push(toolMsg);
176
- }
177
- }
178
- return result;
179
- }
180
- function convertJsonSchemaToZodSchema(jsonSchema, required) {
181
- if (!jsonSchema.type) {
182
- return required ? import_zod.z.object({}) : import_zod.z.object({}).optional();
183
- }
184
- if (jsonSchema.type === "object") {
185
- const spec = {};
186
- if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
187
- return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
188
- }
189
- for (const [key, value] of Object.entries(jsonSchema.properties)) {
190
- spec[key] = convertJsonSchemaToZodSchema(
191
- value,
192
- jsonSchema.required ? jsonSchema.required.includes(key) : false
193
- );
194
- }
195
- let schema = import_zod.z.object(spec).describe(jsonSchema.description ?? "");
196
- return required ? schema : schema.optional();
197
- } else if (jsonSchema.type === "string") {
198
- let schema = import_zod.z.string().describe(jsonSchema.description ?? "");
199
- return required ? schema : schema.optional();
200
- } else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
201
- let schema = import_zod.z.number().describe(jsonSchema.description ?? "");
202
- return required ? schema : schema.optional();
203
- } else if (jsonSchema.type === "boolean") {
204
- let schema = import_zod.z.boolean().describe(jsonSchema.description ?? "");
205
- return required ? schema : schema.optional();
206
- } else if (jsonSchema.type === "array") {
207
- if (!jsonSchema.items) {
208
- throw new Error("Array type must have items property");
209
- }
210
- let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
211
- let schema = import_zod.z.array(itemSchema).describe(jsonSchema.description ?? "");
212
- return required ? schema : schema.optional();
213
- }
214
- console.error("Invalid JSON schema:", JSON.stringify(jsonSchema, null, 2));
215
- throw new Error("Invalid JSON schema");
216
- }
217
- function isJsonSchema(obj) {
218
- if (typeof obj !== "object" || obj === null) return false;
219
- const schema = obj;
220
- if (Object.keys(schema).length === 0) return true;
221
- return typeof schema.type === "string" && ["object", "string", "number", "integer", "boolean", "array"].includes(
222
- schema.type
223
- );
224
- }
225
- function convertToolsToVercelAITools(tools) {
226
- const result = {};
227
- for (const tool of tools) {
228
- if (!isJsonSchema(tool.parameters)) {
229
- throw new Error(`Invalid JSON schema for tool ${tool.name}`);
230
- }
231
- const zodSchema = convertJsonSchemaToZodSchema(tool.parameters, true);
232
- result[tool.name] = (0, import_ai.tool)({
233
- description: tool.description,
234
- inputSchema: zodSchema
235
- });
236
- }
237
- return result;
238
- }
239
- function convertToolDefinitionsToVercelAITools(tools) {
240
- const result = {};
241
- for (const tool of tools) {
242
- result[tool.name] = (0, import_ai.tool)({
243
- description: tool.description,
244
- inputSchema: tool.parameters,
245
- execute: tool.execute
246
- });
247
- }
248
- return result;
249
- }
250
- var BuiltInAgent = class _BuiltInAgent extends import_client.AbstractAgent {
251
- constructor(config) {
252
- super();
253
- this.config = config;
254
- }
255
- abortController;
256
- /**
257
- * Check if a property can be overridden by forwardedProps
258
- */
259
- canOverride(property) {
260
- return this.config?.overridableProperties?.includes(property) ?? false;
261
- }
262
- run(input) {
263
- return new import_rxjs.Observable((subscriber) => {
264
- const startEvent = {
265
- type: import_client.EventType.RUN_STARTED,
266
- threadId: input.threadId,
267
- runId: input.runId
268
- };
269
- subscriber.next(startEvent);
270
- const model = resolveModel(this.config.model, this.config.apiKey);
271
- let systemPrompt = void 0;
272
- const hasPrompt = !!this.config.prompt;
273
- const hasContext = input.context && input.context.length > 0;
274
- const hasState = input.state !== void 0 && input.state !== null && !(typeof input.state === "object" && Object.keys(input.state).length === 0);
275
- if (hasPrompt || hasContext || hasState) {
276
- const parts = [];
277
- if (hasPrompt) {
278
- parts.push(this.config.prompt);
279
- }
280
- if (hasContext) {
281
- parts.push("\n## Context from the application\n");
282
- for (const ctx of input.context) {
283
- parts.push(`${ctx.description}:
284
- ${ctx.value}
285
- `);
286
- }
287
- }
288
- if (hasState) {
289
- parts.push(
290
- `
291
- ## Application State
292
- This is state from the application that you can edit by calling AGUISendStateSnapshot or AGUISendStateDelta.
293
- \`\`\`json
294
- ${JSON.stringify(input.state, null, 2)}
295
- \`\`\`
296
- `
297
- );
298
- }
299
- systemPrompt = parts.join("");
300
- }
301
- const messages = convertMessagesToVercelAISDKMessages(input.messages, {
302
- forwardSystemMessages: this.config.forwardSystemMessages,
303
- forwardDeveloperMessages: this.config.forwardDeveloperMessages
304
- });
305
- if (systemPrompt) {
306
- messages.unshift({
307
- role: "system",
308
- content: systemPrompt
309
- });
310
- }
311
- let allTools = convertToolsToVercelAITools(input.tools);
312
- if (this.config.tools && this.config.tools.length > 0) {
313
- const configTools = convertToolDefinitionsToVercelAITools(
314
- this.config.tools
315
- );
316
- allTools = { ...allTools, ...configTools };
317
- }
318
- const streamTextParams = {
319
- model,
320
- messages,
321
- tools: allTools,
322
- toolChoice: this.config.toolChoice,
323
- stopWhen: this.config.maxSteps ? (0, import_ai.stepCountIs)(this.config.maxSteps) : void 0,
324
- maxOutputTokens: this.config.maxOutputTokens,
325
- temperature: this.config.temperature,
326
- topP: this.config.topP,
327
- topK: this.config.topK,
328
- presencePenalty: this.config.presencePenalty,
329
- frequencyPenalty: this.config.frequencyPenalty,
330
- stopSequences: this.config.stopSequences,
331
- seed: this.config.seed,
332
- providerOptions: this.config.providerOptions,
333
- maxRetries: this.config.maxRetries
334
- };
335
- if (input.forwardedProps && typeof input.forwardedProps === "object") {
336
- const props = input.forwardedProps;
337
- if (props.model !== void 0 && this.canOverride("model")) {
338
- if (typeof props.model === "string" || typeof props.model === "object") {
339
- streamTextParams.model = resolveModel(
340
- props.model,
341
- this.config.apiKey
342
- );
343
- }
344
- }
345
- if (props.toolChoice !== void 0 && this.canOverride("toolChoice")) {
346
- const toolChoice = props.toolChoice;
347
- if (toolChoice === "auto" || toolChoice === "required" || toolChoice === "none" || typeof toolChoice === "object" && toolChoice !== null && "type" in toolChoice && toolChoice.type === "tool") {
348
- streamTextParams.toolChoice = toolChoice;
349
- }
350
- }
351
- if (typeof props.maxOutputTokens === "number" && this.canOverride("maxOutputTokens")) {
352
- streamTextParams.maxOutputTokens = props.maxOutputTokens;
353
- }
354
- if (typeof props.temperature === "number" && this.canOverride("temperature")) {
355
- streamTextParams.temperature = props.temperature;
356
- }
357
- if (typeof props.topP === "number" && this.canOverride("topP")) {
358
- streamTextParams.topP = props.topP;
359
- }
360
- if (typeof props.topK === "number" && this.canOverride("topK")) {
361
- streamTextParams.topK = props.topK;
362
- }
363
- if (typeof props.presencePenalty === "number" && this.canOverride("presencePenalty")) {
364
- streamTextParams.presencePenalty = props.presencePenalty;
365
- }
366
- if (typeof props.frequencyPenalty === "number" && this.canOverride("frequencyPenalty")) {
367
- streamTextParams.frequencyPenalty = props.frequencyPenalty;
368
- }
369
- if (Array.isArray(props.stopSequences) && this.canOverride("stopSequences")) {
370
- if (props.stopSequences.every(
371
- (item) => typeof item === "string"
372
- )) {
373
- streamTextParams.stopSequences = props.stopSequences;
374
- }
375
- }
376
- if (typeof props.seed === "number" && this.canOverride("seed")) {
377
- streamTextParams.seed = props.seed;
378
- }
379
- if (typeof props.maxRetries === "number" && this.canOverride("maxRetries")) {
380
- streamTextParams.maxRetries = props.maxRetries;
381
- }
382
- if (props.providerOptions !== void 0 && this.canOverride("providerOptions")) {
383
- if (typeof props.providerOptions === "object" && props.providerOptions !== null) {
384
- streamTextParams.providerOptions = props.providerOptions;
385
- }
386
- }
387
- }
388
- const mcpClients = [];
389
- (async () => {
390
- const abortController = new AbortController();
391
- this.abortController = abortController;
392
- let terminalEventEmitted = false;
393
- try {
394
- streamTextParams.tools = {
395
- ...streamTextParams.tools,
396
- AGUISendStateSnapshot: (0, import_ai.tool)({
397
- description: "Replace the entire application state with a new snapshot",
398
- inputSchema: import_zod.z.object({
399
- snapshot: import_zod.z.any().describe("The complete new state object")
400
- }),
401
- execute: async ({ snapshot }) => {
402
- return { success: true, snapshot };
403
- }
404
- }),
405
- AGUISendStateDelta: (0, import_ai.tool)({
406
- description: "Apply incremental updates to application state using JSON Patch operations",
407
- inputSchema: import_zod.z.object({
408
- delta: import_zod.z.array(
409
- import_zod.z.object({
410
- op: import_zod.z.enum(["add", "replace", "remove"]).describe("The operation to perform"),
411
- path: import_zod.z.string().describe("JSON Pointer path (e.g., '/foo/bar')"),
412
- value: import_zod.z.any().optional().describe(
413
- "The value to set. Required for 'add' and 'replace' operations, ignored for 'remove'."
414
- )
415
- })
416
- ).describe("Array of JSON Patch operations")
417
- }),
418
- execute: async ({ delta }) => {
419
- return { success: true, delta };
420
- }
421
- })
422
- };
423
- if (this.config.mcpServers && this.config.mcpServers.length > 0) {
424
- for (const serverConfig of this.config.mcpServers) {
425
- let transport;
426
- if (serverConfig.type === "http") {
427
- const url = new URL(serverConfig.url);
428
- transport = new import_streamableHttp.StreamableHTTPClientTransport(
429
- url,
430
- serverConfig.options
431
- );
432
- } else if (serverConfig.type === "sse") {
433
- transport = new import_sse.SSEClientTransport(
434
- new URL(serverConfig.url),
435
- serverConfig.headers
436
- );
437
- }
438
- if (transport) {
439
- const mcpClient = await (0, import_mcp.experimental_createMCPClient)({ transport });
440
- mcpClients.push(mcpClient);
441
- const mcpTools = await mcpClient.tools();
442
- streamTextParams.tools = {
443
- ...streamTextParams.tools,
444
- ...mcpTools
445
- };
446
- }
447
- }
448
- }
449
- const response = (0, import_ai.streamText)({
450
- ...streamTextParams,
451
- abortSignal: abortController.signal
452
- });
453
- let messageId = (0, import_crypto.randomUUID)();
454
- let reasoningMessageId = (0, import_crypto.randomUUID)();
455
- const toolCallStates = /* @__PURE__ */ new Map();
456
- const ensureToolCallState = (toolCallId) => {
457
- let state = toolCallStates.get(toolCallId);
458
- if (!state) {
459
- state = { started: false, hasArgsDelta: false, ended: false };
460
- toolCallStates.set(toolCallId, state);
461
- }
462
- return state;
463
- };
464
- for await (const part of response.fullStream) {
465
- switch (part.type) {
466
- case "abort": {
467
- const abortEndEvent = {
468
- type: import_client.EventType.RUN_FINISHED,
469
- threadId: input.threadId,
470
- runId: input.runId
471
- };
472
- subscriber.next(abortEndEvent);
473
- terminalEventEmitted = true;
474
- subscriber.complete();
475
- break;
476
- }
477
- case "reasoning-start": {
478
- const providedId = "id" in part ? part.id : void 0;
479
- if (providedId && providedId !== "0") {
480
- reasoningMessageId = providedId;
481
- }
482
- const reasoningStartEvent = {
483
- type: import_client.EventType.REASONING_START,
484
- messageId: reasoningMessageId
485
- };
486
- subscriber.next(reasoningStartEvent);
487
- const reasoningMessageStart = {
488
- type: import_client.EventType.REASONING_MESSAGE_START,
489
- messageId: reasoningMessageId,
490
- role: "reasoning"
491
- };
492
- subscriber.next(reasoningMessageStart);
493
- break;
494
- }
495
- case "reasoning-delta": {
496
- const reasoningDeltaEvent = {
497
- type: import_client.EventType.REASONING_MESSAGE_CONTENT,
498
- messageId: reasoningMessageId,
499
- delta: ("text" in part ? part.text : part.delta) ?? ""
500
- };
501
- subscriber.next(reasoningDeltaEvent);
502
- break;
503
- }
504
- case "reasoning-end": {
505
- const reasoningMessageEnd = {
506
- type: import_client.EventType.REASONING_MESSAGE_END,
507
- messageId: reasoningMessageId
508
- };
509
- subscriber.next(reasoningMessageEnd);
510
- const reasoningEndEvent = {
511
- type: import_client.EventType.REASONING_END,
512
- messageId: reasoningMessageId
513
- };
514
- subscriber.next(reasoningEndEvent);
515
- break;
516
- }
517
- case "tool-input-start": {
518
- const toolCallId = part.id;
519
- const state = ensureToolCallState(toolCallId);
520
- state.toolName = part.toolName;
521
- if (!state.started) {
522
- state.started = true;
523
- const startEvent2 = {
524
- type: import_client.EventType.TOOL_CALL_START,
525
- parentMessageId: messageId,
526
- toolCallId,
527
- toolCallName: part.toolName
528
- };
529
- subscriber.next(startEvent2);
530
- }
531
- break;
532
- }
533
- case "tool-input-delta": {
534
- const toolCallId = part.id;
535
- const state = ensureToolCallState(toolCallId);
536
- state.hasArgsDelta = true;
537
- const argsEvent = {
538
- type: import_client.EventType.TOOL_CALL_ARGS,
539
- toolCallId,
540
- delta: part.delta
541
- };
542
- subscriber.next(argsEvent);
543
- break;
544
- }
545
- case "tool-input-end": {
546
- break;
547
- }
548
- case "text-start": {
549
- const providedId = "id" in part ? part.id : void 0;
550
- messageId = providedId && providedId !== "0" ? providedId : (0, import_crypto.randomUUID)();
551
- break;
552
- }
553
- case "text-delta": {
554
- const textDelta = "text" in part ? part.text : "";
555
- const textEvent = {
556
- type: import_client.EventType.TEXT_MESSAGE_CHUNK,
557
- role: "assistant",
558
- messageId,
559
- delta: textDelta
560
- };
561
- subscriber.next(textEvent);
562
- break;
563
- }
564
- case "tool-call": {
565
- const toolCallId = part.toolCallId;
566
- const state = ensureToolCallState(toolCallId);
567
- state.toolName = part.toolName ?? state.toolName;
568
- if (!state.started) {
569
- state.started = true;
570
- const startEvent2 = {
571
- type: import_client.EventType.TOOL_CALL_START,
572
- parentMessageId: messageId,
573
- toolCallId,
574
- toolCallName: part.toolName
575
- };
576
- subscriber.next(startEvent2);
577
- }
578
- if (!state.hasArgsDelta && "input" in part && part.input !== void 0) {
579
- let serializedInput = "";
580
- if (typeof part.input === "string") {
581
- serializedInput = part.input;
582
- } else {
583
- try {
584
- serializedInput = JSON.stringify(part.input);
585
- } catch {
586
- serializedInput = String(part.input);
587
- }
588
- }
589
- if (serializedInput.length > 0) {
590
- const argsEvent = {
591
- type: import_client.EventType.TOOL_CALL_ARGS,
592
- toolCallId,
593
- delta: serializedInput
594
- };
595
- subscriber.next(argsEvent);
596
- state.hasArgsDelta = true;
597
- }
598
- }
599
- if (!state.ended) {
600
- state.ended = true;
601
- const endEvent = {
602
- type: import_client.EventType.TOOL_CALL_END,
603
- toolCallId
604
- };
605
- subscriber.next(endEvent);
606
- }
607
- break;
608
- }
609
- case "tool-result": {
610
- const toolResult = "output" in part ? part.output : null;
611
- const toolName = "toolName" in part ? part.toolName : "";
612
- toolCallStates.delete(part.toolCallId);
613
- if (toolName === "AGUISendStateSnapshot" && toolResult && typeof toolResult === "object") {
614
- const stateSnapshotEvent = {
615
- type: import_client.EventType.STATE_SNAPSHOT,
616
- snapshot: toolResult.snapshot
617
- };
618
- subscriber.next(stateSnapshotEvent);
619
- } else if (toolName === "AGUISendStateDelta" && toolResult && typeof toolResult === "object") {
620
- const stateDeltaEvent = {
621
- type: import_client.EventType.STATE_DELTA,
622
- delta: toolResult.delta
623
- };
624
- subscriber.next(stateDeltaEvent);
625
- }
626
- const resultEvent = {
627
- type: import_client.EventType.TOOL_CALL_RESULT,
628
- role: "tool",
629
- messageId: (0, import_crypto.randomUUID)(),
630
- toolCallId: part.toolCallId,
631
- content: JSON.stringify(toolResult)
632
- };
633
- subscriber.next(resultEvent);
634
- break;
635
- }
636
- case "finish": {
637
- const finishedEvent = {
638
- type: import_client.EventType.RUN_FINISHED,
639
- threadId: input.threadId,
640
- runId: input.runId
641
- };
642
- subscriber.next(finishedEvent);
643
- terminalEventEmitted = true;
644
- subscriber.complete();
645
- break;
646
- }
647
- case "error": {
648
- if (abortController.signal.aborted) {
649
- break;
650
- }
651
- const runErrorEvent = {
652
- type: import_client.EventType.RUN_ERROR,
653
- message: part.error + ""
654
- };
655
- subscriber.next(runErrorEvent);
656
- terminalEventEmitted = true;
657
- subscriber.error(part.error);
658
- break;
659
- }
660
- }
661
- }
662
- if (!terminalEventEmitted) {
663
- if (abortController.signal.aborted) {
664
- } else {
665
- const finishedEvent = {
666
- type: import_client.EventType.RUN_FINISHED,
667
- threadId: input.threadId,
668
- runId: input.runId
669
- };
670
- subscriber.next(finishedEvent);
671
- }
672
- terminalEventEmitted = true;
673
- subscriber.complete();
674
- }
675
- } catch (error) {
676
- if (abortController.signal.aborted) {
677
- subscriber.complete();
678
- } else {
679
- const runErrorEvent = {
680
- type: import_client.EventType.RUN_ERROR,
681
- message: error + ""
682
- };
683
- subscriber.next(runErrorEvent);
684
- terminalEventEmitted = true;
685
- subscriber.error(error);
686
- }
687
- } finally {
688
- this.abortController = void 0;
689
- await Promise.all(mcpClients.map((client) => client.close()));
690
- }
691
- })();
692
- return () => {
693
- Promise.all(mcpClients.map((client) => client.close())).catch(() => {
694
- });
695
- };
696
- });
697
- }
698
- clone() {
699
- const cloned = new _BuiltInAgent(this.config);
700
- cloned.middlewares = [...this.middlewares];
701
- return cloned;
702
- }
703
- abortRun() {
704
- this.abortController?.abort();
705
- }
706
- };
707
- var BasicAgent = class extends BuiltInAgent {
708
- constructor(config) {
709
- super(config);
710
- console.warn("BasicAgent is deprecated, use BuiltInAgent instead");
711
- }
712
- };
713
- // Annotate the CommonJS export names for ESM import in node:
714
- 0 && (module.exports = {
715
- BasicAgent,
716
- BuiltInAgent,
717
- convertJsonSchemaToZodSchema,
718
- convertMessagesToVercelAISDKMessages,
719
- convertToolDefinitionsToVercelAITools,
720
- convertToolsToVercelAITools,
721
- defineTool,
722
- resolveModel
723
- });
724
- //# sourceMappingURL=index.js.map