@opentiny/next-sdk 0.2.4 → 0.2.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -171,7 +171,7 @@ function requireScope() {
171
171
  (function(exports) {
172
172
  Object.defineProperty(exports, "__esModule", { value: true });
173
173
  exports.ValueScope = exports.ValueScopeName = exports.Scope = exports.varKinds = exports.UsedValueState = void 0;
174
- const code_1 = requireCode$1();
174
+ const code_1 = /* @__PURE__ */ requireCode$1();
175
175
  class ValueError extends Error {
176
176
  constructor(name16) {
177
177
  super(`CodeGen: "code" for ${name16} not defined`);
@@ -317,9 +317,9 @@ function requireCodegen() {
317
317
  (function(exports) {
318
318
  Object.defineProperty(exports, "__esModule", { value: true });
319
319
  exports.or = exports.and = exports.not = exports.CodeGen = exports.operators = exports.varKinds = exports.ValueScopeName = exports.ValueScope = exports.Scope = exports.Name = exports.regexpCode = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;
320
- const code_1 = requireCode$1();
321
- const scope_1 = requireScope();
322
- var code_2 = requireCode$1();
320
+ const code_1 = /* @__PURE__ */ requireCode$1();
321
+ const scope_1 = /* @__PURE__ */ requireScope();
322
+ var code_2 = /* @__PURE__ */ requireCode$1();
323
323
  Object.defineProperty(exports, "_", { enumerable: true, get: function() {
324
324
  return code_2._;
325
325
  } });
@@ -344,7 +344,7 @@ function requireCodegen() {
344
344
  Object.defineProperty(exports, "Name", { enumerable: true, get: function() {
345
345
  return code_2.Name;
346
346
  } });
347
- var scope_2 = requireScope();
347
+ var scope_2 = /* @__PURE__ */ requireScope();
348
348
  Object.defineProperty(exports, "Scope", { enumerable: true, get: function() {
349
349
  return scope_2.Scope;
350
350
  } });
@@ -1038,8 +1038,8 @@ function requireUtil() {
1038
1038
  hasRequiredUtil = 1;
1039
1039
  Object.defineProperty(util$1, "__esModule", { value: true });
1040
1040
  util$1.checkStrictMode = util$1.getErrorPath = util$1.Type = util$1.useFunc = util$1.setEvaluated = util$1.evaluatedPropsToName = util$1.mergeEvaluated = util$1.eachItem = util$1.unescapeJsonPointer = util$1.escapeJsonPointer = util$1.escapeFragment = util$1.unescapeFragment = util$1.schemaRefOrVal = util$1.schemaHasRulesButRef = util$1.schemaHasRules = util$1.checkUnknownRules = util$1.alwaysValidSchema = util$1.toHash = void 0;
1041
- const codegen_1 = requireCodegen();
1042
- const code_1 = requireCode$1();
1041
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1042
+ const code_1 = /* @__PURE__ */ requireCode$1();
1043
1043
  function toHash(arr) {
1044
1044
  const hash = {};
1045
1045
  for (const item of arr)
@@ -1204,7 +1204,7 @@ function requireNames() {
1204
1204
  if (hasRequiredNames) return names;
1205
1205
  hasRequiredNames = 1;
1206
1206
  Object.defineProperty(names, "__esModule", { value: true });
1207
- const codegen_1 = requireCodegen();
1207
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1208
1208
  const names$1 = {
1209
1209
  // validation function arguments
1210
1210
  data: new codegen_1.Name("data"),
@@ -1244,9 +1244,9 @@ function requireErrors() {
1244
1244
  (function(exports) {
1245
1245
  Object.defineProperty(exports, "__esModule", { value: true });
1246
1246
  exports.extendErrors = exports.resetErrorsCount = exports.reportExtraError = exports.reportError = exports.keyword$DataError = exports.keywordError = void 0;
1247
- const codegen_1 = requireCodegen();
1248
- const util_1 = requireUtil();
1249
- const names_1 = requireNames();
1247
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1248
+ const util_1 = /* @__PURE__ */ requireUtil();
1249
+ const names_1 = /* @__PURE__ */ requireNames();
1250
1250
  exports.keywordError = {
1251
1251
  message: ({ keyword: keyword2 }) => (0, codegen_1.str)`must pass "${keyword2}" keyword validation`
1252
1252
  };
@@ -1366,9 +1366,9 @@ function requireBoolSchema() {
1366
1366
  hasRequiredBoolSchema = 1;
1367
1367
  Object.defineProperty(boolSchema, "__esModule", { value: true });
1368
1368
  boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
1369
- const errors_1 = requireErrors();
1370
- const codegen_1 = requireCodegen();
1371
- const names_1 = requireNames();
1369
+ const errors_1 = /* @__PURE__ */ requireErrors();
1370
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1371
+ const names_1 = /* @__PURE__ */ requireNames();
1372
1372
  const boolError = {
1373
1373
  message: "boolean schema is false"
1374
1374
  };
@@ -1471,11 +1471,11 @@ function requireDataType() {
1471
1471
  hasRequiredDataType = 1;
1472
1472
  Object.defineProperty(dataType, "__esModule", { value: true });
1473
1473
  dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
1474
- const rules_1 = requireRules();
1475
- const applicability_1 = requireApplicability();
1476
- const errors_1 = requireErrors();
1477
- const codegen_1 = requireCodegen();
1478
- const util_1 = requireUtil();
1474
+ const rules_1 = /* @__PURE__ */ requireRules();
1475
+ const applicability_1 = /* @__PURE__ */ requireApplicability();
1476
+ const errors_1 = /* @__PURE__ */ requireErrors();
1477
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1478
+ const util_1 = /* @__PURE__ */ requireUtil();
1479
1479
  var DataType;
1480
1480
  (function(DataType2) {
1481
1481
  DataType2[DataType2["Correct"] = 0] = "Correct";
@@ -1655,8 +1655,8 @@ function requireDefaults() {
1655
1655
  hasRequiredDefaults = 1;
1656
1656
  Object.defineProperty(defaults, "__esModule", { value: true });
1657
1657
  defaults.assignDefaults = void 0;
1658
- const codegen_1 = requireCodegen();
1659
- const util_1 = requireUtil();
1658
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1659
+ const util_1 = /* @__PURE__ */ requireUtil();
1660
1660
  function assignDefaults(it, ty) {
1661
1661
  const { properties: properties2, items: items2 } = it.schema;
1662
1662
  if (ty === "object" && properties2) {
@@ -1693,10 +1693,10 @@ function requireCode() {
1693
1693
  hasRequiredCode = 1;
1694
1694
  Object.defineProperty(code, "__esModule", { value: true });
1695
1695
  code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
1696
- const codegen_1 = requireCodegen();
1697
- const util_1 = requireUtil();
1698
- const names_1 = requireNames();
1699
- const util_2 = requireUtil();
1696
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1697
+ const util_1 = /* @__PURE__ */ requireUtil();
1698
+ const names_1 = /* @__PURE__ */ requireNames();
1699
+ const util_2 = /* @__PURE__ */ requireUtil();
1700
1700
  function checkReportMissingProp(cxt, prop) {
1701
1701
  const { gen, data, it } = cxt;
1702
1702
  gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
@@ -1825,10 +1825,10 @@ function requireKeyword() {
1825
1825
  hasRequiredKeyword = 1;
1826
1826
  Object.defineProperty(keyword, "__esModule", { value: true });
1827
1827
  keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
1828
- const codegen_1 = requireCodegen();
1829
- const names_1 = requireNames();
1830
- const code_1 = requireCode();
1831
- const errors_1 = requireErrors();
1828
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1829
+ const names_1 = /* @__PURE__ */ requireNames();
1830
+ const code_1 = /* @__PURE__ */ requireCode();
1831
+ const errors_1 = /* @__PURE__ */ requireErrors();
1832
1832
  function macroKeywordCode(cxt, def) {
1833
1833
  const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
1834
1834
  const macroSchema = def.macro.call(it.self, schema, parentSchema, it);
@@ -1943,8 +1943,8 @@ function requireSubschema() {
1943
1943
  hasRequiredSubschema = 1;
1944
1944
  Object.defineProperty(subschema, "__esModule", { value: true });
1945
1945
  subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
1946
- const codegen_1 = requireCodegen();
1947
- const util_1 = requireUtil();
1946
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1947
+ const util_1 = /* @__PURE__ */ requireUtil();
1948
1948
  function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
1949
1949
  if (keyword2 !== void 0 && schema !== void 0) {
1950
1950
  throw new Error('both "keyword" and "schema" passed, only one allowed');
@@ -2149,7 +2149,7 @@ function requireResolve() {
2149
2149
  hasRequiredResolve = 1;
2150
2150
  Object.defineProperty(resolve$1, "__esModule", { value: true });
2151
2151
  resolve$1.getSchemaRefs = resolve$1.resolveUrl = resolve$1.normalizeId = resolve$1._getFullPath = resolve$1.getFullPath = resolve$1.inlineRef = void 0;
2152
- const util_1 = requireUtil();
2152
+ const util_1 = /* @__PURE__ */ requireUtil();
2153
2153
  const equal2 = requireFastDeepEqual();
2154
2154
  const traverse = requireJsonSchemaTraverse();
2155
2155
  const SIMPLE_INLINED = /* @__PURE__ */ new Set([
@@ -2304,18 +2304,18 @@ function requireValidate() {
2304
2304
  hasRequiredValidate = 1;
2305
2305
  Object.defineProperty(validate, "__esModule", { value: true });
2306
2306
  validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
2307
- const boolSchema_1 = requireBoolSchema();
2308
- const dataType_1 = requireDataType();
2309
- const applicability_1 = requireApplicability();
2310
- const dataType_2 = requireDataType();
2311
- const defaults_1 = requireDefaults();
2312
- const keyword_1 = requireKeyword();
2313
- const subschema_1 = requireSubschema();
2314
- const codegen_1 = requireCodegen();
2315
- const names_1 = requireNames();
2316
- const resolve_1 = requireResolve();
2317
- const util_1 = requireUtil();
2318
- const errors_1 = requireErrors();
2307
+ const boolSchema_1 = /* @__PURE__ */ requireBoolSchema();
2308
+ const dataType_1 = /* @__PURE__ */ requireDataType();
2309
+ const applicability_1 = /* @__PURE__ */ requireApplicability();
2310
+ const dataType_2 = /* @__PURE__ */ requireDataType();
2311
+ const defaults_1 = /* @__PURE__ */ requireDefaults();
2312
+ const keyword_1 = /* @__PURE__ */ requireKeyword();
2313
+ const subschema_1 = /* @__PURE__ */ requireSubschema();
2314
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
2315
+ const names_1 = /* @__PURE__ */ requireNames();
2316
+ const resolve_1 = /* @__PURE__ */ requireResolve();
2317
+ const util_1 = /* @__PURE__ */ requireUtil();
2318
+ const errors_1 = /* @__PURE__ */ requireErrors();
2319
2319
  function validateFunctionCode(it) {
2320
2320
  if (isSchemaObj(it)) {
2321
2321
  checkKeywords(it);
@@ -2826,7 +2826,7 @@ function requireRef_error() {
2826
2826
  if (hasRequiredRef_error) return ref_error;
2827
2827
  hasRequiredRef_error = 1;
2828
2828
  Object.defineProperty(ref_error, "__esModule", { value: true });
2829
- const resolve_1 = requireResolve();
2829
+ const resolve_1 = /* @__PURE__ */ requireResolve();
2830
2830
  class MissingRefError extends Error {
2831
2831
  constructor(resolver, baseId, ref2, msg) {
2832
2832
  super(msg || `can't resolve reference ${ref2} from id ${baseId}`);
@@ -2844,12 +2844,12 @@ function requireCompile() {
2844
2844
  hasRequiredCompile = 1;
2845
2845
  Object.defineProperty(compile, "__esModule", { value: true });
2846
2846
  compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
2847
- const codegen_1 = requireCodegen();
2848
- const validation_error_1 = requireValidation_error();
2849
- const names_1 = requireNames();
2850
- const resolve_1 = requireResolve();
2851
- const util_1 = requireUtil();
2852
- const validate_1 = requireValidate();
2847
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
2848
+ const validation_error_1 = /* @__PURE__ */ requireValidation_error();
2849
+ const names_1 = /* @__PURE__ */ requireNames();
2850
+ const resolve_1 = /* @__PURE__ */ requireResolve();
2851
+ const util_1 = /* @__PURE__ */ requireUtil();
2852
+ const validate_1 = /* @__PURE__ */ requireValidate();
2853
2853
  class SchemaEnv {
2854
2854
  constructor(env) {
2855
2855
  var _a10;
@@ -3083,7 +3083,7 @@ function requireUtils$2() {
3083
3083
  if (hasRequiredUtils$2) return utils$2;
3084
3084
  hasRequiredUtils$2 = 1;
3085
3085
  const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
3086
- const isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
3086
+ const isIPv42 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
3087
3087
  function stringArrayToHexStripped(input) {
3088
3088
  let acc = "";
3089
3089
  let code2 = 0;
@@ -3306,7 +3306,7 @@ function requireUtils$2() {
3306
3306
  }
3307
3307
  if (component.host !== void 0) {
3308
3308
  let host = unescape(component.host);
3309
- if (!isIPv4(host)) {
3309
+ if (!isIPv42(host)) {
3310
3310
  const ipV6res = normalizeIPv6(host);
3311
3311
  if (ipV6res.isIPV6 === true) {
3312
3312
  host = `[${ipV6res.escapedHost}]`;
@@ -3327,7 +3327,7 @@ function requireUtils$2() {
3327
3327
  recomposeAuthority,
3328
3328
  normalizeComponentEncoding,
3329
3329
  removeDotSegments,
3330
- isIPv4,
3330
+ isIPv4: isIPv42,
3331
3331
  isUUID,
3332
3332
  normalizeIPv6,
3333
3333
  stringArrayToHexStripped
@@ -3548,7 +3548,7 @@ var hasRequiredFastUri;
3548
3548
  function requireFastUri() {
3549
3549
  if (hasRequiredFastUri) return fastUri.exports;
3550
3550
  hasRequiredFastUri = 1;
3551
- const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = requireUtils$2();
3551
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4: isIPv42, nonSimpleDomain } = requireUtils$2();
3552
3552
  const { SCHEMES, getSchemeHandler } = requireSchemes();
3553
3553
  function normalize(uri2, options) {
3554
3554
  if (typeof uri2 === "string") {
@@ -3729,7 +3729,7 @@ function requireFastUri() {
3729
3729
  parsed.port = matches[5];
3730
3730
  }
3731
3731
  if (parsed.host) {
3732
- const ipv4result = isIPv4(parsed.host);
3732
+ const ipv4result = isIPv42(parsed.host);
3733
3733
  if (ipv4result === false) {
3734
3734
  const ipv6result = normalizeIPv6(parsed.host);
3735
3735
  parsed.host = ipv6result.host.toLowerCase();
@@ -3815,11 +3815,11 @@ function requireCore$1() {
3815
3815
  (function(exports) {
3816
3816
  Object.defineProperty(exports, "__esModule", { value: true });
3817
3817
  exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
3818
- var validate_1 = requireValidate();
3818
+ var validate_1 = /* @__PURE__ */ requireValidate();
3819
3819
  Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
3820
3820
  return validate_1.KeywordCxt;
3821
3821
  } });
3822
- var codegen_1 = requireCodegen();
3822
+ var codegen_1 = /* @__PURE__ */ requireCodegen();
3823
3823
  Object.defineProperty(exports, "_", { enumerable: true, get: function() {
3824
3824
  return codegen_1._;
3825
3825
  } });
@@ -3838,16 +3838,16 @@ function requireCore$1() {
3838
3838
  Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
3839
3839
  return codegen_1.CodeGen;
3840
3840
  } });
3841
- const validation_error_1 = requireValidation_error();
3842
- const ref_error_1 = requireRef_error();
3843
- const rules_1 = requireRules();
3844
- const compile_1 = requireCompile();
3845
- const codegen_2 = requireCodegen();
3846
- const resolve_1 = requireResolve();
3847
- const dataType_1 = requireDataType();
3848
- const util_1 = requireUtil();
3841
+ const validation_error_1 = /* @__PURE__ */ requireValidation_error();
3842
+ const ref_error_1 = /* @__PURE__ */ requireRef_error();
3843
+ const rules_1 = /* @__PURE__ */ requireRules();
3844
+ const compile_1 = /* @__PURE__ */ requireCompile();
3845
+ const codegen_2 = /* @__PURE__ */ requireCodegen();
3846
+ const resolve_1 = /* @__PURE__ */ requireResolve();
3847
+ const dataType_1 = /* @__PURE__ */ requireDataType();
3848
+ const util_1 = /* @__PURE__ */ requireUtil();
3849
3849
  const $dataRefSchema = require$$9;
3850
- const uri_1 = requireUri();
3850
+ const uri_1 = /* @__PURE__ */ requireUri();
3851
3851
  const defaultRegExp = (str, flags) => new RegExp(str, flags);
3852
3852
  defaultRegExp.code = "new RegExp";
3853
3853
  const META_IGNORE_OPTIONS = ["removeAdditional", "useDefaults", "coerceTypes"];
@@ -4444,12 +4444,12 @@ function requireRef() {
4444
4444
  hasRequiredRef = 1;
4445
4445
  Object.defineProperty(ref, "__esModule", { value: true });
4446
4446
  ref.callRef = ref.getValidate = void 0;
4447
- const ref_error_1 = requireRef_error();
4448
- const code_1 = requireCode();
4449
- const codegen_1 = requireCodegen();
4450
- const names_1 = requireNames();
4451
- const compile_1 = requireCompile();
4452
- const util_1 = requireUtil();
4447
+ const ref_error_1 = /* @__PURE__ */ requireRef_error();
4448
+ const code_1 = /* @__PURE__ */ requireCode();
4449
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4450
+ const names_1 = /* @__PURE__ */ requireNames();
4451
+ const compile_1 = /* @__PURE__ */ requireCompile();
4452
+ const util_1 = /* @__PURE__ */ requireUtil();
4453
4453
  const def = {
4454
4454
  keyword: "$ref",
4455
4455
  schemaType: "string",
@@ -4564,8 +4564,8 @@ function requireCore() {
4564
4564
  if (hasRequiredCore) return core;
4565
4565
  hasRequiredCore = 1;
4566
4566
  Object.defineProperty(core, "__esModule", { value: true });
4567
- const id_1 = requireId();
4568
- const ref_1 = requireRef();
4567
+ const id_1 = /* @__PURE__ */ requireId();
4568
+ const ref_1 = /* @__PURE__ */ requireRef();
4569
4569
  const core$12 = [
4570
4570
  "$schema",
4571
4571
  "$id",
@@ -4586,7 +4586,7 @@ function requireLimitNumber() {
4586
4586
  if (hasRequiredLimitNumber) return limitNumber;
4587
4587
  hasRequiredLimitNumber = 1;
4588
4588
  Object.defineProperty(limitNumber, "__esModule", { value: true });
4589
- const codegen_1 = requireCodegen();
4589
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4590
4590
  const ops = codegen_1.operators;
4591
4591
  const KWDs = {
4592
4592
  maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
@@ -4618,7 +4618,7 @@ function requireMultipleOf() {
4618
4618
  if (hasRequiredMultipleOf) return multipleOf;
4619
4619
  hasRequiredMultipleOf = 1;
4620
4620
  Object.defineProperty(multipleOf, "__esModule", { value: true });
4621
- const codegen_1 = requireCodegen();
4621
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4622
4622
  const error = {
4623
4623
  message: ({ schemaCode }) => (0, codegen_1.str)`must be multiple of ${schemaCode}`,
4624
4624
  params: ({ schemaCode }) => (0, codegen_1._)`{multipleOf: ${schemaCode}}`
@@ -4672,9 +4672,9 @@ function requireLimitLength() {
4672
4672
  if (hasRequiredLimitLength) return limitLength;
4673
4673
  hasRequiredLimitLength = 1;
4674
4674
  Object.defineProperty(limitLength, "__esModule", { value: true });
4675
- const codegen_1 = requireCodegen();
4676
- const util_1 = requireUtil();
4677
- const ucs2length_1 = requireUcs2length();
4675
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4676
+ const util_1 = /* @__PURE__ */ requireUtil();
4677
+ const ucs2length_1 = /* @__PURE__ */ requireUcs2length();
4678
4678
  const error = {
4679
4679
  message({ keyword: keyword2, schemaCode }) {
4680
4680
  const comp = keyword2 === "maxLength" ? "more" : "fewer";
@@ -4704,8 +4704,9 @@ function requirePattern() {
4704
4704
  if (hasRequiredPattern) return pattern;
4705
4705
  hasRequiredPattern = 1;
4706
4706
  Object.defineProperty(pattern, "__esModule", { value: true });
4707
- const code_1 = requireCode();
4708
- const codegen_1 = requireCodegen();
4707
+ const code_1 = /* @__PURE__ */ requireCode();
4708
+ const util_1 = /* @__PURE__ */ requireUtil();
4709
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4709
4710
  const error = {
4710
4711
  message: ({ schemaCode }) => (0, codegen_1.str)`must match pattern "${schemaCode}"`,
4711
4712
  params: ({ schemaCode }) => (0, codegen_1._)`{pattern: ${schemaCode}}`
@@ -4717,10 +4718,18 @@ function requirePattern() {
4717
4718
  $data: true,
4718
4719
  error,
4719
4720
  code(cxt) {
4720
- const { data, $data, schema, schemaCode, it } = cxt;
4721
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
4721
4722
  const u = it.opts.unicodeRegExp ? "u" : "";
4722
- const regExp = $data ? (0, codegen_1._)`(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
4723
- cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4723
+ if ($data) {
4724
+ const { regExp } = it.opts.code;
4725
+ const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._)`new RegExp` : (0, util_1.useFunc)(gen, regExp);
4726
+ const valid = gen.let("valid");
4727
+ gen.try(() => gen.assign(valid, (0, codegen_1._)`${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid, false));
4728
+ cxt.fail$data((0, codegen_1._)`!${valid}`);
4729
+ } else {
4730
+ const regExp = (0, code_1.usePattern)(cxt, schema);
4731
+ cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4732
+ }
4724
4733
  }
4725
4734
  };
4726
4735
  pattern.default = def;
@@ -4732,7 +4741,7 @@ function requireLimitProperties() {
4732
4741
  if (hasRequiredLimitProperties) return limitProperties;
4733
4742
  hasRequiredLimitProperties = 1;
4734
4743
  Object.defineProperty(limitProperties, "__esModule", { value: true });
4735
- const codegen_1 = requireCodegen();
4744
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4736
4745
  const error = {
4737
4746
  message({ keyword: keyword2, schemaCode }) {
4738
4747
  const comp = keyword2 === "maxProperties" ? "more" : "fewer";
@@ -4761,9 +4770,9 @@ function requireRequired() {
4761
4770
  if (hasRequiredRequired) return required$1;
4762
4771
  hasRequiredRequired = 1;
4763
4772
  Object.defineProperty(required$1, "__esModule", { value: true });
4764
- const code_1 = requireCode();
4765
- const codegen_1 = requireCodegen();
4766
- const util_1 = requireUtil();
4773
+ const code_1 = /* @__PURE__ */ requireCode();
4774
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4775
+ const util_1 = /* @__PURE__ */ requireUtil();
4767
4776
  const error = {
4768
4777
  message: ({ params: { missingProperty } }) => (0, codegen_1.str)`must have required property '${missingProperty}'`,
4769
4778
  params: ({ params: { missingProperty } }) => (0, codegen_1._)`{missingProperty: ${missingProperty}}`
@@ -4843,7 +4852,7 @@ function requireLimitItems() {
4843
4852
  if (hasRequiredLimitItems) return limitItems;
4844
4853
  hasRequiredLimitItems = 1;
4845
4854
  Object.defineProperty(limitItems, "__esModule", { value: true });
4846
- const codegen_1 = requireCodegen();
4855
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4847
4856
  const error = {
4848
4857
  message({ keyword: keyword2, schemaCode }) {
4849
4858
  const comp = keyword2 === "maxItems" ? "more" : "fewer";
@@ -4883,10 +4892,10 @@ function requireUniqueItems() {
4883
4892
  if (hasRequiredUniqueItems) return uniqueItems;
4884
4893
  hasRequiredUniqueItems = 1;
4885
4894
  Object.defineProperty(uniqueItems, "__esModule", { value: true });
4886
- const dataType_1 = requireDataType();
4887
- const codegen_1 = requireCodegen();
4888
- const util_1 = requireUtil();
4889
- const equal_1 = requireEqual();
4895
+ const dataType_1 = /* @__PURE__ */ requireDataType();
4896
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4897
+ const util_1 = /* @__PURE__ */ requireUtil();
4898
+ const equal_1 = /* @__PURE__ */ requireEqual();
4890
4899
  const error = {
4891
4900
  message: ({ params: { i, j } }) => (0, codegen_1.str)`must NOT have duplicate items (items ## ${j} and ${i} are identical)`,
4892
4901
  params: ({ params: { i, j } }) => (0, codegen_1._)`{i: ${i}, j: ${j}}`
@@ -4950,9 +4959,9 @@ function require_const() {
4950
4959
  if (hasRequired_const) return _const;
4951
4960
  hasRequired_const = 1;
4952
4961
  Object.defineProperty(_const, "__esModule", { value: true });
4953
- const codegen_1 = requireCodegen();
4954
- const util_1 = requireUtil();
4955
- const equal_1 = requireEqual();
4962
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4963
+ const util_1 = /* @__PURE__ */ requireUtil();
4964
+ const equal_1 = /* @__PURE__ */ requireEqual();
4956
4965
  const error = {
4957
4966
  message: "must be equal to constant",
4958
4967
  params: ({ schemaCode }) => (0, codegen_1._)`{allowedValue: ${schemaCode}}`
@@ -4979,9 +4988,9 @@ function require_enum() {
4979
4988
  if (hasRequired_enum) return _enum$1;
4980
4989
  hasRequired_enum = 1;
4981
4990
  Object.defineProperty(_enum$1, "__esModule", { value: true });
4982
- const codegen_1 = requireCodegen();
4983
- const util_1 = requireUtil();
4984
- const equal_1 = requireEqual();
4991
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4992
+ const util_1 = /* @__PURE__ */ requireUtil();
4993
+ const equal_1 = /* @__PURE__ */ requireEqual();
4985
4994
  const error = {
4986
4995
  message: "must be equal to one of the allowed values",
4987
4996
  params: ({ schemaCode }) => (0, codegen_1._)`{allowedValues: ${schemaCode}}`
@@ -5027,16 +5036,16 @@ function requireValidation() {
5027
5036
  if (hasRequiredValidation) return validation;
5028
5037
  hasRequiredValidation = 1;
5029
5038
  Object.defineProperty(validation, "__esModule", { value: true });
5030
- const limitNumber_1 = requireLimitNumber();
5031
- const multipleOf_1 = requireMultipleOf();
5032
- const limitLength_1 = requireLimitLength();
5033
- const pattern_1 = requirePattern();
5034
- const limitProperties_1 = requireLimitProperties();
5035
- const required_1 = requireRequired();
5036
- const limitItems_1 = requireLimitItems();
5037
- const uniqueItems_1 = requireUniqueItems();
5038
- const const_1 = require_const();
5039
- const enum_1 = require_enum();
5039
+ const limitNumber_1 = /* @__PURE__ */ requireLimitNumber();
5040
+ const multipleOf_1 = /* @__PURE__ */ requireMultipleOf();
5041
+ const limitLength_1 = /* @__PURE__ */ requireLimitLength();
5042
+ const pattern_1 = /* @__PURE__ */ requirePattern();
5043
+ const limitProperties_1 = /* @__PURE__ */ requireLimitProperties();
5044
+ const required_1 = /* @__PURE__ */ requireRequired();
5045
+ const limitItems_1 = /* @__PURE__ */ requireLimitItems();
5046
+ const uniqueItems_1 = /* @__PURE__ */ requireUniqueItems();
5047
+ const const_1 = /* @__PURE__ */ require_const();
5048
+ const enum_1 = /* @__PURE__ */ require_enum();
5040
5049
  const validation$1 = [
5041
5050
  // number
5042
5051
  limitNumber_1.default,
@@ -5067,8 +5076,8 @@ function requireAdditionalItems() {
5067
5076
  hasRequiredAdditionalItems = 1;
5068
5077
  Object.defineProperty(additionalItems, "__esModule", { value: true });
5069
5078
  additionalItems.validateAdditionalItems = void 0;
5070
- const codegen_1 = requireCodegen();
5071
- const util_1 = requireUtil();
5079
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5080
+ const util_1 = /* @__PURE__ */ requireUtil();
5072
5081
  const error = {
5073
5082
  message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
5074
5083
  params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
@@ -5121,9 +5130,9 @@ function requireItems() {
5121
5130
  hasRequiredItems = 1;
5122
5131
  Object.defineProperty(items, "__esModule", { value: true });
5123
5132
  items.validateTuple = void 0;
5124
- const codegen_1 = requireCodegen();
5125
- const util_1 = requireUtil();
5126
- const code_1 = requireCode();
5133
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5134
+ const util_1 = /* @__PURE__ */ requireUtil();
5135
+ const code_1 = /* @__PURE__ */ requireCode();
5127
5136
  const def = {
5128
5137
  keyword: "items",
5129
5138
  type: "array",
@@ -5176,7 +5185,7 @@ function requirePrefixItems() {
5176
5185
  if (hasRequiredPrefixItems) return prefixItems;
5177
5186
  hasRequiredPrefixItems = 1;
5178
5187
  Object.defineProperty(prefixItems, "__esModule", { value: true });
5179
- const items_1 = requireItems();
5188
+ const items_1 = /* @__PURE__ */ requireItems();
5180
5189
  const def = {
5181
5190
  keyword: "prefixItems",
5182
5191
  type: "array",
@@ -5193,10 +5202,10 @@ function requireItems2020() {
5193
5202
  if (hasRequiredItems2020) return items2020;
5194
5203
  hasRequiredItems2020 = 1;
5195
5204
  Object.defineProperty(items2020, "__esModule", { value: true });
5196
- const codegen_1 = requireCodegen();
5197
- const util_1 = requireUtil();
5198
- const code_1 = requireCode();
5199
- const additionalItems_1 = requireAdditionalItems();
5205
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5206
+ const util_1 = /* @__PURE__ */ requireUtil();
5207
+ const code_1 = /* @__PURE__ */ requireCode();
5208
+ const additionalItems_1 = /* @__PURE__ */ requireAdditionalItems();
5200
5209
  const error = {
5201
5210
  message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
5202
5211
  params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
@@ -5228,8 +5237,8 @@ function requireContains() {
5228
5237
  if (hasRequiredContains) return contains;
5229
5238
  hasRequiredContains = 1;
5230
5239
  Object.defineProperty(contains, "__esModule", { value: true });
5231
- const codegen_1 = requireCodegen();
5232
- const util_1 = requireUtil();
5240
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5241
+ const util_1 = /* @__PURE__ */ requireUtil();
5233
5242
  const error = {
5234
5243
  message: ({ params: { min, max } }) => max === void 0 ? (0, codegen_1.str)`must contain at least ${min} valid item(s)` : (0, codegen_1.str)`must contain at least ${min} and no more than ${max} valid item(s)`,
5235
5244
  params: ({ params: { min, max } }) => max === void 0 ? (0, codegen_1._)`{minContains: ${min}}` : (0, codegen_1._)`{minContains: ${min}, maxContains: ${max}}`
@@ -5324,9 +5333,9 @@ function requireDependencies() {
5324
5333
  (function(exports) {
5325
5334
  Object.defineProperty(exports, "__esModule", { value: true });
5326
5335
  exports.validateSchemaDeps = exports.validatePropertyDeps = exports.error = void 0;
5327
- const codegen_1 = requireCodegen();
5328
- const util_1 = requireUtil();
5329
- const code_1 = requireCode();
5336
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5337
+ const util_1 = /* @__PURE__ */ requireUtil();
5338
+ const code_1 = /* @__PURE__ */ requireCode();
5330
5339
  exports.error = {
5331
5340
  message: ({ params: { property, depsCount, deps } }) => {
5332
5341
  const property_ies = depsCount === 1 ? "property" : "properties";
@@ -5418,8 +5427,8 @@ function requirePropertyNames() {
5418
5427
  if (hasRequiredPropertyNames) return propertyNames;
5419
5428
  hasRequiredPropertyNames = 1;
5420
5429
  Object.defineProperty(propertyNames, "__esModule", { value: true });
5421
- const codegen_1 = requireCodegen();
5422
- const util_1 = requireUtil();
5430
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5431
+ const util_1 = /* @__PURE__ */ requireUtil();
5423
5432
  const error = {
5424
5433
  message: "property name must be valid",
5425
5434
  params: ({ params }) => (0, codegen_1._)`{propertyName: ${params.propertyName}}`
@@ -5461,10 +5470,10 @@ function requireAdditionalProperties() {
5461
5470
  if (hasRequiredAdditionalProperties) return additionalProperties;
5462
5471
  hasRequiredAdditionalProperties = 1;
5463
5472
  Object.defineProperty(additionalProperties, "__esModule", { value: true });
5464
- const code_1 = requireCode();
5465
- const codegen_1 = requireCodegen();
5466
- const names_1 = requireNames();
5467
- const util_1 = requireUtil();
5473
+ const code_1 = /* @__PURE__ */ requireCode();
5474
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5475
+ const names_1 = /* @__PURE__ */ requireNames();
5476
+ const util_1 = /* @__PURE__ */ requireUtil();
5468
5477
  const error = {
5469
5478
  message: "must NOT have additional properties",
5470
5479
  params: ({ params }) => (0, codegen_1._)`{additionalProperty: ${params.additionalProperty}}`
@@ -5567,10 +5576,10 @@ function requireProperties() {
5567
5576
  if (hasRequiredProperties) return properties$1;
5568
5577
  hasRequiredProperties = 1;
5569
5578
  Object.defineProperty(properties$1, "__esModule", { value: true });
5570
- const validate_1 = requireValidate();
5571
- const code_1 = requireCode();
5572
- const util_1 = requireUtil();
5573
- const additionalProperties_1 = requireAdditionalProperties();
5579
+ const validate_1 = /* @__PURE__ */ requireValidate();
5580
+ const code_1 = /* @__PURE__ */ requireCode();
5581
+ const util_1 = /* @__PURE__ */ requireUtil();
5582
+ const additionalProperties_1 = /* @__PURE__ */ requireAdditionalProperties();
5574
5583
  const def = {
5575
5584
  keyword: "properties",
5576
5585
  type: "object",
@@ -5625,10 +5634,10 @@ function requirePatternProperties() {
5625
5634
  if (hasRequiredPatternProperties) return patternProperties;
5626
5635
  hasRequiredPatternProperties = 1;
5627
5636
  Object.defineProperty(patternProperties, "__esModule", { value: true });
5628
- const code_1 = requireCode();
5629
- const codegen_1 = requireCodegen();
5630
- const util_1 = requireUtil();
5631
- const util_2 = requireUtil();
5637
+ const code_1 = /* @__PURE__ */ requireCode();
5638
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5639
+ const util_1 = /* @__PURE__ */ requireUtil();
5640
+ const util_2 = /* @__PURE__ */ requireUtil();
5632
5641
  const def = {
5633
5642
  keyword: "patternProperties",
5634
5643
  type: "object",
@@ -5699,7 +5708,7 @@ function requireNot() {
5699
5708
  if (hasRequiredNot) return not;
5700
5709
  hasRequiredNot = 1;
5701
5710
  Object.defineProperty(not, "__esModule", { value: true });
5702
- const util_1 = requireUtil();
5711
+ const util_1 = /* @__PURE__ */ requireUtil();
5703
5712
  const def = {
5704
5713
  keyword: "not",
5705
5714
  schemaType: ["object", "boolean"],
@@ -5730,7 +5739,7 @@ function requireAnyOf() {
5730
5739
  if (hasRequiredAnyOf) return anyOf;
5731
5740
  hasRequiredAnyOf = 1;
5732
5741
  Object.defineProperty(anyOf, "__esModule", { value: true });
5733
- const code_1 = requireCode();
5742
+ const code_1 = /* @__PURE__ */ requireCode();
5734
5743
  const def = {
5735
5744
  keyword: "anyOf",
5736
5745
  schemaType: "array",
@@ -5747,8 +5756,8 @@ function requireOneOf() {
5747
5756
  if (hasRequiredOneOf) return oneOf;
5748
5757
  hasRequiredOneOf = 1;
5749
5758
  Object.defineProperty(oneOf, "__esModule", { value: true });
5750
- const codegen_1 = requireCodegen();
5751
- const util_1 = requireUtil();
5759
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5760
+ const util_1 = /* @__PURE__ */ requireUtil();
5752
5761
  const error = {
5753
5762
  message: "must match exactly one schema in oneOf",
5754
5763
  params: ({ params }) => (0, codegen_1._)`{passingSchemas: ${params.passing}}`
@@ -5805,7 +5814,7 @@ function requireAllOf() {
5805
5814
  if (hasRequiredAllOf) return allOf;
5806
5815
  hasRequiredAllOf = 1;
5807
5816
  Object.defineProperty(allOf, "__esModule", { value: true });
5808
- const util_1 = requireUtil();
5817
+ const util_1 = /* @__PURE__ */ requireUtil();
5809
5818
  const def = {
5810
5819
  keyword: "allOf",
5811
5820
  schemaType: "array",
@@ -5832,8 +5841,8 @@ function require_if() {
5832
5841
  if (hasRequired_if) return _if;
5833
5842
  hasRequired_if = 1;
5834
5843
  Object.defineProperty(_if, "__esModule", { value: true });
5835
- const codegen_1 = requireCodegen();
5836
- const util_1 = requireUtil();
5844
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5845
+ const util_1 = /* @__PURE__ */ requireUtil();
5837
5846
  const error = {
5838
5847
  message: ({ params }) => (0, codegen_1.str)`must match "${params.ifClause}" schema`,
5839
5848
  params: ({ params }) => (0, codegen_1._)`{failingKeyword: ${params.ifClause}}`
@@ -5901,7 +5910,7 @@ function requireThenElse() {
5901
5910
  if (hasRequiredThenElse) return thenElse;
5902
5911
  hasRequiredThenElse = 1;
5903
5912
  Object.defineProperty(thenElse, "__esModule", { value: true });
5904
- const util_1 = requireUtil();
5913
+ const util_1 = /* @__PURE__ */ requireUtil();
5905
5914
  const def = {
5906
5915
  keyword: ["then", "else"],
5907
5916
  schemaType: ["object", "boolean"],
@@ -5918,22 +5927,22 @@ function requireApplicator() {
5918
5927
  if (hasRequiredApplicator) return applicator;
5919
5928
  hasRequiredApplicator = 1;
5920
5929
  Object.defineProperty(applicator, "__esModule", { value: true });
5921
- const additionalItems_1 = requireAdditionalItems();
5922
- const prefixItems_1 = requirePrefixItems();
5923
- const items_1 = requireItems();
5924
- const items2020_1 = requireItems2020();
5925
- const contains_1 = requireContains();
5926
- const dependencies_1 = requireDependencies();
5927
- const propertyNames_1 = requirePropertyNames();
5928
- const additionalProperties_1 = requireAdditionalProperties();
5929
- const properties_1 = requireProperties();
5930
- const patternProperties_1 = requirePatternProperties();
5931
- const not_1 = requireNot();
5932
- const anyOf_1 = requireAnyOf();
5933
- const oneOf_1 = requireOneOf();
5934
- const allOf_1 = requireAllOf();
5935
- const if_1 = require_if();
5936
- const thenElse_1 = requireThenElse();
5930
+ const additionalItems_1 = /* @__PURE__ */ requireAdditionalItems();
5931
+ const prefixItems_1 = /* @__PURE__ */ requirePrefixItems();
5932
+ const items_1 = /* @__PURE__ */ requireItems();
5933
+ const items2020_1 = /* @__PURE__ */ requireItems2020();
5934
+ const contains_1 = /* @__PURE__ */ requireContains();
5935
+ const dependencies_1 = /* @__PURE__ */ requireDependencies();
5936
+ const propertyNames_1 = /* @__PURE__ */ requirePropertyNames();
5937
+ const additionalProperties_1 = /* @__PURE__ */ requireAdditionalProperties();
5938
+ const properties_1 = /* @__PURE__ */ requireProperties();
5939
+ const patternProperties_1 = /* @__PURE__ */ requirePatternProperties();
5940
+ const not_1 = /* @__PURE__ */ requireNot();
5941
+ const anyOf_1 = /* @__PURE__ */ requireAnyOf();
5942
+ const oneOf_1 = /* @__PURE__ */ requireOneOf();
5943
+ const allOf_1 = /* @__PURE__ */ requireAllOf();
5944
+ const if_1 = /* @__PURE__ */ require_if();
5945
+ const thenElse_1 = /* @__PURE__ */ requireThenElse();
5937
5946
  function getApplicator(draft2020 = false) {
5938
5947
  const applicator2 = [
5939
5948
  // any
@@ -5967,7 +5976,7 @@ function requireFormat$1() {
5967
5976
  if (hasRequiredFormat$1) return format;
5968
5977
  hasRequiredFormat$1 = 1;
5969
5978
  Object.defineProperty(format, "__esModule", { value: true });
5970
- const codegen_1 = requireCodegen();
5979
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5971
5980
  const error = {
5972
5981
  message: ({ schemaCode }) => (0, codegen_1.str)`must match format "${schemaCode}"`,
5973
5982
  params: ({ schemaCode }) => (0, codegen_1._)`{format: ${schemaCode}}`
@@ -6056,7 +6065,7 @@ function requireFormat() {
6056
6065
  if (hasRequiredFormat) return format$1;
6057
6066
  hasRequiredFormat = 1;
6058
6067
  Object.defineProperty(format$1, "__esModule", { value: true });
6059
- const format_1 = requireFormat$1();
6068
+ const format_1 = /* @__PURE__ */ requireFormat$1();
6060
6069
  const format2 = [format_1.default];
6061
6070
  format$1.default = format2;
6062
6071
  return format$1;
@@ -6089,11 +6098,11 @@ function requireDraft7() {
6089
6098
  if (hasRequiredDraft7) return draft7;
6090
6099
  hasRequiredDraft7 = 1;
6091
6100
  Object.defineProperty(draft7, "__esModule", { value: true });
6092
- const core_1 = requireCore();
6093
- const validation_1 = requireValidation();
6094
- const applicator_1 = requireApplicator();
6095
- const format_1 = requireFormat();
6096
- const metadata_1 = requireMetadata();
6101
+ const core_1 = /* @__PURE__ */ requireCore();
6102
+ const validation_1 = /* @__PURE__ */ requireValidation();
6103
+ const applicator_1 = /* @__PURE__ */ requireApplicator();
6104
+ const format_1 = /* @__PURE__ */ requireFormat();
6105
+ const metadata_1 = /* @__PURE__ */ requireMetadata();
6097
6106
  const draft7Vocabularies = [
6098
6107
  core_1.default,
6099
6108
  validation_1.default,
@@ -6125,11 +6134,11 @@ function requireDiscriminator() {
6125
6134
  if (hasRequiredDiscriminator) return discriminator;
6126
6135
  hasRequiredDiscriminator = 1;
6127
6136
  Object.defineProperty(discriminator, "__esModule", { value: true });
6128
- const codegen_1 = requireCodegen();
6129
- const types_1 = requireTypes();
6130
- const compile_1 = requireCompile();
6131
- const ref_error_1 = requireRef_error();
6132
- const util_1 = requireUtil();
6137
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
6138
+ const types_1 = /* @__PURE__ */ requireTypes();
6139
+ const compile_1 = /* @__PURE__ */ requireCompile();
6140
+ const ref_error_1 = /* @__PURE__ */ requireRef_error();
6141
+ const util_1 = /* @__PURE__ */ requireUtil();
6133
6142
  const error = {
6134
6143
  message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag ? `tag "${tagName}" must be string` : `value of tag "${tagName}" must be in oneOf`,
6135
6144
  params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._)`{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`
@@ -6246,9 +6255,9 @@ function requireAjv() {
6246
6255
  (function(module, exports) {
6247
6256
  Object.defineProperty(exports, "__esModule", { value: true });
6248
6257
  exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv = void 0;
6249
- const core_1 = requireCore$1();
6250
- const draft7_1 = requireDraft7();
6251
- const discriminator_1 = requireDiscriminator();
6258
+ const core_1 = /* @__PURE__ */ requireCore$1();
6259
+ const draft7_1 = /* @__PURE__ */ requireDraft7();
6260
+ const discriminator_1 = /* @__PURE__ */ requireDiscriminator();
6252
6261
  const draft7MetaSchema = require$$3;
6253
6262
  const META_SUPPORT_DATA = ["/properties"];
6254
6263
  const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
@@ -6276,11 +6285,11 @@ function requireAjv() {
6276
6285
  module.exports.Ajv = Ajv2;
6277
6286
  Object.defineProperty(exports, "__esModule", { value: true });
6278
6287
  exports.default = Ajv2;
6279
- var validate_1 = requireValidate();
6288
+ var validate_1 = /* @__PURE__ */ requireValidate();
6280
6289
  Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
6281
6290
  return validate_1.KeywordCxt;
6282
6291
  } });
6283
- var codegen_1 = requireCodegen();
6292
+ var codegen_1 = /* @__PURE__ */ requireCodegen();
6284
6293
  Object.defineProperty(exports, "_", { enumerable: true, get: function() {
6285
6294
  return codegen_1._;
6286
6295
  } });
@@ -6299,18 +6308,18 @@ function requireAjv() {
6299
6308
  Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
6300
6309
  return codegen_1.CodeGen;
6301
6310
  } });
6302
- var validation_error_1 = requireValidation_error();
6311
+ var validation_error_1 = /* @__PURE__ */ requireValidation_error();
6303
6312
  Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
6304
6313
  return validation_error_1.default;
6305
6314
  } });
6306
- var ref_error_1 = requireRef_error();
6315
+ var ref_error_1 = /* @__PURE__ */ requireRef_error();
6307
6316
  Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function() {
6308
6317
  return ref_error_1.default;
6309
6318
  } });
6310
6319
  })(ajv, ajv.exports);
6311
6320
  return ajv.exports;
6312
6321
  }
6313
- var ajvExports = requireAjv();
6322
+ var ajvExports = /* @__PURE__ */ requireAjv();
6314
6323
  const Ajv = /* @__PURE__ */ getDefaultExportFromCjs(ajvExports);
6315
6324
  var util;
6316
6325
  (function(util2) {
@@ -18621,8 +18630,8 @@ function requireLimit() {
18621
18630
  (function(exports) {
18622
18631
  Object.defineProperty(exports, "__esModule", { value: true });
18623
18632
  exports.formatLimitDefinition = void 0;
18624
- const ajv_1 = requireAjv();
18625
- const codegen_1 = requireCodegen();
18633
+ const ajv_1 = /* @__PURE__ */ requireAjv();
18634
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
18626
18635
  const ops = codegen_1.operators;
18627
18636
  const KWDs = {
18628
18637
  formatMaximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
@@ -18695,7 +18704,7 @@ function requireDist() {
18695
18704
  Object.defineProperty(exports, "__esModule", { value: true });
18696
18705
  const formats_1 = requireFormats();
18697
18706
  const limit_1 = requireLimit();
18698
- const codegen_1 = requireCodegen();
18707
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
18699
18708
  const fullName = new codegen_1.Name("fullFormats");
18700
18709
  const fastName = new codegen_1.Name("fastFormats");
18701
18710
  const formatsPlugin = (ajv2, opts = { keywords: true }) => {
@@ -28040,25 +28049,30 @@ function combineHeaders$1(...headers) {
28040
28049
  }
28041
28050
  function createToolNameMapping({
28042
28051
  tools = [],
28043
- providerToolNames
28052
+ providerToolNames,
28053
+ resolveProviderToolName
28044
28054
  }) {
28055
+ var _a22;
28045
28056
  const customToolNameToProviderToolName = {};
28046
28057
  const providerToolNameToCustomToolName = {};
28047
28058
  for (const tool2 of tools) {
28048
- if (tool2.type === "provider" && tool2.id in providerToolNames) {
28049
- const providerToolName = providerToolNames[tool2.id];
28059
+ if (tool2.type === "provider") {
28060
+ const providerToolName = (_a22 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a22 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
28061
+ if (providerToolName == null) {
28062
+ continue;
28063
+ }
28050
28064
  customToolNameToProviderToolName[tool2.name] = providerToolName;
28051
28065
  providerToolNameToCustomToolName[providerToolName] = tool2.name;
28052
28066
  }
28053
28067
  }
28054
28068
  return {
28055
28069
  toProviderToolName: (customToolName) => {
28056
- var _a22;
28057
- return (_a22 = customToolNameToProviderToolName[customToolName]) != null ? _a22 : customToolName;
28070
+ var _a32;
28071
+ return (_a32 = customToolNameToProviderToolName[customToolName]) != null ? _a32 : customToolName;
28058
28072
  },
28059
28073
  toCustomToolName: (providerToolName) => {
28060
- var _a22;
28061
- return (_a22 = providerToolNameToCustomToolName[providerToolName]) != null ? _a22 : providerToolName;
28074
+ var _a32;
28075
+ return (_a32 = providerToolNameToCustomToolName[providerToolName]) != null ? _a32 : providerToolName;
28062
28076
  }
28063
28077
  };
28064
28078
  }
@@ -28251,8 +28265,103 @@ async function readResponseWithSizeLimit({
28251
28265
  }
28252
28266
  return result;
28253
28267
  }
28268
+ function validateDownloadUrl(url2) {
28269
+ let parsed;
28270
+ try {
28271
+ parsed = new URL(url2);
28272
+ } catch (e) {
28273
+ throw new DownloadError({
28274
+ url: url2,
28275
+ message: `Invalid URL: ${url2}`
28276
+ });
28277
+ }
28278
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
28279
+ throw new DownloadError({
28280
+ url: url2,
28281
+ message: `URL scheme must be http or https, got ${parsed.protocol}`
28282
+ });
28283
+ }
28284
+ const hostname2 = parsed.hostname;
28285
+ if (!hostname2) {
28286
+ throw new DownloadError({
28287
+ url: url2,
28288
+ message: `URL must have a hostname`
28289
+ });
28290
+ }
28291
+ if (hostname2 === "localhost" || hostname2.endsWith(".local") || hostname2.endsWith(".localhost")) {
28292
+ throw new DownloadError({
28293
+ url: url2,
28294
+ message: `URL with hostname ${hostname2} is not allowed`
28295
+ });
28296
+ }
28297
+ if (hostname2.startsWith("[") && hostname2.endsWith("]")) {
28298
+ const ipv62 = hostname2.slice(1, -1);
28299
+ if (isPrivateIPv6(ipv62)) {
28300
+ throw new DownloadError({
28301
+ url: url2,
28302
+ message: `URL with IPv6 address ${hostname2} is not allowed`
28303
+ });
28304
+ }
28305
+ return;
28306
+ }
28307
+ if (isIPv4(hostname2)) {
28308
+ if (isPrivateIPv4(hostname2)) {
28309
+ throw new DownloadError({
28310
+ url: url2,
28311
+ message: `URL with IP address ${hostname2} is not allowed`
28312
+ });
28313
+ }
28314
+ return;
28315
+ }
28316
+ }
28317
+ function isIPv4(hostname2) {
28318
+ const parts = hostname2.split(".");
28319
+ if (parts.length !== 4) return false;
28320
+ return parts.every((part) => {
28321
+ const num = Number(part);
28322
+ return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
28323
+ });
28324
+ }
28325
+ function isPrivateIPv4(ip) {
28326
+ const parts = ip.split(".").map(Number);
28327
+ const [a, b] = parts;
28328
+ if (a === 0) return true;
28329
+ if (a === 10) return true;
28330
+ if (a === 127) return true;
28331
+ if (a === 169 && b === 254) return true;
28332
+ if (a === 172 && b >= 16 && b <= 31) return true;
28333
+ if (a === 192 && b === 168) return true;
28334
+ return false;
28335
+ }
28336
+ function isPrivateIPv6(ip) {
28337
+ const normalized = ip.toLowerCase();
28338
+ if (normalized === "::1") return true;
28339
+ if (normalized === "::") return true;
28340
+ if (normalized.startsWith("::ffff:")) {
28341
+ const mappedPart = normalized.slice(7);
28342
+ if (isIPv4(mappedPart)) {
28343
+ return isPrivateIPv4(mappedPart);
28344
+ }
28345
+ const hexParts = mappedPart.split(":");
28346
+ if (hexParts.length === 2) {
28347
+ const high = parseInt(hexParts[0], 16);
28348
+ const low = parseInt(hexParts[1], 16);
28349
+ if (!isNaN(high) && !isNaN(low)) {
28350
+ const a = high >> 8 & 255;
28351
+ const b = high & 255;
28352
+ const c = low >> 8 & 255;
28353
+ const d = low & 255;
28354
+ return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
28355
+ }
28356
+ }
28357
+ }
28358
+ if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
28359
+ if (normalized.startsWith("fe80")) return true;
28360
+ return false;
28361
+ }
28254
28362
  async function downloadBlob(url2, options) {
28255
28363
  var _a22, _b22;
28364
+ validateDownloadUrl(url2);
28256
28365
  try {
28257
28366
  const response = await fetch(url2, {
28258
28367
  signal: options == null ? void 0 : options.abortSignal
@@ -28418,7 +28527,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
28418
28527
  );
28419
28528
  return Object.fromEntries(normalizedHeaders.entries());
28420
28529
  }
28421
- var VERSION$7 = "4.0.15";
28530
+ var VERSION$7 = "4.0.19";
28422
28531
  var getOriginalFetch = () => globalThis.fetch;
28423
28532
  var getFromApi = async ({
28424
28533
  url: url2,
@@ -28561,8 +28670,8 @@ function mediaTypeToExtension(mediaType) {
28561
28670
  "x-m4a": "m4a"
28562
28671
  }[subtype]) != null ? _a22 : subtype;
28563
28672
  }
28564
- var suspectProtoRx$1 = /"__proto__"\s*:/;
28565
- var suspectConstructorRx$1 = /"constructor"\s*:/;
28673
+ var suspectProtoRx$1 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
28674
+ var suspectConstructorRx$1 = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
28566
28675
  function _parse$1(text2) {
28567
28676
  const obj = JSON.parse(text2);
28568
28677
  if (obj === null || typeof obj !== "object") {
@@ -28582,7 +28691,7 @@ function filter$1(obj) {
28582
28691
  if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
28583
28692
  throw new SyntaxError("Object contains forbidden prototype property");
28584
28693
  }
28585
- if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
28694
+ if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
28586
28695
  throw new SyntaxError("Object contains forbidden prototype property");
28587
28696
  }
28588
28697
  for (const key in node) {
@@ -30069,6 +30178,33 @@ function tool(tool2) {
30069
30178
  function dynamicTool(tool2) {
30070
30179
  return { ...tool2, type: "dynamic" };
30071
30180
  }
30181
+ function createProviderToolFactory({
30182
+ id: id2,
30183
+ inputSchema
30184
+ }) {
30185
+ return ({
30186
+ execute,
30187
+ outputSchema: outputSchema2,
30188
+ needsApproval,
30189
+ toModelOutput,
30190
+ onInputStart,
30191
+ onInputDelta,
30192
+ onInputAvailable,
30193
+ ...args
30194
+ }) => tool({
30195
+ type: "provider",
30196
+ id: id2,
30197
+ args,
30198
+ inputSchema,
30199
+ outputSchema: outputSchema2,
30200
+ execute,
30201
+ needsApproval,
30202
+ toModelOutput,
30203
+ onInputStart,
30204
+ onInputDelta,
30205
+ onInputAvailable
30206
+ });
30207
+ }
30072
30208
  function createProviderToolFactoryWithOutputSchema({
30073
30209
  id: id2,
30074
30210
  inputSchema,
@@ -31193,17 +31329,14 @@ var GatewayVideoModel = class {
31193
31329
  var _a92;
31194
31330
  const resolvedHeaders = await resolve(this.config.headers());
31195
31331
  try {
31196
- const {
31197
- responseHeaders,
31198
- value: responseBody,
31199
- rawValue
31200
- } = await postJsonToApi$1({
31332
+ const { responseHeaders, value: responseBody } = await postJsonToApi$1({
31201
31333
  url: this.getUrl(),
31202
31334
  headers: combineHeaders$1(
31203
31335
  resolvedHeaders,
31204
31336
  headers != null ? headers : {},
31205
31337
  this.getModelConfigHeaders(),
31206
- await resolve(this.config.o11yHeaders)
31338
+ await resolve(this.config.o11yHeaders),
31339
+ { accept: "text/event-stream" }
31207
31340
  ),
31208
31341
  body: {
31209
31342
  prompt,
@@ -31216,9 +31349,70 @@ var GatewayVideoModel = class {
31216
31349
  ...providerOptions && { providerOptions },
31217
31350
  ...image && { image: maybeEncodeVideoFile(image) }
31218
31351
  },
31219
- successfulResponseHandler: createJsonResponseHandler$1(
31220
- gatewayVideoResponseSchema
31221
- ),
31352
+ successfulResponseHandler: async ({
31353
+ response,
31354
+ url: url2,
31355
+ requestBodyValues
31356
+ }) => {
31357
+ if (response.body == null) {
31358
+ throw new APICallError$1({
31359
+ message: "SSE response body is empty",
31360
+ url: url2,
31361
+ requestBodyValues,
31362
+ statusCode: response.status
31363
+ });
31364
+ }
31365
+ const eventStream = parseJsonEventStream$1({
31366
+ stream: response.body,
31367
+ schema: gatewayVideoEventSchema
31368
+ });
31369
+ const reader = eventStream.getReader();
31370
+ const { done, value: parseResult } = await reader.read();
31371
+ reader.releaseLock();
31372
+ if (done || !parseResult) {
31373
+ throw new APICallError$1({
31374
+ message: "SSE stream ended without a data event",
31375
+ url: url2,
31376
+ requestBodyValues,
31377
+ statusCode: response.status
31378
+ });
31379
+ }
31380
+ if (!parseResult.success) {
31381
+ throw new APICallError$1({
31382
+ message: "Failed to parse video SSE event",
31383
+ cause: parseResult.error,
31384
+ url: url2,
31385
+ requestBodyValues,
31386
+ statusCode: response.status
31387
+ });
31388
+ }
31389
+ const event = parseResult.value;
31390
+ if (event.type === "error") {
31391
+ throw new APICallError$1({
31392
+ message: event.message,
31393
+ statusCode: event.statusCode,
31394
+ url: url2,
31395
+ requestBodyValues,
31396
+ responseHeaders: Object.fromEntries([...response.headers]),
31397
+ responseBody: JSON.stringify(event),
31398
+ data: {
31399
+ error: {
31400
+ message: event.message,
31401
+ type: event.errorType,
31402
+ param: event.param
31403
+ }
31404
+ }
31405
+ });
31406
+ }
31407
+ return {
31408
+ value: {
31409
+ videos: event.videos,
31410
+ warnings: event.warnings,
31411
+ providerMetadata: event.providerMetadata
31412
+ },
31413
+ responseHeaders: Object.fromEntries([...response.headers])
31414
+ };
31415
+ },
31222
31416
  failedResponseHandler: createJsonErrorResponseHandler$1({
31223
31417
  errorSchema: any(),
31224
31418
  errorToMessage: (data) => data
@@ -31290,11 +31484,21 @@ var gatewayVideoWarningSchema = discriminatedUnion("type", [
31290
31484
  message: string()
31291
31485
  })
31292
31486
  ]);
31293
- var gatewayVideoResponseSchema = object$2({
31294
- videos: array$1(gatewayVideoDataSchema),
31295
- warnings: array$1(gatewayVideoWarningSchema).optional(),
31296
- providerMetadata: record(string(), providerMetadataEntrySchema2).optional()
31297
- });
31487
+ var gatewayVideoEventSchema = discriminatedUnion("type", [
31488
+ object$2({
31489
+ type: literal("result"),
31490
+ videos: array$1(gatewayVideoDataSchema),
31491
+ warnings: array$1(gatewayVideoWarningSchema).optional(),
31492
+ providerMetadata: record(string(), providerMetadataEntrySchema2).optional()
31493
+ }),
31494
+ object$2({
31495
+ type: literal("error"),
31496
+ message: string(),
31497
+ errorType: string(),
31498
+ statusCode: number$1(),
31499
+ param: unknown().nullable()
31500
+ })
31501
+ ]);
31298
31502
  var parallelSearchInputSchema = lazySchema(
31299
31503
  () => zodSchema(
31300
31504
  objectType({
@@ -31471,7 +31675,7 @@ async function getVercelRequestId() {
31471
31675
  var _a92;
31472
31676
  return (_a92 = indexBrowserExports.getContext().headers) == null ? void 0 : _a92["x-vercel-id"];
31473
31677
  }
31474
- var VERSION$6 = "3.0.45";
31678
+ var VERSION$6 = "3.0.66";
31475
31679
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
31476
31680
  function createGatewayProvider(options = {}) {
31477
31681
  var _a92, _b9;
@@ -31514,13 +31718,18 @@ function createGatewayProvider(options = {}) {
31514
31718
  settingValue: void 0,
31515
31719
  environmentVariableName: "VERCEL_REGION"
31516
31720
  });
31721
+ const projectId = loadOptionalSetting({
31722
+ settingValue: void 0,
31723
+ environmentVariableName: "VERCEL_PROJECT_ID"
31724
+ });
31517
31725
  return async () => {
31518
31726
  const requestId = await getVercelRequestId();
31519
31727
  return {
31520
31728
  ...deploymentId && { "ai-o11y-deployment-id": deploymentId },
31521
31729
  ...environment && { "ai-o11y-environment": environment },
31522
31730
  ...region && { "ai-o11y-region": region },
31523
- ...requestId && { "ai-o11y-request-id": requestId }
31731
+ ...requestId && { "ai-o11y-request-id": requestId },
31732
+ ...projectId && { "ai-o11y-project-id": projectId }
31524
31733
  };
31525
31734
  };
31526
31735
  };
@@ -32599,6 +32808,19 @@ var RetryError = class extends AISDKError$1 {
32599
32808
  }
32600
32809
  };
32601
32810
  _a19 = symbol19;
32811
+ function asArray(value) {
32812
+ return value === void 0 ? [] : Array.isArray(value) ? value : [value];
32813
+ }
32814
+ async function notify(options) {
32815
+ for (const callback of asArray(options.callbacks)) {
32816
+ if (callback == null)
32817
+ continue;
32818
+ try {
32819
+ await callback(options.event);
32820
+ } catch (_ignored) {
32821
+ }
32822
+ }
32823
+ }
32602
32824
  function formatWarning({
32603
32825
  warning,
32604
32826
  provider,
@@ -32899,7 +33121,7 @@ function detectMediaType({
32899
33121
  }
32900
33122
  return void 0;
32901
33123
  }
32902
- var VERSION$4 = "6.0.85";
33124
+ var VERSION$4 = "6.0.116";
32903
33125
  var download = async ({
32904
33126
  url: url2,
32905
33127
  maxBytes,
@@ -32907,6 +33129,7 @@ var download = async ({
32907
33129
  }) => {
32908
33130
  var _a21;
32909
33131
  const urlText = url2.toString();
33132
+ validateDownloadUrl(urlText);
32910
33133
  try {
32911
33134
  const response = await fetch(urlText, {
32912
33135
  headers: withUserAgentSuffix$1(
@@ -33007,9 +33230,6 @@ function convertDataContentToBase64String(content) {
33007
33230
  }
33008
33231
  return convertUint8ArrayToBase64$1(content);
33009
33232
  }
33010
- function asArray(value) {
33011
- return value === void 0 ? [] : Array.isArray(value) ? value : [value];
33012
- }
33013
33233
  async function convertToLanguageModelPrompt({
33014
33234
  prompt,
33015
33235
  supportedUrls,
@@ -34015,6 +34235,44 @@ function stringifyForTelemetry(prompt) {
34015
34235
  }))
34016
34236
  );
34017
34237
  }
34238
+ function getGlobalTelemetryIntegrations() {
34239
+ var _a21;
34240
+ return (_a21 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a21 : [];
34241
+ }
34242
+ function getGlobalTelemetryIntegration() {
34243
+ const globalIntegrations = getGlobalTelemetryIntegrations();
34244
+ return (integrations) => {
34245
+ const localIntegrations = asArray(integrations);
34246
+ const allIntegrations = [...globalIntegrations, ...localIntegrations];
34247
+ function createTelemetryComposite(getListenerFromIntegration) {
34248
+ const listeners = allIntegrations.map(getListenerFromIntegration).filter(Boolean);
34249
+ return async (event) => {
34250
+ for (const listener of listeners) {
34251
+ try {
34252
+ await listener(event);
34253
+ } catch (_ignored) {
34254
+ }
34255
+ }
34256
+ };
34257
+ }
34258
+ return {
34259
+ onStart: createTelemetryComposite((integration) => integration.onStart),
34260
+ onStepStart: createTelemetryComposite(
34261
+ (integration) => integration.onStepStart
34262
+ ),
34263
+ onToolCallStart: createTelemetryComposite(
34264
+ (integration) => integration.onToolCallStart
34265
+ ),
34266
+ onToolCallFinish: createTelemetryComposite(
34267
+ (integration) => integration.onToolCallFinish
34268
+ ),
34269
+ onStepFinish: createTelemetryComposite(
34270
+ (integration) => integration.onStepFinish
34271
+ ),
34272
+ onFinish: createTelemetryComposite((integration) => integration.onFinish)
34273
+ };
34274
+ };
34275
+ }
34018
34276
  function asLanguageModelUsage(usage) {
34019
34277
  return {
34020
34278
  inputTokens: usage.inputTokens.total,
@@ -34324,6 +34582,10 @@ function collectToolApprovals({
34324
34582
  }
34325
34583
  return { approvedToolApprovals, deniedToolApprovals };
34326
34584
  }
34585
+ function now() {
34586
+ var _a21, _b9;
34587
+ return (_b9 = (_a21 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a21.now()) != null ? _b9 : Date.now();
34588
+ }
34327
34589
  async function executeToolCall({
34328
34590
  toolCall,
34329
34591
  tools,
@@ -34332,13 +34594,27 @@ async function executeToolCall({
34332
34594
  messages,
34333
34595
  abortSignal,
34334
34596
  experimental_context,
34335
- onPreliminaryToolResult
34597
+ stepNumber,
34598
+ model,
34599
+ onPreliminaryToolResult,
34600
+ onToolCallStart,
34601
+ onToolCallFinish
34336
34602
  }) {
34337
34603
  const { toolName, toolCallId, input } = toolCall;
34338
34604
  const tool2 = tools == null ? void 0 : tools[toolName];
34339
34605
  if ((tool2 == null ? void 0 : tool2.execute) == null) {
34340
34606
  return void 0;
34341
34607
  }
34608
+ const baseCallbackEvent = {
34609
+ stepNumber,
34610
+ model,
34611
+ toolCall,
34612
+ messages,
34613
+ abortSignal,
34614
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
34615
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
34616
+ experimental_context
34617
+ };
34342
34618
  return recordSpan({
34343
34619
  name: "ai.toolCall",
34344
34620
  attributes: selectTelemetryAttributes({
@@ -34358,6 +34634,8 @@ async function executeToolCall({
34358
34634
  tracer,
34359
34635
  fn: async (span) => {
34360
34636
  let output;
34637
+ await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
34638
+ const startTime = now();
34361
34639
  try {
34362
34640
  const stream = executeTool({
34363
34641
  execute: tool2.execute.bind(tool2),
@@ -34382,6 +34660,16 @@ async function executeToolCall({
34382
34660
  }
34383
34661
  }
34384
34662
  } catch (error) {
34663
+ const durationMs2 = now() - startTime;
34664
+ await notify({
34665
+ event: {
34666
+ ...baseCallbackEvent,
34667
+ success: false,
34668
+ error,
34669
+ durationMs: durationMs2
34670
+ },
34671
+ callbacks: onToolCallFinish
34672
+ });
34385
34673
  recordErrorOnSpan(span, error);
34386
34674
  return {
34387
34675
  type: "tool-error",
@@ -34393,6 +34681,16 @@ async function executeToolCall({
34393
34681
  ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {}
34394
34682
  };
34395
34683
  }
34684
+ const durationMs = now() - startTime;
34685
+ await notify({
34686
+ event: {
34687
+ ...baseCallbackEvent,
34688
+ success: true,
34689
+ output,
34690
+ durationMs
34691
+ },
34692
+ callbacks: onToolCallFinish
34693
+ });
34396
34694
  try {
34397
34695
  span.setAttributes(
34398
34696
  await selectTelemetryAttributes({
@@ -35256,6 +35554,11 @@ async function doParseToolCall({
35256
35554
  }
35257
35555
  var DefaultStepResult = class {
35258
35556
  constructor({
35557
+ stepNumber,
35558
+ model,
35559
+ functionId,
35560
+ metadata: metadata2,
35561
+ experimental_context,
35259
35562
  content,
35260
35563
  finishReason,
35261
35564
  rawFinishReason,
@@ -35265,6 +35568,11 @@ var DefaultStepResult = class {
35265
35568
  response,
35266
35569
  providerMetadata
35267
35570
  }) {
35571
+ this.stepNumber = stepNumber;
35572
+ this.model = model;
35573
+ this.functionId = functionId;
35574
+ this.metadata = metadata2;
35575
+ this.experimental_context = experimental_context;
35268
35576
  this.content = content;
35269
35577
  this.finishReason = finishReason;
35270
35578
  this.rawFinishReason = rawFinishReason;
@@ -35506,11 +35814,16 @@ async function generateText({
35506
35814
  experimental_context,
35507
35815
  experimental_include: include,
35508
35816
  _internal: { generateId: generateId2 = originalGenerateId } = {},
35817
+ experimental_onStart: onStart,
35818
+ experimental_onStepStart: onStepStart,
35819
+ experimental_onToolCallStart: onToolCallStart,
35820
+ experimental_onToolCallFinish: onToolCallFinish,
35509
35821
  onStepFinish,
35510
35822
  onFinish,
35511
35823
  ...settings
35512
35824
  }) {
35513
35825
  const model = resolveLanguageModel(modelArg);
35826
+ const createGlobalTelemetry = getGlobalTelemetryIntegration();
35514
35827
  const stopConditions = asArray(stopWhen);
35515
35828
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
35516
35829
  const stepTimeoutMs = getStepTimeoutMs(timeout);
@@ -35535,11 +35848,47 @@ async function generateText({
35535
35848
  headers: headersWithUserAgent,
35536
35849
  settings: { ...callSettings, maxRetries }
35537
35850
  });
35851
+ const modelInfo = { provider: model.provider, modelId: model.modelId };
35538
35852
  const initialPrompt = await standardizePrompt({
35539
35853
  system,
35540
35854
  prompt,
35541
35855
  messages
35542
35856
  });
35857
+ const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
35858
+ await notify({
35859
+ event: {
35860
+ model: modelInfo,
35861
+ system,
35862
+ prompt,
35863
+ messages,
35864
+ tools,
35865
+ toolChoice,
35866
+ activeTools,
35867
+ maxOutputTokens: callSettings.maxOutputTokens,
35868
+ temperature: callSettings.temperature,
35869
+ topP: callSettings.topP,
35870
+ topK: callSettings.topK,
35871
+ presencePenalty: callSettings.presencePenalty,
35872
+ frequencyPenalty: callSettings.frequencyPenalty,
35873
+ stopSequences: callSettings.stopSequences,
35874
+ seed: callSettings.seed,
35875
+ maxRetries,
35876
+ timeout,
35877
+ headers,
35878
+ providerOptions,
35879
+ stopWhen,
35880
+ output,
35881
+ abortSignal,
35882
+ include,
35883
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
35884
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
35885
+ experimental_context
35886
+ },
35887
+ callbacks: [
35888
+ onStart,
35889
+ globalTelemetry.onStart
35890
+ ]
35891
+ });
35543
35892
  const tracer = getTracer(telemetry);
35544
35893
  try {
35545
35894
  return await recordSpan({
@@ -35563,7 +35912,7 @@ async function generateText({
35563
35912
  }),
35564
35913
  tracer,
35565
35914
  fn: async (span) => {
35566
- var _a21, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k;
35915
+ var _a21, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
35567
35916
  const initialMessages = initialPrompt.messages;
35568
35917
  const responseMessages = [];
35569
35918
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
@@ -35580,7 +35929,17 @@ async function generateText({
35580
35929
  telemetry,
35581
35930
  messages: initialMessages,
35582
35931
  abortSignal: mergedAbortSignal,
35583
- experimental_context
35932
+ experimental_context,
35933
+ stepNumber: 0,
35934
+ model: modelInfo,
35935
+ onToolCallStart: [
35936
+ onToolCallStart,
35937
+ globalTelemetry.onToolCallStart
35938
+ ],
35939
+ onToolCallFinish: [
35940
+ onToolCallFinish,
35941
+ globalTelemetry.onToolCallFinish
35942
+ ]
35584
35943
  });
35585
35944
  const toolContent = [];
35586
35945
  for (const output2 of toolOutputs) {
@@ -35589,7 +35948,7 @@ async function generateText({
35589
35948
  input: output2.input,
35590
35949
  tool: tools == null ? void 0 : tools[output2.toolName],
35591
35950
  output: output2.type === "tool-result" ? output2.output : output2.error,
35592
- errorMode: output2.type === "tool-error" ? "json" : "none"
35951
+ errorMode: output2.type === "tool-error" ? "text" : "none"
35593
35952
  });
35594
35953
  toolContent.push({
35595
35954
  type: "tool-result",
@@ -35660,6 +36019,10 @@ async function generateText({
35660
36019
  const stepModel = resolveLanguageModel(
35661
36020
  (_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
35662
36021
  );
36022
+ const stepModelInfo = {
36023
+ provider: stepModel.provider,
36024
+ modelId: stepModel.modelId
36025
+ };
35663
36026
  const promptMessages = await convertToLanguageModelPrompt({
35664
36027
  prompt: {
35665
36028
  system: (_b9 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b9 : initialPrompt.system,
@@ -35669,10 +36032,43 @@ async function generateText({
35669
36032
  download: download2
35670
36033
  });
35671
36034
  experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
36035
+ const stepActiveTools = (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools;
35672
36036
  const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
35673
36037
  tools,
35674
- toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
35675
- activeTools: (_f = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _f : activeTools
36038
+ toolChoice: (_f = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _f : toolChoice,
36039
+ activeTools: stepActiveTools
36040
+ });
36041
+ const stepMessages = (_g = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _g : stepInputMessages;
36042
+ const stepSystem = (_h = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _h : initialPrompt.system;
36043
+ const stepProviderOptions = mergeObjects(
36044
+ providerOptions,
36045
+ prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
36046
+ );
36047
+ await notify({
36048
+ event: {
36049
+ stepNumber: steps.length,
36050
+ model: stepModelInfo,
36051
+ system: stepSystem,
36052
+ messages: stepMessages,
36053
+ tools,
36054
+ toolChoice: stepToolChoice,
36055
+ activeTools: stepActiveTools,
36056
+ steps: [...steps],
36057
+ providerOptions: stepProviderOptions,
36058
+ timeout,
36059
+ headers,
36060
+ stopWhen,
36061
+ output,
36062
+ abortSignal,
36063
+ include,
36064
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
36065
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
36066
+ experimental_context
36067
+ },
36068
+ callbacks: [
36069
+ onStepStart,
36070
+ globalTelemetry.onStepStart
36071
+ ]
35676
36072
  });
35677
36073
  currentModelResponse = await retry(
35678
36074
  () => {
@@ -35716,10 +36112,6 @@ async function generateText({
35716
36112
  tracer,
35717
36113
  fn: async (span2) => {
35718
36114
  var _a23, _b22, _c2, _d2, _e2, _f2, _g2, _h2;
35719
- const stepProviderOptions = mergeObjects(
35720
- providerOptions,
35721
- prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
35722
- );
35723
36115
  const result = await stepModel.doGenerate({
35724
36116
  ...callSettings2,
35725
36117
  tools: stepTools,
@@ -35851,7 +36243,17 @@ async function generateText({
35851
36243
  telemetry,
35852
36244
  messages: stepInputMessages,
35853
36245
  abortSignal: mergedAbortSignal,
35854
- experimental_context
36246
+ experimental_context,
36247
+ stepNumber: steps.length,
36248
+ model: stepModelInfo,
36249
+ onToolCallStart: [
36250
+ onToolCallStart,
36251
+ globalTelemetry.onToolCallStart
36252
+ ],
36253
+ onToolCallFinish: [
36254
+ onToolCallFinish,
36255
+ globalTelemetry.onToolCallFinish
36256
+ ]
35855
36257
  })
35856
36258
  );
35857
36259
  }
@@ -35888,15 +36290,21 @@ async function generateText({
35888
36290
  tools
35889
36291
  })
35890
36292
  );
35891
- const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? (_h = currentModelResponse.request) != null ? _h : {} : { ...currentModelResponse.request, body: void 0 };
36293
+ const stepRequest = ((_i = include == null ? void 0 : include.requestBody) != null ? _i : true) ? (_j = currentModelResponse.request) != null ? _j : {} : { ...currentModelResponse.request, body: void 0 };
35892
36294
  const stepResponse = {
35893
36295
  ...currentModelResponse.response,
35894
36296
  // deep clone msgs to avoid mutating past messages in multi-step:
35895
36297
  messages: structuredClone(responseMessages),
35896
36298
  // Conditionally include response body:
35897
- body: ((_i = include == null ? void 0 : include.responseBody) != null ? _i : true) ? (_j = currentModelResponse.response) == null ? void 0 : _j.body : void 0
36299
+ body: ((_k = include == null ? void 0 : include.responseBody) != null ? _k : true) ? (_l = currentModelResponse.response) == null ? void 0 : _l.body : void 0
35898
36300
  };
36301
+ const stepNumber = steps.length;
35899
36302
  const currentStepResult = new DefaultStepResult({
36303
+ stepNumber,
36304
+ model: stepModelInfo,
36305
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
36306
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
36307
+ experimental_context,
35900
36308
  content: stepContent,
35901
36309
  finishReason: currentModelResponse.finishReason.unified,
35902
36310
  rawFinishReason: currentModelResponse.finishReason.raw,
@@ -35907,12 +36315,15 @@ async function generateText({
35907
36315
  response: stepResponse
35908
36316
  });
35909
36317
  logWarnings({
35910
- warnings: (_k = currentModelResponse.warnings) != null ? _k : [],
35911
- provider: stepModel.provider,
35912
- model: stepModel.modelId
36318
+ warnings: (_m = currentModelResponse.warnings) != null ? _m : [],
36319
+ provider: stepModelInfo.provider,
36320
+ model: stepModelInfo.modelId
35913
36321
  });
35914
36322
  steps.push(currentStepResult);
35915
- await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
36323
+ await notify({
36324
+ event: currentStepResult,
36325
+ callbacks: [onStepFinish, globalTelemetry.onStepFinish]
36326
+ });
35916
36327
  } finally {
35917
36328
  if (stepTimeoutId != null) {
35918
36329
  clearTimeout(stepTimeoutId);
@@ -35964,30 +36375,40 @@ async function generateText({
35964
36375
  cachedInputTokens: void 0
35965
36376
  }
35966
36377
  );
35967
- await (onFinish == null ? void 0 : onFinish({
35968
- finishReason: lastStep.finishReason,
35969
- rawFinishReason: lastStep.rawFinishReason,
35970
- usage: lastStep.usage,
35971
- content: lastStep.content,
35972
- text: lastStep.text,
35973
- reasoningText: lastStep.reasoningText,
35974
- reasoning: lastStep.reasoning,
35975
- files: lastStep.files,
35976
- sources: lastStep.sources,
35977
- toolCalls: lastStep.toolCalls,
35978
- staticToolCalls: lastStep.staticToolCalls,
35979
- dynamicToolCalls: lastStep.dynamicToolCalls,
35980
- toolResults: lastStep.toolResults,
35981
- staticToolResults: lastStep.staticToolResults,
35982
- dynamicToolResults: lastStep.dynamicToolResults,
35983
- request: lastStep.request,
35984
- response: lastStep.response,
35985
- warnings: lastStep.warnings,
35986
- providerMetadata: lastStep.providerMetadata,
35987
- steps,
35988
- totalUsage,
35989
- experimental_context
35990
- }));
36378
+ await notify({
36379
+ event: {
36380
+ stepNumber: lastStep.stepNumber,
36381
+ model: lastStep.model,
36382
+ functionId: lastStep.functionId,
36383
+ metadata: lastStep.metadata,
36384
+ experimental_context: lastStep.experimental_context,
36385
+ finishReason: lastStep.finishReason,
36386
+ rawFinishReason: lastStep.rawFinishReason,
36387
+ usage: lastStep.usage,
36388
+ content: lastStep.content,
36389
+ text: lastStep.text,
36390
+ reasoningText: lastStep.reasoningText,
36391
+ reasoning: lastStep.reasoning,
36392
+ files: lastStep.files,
36393
+ sources: lastStep.sources,
36394
+ toolCalls: lastStep.toolCalls,
36395
+ staticToolCalls: lastStep.staticToolCalls,
36396
+ dynamicToolCalls: lastStep.dynamicToolCalls,
36397
+ toolResults: lastStep.toolResults,
36398
+ staticToolResults: lastStep.staticToolResults,
36399
+ dynamicToolResults: lastStep.dynamicToolResults,
36400
+ request: lastStep.request,
36401
+ response: lastStep.response,
36402
+ warnings: lastStep.warnings,
36403
+ providerMetadata: lastStep.providerMetadata,
36404
+ steps,
36405
+ totalUsage
36406
+ },
36407
+ callbacks: [
36408
+ onFinish,
36409
+ globalTelemetry.onFinish
36410
+ ]
36411
+ });
35991
36412
  let resolvedOutput;
35992
36413
  if (lastStep.finishReason === "stop") {
35993
36414
  const outputSpecification = output != null ? output : text();
@@ -36018,7 +36439,11 @@ async function executeTools({
36018
36439
  telemetry,
36019
36440
  messages,
36020
36441
  abortSignal,
36021
- experimental_context
36442
+ experimental_context,
36443
+ stepNumber,
36444
+ model,
36445
+ onToolCallStart,
36446
+ onToolCallFinish
36022
36447
  }) {
36023
36448
  const toolOutputs = await Promise.all(
36024
36449
  toolCalls.map(
@@ -36029,7 +36454,11 @@ async function executeTools({
36029
36454
  telemetry,
36030
36455
  messages,
36031
36456
  abortSignal,
36032
- experimental_context
36457
+ experimental_context,
36458
+ stepNumber,
36459
+ model,
36460
+ onToolCallStart,
36461
+ onToolCallFinish
36033
36462
  })
36034
36463
  )
36035
36464
  );
@@ -36597,7 +37026,8 @@ function processUIMessageStream({
36597
37026
  state.message.parts.push({
36598
37027
  type: "file",
36599
37028
  mediaType: chunk.mediaType,
36600
- url: chunk.url
37029
+ url: chunk.url,
37030
+ ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
36601
37031
  });
36602
37032
  write();
36603
37033
  break;
@@ -36722,7 +37152,9 @@ function processUIMessageStream({
36722
37152
  break;
36723
37153
  }
36724
37154
  case "tool-input-error": {
36725
- if (chunk.dynamic) {
37155
+ const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
37156
+ const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
37157
+ if (isDynamic) {
36726
37158
  updateDynamicToolPart({
36727
37159
  toolCallId: chunk.toolCallId,
36728
37160
  toolName: chunk.toolName,
@@ -37190,10 +37622,6 @@ function createStitchableStream() {
37190
37622
  terminate
37191
37623
  };
37192
37624
  }
37193
- function now() {
37194
- var _a21, _b9;
37195
- return (_b9 = (_a21 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a21.now()) != null ? _b9 : Date.now();
37196
- }
37197
37625
  function runToolsTransformation({
37198
37626
  tools,
37199
37627
  generatorStream,
@@ -37204,7 +37632,11 @@ function runToolsTransformation({
37204
37632
  abortSignal,
37205
37633
  repairToolCall,
37206
37634
  experimental_context,
37207
- generateId: generateId2
37635
+ generateId: generateId2,
37636
+ stepNumber,
37637
+ model,
37638
+ onToolCallStart,
37639
+ onToolCallFinish
37208
37640
  }) {
37209
37641
  let toolResultsStreamController = null;
37210
37642
  const toolResultsStream = new ReadableStream({
@@ -37252,7 +37684,8 @@ function runToolsTransformation({
37252
37684
  file: new DefaultGeneratedFileWithType({
37253
37685
  data: chunk.data,
37254
37686
  mediaType: chunk.mediaType
37255
- })
37687
+ }),
37688
+ ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
37256
37689
  });
37257
37690
  break;
37258
37691
  }
@@ -37346,6 +37779,10 @@ function runToolsTransformation({
37346
37779
  messages,
37347
37780
  abortSignal,
37348
37781
  experimental_context,
37782
+ stepNumber,
37783
+ model,
37784
+ onToolCallStart,
37785
+ onToolCallFinish,
37349
37786
  onPreliminaryToolResult: (result) => {
37350
37787
  toolResultsStreamController.enqueue(result);
37351
37788
  }
@@ -37462,6 +37899,10 @@ function streamText({
37462
37899
  onFinish,
37463
37900
  onAbort,
37464
37901
  onStepFinish,
37902
+ experimental_onStart: onStart,
37903
+ experimental_onStepStart: onStepStart,
37904
+ experimental_onToolCallStart: onToolCallStart,
37905
+ experimental_onToolCallFinish: onToolCallFinish,
37465
37906
  experimental_context,
37466
37907
  experimental_include: include,
37467
37908
  _internal: { now: now2 = now, generateId: generateId2 = originalGenerateId2 } = {},
@@ -37501,11 +37942,18 @@ function streamText({
37501
37942
  providerOptions,
37502
37943
  prepareStep,
37503
37944
  includeRawChunks,
37945
+ timeout,
37946
+ stopWhen,
37947
+ originalAbortSignal: abortSignal,
37504
37948
  onChunk,
37505
37949
  onError,
37506
37950
  onFinish,
37507
37951
  onAbort,
37508
37952
  onStepFinish,
37953
+ onStart,
37954
+ onStepStart,
37955
+ onToolCallStart,
37956
+ onToolCallFinish,
37509
37957
  now: now2,
37510
37958
  generateId: generateId2,
37511
37959
  experimental_context,
@@ -37602,11 +38050,18 @@ var DefaultStreamTextResult = class {
37602
38050
  includeRawChunks,
37603
38051
  now: now2,
37604
38052
  generateId: generateId2,
38053
+ timeout,
38054
+ stopWhen,
38055
+ originalAbortSignal,
37605
38056
  onChunk,
37606
38057
  onError,
37607
38058
  onFinish,
37608
38059
  onAbort,
37609
38060
  onStepFinish,
38061
+ onStart,
38062
+ onStepStart,
38063
+ onToolCallStart,
38064
+ onToolCallFinish,
37610
38065
  experimental_context,
37611
38066
  download: download2,
37612
38067
  include
@@ -37618,6 +38073,8 @@ var DefaultStreamTextResult = class {
37618
38073
  this.outputSpecification = output;
37619
38074
  this.includeRawChunks = includeRawChunks;
37620
38075
  this.tools = tools;
38076
+ const createGlobalTelemetry = getGlobalTelemetryIntegration();
38077
+ const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
37621
38078
  let stepFinish;
37622
38079
  let recordedContent = [];
37623
38080
  const recordedResponseMessages = [];
@@ -37719,7 +38176,11 @@ var DefaultStreamTextResult = class {
37719
38176
  delete activeReasoningContent[part.id];
37720
38177
  }
37721
38178
  if (part.type === "file") {
37722
- recordedContent.push({ type: "file", file: part.file });
38179
+ recordedContent.push({
38180
+ type: "file",
38181
+ file: part.file,
38182
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
38183
+ });
37723
38184
  }
37724
38185
  if (part.type === "source") {
37725
38186
  recordedContent.push(part);
@@ -37749,6 +38210,10 @@ var DefaultStreamTextResult = class {
37749
38210
  tools
37750
38211
  });
37751
38212
  const currentStepResult = new DefaultStepResult({
38213
+ stepNumber: recordedSteps.length,
38214
+ model: modelInfo,
38215
+ ...callbackTelemetryProps,
38216
+ experimental_context,
37752
38217
  content: recordedContent,
37753
38218
  finishReason: part.finishReason,
37754
38219
  rawFinishReason: part.rawFinishReason,
@@ -37761,11 +38226,14 @@ var DefaultStreamTextResult = class {
37761
38226
  },
37762
38227
  providerMetadata: part.providerMetadata
37763
38228
  });
37764
- await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
38229
+ await notify({
38230
+ event: currentStepResult,
38231
+ callbacks: [onStepFinish, globalTelemetry.onStepFinish]
38232
+ });
37765
38233
  logWarnings({
37766
38234
  warnings: recordedWarnings,
37767
- provider: model.provider,
37768
- model: model.modelId
38235
+ provider: modelInfo.provider,
38236
+ model: modelInfo.modelId
37769
38237
  });
37770
38238
  recordedSteps.push(currentStepResult);
37771
38239
  recordedResponseMessages.push(...stepMessages);
@@ -37796,30 +38264,40 @@ var DefaultStreamTextResult = class {
37796
38264
  self2._totalUsage.resolve(totalUsage);
37797
38265
  self2._steps.resolve(recordedSteps);
37798
38266
  const finalStep = recordedSteps[recordedSteps.length - 1];
37799
- await (onFinish == null ? void 0 : onFinish({
37800
- finishReason: finalStep.finishReason,
37801
- rawFinishReason: finalStep.rawFinishReason,
37802
- totalUsage,
37803
- usage: finalStep.usage,
37804
- content: finalStep.content,
37805
- text: finalStep.text,
37806
- reasoningText: finalStep.reasoningText,
37807
- reasoning: finalStep.reasoning,
37808
- files: finalStep.files,
37809
- sources: finalStep.sources,
37810
- toolCalls: finalStep.toolCalls,
37811
- staticToolCalls: finalStep.staticToolCalls,
37812
- dynamicToolCalls: finalStep.dynamicToolCalls,
37813
- toolResults: finalStep.toolResults,
37814
- staticToolResults: finalStep.staticToolResults,
37815
- dynamicToolResults: finalStep.dynamicToolResults,
37816
- request: finalStep.request,
37817
- response: finalStep.response,
37818
- warnings: finalStep.warnings,
37819
- providerMetadata: finalStep.providerMetadata,
37820
- steps: recordedSteps,
37821
- experimental_context
37822
- }));
38267
+ await notify({
38268
+ event: {
38269
+ stepNumber: finalStep.stepNumber,
38270
+ model: finalStep.model,
38271
+ functionId: finalStep.functionId,
38272
+ metadata: finalStep.metadata,
38273
+ experimental_context: finalStep.experimental_context,
38274
+ finishReason: finalStep.finishReason,
38275
+ rawFinishReason: finalStep.rawFinishReason,
38276
+ totalUsage,
38277
+ usage: finalStep.usage,
38278
+ content: finalStep.content,
38279
+ text: finalStep.text,
38280
+ reasoningText: finalStep.reasoningText,
38281
+ reasoning: finalStep.reasoning,
38282
+ files: finalStep.files,
38283
+ sources: finalStep.sources,
38284
+ toolCalls: finalStep.toolCalls,
38285
+ staticToolCalls: finalStep.staticToolCalls,
38286
+ dynamicToolCalls: finalStep.dynamicToolCalls,
38287
+ toolResults: finalStep.toolResults,
38288
+ staticToolResults: finalStep.staticToolResults,
38289
+ dynamicToolResults: finalStep.dynamicToolResults,
38290
+ request: finalStep.request,
38291
+ response: finalStep.response,
38292
+ warnings: finalStep.warnings,
38293
+ providerMetadata: finalStep.providerMetadata,
38294
+ steps: recordedSteps
38295
+ },
38296
+ callbacks: [
38297
+ onFinish,
38298
+ globalTelemetry.onFinish
38299
+ ]
38300
+ });
37823
38301
  rootSpan.setAttributes(
37824
38302
  await selectTelemetryAttributes({
37825
38303
  telemetry,
@@ -37920,6 +38398,11 @@ var DefaultStreamTextResult = class {
37920
38398
  settings: { ...callSettings, maxRetries }
37921
38399
  });
37922
38400
  const self2 = this;
38401
+ const modelInfo = { provider: model.provider, modelId: model.modelId };
38402
+ const callbackTelemetryProps = {
38403
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
38404
+ metadata: telemetry == null ? void 0 : telemetry.metadata
38405
+ };
37923
38406
  recordSpan({
37924
38407
  name: "ai.streamText",
37925
38408
  attributes: selectTelemetryAttributes({
@@ -37942,6 +38425,39 @@ var DefaultStreamTextResult = class {
37942
38425
  prompt,
37943
38426
  messages
37944
38427
  });
38428
+ await notify({
38429
+ event: {
38430
+ model: modelInfo,
38431
+ system,
38432
+ prompt,
38433
+ messages,
38434
+ tools,
38435
+ toolChoice,
38436
+ activeTools,
38437
+ maxOutputTokens: callSettings.maxOutputTokens,
38438
+ temperature: callSettings.temperature,
38439
+ topP: callSettings.topP,
38440
+ topK: callSettings.topK,
38441
+ presencePenalty: callSettings.presencePenalty,
38442
+ frequencyPenalty: callSettings.frequencyPenalty,
38443
+ stopSequences: callSettings.stopSequences,
38444
+ seed: callSettings.seed,
38445
+ maxRetries,
38446
+ timeout,
38447
+ headers,
38448
+ providerOptions,
38449
+ stopWhen,
38450
+ output,
38451
+ abortSignal: originalAbortSignal,
38452
+ include,
38453
+ ...callbackTelemetryProps,
38454
+ experimental_context
38455
+ },
38456
+ callbacks: [
38457
+ onStart,
38458
+ globalTelemetry.onStart
38459
+ ]
38460
+ });
37945
38461
  const initialMessages = initialPrompt.messages;
37946
38462
  const initialResponseMessages = [];
37947
38463
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
@@ -37988,6 +38504,16 @@ var DefaultStreamTextResult = class {
37988
38504
  messages: initialMessages,
37989
38505
  abortSignal,
37990
38506
  experimental_context,
38507
+ stepNumber: recordedSteps.length,
38508
+ model: modelInfo,
38509
+ onToolCallStart: [
38510
+ onToolCallStart,
38511
+ globalTelemetry.onToolCallStart
38512
+ ],
38513
+ onToolCallFinish: [
38514
+ onToolCallFinish,
38515
+ globalTelemetry.onToolCallFinish
38516
+ ],
37991
38517
  onPreliminaryToolResult: (result2) => {
37992
38518
  toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue(result2);
37993
38519
  }
@@ -38024,7 +38550,7 @@ var DefaultStreamTextResult = class {
38024
38550
  input: output2.input,
38025
38551
  tool: tools == null ? void 0 : tools[output2.toolName],
38026
38552
  output: output2.type === "tool-result" ? output2.output : output2.error,
38027
- errorMode: output2.type === "tool-error" ? "json" : "none"
38553
+ errorMode: output2.type === "tool-error" ? "text" : "none"
38028
38554
  })
38029
38555
  });
38030
38556
  }
@@ -38054,7 +38580,7 @@ var DefaultStreamTextResult = class {
38054
38580
  responseMessages,
38055
38581
  usage
38056
38582
  }) {
38057
- var _a21, _b9, _c, _d, _e, _f, _g;
38583
+ var _a21, _b9, _c, _d, _e, _f, _g, _h, _i;
38058
38584
  const includeRawChunks2 = self2.includeRawChunks;
38059
38585
  const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : void 0;
38060
38586
  let chunkTimeoutId = void 0;
@@ -38093,6 +38619,10 @@ var DefaultStreamTextResult = class {
38093
38619
  const stepModel = resolveLanguageModel(
38094
38620
  (_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
38095
38621
  );
38622
+ const stepModelInfo = {
38623
+ provider: stepModel.provider,
38624
+ modelId: stepModel.modelId
38625
+ };
38096
38626
  const promptMessages = await convertToLanguageModelPrompt({
38097
38627
  prompt: {
38098
38628
  system: (_b9 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b9 : initialPrompt.system,
@@ -38101,16 +38631,44 @@ var DefaultStreamTextResult = class {
38101
38631
  supportedUrls: await stepModel.supportedUrls,
38102
38632
  download: download2
38103
38633
  });
38634
+ const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
38104
38635
  const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
38105
38636
  tools,
38106
- toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
38107
- activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
38637
+ toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
38638
+ activeTools: stepActiveTools
38108
38639
  });
38109
38640
  experimental_context = (_f = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _f : experimental_context;
38641
+ const stepMessages = (_g = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _g : stepInputMessages;
38642
+ const stepSystem = (_h = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _h : initialPrompt.system;
38110
38643
  const stepProviderOptions = mergeObjects(
38111
38644
  providerOptions,
38112
38645
  prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
38113
38646
  );
38647
+ await notify({
38648
+ event: {
38649
+ stepNumber: recordedSteps.length,
38650
+ model: stepModelInfo,
38651
+ system: stepSystem,
38652
+ messages: stepMessages,
38653
+ tools,
38654
+ toolChoice: stepToolChoice,
38655
+ activeTools: stepActiveTools,
38656
+ steps: [...recordedSteps],
38657
+ providerOptions: stepProviderOptions,
38658
+ timeout,
38659
+ headers,
38660
+ stopWhen,
38661
+ output,
38662
+ abortSignal: originalAbortSignal,
38663
+ include,
38664
+ ...callbackTelemetryProps,
38665
+ experimental_context
38666
+ },
38667
+ callbacks: [
38668
+ onStepStart,
38669
+ globalTelemetry.onStepStart
38670
+ ]
38671
+ });
38114
38672
  const {
38115
38673
  result: { stream: stream2, response, request },
38116
38674
  doStreamSpan,
@@ -38182,9 +38740,19 @@ var DefaultStreamTextResult = class {
38182
38740
  repairToolCall,
38183
38741
  abortSignal,
38184
38742
  experimental_context,
38185
- generateId: generateId2
38743
+ generateId: generateId2,
38744
+ stepNumber: recordedSteps.length,
38745
+ model: stepModelInfo,
38746
+ onToolCallStart: [
38747
+ onToolCallStart,
38748
+ globalTelemetry.onToolCallStart
38749
+ ],
38750
+ onToolCallFinish: [
38751
+ onToolCallFinish,
38752
+ globalTelemetry.onToolCallFinish
38753
+ ]
38186
38754
  });
38187
- const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? request != null ? request : {} : { ...request, body: void 0 };
38755
+ const stepRequest = ((_i = include == null ? void 0 : include.requestBody) != null ? _i : true) ? request != null ? request : {} : { ...request, body: void 0 };
38188
38756
  const stepToolCalls = [];
38189
38757
  const stepToolOutputs = [];
38190
38758
  let warnings;
@@ -38197,7 +38765,7 @@ var DefaultStreamTextResult = class {
38197
38765
  let stepResponse = {
38198
38766
  id: generateId2(),
38199
38767
  timestamp: /* @__PURE__ */ new Date(),
38200
- modelId: model.modelId
38768
+ modelId: modelInfo.modelId
38201
38769
  };
38202
38770
  let activeText = "";
38203
38771
  self2.addStream(
@@ -38764,7 +39332,8 @@ var DefaultStreamTextResult = class {
38764
39332
  controller.enqueue({
38765
39333
  type: "file",
38766
39334
  mediaType: part.file.mediaType,
38767
- url: `data:${part.file.mediaType};base64,${part.file.base64}`
39335
+ url: `data:${part.file.mediaType};base64,${part.file.base64}`,
39336
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
38768
39337
  });
38769
39338
  break;
38770
39339
  }
@@ -41086,7 +41655,7 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler$1({
41086
41655
  function getOpenAILanguageModelCapabilities(modelId) {
41087
41656
  const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
41088
41657
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
41089
- const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("codex-mini") || modelId.startsWith("computer-use-preview") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
41658
+ const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
41090
41659
  const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
41091
41660
  const systemMessageMode = isReasoningModel ? "developer" : "system";
41092
41661
  return {
@@ -42021,7 +42590,7 @@ var OpenAIChatLanguageModel = class {
42021
42590
  for (const toolCallDelta of delta.tool_calls) {
42022
42591
  const index = toolCallDelta.index;
42023
42592
  if (toolCalls[index] == null) {
42024
- if (toolCallDelta.type !== "function") {
42593
+ if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
42025
42594
  throw new InvalidResponseDataError$1({
42026
42595
  data: toolCallDelta,
42027
42596
  message: `Expected 'function' type.`
@@ -42711,9 +43280,11 @@ var modelMaxImagesPerCall = {
42711
43280
  "dall-e-2": 10,
42712
43281
  "gpt-image-1": 10,
42713
43282
  "gpt-image-1-mini": 10,
42714
- "gpt-image-1.5": 10
43283
+ "gpt-image-1.5": 10,
43284
+ "chatgpt-image-latest": 10
42715
43285
  };
42716
43286
  var defaultResponseFormatPrefixes = [
43287
+ "chatgpt-image-",
42717
43288
  "gpt-image-1-mini",
42718
43289
  "gpt-image-1.5",
42719
43290
  "gpt-image-1"
@@ -42812,15 +43383,20 @@ var OpenAIImageModel = class {
42812
43383
  },
42813
43384
  providerMetadata: {
42814
43385
  openai: {
42815
- images: response2.data.map((item) => {
42816
- var _a22, _b22, _c2, _d2, _e2;
43386
+ images: response2.data.map((item, index) => {
43387
+ var _a22, _b22, _c2, _d2, _e2, _f2;
42817
43388
  return {
42818
43389
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
42819
43390
  created: (_a22 = response2.created) != null ? _a22 : void 0,
42820
43391
  size: (_b22 = response2.size) != null ? _b22 : void 0,
42821
43392
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
42822
43393
  background: (_d2 = response2.background) != null ? _d2 : void 0,
42823
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
43394
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
43395
+ ...distributeTokenDetails(
43396
+ (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
43397
+ index,
43398
+ response2.data.length
43399
+ )
42824
43400
  };
42825
43401
  })
42826
43402
  }
@@ -42863,15 +43439,20 @@ var OpenAIImageModel = class {
42863
43439
  },
42864
43440
  providerMetadata: {
42865
43441
  openai: {
42866
- images: response.data.map((item) => {
42867
- var _a22, _b22, _c2, _d2, _e2;
43442
+ images: response.data.map((item, index) => {
43443
+ var _a22, _b22, _c2, _d2, _e2, _f2;
42868
43444
  return {
42869
43445
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
42870
43446
  created: (_a22 = response.created) != null ? _a22 : void 0,
42871
43447
  size: (_b22 = response.size) != null ? _b22 : void 0,
42872
43448
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
42873
43449
  background: (_d2 = response.background) != null ? _d2 : void 0,
42874
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0
43450
+ outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
43451
+ ...distributeTokenDetails(
43452
+ (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
43453
+ index,
43454
+ response.data.length
43455
+ )
42875
43456
  };
42876
43457
  })
42877
43458
  }
@@ -42879,6 +43460,23 @@ var OpenAIImageModel = class {
42879
43460
  };
42880
43461
  }
42881
43462
  };
43463
+ function distributeTokenDetails(details, index, total) {
43464
+ if (details == null) {
43465
+ return {};
43466
+ }
43467
+ const result = {};
43468
+ if (details.image_tokens != null) {
43469
+ const base = Math.floor(details.image_tokens / total);
43470
+ const remainder = details.image_tokens - base * (total - 1);
43471
+ result.imageTokens = index === total - 1 ? remainder : base;
43472
+ }
43473
+ if (details.text_tokens != null) {
43474
+ const base = Math.floor(details.text_tokens / total);
43475
+ const remainder = details.text_tokens - base * (total - 1);
43476
+ result.textTokens = index === total - 1 ? remainder : base;
43477
+ }
43478
+ return result;
43479
+ }
42882
43480
  async function fileToBlob(file) {
42883
43481
  if (!file) return void 0;
42884
43482
  if (file.type === "url") {
@@ -42964,6 +43562,30 @@ var codeInterpreterToolFactory = createProviderToolFactoryWithOutputSchema({
42964
43562
  var codeInterpreter = (args = {}) => {
42965
43563
  return codeInterpreterToolFactory(args);
42966
43564
  };
43565
+ var customArgsSchema = lazySchema(
43566
+ () => zodSchema(
43567
+ object$2({
43568
+ name: string(),
43569
+ description: string().optional(),
43570
+ format: union([
43571
+ object$2({
43572
+ type: literal("grammar"),
43573
+ syntax: _enum(["regex", "lark"]),
43574
+ definition: string()
43575
+ }),
43576
+ object$2({
43577
+ type: literal("text")
43578
+ })
43579
+ ]).optional()
43580
+ })
43581
+ )
43582
+ );
43583
+ var customInputSchema = lazySchema(() => zodSchema(string()));
43584
+ var customToolFactory = createProviderToolFactory({
43585
+ id: "openai.custom",
43586
+ inputSchema: customInputSchema
43587
+ });
43588
+ var customTool = (args) => customToolFactory(args);
42967
43589
  var comparisonFilterSchema = object$2({
42968
43590
  key: string(),
42969
43591
  type: _enum(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
@@ -43089,6 +43711,67 @@ var shellOutputSchema = lazySchema(
43089
43711
  })
43090
43712
  )
43091
43713
  );
43714
+ var shellSkillsSchema = array$1(
43715
+ discriminatedUnion("type", [
43716
+ object$2({
43717
+ type: literal("skillReference"),
43718
+ skillId: string(),
43719
+ version: string().optional()
43720
+ }),
43721
+ object$2({
43722
+ type: literal("inline"),
43723
+ name: string(),
43724
+ description: string(),
43725
+ source: object$2({
43726
+ type: literal("base64"),
43727
+ mediaType: literal("application/zip"),
43728
+ data: string()
43729
+ })
43730
+ })
43731
+ ])
43732
+ ).optional();
43733
+ var shellArgsSchema = lazySchema(
43734
+ () => zodSchema(
43735
+ object$2({
43736
+ environment: union([
43737
+ object$2({
43738
+ type: literal("containerAuto"),
43739
+ fileIds: array$1(string()).optional(),
43740
+ memoryLimit: _enum(["1g", "4g", "16g", "64g"]).optional(),
43741
+ networkPolicy: discriminatedUnion("type", [
43742
+ object$2({ type: literal("disabled") }),
43743
+ object$2({
43744
+ type: literal("allowlist"),
43745
+ allowedDomains: array$1(string()),
43746
+ domainSecrets: array$1(
43747
+ object$2({
43748
+ domain: string(),
43749
+ name: string(),
43750
+ value: string()
43751
+ })
43752
+ ).optional()
43753
+ })
43754
+ ]).optional(),
43755
+ skills: shellSkillsSchema
43756
+ }),
43757
+ object$2({
43758
+ type: literal("containerReference"),
43759
+ containerId: string()
43760
+ }),
43761
+ object$2({
43762
+ type: literal("local").optional(),
43763
+ skills: array$1(
43764
+ object$2({
43765
+ name: string(),
43766
+ description: string(),
43767
+ path: string()
43768
+ })
43769
+ ).optional()
43770
+ })
43771
+ ]).optional()
43772
+ })
43773
+ )
43774
+ );
43092
43775
  var shell = createProviderToolFactoryWithOutputSchema({
43093
43776
  id: "openai.shell",
43094
43777
  inputSchema: shellInputSchema,
@@ -43128,7 +43811,7 @@ var webSearchOutputSchema = lazySchema(
43128
43811
  url: string().nullish(),
43129
43812
  pattern: string().nullish()
43130
43813
  })
43131
- ]),
43814
+ ]).optional(),
43132
43815
  sources: array$1(
43133
43816
  discriminatedUnion("type", [
43134
43817
  object$2({ type: literal("url"), url: string() }),
@@ -43178,7 +43861,7 @@ var webSearchPreviewOutputSchema = lazySchema(
43178
43861
  url: string().nullish(),
43179
43862
  pattern: string().nullish()
43180
43863
  })
43181
- ])
43864
+ ]).optional()
43182
43865
  })
43183
43866
  )
43184
43867
  );
@@ -43255,6 +43938,16 @@ var openaiTools = {
43255
43938
  *
43256
43939
  */
43257
43940
  applyPatch,
43941
+ /**
43942
+ * Custom tools let callers constrain model output to a grammar (regex or
43943
+ * Lark syntax). The model returns a `custom_tool_call` output item whose
43944
+ * `input` field is a string matching the specified grammar.
43945
+ *
43946
+ * @param name - The name of the custom tool.
43947
+ * @param description - An optional description of the tool.
43948
+ * @param format - The output format constraint (grammar type, syntax, and definition).
43949
+ */
43950
+ customTool,
43258
43951
  /**
43259
43952
  * The Code Interpreter tool allows models to write and run Python code in a
43260
43953
  * sandboxed environment to solve complex problems in domains like data analysis,
@@ -43295,7 +43988,7 @@ var openaiTools = {
43295
43988
  * Local shell is a tool that allows agents to run shell commands locally
43296
43989
  * on a machine you or the user provides.
43297
43990
  *
43298
- * Supported models: `gpt-5-codex` and `codex-mini-latest`
43991
+ * Supported models: `gpt-5-codex`
43299
43992
  */
43300
43993
  localShell,
43301
43994
  /**
@@ -43393,7 +44086,8 @@ async function convertToOpenAIResponsesInput({
43393
44086
  hasConversation = false,
43394
44087
  hasLocalShellTool = false,
43395
44088
  hasShellTool = false,
43396
- hasApplyPatchTool = false
44089
+ hasApplyPatchTool = false,
44090
+ customProviderToolNames
43397
44091
  }) {
43398
44092
  var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
43399
44093
  const input = [];
@@ -43476,7 +44170,9 @@ async function convertToOpenAIResponsesInput({
43476
44170
  for (const part of content) {
43477
44171
  switch (part.type) {
43478
44172
  case "text": {
43479
- const id2 = (_b9 = (_a10 = part.providerOptions) == null ? void 0 : _a10[providerOptionsName]) == null ? void 0 : _b9.itemId;
44173
+ const providerOpts = (_a10 = part.providerOptions) == null ? void 0 : _a10[providerOptionsName];
44174
+ const id2 = providerOpts == null ? void 0 : providerOpts.itemId;
44175
+ const phase = providerOpts == null ? void 0 : providerOpts.phase;
43480
44176
  if (hasConversation && id2 != null) {
43481
44177
  break;
43482
44178
  }
@@ -43487,12 +44183,13 @@ async function convertToOpenAIResponsesInput({
43487
44183
  input.push({
43488
44184
  role: "assistant",
43489
44185
  content: [{ type: "output_text", text: part.text }],
43490
- id: id2
44186
+ id: id2,
44187
+ ...phase != null && { phase }
43491
44188
  });
43492
44189
  break;
43493
44190
  }
43494
44191
  case "tool-call": {
43495
- const id2 = (_g = (_d = (_c = part.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.itemId) != null ? _g : (_f = (_e = part.providerMetadata) == null ? void 0 : _e[providerOptionsName]) == null ? void 0 : _f.itemId;
44192
+ const id2 = (_f = (_c = (_b9 = part.providerOptions) == null ? void 0 : _b9[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
43496
44193
  if (hasConversation && id2 != null) {
43497
44194
  break;
43498
44195
  }
@@ -43561,6 +44258,16 @@ async function convertToOpenAIResponsesInput({
43561
44258
  });
43562
44259
  break;
43563
44260
  }
44261
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
44262
+ input.push({
44263
+ type: "custom_tool_call",
44264
+ call_id: part.toolCallId,
44265
+ name: resolvedToolName,
44266
+ input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
44267
+ id: id2
44268
+ });
44269
+ break;
44270
+ }
43564
44271
  input.push({
43565
44272
  type: "function_call",
43566
44273
  call_id: part.toolCallId,
@@ -43578,8 +44285,32 @@ async function convertToOpenAIResponsesInput({
43578
44285
  if (hasConversation) {
43579
44286
  break;
43580
44287
  }
44288
+ const resolvedResultToolName = toolNameMapping.toProviderToolName(
44289
+ part.toolName
44290
+ );
44291
+ if (hasShellTool && resolvedResultToolName === "shell") {
44292
+ if (part.output.type === "json") {
44293
+ const parsedOutput = await validateTypes$1({
44294
+ value: part.output.value,
44295
+ schema: shellOutputSchema
44296
+ });
44297
+ input.push({
44298
+ type: "shell_call_output",
44299
+ call_id: part.toolCallId,
44300
+ output: parsedOutput.output.map((item) => ({
44301
+ stdout: item.stdout,
44302
+ stderr: item.stderr,
44303
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
44304
+ type: "exit",
44305
+ exit_code: item.outcome.exitCode
44306
+ }
44307
+ }))
44308
+ });
44309
+ }
44310
+ break;
44311
+ }
43581
44312
  if (store) {
43582
- const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
44313
+ const itemId = (_i = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.itemId) != null ? _i : part.toolCallId;
43583
44314
  input.push({ type: "item_reference", id: itemId });
43584
44315
  } else {
43585
44316
  warnings.push({
@@ -43639,10 +44370,26 @@ async function convertToOpenAIResponsesInput({
43639
44370
  }
43640
44371
  }
43641
44372
  } else {
43642
- warnings.push({
43643
- type: "other",
43644
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
43645
- });
44373
+ const encryptedContent = providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent;
44374
+ if (encryptedContent != null) {
44375
+ const summaryParts = [];
44376
+ if (part.text.length > 0) {
44377
+ summaryParts.push({
44378
+ type: "summary_text",
44379
+ text: part.text
44380
+ });
44381
+ }
44382
+ input.push({
44383
+ type: "reasoning",
44384
+ encrypted_content: encryptedContent,
44385
+ summary: summaryParts
44386
+ });
44387
+ } else {
44388
+ warnings.push({
44389
+ type: "other",
44390
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
44391
+ });
44392
+ }
43646
44393
  }
43647
44394
  break;
43648
44395
  }
@@ -43673,7 +44420,7 @@ async function convertToOpenAIResponsesInput({
43673
44420
  }
43674
44421
  const output = part.output;
43675
44422
  if (output.type === "execution-denied") {
43676
- const approvalId = (_l = (_k = output.providerOptions) == null ? void 0 : _k.openai) == null ? void 0 : _l.approvalId;
44423
+ const approvalId = (_k = (_j = output.providerOptions) == null ? void 0 : _j.openai) == null ? void 0 : _k.approvalId;
43677
44424
  if (approvalId) {
43678
44425
  continue;
43679
44426
  }
@@ -43725,6 +44472,61 @@ async function convertToOpenAIResponsesInput({
43725
44472
  });
43726
44473
  continue;
43727
44474
  }
44475
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
44476
+ let outputValue;
44477
+ switch (output.type) {
44478
+ case "text":
44479
+ case "error-text":
44480
+ outputValue = output.value;
44481
+ break;
44482
+ case "execution-denied":
44483
+ outputValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
44484
+ break;
44485
+ case "json":
44486
+ case "error-json":
44487
+ outputValue = JSON.stringify(output.value);
44488
+ break;
44489
+ case "content":
44490
+ outputValue = output.value.map((item) => {
44491
+ var _a22;
44492
+ switch (item.type) {
44493
+ case "text":
44494
+ return { type: "input_text", text: item.text };
44495
+ case "image-data":
44496
+ return {
44497
+ type: "input_image",
44498
+ image_url: `data:${item.mediaType};base64,${item.data}`
44499
+ };
44500
+ case "image-url":
44501
+ return {
44502
+ type: "input_image",
44503
+ image_url: item.url
44504
+ };
44505
+ case "file-data":
44506
+ return {
44507
+ type: "input_file",
44508
+ filename: (_a22 = item.filename) != null ? _a22 : "data",
44509
+ file_data: `data:${item.mediaType};base64,${item.data}`
44510
+ };
44511
+ default:
44512
+ warnings.push({
44513
+ type: "other",
44514
+ message: `unsupported custom tool content part type: ${item.type}`
44515
+ });
44516
+ return void 0;
44517
+ }
44518
+ }).filter(isNonNullable);
44519
+ break;
44520
+ default:
44521
+ outputValue = "";
44522
+ }
44523
+ input.push({
44524
+ type: "custom_tool_call_output",
44525
+ call_id: part.toolCallId,
44526
+ output: outputValue
44527
+ });
44528
+ continue;
44529
+ }
43728
44530
  let contentValue;
43729
44531
  switch (output.type) {
43730
44532
  case "text":
@@ -43859,7 +44661,8 @@ var openaiResponsesChunkSchema = lazySchema(
43859
44661
  item: discriminatedUnion("type", [
43860
44662
  object$2({
43861
44663
  type: literal("message"),
43862
- id: string()
44664
+ id: string(),
44665
+ phase: _enum(["commentary", "final_answer"]).nullish()
43863
44666
  }),
43864
44667
  object$2({
43865
44668
  type: literal("reasoning"),
@@ -43940,6 +44743,13 @@ var openaiResponsesChunkSchema = lazySchema(
43940
44743
  })
43941
44744
  ])
43942
44745
  }),
44746
+ object$2({
44747
+ type: literal("custom_tool_call"),
44748
+ id: string(),
44749
+ call_id: string(),
44750
+ name: string(),
44751
+ input: string()
44752
+ }),
43943
44753
  object$2({
43944
44754
  type: literal("shell_call"),
43945
44755
  id: string(),
@@ -43948,6 +44758,25 @@ var openaiResponsesChunkSchema = lazySchema(
43948
44758
  action: object$2({
43949
44759
  commands: array$1(string())
43950
44760
  })
44761
+ }),
44762
+ object$2({
44763
+ type: literal("shell_call_output"),
44764
+ id: string(),
44765
+ call_id: string(),
44766
+ status: _enum(["in_progress", "completed", "incomplete"]),
44767
+ output: array$1(
44768
+ object$2({
44769
+ stdout: string(),
44770
+ stderr: string(),
44771
+ outcome: discriminatedUnion("type", [
44772
+ object$2({ type: literal("timeout") }),
44773
+ object$2({
44774
+ type: literal("exit"),
44775
+ exit_code: number$1()
44776
+ })
44777
+ ])
44778
+ })
44779
+ )
43951
44780
  })
43952
44781
  ])
43953
44782
  }),
@@ -43957,7 +44786,8 @@ var openaiResponsesChunkSchema = lazySchema(
43957
44786
  item: discriminatedUnion("type", [
43958
44787
  object$2({
43959
44788
  type: literal("message"),
43960
- id: string()
44789
+ id: string(),
44790
+ phase: _enum(["commentary", "final_answer"]).nullish()
43961
44791
  }),
43962
44792
  object$2({
43963
44793
  type: literal("reasoning"),
@@ -43972,6 +44802,14 @@ var openaiResponsesChunkSchema = lazySchema(
43972
44802
  arguments: string(),
43973
44803
  status: literal("completed")
43974
44804
  }),
44805
+ object$2({
44806
+ type: literal("custom_tool_call"),
44807
+ id: string(),
44808
+ call_id: string(),
44809
+ name: string(),
44810
+ input: string(),
44811
+ status: literal("completed")
44812
+ }),
43975
44813
  object$2({
43976
44814
  type: literal("code_interpreter_call"),
43977
44815
  id: string(),
@@ -44013,7 +44851,7 @@ var openaiResponsesChunkSchema = lazySchema(
44013
44851
  url: string().nullish(),
44014
44852
  pattern: string().nullish()
44015
44853
  })
44016
- ])
44854
+ ]).nullish()
44017
44855
  }),
44018
44856
  object$2({
44019
44857
  type: literal("file_search_call"),
@@ -44127,6 +44965,25 @@ var openaiResponsesChunkSchema = lazySchema(
44127
44965
  action: object$2({
44128
44966
  commands: array$1(string())
44129
44967
  })
44968
+ }),
44969
+ object$2({
44970
+ type: literal("shell_call_output"),
44971
+ id: string(),
44972
+ call_id: string(),
44973
+ status: _enum(["in_progress", "completed", "incomplete"]),
44974
+ output: array$1(
44975
+ object$2({
44976
+ stdout: string(),
44977
+ stderr: string(),
44978
+ outcome: discriminatedUnion("type", [
44979
+ object$2({ type: literal("timeout") }),
44980
+ object$2({
44981
+ type: literal("exit"),
44982
+ exit_code: number$1()
44983
+ })
44984
+ ])
44985
+ })
44986
+ )
44130
44987
  })
44131
44988
  ])
44132
44989
  }),
@@ -44136,6 +44993,12 @@ var openaiResponsesChunkSchema = lazySchema(
44136
44993
  output_index: number$1(),
44137
44994
  delta: string()
44138
44995
  }),
44996
+ object$2({
44997
+ type: literal("response.custom_tool_call_input.delta"),
44998
+ item_id: string(),
44999
+ output_index: number$1(),
45000
+ delta: string()
45001
+ }),
44139
45002
  object$2({
44140
45003
  type: literal("response.image_generation_call.partial_image"),
44141
45004
  item_id: string(),
@@ -44250,6 +45113,7 @@ var openaiResponsesResponseSchema = lazySchema(
44250
45113
  type: literal("message"),
44251
45114
  role: literal("assistant"),
44252
45115
  id: string(),
45116
+ phase: _enum(["commentary", "final_answer"]).nullish(),
44253
45117
  content: array$1(
44254
45118
  object$2({
44255
45119
  type: literal("output_text"),
@@ -44310,7 +45174,10 @@ var openaiResponsesResponseSchema = lazySchema(
44310
45174
  sources: array$1(
44311
45175
  discriminatedUnion("type", [
44312
45176
  object$2({ type: literal("url"), url: string() }),
44313
- object$2({ type: literal("api"), name: string() })
45177
+ object$2({
45178
+ type: literal("api"),
45179
+ name: string()
45180
+ })
44314
45181
  ])
44315
45182
  ).nullish()
44316
45183
  }),
@@ -44323,7 +45190,7 @@ var openaiResponsesResponseSchema = lazySchema(
44323
45190
  url: string().nullish(),
44324
45191
  pattern: string().nullish()
44325
45192
  })
44326
- ])
45193
+ ]).nullish()
44327
45194
  }),
44328
45195
  object$2({
44329
45196
  type: literal("file_search_call"),
@@ -44379,6 +45246,13 @@ var openaiResponsesResponseSchema = lazySchema(
44379
45246
  arguments: string(),
44380
45247
  id: string()
44381
45248
  }),
45249
+ object$2({
45250
+ type: literal("custom_tool_call"),
45251
+ call_id: string(),
45252
+ name: string(),
45253
+ input: string(),
45254
+ id: string()
45255
+ }),
44382
45256
  object$2({
44383
45257
  type: literal("computer_call"),
44384
45258
  id: string(),
@@ -44472,6 +45346,25 @@ var openaiResponsesResponseSchema = lazySchema(
44472
45346
  action: object$2({
44473
45347
  commands: array$1(string())
44474
45348
  })
45349
+ }),
45350
+ object$2({
45351
+ type: literal("shell_call_output"),
45352
+ id: string(),
45353
+ call_id: string(),
45354
+ status: _enum(["in_progress", "completed", "incomplete"]),
45355
+ output: array$1(
45356
+ object$2({
45357
+ stdout: string(),
45358
+ stderr: string(),
45359
+ outcome: discriminatedUnion("type", [
45360
+ object$2({ type: literal("timeout") }),
45361
+ object$2({
45362
+ type: literal("exit"),
45363
+ exit_code: number$1()
45364
+ })
45365
+ ])
45366
+ })
45367
+ )
44475
45368
  })
44476
45369
  ])
44477
45370
  ).optional(),
@@ -44643,14 +45536,18 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema(
44643
45536
  );
44644
45537
  async function prepareResponsesTools({
44645
45538
  tools,
44646
- toolChoice
45539
+ toolChoice,
45540
+ toolNameMapping,
45541
+ customProviderToolNames
44647
45542
  }) {
45543
+ var _a10;
44648
45544
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
44649
45545
  const toolWarnings = [];
44650
45546
  if (tools == null) {
44651
45547
  return { tools: void 0, toolChoice: void 0, toolWarnings };
44652
45548
  }
44653
45549
  const openaiTools2 = [];
45550
+ const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
44654
45551
  for (const tool2 of tools) {
44655
45552
  switch (tool2.type) {
44656
45553
  case "function":
@@ -44688,8 +45585,15 @@ async function prepareResponsesTools({
44688
45585
  break;
44689
45586
  }
44690
45587
  case "openai.shell": {
45588
+ const args = await validateTypes$1({
45589
+ value: tool2.args,
45590
+ schema: shellArgsSchema
45591
+ });
44691
45592
  openaiTools2.push({
44692
- type: "shell"
45593
+ type: "shell",
45594
+ ...args.environment && {
45595
+ environment: mapShellEnvironment(args.environment)
45596
+ }
44693
45597
  });
44694
45598
  break;
44695
45599
  }
@@ -44785,6 +45689,20 @@ async function prepareResponsesTools({
44785
45689
  });
44786
45690
  break;
44787
45691
  }
45692
+ case "openai.custom": {
45693
+ const args = await validateTypes$1({
45694
+ value: tool2.args,
45695
+ schema: customArgsSchema
45696
+ });
45697
+ openaiTools2.push({
45698
+ type: "custom",
45699
+ name: args.name,
45700
+ description: args.description,
45701
+ format: args.format
45702
+ });
45703
+ resolvedCustomProviderToolNames.add(args.name);
45704
+ break;
45705
+ }
44788
45706
  }
44789
45707
  break;
44790
45708
  }
@@ -44805,12 +45723,14 @@ async function prepareResponsesTools({
44805
45723
  case "none":
44806
45724
  case "required":
44807
45725
  return { tools: openaiTools2, toolChoice: type2, toolWarnings };
44808
- case "tool":
45726
+ case "tool": {
45727
+ const resolvedToolName = (_a10 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a10 : toolChoice.toolName;
44809
45728
  return {
44810
45729
  tools: openaiTools2,
44811
- toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "image_generation" || toolChoice.toolName === "web_search_preview" || toolChoice.toolName === "web_search" || toolChoice.toolName === "mcp" || toolChoice.toolName === "apply_patch" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
45730
+ toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? { type: "custom", name: resolvedToolName } : { type: "function", name: resolvedToolName },
44812
45731
  toolWarnings
44813
45732
  };
45733
+ }
44814
45734
  default: {
44815
45735
  const _exhaustiveCheck = type2;
44816
45736
  throw new UnsupportedFunctionalityError$1({
@@ -44819,6 +45739,52 @@ async function prepareResponsesTools({
44819
45739
  }
44820
45740
  }
44821
45741
  }
45742
+ function mapShellEnvironment(environment) {
45743
+ if (environment.type === "containerReference") {
45744
+ const env2 = environment;
45745
+ return {
45746
+ type: "container_reference",
45747
+ container_id: env2.containerId
45748
+ };
45749
+ }
45750
+ if (environment.type === "containerAuto") {
45751
+ const env2 = environment;
45752
+ return {
45753
+ type: "container_auto",
45754
+ file_ids: env2.fileIds,
45755
+ memory_limit: env2.memoryLimit,
45756
+ network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
45757
+ type: "allowlist",
45758
+ allowed_domains: env2.networkPolicy.allowedDomains,
45759
+ domain_secrets: env2.networkPolicy.domainSecrets
45760
+ },
45761
+ skills: mapShellSkills(env2.skills)
45762
+ };
45763
+ }
45764
+ const env = environment;
45765
+ return {
45766
+ type: "local",
45767
+ skills: env.skills
45768
+ };
45769
+ }
45770
+ function mapShellSkills(skills) {
45771
+ return skills == null ? void 0 : skills.map(
45772
+ (skill) => skill.type === "skillReference" ? {
45773
+ type: "skill_reference",
45774
+ skill_id: skill.skillId,
45775
+ version: skill.version
45776
+ } : {
45777
+ type: "inline",
45778
+ name: skill.name,
45779
+ description: skill.description,
45780
+ source: {
45781
+ type: "base64",
45782
+ media_type: skill.source.mediaType,
45783
+ data: skill.source.data
45784
+ }
45785
+ }
45786
+ );
45787
+ }
44822
45788
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
44823
45789
  var _a10, _b9;
44824
45790
  const mapping = {};
@@ -44862,7 +45828,7 @@ var OpenAIResponsesLanguageModel = class {
44862
45828
  toolChoice,
44863
45829
  responseFormat
44864
45830
  }) {
44865
- var _a10, _b9, _c, _d, _e, _f;
45831
+ var _a10, _b9, _c, _d, _e, _f, _g, _h, _i;
44866
45832
  const warnings = [];
44867
45833
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
44868
45834
  if (topK != null) {
@@ -44913,7 +45879,19 @@ var OpenAIResponsesLanguageModel = class {
44913
45879
  "openai.web_search_preview": "web_search_preview",
44914
45880
  "openai.mcp": "mcp",
44915
45881
  "openai.apply_patch": "apply_patch"
44916
- }
45882
+ },
45883
+ resolveProviderToolName: (tool2) => tool2.id === "openai.custom" ? tool2.args.name : void 0
45884
+ });
45885
+ const customProviderToolNames = /* @__PURE__ */ new Set();
45886
+ const {
45887
+ tools: openaiTools2,
45888
+ toolChoice: openaiToolChoice,
45889
+ toolWarnings
45890
+ } = await prepareResponsesTools({
45891
+ tools,
45892
+ toolChoice,
45893
+ toolNameMapping,
45894
+ customProviderToolNames
44917
45895
  });
44918
45896
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
44919
45897
  prompt,
@@ -44925,7 +45903,8 @@ var OpenAIResponsesLanguageModel = class {
44925
45903
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
44926
45904
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
44927
45905
  hasShellTool: hasOpenAITool("openai.shell"),
44928
- hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
45906
+ hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
45907
+ customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
44929
45908
  });
44930
45909
  warnings.push(...inputWarnings);
44931
45910
  const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
@@ -45058,14 +46037,10 @@ var OpenAIResponsesLanguageModel = class {
45058
46037
  });
45059
46038
  delete baseArgs.service_tier;
45060
46039
  }
45061
- const {
45062
- tools: openaiTools2,
45063
- toolChoice: openaiToolChoice,
45064
- toolWarnings
45065
- } = await prepareResponsesTools({
45066
- tools,
45067
- toolChoice
45068
- });
46040
+ const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
46041
+ (tool2) => tool2.type === "provider" && tool2.id === "openai.shell"
46042
+ )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
46043
+ const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
45069
46044
  return {
45070
46045
  webSearchToolName,
45071
46046
  args: {
@@ -45076,7 +46051,8 @@ var OpenAIResponsesLanguageModel = class {
45076
46051
  warnings: [...warnings, ...toolWarnings],
45077
46052
  store,
45078
46053
  toolNameMapping,
45079
- providerOptionsName
46054
+ providerOptionsName,
46055
+ isShellProviderExecuted
45080
46056
  };
45081
46057
  }
45082
46058
  async doGenerate(options) {
@@ -45086,7 +46062,8 @@ var OpenAIResponsesLanguageModel = class {
45086
46062
  warnings,
45087
46063
  webSearchToolName,
45088
46064
  toolNameMapping,
45089
- providerOptionsName
46065
+ providerOptionsName,
46066
+ isShellProviderExecuted
45090
46067
  } = await this.getArgs(options);
45091
46068
  const url2 = this.config.url({
45092
46069
  path: "/responses",
@@ -45186,6 +46163,7 @@ var OpenAIResponsesLanguageModel = class {
45186
46163
  commands: part.action.commands
45187
46164
  }
45188
46165
  }),
46166
+ ...isShellProviderExecuted && { providerExecuted: true },
45189
46167
  providerMetadata: {
45190
46168
  [providerOptionsName]: {
45191
46169
  itemId: part.id
@@ -45194,6 +46172,24 @@ var OpenAIResponsesLanguageModel = class {
45194
46172
  });
45195
46173
  break;
45196
46174
  }
46175
+ case "shell_call_output": {
46176
+ content.push({
46177
+ type: "tool-result",
46178
+ toolCallId: part.call_id,
46179
+ toolName: toolNameMapping.toCustomToolName("shell"),
46180
+ result: {
46181
+ output: part.output.map((item) => ({
46182
+ stdout: item.stdout,
46183
+ stderr: item.stderr,
46184
+ outcome: item.outcome.type === "exit" ? {
46185
+ type: "exit",
46186
+ exitCode: item.outcome.exit_code
46187
+ } : { type: "timeout" }
46188
+ }))
46189
+ }
46190
+ });
46191
+ break;
46192
+ }
45197
46193
  case "message": {
45198
46194
  for (const contentPart of part.content) {
45199
46195
  if (((_c = (_b9 = options.providerOptions) == null ? void 0 : _b9[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
@@ -45201,6 +46197,7 @@ var OpenAIResponsesLanguageModel = class {
45201
46197
  }
45202
46198
  const providerMetadata2 = {
45203
46199
  itemId: part.id,
46200
+ ...part.phase != null && { phase: part.phase },
45204
46201
  ...contentPart.annotations.length > 0 && {
45205
46202
  annotations: contentPart.annotations
45206
46203
  }
@@ -45289,6 +46286,22 @@ var OpenAIResponsesLanguageModel = class {
45289
46286
  });
45290
46287
  break;
45291
46288
  }
46289
+ case "custom_tool_call": {
46290
+ hasFunctionCall = true;
46291
+ const toolName = toolNameMapping.toCustomToolName(part.name);
46292
+ content.push({
46293
+ type: "tool-call",
46294
+ toolCallId: part.call_id,
46295
+ toolName,
46296
+ input: JSON.stringify(part.input),
46297
+ providerMetadata: {
46298
+ [providerOptionsName]: {
46299
+ itemId: part.id
46300
+ }
46301
+ }
46302
+ });
46303
+ break;
46304
+ }
45292
46305
  case "web_search_call": {
45293
46306
  content.push({
45294
46307
  type: "tool-call",
@@ -45483,7 +46496,8 @@ var OpenAIResponsesLanguageModel = class {
45483
46496
  webSearchToolName,
45484
46497
  toolNameMapping,
45485
46498
  store,
45486
- providerOptionsName
46499
+ providerOptionsName,
46500
+ isShellProviderExecuted
45487
46501
  } = await this.getArgs(options);
45488
46502
  const { responseHeaders, value: response } = await postJsonToApi$1({
45489
46503
  url: this.config.url({
@@ -45514,6 +46528,7 @@ var OpenAIResponsesLanguageModel = class {
45514
46528
  let responseId = null;
45515
46529
  const ongoingToolCalls = {};
45516
46530
  const ongoingAnnotations = [];
46531
+ let activeMessagePhase;
45517
46532
  let hasFunctionCall = false;
45518
46533
  const activeReasoning = {};
45519
46534
  let serviceTier;
@@ -45524,7 +46539,7 @@ var OpenAIResponsesLanguageModel = class {
45524
46539
  controller.enqueue({ type: "stream-start", warnings });
45525
46540
  },
45526
46541
  transform(chunk, controller) {
45527
- var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
46542
+ var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
45528
46543
  if (options.includeRawChunks) {
45529
46544
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
45530
46545
  }
@@ -45545,6 +46560,19 @@ var OpenAIResponsesLanguageModel = class {
45545
46560
  id: value.item.call_id,
45546
46561
  toolName: value.item.name
45547
46562
  });
46563
+ } else if (value.item.type === "custom_tool_call") {
46564
+ const toolName = toolNameMapping.toCustomToolName(
46565
+ value.item.name
46566
+ );
46567
+ ongoingToolCalls[value.output_index] = {
46568
+ toolName,
46569
+ toolCallId: value.item.call_id
46570
+ };
46571
+ controller.enqueue({
46572
+ type: "tool-input-start",
46573
+ id: value.item.call_id,
46574
+ toolName
46575
+ });
45548
46576
  } else if (value.item.type === "web_search_call") {
45549
46577
  ongoingToolCalls[value.output_index] = {
45550
46578
  toolName: toolNameMapping.toCustomToolName(
@@ -45662,14 +46690,19 @@ var OpenAIResponsesLanguageModel = class {
45662
46690
  toolName: toolNameMapping.toCustomToolName("shell"),
45663
46691
  toolCallId: value.item.call_id
45664
46692
  };
45665
- } else if (value.item.type === "message") {
46693
+ } else if (value.item.type === "shell_call_output") ;
46694
+ else if (value.item.type === "message") {
45666
46695
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
46696
+ activeMessagePhase = (_a10 = value.item.phase) != null ? _a10 : void 0;
45667
46697
  controller.enqueue({
45668
46698
  type: "text-start",
45669
46699
  id: value.item.id,
45670
46700
  providerMetadata: {
45671
46701
  [providerOptionsName]: {
45672
- itemId: value.item.id
46702
+ itemId: value.item.id,
46703
+ ...value.item.phase != null && {
46704
+ phase: value.item.phase
46705
+ }
45673
46706
  }
45674
46707
  }
45675
46708
  });
@@ -45684,19 +46717,22 @@ var OpenAIResponsesLanguageModel = class {
45684
46717
  providerMetadata: {
45685
46718
  [providerOptionsName]: {
45686
46719
  itemId: value.item.id,
45687
- reasoningEncryptedContent: (_a10 = value.item.encrypted_content) != null ? _a10 : null
46720
+ reasoningEncryptedContent: (_b9 = value.item.encrypted_content) != null ? _b9 : null
45688
46721
  }
45689
46722
  }
45690
46723
  });
45691
46724
  }
45692
46725
  } else if (isResponseOutputItemDoneChunk(value)) {
45693
46726
  if (value.item.type === "message") {
46727
+ const phase = (_c = value.item.phase) != null ? _c : activeMessagePhase;
46728
+ activeMessagePhase = void 0;
45694
46729
  controller.enqueue({
45695
46730
  type: "text-end",
45696
46731
  id: value.item.id,
45697
46732
  providerMetadata: {
45698
46733
  [providerOptionsName]: {
45699
46734
  itemId: value.item.id,
46735
+ ...phase != null && { phase },
45700
46736
  ...ongoingAnnotations.length > 0 && {
45701
46737
  annotations: ongoingAnnotations
45702
46738
  }
@@ -45721,6 +46757,27 @@ var OpenAIResponsesLanguageModel = class {
45721
46757
  }
45722
46758
  }
45723
46759
  });
46760
+ } else if (value.item.type === "custom_tool_call") {
46761
+ ongoingToolCalls[value.output_index] = void 0;
46762
+ hasFunctionCall = true;
46763
+ const toolName = toolNameMapping.toCustomToolName(
46764
+ value.item.name
46765
+ );
46766
+ controller.enqueue({
46767
+ type: "tool-input-end",
46768
+ id: value.item.call_id
46769
+ });
46770
+ controller.enqueue({
46771
+ type: "tool-call",
46772
+ toolCallId: value.item.call_id,
46773
+ toolName,
46774
+ input: JSON.stringify(value.item.input),
46775
+ providerMetadata: {
46776
+ [providerOptionsName]: {
46777
+ itemId: value.item.id
46778
+ }
46779
+ }
46780
+ });
45724
46781
  } else if (value.item.type === "web_search_call") {
45725
46782
  ongoingToolCalls[value.output_index] = void 0;
45726
46783
  controller.enqueue({
@@ -45761,13 +46818,13 @@ var OpenAIResponsesLanguageModel = class {
45761
46818
  toolName: toolNameMapping.toCustomToolName("file_search"),
45762
46819
  result: {
45763
46820
  queries: value.item.queries,
45764
- results: (_c = (_b9 = value.item.results) == null ? void 0 : _b9.map((result) => ({
46821
+ results: (_e = (_d = value.item.results) == null ? void 0 : _d.map((result) => ({
45765
46822
  attributes: result.attributes,
45766
46823
  fileId: result.file_id,
45767
46824
  filename: result.filename,
45768
46825
  score: result.score,
45769
46826
  text: result.text
45770
- }))) != null ? _c : null
46827
+ }))) != null ? _e : null
45771
46828
  }
45772
46829
  });
45773
46830
  } else if (value.item.type === "code_interpreter_call") {
@@ -45791,10 +46848,10 @@ var OpenAIResponsesLanguageModel = class {
45791
46848
  });
45792
46849
  } else if (value.item.type === "mcp_call") {
45793
46850
  ongoingToolCalls[value.output_index] = void 0;
45794
- const approvalRequestId = (_d = value.item.approval_request_id) != null ? _d : void 0;
45795
- const aliasedToolCallId = approvalRequestId != null ? (_f = (_e = approvalRequestIdToDummyToolCallIdFromStream.get(
46851
+ const approvalRequestId = (_f = value.item.approval_request_id) != null ? _f : void 0;
46852
+ const aliasedToolCallId = approvalRequestId != null ? (_h = (_g = approvalRequestIdToDummyToolCallIdFromStream.get(
45796
46853
  approvalRequestId
45797
- )) != null ? _e : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _f : value.item.id : value.item.id;
46854
+ )) != null ? _g : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _h : value.item.id : value.item.id;
45798
46855
  const toolName = `mcp.${value.item.name}`;
45799
46856
  controller.enqueue({
45800
46857
  type: "tool-call",
@@ -45864,8 +46921,8 @@ var OpenAIResponsesLanguageModel = class {
45864
46921
  ongoingToolCalls[value.output_index] = void 0;
45865
46922
  } else if (value.item.type === "mcp_approval_request") {
45866
46923
  ongoingToolCalls[value.output_index] = void 0;
45867
- const dummyToolCallId = (_i = (_h = (_g = self2.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId$1();
45868
- const approvalRequestId = (_j = value.item.approval_request_id) != null ? _j : value.item.id;
46924
+ const dummyToolCallId = (_k = (_j = (_i = self2.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId$1();
46925
+ const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : value.item.id;
45869
46926
  approvalRequestIdToDummyToolCallIdFromStream.set(
45870
46927
  approvalRequestId,
45871
46928
  dummyToolCallId
@@ -45915,10 +46972,31 @@ var OpenAIResponsesLanguageModel = class {
45915
46972
  commands: value.item.action.commands
45916
46973
  }
45917
46974
  }),
46975
+ ...isShellProviderExecuted && {
46976
+ providerExecuted: true
46977
+ },
45918
46978
  providerMetadata: {
45919
46979
  [providerOptionsName]: { itemId: value.item.id }
45920
46980
  }
45921
46981
  });
46982
+ } else if (value.item.type === "shell_call_output") {
46983
+ controller.enqueue({
46984
+ type: "tool-result",
46985
+ toolCallId: value.item.call_id,
46986
+ toolName: toolNameMapping.toCustomToolName("shell"),
46987
+ result: {
46988
+ output: value.item.output.map(
46989
+ (item) => ({
46990
+ stdout: item.stdout,
46991
+ stderr: item.stderr,
46992
+ outcome: item.outcome.type === "exit" ? {
46993
+ type: "exit",
46994
+ exitCode: item.outcome.exit_code
46995
+ } : { type: "timeout" }
46996
+ })
46997
+ )
46998
+ }
46999
+ });
45922
47000
  } else if (value.item.type === "reasoning") {
45923
47001
  const activeReasoningPart = activeReasoning[value.item.id];
45924
47002
  const summaryPartIndices = Object.entries(
@@ -45933,7 +47011,7 @@ var OpenAIResponsesLanguageModel = class {
45933
47011
  providerMetadata: {
45934
47012
  [providerOptionsName]: {
45935
47013
  itemId: value.item.id,
45936
- reasoningEncryptedContent: (_k = value.item.encrypted_content) != null ? _k : null
47014
+ reasoningEncryptedContent: (_m = value.item.encrypted_content) != null ? _m : null
45937
47015
  }
45938
47016
  }
45939
47017
  });
@@ -45949,6 +47027,15 @@ var OpenAIResponsesLanguageModel = class {
45949
47027
  delta: value.delta
45950
47028
  });
45951
47029
  }
47030
+ } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
47031
+ const toolCall = ongoingToolCalls[value.output_index];
47032
+ if (toolCall != null) {
47033
+ controller.enqueue({
47034
+ type: "tool-input-delta",
47035
+ id: toolCall.toolCallId,
47036
+ delta: value.delta
47037
+ });
47038
+ }
45952
47039
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
45953
47040
  const toolCall = ongoingToolCalls[value.output_index];
45954
47041
  if (toolCall == null ? void 0 : toolCall.applyPatch) {
@@ -46037,7 +47124,7 @@ var OpenAIResponsesLanguageModel = class {
46037
47124
  id: value.item_id,
46038
47125
  delta: value.delta
46039
47126
  });
46040
- if (((_m = (_l = options.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.logprobs) && value.logprobs) {
47127
+ if (((_o = (_n = options.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.logprobs) && value.logprobs) {
46041
47128
  logprobs.push(value.logprobs);
46042
47129
  }
46043
47130
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -46066,7 +47153,7 @@ var OpenAIResponsesLanguageModel = class {
46066
47153
  providerMetadata: {
46067
47154
  [providerOptionsName]: {
46068
47155
  itemId: value.item_id,
46069
- reasoningEncryptedContent: (_o = (_n = activeReasoning[value.item_id]) == null ? void 0 : _n.encryptedContent) != null ? _o : null
47156
+ reasoningEncryptedContent: (_q = (_p = activeReasoning[value.item_id]) == null ? void 0 : _p.encryptedContent) != null ? _q : null
46070
47157
  }
46071
47158
  }
46072
47159
  });
@@ -46100,10 +47187,10 @@ var OpenAIResponsesLanguageModel = class {
46100
47187
  } else if (isResponseFinishedChunk(value)) {
46101
47188
  finishReason = {
46102
47189
  unified: mapOpenAIResponseFinishReason({
46103
- finishReason: (_p = value.response.incomplete_details) == null ? void 0 : _p.reason,
47190
+ finishReason: (_r = value.response.incomplete_details) == null ? void 0 : _r.reason,
46104
47191
  hasFunctionCall
46105
47192
  }),
46106
- raw: (_r = (_q = value.response.incomplete_details) == null ? void 0 : _q.reason) != null ? _r : void 0
47193
+ raw: (_t = (_s = value.response.incomplete_details) == null ? void 0 : _s.reason) != null ? _t : void 0
46107
47194
  };
46108
47195
  usage = value.response.usage;
46109
47196
  if (typeof value.response.service_tier === "string") {
@@ -46115,7 +47202,7 @@ var OpenAIResponsesLanguageModel = class {
46115
47202
  controller.enqueue({
46116
47203
  type: "source",
46117
47204
  sourceType: "url",
46118
- id: (_u = (_t = (_s = self2.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId$1(),
47205
+ id: (_w = (_v = (_u = self2.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId$1(),
46119
47206
  url: value.annotation.url,
46120
47207
  title: value.annotation.title
46121
47208
  });
@@ -46123,7 +47210,7 @@ var OpenAIResponsesLanguageModel = class {
46123
47210
  controller.enqueue({
46124
47211
  type: "source",
46125
47212
  sourceType: "document",
46126
- id: (_x = (_w = (_v = self2.config).generateId) == null ? void 0 : _w.call(_v)) != null ? _x : generateId$1(),
47213
+ id: (_z = (_y = (_x = self2.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId$1(),
46127
47214
  mediaType: "text/plain",
46128
47215
  title: value.annotation.filename,
46129
47216
  filename: value.annotation.filename,
@@ -46139,7 +47226,7 @@ var OpenAIResponsesLanguageModel = class {
46139
47226
  controller.enqueue({
46140
47227
  type: "source",
46141
47228
  sourceType: "document",
46142
- id: (_A = (_z = (_y = self2.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : generateId$1(),
47229
+ id: (_C = (_B = (_A = self2.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId$1(),
46143
47230
  mediaType: "text/plain",
46144
47231
  title: value.annotation.filename,
46145
47232
  filename: value.annotation.filename,
@@ -46155,7 +47242,7 @@ var OpenAIResponsesLanguageModel = class {
46155
47242
  controller.enqueue({
46156
47243
  type: "source",
46157
47244
  sourceType: "document",
46158
- id: (_D = (_C = (_B = self2.config).generateId) == null ? void 0 : _C.call(_B)) != null ? _D : generateId$1(),
47245
+ id: (_F = (_E = (_D = self2.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId$1(),
46159
47246
  mediaType: "application/octet-stream",
46160
47247
  title: value.annotation.file_id,
46161
47248
  filename: value.annotation.file_id,
@@ -46209,6 +47296,9 @@ function isResponseCreatedChunk(chunk) {
46209
47296
  function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
46210
47297
  return chunk.type === "response.function_call_arguments.delta";
46211
47298
  }
47299
+ function isResponseCustomToolCallInputDeltaChunk(chunk) {
47300
+ return chunk.type === "response.custom_tool_call_input.delta";
47301
+ }
46212
47302
  function isResponseImageGenerationCallPartialImageChunk(chunk) {
46213
47303
  return chunk.type === "response.image_generation_call.partial_image";
46214
47304
  }
@@ -46235,6 +47325,9 @@ function isErrorChunk(chunk) {
46235
47325
  }
46236
47326
  function mapWebSearchOutput(action) {
46237
47327
  var _a10;
47328
+ if (action == null) {
47329
+ return {};
47330
+ }
46238
47331
  switch (action.type) {
46239
47332
  case "search":
46240
47333
  return {
@@ -46587,7 +47680,7 @@ var OpenAITranscriptionModel = class {
46587
47680
  };
46588
47681
  }
46589
47682
  };
46590
- var VERSION$2 = "3.0.28";
47683
+ var VERSION$2 = "3.0.41";
46591
47684
  function createOpenAI(options = {}) {
46592
47685
  var _a10, _b9;
46593
47686
  const baseURL = (_a10 = withoutTrailingSlash$1(
@@ -48407,9 +49500,13 @@ function generateReActToolsPrompt(tools) {
48407
49500
  if (toolEntries.length === 0) {
48408
49501
  return "";
48409
49502
  }
48410
- let prompt = "\n\n# 工具调用\n\n";
48411
- prompt += "你可以根据需要调用以下工具:\n\n";
48412
- prompt += "<tools>\n";
49503
+ let prompt = `
49504
+ # 工具调用
49505
+
49506
+ 你可以根据需要调用以下工具:
49507
+
49508
+ <tools>
49509
+ `;
48413
49510
  toolEntries.forEach(([toolName, tool2]) => {
48414
49511
  const toolInfo = tool2;
48415
49512
  const description2 = toolInfo.description || "无描述";
@@ -48422,23 +49519,36 @@ function generateReActToolsPrompt(tools) {
48422
49519
  prompt += `${JSON.stringify(toolJson, null, 2)}
48423
49520
  `;
48424
49521
  });
48425
- prompt += "</tools>\n\n";
48426
- prompt += "## 工具调用格式\n\n";
48427
- prompt += "要调用工具,请使用以下 XML 格式:\n";
48428
- prompt += "Thought: [你的思考过程]\n";
48429
- prompt += '<tool_call>{"name": "toolName", "arguments": {"arg1": "value1"}}</tool_call>\n\n';
48430
- prompt += "工具执行后,你将收到 <tool_response> 格式的结果。你可以继续思考或调用其他工具。\n\n";
48431
- prompt += "## 使用示例\n\n";
48432
- prompt += '如果用户要求"获取今天的日期",你可以这样调用工具:\n';
48433
- prompt += "Thought: 用户想要获取今天的日期,我需要调用日期相关的工具。\n";
48434
- prompt += '<tool_call>{"name": "get-today", "arguments": {}}</tool_call>\n\n';
48435
- prompt += "然后等待工具返回结果(Observation),再根据结果给出最终答案。\n\n";
48436
- prompt += "## 任务完成\n\n";
48437
- prompt += "当任务完成或无法继续时,直接给出最终答案即可。\n\n";
48438
- prompt += "**重要提示**:\n";
48439
- prompt += "- 必须严格按照 XML 格式调用工具\n";
48440
- prompt += "- arguments 必须是有效的 JSON 格式\n";
48441
- prompt += "- 如果不需要调用工具,直接给出最终答案即可\n";
49522
+ prompt += `
49523
+ </tools>
49524
+
49525
+ ## 工具调用格式
49526
+
49527
+ 要调用工具,请使用以下 XML 格式:
49528
+ Thought: [你的思考过程]
49529
+ <tool_call>
49530
+ {"name": "toolName", "arguments": {"arg1": "value1"}}
49531
+ </tool_call>
49532
+
49533
+ 工具执行后,你将收到 <tool_response> 格式的结果。你可以继续思考或调用其他工具。
49534
+
49535
+ ## 使用示例
49536
+
49537
+ 如果用户要求"获取今天的日期",你可以这样调用工具:
49538
+ Thought: 用户想要获取今天的日期,我需要调用日期相关的工具。
49539
+ <tool_call>{"name": "get-today", "arguments": {}}</tool_call>
49540
+
49541
+ 然后等待工具返回结果(Observation),再根据结果给出最终答案。
49542
+
49543
+ ## 任务完成
49544
+
49545
+ 当任务完成或无法继续时,直接给出最终答案即可。
49546
+
49547
+ **重要提示**:
49548
+ - 必须严格按照 XML 格式调用工具
49549
+ - arguments 必须是有效的 JSON 格式
49550
+ - 如果不需要调用工具,直接给出最终答案即可
49551
+ `;
48442
49552
  return prompt;
48443
49553
  }
48444
49554
  function parseReActAction(text2, availableTools) {
@@ -49045,6 +50155,122 @@ ${observationText}
49045
50155
  return this._chat(streamText, options);
49046
50156
  }
49047
50157
  }
50158
+ const MSG_TOOL_CALL = "next-sdk:tool-call";
50159
+ const MSG_TOOL_RESPONSE = "next-sdk:tool-response";
50160
+ const MSG_PAGE_READY = "next-sdk:page-ready";
50161
+ const activePages = /* @__PURE__ */ new Map();
50162
+ let _navigator = null;
50163
+ function setNavigator(fn) {
50164
+ _navigator = fn;
50165
+ }
50166
+ function buildPageHandler(name16, route, timeout = 3e4) {
50167
+ return (input) => {
50168
+ const callId = randomUUID();
50169
+ return new Promise((resolve2, reject) => {
50170
+ let timer;
50171
+ let readyHandler;
50172
+ const cleanup = () => {
50173
+ clearTimeout(timer);
50174
+ window.removeEventListener("message", responseHandler);
50175
+ if (readyHandler) {
50176
+ window.removeEventListener("message", readyHandler);
50177
+ }
50178
+ };
50179
+ timer = setTimeout(() => {
50180
+ cleanup();
50181
+ reject(new Error(`工具 [${name16}] 调用超时 (${timeout}ms),请检查目标页面是否正确调用了 registerPageTool`));
50182
+ }, timeout);
50183
+ const responseHandler = (event) => {
50184
+ if (event.source === window && event.data?.type === MSG_TOOL_RESPONSE && event.data.callId === callId) {
50185
+ cleanup();
50186
+ event.data.error ? reject(new Error(event.data.error)) : resolve2(event.data.result);
50187
+ }
50188
+ };
50189
+ window.addEventListener("message", responseHandler);
50190
+ const sendCall = () => {
50191
+ window.postMessage({ type: MSG_TOOL_CALL, callId, toolName: name16, route, input }, window.location.origin || "*");
50192
+ };
50193
+ let callSent = false;
50194
+ const sendCallOnce = () => {
50195
+ if (callSent) return;
50196
+ callSent = true;
50197
+ sendCall();
50198
+ };
50199
+ const run = async () => {
50200
+ try {
50201
+ if (activePages.get(route)) {
50202
+ sendCallOnce();
50203
+ return;
50204
+ }
50205
+ readyHandler = (event) => {
50206
+ if (event.source === window && event.data?.type === MSG_PAGE_READY && event.data.route === route) {
50207
+ window.removeEventListener("message", readyHandler);
50208
+ sendCallOnce();
50209
+ }
50210
+ };
50211
+ window.addEventListener("message", readyHandler);
50212
+ if (_navigator) {
50213
+ await _navigator(route);
50214
+ }
50215
+ if (activePages.get(route)) {
50216
+ window.removeEventListener("message", readyHandler);
50217
+ sendCallOnce();
50218
+ }
50219
+ } catch (err) {
50220
+ cleanup();
50221
+ reject(err instanceof Error ? err : new Error(String(err)));
50222
+ }
50223
+ };
50224
+ void run();
50225
+ });
50226
+ };
50227
+ }
50228
+ function withPageTools(server) {
50229
+ return new Proxy(server, {
50230
+ get(target, prop, receiver) {
50231
+ if (prop === "registerTool") {
50232
+ return (name16, config2, handlerOrRoute) => {
50233
+ if (typeof handlerOrRoute === "function") {
50234
+ return target.registerTool(name16, config2, handlerOrRoute);
50235
+ }
50236
+ const { route, timeout } = handlerOrRoute;
50237
+ return target.registerTool(name16, config2, buildPageHandler(name16, route, timeout));
50238
+ };
50239
+ }
50240
+ return Reflect.get(target, prop, receiver);
50241
+ }
50242
+ });
50243
+ }
50244
+ function registerPageTool(options) {
50245
+ const { handlers } = options;
50246
+ const route = window.location.pathname;
50247
+ const handleMessage = async (event) => {
50248
+ if (event.source !== window || event.data?.type !== MSG_TOOL_CALL || event.data?.route !== route || !(event.data.toolName in handlers)) {
50249
+ return;
50250
+ }
50251
+ const { callId, toolName, input } = event.data;
50252
+ try {
50253
+ const result = await handlers[toolName](input);
50254
+ window.postMessage({ type: MSG_TOOL_RESPONSE, callId, result }, window.location.origin || "*");
50255
+ } catch (err) {
50256
+ window.postMessage(
50257
+ {
50258
+ type: MSG_TOOL_RESPONSE,
50259
+ callId,
50260
+ error: err instanceof Error ? err.message : String(err)
50261
+ },
50262
+ window.location.origin || "*"
50263
+ );
50264
+ }
50265
+ };
50266
+ activePages.set(route, true);
50267
+ window.addEventListener("message", handleMessage);
50268
+ window.postMessage({ type: MSG_PAGE_READY, route }, window.location.origin || "*");
50269
+ return () => {
50270
+ activePages.delete(route);
50271
+ window.removeEventListener("message", handleMessage);
50272
+ };
50273
+ }
49048
50274
  const MAIN_SKILL_PATH_REG = /^\.\/[^/]+\/SKILL\.md$/;
49049
50275
  const FRONT_MATTER_BLOCK_REG = /^---\s*\n([\s\S]+?)\s*\n---/;
49050
50276
  function parseSkillFrontMatter(content) {
@@ -49057,14 +50283,27 @@ function parseSkillFrontMatter(content) {
49057
50283
  const description2 = descMatch?.[1]?.trim();
49058
50284
  return name16 && description2 ? { name: name16, description: description2 } : null;
49059
50285
  }
50286
+ function normalizeSkillModuleKeys(modules) {
50287
+ const result = {};
50288
+ for (const [key, content] of Object.entries(modules)) {
50289
+ const normalizedKey = key.replace(/\\/g, "/");
50290
+ const skillsIndex = normalizedKey.lastIndexOf("skills/");
50291
+ const relativePath = skillsIndex >= 0 ? normalizedKey.slice(skillsIndex + 7) : normalizedKey;
50292
+ const standardPath = relativePath.startsWith("./") ? relativePath : `./${relativePath}`;
50293
+ result[standardPath] = content;
50294
+ }
50295
+ return result;
50296
+ }
49060
50297
  function getMainSkillPaths(modules) {
49061
- return Object.keys(modules).filter((path) => MAIN_SKILL_PATH_REG.test(path));
50298
+ const normalized = normalizeSkillModuleKeys(modules);
50299
+ return Object.keys(normalized).filter((path) => MAIN_SKILL_PATH_REG.test(path));
49062
50300
  }
49063
50301
  function getSkillOverviews(modules) {
49064
- const mainPaths = getMainSkillPaths(modules);
50302
+ const normalized = normalizeSkillModuleKeys(modules);
50303
+ const mainPaths = Object.keys(normalized).filter((path) => MAIN_SKILL_PATH_REG.test(path));
49065
50304
  const list = [];
49066
50305
  for (const path of mainPaths) {
49067
- const content = modules[path];
50306
+ const content = normalized[path];
49068
50307
  if (!content) continue;
49069
50308
  const parsed = parseSkillFrontMatter(content);
49070
50309
  if (!parsed) continue;
@@ -49086,34 +50325,38 @@ ${lines.join("\n")}
49086
50325
  当需要用到某技能时,请使用 get_skill_content 工具获取该技能的完整文档内容。`;
49087
50326
  }
49088
50327
  function getSkillMdPaths(modules) {
49089
- return Object.keys(modules);
50328
+ const normalized = normalizeSkillModuleKeys(modules);
50329
+ return Object.keys(normalized);
49090
50330
  }
49091
50331
  function getSkillMdContent(modules, path) {
49092
- return modules[path];
50332
+ const normalized = normalizeSkillModuleKeys(modules);
50333
+ return normalized[path];
49093
50334
  }
49094
50335
  function getMainSkillPathByName(modules, name16) {
49095
50336
  return getMainSkillPaths(modules).find((p) => p.startsWith(`./${name16}/SKILL.md`));
49096
50337
  }
50338
+ const SKILL_INPUT_SCHEMA = objectType({
50339
+ skillName: stringType().optional().describe("技能名称,与目录名一致,如 calculator"),
50340
+ path: stringType().optional().describe("文档相对路径,如 ./calculator/SKILL.md 或 ./product-guide/reference/xxx.json")
50341
+ });
49097
50342
  function createSkillTools(modules) {
50343
+ const normalizedModules = normalizeSkillModuleKeys(modules);
49098
50344
  const getSkillContent = tool({
49099
- description: "根据技能名称或文档路径获取该技能的完整 Markdown 文档内容。传入 skillName(如 calculator)或 path(如 ./calculator/SKILL.md",
49100
- inputSchema: objectType({
49101
- skillName: stringType().optional().describe("技能名称,与目录名一致,如 calculator"),
49102
- path: stringType().optional().describe("文档相对路径,如 ./calculator/SKILL.md 或 ./product-guide/reference/xxx.md")
49103
- }),
50345
+ description: "根据技能名称或文档路径获取该技能的完整文档内容。传入 skillName(如 calculator)或 path(如 ./calculator/SKILL.md)。支持 .md、.json、.xml 等各类文本格式文件。",
50346
+ inputSchema: SKILL_INPUT_SCHEMA,
49104
50347
  execute: (args) => {
49105
50348
  const { skillName, path: pathArg } = args;
49106
50349
  let content;
49107
50350
  if (pathArg) {
49108
- content = getSkillMdContent(modules, pathArg);
50351
+ content = getSkillMdContent(normalizedModules, pathArg);
49109
50352
  } else if (skillName) {
49110
- const mainPath = getMainSkillPathByName(modules, skillName);
49111
- content = mainPath ? getSkillMdContent(modules, mainPath) : void 0;
50353
+ const mainPath = getMainSkillPathByName(normalizedModules, skillName);
50354
+ content = mainPath ? getSkillMdContent(normalizedModules, mainPath) : void 0;
49112
50355
  }
49113
50356
  if (content === void 0) {
49114
50357
  return { error: "未找到对应技能文档", skillName: skillName ?? pathArg };
49115
50358
  }
49116
- return { content, path: pathArg ?? getMainSkillPathByName(modules, skillName) };
50359
+ return { content, path: pathArg ?? getMainSkillPathByName(normalizedModules, skillName) };
49117
50360
  }
49118
50361
  });
49119
50362
  return {
@@ -49156,5 +50399,8 @@ export {
49156
50399
  isSSEClientTransport,
49157
50400
  isStreamableHTTPClientTransport,
49158
50401
  parseSkillFrontMatter,
50402
+ registerPageTool,
50403
+ setNavigator,
50404
+ withPageTools,
49159
50405
  z
49160
50406
  };