@cydm/pie 2.8.0 → 2.8.1

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.
Files changed (30) hide show
  1. package/README.md +18 -0
  2. package/dist/builtin/extensions/ask-user/index.js +4 -3
  3. package/dist/builtin/extensions/cron/index.js +265 -31
  4. package/dist/builtin/extensions/im-forward/index.js +13 -2
  5. package/dist/builtin/extensions/memory/index.js +275 -83
  6. package/dist/builtin/extensions/memory/package.json +2 -1
  7. package/dist/builtin/extensions/plan-mode/index.js +4 -3
  8. package/dist/builtin/extensions/subagent/index.js +6 -5
  9. package/dist/builtin/extensions/todo/index.js +4 -3
  10. package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +6 -1
  11. package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +6 -1
  12. package/dist/chunks/auth-storage-3EGM3VTK.js +13 -0
  13. package/dist/chunks/{chunk-JNOFHHLZ.js → chunk-3BC5KGDQ.js} +383 -185
  14. package/dist/chunks/chunk-3NHP7HK5.js +298 -0
  15. package/dist/chunks/chunk-6DNYGVZP.js +278 -0
  16. package/dist/chunks/{chunk-NEES4EBX.js → chunk-GDIYSMTS.js} +6 -4
  17. package/dist/chunks/{chunk-HGC25NYB.js → chunk-GH4VW2OT.js} +1 -1
  18. package/dist/chunks/{chunk-5353DEEC.js → chunk-ILUHTKF3.js} +20 -1
  19. package/dist/chunks/{chunk-LJXHECZ7.js → chunk-PK72LVWQ.js} +13867 -19759
  20. package/dist/chunks/chunk-RSL7E4R7.js +9634 -0
  21. package/dist/chunks/chunk-YRR6C43W.js +1740 -0
  22. package/dist/chunks/config-74AUVDLT.js +46 -0
  23. package/dist/chunks/model-registry-LI5THXV4.js +17 -0
  24. package/dist/chunks/src-66XSMIAM.js +134 -0
  25. package/dist/chunks/src-BPSQMSSC.js +431 -0
  26. package/dist/chunks/src-OPPYTPWG.js +285 -0
  27. package/dist/chunks/{src-5XOKRS6F.js → src-YG5M2H44.js} +2 -2
  28. package/dist/chunks/{test-stream-5SDHKKDB.js → test-stream-JBWXKOQA.js} +1 -1
  29. package/dist/cli.js +970 -2283
  30. package/package.json +2 -2
@@ -285,125 +285,6 @@ var require_dist = __commonJS({
285
285
  }
286
286
  });
287
287
 
288
- // ../../packages/ai/src/utils/event-stream.ts
289
- var EventStream = class {
290
- constructor(isComplete, extractResult) {
291
- this.isComplete = isComplete;
292
- this.extractResult = extractResult;
293
- this.finalResultPromise = new Promise((resolve) => {
294
- this.resolveFinalResult = resolve;
295
- });
296
- }
297
- isComplete;
298
- extractResult;
299
- queue = [];
300
- waiting = [];
301
- done = false;
302
- resultResolved = false;
303
- finalResultPromise;
304
- resolveFinalResult;
305
- push(event) {
306
- if (this.done) return;
307
- if (this.isComplete(event)) {
308
- this.done = true;
309
- if (!this.resultResolved) {
310
- this.resultResolved = true;
311
- this.resolveFinalResult(this.extractResult(event));
312
- }
313
- }
314
- const waiter = this.waiting.shift();
315
- if (waiter) {
316
- waiter({ value: event, done: false });
317
- } else {
318
- this.queue.push(event);
319
- }
320
- }
321
- end(result) {
322
- this.done = true;
323
- if (result !== void 0 && !this.resultResolved) {
324
- this.resultResolved = true;
325
- this.resolveFinalResult(result);
326
- }
327
- while (this.waiting.length > 0) {
328
- const waiter = this.waiting.shift();
329
- waiter({ value: void 0, done: true });
330
- }
331
- }
332
- async *[Symbol.asyncIterator]() {
333
- while (true) {
334
- if (this.queue.length > 0) {
335
- yield this.queue.shift();
336
- } else if (this.done) {
337
- return;
338
- } else {
339
- const result = await new Promise((resolve) => this.waiting.push(resolve));
340
- if (result.done) return;
341
- yield result.value;
342
- }
343
- }
344
- }
345
- result() {
346
- return this.finalResultPromise;
347
- }
348
- };
349
- var AssistantMessageEventStream = class extends EventStream {
350
- constructor() {
351
- super(
352
- (event) => event.type === "done" || event.type === "error",
353
- (event) => {
354
- if (event.type === "done") {
355
- return event.message;
356
- } else if (event.type === "error") {
357
- return event.error;
358
- }
359
- throw new Error("Unexpected event type for final result");
360
- }
361
- );
362
- }
363
- };
364
-
365
- // ../../packages/ai/src/api-registry.ts
366
- var apiProviderRegistry = /* @__PURE__ */ new Map();
367
- function registerApiProvider(provider) {
368
- apiProviderRegistry.set(provider.api, {
369
- api: provider.api,
370
- stream: (model, context, options) => provider.stream(model, context, options),
371
- streamSimple: (model, context, options) => provider.streamSimple(model, context, options)
372
- });
373
- }
374
- function getApiProvider(api) {
375
- return apiProviderRegistry.get(api);
376
- }
377
-
378
- // ../../packages/ai/src/env-api-keys.ts
379
- function getEnvApiKey(provider, explicitEnvVar) {
380
- void provider;
381
- const env = typeof process !== "undefined" ? process.env : {};
382
- const explicitEnv = explicitEnvVar;
383
- if (explicitEnv) {
384
- const value = env[explicitEnv];
385
- if (value) return value;
386
- }
387
- return void 0;
388
- }
389
-
390
- // ../../packages/ai/src/stream.ts
391
- function resolveApiProvider(api) {
392
- const provider = getApiProvider(api);
393
- if (!provider) {
394
- throw new Error(`No API provider registered for api: ${api}`);
395
- }
396
- return provider;
397
- }
398
- function streamSimple(model, context, options) {
399
- const provider = resolveApiProvider(model.api);
400
- return provider.streamSimple(model, context, options);
401
- }
402
- async function completeSimple(model, context, options) {
403
- const s = streamSimple(model, context, options);
404
- return s.result();
405
- }
406
-
407
288
  // ../../node_modules/@sinclair/typebox/build/esm/type/registry/format.mjs
408
289
  var format_exports = {};
409
290
  __export(format_exports, {
@@ -485,7 +366,107 @@ function ExtendsUndefinedCheck(schema) {
485
366
  return schema[Kind] === "Intersect" ? Intersect(schema) : schema[Kind] === "Union" ? Union2(schema) : schema[Kind] === "Not" ? Not(schema) : schema[Kind] === "Undefined" ? true : false;
486
367
  }
487
368
 
369
+ // ../../packages/ai/src/api-registry.ts
370
+ var apiProviderRegistry = /* @__PURE__ */ new Map();
371
+ function registerApiProvider(provider) {
372
+ apiProviderRegistry.set(provider.api, {
373
+ api: provider.api,
374
+ stream: (model, context, options) => provider.stream(model, context, options),
375
+ streamSimple: (model, context, options) => provider.streamSimple(model, context, options)
376
+ });
377
+ }
378
+ function getApiProvider(api) {
379
+ return apiProviderRegistry.get(api);
380
+ }
381
+ function getApiProviders() {
382
+ return Array.from(apiProviderRegistry.values());
383
+ }
384
+ function clearApiProviders() {
385
+ apiProviderRegistry.clear();
386
+ }
387
+
388
+ // ../../packages/ai/src/env-api-keys.ts
389
+ function getProviderEnvVar(provider) {
390
+ return `${provider.toUpperCase().replace(/[^A-Z0-9]+/gi, "_")}_API_KEY`;
391
+ }
392
+ function getEnvApiKey(provider, explicitEnvVar) {
393
+ void provider;
394
+ const env = typeof process !== "undefined" ? process.env : {};
395
+ const explicitEnv = explicitEnvVar;
396
+ if (explicitEnv) {
397
+ const value = env[explicitEnv];
398
+ if (value) return value;
399
+ }
400
+ return void 0;
401
+ }
402
+
403
+ // ../../packages/ai/src/models.builtins.ts
404
+ var BUILTIN_MODEL_DEFINITIONS = {};
405
+ function getBuiltInModels() {
406
+ return [];
407
+ }
408
+
488
409
  // ../../packages/ai/src/models.ts
410
+ var modelRegistry = /* @__PURE__ */ new Map();
411
+ function getModel(provider, modelId) {
412
+ const providerModels = modelRegistry.get(provider);
413
+ const model = providerModels?.get(modelId);
414
+ if (!model) {
415
+ throw new Error(`Model "${modelId}" not found for provider "${provider}". Available: ${listAvailableModels().join(", ") || "(none)"}`);
416
+ }
417
+ return model;
418
+ }
419
+ function registerModel(model) {
420
+ let providerModels = modelRegistry.get(model.provider);
421
+ if (!providerModels) {
422
+ providerModels = /* @__PURE__ */ new Map();
423
+ modelRegistry.set(model.provider, providerModels);
424
+ }
425
+ providerModels.set(model.id, model);
426
+ }
427
+ function registerModels(models) {
428
+ for (const model of models) {
429
+ registerModel(model);
430
+ }
431
+ }
432
+ function unregisterModel(provider, modelId) {
433
+ const providerModels = modelRegistry.get(provider);
434
+ if (!providerModels) return false;
435
+ const deleted = providerModels.delete(modelId);
436
+ if (providerModels.size === 0) {
437
+ modelRegistry.delete(provider);
438
+ }
439
+ return deleted;
440
+ }
441
+ function getProviders() {
442
+ return Array.from(modelRegistry.keys());
443
+ }
444
+ function getModels(provider) {
445
+ const models = modelRegistry.get(provider);
446
+ return models ? Array.from(models.values()) : [];
447
+ }
448
+ function getAllModels() {
449
+ const all = [];
450
+ for (const providerModels of modelRegistry.values()) {
451
+ all.push(...providerModels.values());
452
+ }
453
+ return all;
454
+ }
455
+ function listAvailableModels() {
456
+ const ids = [];
457
+ for (const [provider, models] of modelRegistry) {
458
+ for (const modelId of models.keys()) {
459
+ ids.push(`${provider}/${modelId}`);
460
+ }
461
+ }
462
+ return ids.sort();
463
+ }
464
+ function hasModel(provider, modelId) {
465
+ return modelRegistry.get(provider)?.has(modelId) ?? false;
466
+ }
467
+ function clearModels() {
468
+ modelRegistry.clear();
469
+ }
489
470
  function calculateCost(model, usage) {
490
471
  const input = model.cost.input / 1e6 * usage.input;
491
472
  const output = model.cost.output / 1e6 * usage.output;
@@ -507,6 +488,129 @@ function calculateCost(model, usage) {
507
488
  total: input + output + cacheRead + cacheWrite + cacheWriteLong
508
489
  };
509
490
  }
491
+ function createModel(id, config) {
492
+ return {
493
+ id,
494
+ ...config
495
+ };
496
+ }
497
+ function registerDefaultModels() {
498
+ registerModels(getBuiltInModels());
499
+ }
500
+ function registerModelsFromConfig(config) {
501
+ const apiKeys = /* @__PURE__ */ new Map();
502
+ const configuredProfiles = config.profiles || {};
503
+ for (const [providerName, providerConfig] of Object.entries(configuredProfiles)) {
504
+ if (providerConfig.apiKey) {
505
+ apiKeys.set(providerName, providerConfig.apiKey);
506
+ }
507
+ for (const modelDef of providerConfig.models) {
508
+ const model = {
509
+ id: modelDef.id,
510
+ name: modelDef.name,
511
+ api: providerConfig.api,
512
+ provider: providerName,
513
+ baseUrl: providerConfig.baseUrl,
514
+ reasoning: modelDef.reasoning,
515
+ input: modelDef.input,
516
+ cost: modelDef.cost,
517
+ contextWindow: modelDef.contextWindow,
518
+ maxTokens: modelDef.maxTokens,
519
+ apiKeyEnv: modelDef.apiKeyEnv || providerConfig.apiKeyEnv,
520
+ displayName: modelDef.displayName || providerConfig.displayName,
521
+ filePlatform: modelDef.filePlatform || providerConfig.filePlatform,
522
+ attachmentPlatform: modelDef.attachmentPlatform || providerConfig.attachmentPlatform,
523
+ headers: providerConfig.headers ? { ...providerConfig.headers, ...modelDef.headers } : modelDef.headers,
524
+ compat: modelDef.compat,
525
+ cacheCapability: modelDef.cacheCapability,
526
+ webSearch: modelDef.webSearch || providerConfig.webSearch,
527
+ fileCapabilities: modelDef.fileCapabilities || providerConfig.fileCapabilities
528
+ };
529
+ registerModel(model);
530
+ }
531
+ }
532
+ return apiKeys;
533
+ }
534
+
535
+ // ../../packages/ai/src/utils/event-stream.ts
536
+ var EventStream = class {
537
+ constructor(isComplete, extractResult) {
538
+ this.isComplete = isComplete;
539
+ this.extractResult = extractResult;
540
+ this.finalResultPromise = new Promise((resolve) => {
541
+ this.resolveFinalResult = resolve;
542
+ });
543
+ }
544
+ isComplete;
545
+ extractResult;
546
+ queue = [];
547
+ waiting = [];
548
+ done = false;
549
+ resultResolved = false;
550
+ finalResultPromise;
551
+ resolveFinalResult;
552
+ push(event) {
553
+ if (this.done) return;
554
+ if (this.isComplete(event)) {
555
+ this.done = true;
556
+ if (!this.resultResolved) {
557
+ this.resultResolved = true;
558
+ this.resolveFinalResult(this.extractResult(event));
559
+ }
560
+ }
561
+ const waiter = this.waiting.shift();
562
+ if (waiter) {
563
+ waiter({ value: event, done: false });
564
+ } else {
565
+ this.queue.push(event);
566
+ }
567
+ }
568
+ end(result) {
569
+ this.done = true;
570
+ if (result !== void 0 && !this.resultResolved) {
571
+ this.resultResolved = true;
572
+ this.resolveFinalResult(result);
573
+ }
574
+ while (this.waiting.length > 0) {
575
+ const waiter = this.waiting.shift();
576
+ waiter({ value: void 0, done: true });
577
+ }
578
+ }
579
+ async *[Symbol.asyncIterator]() {
580
+ while (true) {
581
+ if (this.queue.length > 0) {
582
+ yield this.queue.shift();
583
+ } else if (this.done) {
584
+ return;
585
+ } else {
586
+ const result = await new Promise((resolve) => this.waiting.push(resolve));
587
+ if (result.done) return;
588
+ yield result.value;
589
+ }
590
+ }
591
+ }
592
+ result() {
593
+ return this.finalResultPromise;
594
+ }
595
+ };
596
+ var AssistantMessageEventStream = class extends EventStream {
597
+ constructor() {
598
+ super(
599
+ (event) => event.type === "done" || event.type === "error",
600
+ (event) => {
601
+ if (event.type === "done") {
602
+ return event.message;
603
+ } else if (event.type === "error") {
604
+ return event.error;
605
+ }
606
+ throw new Error("Unexpected event type for final result");
607
+ }
608
+ );
609
+ }
610
+ };
611
+ function createAssistantMessageEventStream() {
612
+ return new AssistantMessageEventStream();
613
+ }
510
614
 
511
615
  // ../../packages/platform/src/text-hash.ts
512
616
  function createTextHasher() {
@@ -1215,11 +1319,11 @@ var NodeFileSystem = class {
1215
1319
  lastCharWasNewline = char === "\n";
1216
1320
  }
1217
1321
  };
1218
- const stream = fs.createReadStream(path);
1322
+ const stream2 = fs.createReadStream(path);
1219
1323
  try {
1220
- for await (const chunk of stream) {
1324
+ for await (const chunk of stream2) {
1221
1325
  if (signal?.aborted) {
1222
- stream.destroy();
1326
+ stream2.destroy();
1223
1327
  throw new Error("Operation aborted");
1224
1328
  }
1225
1329
  const bytes = chunk;
@@ -1229,7 +1333,7 @@ var NodeFileSystem = class {
1229
1333
  scanText(textDecoder.decode());
1230
1334
  finishLine();
1231
1335
  } finally {
1232
- stream.destroy();
1336
+ stream2.destroy();
1233
1337
  }
1234
1338
  return {
1235
1339
  content: outputLines.join("\n"),
@@ -1312,11 +1416,11 @@ var NodeFileSystem = class {
1312
1416
  lastCharWasNewline = char === "\n";
1313
1417
  }
1314
1418
  };
1315
- const stream = fs.createReadStream(path);
1419
+ const stream2 = fs.createReadStream(path);
1316
1420
  try {
1317
- for await (const chunk of stream) {
1421
+ for await (const chunk of stream2) {
1318
1422
  if (signal?.aborted) {
1319
- stream.destroy();
1423
+ stream2.destroy();
1320
1424
  throw new Error("Operation aborted");
1321
1425
  }
1322
1426
  const bytes = chunk;
@@ -1325,7 +1429,7 @@ var NodeFileSystem = class {
1325
1429
  }
1326
1430
  scanText(textDecoder.decode());
1327
1431
  } finally {
1328
- stream.destroy();
1432
+ stream2.destroy();
1329
1433
  }
1330
1434
  if (lastCharWasNewline) {
1331
1435
  totalLines++;
@@ -2660,9 +2764,9 @@ var NodeHttpClient = class {
2660
2764
  });
2661
2765
  }
2662
2766
  };
2663
- function scheduleNextTick(callback, _delayMs) {
2767
+ function scheduleNextTick(callback) {
2664
2768
  if (typeof setTimeout === "function") {
2665
- setTimeout(callback, _delayMs);
2769
+ setTimeout(callback, 0);
2666
2770
  return;
2667
2771
  }
2668
2772
  Promise.resolve().then(callback);
@@ -2675,7 +2779,6 @@ var PuerTSHttpClient = class {
2675
2779
  url: url.slice(0, 100),
2676
2780
  method: options.method || "GET"
2677
2781
  });
2678
- void scheduleNextTick;
2679
2782
  let legacyBridge = false;
2680
2783
  try {
2681
2784
  legacyBridge = typeof CS !== "undefined" && !!CS?.AgentBridge && typeof CS.AgentBridge.HttpPostAsyncStart === "function";
@@ -2854,7 +2957,7 @@ var PuerTSHttpClient = class {
2854
2957
  void completed.then(() => checkComplete());
2855
2958
  }
2856
2959
  };
2857
- scheduleNextTick(checkComplete, 0);
2960
+ scheduleNextTick(checkComplete);
2858
2961
  });
2859
2962
  }
2860
2963
  };
@@ -3480,6 +3583,13 @@ var FileSystemGateway = class {
3480
3583
  return this.config;
3481
3584
  }
3482
3585
  };
3586
+ var gatewayInstance = null;
3587
+ function getFileSystemGateway(options) {
3588
+ if (!gatewayInstance) {
3589
+ gatewayInstance = new FileSystemGateway(options);
3590
+ }
3591
+ return gatewayInstance;
3592
+ }
3483
3593
  function csharpStringArray(value) {
3484
3594
  if (Array.isArray(value)) {
3485
3595
  return value.map((entry) => String(entry ?? ""));
@@ -3999,6 +4109,9 @@ function getModelCacheCapability(model) {
3999
4109
  function isPromptCacheCapability(capability) {
4000
4110
  return capability.mode === "prompt_cache";
4001
4111
  }
4112
+ function isSessionStoreCapability(capability) {
4113
+ return capability.mode === "session_store";
4114
+ }
4002
4115
 
4003
4116
  // ../../packages/ai/src/providers/openai-compat-config.ts
4004
4117
  function detectCompat(_model) {
@@ -4547,7 +4660,7 @@ function tryParseFinalToolArguments(partialArgs) {
4547
4660
  }
4548
4661
  var streamOpenAICompletions = (model, context, options) => {
4549
4662
  if ((options?.transport ?? model.transport) === "websocket") throw new Error(`API ${model.api} does not support WebSocket transport.`);
4550
- const stream = new AssistantMessageEventStream();
4663
+ const stream2 = new AssistantMessageEventStream();
4551
4664
  (async () => {
4552
4665
  const output = {
4553
4666
  role: "assistant",
@@ -4601,7 +4714,7 @@ var streamOpenAICompletions = (model, context, options) => {
4601
4714
  const errorBody = await response.text().catch(() => "");
4602
4715
  throw new Error(`API error ${response.status}: ${errorBody}`);
4603
4716
  }
4604
- stream.push({ type: "start", partial: output });
4717
+ stream2.push({ type: "start", partial: output });
4605
4718
  let currentBlock = null;
4606
4719
  const blocks = output.content;
4607
4720
  const blockIndex = () => blocks.length - 1;
@@ -4622,7 +4735,7 @@ var streamOpenAICompletions = (model, context, options) => {
4622
4735
  output.content.push(block);
4623
4736
  const entry = { block, partialArgs: "", contentIndex: blockIndex(), index };
4624
4737
  toolCallEntries.push(entry);
4625
- stream.push({
4738
+ stream2.push({
4626
4739
  type: "toolcall_start",
4627
4740
  contentIndex: entry.contentIndex,
4628
4741
  partial: output
@@ -4696,14 +4809,14 @@ var streamOpenAICompletions = (model, context, options) => {
4696
4809
  const finishCurrentBlock = (block) => {
4697
4810
  if (block) {
4698
4811
  if (block.type === "text") {
4699
- stream.push({
4812
+ stream2.push({
4700
4813
  type: "text_end",
4701
4814
  contentIndex: blocks.indexOf(block),
4702
4815
  content: block.text,
4703
4816
  partial: output
4704
4817
  });
4705
4818
  } else if (block.type === "thinking") {
4706
- stream.push({
4819
+ stream2.push({
4707
4820
  type: "thinking_end",
4708
4821
  contentIndex: blocks.indexOf(block),
4709
4822
  content: block.thinking,
@@ -4769,7 +4882,7 @@ var streamOpenAICompletions = (model, context, options) => {
4769
4882
  finishCurrentBlock(currentBlock);
4770
4883
  currentBlock = { type: "text", text: "" };
4771
4884
  output.content.push(currentBlock);
4772
- stream.push({
4885
+ stream2.push({
4773
4886
  type: "text_start",
4774
4887
  contentIndex: blockIndex(),
4775
4888
  partial: output
@@ -4777,7 +4890,7 @@ var streamOpenAICompletions = (model, context, options) => {
4777
4890
  }
4778
4891
  if (currentBlock.type === "text") {
4779
4892
  currentBlock.text += choice.delta.content;
4780
- stream.push({
4893
+ stream2.push({
4781
4894
  type: "text_delta",
4782
4895
  contentIndex: blockIndex(),
4783
4896
  delta: choice.delta.content,
@@ -4806,7 +4919,7 @@ var streamOpenAICompletions = (model, context, options) => {
4806
4919
  thinkingSignature: foundReasoningField
4807
4920
  };
4808
4921
  output.content.push(currentBlock);
4809
- stream.push({
4922
+ stream2.push({
4810
4923
  type: "thinking_start",
4811
4924
  contentIndex: blockIndex(),
4812
4925
  partial: output
@@ -4815,7 +4928,7 @@ var streamOpenAICompletions = (model, context, options) => {
4815
4928
  if (currentBlock.type === "thinking") {
4816
4929
  const delta = choice.delta[foundReasoningField];
4817
4930
  currentBlock.thinking += delta;
4818
- stream.push({
4931
+ stream2.push({
4819
4932
  type: "thinking_delta",
4820
4933
  contentIndex: blockIndex(),
4821
4934
  delta,
@@ -4843,7 +4956,7 @@ var streamOpenAICompletions = (model, context, options) => {
4843
4956
  entry.partialArgs += delta;
4844
4957
  entry.block.arguments = parseStreamingJson(entry.partialArgs);
4845
4958
  }
4846
- stream.push({
4959
+ stream2.push({
4847
4960
  type: "toolcall_delta",
4848
4961
  contentIndex: entry.contentIndex,
4849
4962
  delta,
@@ -4942,7 +5055,7 @@ ${entry.partialArgs}`;
4942
5055
  throw createProtocolError("OpenAI-compatible stream returned a tool call without a function name.");
4943
5056
  }
4944
5057
  block.arguments = parseFinalToolArguments(partialArgs, block.name);
4945
- stream.push({ type: "toolcall_end", contentIndex, toolCall: block, partial: output });
5058
+ stream2.push({ type: "toolcall_end", contentIndex, toolCall: block, partial: output });
4946
5059
  }
4947
5060
  const hasToolCallBlocks = output.content.some((block) => block.type === "toolCall");
4948
5061
  if (output.stopReason !== "error" && output.stopReason !== "aborted" && hasToolCallBlocks) {
@@ -4958,8 +5071,8 @@ ${entry.partialArgs}`;
4958
5071
  }
4959
5072
  assertAssistantHasContent(output);
4960
5073
  resetOpenAICompatFirstByteTimeoutEscalation(model);
4961
- stream.push({ type: "done", reason: output.stopReason, message: output });
4962
- stream.end();
5074
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
5075
+ stream2.end();
4963
5076
  } catch (error) {
4964
5077
  logEmptyAssistantContentError(error, model, options);
4965
5078
  if (error instanceof Error && error.message.includes("Request timeout (first byte)")) {
@@ -4967,11 +5080,11 @@ ${entry.partialArgs}`;
4967
5080
  }
4968
5081
  output.stopReason = options?.signal?.aborted ? "aborted" : "error";
4969
5082
  output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
4970
- stream.push({ type: "error", reason: output.stopReason, error: output });
4971
- stream.end();
5083
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
5084
+ stream2.end();
4972
5085
  }
4973
5086
  })();
4974
- return stream;
5087
+ return stream2;
4975
5088
  };
4976
5089
  var streamSimpleOpenAICompletions = (model, context, options) => {
4977
5090
  const apiKey = options?.apiKey || getEnvApiKey(model.provider, model.apiKeyEnv);
@@ -5252,7 +5365,7 @@ function applyCacheBreakpoints(params, retention) {
5252
5365
  }
5253
5366
  var streamAnthropic = (model, context, options) => {
5254
5367
  if ((options?.transport ?? model.transport) === "websocket") throw new Error(`API ${model.api} does not support WebSocket transport.`);
5255
- const stream = new AssistantMessageEventStream();
5368
+ const stream2 = new AssistantMessageEventStream();
5256
5369
  (async () => {
5257
5370
  const output = {
5258
5371
  role: "assistant",
@@ -5319,7 +5432,7 @@ var streamAnthropic = (model, context, options) => {
5319
5432
  }
5320
5433
  options?.onPayload?.(params);
5321
5434
  const anthropicStream = client.messages.stream({ ...params, stream: true }, { signal: options?.signal });
5322
- stream.push({ type: "start", partial: output });
5435
+ stream2.push({ type: "start", partial: output });
5323
5436
  const blocks = output.content;
5324
5437
  let hasReportedInputUsage = false;
5325
5438
  for await (const event of anthropicStream) {
@@ -5331,11 +5444,11 @@ var streamAnthropic = (model, context, options) => {
5331
5444
  if (event.content_block.type === "text") {
5332
5445
  const block = { type: "text", text: "", index: event.index };
5333
5446
  output.content.push(block);
5334
- stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
5447
+ stream2.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
5335
5448
  } else if (event.content_block.type === "thinking") {
5336
5449
  const block = { type: "thinking", thinking: "", thinkingSignature: "", index: event.index };
5337
5450
  output.content.push(block);
5338
- stream.push({
5451
+ stream2.push({
5339
5452
  type: "thinking_start",
5340
5453
  contentIndex: output.content.length - 1,
5341
5454
  partial: output
@@ -5350,7 +5463,7 @@ var streamAnthropic = (model, context, options) => {
5350
5463
  index: event.index
5351
5464
  };
5352
5465
  output.content.push(block);
5353
- stream.push({
5466
+ stream2.push({
5354
5467
  type: "toolcall_start",
5355
5468
  contentIndex: output.content.length - 1,
5356
5469
  partial: output
@@ -5362,14 +5475,14 @@ var streamAnthropic = (model, context, options) => {
5362
5475
  const block = blocks[index];
5363
5476
  if (block?.type === "text") {
5364
5477
  block.text += event.delta.text;
5365
- stream.push({ type: "text_delta", contentIndex: index, delta: event.delta.text, partial: output });
5478
+ stream2.push({ type: "text_delta", contentIndex: index, delta: event.delta.text, partial: output });
5366
5479
  }
5367
5480
  } else if (event.delta.type === "thinking_delta") {
5368
5481
  const index = blocks.findIndex((b) => b.index === event.index);
5369
5482
  const block = blocks[index];
5370
5483
  if (block?.type === "thinking") {
5371
5484
  block.thinking += event.delta.thinking;
5372
- stream.push({
5485
+ stream2.push({
5373
5486
  type: "thinking_delta",
5374
5487
  contentIndex: index,
5375
5488
  delta: event.delta.thinking,
@@ -5382,7 +5495,7 @@ var streamAnthropic = (model, context, options) => {
5382
5495
  if (block?.type === "toolCall") {
5383
5496
  block.partialJson += event.delta.partial_json;
5384
5497
  block.arguments = parseStreamingJson(block.partialJson);
5385
- stream.push({
5498
+ stream2.push({
5386
5499
  type: "toolcall_delta",
5387
5500
  contentIndex: index,
5388
5501
  delta: event.delta.partial_json,
@@ -5402,14 +5515,14 @@ var streamAnthropic = (model, context, options) => {
5402
5515
  if (block) {
5403
5516
  delete block.index;
5404
5517
  if (block.type === "text") {
5405
- stream.push({
5518
+ stream2.push({
5406
5519
  type: "text_end",
5407
5520
  contentIndex: index,
5408
5521
  content: block.text,
5409
5522
  partial: output
5410
5523
  });
5411
5524
  } else if (block.type === "thinking") {
5412
- stream.push({
5525
+ stream2.push({
5413
5526
  type: "thinking_end",
5414
5527
  contentIndex: index,
5415
5528
  content: block.thinking,
@@ -5418,7 +5531,7 @@ var streamAnthropic = (model, context, options) => {
5418
5531
  } else if (block.type === "toolCall") {
5419
5532
  block.arguments = parseStreamingJson(block.partialJson);
5420
5533
  delete block.partialJson;
5421
- stream.push({
5534
+ stream2.push({
5422
5535
  type: "toolcall_end",
5423
5536
  contentIndex: index,
5424
5537
  toolCall: block,
@@ -5438,18 +5551,18 @@ var streamAnthropic = (model, context, options) => {
5438
5551
  throw new Error("Request was aborted");
5439
5552
  }
5440
5553
  assertAssistantHasContent(output);
5441
- stream.push({ type: "done", reason: output.stopReason, message: output });
5442
- stream.end();
5554
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
5555
+ stream2.end();
5443
5556
  } catch (error) {
5444
5557
  logEmptyAssistantContentError(error, model, options);
5445
5558
  for (const block of output.content) delete block.index;
5446
5559
  output.stopReason = options?.signal?.aborted ? "aborted" : "error";
5447
5560
  output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
5448
- stream.push({ type: "error", reason: output.stopReason, error: output });
5449
- stream.end();
5561
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
5562
+ stream2.end();
5450
5563
  }
5451
5564
  })();
5452
- return stream;
5565
+ return stream2;
5453
5566
  };
5454
5567
  var streamSimpleAnthropic = (model, context, options) => {
5455
5568
  const apiKey = options?.apiKey || getEnvApiKey(model.provider, model.apiKeyEnv);
@@ -5564,13 +5677,16 @@ function encodeUserMessage(content, model) {
5564
5677
  }
5565
5678
  return { role: "user", type: "message", content: parts };
5566
5679
  }
5680
+ function omittedAttachmentNote(modality, reason) {
5681
+ return { type: "input_text", text: `[${modality} attachment omitted: ${reason} Re-read with a compatible model.]` };
5682
+ }
5567
5683
  function encodeUserContentBlock(block, model) {
5568
5684
  if (block.type === "hostContext") {
5569
5685
  throw new ResponsesProtocolError(`Unprojected hostContext block reached Responses conversion (${block.kind}); the request path must project host envelopes to text first.`);
5570
5686
  }
5571
5687
  const modality = block.type === "fileRef" ? block.modality : block.type;
5572
5688
  if (modality !== "text" && !model.input.includes(modality)) {
5573
- throw new ResponsesProtocolError(`Current model does not support ${modality} input.`);
5689
+ return [omittedAttachmentNote(modality, "current model does not support this modality.")];
5574
5690
  }
5575
5691
  switch (block.type) {
5576
5692
  case "text":
@@ -5579,13 +5695,13 @@ function encodeUserContentBlock(block, model) {
5579
5695
  return [{ type: "input_image", image_url: `data:${block.mimeType};base64,${block.data}` }];
5580
5696
  case "video":
5581
5697
  case "audio":
5582
- throw new ResponsesProtocolError(`Responses ${block.type} input is not supported by this provider.`);
5698
+ return [omittedAttachmentNote(block.type, `the Responses provider does not deliver ${block.type} input.`)];
5583
5699
  case "fileRef": {
5584
5700
  const ref = block;
5585
5701
  if (ref.modality === "image") {
5586
5702
  return [{ type: "input_image", image_url: ref.url }];
5587
5703
  }
5588
- throw new ResponsesProtocolError(`Responses ${ref.modality} file references are not supported by this provider.`);
5704
+ return [omittedAttachmentNote(ref.modality, `the Responses provider does not deliver ${ref.modality} file references.`)];
5589
5705
  }
5590
5706
  default:
5591
5707
  throw new ResponsesProtocolError("Unsupported Responses content block.");
@@ -6346,7 +6462,7 @@ function resolveSSEBudgets(options, model) {
6346
6462
  };
6347
6463
  }
6348
6464
  function streamResponsesSSE(model, context, options) {
6349
- const stream = new AssistantMessageEventStream();
6465
+ const stream2 = new AssistantMessageEventStream();
6350
6466
  void (async () => {
6351
6467
  const reducer = new ResponsesEventReducer(model);
6352
6468
  const localRequestId = nextLocalRequestId("sse");
@@ -6534,7 +6650,7 @@ function streamResponsesSSE(model, context, options) {
6534
6650
  throw error;
6535
6651
  }
6536
6652
  for (const assistantEvent of events) {
6537
- stream.push(assistantEvent);
6653
+ stream2.push(assistantEvent);
6538
6654
  }
6539
6655
  if (reducer.isTerminal) {
6540
6656
  terminalAccepted = true;
@@ -6545,7 +6661,7 @@ function streamResponsesSSE(model, context, options) {
6545
6661
  }
6546
6662
  }
6547
6663
  if (reducer.isTerminal) {
6548
- stream.end();
6664
+ stream2.end();
6549
6665
  return;
6550
6666
  }
6551
6667
  if (requestAbort.signal.aborted) {
@@ -6555,7 +6671,7 @@ function streamResponsesSSE(model, context, options) {
6555
6671
  throw reducer.finishWithoutTerminal();
6556
6672
  } catch (error) {
6557
6673
  if (reducer.isTerminal) {
6558
- stream.end();
6674
+ stream2.end();
6559
6675
  return;
6560
6676
  }
6561
6677
  const message = reducer.message;
@@ -6591,14 +6707,14 @@ function streamResponsesSSE(model, context, options) {
6591
6707
  cancelSource: userAborted ? "user" : internalTimeout ? "internal_timeout" : "none",
6592
6708
  cleanupOutcome: "request_abandoned"
6593
6709
  });
6594
- stream.push({ type: "error", reason: message.stopReason, error: message });
6595
- stream.end();
6710
+ stream2.push({ type: "error", reason: message.stopReason, error: message });
6711
+ stream2.end();
6596
6712
  } finally {
6597
6713
  clearTotalTimer();
6598
6714
  options?.signal?.removeEventListener("abort", onUserAbort);
6599
6715
  }
6600
6716
  })();
6601
- return stream;
6717
+ return stream2;
6602
6718
  }
6603
6719
 
6604
6720
  // ../../packages/ai/src/providers/responses/responses-continuation.ts
@@ -6806,7 +6922,7 @@ function websocketUrl(base) {
6806
6922
  return `${url.protocol === "https:" ? "wss:" : "ws:"}${url.toString().slice(url.protocol.length)}`;
6807
6923
  }
6808
6924
  function streamResponsesWS(model, context, options) {
6809
- const stream = new AssistantMessageEventStream();
6925
+ const stream2 = new AssistantMessageEventStream();
6810
6926
  const owner = options?.transportOwner ?? {};
6811
6927
  const state = stateFor(owner);
6812
6928
  const reducer = new ResponsesEventReducer(model);
@@ -6814,9 +6930,9 @@ function streamResponsesWS(model, context, options) {
6814
6930
  reducer.message.stopReason = "error";
6815
6931
  reducer.message.errorMessage = "Responses owner already has an in-flight request.";
6816
6932
  reducer.message.retryable = false;
6817
- stream.push({ type: "error", reason: "error", error: reducer.message });
6818
- stream.end();
6819
- return stream;
6933
+ stream2.push({ type: "error", reason: "error", error: reducer.message });
6934
+ stream2.end();
6935
+ return stream2;
6820
6936
  }
6821
6937
  let budgets;
6822
6938
  try {
@@ -6825,9 +6941,9 @@ function streamResponsesWS(model, context, options) {
6825
6941
  reducer.message.stopReason = "error";
6826
6942
  reducer.message.errorMessage = error instanceof Error ? error.message : String(error);
6827
6943
  reducer.message.retryable = false;
6828
- stream.push({ type: "error", reason: "error", error: reducer.message });
6829
- stream.end();
6830
- return stream;
6944
+ stream2.push({ type: "error", reason: "error", error: reducer.message });
6945
+ stream2.end();
6946
+ return stream2;
6831
6947
  }
6832
6948
  state.busy = true;
6833
6949
  const localRequestId = nextLocalRequestId("ws");
@@ -6869,7 +6985,7 @@ function streamResponsesWS(model, context, options) {
6869
6985
  const requestAbort = new AbortController();
6870
6986
  const publish = (event) => {
6871
6987
  if (event.type === "done" || event.type === "error") terminalEvents.push(event);
6872
- else stream.push(event);
6988
+ else stream2.push(event);
6873
6989
  };
6874
6990
  const ageMs = () => Math.round(monotonicNow() - startedAt);
6875
6991
  const lastReceiveAgeMs = () => Math.round(monotonicNow() - lastReceiveAt);
@@ -7283,7 +7399,7 @@ function streamResponsesWS(model, context, options) {
7283
7399
  }
7284
7400
  if (message.remoteFailure) retryDecision = `remote_${message.remoteFailure.category}`;
7285
7401
  cleanupCancelSource = userAborted ? "user" : timedOut ? "internal_timeout" : ownerDisposed ? "owner_disposal" : "none";
7286
- stream.push({ type: "error", reason: message.stopReason, error: message });
7402
+ stream2.push({ type: "error", reason: message.stopReason, error: message });
7287
7403
  }
7288
7404
  } finally {
7289
7405
  clearRequestTimers();
@@ -7308,11 +7424,11 @@ function streamResponsesWS(model, context, options) {
7308
7424
  retryDecision,
7309
7425
  cleanupOutcome
7310
7426
  });
7311
- for (const event of terminalEvents) stream.push(event);
7312
- stream.end();
7427
+ for (const event of terminalEvents) stream2.push(event);
7428
+ stream2.end();
7313
7429
  }
7314
7430
  })();
7315
- return stream;
7431
+ return stream2;
7316
7432
  }
7317
7433
 
7318
7434
  // ../../packages/ai/src/providers/openai-responses.ts
@@ -7352,6 +7468,31 @@ var streamSimpleResponses = (model, context, options) => {
7352
7468
  });
7353
7469
  };
7354
7470
 
7471
+ // ../../packages/ai/src/stream.ts
7472
+ function resolveApiProvider(api) {
7473
+ const provider = getApiProvider(api);
7474
+ if (!provider) {
7475
+ throw new Error(`No API provider registered for api: ${api}`);
7476
+ }
7477
+ return provider;
7478
+ }
7479
+ function stream(model, context, options) {
7480
+ const provider = resolveApiProvider(model.api);
7481
+ return provider.stream(model, context, options);
7482
+ }
7483
+ async function complete(model, context, options) {
7484
+ const s = stream(model, context, options);
7485
+ return s.result();
7486
+ }
7487
+ function streamSimple(model, context, options) {
7488
+ const provider = resolveApiProvider(model.api);
7489
+ return provider.streamSimple(model, context, options);
7490
+ }
7491
+ async function completeSimple(model, context, options) {
7492
+ const s = streamSimple(model, context, options);
7493
+ return s.result();
7494
+ }
7495
+
7355
7496
  // ../../packages/ai/src/tool-model-routing.ts
7356
7497
  var MODEL_CLASS_FALLBACK_ORDER = ["balanced", "light", "strong"];
7357
7498
  var WEB_SEARCH_CAPABILITY_PRIORITY = {
@@ -10728,6 +10869,13 @@ __export(value_exports, {
10728
10869
  });
10729
10870
 
10730
10871
  // ../../packages/ai/src/utils/validation.ts
10872
+ function validateToolCall(tools, toolCall) {
10873
+ const tool = tools.find((t) => t.name === toolCall.name);
10874
+ if (!tool) {
10875
+ throw new Error(`Tool "${toolCall.name}" not found`);
10876
+ }
10877
+ return validateToolArguments(tool, toolCall);
10878
+ }
10731
10879
  function validateToolArguments(tool, toolCall) {
10732
10880
  const args = toolCall.arguments ?? {};
10733
10881
  if (value_exports.Check(tool.parameters, args)) {
@@ -10809,19 +10957,68 @@ export {
10809
10957
  getLogger,
10810
10958
  getPlatformConfig,
10811
10959
  FileSystemGateway,
10960
+ getFileSystemGateway,
10812
10961
  getFileSystem,
10813
10962
  format_exports,
10814
10963
  type_exports,
10815
10964
  ExtendsUndefinedCheck,
10965
+ registerApiProvider,
10966
+ getApiProvider,
10967
+ getApiProviders,
10968
+ clearApiProviders,
10969
+ getProviderEnvVar,
10970
+ getEnvApiKey,
10971
+ BUILTIN_MODEL_DEFINITIONS,
10972
+ getBuiltInModels,
10973
+ getModel,
10974
+ registerModel,
10975
+ registerModels,
10976
+ unregisterModel,
10977
+ getProviders,
10978
+ getModels,
10979
+ getAllModels,
10980
+ listAvailableModels,
10981
+ hasModel,
10982
+ clearModels,
10983
+ calculateCost,
10984
+ createModel,
10985
+ registerDefaultModels,
10986
+ registerModelsFromConfig,
10816
10987
  EventStream,
10817
10988
  AssistantMessageEventStream,
10989
+ createAssistantMessageEventStream,
10990
+ parseStreamingJson,
10991
+ NO_CACHE_CAPABILITY,
10992
+ ANTHROPIC_PROMPT_CACHE_CAPABILITY,
10818
10993
  getModelCacheCapability,
10994
+ isPromptCacheCapability,
10995
+ isSessionStoreCapability,
10996
+ getCompat,
10819
10997
  EMPTY_ASSISTANT_CONTENT_ERROR,
10998
+ EMPTY_ASSISTANT_CONTENT_ERROR_CODE,
10999
+ EmptyAssistantContentError,
11000
+ hasAssistantContent,
11001
+ assertAssistantHasContent,
11002
+ isEmptyAssistantContentError,
11003
+ logEmptyAssistantContentError,
10820
11004
  OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
11005
+ OpenAICompatProtocolError,
11006
+ streamOpenAICompletions,
11007
+ streamSimpleOpenAICompletions,
11008
+ streamAnthropic,
11009
+ streamSimpleAnthropic,
11010
+ getResponsesCompat,
11011
+ RESPONSES_PROTOCOL_ERROR_CODE,
11012
+ ResponsesProtocolError,
10821
11013
  disposeModelTransports,
11014
+ streamResponses,
11015
+ streamSimpleResponses,
11016
+ stream,
11017
+ complete,
10822
11018
  streamSimple,
10823
11019
  completeSimple,
10824
11020
  MODEL_CLASS_FALLBACK_ORDER,
11021
+ fileKindForToolModelPurpose,
10825
11022
  requiredCapabilityForToolPurpose,
10826
11023
  modelSupportsToolPurpose,
10827
11024
  sortToolModelCandidatesByCapability,
@@ -10833,5 +11030,6 @@ export {
10833
11030
  TransformEncodeCheckError,
10834
11031
  TransformEncode,
10835
11032
  HasTransform,
11033
+ validateToolCall,
10836
11034
  validateToolArguments
10837
11035
  };