veryfront 0.0.69 → 0.0.71

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/ai/index.js CHANGED
@@ -19,6 +19,11 @@ globalThis.Deno = globalThis.Deno || {
19
19
  }
20
20
  };
21
21
 
22
+ // src/ai/types/agent.ts
23
+ function getTextFromParts(parts) {
24
+ return parts.filter((p) => p.type === "text").map((p) => p.text).join("");
25
+ }
26
+
22
27
  // src/ai/providers/openai.ts
23
28
  import { z as z2 } from "zod";
24
29
 
@@ -174,6 +179,7 @@ var OpenAIStreamChunkSchema = z.object({
174
179
  })).min(1)
175
180
  });
176
181
  var BaseProvider = class {
182
+ config;
177
183
  constructor(config) {
178
184
  this.config = config;
179
185
  this.validateConfig();
@@ -388,9 +394,12 @@ var OpenAIResponseSchema = z2.object({
388
394
  }).optional()
389
395
  });
390
396
  var OpenAIProvider = class extends BaseProvider {
397
+ name = "openai";
398
+ apiKey;
399
+ baseURL;
400
+ organizationId;
391
401
  constructor(config) {
392
402
  super(config);
393
- this.name = "openai";
394
403
  this.apiKey = config.apiKey;
395
404
  this.baseURL = config.baseURL || "https://api.openai.com/v1";
396
405
  this.organizationId = config.organizationId;
@@ -492,9 +501,11 @@ var OpenAIProvider = class extends BaseProvider {
492
501
 
493
502
  // src/ai/providers/anthropic.ts
494
503
  var AnthropicProvider = class extends BaseProvider {
504
+ name = "anthropic";
505
+ apiKey;
506
+ baseURL;
495
507
  constructor(config) {
496
508
  super(config);
497
- this.name = "anthropic";
498
509
  this.apiKey = config.apiKey;
499
510
  this.baseURL = config.baseURL || "https://api.anthropic.com";
500
511
  }
@@ -792,9 +803,11 @@ var GoogleResponseSchema = z3.object({
792
803
  }).optional()
793
804
  });
794
805
  var GoogleProvider = class extends BaseProvider {
806
+ name = "google";
807
+ apiKey;
808
+ baseURL;
795
809
  constructor(config) {
796
810
  super(config);
797
- this.name = "google";
798
811
  this.apiKey = config.apiKey;
799
812
  this.baseURL = config.baseURL || "https://generativelanguage.googleapis.com/v1beta";
800
813
  }
@@ -916,11 +929,9 @@ function getEnv(key) {
916
929
 
917
930
  // src/ai/providers/factory.ts
918
931
  var ProviderRegistry = class {
919
- constructor() {
920
- this.providers = /* @__PURE__ */ new Map();
921
- this.config = {};
922
- this.autoInitialized = false;
923
- }
932
+ providers = /* @__PURE__ */ new Map();
933
+ config = {};
934
+ autoInitialized = false;
924
935
  /**
925
936
  * Auto-initialize providers from environment variables
926
937
  * This is called lazily when a provider is first requested
@@ -1259,6 +1270,7 @@ function tool(config) {
1259
1270
  }
1260
1271
  return {
1261
1272
  id,
1273
+ type: "function",
1262
1274
  description: config.description,
1263
1275
  inputSchema: config.inputSchema,
1264
1276
  inputSchemaJson,
@@ -1288,14 +1300,62 @@ function tool(config) {
1288
1300
  mcp: config.mcp
1289
1301
  };
1290
1302
  }
1303
+ function dynamicTool(config) {
1304
+ const id = config.id || generateToolId();
1305
+ let inputSchemaJson;
1306
+ const zodLikeSchema = config.inputSchema;
1307
+ if (zodLikeSchema?._def?.typeName) {
1308
+ try {
1309
+ inputSchemaJson = zodToJsonSchema(config.inputSchema);
1310
+ agentLogger.info(
1311
+ `[DYNAMIC_TOOL] Converted schema for "${id}": ${Object.keys(inputSchemaJson.properties || {}).length} properties`
1312
+ );
1313
+ } catch {
1314
+ inputSchemaJson = { type: "object", properties: {}, additionalProperties: true };
1315
+ agentLogger.info(`[DYNAMIC_TOOL] Using permissive schema for "${id}"`);
1316
+ }
1317
+ } else if (zodLikeSchema?._def?.shape) {
1318
+ try {
1319
+ const shape = typeof zodLikeSchema._def.shape === "function" ? zodLikeSchema._def.shape() : zodLikeSchema._def.shape;
1320
+ const properties = {};
1321
+ for (const key of Object.keys(shape || {})) {
1322
+ properties[key] = { type: "string" };
1323
+ }
1324
+ inputSchemaJson = {
1325
+ type: "object",
1326
+ properties,
1327
+ additionalProperties: true
1328
+ };
1329
+ agentLogger.info(`[DYNAMIC_TOOL] Introspected schema for "${id}"`);
1330
+ } catch {
1331
+ inputSchemaJson = { type: "object", properties: {}, additionalProperties: true };
1332
+ }
1333
+ } else {
1334
+ inputSchemaJson = { type: "object", properties: {}, additionalProperties: true };
1335
+ agentLogger.info(`[DYNAMIC_TOOL] Using fully dynamic schema for "${id}"`);
1336
+ }
1337
+ return {
1338
+ id,
1339
+ type: "dynamic",
1340
+ description: config.description,
1341
+ inputSchema: config.inputSchema,
1342
+ inputSchemaJson,
1343
+ execute: async (input, context) => {
1344
+ const result = await config.execute(input, context);
1345
+ if (config.toModelOutput) {
1346
+ return config.toModelOutput(result);
1347
+ }
1348
+ return result;
1349
+ },
1350
+ mcp: config.mcp
1351
+ };
1352
+ }
1291
1353
  var toolIdCounter = 0;
1292
1354
  function generateToolId() {
1293
1355
  return `tool_${Date.now()}_${toolIdCounter++}`;
1294
1356
  }
1295
1357
  var ToolRegistryClass = class {
1296
- constructor() {
1297
- this.tools = /* @__PURE__ */ new Map();
1298
- }
1358
+ tools = /* @__PURE__ */ new Map();
1299
1359
  register(id, toolInstance) {
1300
1360
  if (this.tools.has(id)) {
1301
1361
  agentLogger.debug(`Tool "${id}" is already registered. Overwriting.`);
@@ -1555,9 +1615,7 @@ function patternToId(pattern) {
1555
1615
  return pattern.replace(/^\//, "").replace(/\//g, "_").replace(/:/g, "");
1556
1616
  }
1557
1617
  var ResourceRegistryClass = class {
1558
- constructor() {
1559
- this.resources = /* @__PURE__ */ new Map();
1560
- }
1618
+ resources = /* @__PURE__ */ new Map();
1561
1619
  /**
1562
1620
  * Register a resource
1563
1621
  */
@@ -1653,9 +1711,7 @@ function interpolateVariables(template, variables) {
1653
1711
  });
1654
1712
  }
1655
1713
  var PromptRegistryClass = class {
1656
- constructor() {
1657
- this.prompts = /* @__PURE__ */ new Map();
1658
- }
1714
+ prompts = /* @__PURE__ */ new Map();
1659
1715
  /**
1660
1716
  * Register a prompt
1661
1717
  */
@@ -1733,6 +1789,7 @@ import { z as z4 } from "zod";
1733
1789
  function agentAsTool(agent2, description) {
1734
1790
  return {
1735
1791
  id: `agent_${agent2.id}`,
1792
+ type: "function",
1736
1793
  description,
1737
1794
  inputSchema: z4.object({
1738
1795
  input: z4.string().describe("Input for the agent")
@@ -1785,9 +1842,7 @@ function createWorkflow(config) {
1785
1842
  };
1786
1843
  }
1787
1844
  var AgentRegistryClass = class {
1788
- constructor() {
1789
- this.agents = /* @__PURE__ */ new Map();
1790
- }
1845
+ agents = /* @__PURE__ */ new Map();
1791
1846
  /**
1792
1847
  * Register an agent
1793
1848
  */
@@ -2040,7 +2095,7 @@ import { join } from "node:path";
2040
2095
  // deno.json
2041
2096
  var deno_default = {
2042
2097
  name: "veryfront",
2043
- version: "0.0.68",
2098
+ version: "0.0.71",
2044
2099
  nodeModulesDir: "auto",
2045
2100
  exclude: [
2046
2101
  "npm/",
@@ -2709,12 +2764,10 @@ function createMockAdapter() {
2709
2764
 
2710
2765
  // src/platform/compat/fs.ts
2711
2766
  var NodeFileSystem = class {
2712
- constructor() {
2713
- this.fs = null;
2714
- this.os = null;
2715
- this.path = null;
2716
- this.initialized = false;
2717
- }
2767
+ fs = null;
2768
+ os = null;
2769
+ path = null;
2770
+ initialized = false;
2718
2771
  async ensureInitialized() {
2719
2772
  if (this.initialized)
2720
2773
  return;
@@ -3455,8 +3508,9 @@ function generateId(prefix) {
3455
3508
 
3456
3509
  // src/ai/agent/memory.ts
3457
3510
  var ConversationMemory = class {
3511
+ messages = [];
3512
+ config;
3458
3513
  constructor(config) {
3459
- this.messages = [];
3460
3514
  this.config = config;
3461
3515
  }
3462
3516
  async add(message) {
@@ -3494,15 +3548,17 @@ var ConversationMemory = class {
3494
3548
  }
3495
3549
  estimateTokens(messages) {
3496
3550
  const totalChars = messages.reduce(
3497
- (sum, msg) => sum + msg.content.length,
3551
+ (sum, msg) => sum + getTextFromParts(msg.parts).length,
3498
3552
  0
3499
3553
  );
3500
3554
  return Math.ceil(totalChars / 4);
3501
3555
  }
3502
3556
  };
3503
3557
  var BufferMemory = class {
3558
+ messages = [];
3559
+ config;
3560
+ bufferSize;
3504
3561
  constructor(config) {
3505
- this.messages = [];
3506
3562
  this.config = config;
3507
3563
  this.bufferSize = config.maxMessages || 10;
3508
3564
  }
@@ -3529,16 +3585,18 @@ var BufferMemory = class {
3529
3585
  }
3530
3586
  estimateTokens(messages) {
3531
3587
  const totalChars = messages.reduce(
3532
- (sum, msg) => sum + msg.content.length,
3588
+ (sum, msg) => sum + getTextFromParts(msg.parts).length,
3533
3589
  0
3534
3590
  );
3535
3591
  return Math.ceil(totalChars / 4);
3536
3592
  }
3537
3593
  };
3538
3594
  var SummaryMemory = class {
3595
+ messages = [];
3596
+ summary = "";
3597
+ config;
3598
+ summaryThreshold;
3539
3599
  constructor(config) {
3540
- this.messages = [];
3541
- this.summary = "";
3542
3600
  this.config = config;
3543
3601
  this.summaryThreshold = config.maxMessages || 20;
3544
3602
  }
@@ -3554,8 +3612,8 @@ var SummaryMemory = class {
3554
3612
  {
3555
3613
  id: "summary",
3556
3614
  role: "system",
3557
- content: `Previous conversation summary:
3558
- ${this.summary}`,
3615
+ parts: [{ type: "text", text: `Previous conversation summary:
3616
+ ${this.summary}` }],
3559
3617
  timestamp: Date.now()
3560
3618
  },
3561
3619
  ...this.messages
@@ -3579,13 +3637,13 @@ ${this.summary}`,
3579
3637
  summarizeOldMessages() {
3580
3638
  const toSummarize = this.messages.slice(0, Math.floor(this.messages.length / 2));
3581
3639
  const remaining = this.messages.slice(Math.floor(this.messages.length / 2));
3582
- const topics = toSummarize.filter((m) => m.role === "user").map((m) => m.content.substring(0, 50)).join("; ");
3640
+ const topics = toSummarize.filter((m) => m.role === "user").map((m) => getTextFromParts(m.parts).substring(0, 50)).join("; ");
3583
3641
  this.summary = `Discussed: ${topics}`;
3584
3642
  this.messages = remaining;
3585
3643
  return Promise.resolve();
3586
3644
  }
3587
3645
  estimateTokens(messages) {
3588
- const totalChars = messages.reduce((sum, msg) => sum + msg.content.length, 0) + this.summary.length;
3646
+ const totalChars = messages.reduce((sum, msg) => sum + getTextFromParts(msg.parts).length, 0) + this.summary.length;
3589
3647
  return Math.ceil(totalChars / 4);
3590
3648
  }
3591
3649
  };
@@ -3647,11 +3705,9 @@ var VERYFRONT_PATHS = {
3647
3705
 
3648
3706
  // src/core/utils/bundle-manifest.ts
3649
3707
  var InMemoryBundleManifestStore = class {
3650
- constructor() {
3651
- this.metadata = /* @__PURE__ */ new Map();
3652
- this.code = /* @__PURE__ */ new Map();
3653
- this.sourceIndex = /* @__PURE__ */ new Map();
3654
- }
3708
+ metadata = /* @__PURE__ */ new Map();
3709
+ code = /* @__PURE__ */ new Map();
3710
+ sourceIndex = /* @__PURE__ */ new Map();
3655
3711
  getBundleMetadata(key) {
3656
3712
  const entry = this.metadata.get(key);
3657
3713
  if (!entry)
@@ -3943,16 +3999,14 @@ var ContextPropagation = class {
3943
3999
 
3944
4000
  // src/observability/tracing/manager.ts
3945
4001
  var TracingManager = class {
3946
- constructor() {
3947
- this.state = {
3948
- initialized: false,
3949
- tracer: null,
3950
- api: null,
3951
- propagator: null
3952
- };
3953
- this.spanOps = null;
3954
- this.contextProp = null;
3955
- }
4002
+ state = {
4003
+ initialized: false,
4004
+ tracer: null,
4005
+ api: null,
4006
+ propagator: null
4007
+ };
4008
+ spanOps = null;
4009
+ contextProp = null;
3956
4010
  async initialize(config = {}, adapter) {
3957
4011
  if (this.state.initialized) {
3958
4012
  serverLogger.debug("[tracing] Already initialized");
@@ -4080,9 +4134,40 @@ var AgentStreamEventSchema = z6.discriminatedUnion("type", [
4080
4134
  ]);
4081
4135
  var DEFAULT_MAX_TOKENS = 4096;
4082
4136
  var DEFAULT_TEMPERATURE = 0.7;
4137
+ function convertMessageToProvider(msg) {
4138
+ const content = getTextFromParts(msg.parts);
4139
+ const providerMsg = {
4140
+ role: msg.role,
4141
+ content
4142
+ };
4143
+ const toolCallParts = msg.parts.filter(
4144
+ (p) => p.type === "tool-call"
4145
+ );
4146
+ if (toolCallParts.length > 0) {
4147
+ providerMsg.tool_calls = toolCallParts.map((tc) => ({
4148
+ id: tc.toolCallId,
4149
+ type: "function",
4150
+ function: {
4151
+ name: tc.toolName,
4152
+ arguments: JSON.stringify(tc.args)
4153
+ }
4154
+ }));
4155
+ }
4156
+ const toolResultPart = msg.parts.find(
4157
+ (p) => p.type === "tool-result"
4158
+ );
4159
+ if (toolResultPart && msg.role === "tool") {
4160
+ providerMsg.tool_call_id = toolResultPart.toolCallId;
4161
+ providerMsg.content = JSON.stringify(toolResultPart.result);
4162
+ }
4163
+ return providerMsg;
4164
+ }
4083
4165
  var AgentRuntime = class {
4166
+ id;
4167
+ config;
4168
+ memory;
4169
+ status = "idle";
4084
4170
  constructor(id, config) {
4085
- this.status = "idle";
4086
4171
  this.id = id;
4087
4172
  this.config = config;
4088
4173
  const memoryConfig = config.memory || { type: "conversation", maxTokens: 4e3 };
@@ -4150,7 +4235,8 @@ var AgentRuntime = class {
4150
4235
  start: async (controller) => {
4151
4236
  try {
4152
4237
  this.status = "streaming";
4153
- const startEvent = JSON.stringify({ type: "start" });
4238
+ const messageId = `msg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
4239
+ const startEvent = JSON.stringify({ type: "start", messageId });
4154
4240
  controller.enqueue(encoder.encode(`data: ${startEvent}
4155
4241
 
4156
4242
  `));
@@ -4224,26 +4310,7 @@ var AgentRuntime = class {
4224
4310
  return await provider.complete({
4225
4311
  model,
4226
4312
  system: systemPrompt,
4227
- messages: currentMessages.map((m) => {
4228
- const msg = {
4229
- role: m.role,
4230
- content: m.content
4231
- };
4232
- if (m.role === "assistant" && m.toolCalls) {
4233
- msg.tool_calls = m.toolCalls.map((tc) => ({
4234
- id: tc.id,
4235
- type: "function",
4236
- function: {
4237
- name: tc.name,
4238
- arguments: JSON.stringify(tc.arguments)
4239
- }
4240
- }));
4241
- }
4242
- if (m.role === "tool" && m.toolCallId) {
4243
- msg.tool_call_id = m.toolCallId;
4244
- }
4245
- return msg;
4246
- }),
4313
+ messages: currentMessages.map((m) => convertMessageToProvider(m)),
4247
4314
  tools: tools.length > 0 ? tools : void 0,
4248
4315
  maxTokens: this.config.memory?.maxTokens || DEFAULT_MAX_TOKENS,
4249
4316
  temperature: DEFAULT_TEMPERATURE
@@ -4252,11 +4319,24 @@ var AgentRuntime = class {
4252
4319
  totalUsage.promptTokens += response.usage.promptTokens;
4253
4320
  totalUsage.completionTokens += response.usage.completionTokens;
4254
4321
  totalUsage.totalTokens += response.usage.totalTokens;
4322
+ const assistantParts = [];
4323
+ if (response.text) {
4324
+ assistantParts.push({ type: "text", text: response.text });
4325
+ }
4326
+ if (response.toolCalls) {
4327
+ for (const tc of response.toolCalls) {
4328
+ assistantParts.push({
4329
+ type: "tool-call",
4330
+ toolCallId: tc.id,
4331
+ toolName: tc.name,
4332
+ args: tc.arguments
4333
+ });
4334
+ }
4335
+ }
4255
4336
  const assistantMessage = {
4256
4337
  id: `msg_${Date.now()}_${step2}`,
4257
4338
  role: "assistant",
4258
- content: response.text,
4259
- toolCalls: response.toolCalls,
4339
+ parts: assistantParts,
4260
4340
  timestamp: Date.now()
4261
4341
  };
4262
4342
  currentMessages.push(assistantMessage);
@@ -4290,9 +4370,12 @@ var AgentRuntime = class {
4290
4370
  const toolResultMessage = {
4291
4371
  id: `tool_${tc.id}`,
4292
4372
  role: "tool",
4293
- content: JSON.stringify(result),
4294
- toolCallId: tc.id,
4295
- toolCall,
4373
+ parts: [{
4374
+ type: "tool-result",
4375
+ toolCallId: tc.id,
4376
+ toolName: tc.name,
4377
+ result
4378
+ }],
4296
4379
  timestamp: Date.now()
4297
4380
  };
4298
4381
  currentMessages.push(toolResultMessage);
@@ -4304,9 +4387,12 @@ var AgentRuntime = class {
4304
4387
  const errorMessage = {
4305
4388
  id: `tool_error_${tc.id}`,
4306
4389
  role: "tool",
4307
- content: `Error: ${toolCall.error}`,
4308
- toolCallId: tc.id,
4309
- toolCall,
4390
+ parts: [{
4391
+ type: "tool-result",
4392
+ toolCallId: tc.id,
4393
+ toolName: tc.name,
4394
+ result: { error: toolCall.error }
4395
+ }],
4310
4396
  timestamp: Date.now()
4311
4397
  };
4312
4398
  currentMessages.push(errorMessage);
@@ -4329,8 +4415,9 @@ var AgentRuntime = class {
4329
4415
  }
4330
4416
  this.status = "completed";
4331
4417
  addSpanEvent(loopSpan, "max_steps_reached", { maxSteps });
4418
+ const lastMsg = currentMessages[currentMessages.length - 1];
4332
4419
  return {
4333
- text: currentMessages[currentMessages.length - 1]?.content || "",
4420
+ text: lastMsg ? getTextFromParts(lastMsg.parts) : "",
4334
4421
  messages: currentMessages,
4335
4422
  toolCalls,
4336
4423
  status: this.status,
@@ -4356,23 +4443,15 @@ var AgentRuntime = class {
4356
4443
  totalTokens: 0
4357
4444
  };
4358
4445
  for (let step2 = 0; step2 < maxSteps; step2++) {
4446
+ const startStepEvent = JSON.stringify({ type: "start-step" });
4447
+ controller.enqueue(encoder.encode(`data: ${startStepEvent}
4448
+
4449
+ `));
4359
4450
  const tools = this.getAvailableTools();
4360
4451
  const stream = await provider.stream({
4361
4452
  model,
4362
4453
  system: systemPrompt,
4363
- messages: currentMessages.map((m) => ({
4364
- role: m.role,
4365
- content: m.content,
4366
- tool_calls: m.toolCalls?.map((tc) => ({
4367
- id: tc.id,
4368
- type: "function",
4369
- function: {
4370
- name: tc.name,
4371
- arguments: JSON.stringify(tc.arguments)
4372
- }
4373
- })),
4374
- tool_call_id: m.toolCallId
4375
- })),
4454
+ messages: currentMessages.map((m) => convertMessageToProvider(m)),
4376
4455
  tools: tools.length > 0 ? tools : void 0,
4377
4456
  maxTokens: this.config.memory?.maxTokens || DEFAULT_MAX_TOKENS,
4378
4457
  temperature: DEFAULT_TEMPERATURE
@@ -4400,9 +4479,13 @@ var AgentRuntime = class {
4400
4479
  toolCall.status = "error";
4401
4480
  toolCall.error = errorStr;
4402
4481
  toolCalls.push(toolCall);
4482
+ const errorTool = toolRegistry.get(toolCall.name);
4483
+ const errorIsDynamic = errorTool?.type === "dynamic";
4403
4484
  const errorData = JSON.stringify({
4404
- type: "error",
4405
- error: errorStr
4485
+ type: "tool-output-error",
4486
+ toolCallId: toolCall.id,
4487
+ errorText: errorStr,
4488
+ ...errorIsDynamic && { dynamic: true }
4406
4489
  });
4407
4490
  controller.enqueue(encoder.encode(`data: ${errorData}
4408
4491
 
@@ -4410,9 +4493,12 @@ var AgentRuntime = class {
4410
4493
  const errorMessage = {
4411
4494
  id: `tool_error_${toolCall.id}`,
4412
4495
  role: "tool",
4413
- content: `Error: ${errorStr}`,
4414
- toolCallId: toolCall.id,
4415
- toolCall,
4496
+ parts: [{
4497
+ type: "tool-result",
4498
+ toolCallId: toolCall.id,
4499
+ toolName: toolCall.name,
4500
+ result: { error: errorStr }
4501
+ }],
4416
4502
  timestamp: Date.now()
4417
4503
  };
4418
4504
  currentMessages.push(errorMessage);
@@ -4442,10 +4528,13 @@ var AgentRuntime = class {
4442
4528
  name: event.toolCall.name,
4443
4529
  arguments: ""
4444
4530
  });
4531
+ const startTool = toolRegistry.get(event.toolCall.name);
4532
+ const startIsDynamic = startTool?.type === "dynamic";
4445
4533
  const toolStartEvent = JSON.stringify({
4446
- type: "tool-call-streaming-start",
4534
+ type: "tool-input-start",
4447
4535
  toolCallId: event.toolCall.id,
4448
- toolName: event.toolCall.name
4536
+ toolName: event.toolCall.name,
4537
+ ...startIsDynamic && { dynamic: true }
4449
4538
  });
4450
4539
  controller.enqueue(encoder.encode(`data: ${toolStartEvent}
4451
4540
 
@@ -4457,9 +4546,9 @@ var AgentRuntime = class {
4457
4546
  const tc = streamToolCalls.get(event.id);
4458
4547
  tc.arguments += event.arguments;
4459
4548
  const toolDeltaEvent = JSON.stringify({
4460
- type: "tool-call-delta",
4549
+ type: "tool-input-delta",
4461
4550
  toolCallId: event.id,
4462
- argsTextDelta: event.arguments
4551
+ inputTextDelta: event.arguments
4463
4552
  });
4464
4553
  controller.enqueue(encoder.encode(`data: ${toolDeltaEvent}
4465
4554
 
@@ -4473,12 +4562,15 @@ var AgentRuntime = class {
4473
4562
  name: event.toolCall.name,
4474
4563
  arguments: event.toolCall.arguments
4475
4564
  });
4565
+ const completeTool = toolRegistry.get(event.toolCall.name);
4566
+ const completeIsDynamic = completeTool?.type === "dynamic";
4476
4567
  const { args } = parseStreamToolArgs(event.toolCall.arguments);
4477
4568
  const toolCallEvent = JSON.stringify({
4478
- type: "tool-call",
4569
+ type: "tool-input-available",
4479
4570
  toolCallId: event.toolCall.id,
4480
4571
  toolName: event.toolCall.name,
4481
- args
4572
+ input: args,
4573
+ ...completeIsDynamic && { dynamic: true }
4482
4574
  });
4483
4575
  controller.enqueue(encoder.encode(`data: ${toolCallEvent}
4484
4576
 
@@ -4531,30 +4623,33 @@ var AgentRuntime = class {
4531
4623
  } catch {
4532
4624
  }
4533
4625
  }
4626
+ const streamParts = [];
4627
+ if (accumulatedText) {
4628
+ streamParts.push({ type: "text", text: accumulatedText });
4629
+ }
4630
+ if (streamToolCalls.size > 0) {
4631
+ for (const tc of streamToolCalls.values()) {
4632
+ const { args, error } = parseStreamToolArgs(tc.arguments);
4633
+ if (error) {
4634
+ serverLogger.warn("[AGENT] Failed to parse streamed tool arguments", {
4635
+ toolCallId: tc.id,
4636
+ error
4637
+ });
4638
+ }
4639
+ streamParts.push({
4640
+ type: "tool-call",
4641
+ toolCallId: tc.id,
4642
+ toolName: tc.name,
4643
+ args
4644
+ });
4645
+ }
4646
+ }
4534
4647
  const assistantMessage = {
4535
4648
  id: `msg_${Date.now()}_${step2}`,
4536
4649
  role: "assistant",
4537
- content: accumulatedText,
4650
+ parts: streamParts,
4538
4651
  timestamp: Date.now()
4539
4652
  };
4540
- if (streamToolCalls.size > 0) {
4541
- assistantMessage.toolCalls = Array.from(streamToolCalls.values()).map(
4542
- (tc) => {
4543
- const { args, error } = parseStreamToolArgs(tc.arguments);
4544
- if (error) {
4545
- serverLogger.warn("[AGENT] Failed to parse streamed tool arguments", {
4546
- toolCallId: tc.id,
4547
- error
4548
- });
4549
- }
4550
- return {
4551
- id: tc.id,
4552
- name: tc.name,
4553
- arguments: args
4554
- };
4555
- }
4556
- );
4557
- }
4558
4653
  currentMessages.push(assistantMessage);
4559
4654
  await this.memory.add(assistantMessage);
4560
4655
  if (finishReason === "tool_calls" && streamToolCalls.size > 0) {
@@ -4572,6 +4667,17 @@ var AgentRuntime = class {
4572
4667
  toolCallId: tc.id,
4573
4668
  error: argError
4574
4669
  });
4670
+ const inputErrorTool = toolRegistry.get(tc.name);
4671
+ const inputErrorIsDynamic = inputErrorTool?.type === "dynamic";
4672
+ const inputErrorEvent = JSON.stringify({
4673
+ type: "tool-input-error",
4674
+ toolCallId: tc.id,
4675
+ errorText: `Invalid tool arguments: ${argError}`,
4676
+ ...inputErrorIsDynamic && { dynamic: true }
4677
+ });
4678
+ controller.enqueue(encoder.encode(`data: ${inputErrorEvent}
4679
+
4680
+ `));
4575
4681
  await recordToolError(toolCall, `Invalid tool arguments: ${argError}`);
4576
4682
  continue;
4577
4683
  }
@@ -4581,15 +4687,6 @@ var AgentRuntime = class {
4581
4687
  if (callbacks?.onToolCall) {
4582
4688
  callbacks.onToolCall(toolCall);
4583
4689
  }
4584
- const toolCallEvent = JSON.stringify({
4585
- type: "tool-call",
4586
- toolCallId: toolCall.id,
4587
- toolName: toolCall.name,
4588
- args: toolCall.args
4589
- });
4590
- controller.enqueue(encoder.encode(`data: ${toolCallEvent}
4591
-
4592
- `));
4593
4690
  const result = await executeTool(tc.name, toolCall.args, {
4594
4691
  agentId: this.id,
4595
4692
  ...toolContext
@@ -4598,10 +4695,13 @@ var AgentRuntime = class {
4598
4695
  toolCall.result = result;
4599
4696
  toolCall.executionTime = Date.now() - startTime;
4600
4697
  toolCalls.push(toolCall);
4698
+ const outputTool = toolRegistry.get(tc.name);
4699
+ const outputIsDynamic = outputTool?.type === "dynamic";
4601
4700
  const toolResultEvent = JSON.stringify({
4602
- type: "tool-result",
4701
+ type: "tool-output-available",
4603
4702
  toolCallId: toolCall.id,
4604
- result
4703
+ output: result,
4704
+ ...outputIsDynamic && { dynamic: true }
4605
4705
  });
4606
4706
  controller.enqueue(encoder.encode(`data: ${toolResultEvent}
4607
4707
 
@@ -4609,9 +4709,12 @@ var AgentRuntime = class {
4609
4709
  const toolResultMessage = {
4610
4710
  id: `tool_${tc.id}`,
4611
4711
  role: "tool",
4612
- content: JSON.stringify(result),
4613
- toolCallId: tc.id,
4614
- toolCall,
4712
+ parts: [{
4713
+ type: "tool-result",
4714
+ toolCallId: tc.id,
4715
+ toolName: tc.name,
4716
+ result
4717
+ }],
4615
4718
  timestamp: Date.now()
4616
4719
  };
4617
4720
  currentMessages.push(toolResultMessage);
@@ -4621,13 +4724,22 @@ var AgentRuntime = class {
4621
4724
  await recordToolError(toolCall, errorStr);
4622
4725
  }
4623
4726
  }
4727
+ const finishStepToolsEvent = JSON.stringify({ type: "finish-step" });
4728
+ controller.enqueue(encoder.encode(`data: ${finishStepToolsEvent}
4729
+
4730
+ `));
4624
4731
  this.status = "thinking";
4625
4732
  continue;
4626
4733
  }
4734
+ const finishStepEvent = JSON.stringify({ type: "finish-step" });
4735
+ controller.enqueue(encoder.encode(`data: ${finishStepEvent}
4736
+
4737
+ `));
4627
4738
  break;
4628
4739
  }
4740
+ const lastMessage = currentMessages[currentMessages.length - 1];
4629
4741
  return {
4630
- text: currentMessages[currentMessages.length - 1]?.content || "",
4742
+ text: lastMessage ? getTextFromParts(lastMessage.parts) : "",
4631
4743
  messages: currentMessages,
4632
4744
  toolCalls,
4633
4745
  status: "completed",
@@ -4703,7 +4815,7 @@ var AgentRuntime = class {
4703
4815
  return "You are a helpful AI assistant.";
4704
4816
  }
4705
4817
  /**
4706
- * Normalize input to messages array
4818
+ * Normalize input to messages array (v5 format with parts)
4707
4819
  */
4708
4820
  normalizeInput(input) {
4709
4821
  if (typeof input === "string") {
@@ -4711,7 +4823,7 @@ var AgentRuntime = class {
4711
4823
  {
4712
4824
  id: `msg_${Date.now()}`,
4713
4825
  role: "user",
4714
- content: input,
4826
+ parts: [{ type: "text", text: input }],
4715
4827
  timestamp: Date.now()
4716
4828
  }
4717
4829
  ];
@@ -4812,7 +4924,11 @@ ${compatibility.warnings.join("\n")}`
4812
4924
  return runtime.generate(input.input, input.context);
4813
4925
  },
4814
4926
  async stream(input) {
4815
- const inputMessages = input.input ? [{ role: "user", content: input.input }] : input.messages || [];
4927
+ const inputMessages = input.input ? [{
4928
+ id: `msg_${Date.now()}`,
4929
+ role: "user",
4930
+ parts: [{ type: "text", text: input.input }]
4931
+ }] : input.messages || [];
4816
4932
  const stream = await runtime.stream(inputMessages, input.context, {
4817
4933
  onToolCall: input.onToolCall,
4818
4934
  onChunk: input.onChunk
@@ -5035,6 +5151,7 @@ async function setupAI(options = {}) {
5035
5151
 
5036
5152
  // src/ai/mcp/server.ts
5037
5153
  var MCPServer = class {
5154
+ config;
5038
5155
  constructor(config) {
5039
5156
  this.config = config;
5040
5157
  }
@@ -5346,8 +5463,9 @@ import { anthropic } from "@ai-sdk/anthropic";
5346
5463
 
5347
5464
  // src/ai/production/rate-limit/limiter.ts
5348
5465
  var FixedWindowLimiter = class {
5466
+ requests = /* @__PURE__ */ new Map();
5467
+ config;
5349
5468
  constructor(config) {
5350
- this.requests = /* @__PURE__ */ new Map();
5351
5469
  this.config = config;
5352
5470
  }
5353
5471
  check(identifier) {
@@ -5388,8 +5506,10 @@ var FixedWindowLimiter = class {
5388
5506
  }
5389
5507
  };
5390
5508
  var TokenBucketLimiter = class {
5509
+ buckets = /* @__PURE__ */ new Map();
5510
+ config;
5511
+ refillRate;
5391
5512
  constructor(config) {
5392
- this.buckets = /* @__PURE__ */ new Map();
5393
5513
  this.config = config;
5394
5514
  this.refillRate = config.maxRequests / config.windowMs;
5395
5515
  }
@@ -5492,9 +5612,7 @@ function rateLimitMiddleware(config) {
5492
5612
 
5493
5613
  // src/ai/production/cache/cache.ts
5494
5614
  var MemoryCache = class {
5495
- constructor() {
5496
- this.cache = /* @__PURE__ */ new Map();
5497
- }
5615
+ cache = /* @__PURE__ */ new Map();
5498
5616
  set(key, response) {
5499
5617
  this.cache.set(key, {
5500
5618
  response,
@@ -5525,8 +5643,9 @@ var MemoryCache = class {
5525
5643
  }
5526
5644
  };
5527
5645
  var LRUCache = class {
5646
+ cache = /* @__PURE__ */ new Map();
5647
+ maxSize;
5528
5648
  constructor(maxSize = 100) {
5529
- this.cache = /* @__PURE__ */ new Map();
5530
5649
  this.maxSize = maxSize;
5531
5650
  }
5532
5651
  set(key, response) {
@@ -5570,9 +5689,10 @@ var LRUCache = class {
5570
5689
  }
5571
5690
  };
5572
5691
  var TTLCache = class {
5692
+ cache = /* @__PURE__ */ new Map();
5693
+ ttl;
5694
+ cleanupInterval = null;
5573
5695
  constructor(ttl = 3e5) {
5574
- this.cache = /* @__PURE__ */ new Map();
5575
- this.cleanupInterval = null;
5576
5696
  this.ttl = ttl;
5577
5697
  this.startCleanup();
5578
5698
  }
@@ -5726,13 +5846,14 @@ function cacheMiddleware(config) {
5726
5846
 
5727
5847
  // src/ai/production/cost-tracking/tracker.ts
5728
5848
  var CostTracker = class {
5849
+ records = [];
5850
+ config;
5851
+ dailyTotal = 0;
5852
+ monthlyTotal = 0;
5853
+ lastDayReset = Date.now();
5854
+ lastMonthReset = Date.now();
5855
+ resetInterval = null;
5729
5856
  constructor(config) {
5730
- this.records = [];
5731
- this.dailyTotal = 0;
5732
- this.monthlyTotal = 0;
5733
- this.lastDayReset = Date.now();
5734
- this.lastMonthReset = Date.now();
5735
- this.resetInterval = null;
5736
5857
  this.config = config;
5737
5858
  this.startPeriodicReset();
5738
5859
  }
@@ -5995,6 +6116,7 @@ var PII_PATTERNS = {
5995
6116
  creditCard: /\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/g
5996
6117
  };
5997
6118
  var InputValidator = class {
6119
+ config;
5998
6120
  constructor(config) {
5999
6121
  this.config = config || {};
6000
6122
  }
@@ -6054,6 +6176,7 @@ var InputValidator = class {
6054
6176
  }
6055
6177
  };
6056
6178
  var OutputFilter = class {
6179
+ config;
6057
6180
  constructor(config) {
6058
6181
  this.config = config || {};
6059
6182
  }
@@ -6327,12 +6450,13 @@ function hasLockSupport(backend) {
6327
6450
  // src/ai/workflow/backends/memory.ts
6328
6451
  var DEFAULT_MAX_QUEUE_SIZE = 1e4;
6329
6452
  var MemoryBackend = class {
6453
+ runs = /* @__PURE__ */ new Map();
6454
+ checkpoints = /* @__PURE__ */ new Map();
6455
+ approvals = /* @__PURE__ */ new Map();
6456
+ queue = [];
6457
+ locks = /* @__PURE__ */ new Map();
6458
+ config;
6330
6459
  constructor(config = {}) {
6331
- this.runs = /* @__PURE__ */ new Map();
6332
- this.checkpoints = /* @__PURE__ */ new Map();
6333
- this.approvals = /* @__PURE__ */ new Map();
6334
- this.queue = [];
6335
- this.locks = /* @__PURE__ */ new Map();
6336
6460
  this.config = {
6337
6461
  prefix: "wf:",
6338
6462
  debug: false,
@@ -6663,6 +6787,7 @@ var MemoryBackend = class {
6663
6787
 
6664
6788
  // src/ai/workflow/executor/dag-executor.ts
6665
6789
  var DAGExecutor = class {
6790
+ config;
6666
6791
  constructor(config) {
6667
6792
  this.config = {
6668
6793
  maxConcurrency: 10,
@@ -7204,6 +7329,7 @@ var DAGExecutor = class {
7204
7329
 
7205
7330
  // src/ai/workflow/executor/checkpoint-manager.ts
7206
7331
  var CheckpointManager = class {
7332
+ config;
7207
7333
  constructor(config) {
7208
7334
  this.config = {
7209
7335
  debug: false,
@@ -7361,6 +7487,7 @@ var CheckpointManager = class {
7361
7487
  // src/ai/workflow/executor/step-executor.ts
7362
7488
  var DEFAULT_STEP_TIMEOUT_MS = 5 * 60 * 1e3;
7363
7489
  var StepExecutor = class {
7490
+ config;
7364
7491
  constructor(config = {}) {
7365
7492
  this.config = {
7366
7493
  defaultTimeout: DEFAULT_STEP_TIMEOUT_MS,
@@ -7582,8 +7709,15 @@ var StepExecutor = class {
7582
7709
 
7583
7710
  // src/ai/workflow/executor/workflow-executor.ts
7584
7711
  var WorkflowExecutor = class _WorkflowExecutor {
7712
+ config;
7713
+ stepExecutor;
7714
+ checkpointManager;
7715
+ dagExecutor;
7716
+ workflows = /* @__PURE__ */ new Map();
7717
+ blobResolver;
7718
+ /** Default lock duration: 30 seconds */
7719
+ static DEFAULT_LOCK_DURATION = 3e4;
7585
7720
  constructor(config) {
7586
- this.workflows = /* @__PURE__ */ new Map();
7587
7721
  this.config = {
7588
7722
  maxConcurrency: 10,
7589
7723
  debug: false,
@@ -7619,10 +7753,6 @@ var WorkflowExecutor = class _WorkflowExecutor {
7619
7753
  };
7620
7754
  }
7621
7755
  }
7622
- static {
7623
- /** Default lock duration: 30 seconds */
7624
- this.DEFAULT_LOCK_DURATION = 3e4;
7625
- }
7626
7756
  /**
7627
7757
  * Register a workflow definition
7628
7758
  */
@@ -7977,8 +8107,10 @@ var WorkflowExecutor = class _WorkflowExecutor {
7977
8107
 
7978
8108
  // src/ai/workflow/runtime/approval-manager.ts
7979
8109
  var ApprovalManager = class {
8110
+ config;
8111
+ expirationTimer;
8112
+ destroyed = false;
7980
8113
  constructor(config) {
7981
- this.destroyed = false;
7982
8114
  this.config = {
7983
8115
  expirationCheckInterval: 6e4,
7984
8116
  // Check every minute
@@ -8205,6 +8337,10 @@ var ApprovalManager = class {
8205
8337
 
8206
8338
  // src/ai/workflow/api/workflow-client.ts
8207
8339
  var WorkflowClient = class {
8340
+ backend;
8341
+ executor;
8342
+ approvalManager;
8343
+ debug;
8208
8344
  constructor(config = {}) {
8209
8345
  this.debug = config.debug ?? false;
8210
8346
  this.backend = config.backend ?? new MemoryBackend({ debug: this.debug });
@@ -8413,6 +8549,7 @@ export {
8413
8549
  createWorkflowClient,
8414
8550
  detectPlatform,
8415
8551
  discoverAll,
8552
+ dynamicTool,
8416
8553
  embed,
8417
8554
  embedMany,
8418
8555
  experimental_createMCPClient,