@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.
@@ -175,7 +175,7 @@
175
175
  (function(exports3) {
176
176
  Object.defineProperty(exports3, "__esModule", { value: true });
177
177
  exports3.ValueScope = exports3.ValueScopeName = exports3.Scope = exports3.varKinds = exports3.UsedValueState = void 0;
178
- const code_1 = requireCode$1();
178
+ const code_1 = /* @__PURE__ */ requireCode$1();
179
179
  class ValueError extends Error {
180
180
  constructor(name16) {
181
181
  super(`CodeGen: "code" for ${name16} not defined`);
@@ -321,9 +321,9 @@
321
321
  (function(exports3) {
322
322
  Object.defineProperty(exports3, "__esModule", { value: true });
323
323
  exports3.or = exports3.and = exports3.not = exports3.CodeGen = exports3.operators = exports3.varKinds = exports3.ValueScopeName = exports3.ValueScope = exports3.Scope = exports3.Name = exports3.regexpCode = exports3.stringify = exports3.getProperty = exports3.nil = exports3.strConcat = exports3.str = exports3._ = void 0;
324
- const code_1 = requireCode$1();
325
- const scope_1 = requireScope();
326
- var code_2 = requireCode$1();
324
+ const code_1 = /* @__PURE__ */ requireCode$1();
325
+ const scope_1 = /* @__PURE__ */ requireScope();
326
+ var code_2 = /* @__PURE__ */ requireCode$1();
327
327
  Object.defineProperty(exports3, "_", { enumerable: true, get: function() {
328
328
  return code_2._;
329
329
  } });
@@ -348,7 +348,7 @@
348
348
  Object.defineProperty(exports3, "Name", { enumerable: true, get: function() {
349
349
  return code_2.Name;
350
350
  } });
351
- var scope_2 = requireScope();
351
+ var scope_2 = /* @__PURE__ */ requireScope();
352
352
  Object.defineProperty(exports3, "Scope", { enumerable: true, get: function() {
353
353
  return scope_2.Scope;
354
354
  } });
@@ -1042,8 +1042,8 @@
1042
1042
  hasRequiredUtil = 1;
1043
1043
  Object.defineProperty(util$1, "__esModule", { value: true });
1044
1044
  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;
1045
- const codegen_1 = requireCodegen();
1046
- const code_1 = requireCode$1();
1045
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1046
+ const code_1 = /* @__PURE__ */ requireCode$1();
1047
1047
  function toHash(arr) {
1048
1048
  const hash = {};
1049
1049
  for (const item of arr)
@@ -1208,7 +1208,7 @@
1208
1208
  if (hasRequiredNames) return names;
1209
1209
  hasRequiredNames = 1;
1210
1210
  Object.defineProperty(names, "__esModule", { value: true });
1211
- const codegen_1 = requireCodegen();
1211
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1212
1212
  const names$1 = {
1213
1213
  // validation function arguments
1214
1214
  data: new codegen_1.Name("data"),
@@ -1248,9 +1248,9 @@
1248
1248
  (function(exports3) {
1249
1249
  Object.defineProperty(exports3, "__esModule", { value: true });
1250
1250
  exports3.extendErrors = exports3.resetErrorsCount = exports3.reportExtraError = exports3.reportError = exports3.keyword$DataError = exports3.keywordError = void 0;
1251
- const codegen_1 = requireCodegen();
1252
- const util_1 = requireUtil();
1253
- const names_1 = requireNames();
1251
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1252
+ const util_1 = /* @__PURE__ */ requireUtil();
1253
+ const names_1 = /* @__PURE__ */ requireNames();
1254
1254
  exports3.keywordError = {
1255
1255
  message: ({ keyword: keyword2 }) => (0, codegen_1.str)`must pass "${keyword2}" keyword validation`
1256
1256
  };
@@ -1370,9 +1370,9 @@
1370
1370
  hasRequiredBoolSchema = 1;
1371
1371
  Object.defineProperty(boolSchema, "__esModule", { value: true });
1372
1372
  boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
1373
- const errors_1 = requireErrors();
1374
- const codegen_1 = requireCodegen();
1375
- const names_1 = requireNames();
1373
+ const errors_1 = /* @__PURE__ */ requireErrors();
1374
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1375
+ const names_1 = /* @__PURE__ */ requireNames();
1376
1376
  const boolError = {
1377
1377
  message: "boolean schema is false"
1378
1378
  };
@@ -1475,11 +1475,11 @@
1475
1475
  hasRequiredDataType = 1;
1476
1476
  Object.defineProperty(dataType, "__esModule", { value: true });
1477
1477
  dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
1478
- const rules_1 = requireRules();
1479
- const applicability_1 = requireApplicability();
1480
- const errors_1 = requireErrors();
1481
- const codegen_1 = requireCodegen();
1482
- const util_1 = requireUtil();
1478
+ const rules_1 = /* @__PURE__ */ requireRules();
1479
+ const applicability_1 = /* @__PURE__ */ requireApplicability();
1480
+ const errors_1 = /* @__PURE__ */ requireErrors();
1481
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1482
+ const util_1 = /* @__PURE__ */ requireUtil();
1483
1483
  var DataType;
1484
1484
  (function(DataType2) {
1485
1485
  DataType2[DataType2["Correct"] = 0] = "Correct";
@@ -1659,8 +1659,8 @@
1659
1659
  hasRequiredDefaults = 1;
1660
1660
  Object.defineProperty(defaults, "__esModule", { value: true });
1661
1661
  defaults.assignDefaults = void 0;
1662
- const codegen_1 = requireCodegen();
1663
- const util_1 = requireUtil();
1662
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1663
+ const util_1 = /* @__PURE__ */ requireUtil();
1664
1664
  function assignDefaults(it, ty) {
1665
1665
  const { properties: properties2, items: items2 } = it.schema;
1666
1666
  if (ty === "object" && properties2) {
@@ -1697,10 +1697,10 @@
1697
1697
  hasRequiredCode = 1;
1698
1698
  Object.defineProperty(code, "__esModule", { value: true });
1699
1699
  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;
1700
- const codegen_1 = requireCodegen();
1701
- const util_1 = requireUtil();
1702
- const names_1 = requireNames();
1703
- const util_2 = requireUtil();
1700
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1701
+ const util_1 = /* @__PURE__ */ requireUtil();
1702
+ const names_1 = /* @__PURE__ */ requireNames();
1703
+ const util_2 = /* @__PURE__ */ requireUtil();
1704
1704
  function checkReportMissingProp(cxt, prop) {
1705
1705
  const { gen, data, it } = cxt;
1706
1706
  gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
@@ -1829,10 +1829,10 @@
1829
1829
  hasRequiredKeyword = 1;
1830
1830
  Object.defineProperty(keyword, "__esModule", { value: true });
1831
1831
  keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
1832
- const codegen_1 = requireCodegen();
1833
- const names_1 = requireNames();
1834
- const code_1 = requireCode();
1835
- const errors_1 = requireErrors();
1832
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1833
+ const names_1 = /* @__PURE__ */ requireNames();
1834
+ const code_1 = /* @__PURE__ */ requireCode();
1835
+ const errors_1 = /* @__PURE__ */ requireErrors();
1836
1836
  function macroKeywordCode(cxt, def) {
1837
1837
  const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
1838
1838
  const macroSchema = def.macro.call(it.self, schema, parentSchema, it);
@@ -1947,8 +1947,8 @@
1947
1947
  hasRequiredSubschema = 1;
1948
1948
  Object.defineProperty(subschema, "__esModule", { value: true });
1949
1949
  subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
1950
- const codegen_1 = requireCodegen();
1951
- const util_1 = requireUtil();
1950
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
1951
+ const util_1 = /* @__PURE__ */ requireUtil();
1952
1952
  function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
1953
1953
  if (keyword2 !== void 0 && schema !== void 0) {
1954
1954
  throw new Error('both "keyword" and "schema" passed, only one allowed');
@@ -2153,7 +2153,7 @@
2153
2153
  hasRequiredResolve = 1;
2154
2154
  Object.defineProperty(resolve$1, "__esModule", { value: true });
2155
2155
  resolve$1.getSchemaRefs = resolve$1.resolveUrl = resolve$1.normalizeId = resolve$1._getFullPath = resolve$1.getFullPath = resolve$1.inlineRef = void 0;
2156
- const util_1 = requireUtil();
2156
+ const util_1 = /* @__PURE__ */ requireUtil();
2157
2157
  const equal2 = requireFastDeepEqual();
2158
2158
  const traverse = requireJsonSchemaTraverse();
2159
2159
  const SIMPLE_INLINED = /* @__PURE__ */ new Set([
@@ -2308,18 +2308,18 @@
2308
2308
  hasRequiredValidate = 1;
2309
2309
  Object.defineProperty(validate, "__esModule", { value: true });
2310
2310
  validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
2311
- const boolSchema_1 = requireBoolSchema();
2312
- const dataType_1 = requireDataType();
2313
- const applicability_1 = requireApplicability();
2314
- const dataType_2 = requireDataType();
2315
- const defaults_1 = requireDefaults();
2316
- const keyword_1 = requireKeyword();
2317
- const subschema_1 = requireSubschema();
2318
- const codegen_1 = requireCodegen();
2319
- const names_1 = requireNames();
2320
- const resolve_1 = requireResolve();
2321
- const util_1 = requireUtil();
2322
- const errors_1 = requireErrors();
2311
+ const boolSchema_1 = /* @__PURE__ */ requireBoolSchema();
2312
+ const dataType_1 = /* @__PURE__ */ requireDataType();
2313
+ const applicability_1 = /* @__PURE__ */ requireApplicability();
2314
+ const dataType_2 = /* @__PURE__ */ requireDataType();
2315
+ const defaults_1 = /* @__PURE__ */ requireDefaults();
2316
+ const keyword_1 = /* @__PURE__ */ requireKeyword();
2317
+ const subschema_1 = /* @__PURE__ */ requireSubschema();
2318
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
2319
+ const names_1 = /* @__PURE__ */ requireNames();
2320
+ const resolve_1 = /* @__PURE__ */ requireResolve();
2321
+ const util_1 = /* @__PURE__ */ requireUtil();
2322
+ const errors_1 = /* @__PURE__ */ requireErrors();
2323
2323
  function validateFunctionCode(it) {
2324
2324
  if (isSchemaObj(it)) {
2325
2325
  checkKeywords(it);
@@ -2830,7 +2830,7 @@
2830
2830
  if (hasRequiredRef_error) return ref_error;
2831
2831
  hasRequiredRef_error = 1;
2832
2832
  Object.defineProperty(ref_error, "__esModule", { value: true });
2833
- const resolve_1 = requireResolve();
2833
+ const resolve_1 = /* @__PURE__ */ requireResolve();
2834
2834
  class MissingRefError extends Error {
2835
2835
  constructor(resolver, baseId, ref2, msg) {
2836
2836
  super(msg || `can't resolve reference ${ref2} from id ${baseId}`);
@@ -2848,12 +2848,12 @@
2848
2848
  hasRequiredCompile = 1;
2849
2849
  Object.defineProperty(compile, "__esModule", { value: true });
2850
2850
  compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
2851
- const codegen_1 = requireCodegen();
2852
- const validation_error_1 = requireValidation_error();
2853
- const names_1 = requireNames();
2854
- const resolve_1 = requireResolve();
2855
- const util_1 = requireUtil();
2856
- const validate_1 = requireValidate();
2851
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
2852
+ const validation_error_1 = /* @__PURE__ */ requireValidation_error();
2853
+ const names_1 = /* @__PURE__ */ requireNames();
2854
+ const resolve_1 = /* @__PURE__ */ requireResolve();
2855
+ const util_1 = /* @__PURE__ */ requireUtil();
2856
+ const validate_1 = /* @__PURE__ */ requireValidate();
2857
2857
  class SchemaEnv {
2858
2858
  constructor(env) {
2859
2859
  var _a10;
@@ -3087,7 +3087,7 @@
3087
3087
  if (hasRequiredUtils$2) return utils$2;
3088
3088
  hasRequiredUtils$2 = 1;
3089
3089
  const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
3090
- 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);
3090
+ 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);
3091
3091
  function stringArrayToHexStripped(input) {
3092
3092
  let acc = "";
3093
3093
  let code2 = 0;
@@ -3310,7 +3310,7 @@
3310
3310
  }
3311
3311
  if (component.host !== void 0) {
3312
3312
  let host = unescape(component.host);
3313
- if (!isIPv4(host)) {
3313
+ if (!isIPv42(host)) {
3314
3314
  const ipV6res = normalizeIPv6(host);
3315
3315
  if (ipV6res.isIPV6 === true) {
3316
3316
  host = `[${ipV6res.escapedHost}]`;
@@ -3331,7 +3331,7 @@
3331
3331
  recomposeAuthority,
3332
3332
  normalizeComponentEncoding,
3333
3333
  removeDotSegments,
3334
- isIPv4,
3334
+ isIPv4: isIPv42,
3335
3335
  isUUID,
3336
3336
  normalizeIPv6,
3337
3337
  stringArrayToHexStripped
@@ -3552,7 +3552,7 @@
3552
3552
  function requireFastUri() {
3553
3553
  if (hasRequiredFastUri) return fastUri.exports;
3554
3554
  hasRequiredFastUri = 1;
3555
- const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = requireUtils$2();
3555
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4: isIPv42, nonSimpleDomain } = requireUtils$2();
3556
3556
  const { SCHEMES, getSchemeHandler } = requireSchemes();
3557
3557
  function normalize(uri2, options) {
3558
3558
  if (typeof uri2 === "string") {
@@ -3733,7 +3733,7 @@
3733
3733
  parsed.port = matches[5];
3734
3734
  }
3735
3735
  if (parsed.host) {
3736
- const ipv4result = isIPv4(parsed.host);
3736
+ const ipv4result = isIPv42(parsed.host);
3737
3737
  if (ipv4result === false) {
3738
3738
  const ipv6result = normalizeIPv6(parsed.host);
3739
3739
  parsed.host = ipv6result.host.toLowerCase();
@@ -3819,11 +3819,11 @@
3819
3819
  (function(exports3) {
3820
3820
  Object.defineProperty(exports3, "__esModule", { value: true });
3821
3821
  exports3.CodeGen = exports3.Name = exports3.nil = exports3.stringify = exports3.str = exports3._ = exports3.KeywordCxt = void 0;
3822
- var validate_1 = requireValidate();
3822
+ var validate_1 = /* @__PURE__ */ requireValidate();
3823
3823
  Object.defineProperty(exports3, "KeywordCxt", { enumerable: true, get: function() {
3824
3824
  return validate_1.KeywordCxt;
3825
3825
  } });
3826
- var codegen_1 = requireCodegen();
3826
+ var codegen_1 = /* @__PURE__ */ requireCodegen();
3827
3827
  Object.defineProperty(exports3, "_", { enumerable: true, get: function() {
3828
3828
  return codegen_1._;
3829
3829
  } });
@@ -3842,16 +3842,16 @@
3842
3842
  Object.defineProperty(exports3, "CodeGen", { enumerable: true, get: function() {
3843
3843
  return codegen_1.CodeGen;
3844
3844
  } });
3845
- const validation_error_1 = requireValidation_error();
3846
- const ref_error_1 = requireRef_error();
3847
- const rules_1 = requireRules();
3848
- const compile_1 = requireCompile();
3849
- const codegen_2 = requireCodegen();
3850
- const resolve_1 = requireResolve();
3851
- const dataType_1 = requireDataType();
3852
- const util_1 = requireUtil();
3845
+ const validation_error_1 = /* @__PURE__ */ requireValidation_error();
3846
+ const ref_error_1 = /* @__PURE__ */ requireRef_error();
3847
+ const rules_1 = /* @__PURE__ */ requireRules();
3848
+ const compile_1 = /* @__PURE__ */ requireCompile();
3849
+ const codegen_2 = /* @__PURE__ */ requireCodegen();
3850
+ const resolve_1 = /* @__PURE__ */ requireResolve();
3851
+ const dataType_1 = /* @__PURE__ */ requireDataType();
3852
+ const util_1 = /* @__PURE__ */ requireUtil();
3853
3853
  const $dataRefSchema = require$$9;
3854
- const uri_1 = requireUri();
3854
+ const uri_1 = /* @__PURE__ */ requireUri();
3855
3855
  const defaultRegExp = (str, flags) => new RegExp(str, flags);
3856
3856
  defaultRegExp.code = "new RegExp";
3857
3857
  const META_IGNORE_OPTIONS = ["removeAdditional", "useDefaults", "coerceTypes"];
@@ -4448,12 +4448,12 @@
4448
4448
  hasRequiredRef = 1;
4449
4449
  Object.defineProperty(ref, "__esModule", { value: true });
4450
4450
  ref.callRef = ref.getValidate = void 0;
4451
- const ref_error_1 = requireRef_error();
4452
- const code_1 = requireCode();
4453
- const codegen_1 = requireCodegen();
4454
- const names_1 = requireNames();
4455
- const compile_1 = requireCompile();
4456
- const util_1 = requireUtil();
4451
+ const ref_error_1 = /* @__PURE__ */ requireRef_error();
4452
+ const code_1 = /* @__PURE__ */ requireCode();
4453
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4454
+ const names_1 = /* @__PURE__ */ requireNames();
4455
+ const compile_1 = /* @__PURE__ */ requireCompile();
4456
+ const util_1 = /* @__PURE__ */ requireUtil();
4457
4457
  const def = {
4458
4458
  keyword: "$ref",
4459
4459
  schemaType: "string",
@@ -4568,8 +4568,8 @@
4568
4568
  if (hasRequiredCore) return core;
4569
4569
  hasRequiredCore = 1;
4570
4570
  Object.defineProperty(core, "__esModule", { value: true });
4571
- const id_1 = requireId();
4572
- const ref_1 = requireRef();
4571
+ const id_1 = /* @__PURE__ */ requireId();
4572
+ const ref_1 = /* @__PURE__ */ requireRef();
4573
4573
  const core$12 = [
4574
4574
  "$schema",
4575
4575
  "$id",
@@ -4590,7 +4590,7 @@
4590
4590
  if (hasRequiredLimitNumber) return limitNumber;
4591
4591
  hasRequiredLimitNumber = 1;
4592
4592
  Object.defineProperty(limitNumber, "__esModule", { value: true });
4593
- const codegen_1 = requireCodegen();
4593
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4594
4594
  const ops = codegen_1.operators;
4595
4595
  const KWDs = {
4596
4596
  maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
@@ -4622,7 +4622,7 @@
4622
4622
  if (hasRequiredMultipleOf) return multipleOf;
4623
4623
  hasRequiredMultipleOf = 1;
4624
4624
  Object.defineProperty(multipleOf, "__esModule", { value: true });
4625
- const codegen_1 = requireCodegen();
4625
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4626
4626
  const error = {
4627
4627
  message: ({ schemaCode }) => (0, codegen_1.str)`must be multiple of ${schemaCode}`,
4628
4628
  params: ({ schemaCode }) => (0, codegen_1._)`{multipleOf: ${schemaCode}}`
@@ -4676,9 +4676,9 @@
4676
4676
  if (hasRequiredLimitLength) return limitLength;
4677
4677
  hasRequiredLimitLength = 1;
4678
4678
  Object.defineProperty(limitLength, "__esModule", { value: true });
4679
- const codegen_1 = requireCodegen();
4680
- const util_1 = requireUtil();
4681
- const ucs2length_1 = requireUcs2length();
4679
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4680
+ const util_1 = /* @__PURE__ */ requireUtil();
4681
+ const ucs2length_1 = /* @__PURE__ */ requireUcs2length();
4682
4682
  const error = {
4683
4683
  message({ keyword: keyword2, schemaCode }) {
4684
4684
  const comp = keyword2 === "maxLength" ? "more" : "fewer";
@@ -4708,8 +4708,9 @@
4708
4708
  if (hasRequiredPattern) return pattern;
4709
4709
  hasRequiredPattern = 1;
4710
4710
  Object.defineProperty(pattern, "__esModule", { value: true });
4711
- const code_1 = requireCode();
4712
- const codegen_1 = requireCodegen();
4711
+ const code_1 = /* @__PURE__ */ requireCode();
4712
+ const util_1 = /* @__PURE__ */ requireUtil();
4713
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4713
4714
  const error = {
4714
4715
  message: ({ schemaCode }) => (0, codegen_1.str)`must match pattern "${schemaCode}"`,
4715
4716
  params: ({ schemaCode }) => (0, codegen_1._)`{pattern: ${schemaCode}}`
@@ -4721,10 +4722,18 @@
4721
4722
  $data: true,
4722
4723
  error,
4723
4724
  code(cxt) {
4724
- const { data, $data, schema, schemaCode, it } = cxt;
4725
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
4725
4726
  const u = it.opts.unicodeRegExp ? "u" : "";
4726
- const regExp = $data ? (0, codegen_1._)`(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
4727
- cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4727
+ if ($data) {
4728
+ const { regExp } = it.opts.code;
4729
+ const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._)`new RegExp` : (0, util_1.useFunc)(gen, regExp);
4730
+ const valid = gen.let("valid");
4731
+ gen.try(() => gen.assign(valid, (0, codegen_1._)`${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid, false));
4732
+ cxt.fail$data((0, codegen_1._)`!${valid}`);
4733
+ } else {
4734
+ const regExp = (0, code_1.usePattern)(cxt, schema);
4735
+ cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4736
+ }
4728
4737
  }
4729
4738
  };
4730
4739
  pattern.default = def;
@@ -4736,7 +4745,7 @@
4736
4745
  if (hasRequiredLimitProperties) return limitProperties;
4737
4746
  hasRequiredLimitProperties = 1;
4738
4747
  Object.defineProperty(limitProperties, "__esModule", { value: true });
4739
- const codegen_1 = requireCodegen();
4748
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4740
4749
  const error = {
4741
4750
  message({ keyword: keyword2, schemaCode }) {
4742
4751
  const comp = keyword2 === "maxProperties" ? "more" : "fewer";
@@ -4765,9 +4774,9 @@
4765
4774
  if (hasRequiredRequired) return required$1;
4766
4775
  hasRequiredRequired = 1;
4767
4776
  Object.defineProperty(required$1, "__esModule", { value: true });
4768
- const code_1 = requireCode();
4769
- const codegen_1 = requireCodegen();
4770
- const util_1 = requireUtil();
4777
+ const code_1 = /* @__PURE__ */ requireCode();
4778
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4779
+ const util_1 = /* @__PURE__ */ requireUtil();
4771
4780
  const error = {
4772
4781
  message: ({ params: { missingProperty } }) => (0, codegen_1.str)`must have required property '${missingProperty}'`,
4773
4782
  params: ({ params: { missingProperty } }) => (0, codegen_1._)`{missingProperty: ${missingProperty}}`
@@ -4847,7 +4856,7 @@
4847
4856
  if (hasRequiredLimitItems) return limitItems;
4848
4857
  hasRequiredLimitItems = 1;
4849
4858
  Object.defineProperty(limitItems, "__esModule", { value: true });
4850
- const codegen_1 = requireCodegen();
4859
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4851
4860
  const error = {
4852
4861
  message({ keyword: keyword2, schemaCode }) {
4853
4862
  const comp = keyword2 === "maxItems" ? "more" : "fewer";
@@ -4887,10 +4896,10 @@
4887
4896
  if (hasRequiredUniqueItems) return uniqueItems;
4888
4897
  hasRequiredUniqueItems = 1;
4889
4898
  Object.defineProperty(uniqueItems, "__esModule", { value: true });
4890
- const dataType_1 = requireDataType();
4891
- const codegen_1 = requireCodegen();
4892
- const util_1 = requireUtil();
4893
- const equal_1 = requireEqual();
4899
+ const dataType_1 = /* @__PURE__ */ requireDataType();
4900
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4901
+ const util_1 = /* @__PURE__ */ requireUtil();
4902
+ const equal_1 = /* @__PURE__ */ requireEqual();
4894
4903
  const error = {
4895
4904
  message: ({ params: { i, j } }) => (0, codegen_1.str)`must NOT have duplicate items (items ## ${j} and ${i} are identical)`,
4896
4905
  params: ({ params: { i, j } }) => (0, codegen_1._)`{i: ${i}, j: ${j}}`
@@ -4954,9 +4963,9 @@
4954
4963
  if (hasRequired_const) return _const;
4955
4964
  hasRequired_const = 1;
4956
4965
  Object.defineProperty(_const, "__esModule", { value: true });
4957
- const codegen_1 = requireCodegen();
4958
- const util_1 = requireUtil();
4959
- const equal_1 = requireEqual();
4966
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4967
+ const util_1 = /* @__PURE__ */ requireUtil();
4968
+ const equal_1 = /* @__PURE__ */ requireEqual();
4960
4969
  const error = {
4961
4970
  message: "must be equal to constant",
4962
4971
  params: ({ schemaCode }) => (0, codegen_1._)`{allowedValue: ${schemaCode}}`
@@ -4983,9 +4992,9 @@
4983
4992
  if (hasRequired_enum) return _enum$1;
4984
4993
  hasRequired_enum = 1;
4985
4994
  Object.defineProperty(_enum$1, "__esModule", { value: true });
4986
- const codegen_1 = requireCodegen();
4987
- const util_1 = requireUtil();
4988
- const equal_1 = requireEqual();
4995
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
4996
+ const util_1 = /* @__PURE__ */ requireUtil();
4997
+ const equal_1 = /* @__PURE__ */ requireEqual();
4989
4998
  const error = {
4990
4999
  message: "must be equal to one of the allowed values",
4991
5000
  params: ({ schemaCode }) => (0, codegen_1._)`{allowedValues: ${schemaCode}}`
@@ -5031,16 +5040,16 @@
5031
5040
  if (hasRequiredValidation) return validation;
5032
5041
  hasRequiredValidation = 1;
5033
5042
  Object.defineProperty(validation, "__esModule", { value: true });
5034
- const limitNumber_1 = requireLimitNumber();
5035
- const multipleOf_1 = requireMultipleOf();
5036
- const limitLength_1 = requireLimitLength();
5037
- const pattern_1 = requirePattern();
5038
- const limitProperties_1 = requireLimitProperties();
5039
- const required_1 = requireRequired();
5040
- const limitItems_1 = requireLimitItems();
5041
- const uniqueItems_1 = requireUniqueItems();
5042
- const const_1 = require_const();
5043
- const enum_1 = require_enum();
5043
+ const limitNumber_1 = /* @__PURE__ */ requireLimitNumber();
5044
+ const multipleOf_1 = /* @__PURE__ */ requireMultipleOf();
5045
+ const limitLength_1 = /* @__PURE__ */ requireLimitLength();
5046
+ const pattern_1 = /* @__PURE__ */ requirePattern();
5047
+ const limitProperties_1 = /* @__PURE__ */ requireLimitProperties();
5048
+ const required_1 = /* @__PURE__ */ requireRequired();
5049
+ const limitItems_1 = /* @__PURE__ */ requireLimitItems();
5050
+ const uniqueItems_1 = /* @__PURE__ */ requireUniqueItems();
5051
+ const const_1 = /* @__PURE__ */ require_const();
5052
+ const enum_1 = /* @__PURE__ */ require_enum();
5044
5053
  const validation$1 = [
5045
5054
  // number
5046
5055
  limitNumber_1.default,
@@ -5071,8 +5080,8 @@
5071
5080
  hasRequiredAdditionalItems = 1;
5072
5081
  Object.defineProperty(additionalItems, "__esModule", { value: true });
5073
5082
  additionalItems.validateAdditionalItems = void 0;
5074
- const codegen_1 = requireCodegen();
5075
- const util_1 = requireUtil();
5083
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5084
+ const util_1 = /* @__PURE__ */ requireUtil();
5076
5085
  const error = {
5077
5086
  message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
5078
5087
  params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
@@ -5125,9 +5134,9 @@
5125
5134
  hasRequiredItems = 1;
5126
5135
  Object.defineProperty(items, "__esModule", { value: true });
5127
5136
  items.validateTuple = void 0;
5128
- const codegen_1 = requireCodegen();
5129
- const util_1 = requireUtil();
5130
- const code_1 = requireCode();
5137
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5138
+ const util_1 = /* @__PURE__ */ requireUtil();
5139
+ const code_1 = /* @__PURE__ */ requireCode();
5131
5140
  const def = {
5132
5141
  keyword: "items",
5133
5142
  type: "array",
@@ -5180,7 +5189,7 @@
5180
5189
  if (hasRequiredPrefixItems) return prefixItems;
5181
5190
  hasRequiredPrefixItems = 1;
5182
5191
  Object.defineProperty(prefixItems, "__esModule", { value: true });
5183
- const items_1 = requireItems();
5192
+ const items_1 = /* @__PURE__ */ requireItems();
5184
5193
  const def = {
5185
5194
  keyword: "prefixItems",
5186
5195
  type: "array",
@@ -5197,10 +5206,10 @@
5197
5206
  if (hasRequiredItems2020) return items2020;
5198
5207
  hasRequiredItems2020 = 1;
5199
5208
  Object.defineProperty(items2020, "__esModule", { value: true });
5200
- const codegen_1 = requireCodegen();
5201
- const util_1 = requireUtil();
5202
- const code_1 = requireCode();
5203
- const additionalItems_1 = requireAdditionalItems();
5209
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5210
+ const util_1 = /* @__PURE__ */ requireUtil();
5211
+ const code_1 = /* @__PURE__ */ requireCode();
5212
+ const additionalItems_1 = /* @__PURE__ */ requireAdditionalItems();
5204
5213
  const error = {
5205
5214
  message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
5206
5215
  params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
@@ -5232,8 +5241,8 @@
5232
5241
  if (hasRequiredContains) return contains;
5233
5242
  hasRequiredContains = 1;
5234
5243
  Object.defineProperty(contains, "__esModule", { value: true });
5235
- const codegen_1 = requireCodegen();
5236
- const util_1 = requireUtil();
5244
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5245
+ const util_1 = /* @__PURE__ */ requireUtil();
5237
5246
  const error = {
5238
5247
  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)`,
5239
5248
  params: ({ params: { min, max } }) => max === void 0 ? (0, codegen_1._)`{minContains: ${min}}` : (0, codegen_1._)`{minContains: ${min}, maxContains: ${max}}`
@@ -5328,9 +5337,9 @@
5328
5337
  (function(exports3) {
5329
5338
  Object.defineProperty(exports3, "__esModule", { value: true });
5330
5339
  exports3.validateSchemaDeps = exports3.validatePropertyDeps = exports3.error = void 0;
5331
- const codegen_1 = requireCodegen();
5332
- const util_1 = requireUtil();
5333
- const code_1 = requireCode();
5340
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5341
+ const util_1 = /* @__PURE__ */ requireUtil();
5342
+ const code_1 = /* @__PURE__ */ requireCode();
5334
5343
  exports3.error = {
5335
5344
  message: ({ params: { property, depsCount, deps } }) => {
5336
5345
  const property_ies = depsCount === 1 ? "property" : "properties";
@@ -5422,8 +5431,8 @@
5422
5431
  if (hasRequiredPropertyNames) return propertyNames;
5423
5432
  hasRequiredPropertyNames = 1;
5424
5433
  Object.defineProperty(propertyNames, "__esModule", { value: true });
5425
- const codegen_1 = requireCodegen();
5426
- const util_1 = requireUtil();
5434
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5435
+ const util_1 = /* @__PURE__ */ requireUtil();
5427
5436
  const error = {
5428
5437
  message: "property name must be valid",
5429
5438
  params: ({ params }) => (0, codegen_1._)`{propertyName: ${params.propertyName}}`
@@ -5465,10 +5474,10 @@
5465
5474
  if (hasRequiredAdditionalProperties) return additionalProperties;
5466
5475
  hasRequiredAdditionalProperties = 1;
5467
5476
  Object.defineProperty(additionalProperties, "__esModule", { value: true });
5468
- const code_1 = requireCode();
5469
- const codegen_1 = requireCodegen();
5470
- const names_1 = requireNames();
5471
- const util_1 = requireUtil();
5477
+ const code_1 = /* @__PURE__ */ requireCode();
5478
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5479
+ const names_1 = /* @__PURE__ */ requireNames();
5480
+ const util_1 = /* @__PURE__ */ requireUtil();
5472
5481
  const error = {
5473
5482
  message: "must NOT have additional properties",
5474
5483
  params: ({ params }) => (0, codegen_1._)`{additionalProperty: ${params.additionalProperty}}`
@@ -5571,10 +5580,10 @@
5571
5580
  if (hasRequiredProperties) return properties$1;
5572
5581
  hasRequiredProperties = 1;
5573
5582
  Object.defineProperty(properties$1, "__esModule", { value: true });
5574
- const validate_1 = requireValidate();
5575
- const code_1 = requireCode();
5576
- const util_1 = requireUtil();
5577
- const additionalProperties_1 = requireAdditionalProperties();
5583
+ const validate_1 = /* @__PURE__ */ requireValidate();
5584
+ const code_1 = /* @__PURE__ */ requireCode();
5585
+ const util_1 = /* @__PURE__ */ requireUtil();
5586
+ const additionalProperties_1 = /* @__PURE__ */ requireAdditionalProperties();
5578
5587
  const def = {
5579
5588
  keyword: "properties",
5580
5589
  type: "object",
@@ -5629,10 +5638,10 @@
5629
5638
  if (hasRequiredPatternProperties) return patternProperties;
5630
5639
  hasRequiredPatternProperties = 1;
5631
5640
  Object.defineProperty(patternProperties, "__esModule", { value: true });
5632
- const code_1 = requireCode();
5633
- const codegen_1 = requireCodegen();
5634
- const util_1 = requireUtil();
5635
- const util_2 = requireUtil();
5641
+ const code_1 = /* @__PURE__ */ requireCode();
5642
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5643
+ const util_1 = /* @__PURE__ */ requireUtil();
5644
+ const util_2 = /* @__PURE__ */ requireUtil();
5636
5645
  const def = {
5637
5646
  keyword: "patternProperties",
5638
5647
  type: "object",
@@ -5703,7 +5712,7 @@
5703
5712
  if (hasRequiredNot) return not;
5704
5713
  hasRequiredNot = 1;
5705
5714
  Object.defineProperty(not, "__esModule", { value: true });
5706
- const util_1 = requireUtil();
5715
+ const util_1 = /* @__PURE__ */ requireUtil();
5707
5716
  const def = {
5708
5717
  keyword: "not",
5709
5718
  schemaType: ["object", "boolean"],
@@ -5734,7 +5743,7 @@
5734
5743
  if (hasRequiredAnyOf) return anyOf;
5735
5744
  hasRequiredAnyOf = 1;
5736
5745
  Object.defineProperty(anyOf, "__esModule", { value: true });
5737
- const code_1 = requireCode();
5746
+ const code_1 = /* @__PURE__ */ requireCode();
5738
5747
  const def = {
5739
5748
  keyword: "anyOf",
5740
5749
  schemaType: "array",
@@ -5751,8 +5760,8 @@
5751
5760
  if (hasRequiredOneOf) return oneOf;
5752
5761
  hasRequiredOneOf = 1;
5753
5762
  Object.defineProperty(oneOf, "__esModule", { value: true });
5754
- const codegen_1 = requireCodegen();
5755
- const util_1 = requireUtil();
5763
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5764
+ const util_1 = /* @__PURE__ */ requireUtil();
5756
5765
  const error = {
5757
5766
  message: "must match exactly one schema in oneOf",
5758
5767
  params: ({ params }) => (0, codegen_1._)`{passingSchemas: ${params.passing}}`
@@ -5809,7 +5818,7 @@
5809
5818
  if (hasRequiredAllOf) return allOf;
5810
5819
  hasRequiredAllOf = 1;
5811
5820
  Object.defineProperty(allOf, "__esModule", { value: true });
5812
- const util_1 = requireUtil();
5821
+ const util_1 = /* @__PURE__ */ requireUtil();
5813
5822
  const def = {
5814
5823
  keyword: "allOf",
5815
5824
  schemaType: "array",
@@ -5836,8 +5845,8 @@
5836
5845
  if (hasRequired_if) return _if;
5837
5846
  hasRequired_if = 1;
5838
5847
  Object.defineProperty(_if, "__esModule", { value: true });
5839
- const codegen_1 = requireCodegen();
5840
- const util_1 = requireUtil();
5848
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5849
+ const util_1 = /* @__PURE__ */ requireUtil();
5841
5850
  const error = {
5842
5851
  message: ({ params }) => (0, codegen_1.str)`must match "${params.ifClause}" schema`,
5843
5852
  params: ({ params }) => (0, codegen_1._)`{failingKeyword: ${params.ifClause}}`
@@ -5905,7 +5914,7 @@
5905
5914
  if (hasRequiredThenElse) return thenElse;
5906
5915
  hasRequiredThenElse = 1;
5907
5916
  Object.defineProperty(thenElse, "__esModule", { value: true });
5908
- const util_1 = requireUtil();
5917
+ const util_1 = /* @__PURE__ */ requireUtil();
5909
5918
  const def = {
5910
5919
  keyword: ["then", "else"],
5911
5920
  schemaType: ["object", "boolean"],
@@ -5922,22 +5931,22 @@
5922
5931
  if (hasRequiredApplicator) return applicator;
5923
5932
  hasRequiredApplicator = 1;
5924
5933
  Object.defineProperty(applicator, "__esModule", { value: true });
5925
- const additionalItems_1 = requireAdditionalItems();
5926
- const prefixItems_1 = requirePrefixItems();
5927
- const items_1 = requireItems();
5928
- const items2020_1 = requireItems2020();
5929
- const contains_1 = requireContains();
5930
- const dependencies_1 = requireDependencies();
5931
- const propertyNames_1 = requirePropertyNames();
5932
- const additionalProperties_1 = requireAdditionalProperties();
5933
- const properties_1 = requireProperties();
5934
- const patternProperties_1 = requirePatternProperties();
5935
- const not_1 = requireNot();
5936
- const anyOf_1 = requireAnyOf();
5937
- const oneOf_1 = requireOneOf();
5938
- const allOf_1 = requireAllOf();
5939
- const if_1 = require_if();
5940
- const thenElse_1 = requireThenElse();
5934
+ const additionalItems_1 = /* @__PURE__ */ requireAdditionalItems();
5935
+ const prefixItems_1 = /* @__PURE__ */ requirePrefixItems();
5936
+ const items_1 = /* @__PURE__ */ requireItems();
5937
+ const items2020_1 = /* @__PURE__ */ requireItems2020();
5938
+ const contains_1 = /* @__PURE__ */ requireContains();
5939
+ const dependencies_1 = /* @__PURE__ */ requireDependencies();
5940
+ const propertyNames_1 = /* @__PURE__ */ requirePropertyNames();
5941
+ const additionalProperties_1 = /* @__PURE__ */ requireAdditionalProperties();
5942
+ const properties_1 = /* @__PURE__ */ requireProperties();
5943
+ const patternProperties_1 = /* @__PURE__ */ requirePatternProperties();
5944
+ const not_1 = /* @__PURE__ */ requireNot();
5945
+ const anyOf_1 = /* @__PURE__ */ requireAnyOf();
5946
+ const oneOf_1 = /* @__PURE__ */ requireOneOf();
5947
+ const allOf_1 = /* @__PURE__ */ requireAllOf();
5948
+ const if_1 = /* @__PURE__ */ require_if();
5949
+ const thenElse_1 = /* @__PURE__ */ requireThenElse();
5941
5950
  function getApplicator(draft2020 = false) {
5942
5951
  const applicator2 = [
5943
5952
  // any
@@ -5971,7 +5980,7 @@
5971
5980
  if (hasRequiredFormat$1) return format;
5972
5981
  hasRequiredFormat$1 = 1;
5973
5982
  Object.defineProperty(format, "__esModule", { value: true });
5974
- const codegen_1 = requireCodegen();
5983
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
5975
5984
  const error = {
5976
5985
  message: ({ schemaCode }) => (0, codegen_1.str)`must match format "${schemaCode}"`,
5977
5986
  params: ({ schemaCode }) => (0, codegen_1._)`{format: ${schemaCode}}`
@@ -6060,7 +6069,7 @@
6060
6069
  if (hasRequiredFormat) return format$1;
6061
6070
  hasRequiredFormat = 1;
6062
6071
  Object.defineProperty(format$1, "__esModule", { value: true });
6063
- const format_1 = requireFormat$1();
6072
+ const format_1 = /* @__PURE__ */ requireFormat$1();
6064
6073
  const format2 = [format_1.default];
6065
6074
  format$1.default = format2;
6066
6075
  return format$1;
@@ -6093,11 +6102,11 @@
6093
6102
  if (hasRequiredDraft7) return draft7;
6094
6103
  hasRequiredDraft7 = 1;
6095
6104
  Object.defineProperty(draft7, "__esModule", { value: true });
6096
- const core_1 = requireCore();
6097
- const validation_1 = requireValidation();
6098
- const applicator_1 = requireApplicator();
6099
- const format_1 = requireFormat();
6100
- const metadata_1 = requireMetadata();
6105
+ const core_1 = /* @__PURE__ */ requireCore();
6106
+ const validation_1 = /* @__PURE__ */ requireValidation();
6107
+ const applicator_1 = /* @__PURE__ */ requireApplicator();
6108
+ const format_1 = /* @__PURE__ */ requireFormat();
6109
+ const metadata_1 = /* @__PURE__ */ requireMetadata();
6101
6110
  const draft7Vocabularies = [
6102
6111
  core_1.default,
6103
6112
  validation_1.default,
@@ -6129,11 +6138,11 @@
6129
6138
  if (hasRequiredDiscriminator) return discriminator;
6130
6139
  hasRequiredDiscriminator = 1;
6131
6140
  Object.defineProperty(discriminator, "__esModule", { value: true });
6132
- const codegen_1 = requireCodegen();
6133
- const types_1 = requireTypes();
6134
- const compile_1 = requireCompile();
6135
- const ref_error_1 = requireRef_error();
6136
- const util_1 = requireUtil();
6141
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
6142
+ const types_1 = /* @__PURE__ */ requireTypes();
6143
+ const compile_1 = /* @__PURE__ */ requireCompile();
6144
+ const ref_error_1 = /* @__PURE__ */ requireRef_error();
6145
+ const util_1 = /* @__PURE__ */ requireUtil();
6137
6146
  const error = {
6138
6147
  message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag ? `tag "${tagName}" must be string` : `value of tag "${tagName}" must be in oneOf`,
6139
6148
  params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._)`{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`
@@ -6250,9 +6259,9 @@
6250
6259
  (function(module2, exports3) {
6251
6260
  Object.defineProperty(exports3, "__esModule", { value: true });
6252
6261
  exports3.MissingRefError = exports3.ValidationError = exports3.CodeGen = exports3.Name = exports3.nil = exports3.stringify = exports3.str = exports3._ = exports3.KeywordCxt = exports3.Ajv = void 0;
6253
- const core_1 = requireCore$1();
6254
- const draft7_1 = requireDraft7();
6255
- const discriminator_1 = requireDiscriminator();
6262
+ const core_1 = /* @__PURE__ */ requireCore$1();
6263
+ const draft7_1 = /* @__PURE__ */ requireDraft7();
6264
+ const discriminator_1 = /* @__PURE__ */ requireDiscriminator();
6256
6265
  const draft7MetaSchema = require$$3;
6257
6266
  const META_SUPPORT_DATA = ["/properties"];
6258
6267
  const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
@@ -6280,11 +6289,11 @@
6280
6289
  module2.exports.Ajv = Ajv2;
6281
6290
  Object.defineProperty(exports3, "__esModule", { value: true });
6282
6291
  exports3.default = Ajv2;
6283
- var validate_1 = requireValidate();
6292
+ var validate_1 = /* @__PURE__ */ requireValidate();
6284
6293
  Object.defineProperty(exports3, "KeywordCxt", { enumerable: true, get: function() {
6285
6294
  return validate_1.KeywordCxt;
6286
6295
  } });
6287
- var codegen_1 = requireCodegen();
6296
+ var codegen_1 = /* @__PURE__ */ requireCodegen();
6288
6297
  Object.defineProperty(exports3, "_", { enumerable: true, get: function() {
6289
6298
  return codegen_1._;
6290
6299
  } });
@@ -6303,18 +6312,18 @@
6303
6312
  Object.defineProperty(exports3, "CodeGen", { enumerable: true, get: function() {
6304
6313
  return codegen_1.CodeGen;
6305
6314
  } });
6306
- var validation_error_1 = requireValidation_error();
6315
+ var validation_error_1 = /* @__PURE__ */ requireValidation_error();
6307
6316
  Object.defineProperty(exports3, "ValidationError", { enumerable: true, get: function() {
6308
6317
  return validation_error_1.default;
6309
6318
  } });
6310
- var ref_error_1 = requireRef_error();
6319
+ var ref_error_1 = /* @__PURE__ */ requireRef_error();
6311
6320
  Object.defineProperty(exports3, "MissingRefError", { enumerable: true, get: function() {
6312
6321
  return ref_error_1.default;
6313
6322
  } });
6314
6323
  })(ajv, ajv.exports);
6315
6324
  return ajv.exports;
6316
6325
  }
6317
- var ajvExports = requireAjv();
6326
+ var ajvExports = /* @__PURE__ */ requireAjv();
6318
6327
  const Ajv = /* @__PURE__ */ getDefaultExportFromCjs(ajvExports);
6319
6328
  var util;
6320
6329
  (function(util2) {
@@ -18625,8 +18634,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18625
18634
  (function(exports3) {
18626
18635
  Object.defineProperty(exports3, "__esModule", { value: true });
18627
18636
  exports3.formatLimitDefinition = void 0;
18628
- const ajv_1 = requireAjv();
18629
- const codegen_1 = requireCodegen();
18637
+ const ajv_1 = /* @__PURE__ */ requireAjv();
18638
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
18630
18639
  const ops = codegen_1.operators;
18631
18640
  const KWDs = {
18632
18641
  formatMaximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
@@ -18699,7 +18708,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18699
18708
  Object.defineProperty(exports3, "__esModule", { value: true });
18700
18709
  const formats_1 = requireFormats();
18701
18710
  const limit_1 = requireLimit();
18702
- const codegen_1 = requireCodegen();
18711
+ const codegen_1 = /* @__PURE__ */ requireCodegen();
18703
18712
  const fullName = new codegen_1.Name("fullFormats");
18704
18713
  const fastName = new codegen_1.Name("fastFormats");
18705
18714
  const formatsPlugin = (ajv2, opts = { keywords: true }) => {
@@ -28044,25 +28053,30 @@ Error message: ${getErrorMessage$2(cause)}`,
28044
28053
  }
28045
28054
  function createToolNameMapping({
28046
28055
  tools = [],
28047
- providerToolNames
28056
+ providerToolNames,
28057
+ resolveProviderToolName
28048
28058
  }) {
28059
+ var _a22;
28049
28060
  const customToolNameToProviderToolName = {};
28050
28061
  const providerToolNameToCustomToolName = {};
28051
28062
  for (const tool2 of tools) {
28052
- if (tool2.type === "provider" && tool2.id in providerToolNames) {
28053
- const providerToolName = providerToolNames[tool2.id];
28063
+ if (tool2.type === "provider") {
28064
+ const providerToolName = (_a22 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a22 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
28065
+ if (providerToolName == null) {
28066
+ continue;
28067
+ }
28054
28068
  customToolNameToProviderToolName[tool2.name] = providerToolName;
28055
28069
  providerToolNameToCustomToolName[providerToolName] = tool2.name;
28056
28070
  }
28057
28071
  }
28058
28072
  return {
28059
28073
  toProviderToolName: (customToolName) => {
28060
- var _a22;
28061
- return (_a22 = customToolNameToProviderToolName[customToolName]) != null ? _a22 : customToolName;
28074
+ var _a32;
28075
+ return (_a32 = customToolNameToProviderToolName[customToolName]) != null ? _a32 : customToolName;
28062
28076
  },
28063
28077
  toCustomToolName: (providerToolName) => {
28064
- var _a22;
28065
- return (_a22 = providerToolNameToCustomToolName[providerToolName]) != null ? _a22 : providerToolName;
28078
+ var _a32;
28079
+ return (_a32 = providerToolNameToCustomToolName[providerToolName]) != null ? _a32 : providerToolName;
28066
28080
  }
28067
28081
  };
28068
28082
  }
@@ -28255,8 +28269,103 @@ Error message: ${getErrorMessage$2(cause)}`,
28255
28269
  }
28256
28270
  return result;
28257
28271
  }
28272
+ function validateDownloadUrl(url2) {
28273
+ let parsed;
28274
+ try {
28275
+ parsed = new URL(url2);
28276
+ } catch (e) {
28277
+ throw new DownloadError({
28278
+ url: url2,
28279
+ message: `Invalid URL: ${url2}`
28280
+ });
28281
+ }
28282
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
28283
+ throw new DownloadError({
28284
+ url: url2,
28285
+ message: `URL scheme must be http or https, got ${parsed.protocol}`
28286
+ });
28287
+ }
28288
+ const hostname2 = parsed.hostname;
28289
+ if (!hostname2) {
28290
+ throw new DownloadError({
28291
+ url: url2,
28292
+ message: `URL must have a hostname`
28293
+ });
28294
+ }
28295
+ if (hostname2 === "localhost" || hostname2.endsWith(".local") || hostname2.endsWith(".localhost")) {
28296
+ throw new DownloadError({
28297
+ url: url2,
28298
+ message: `URL with hostname ${hostname2} is not allowed`
28299
+ });
28300
+ }
28301
+ if (hostname2.startsWith("[") && hostname2.endsWith("]")) {
28302
+ const ipv62 = hostname2.slice(1, -1);
28303
+ if (isPrivateIPv6(ipv62)) {
28304
+ throw new DownloadError({
28305
+ url: url2,
28306
+ message: `URL with IPv6 address ${hostname2} is not allowed`
28307
+ });
28308
+ }
28309
+ return;
28310
+ }
28311
+ if (isIPv4(hostname2)) {
28312
+ if (isPrivateIPv4(hostname2)) {
28313
+ throw new DownloadError({
28314
+ url: url2,
28315
+ message: `URL with IP address ${hostname2} is not allowed`
28316
+ });
28317
+ }
28318
+ return;
28319
+ }
28320
+ }
28321
+ function isIPv4(hostname2) {
28322
+ const parts = hostname2.split(".");
28323
+ if (parts.length !== 4) return false;
28324
+ return parts.every((part) => {
28325
+ const num = Number(part);
28326
+ return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
28327
+ });
28328
+ }
28329
+ function isPrivateIPv4(ip) {
28330
+ const parts = ip.split(".").map(Number);
28331
+ const [a, b] = parts;
28332
+ if (a === 0) return true;
28333
+ if (a === 10) return true;
28334
+ if (a === 127) return true;
28335
+ if (a === 169 && b === 254) return true;
28336
+ if (a === 172 && b >= 16 && b <= 31) return true;
28337
+ if (a === 192 && b === 168) return true;
28338
+ return false;
28339
+ }
28340
+ function isPrivateIPv6(ip) {
28341
+ const normalized = ip.toLowerCase();
28342
+ if (normalized === "::1") return true;
28343
+ if (normalized === "::") return true;
28344
+ if (normalized.startsWith("::ffff:")) {
28345
+ const mappedPart = normalized.slice(7);
28346
+ if (isIPv4(mappedPart)) {
28347
+ return isPrivateIPv4(mappedPart);
28348
+ }
28349
+ const hexParts = mappedPart.split(":");
28350
+ if (hexParts.length === 2) {
28351
+ const high = parseInt(hexParts[0], 16);
28352
+ const low = parseInt(hexParts[1], 16);
28353
+ if (!isNaN(high) && !isNaN(low)) {
28354
+ const a = high >> 8 & 255;
28355
+ const b = high & 255;
28356
+ const c = low >> 8 & 255;
28357
+ const d = low & 255;
28358
+ return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
28359
+ }
28360
+ }
28361
+ }
28362
+ if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
28363
+ if (normalized.startsWith("fe80")) return true;
28364
+ return false;
28365
+ }
28258
28366
  async function downloadBlob(url2, options) {
28259
28367
  var _a22, _b22;
28368
+ validateDownloadUrl(url2);
28260
28369
  try {
28261
28370
  const response = await fetch(url2, {
28262
28371
  signal: options == null ? void 0 : options.abortSignal
@@ -28422,7 +28531,7 @@ Error message: ${getErrorMessage$2(cause)}`,
28422
28531
  );
28423
28532
  return Object.fromEntries(normalizedHeaders.entries());
28424
28533
  }
28425
- var VERSION$7 = "4.0.15";
28534
+ var VERSION$7 = "4.0.19";
28426
28535
  var getOriginalFetch = () => globalThis.fetch;
28427
28536
  var getFromApi = async ({
28428
28537
  url: url2,
@@ -28565,8 +28674,8 @@ Error message: ${getErrorMessage$2(cause)}`,
28565
28674
  "x-m4a": "m4a"
28566
28675
  }[subtype]) != null ? _a22 : subtype;
28567
28676
  }
28568
- var suspectProtoRx$1 = /"__proto__"\s*:/;
28569
- var suspectConstructorRx$1 = /"constructor"\s*:/;
28677
+ var suspectProtoRx$1 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
28678
+ 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*:/;
28570
28679
  function _parse$1(text2) {
28571
28680
  const obj = JSON.parse(text2);
28572
28681
  if (obj === null || typeof obj !== "object") {
@@ -28586,7 +28695,7 @@ Error message: ${getErrorMessage$2(cause)}`,
28586
28695
  if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
28587
28696
  throw new SyntaxError("Object contains forbidden prototype property");
28588
28697
  }
28589
- if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
28698
+ if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
28590
28699
  throw new SyntaxError("Object contains forbidden prototype property");
28591
28700
  }
28592
28701
  for (const key in node) {
@@ -30073,6 +30182,33 @@ Error message: ${getErrorMessage$2(cause)}`,
30073
30182
  function dynamicTool(tool2) {
30074
30183
  return { ...tool2, type: "dynamic" };
30075
30184
  }
30185
+ function createProviderToolFactory({
30186
+ id: id2,
30187
+ inputSchema
30188
+ }) {
30189
+ return ({
30190
+ execute,
30191
+ outputSchema: outputSchema2,
30192
+ needsApproval,
30193
+ toModelOutput,
30194
+ onInputStart,
30195
+ onInputDelta,
30196
+ onInputAvailable,
30197
+ ...args
30198
+ }) => tool({
30199
+ type: "provider",
30200
+ id: id2,
30201
+ args,
30202
+ inputSchema,
30203
+ outputSchema: outputSchema2,
30204
+ execute,
30205
+ needsApproval,
30206
+ toModelOutput,
30207
+ onInputStart,
30208
+ onInputDelta,
30209
+ onInputAvailable
30210
+ });
30211
+ }
30076
30212
  function createProviderToolFactoryWithOutputSchema({
30077
30213
  id: id2,
30078
30214
  inputSchema,
@@ -31197,17 +31333,14 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
31197
31333
  var _a92;
31198
31334
  const resolvedHeaders = await resolve(this.config.headers());
31199
31335
  try {
31200
- const {
31201
- responseHeaders,
31202
- value: responseBody,
31203
- rawValue
31204
- } = await postJsonToApi$1({
31336
+ const { responseHeaders, value: responseBody } = await postJsonToApi$1({
31205
31337
  url: this.getUrl(),
31206
31338
  headers: combineHeaders$1(
31207
31339
  resolvedHeaders,
31208
31340
  headers != null ? headers : {},
31209
31341
  this.getModelConfigHeaders(),
31210
- await resolve(this.config.o11yHeaders)
31342
+ await resolve(this.config.o11yHeaders),
31343
+ { accept: "text/event-stream" }
31211
31344
  ),
31212
31345
  body: {
31213
31346
  prompt,
@@ -31220,9 +31353,70 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
31220
31353
  ...providerOptions && { providerOptions },
31221
31354
  ...image && { image: maybeEncodeVideoFile(image) }
31222
31355
  },
31223
- successfulResponseHandler: createJsonResponseHandler$1(
31224
- gatewayVideoResponseSchema
31225
- ),
31356
+ successfulResponseHandler: async ({
31357
+ response,
31358
+ url: url2,
31359
+ requestBodyValues
31360
+ }) => {
31361
+ if (response.body == null) {
31362
+ throw new APICallError$1({
31363
+ message: "SSE response body is empty",
31364
+ url: url2,
31365
+ requestBodyValues,
31366
+ statusCode: response.status
31367
+ });
31368
+ }
31369
+ const eventStream = parseJsonEventStream$1({
31370
+ stream: response.body,
31371
+ schema: gatewayVideoEventSchema
31372
+ });
31373
+ const reader = eventStream.getReader();
31374
+ const { done, value: parseResult } = await reader.read();
31375
+ reader.releaseLock();
31376
+ if (done || !parseResult) {
31377
+ throw new APICallError$1({
31378
+ message: "SSE stream ended without a data event",
31379
+ url: url2,
31380
+ requestBodyValues,
31381
+ statusCode: response.status
31382
+ });
31383
+ }
31384
+ if (!parseResult.success) {
31385
+ throw new APICallError$1({
31386
+ message: "Failed to parse video SSE event",
31387
+ cause: parseResult.error,
31388
+ url: url2,
31389
+ requestBodyValues,
31390
+ statusCode: response.status
31391
+ });
31392
+ }
31393
+ const event = parseResult.value;
31394
+ if (event.type === "error") {
31395
+ throw new APICallError$1({
31396
+ message: event.message,
31397
+ statusCode: event.statusCode,
31398
+ url: url2,
31399
+ requestBodyValues,
31400
+ responseHeaders: Object.fromEntries([...response.headers]),
31401
+ responseBody: JSON.stringify(event),
31402
+ data: {
31403
+ error: {
31404
+ message: event.message,
31405
+ type: event.errorType,
31406
+ param: event.param
31407
+ }
31408
+ }
31409
+ });
31410
+ }
31411
+ return {
31412
+ value: {
31413
+ videos: event.videos,
31414
+ warnings: event.warnings,
31415
+ providerMetadata: event.providerMetadata
31416
+ },
31417
+ responseHeaders: Object.fromEntries([...response.headers])
31418
+ };
31419
+ },
31226
31420
  failedResponseHandler: createJsonErrorResponseHandler$1({
31227
31421
  errorSchema: any(),
31228
31422
  errorToMessage: (data) => data
@@ -31294,11 +31488,21 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
31294
31488
  message: string()
31295
31489
  })
31296
31490
  ]);
31297
- var gatewayVideoResponseSchema = object$2({
31298
- videos: array$1(gatewayVideoDataSchema),
31299
- warnings: array$1(gatewayVideoWarningSchema).optional(),
31300
- providerMetadata: record(string(), providerMetadataEntrySchema2).optional()
31301
- });
31491
+ var gatewayVideoEventSchema = discriminatedUnion("type", [
31492
+ object$2({
31493
+ type: literal("result"),
31494
+ videos: array$1(gatewayVideoDataSchema),
31495
+ warnings: array$1(gatewayVideoWarningSchema).optional(),
31496
+ providerMetadata: record(string(), providerMetadataEntrySchema2).optional()
31497
+ }),
31498
+ object$2({
31499
+ type: literal("error"),
31500
+ message: string(),
31501
+ errorType: string(),
31502
+ statusCode: number$1(),
31503
+ param: unknown().nullable()
31504
+ })
31505
+ ]);
31302
31506
  var parallelSearchInputSchema = lazySchema(
31303
31507
  () => zodSchema(
31304
31508
  objectType({
@@ -31475,7 +31679,7 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
31475
31679
  var _a92;
31476
31680
  return (_a92 = indexBrowserExports.getContext().headers) == null ? void 0 : _a92["x-vercel-id"];
31477
31681
  }
31478
- var VERSION$6 = "3.0.45";
31682
+ var VERSION$6 = "3.0.66";
31479
31683
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
31480
31684
  function createGatewayProvider(options = {}) {
31481
31685
  var _a92, _b9;
@@ -31518,13 +31722,18 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
31518
31722
  settingValue: void 0,
31519
31723
  environmentVariableName: "VERCEL_REGION"
31520
31724
  });
31725
+ const projectId = loadOptionalSetting({
31726
+ settingValue: void 0,
31727
+ environmentVariableName: "VERCEL_PROJECT_ID"
31728
+ });
31521
31729
  return async () => {
31522
31730
  const requestId = await getVercelRequestId();
31523
31731
  return {
31524
31732
  ...deploymentId && { "ai-o11y-deployment-id": deploymentId },
31525
31733
  ...environment && { "ai-o11y-environment": environment },
31526
31734
  ...region && { "ai-o11y-region": region },
31527
- ...requestId && { "ai-o11y-request-id": requestId }
31735
+ ...requestId && { "ai-o11y-request-id": requestId },
31736
+ ...projectId && { "ai-o11y-project-id": projectId }
31528
31737
  };
31529
31738
  };
31530
31739
  };
@@ -32992,6 +33201,19 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
32992
33201
  }
32993
33202
  };
32994
33203
  _a19 = symbol19;
33204
+ function asArray(value) {
33205
+ return value === void 0 ? [] : Array.isArray(value) ? value : [value];
33206
+ }
33207
+ async function notify(options) {
33208
+ for (const callback of asArray(options.callbacks)) {
33209
+ if (callback == null)
33210
+ continue;
33211
+ try {
33212
+ await callback(options.event);
33213
+ } catch (_ignored) {
33214
+ }
33215
+ }
33216
+ }
32995
33217
  function formatWarning({
32996
33218
  warning,
32997
33219
  provider,
@@ -33292,7 +33514,7 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
33292
33514
  }
33293
33515
  return void 0;
33294
33516
  }
33295
- var VERSION$4 = "6.0.85";
33517
+ var VERSION$4 = "6.0.116";
33296
33518
  var download = async ({
33297
33519
  url: url2,
33298
33520
  maxBytes,
@@ -33300,6 +33522,7 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
33300
33522
  }) => {
33301
33523
  var _a21;
33302
33524
  const urlText = url2.toString();
33525
+ validateDownloadUrl(urlText);
33303
33526
  try {
33304
33527
  const response = await fetch(urlText, {
33305
33528
  headers: withUserAgentSuffix$1(
@@ -33400,9 +33623,6 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
33400
33623
  }
33401
33624
  return convertUint8ArrayToBase64$1(content);
33402
33625
  }
33403
- function asArray(value) {
33404
- return value === void 0 ? [] : Array.isArray(value) ? value : [value];
33405
- }
33406
33626
  async function convertToLanguageModelPrompt({
33407
33627
  prompt,
33408
33628
  supportedUrls,
@@ -34408,6 +34628,44 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
34408
34628
  }))
34409
34629
  );
34410
34630
  }
34631
+ function getGlobalTelemetryIntegrations() {
34632
+ var _a21;
34633
+ return (_a21 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a21 : [];
34634
+ }
34635
+ function getGlobalTelemetryIntegration() {
34636
+ const globalIntegrations = getGlobalTelemetryIntegrations();
34637
+ return (integrations) => {
34638
+ const localIntegrations = asArray(integrations);
34639
+ const allIntegrations = [...globalIntegrations, ...localIntegrations];
34640
+ function createTelemetryComposite(getListenerFromIntegration) {
34641
+ const listeners = allIntegrations.map(getListenerFromIntegration).filter(Boolean);
34642
+ return async (event) => {
34643
+ for (const listener of listeners) {
34644
+ try {
34645
+ await listener(event);
34646
+ } catch (_ignored) {
34647
+ }
34648
+ }
34649
+ };
34650
+ }
34651
+ return {
34652
+ onStart: createTelemetryComposite((integration) => integration.onStart),
34653
+ onStepStart: createTelemetryComposite(
34654
+ (integration) => integration.onStepStart
34655
+ ),
34656
+ onToolCallStart: createTelemetryComposite(
34657
+ (integration) => integration.onToolCallStart
34658
+ ),
34659
+ onToolCallFinish: createTelemetryComposite(
34660
+ (integration) => integration.onToolCallFinish
34661
+ ),
34662
+ onStepFinish: createTelemetryComposite(
34663
+ (integration) => integration.onStepFinish
34664
+ ),
34665
+ onFinish: createTelemetryComposite((integration) => integration.onFinish)
34666
+ };
34667
+ };
34668
+ }
34411
34669
  function asLanguageModelUsage(usage) {
34412
34670
  return {
34413
34671
  inputTokens: usage.inputTokens.total,
@@ -34717,6 +34975,10 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
34717
34975
  }
34718
34976
  return { approvedToolApprovals, deniedToolApprovals };
34719
34977
  }
34978
+ function now() {
34979
+ var _a21, _b9;
34980
+ return (_b9 = (_a21 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a21.now()) != null ? _b9 : Date.now();
34981
+ }
34720
34982
  async function executeToolCall({
34721
34983
  toolCall,
34722
34984
  tools,
@@ -34725,13 +34987,27 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
34725
34987
  messages,
34726
34988
  abortSignal,
34727
34989
  experimental_context,
34728
- onPreliminaryToolResult
34990
+ stepNumber,
34991
+ model,
34992
+ onPreliminaryToolResult,
34993
+ onToolCallStart,
34994
+ onToolCallFinish
34729
34995
  }) {
34730
34996
  const { toolName, toolCallId, input } = toolCall;
34731
34997
  const tool2 = tools == null ? void 0 : tools[toolName];
34732
34998
  if ((tool2 == null ? void 0 : tool2.execute) == null) {
34733
34999
  return void 0;
34734
35000
  }
35001
+ const baseCallbackEvent = {
35002
+ stepNumber,
35003
+ model,
35004
+ toolCall,
35005
+ messages,
35006
+ abortSignal,
35007
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
35008
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
35009
+ experimental_context
35010
+ };
34735
35011
  return recordSpan({
34736
35012
  name: "ai.toolCall",
34737
35013
  attributes: selectTelemetryAttributes({
@@ -34751,6 +35027,8 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
34751
35027
  tracer,
34752
35028
  fn: async (span) => {
34753
35029
  let output;
35030
+ await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
35031
+ const startTime = now();
34754
35032
  try {
34755
35033
  const stream = executeTool({
34756
35034
  execute: tool2.execute.bind(tool2),
@@ -34775,6 +35053,16 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
34775
35053
  }
34776
35054
  }
34777
35055
  } catch (error) {
35056
+ const durationMs2 = now() - startTime;
35057
+ await notify({
35058
+ event: {
35059
+ ...baseCallbackEvent,
35060
+ success: false,
35061
+ error,
35062
+ durationMs: durationMs2
35063
+ },
35064
+ callbacks: onToolCallFinish
35065
+ });
34778
35066
  recordErrorOnSpan(span, error);
34779
35067
  return {
34780
35068
  type: "tool-error",
@@ -34786,6 +35074,16 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
34786
35074
  ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {}
34787
35075
  };
34788
35076
  }
35077
+ const durationMs = now() - startTime;
35078
+ await notify({
35079
+ event: {
35080
+ ...baseCallbackEvent,
35081
+ success: true,
35082
+ output,
35083
+ durationMs
35084
+ },
35085
+ callbacks: onToolCallFinish
35086
+ });
34789
35087
  try {
34790
35088
  span.setAttributes(
34791
35089
  await selectTelemetryAttributes({
@@ -35649,6 +35947,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35649
35947
  }
35650
35948
  var DefaultStepResult = class {
35651
35949
  constructor({
35950
+ stepNumber,
35951
+ model,
35952
+ functionId,
35953
+ metadata: metadata2,
35954
+ experimental_context,
35652
35955
  content,
35653
35956
  finishReason,
35654
35957
  rawFinishReason,
@@ -35658,6 +35961,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35658
35961
  response,
35659
35962
  providerMetadata
35660
35963
  }) {
35964
+ this.stepNumber = stepNumber;
35965
+ this.model = model;
35966
+ this.functionId = functionId;
35967
+ this.metadata = metadata2;
35968
+ this.experimental_context = experimental_context;
35661
35969
  this.content = content;
35662
35970
  this.finishReason = finishReason;
35663
35971
  this.rawFinishReason = rawFinishReason;
@@ -35899,11 +36207,16 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35899
36207
  experimental_context,
35900
36208
  experimental_include: include,
35901
36209
  _internal: { generateId: generateId2 = originalGenerateId } = {},
36210
+ experimental_onStart: onStart,
36211
+ experimental_onStepStart: onStepStart,
36212
+ experimental_onToolCallStart: onToolCallStart,
36213
+ experimental_onToolCallFinish: onToolCallFinish,
35902
36214
  onStepFinish,
35903
36215
  onFinish,
35904
36216
  ...settings
35905
36217
  }) {
35906
36218
  const model = resolveLanguageModel(modelArg);
36219
+ const createGlobalTelemetry = getGlobalTelemetryIntegration();
35907
36220
  const stopConditions = asArray(stopWhen);
35908
36221
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
35909
36222
  const stepTimeoutMs = getStepTimeoutMs(timeout);
@@ -35928,11 +36241,47 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35928
36241
  headers: headersWithUserAgent,
35929
36242
  settings: { ...callSettings, maxRetries }
35930
36243
  });
36244
+ const modelInfo = { provider: model.provider, modelId: model.modelId };
35931
36245
  const initialPrompt = await standardizePrompt({
35932
36246
  system,
35933
36247
  prompt,
35934
36248
  messages
35935
36249
  });
36250
+ const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
36251
+ await notify({
36252
+ event: {
36253
+ model: modelInfo,
36254
+ system,
36255
+ prompt,
36256
+ messages,
36257
+ tools,
36258
+ toolChoice,
36259
+ activeTools,
36260
+ maxOutputTokens: callSettings.maxOutputTokens,
36261
+ temperature: callSettings.temperature,
36262
+ topP: callSettings.topP,
36263
+ topK: callSettings.topK,
36264
+ presencePenalty: callSettings.presencePenalty,
36265
+ frequencyPenalty: callSettings.frequencyPenalty,
36266
+ stopSequences: callSettings.stopSequences,
36267
+ seed: callSettings.seed,
36268
+ maxRetries,
36269
+ timeout,
36270
+ headers,
36271
+ providerOptions,
36272
+ stopWhen,
36273
+ output,
36274
+ abortSignal,
36275
+ include,
36276
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
36277
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
36278
+ experimental_context
36279
+ },
36280
+ callbacks: [
36281
+ onStart,
36282
+ globalTelemetry.onStart
36283
+ ]
36284
+ });
35936
36285
  const tracer = getTracer(telemetry);
35937
36286
  try {
35938
36287
  return await recordSpan({
@@ -35956,7 +36305,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35956
36305
  }),
35957
36306
  tracer,
35958
36307
  fn: async (span) => {
35959
- var _a21, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k;
36308
+ var _a21, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
35960
36309
  const initialMessages = initialPrompt.messages;
35961
36310
  const responseMessages = [];
35962
36311
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
@@ -35973,7 +36322,17 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35973
36322
  telemetry,
35974
36323
  messages: initialMessages,
35975
36324
  abortSignal: mergedAbortSignal,
35976
- experimental_context
36325
+ experimental_context,
36326
+ stepNumber: 0,
36327
+ model: modelInfo,
36328
+ onToolCallStart: [
36329
+ onToolCallStart,
36330
+ globalTelemetry.onToolCallStart
36331
+ ],
36332
+ onToolCallFinish: [
36333
+ onToolCallFinish,
36334
+ globalTelemetry.onToolCallFinish
36335
+ ]
35977
36336
  });
35978
36337
  const toolContent = [];
35979
36338
  for (const output2 of toolOutputs) {
@@ -35982,7 +36341,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
35982
36341
  input: output2.input,
35983
36342
  tool: tools == null ? void 0 : tools[output2.toolName],
35984
36343
  output: output2.type === "tool-result" ? output2.output : output2.error,
35985
- errorMode: output2.type === "tool-error" ? "json" : "none"
36344
+ errorMode: output2.type === "tool-error" ? "text" : "none"
35986
36345
  });
35987
36346
  toolContent.push({
35988
36347
  type: "tool-result",
@@ -36053,6 +36412,10 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36053
36412
  const stepModel = resolveLanguageModel(
36054
36413
  (_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
36055
36414
  );
36415
+ const stepModelInfo = {
36416
+ provider: stepModel.provider,
36417
+ modelId: stepModel.modelId
36418
+ };
36056
36419
  const promptMessages = await convertToLanguageModelPrompt({
36057
36420
  prompt: {
36058
36421
  system: (_b9 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b9 : initialPrompt.system,
@@ -36062,10 +36425,43 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36062
36425
  download: download2
36063
36426
  });
36064
36427
  experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
36428
+ const stepActiveTools = (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools;
36065
36429
  const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
36066
36430
  tools,
36067
- toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
36068
- activeTools: (_f = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _f : activeTools
36431
+ toolChoice: (_f = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _f : toolChoice,
36432
+ activeTools: stepActiveTools
36433
+ });
36434
+ const stepMessages = (_g = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _g : stepInputMessages;
36435
+ const stepSystem = (_h = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _h : initialPrompt.system;
36436
+ const stepProviderOptions = mergeObjects(
36437
+ providerOptions,
36438
+ prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
36439
+ );
36440
+ await notify({
36441
+ event: {
36442
+ stepNumber: steps.length,
36443
+ model: stepModelInfo,
36444
+ system: stepSystem,
36445
+ messages: stepMessages,
36446
+ tools,
36447
+ toolChoice: stepToolChoice,
36448
+ activeTools: stepActiveTools,
36449
+ steps: [...steps],
36450
+ providerOptions: stepProviderOptions,
36451
+ timeout,
36452
+ headers,
36453
+ stopWhen,
36454
+ output,
36455
+ abortSignal,
36456
+ include,
36457
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
36458
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
36459
+ experimental_context
36460
+ },
36461
+ callbacks: [
36462
+ onStepStart,
36463
+ globalTelemetry.onStepStart
36464
+ ]
36069
36465
  });
36070
36466
  currentModelResponse = await retry(
36071
36467
  () => {
@@ -36109,10 +36505,6 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36109
36505
  tracer,
36110
36506
  fn: async (span2) => {
36111
36507
  var _a23, _b22, _c2, _d2, _e2, _f2, _g2, _h2;
36112
- const stepProviderOptions = mergeObjects(
36113
- providerOptions,
36114
- prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
36115
- );
36116
36508
  const result = await stepModel.doGenerate({
36117
36509
  ...callSettings2,
36118
36510
  tools: stepTools,
@@ -36244,7 +36636,17 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36244
36636
  telemetry,
36245
36637
  messages: stepInputMessages,
36246
36638
  abortSignal: mergedAbortSignal,
36247
- experimental_context
36639
+ experimental_context,
36640
+ stepNumber: steps.length,
36641
+ model: stepModelInfo,
36642
+ onToolCallStart: [
36643
+ onToolCallStart,
36644
+ globalTelemetry.onToolCallStart
36645
+ ],
36646
+ onToolCallFinish: [
36647
+ onToolCallFinish,
36648
+ globalTelemetry.onToolCallFinish
36649
+ ]
36248
36650
  })
36249
36651
  );
36250
36652
  }
@@ -36281,15 +36683,21 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36281
36683
  tools
36282
36684
  })
36283
36685
  );
36284
- const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? (_h = currentModelResponse.request) != null ? _h : {} : { ...currentModelResponse.request, body: void 0 };
36686
+ const stepRequest = ((_i = include == null ? void 0 : include.requestBody) != null ? _i : true) ? (_j = currentModelResponse.request) != null ? _j : {} : { ...currentModelResponse.request, body: void 0 };
36285
36687
  const stepResponse = {
36286
36688
  ...currentModelResponse.response,
36287
36689
  // deep clone msgs to avoid mutating past messages in multi-step:
36288
36690
  messages: structuredClone(responseMessages),
36289
36691
  // Conditionally include response body:
36290
- body: ((_i = include == null ? void 0 : include.responseBody) != null ? _i : true) ? (_j = currentModelResponse.response) == null ? void 0 : _j.body : void 0
36692
+ body: ((_k = include == null ? void 0 : include.responseBody) != null ? _k : true) ? (_l = currentModelResponse.response) == null ? void 0 : _l.body : void 0
36291
36693
  };
36694
+ const stepNumber = steps.length;
36292
36695
  const currentStepResult = new DefaultStepResult({
36696
+ stepNumber,
36697
+ model: stepModelInfo,
36698
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
36699
+ metadata: telemetry == null ? void 0 : telemetry.metadata,
36700
+ experimental_context,
36293
36701
  content: stepContent,
36294
36702
  finishReason: currentModelResponse.finishReason.unified,
36295
36703
  rawFinishReason: currentModelResponse.finishReason.raw,
@@ -36300,12 +36708,15 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36300
36708
  response: stepResponse
36301
36709
  });
36302
36710
  logWarnings({
36303
- warnings: (_k = currentModelResponse.warnings) != null ? _k : [],
36304
- provider: stepModel.provider,
36305
- model: stepModel.modelId
36711
+ warnings: (_m = currentModelResponse.warnings) != null ? _m : [],
36712
+ provider: stepModelInfo.provider,
36713
+ model: stepModelInfo.modelId
36306
36714
  });
36307
36715
  steps.push(currentStepResult);
36308
- await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
36716
+ await notify({
36717
+ event: currentStepResult,
36718
+ callbacks: [onStepFinish, globalTelemetry.onStepFinish]
36719
+ });
36309
36720
  } finally {
36310
36721
  if (stepTimeoutId != null) {
36311
36722
  clearTimeout(stepTimeoutId);
@@ -36357,30 +36768,40 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36357
36768
  cachedInputTokens: void 0
36358
36769
  }
36359
36770
  );
36360
- await (onFinish == null ? void 0 : onFinish({
36361
- finishReason: lastStep.finishReason,
36362
- rawFinishReason: lastStep.rawFinishReason,
36363
- usage: lastStep.usage,
36364
- content: lastStep.content,
36365
- text: lastStep.text,
36366
- reasoningText: lastStep.reasoningText,
36367
- reasoning: lastStep.reasoning,
36368
- files: lastStep.files,
36369
- sources: lastStep.sources,
36370
- toolCalls: lastStep.toolCalls,
36371
- staticToolCalls: lastStep.staticToolCalls,
36372
- dynamicToolCalls: lastStep.dynamicToolCalls,
36373
- toolResults: lastStep.toolResults,
36374
- staticToolResults: lastStep.staticToolResults,
36375
- dynamicToolResults: lastStep.dynamicToolResults,
36376
- request: lastStep.request,
36377
- response: lastStep.response,
36378
- warnings: lastStep.warnings,
36379
- providerMetadata: lastStep.providerMetadata,
36380
- steps,
36381
- totalUsage,
36382
- experimental_context
36383
- }));
36771
+ await notify({
36772
+ event: {
36773
+ stepNumber: lastStep.stepNumber,
36774
+ model: lastStep.model,
36775
+ functionId: lastStep.functionId,
36776
+ metadata: lastStep.metadata,
36777
+ experimental_context: lastStep.experimental_context,
36778
+ finishReason: lastStep.finishReason,
36779
+ rawFinishReason: lastStep.rawFinishReason,
36780
+ usage: lastStep.usage,
36781
+ content: lastStep.content,
36782
+ text: lastStep.text,
36783
+ reasoningText: lastStep.reasoningText,
36784
+ reasoning: lastStep.reasoning,
36785
+ files: lastStep.files,
36786
+ sources: lastStep.sources,
36787
+ toolCalls: lastStep.toolCalls,
36788
+ staticToolCalls: lastStep.staticToolCalls,
36789
+ dynamicToolCalls: lastStep.dynamicToolCalls,
36790
+ toolResults: lastStep.toolResults,
36791
+ staticToolResults: lastStep.staticToolResults,
36792
+ dynamicToolResults: lastStep.dynamicToolResults,
36793
+ request: lastStep.request,
36794
+ response: lastStep.response,
36795
+ warnings: lastStep.warnings,
36796
+ providerMetadata: lastStep.providerMetadata,
36797
+ steps,
36798
+ totalUsage
36799
+ },
36800
+ callbacks: [
36801
+ onFinish,
36802
+ globalTelemetry.onFinish
36803
+ ]
36804
+ });
36384
36805
  let resolvedOutput;
36385
36806
  if (lastStep.finishReason === "stop") {
36386
36807
  const outputSpecification = output != null ? output : text();
@@ -36411,7 +36832,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36411
36832
  telemetry,
36412
36833
  messages,
36413
36834
  abortSignal,
36414
- experimental_context
36835
+ experimental_context,
36836
+ stepNumber,
36837
+ model,
36838
+ onToolCallStart,
36839
+ onToolCallFinish
36415
36840
  }) {
36416
36841
  const toolOutputs = await Promise.all(
36417
36842
  toolCalls.map(
@@ -36422,7 +36847,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36422
36847
  telemetry,
36423
36848
  messages,
36424
36849
  abortSignal,
36425
- experimental_context
36850
+ experimental_context,
36851
+ stepNumber,
36852
+ model,
36853
+ onToolCallStart,
36854
+ onToolCallFinish
36426
36855
  })
36427
36856
  )
36428
36857
  );
@@ -36990,7 +37419,8 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
36990
37419
  state.message.parts.push({
36991
37420
  type: "file",
36992
37421
  mediaType: chunk.mediaType,
36993
- url: chunk.url
37422
+ url: chunk.url,
37423
+ ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
36994
37424
  });
36995
37425
  write();
36996
37426
  break;
@@ -37115,7 +37545,9 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37115
37545
  break;
37116
37546
  }
37117
37547
  case "tool-input-error": {
37118
- if (chunk.dynamic) {
37548
+ const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
37549
+ const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
37550
+ if (isDynamic) {
37119
37551
  updateDynamicToolPart({
37120
37552
  toolCallId: chunk.toolCallId,
37121
37553
  toolName: chunk.toolName,
@@ -37583,10 +38015,6 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37583
38015
  terminate
37584
38016
  };
37585
38017
  }
37586
- function now() {
37587
- var _a21, _b9;
37588
- return (_b9 = (_a21 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a21.now()) != null ? _b9 : Date.now();
37589
- }
37590
38018
  function runToolsTransformation({
37591
38019
  tools,
37592
38020
  generatorStream,
@@ -37597,7 +38025,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37597
38025
  abortSignal,
37598
38026
  repairToolCall,
37599
38027
  experimental_context,
37600
- generateId: generateId2
38028
+ generateId: generateId2,
38029
+ stepNumber,
38030
+ model,
38031
+ onToolCallStart,
38032
+ onToolCallFinish
37601
38033
  }) {
37602
38034
  let toolResultsStreamController = null;
37603
38035
  const toolResultsStream = new ReadableStream({
@@ -37645,7 +38077,8 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37645
38077
  file: new DefaultGeneratedFileWithType({
37646
38078
  data: chunk.data,
37647
38079
  mediaType: chunk.mediaType
37648
- })
38080
+ }),
38081
+ ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
37649
38082
  });
37650
38083
  break;
37651
38084
  }
@@ -37739,6 +38172,10 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37739
38172
  messages,
37740
38173
  abortSignal,
37741
38174
  experimental_context,
38175
+ stepNumber,
38176
+ model,
38177
+ onToolCallStart,
38178
+ onToolCallFinish,
37742
38179
  onPreliminaryToolResult: (result) => {
37743
38180
  toolResultsStreamController.enqueue(result);
37744
38181
  }
@@ -37855,6 +38292,10 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37855
38292
  onFinish,
37856
38293
  onAbort,
37857
38294
  onStepFinish,
38295
+ experimental_onStart: onStart,
38296
+ experimental_onStepStart: onStepStart,
38297
+ experimental_onToolCallStart: onToolCallStart,
38298
+ experimental_onToolCallFinish: onToolCallFinish,
37858
38299
  experimental_context,
37859
38300
  experimental_include: include,
37860
38301
  _internal: { now: now2 = now, generateId: generateId2 = originalGenerateId2 } = {},
@@ -37894,11 +38335,18 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37894
38335
  providerOptions,
37895
38336
  prepareStep,
37896
38337
  includeRawChunks,
38338
+ timeout,
38339
+ stopWhen,
38340
+ originalAbortSignal: abortSignal,
37897
38341
  onChunk,
37898
38342
  onError,
37899
38343
  onFinish,
37900
38344
  onAbort,
37901
38345
  onStepFinish,
38346
+ onStart,
38347
+ onStepStart,
38348
+ onToolCallStart,
38349
+ onToolCallFinish,
37902
38350
  now: now2,
37903
38351
  generateId: generateId2,
37904
38352
  experimental_context,
@@ -37995,11 +38443,18 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
37995
38443
  includeRawChunks,
37996
38444
  now: now2,
37997
38445
  generateId: generateId2,
38446
+ timeout,
38447
+ stopWhen,
38448
+ originalAbortSignal,
37998
38449
  onChunk,
37999
38450
  onError,
38000
38451
  onFinish,
38001
38452
  onAbort,
38002
38453
  onStepFinish,
38454
+ onStart,
38455
+ onStepStart,
38456
+ onToolCallStart,
38457
+ onToolCallFinish,
38003
38458
  experimental_context,
38004
38459
  download: download2,
38005
38460
  include
@@ -38011,6 +38466,8 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38011
38466
  this.outputSpecification = output;
38012
38467
  this.includeRawChunks = includeRawChunks;
38013
38468
  this.tools = tools;
38469
+ const createGlobalTelemetry = getGlobalTelemetryIntegration();
38470
+ const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
38014
38471
  let stepFinish;
38015
38472
  let recordedContent = [];
38016
38473
  const recordedResponseMessages = [];
@@ -38112,7 +38569,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38112
38569
  delete activeReasoningContent[part.id];
38113
38570
  }
38114
38571
  if (part.type === "file") {
38115
- recordedContent.push({ type: "file", file: part.file });
38572
+ recordedContent.push({
38573
+ type: "file",
38574
+ file: part.file,
38575
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
38576
+ });
38116
38577
  }
38117
38578
  if (part.type === "source") {
38118
38579
  recordedContent.push(part);
@@ -38142,6 +38603,10 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38142
38603
  tools
38143
38604
  });
38144
38605
  const currentStepResult = new DefaultStepResult({
38606
+ stepNumber: recordedSteps.length,
38607
+ model: modelInfo,
38608
+ ...callbackTelemetryProps,
38609
+ experimental_context,
38145
38610
  content: recordedContent,
38146
38611
  finishReason: part.finishReason,
38147
38612
  rawFinishReason: part.rawFinishReason,
@@ -38154,11 +38619,14 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38154
38619
  },
38155
38620
  providerMetadata: part.providerMetadata
38156
38621
  });
38157
- await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
38622
+ await notify({
38623
+ event: currentStepResult,
38624
+ callbacks: [onStepFinish, globalTelemetry.onStepFinish]
38625
+ });
38158
38626
  logWarnings({
38159
38627
  warnings: recordedWarnings,
38160
- provider: model.provider,
38161
- model: model.modelId
38628
+ provider: modelInfo.provider,
38629
+ model: modelInfo.modelId
38162
38630
  });
38163
38631
  recordedSteps.push(currentStepResult);
38164
38632
  recordedResponseMessages.push(...stepMessages);
@@ -38189,30 +38657,40 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38189
38657
  self2._totalUsage.resolve(totalUsage);
38190
38658
  self2._steps.resolve(recordedSteps);
38191
38659
  const finalStep = recordedSteps[recordedSteps.length - 1];
38192
- await (onFinish == null ? void 0 : onFinish({
38193
- finishReason: finalStep.finishReason,
38194
- rawFinishReason: finalStep.rawFinishReason,
38195
- totalUsage,
38196
- usage: finalStep.usage,
38197
- content: finalStep.content,
38198
- text: finalStep.text,
38199
- reasoningText: finalStep.reasoningText,
38200
- reasoning: finalStep.reasoning,
38201
- files: finalStep.files,
38202
- sources: finalStep.sources,
38203
- toolCalls: finalStep.toolCalls,
38204
- staticToolCalls: finalStep.staticToolCalls,
38205
- dynamicToolCalls: finalStep.dynamicToolCalls,
38206
- toolResults: finalStep.toolResults,
38207
- staticToolResults: finalStep.staticToolResults,
38208
- dynamicToolResults: finalStep.dynamicToolResults,
38209
- request: finalStep.request,
38210
- response: finalStep.response,
38211
- warnings: finalStep.warnings,
38212
- providerMetadata: finalStep.providerMetadata,
38213
- steps: recordedSteps,
38214
- experimental_context
38215
- }));
38660
+ await notify({
38661
+ event: {
38662
+ stepNumber: finalStep.stepNumber,
38663
+ model: finalStep.model,
38664
+ functionId: finalStep.functionId,
38665
+ metadata: finalStep.metadata,
38666
+ experimental_context: finalStep.experimental_context,
38667
+ finishReason: finalStep.finishReason,
38668
+ rawFinishReason: finalStep.rawFinishReason,
38669
+ totalUsage,
38670
+ usage: finalStep.usage,
38671
+ content: finalStep.content,
38672
+ text: finalStep.text,
38673
+ reasoningText: finalStep.reasoningText,
38674
+ reasoning: finalStep.reasoning,
38675
+ files: finalStep.files,
38676
+ sources: finalStep.sources,
38677
+ toolCalls: finalStep.toolCalls,
38678
+ staticToolCalls: finalStep.staticToolCalls,
38679
+ dynamicToolCalls: finalStep.dynamicToolCalls,
38680
+ toolResults: finalStep.toolResults,
38681
+ staticToolResults: finalStep.staticToolResults,
38682
+ dynamicToolResults: finalStep.dynamicToolResults,
38683
+ request: finalStep.request,
38684
+ response: finalStep.response,
38685
+ warnings: finalStep.warnings,
38686
+ providerMetadata: finalStep.providerMetadata,
38687
+ steps: recordedSteps
38688
+ },
38689
+ callbacks: [
38690
+ onFinish,
38691
+ globalTelemetry.onFinish
38692
+ ]
38693
+ });
38216
38694
  rootSpan.setAttributes(
38217
38695
  await selectTelemetryAttributes({
38218
38696
  telemetry,
@@ -38313,6 +38791,11 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38313
38791
  settings: { ...callSettings, maxRetries }
38314
38792
  });
38315
38793
  const self2 = this;
38794
+ const modelInfo = { provider: model.provider, modelId: model.modelId };
38795
+ const callbackTelemetryProps = {
38796
+ functionId: telemetry == null ? void 0 : telemetry.functionId,
38797
+ metadata: telemetry == null ? void 0 : telemetry.metadata
38798
+ };
38316
38799
  recordSpan({
38317
38800
  name: "ai.streamText",
38318
38801
  attributes: selectTelemetryAttributes({
@@ -38335,6 +38818,39 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38335
38818
  prompt,
38336
38819
  messages
38337
38820
  });
38821
+ await notify({
38822
+ event: {
38823
+ model: modelInfo,
38824
+ system,
38825
+ prompt,
38826
+ messages,
38827
+ tools,
38828
+ toolChoice,
38829
+ activeTools,
38830
+ maxOutputTokens: callSettings.maxOutputTokens,
38831
+ temperature: callSettings.temperature,
38832
+ topP: callSettings.topP,
38833
+ topK: callSettings.topK,
38834
+ presencePenalty: callSettings.presencePenalty,
38835
+ frequencyPenalty: callSettings.frequencyPenalty,
38836
+ stopSequences: callSettings.stopSequences,
38837
+ seed: callSettings.seed,
38838
+ maxRetries,
38839
+ timeout,
38840
+ headers,
38841
+ providerOptions,
38842
+ stopWhen,
38843
+ output,
38844
+ abortSignal: originalAbortSignal,
38845
+ include,
38846
+ ...callbackTelemetryProps,
38847
+ experimental_context
38848
+ },
38849
+ callbacks: [
38850
+ onStart,
38851
+ globalTelemetry.onStart
38852
+ ]
38853
+ });
38338
38854
  const initialMessages = initialPrompt.messages;
38339
38855
  const initialResponseMessages = [];
38340
38856
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
@@ -38381,6 +38897,16 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38381
38897
  messages: initialMessages,
38382
38898
  abortSignal,
38383
38899
  experimental_context,
38900
+ stepNumber: recordedSteps.length,
38901
+ model: modelInfo,
38902
+ onToolCallStart: [
38903
+ onToolCallStart,
38904
+ globalTelemetry.onToolCallStart
38905
+ ],
38906
+ onToolCallFinish: [
38907
+ onToolCallFinish,
38908
+ globalTelemetry.onToolCallFinish
38909
+ ],
38384
38910
  onPreliminaryToolResult: (result2) => {
38385
38911
  toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue(result2);
38386
38912
  }
@@ -38417,7 +38943,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38417
38943
  input: output2.input,
38418
38944
  tool: tools == null ? void 0 : tools[output2.toolName],
38419
38945
  output: output2.type === "tool-result" ? output2.output : output2.error,
38420
- errorMode: output2.type === "tool-error" ? "json" : "none"
38946
+ errorMode: output2.type === "tool-error" ? "text" : "none"
38421
38947
  })
38422
38948
  });
38423
38949
  }
@@ -38447,7 +38973,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38447
38973
  responseMessages,
38448
38974
  usage
38449
38975
  }) {
38450
- var _a21, _b9, _c, _d, _e, _f, _g;
38976
+ var _a21, _b9, _c, _d, _e, _f, _g, _h, _i;
38451
38977
  const includeRawChunks2 = self2.includeRawChunks;
38452
38978
  const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : void 0;
38453
38979
  let chunkTimeoutId = void 0;
@@ -38486,6 +39012,10 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38486
39012
  const stepModel = resolveLanguageModel(
38487
39013
  (_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
38488
39014
  );
39015
+ const stepModelInfo = {
39016
+ provider: stepModel.provider,
39017
+ modelId: stepModel.modelId
39018
+ };
38489
39019
  const promptMessages = await convertToLanguageModelPrompt({
38490
39020
  prompt: {
38491
39021
  system: (_b9 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b9 : initialPrompt.system,
@@ -38494,16 +39024,44 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38494
39024
  supportedUrls: await stepModel.supportedUrls,
38495
39025
  download: download2
38496
39026
  });
39027
+ const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
38497
39028
  const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
38498
39029
  tools,
38499
- toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
38500
- activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
39030
+ toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
39031
+ activeTools: stepActiveTools
38501
39032
  });
38502
39033
  experimental_context = (_f = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _f : experimental_context;
39034
+ const stepMessages = (_g = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _g : stepInputMessages;
39035
+ const stepSystem = (_h = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _h : initialPrompt.system;
38503
39036
  const stepProviderOptions = mergeObjects(
38504
39037
  providerOptions,
38505
39038
  prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
38506
39039
  );
39040
+ await notify({
39041
+ event: {
39042
+ stepNumber: recordedSteps.length,
39043
+ model: stepModelInfo,
39044
+ system: stepSystem,
39045
+ messages: stepMessages,
39046
+ tools,
39047
+ toolChoice: stepToolChoice,
39048
+ activeTools: stepActiveTools,
39049
+ steps: [...recordedSteps],
39050
+ providerOptions: stepProviderOptions,
39051
+ timeout,
39052
+ headers,
39053
+ stopWhen,
39054
+ output,
39055
+ abortSignal: originalAbortSignal,
39056
+ include,
39057
+ ...callbackTelemetryProps,
39058
+ experimental_context
39059
+ },
39060
+ callbacks: [
39061
+ onStepStart,
39062
+ globalTelemetry.onStepStart
39063
+ ]
39064
+ });
38507
39065
  const {
38508
39066
  result: { stream: stream2, response, request },
38509
39067
  doStreamSpan,
@@ -38575,9 +39133,19 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38575
39133
  repairToolCall,
38576
39134
  abortSignal,
38577
39135
  experimental_context,
38578
- generateId: generateId2
39136
+ generateId: generateId2,
39137
+ stepNumber: recordedSteps.length,
39138
+ model: stepModelInfo,
39139
+ onToolCallStart: [
39140
+ onToolCallStart,
39141
+ globalTelemetry.onToolCallStart
39142
+ ],
39143
+ onToolCallFinish: [
39144
+ onToolCallFinish,
39145
+ globalTelemetry.onToolCallFinish
39146
+ ]
38579
39147
  });
38580
- const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? request != null ? request : {} : { ...request, body: void 0 };
39148
+ const stepRequest = ((_i = include == null ? void 0 : include.requestBody) != null ? _i : true) ? request != null ? request : {} : { ...request, body: void 0 };
38581
39149
  const stepToolCalls = [];
38582
39150
  const stepToolOutputs = [];
38583
39151
  let warnings;
@@ -38590,7 +39158,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
38590
39158
  let stepResponse = {
38591
39159
  id: generateId2(),
38592
39160
  timestamp: /* @__PURE__ */ new Date(),
38593
- modelId: model.modelId
39161
+ modelId: modelInfo.modelId
38594
39162
  };
38595
39163
  let activeText = "";
38596
39164
  self2.addStream(
@@ -39157,7 +39725,8 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
39157
39725
  controller.enqueue({
39158
39726
  type: "file",
39159
39727
  mediaType: part.file.mediaType,
39160
- url: `data:${part.file.mediaType};base64,${part.file.base64}`
39728
+ url: `data:${part.file.mediaType};base64,${part.file.base64}`,
39729
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
39161
39730
  });
39162
39731
  break;
39163
39732
  }
@@ -41479,7 +42048,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
41479
42048
  function getOpenAILanguageModelCapabilities(modelId) {
41480
42049
  const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
41481
42050
  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");
41482
- 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");
42051
+ const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
41483
42052
  const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
41484
42053
  const systemMessageMode = isReasoningModel ? "developer" : "system";
41485
42054
  return {
@@ -42414,7 +42983,7 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
42414
42983
  for (const toolCallDelta of delta.tool_calls) {
42415
42984
  const index = toolCallDelta.index;
42416
42985
  if (toolCalls[index] == null) {
42417
- if (toolCallDelta.type !== "function") {
42986
+ if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
42418
42987
  throw new InvalidResponseDataError$1({
42419
42988
  data: toolCallDelta,
42420
42989
  message: `Expected 'function' type.`
@@ -43104,9 +43673,11 @@ ${user}:`]
43104
43673
  "dall-e-2": 10,
43105
43674
  "gpt-image-1": 10,
43106
43675
  "gpt-image-1-mini": 10,
43107
- "gpt-image-1.5": 10
43676
+ "gpt-image-1.5": 10,
43677
+ "chatgpt-image-latest": 10
43108
43678
  };
43109
43679
  var defaultResponseFormatPrefixes = [
43680
+ "chatgpt-image-",
43110
43681
  "gpt-image-1-mini",
43111
43682
  "gpt-image-1.5",
43112
43683
  "gpt-image-1"
@@ -43205,15 +43776,20 @@ ${user}:`]
43205
43776
  },
43206
43777
  providerMetadata: {
43207
43778
  openai: {
43208
- images: response2.data.map((item) => {
43209
- var _a22, _b22, _c2, _d2, _e2;
43779
+ images: response2.data.map((item, index) => {
43780
+ var _a22, _b22, _c2, _d2, _e2, _f2;
43210
43781
  return {
43211
43782
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
43212
43783
  created: (_a22 = response2.created) != null ? _a22 : void 0,
43213
43784
  size: (_b22 = response2.size) != null ? _b22 : void 0,
43214
43785
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
43215
43786
  background: (_d2 = response2.background) != null ? _d2 : void 0,
43216
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
43787
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
43788
+ ...distributeTokenDetails(
43789
+ (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
43790
+ index,
43791
+ response2.data.length
43792
+ )
43217
43793
  };
43218
43794
  })
43219
43795
  }
@@ -43256,15 +43832,20 @@ ${user}:`]
43256
43832
  },
43257
43833
  providerMetadata: {
43258
43834
  openai: {
43259
- images: response.data.map((item) => {
43260
- var _a22, _b22, _c2, _d2, _e2;
43835
+ images: response.data.map((item, index) => {
43836
+ var _a22, _b22, _c2, _d2, _e2, _f2;
43261
43837
  return {
43262
43838
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
43263
43839
  created: (_a22 = response.created) != null ? _a22 : void 0,
43264
43840
  size: (_b22 = response.size) != null ? _b22 : void 0,
43265
43841
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
43266
43842
  background: (_d2 = response.background) != null ? _d2 : void 0,
43267
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0
43843
+ outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
43844
+ ...distributeTokenDetails(
43845
+ (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
43846
+ index,
43847
+ response.data.length
43848
+ )
43268
43849
  };
43269
43850
  })
43270
43851
  }
@@ -43272,6 +43853,23 @@ ${user}:`]
43272
43853
  };
43273
43854
  }
43274
43855
  };
43856
+ function distributeTokenDetails(details, index, total) {
43857
+ if (details == null) {
43858
+ return {};
43859
+ }
43860
+ const result = {};
43861
+ if (details.image_tokens != null) {
43862
+ const base = Math.floor(details.image_tokens / total);
43863
+ const remainder = details.image_tokens - base * (total - 1);
43864
+ result.imageTokens = index === total - 1 ? remainder : base;
43865
+ }
43866
+ if (details.text_tokens != null) {
43867
+ const base = Math.floor(details.text_tokens / total);
43868
+ const remainder = details.text_tokens - base * (total - 1);
43869
+ result.textTokens = index === total - 1 ? remainder : base;
43870
+ }
43871
+ return result;
43872
+ }
43275
43873
  async function fileToBlob(file) {
43276
43874
  if (!file) return void 0;
43277
43875
  if (file.type === "url") {
@@ -43357,6 +43955,30 @@ ${user}:`]
43357
43955
  var codeInterpreter = (args = {}) => {
43358
43956
  return codeInterpreterToolFactory(args);
43359
43957
  };
43958
+ var customArgsSchema = lazySchema(
43959
+ () => zodSchema(
43960
+ object$2({
43961
+ name: string(),
43962
+ description: string().optional(),
43963
+ format: union([
43964
+ object$2({
43965
+ type: literal("grammar"),
43966
+ syntax: _enum(["regex", "lark"]),
43967
+ definition: string()
43968
+ }),
43969
+ object$2({
43970
+ type: literal("text")
43971
+ })
43972
+ ]).optional()
43973
+ })
43974
+ )
43975
+ );
43976
+ var customInputSchema = lazySchema(() => zodSchema(string()));
43977
+ var customToolFactory = createProviderToolFactory({
43978
+ id: "openai.custom",
43979
+ inputSchema: customInputSchema
43980
+ });
43981
+ var customTool = (args) => customToolFactory(args);
43360
43982
  var comparisonFilterSchema = object$2({
43361
43983
  key: string(),
43362
43984
  type: _enum(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
@@ -43482,6 +44104,67 @@ ${user}:`]
43482
44104
  })
43483
44105
  )
43484
44106
  );
44107
+ var shellSkillsSchema = array$1(
44108
+ discriminatedUnion("type", [
44109
+ object$2({
44110
+ type: literal("skillReference"),
44111
+ skillId: string(),
44112
+ version: string().optional()
44113
+ }),
44114
+ object$2({
44115
+ type: literal("inline"),
44116
+ name: string(),
44117
+ description: string(),
44118
+ source: object$2({
44119
+ type: literal("base64"),
44120
+ mediaType: literal("application/zip"),
44121
+ data: string()
44122
+ })
44123
+ })
44124
+ ])
44125
+ ).optional();
44126
+ var shellArgsSchema = lazySchema(
44127
+ () => zodSchema(
44128
+ object$2({
44129
+ environment: union([
44130
+ object$2({
44131
+ type: literal("containerAuto"),
44132
+ fileIds: array$1(string()).optional(),
44133
+ memoryLimit: _enum(["1g", "4g", "16g", "64g"]).optional(),
44134
+ networkPolicy: discriminatedUnion("type", [
44135
+ object$2({ type: literal("disabled") }),
44136
+ object$2({
44137
+ type: literal("allowlist"),
44138
+ allowedDomains: array$1(string()),
44139
+ domainSecrets: array$1(
44140
+ object$2({
44141
+ domain: string(),
44142
+ name: string(),
44143
+ value: string()
44144
+ })
44145
+ ).optional()
44146
+ })
44147
+ ]).optional(),
44148
+ skills: shellSkillsSchema
44149
+ }),
44150
+ object$2({
44151
+ type: literal("containerReference"),
44152
+ containerId: string()
44153
+ }),
44154
+ object$2({
44155
+ type: literal("local").optional(),
44156
+ skills: array$1(
44157
+ object$2({
44158
+ name: string(),
44159
+ description: string(),
44160
+ path: string()
44161
+ })
44162
+ ).optional()
44163
+ })
44164
+ ]).optional()
44165
+ })
44166
+ )
44167
+ );
43485
44168
  var shell = createProviderToolFactoryWithOutputSchema({
43486
44169
  id: "openai.shell",
43487
44170
  inputSchema: shellInputSchema,
@@ -43521,7 +44204,7 @@ ${user}:`]
43521
44204
  url: string().nullish(),
43522
44205
  pattern: string().nullish()
43523
44206
  })
43524
- ]),
44207
+ ]).optional(),
43525
44208
  sources: array$1(
43526
44209
  discriminatedUnion("type", [
43527
44210
  object$2({ type: literal("url"), url: string() }),
@@ -43571,7 +44254,7 @@ ${user}:`]
43571
44254
  url: string().nullish(),
43572
44255
  pattern: string().nullish()
43573
44256
  })
43574
- ])
44257
+ ]).optional()
43575
44258
  })
43576
44259
  )
43577
44260
  );
@@ -43648,6 +44331,16 @@ ${user}:`]
43648
44331
  *
43649
44332
  */
43650
44333
  applyPatch,
44334
+ /**
44335
+ * Custom tools let callers constrain model output to a grammar (regex or
44336
+ * Lark syntax). The model returns a `custom_tool_call` output item whose
44337
+ * `input` field is a string matching the specified grammar.
44338
+ *
44339
+ * @param name - The name of the custom tool.
44340
+ * @param description - An optional description of the tool.
44341
+ * @param format - The output format constraint (grammar type, syntax, and definition).
44342
+ */
44343
+ customTool,
43651
44344
  /**
43652
44345
  * The Code Interpreter tool allows models to write and run Python code in a
43653
44346
  * sandboxed environment to solve complex problems in domains like data analysis,
@@ -43688,7 +44381,7 @@ ${user}:`]
43688
44381
  * Local shell is a tool that allows agents to run shell commands locally
43689
44382
  * on a machine you or the user provides.
43690
44383
  *
43691
- * Supported models: `gpt-5-codex` and `codex-mini-latest`
44384
+ * Supported models: `gpt-5-codex`
43692
44385
  */
43693
44386
  localShell,
43694
44387
  /**
@@ -43786,7 +44479,8 @@ ${user}:`]
43786
44479
  hasConversation = false,
43787
44480
  hasLocalShellTool = false,
43788
44481
  hasShellTool = false,
43789
- hasApplyPatchTool = false
44482
+ hasApplyPatchTool = false,
44483
+ customProviderToolNames
43790
44484
  }) {
43791
44485
  var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
43792
44486
  const input = [];
@@ -43869,7 +44563,9 @@ ${user}:`]
43869
44563
  for (const part of content) {
43870
44564
  switch (part.type) {
43871
44565
  case "text": {
43872
- const id2 = (_b9 = (_a10 = part.providerOptions) == null ? void 0 : _a10[providerOptionsName]) == null ? void 0 : _b9.itemId;
44566
+ const providerOpts = (_a10 = part.providerOptions) == null ? void 0 : _a10[providerOptionsName];
44567
+ const id2 = providerOpts == null ? void 0 : providerOpts.itemId;
44568
+ const phase = providerOpts == null ? void 0 : providerOpts.phase;
43873
44569
  if (hasConversation && id2 != null) {
43874
44570
  break;
43875
44571
  }
@@ -43880,12 +44576,13 @@ ${user}:`]
43880
44576
  input.push({
43881
44577
  role: "assistant",
43882
44578
  content: [{ type: "output_text", text: part.text }],
43883
- id: id2
44579
+ id: id2,
44580
+ ...phase != null && { phase }
43884
44581
  });
43885
44582
  break;
43886
44583
  }
43887
44584
  case "tool-call": {
43888
- 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;
44585
+ 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;
43889
44586
  if (hasConversation && id2 != null) {
43890
44587
  break;
43891
44588
  }
@@ -43954,6 +44651,16 @@ ${user}:`]
43954
44651
  });
43955
44652
  break;
43956
44653
  }
44654
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
44655
+ input.push({
44656
+ type: "custom_tool_call",
44657
+ call_id: part.toolCallId,
44658
+ name: resolvedToolName,
44659
+ input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
44660
+ id: id2
44661
+ });
44662
+ break;
44663
+ }
43957
44664
  input.push({
43958
44665
  type: "function_call",
43959
44666
  call_id: part.toolCallId,
@@ -43971,8 +44678,32 @@ ${user}:`]
43971
44678
  if (hasConversation) {
43972
44679
  break;
43973
44680
  }
44681
+ const resolvedResultToolName = toolNameMapping.toProviderToolName(
44682
+ part.toolName
44683
+ );
44684
+ if (hasShellTool && resolvedResultToolName === "shell") {
44685
+ if (part.output.type === "json") {
44686
+ const parsedOutput = await validateTypes$1({
44687
+ value: part.output.value,
44688
+ schema: shellOutputSchema
44689
+ });
44690
+ input.push({
44691
+ type: "shell_call_output",
44692
+ call_id: part.toolCallId,
44693
+ output: parsedOutput.output.map((item) => ({
44694
+ stdout: item.stdout,
44695
+ stderr: item.stderr,
44696
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
44697
+ type: "exit",
44698
+ exit_code: item.outcome.exitCode
44699
+ }
44700
+ }))
44701
+ });
44702
+ }
44703
+ break;
44704
+ }
43974
44705
  if (store) {
43975
- const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
44706
+ const itemId = (_i = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.itemId) != null ? _i : part.toolCallId;
43976
44707
  input.push({ type: "item_reference", id: itemId });
43977
44708
  } else {
43978
44709
  warnings.push({
@@ -44032,10 +44763,26 @@ ${user}:`]
44032
44763
  }
44033
44764
  }
44034
44765
  } else {
44035
- warnings.push({
44036
- type: "other",
44037
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
44038
- });
44766
+ const encryptedContent = providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent;
44767
+ if (encryptedContent != null) {
44768
+ const summaryParts = [];
44769
+ if (part.text.length > 0) {
44770
+ summaryParts.push({
44771
+ type: "summary_text",
44772
+ text: part.text
44773
+ });
44774
+ }
44775
+ input.push({
44776
+ type: "reasoning",
44777
+ encrypted_content: encryptedContent,
44778
+ summary: summaryParts
44779
+ });
44780
+ } else {
44781
+ warnings.push({
44782
+ type: "other",
44783
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
44784
+ });
44785
+ }
44039
44786
  }
44040
44787
  break;
44041
44788
  }
@@ -44066,7 +44813,7 @@ ${user}:`]
44066
44813
  }
44067
44814
  const output = part.output;
44068
44815
  if (output.type === "execution-denied") {
44069
- const approvalId = (_l = (_k = output.providerOptions) == null ? void 0 : _k.openai) == null ? void 0 : _l.approvalId;
44816
+ const approvalId = (_k = (_j = output.providerOptions) == null ? void 0 : _j.openai) == null ? void 0 : _k.approvalId;
44070
44817
  if (approvalId) {
44071
44818
  continue;
44072
44819
  }
@@ -44118,6 +44865,61 @@ ${user}:`]
44118
44865
  });
44119
44866
  continue;
44120
44867
  }
44868
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
44869
+ let outputValue;
44870
+ switch (output.type) {
44871
+ case "text":
44872
+ case "error-text":
44873
+ outputValue = output.value;
44874
+ break;
44875
+ case "execution-denied":
44876
+ outputValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
44877
+ break;
44878
+ case "json":
44879
+ case "error-json":
44880
+ outputValue = JSON.stringify(output.value);
44881
+ break;
44882
+ case "content":
44883
+ outputValue = output.value.map((item) => {
44884
+ var _a22;
44885
+ switch (item.type) {
44886
+ case "text":
44887
+ return { type: "input_text", text: item.text };
44888
+ case "image-data":
44889
+ return {
44890
+ type: "input_image",
44891
+ image_url: `data:${item.mediaType};base64,${item.data}`
44892
+ };
44893
+ case "image-url":
44894
+ return {
44895
+ type: "input_image",
44896
+ image_url: item.url
44897
+ };
44898
+ case "file-data":
44899
+ return {
44900
+ type: "input_file",
44901
+ filename: (_a22 = item.filename) != null ? _a22 : "data",
44902
+ file_data: `data:${item.mediaType};base64,${item.data}`
44903
+ };
44904
+ default:
44905
+ warnings.push({
44906
+ type: "other",
44907
+ message: `unsupported custom tool content part type: ${item.type}`
44908
+ });
44909
+ return void 0;
44910
+ }
44911
+ }).filter(isNonNullable);
44912
+ break;
44913
+ default:
44914
+ outputValue = "";
44915
+ }
44916
+ input.push({
44917
+ type: "custom_tool_call_output",
44918
+ call_id: part.toolCallId,
44919
+ output: outputValue
44920
+ });
44921
+ continue;
44922
+ }
44121
44923
  let contentValue;
44122
44924
  switch (output.type) {
44123
44925
  case "text":
@@ -44252,7 +45054,8 @@ ${user}:`]
44252
45054
  item: discriminatedUnion("type", [
44253
45055
  object$2({
44254
45056
  type: literal("message"),
44255
- id: string()
45057
+ id: string(),
45058
+ phase: _enum(["commentary", "final_answer"]).nullish()
44256
45059
  }),
44257
45060
  object$2({
44258
45061
  type: literal("reasoning"),
@@ -44333,6 +45136,13 @@ ${user}:`]
44333
45136
  })
44334
45137
  ])
44335
45138
  }),
45139
+ object$2({
45140
+ type: literal("custom_tool_call"),
45141
+ id: string(),
45142
+ call_id: string(),
45143
+ name: string(),
45144
+ input: string()
45145
+ }),
44336
45146
  object$2({
44337
45147
  type: literal("shell_call"),
44338
45148
  id: string(),
@@ -44341,6 +45151,25 @@ ${user}:`]
44341
45151
  action: object$2({
44342
45152
  commands: array$1(string())
44343
45153
  })
45154
+ }),
45155
+ object$2({
45156
+ type: literal("shell_call_output"),
45157
+ id: string(),
45158
+ call_id: string(),
45159
+ status: _enum(["in_progress", "completed", "incomplete"]),
45160
+ output: array$1(
45161
+ object$2({
45162
+ stdout: string(),
45163
+ stderr: string(),
45164
+ outcome: discriminatedUnion("type", [
45165
+ object$2({ type: literal("timeout") }),
45166
+ object$2({
45167
+ type: literal("exit"),
45168
+ exit_code: number$1()
45169
+ })
45170
+ ])
45171
+ })
45172
+ )
44344
45173
  })
44345
45174
  ])
44346
45175
  }),
@@ -44350,7 +45179,8 @@ ${user}:`]
44350
45179
  item: discriminatedUnion("type", [
44351
45180
  object$2({
44352
45181
  type: literal("message"),
44353
- id: string()
45182
+ id: string(),
45183
+ phase: _enum(["commentary", "final_answer"]).nullish()
44354
45184
  }),
44355
45185
  object$2({
44356
45186
  type: literal("reasoning"),
@@ -44365,6 +45195,14 @@ ${user}:`]
44365
45195
  arguments: string(),
44366
45196
  status: literal("completed")
44367
45197
  }),
45198
+ object$2({
45199
+ type: literal("custom_tool_call"),
45200
+ id: string(),
45201
+ call_id: string(),
45202
+ name: string(),
45203
+ input: string(),
45204
+ status: literal("completed")
45205
+ }),
44368
45206
  object$2({
44369
45207
  type: literal("code_interpreter_call"),
44370
45208
  id: string(),
@@ -44406,7 +45244,7 @@ ${user}:`]
44406
45244
  url: string().nullish(),
44407
45245
  pattern: string().nullish()
44408
45246
  })
44409
- ])
45247
+ ]).nullish()
44410
45248
  }),
44411
45249
  object$2({
44412
45250
  type: literal("file_search_call"),
@@ -44520,6 +45358,25 @@ ${user}:`]
44520
45358
  action: object$2({
44521
45359
  commands: array$1(string())
44522
45360
  })
45361
+ }),
45362
+ object$2({
45363
+ type: literal("shell_call_output"),
45364
+ id: string(),
45365
+ call_id: string(),
45366
+ status: _enum(["in_progress", "completed", "incomplete"]),
45367
+ output: array$1(
45368
+ object$2({
45369
+ stdout: string(),
45370
+ stderr: string(),
45371
+ outcome: discriminatedUnion("type", [
45372
+ object$2({ type: literal("timeout") }),
45373
+ object$2({
45374
+ type: literal("exit"),
45375
+ exit_code: number$1()
45376
+ })
45377
+ ])
45378
+ })
45379
+ )
44523
45380
  })
44524
45381
  ])
44525
45382
  }),
@@ -44529,6 +45386,12 @@ ${user}:`]
44529
45386
  output_index: number$1(),
44530
45387
  delta: string()
44531
45388
  }),
45389
+ object$2({
45390
+ type: literal("response.custom_tool_call_input.delta"),
45391
+ item_id: string(),
45392
+ output_index: number$1(),
45393
+ delta: string()
45394
+ }),
44532
45395
  object$2({
44533
45396
  type: literal("response.image_generation_call.partial_image"),
44534
45397
  item_id: string(),
@@ -44643,6 +45506,7 @@ ${user}:`]
44643
45506
  type: literal("message"),
44644
45507
  role: literal("assistant"),
44645
45508
  id: string(),
45509
+ phase: _enum(["commentary", "final_answer"]).nullish(),
44646
45510
  content: array$1(
44647
45511
  object$2({
44648
45512
  type: literal("output_text"),
@@ -44703,7 +45567,10 @@ ${user}:`]
44703
45567
  sources: array$1(
44704
45568
  discriminatedUnion("type", [
44705
45569
  object$2({ type: literal("url"), url: string() }),
44706
- object$2({ type: literal("api"), name: string() })
45570
+ object$2({
45571
+ type: literal("api"),
45572
+ name: string()
45573
+ })
44707
45574
  ])
44708
45575
  ).nullish()
44709
45576
  }),
@@ -44716,7 +45583,7 @@ ${user}:`]
44716
45583
  url: string().nullish(),
44717
45584
  pattern: string().nullish()
44718
45585
  })
44719
- ])
45586
+ ]).nullish()
44720
45587
  }),
44721
45588
  object$2({
44722
45589
  type: literal("file_search_call"),
@@ -44772,6 +45639,13 @@ ${user}:`]
44772
45639
  arguments: string(),
44773
45640
  id: string()
44774
45641
  }),
45642
+ object$2({
45643
+ type: literal("custom_tool_call"),
45644
+ call_id: string(),
45645
+ name: string(),
45646
+ input: string(),
45647
+ id: string()
45648
+ }),
44775
45649
  object$2({
44776
45650
  type: literal("computer_call"),
44777
45651
  id: string(),
@@ -44865,6 +45739,25 @@ ${user}:`]
44865
45739
  action: object$2({
44866
45740
  commands: array$1(string())
44867
45741
  })
45742
+ }),
45743
+ object$2({
45744
+ type: literal("shell_call_output"),
45745
+ id: string(),
45746
+ call_id: string(),
45747
+ status: _enum(["in_progress", "completed", "incomplete"]),
45748
+ output: array$1(
45749
+ object$2({
45750
+ stdout: string(),
45751
+ stderr: string(),
45752
+ outcome: discriminatedUnion("type", [
45753
+ object$2({ type: literal("timeout") }),
45754
+ object$2({
45755
+ type: literal("exit"),
45756
+ exit_code: number$1()
45757
+ })
45758
+ ])
45759
+ })
45760
+ )
44868
45761
  })
44869
45762
  ])
44870
45763
  ).optional(),
@@ -45036,14 +45929,18 @@ ${user}:`]
45036
45929
  );
45037
45930
  async function prepareResponsesTools({
45038
45931
  tools,
45039
- toolChoice
45932
+ toolChoice,
45933
+ toolNameMapping,
45934
+ customProviderToolNames
45040
45935
  }) {
45936
+ var _a10;
45041
45937
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
45042
45938
  const toolWarnings = [];
45043
45939
  if (tools == null) {
45044
45940
  return { tools: void 0, toolChoice: void 0, toolWarnings };
45045
45941
  }
45046
45942
  const openaiTools2 = [];
45943
+ const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
45047
45944
  for (const tool2 of tools) {
45048
45945
  switch (tool2.type) {
45049
45946
  case "function":
@@ -45081,8 +45978,15 @@ ${user}:`]
45081
45978
  break;
45082
45979
  }
45083
45980
  case "openai.shell": {
45981
+ const args = await validateTypes$1({
45982
+ value: tool2.args,
45983
+ schema: shellArgsSchema
45984
+ });
45084
45985
  openaiTools2.push({
45085
- type: "shell"
45986
+ type: "shell",
45987
+ ...args.environment && {
45988
+ environment: mapShellEnvironment(args.environment)
45989
+ }
45086
45990
  });
45087
45991
  break;
45088
45992
  }
@@ -45178,6 +46082,20 @@ ${user}:`]
45178
46082
  });
45179
46083
  break;
45180
46084
  }
46085
+ case "openai.custom": {
46086
+ const args = await validateTypes$1({
46087
+ value: tool2.args,
46088
+ schema: customArgsSchema
46089
+ });
46090
+ openaiTools2.push({
46091
+ type: "custom",
46092
+ name: args.name,
46093
+ description: args.description,
46094
+ format: args.format
46095
+ });
46096
+ resolvedCustomProviderToolNames.add(args.name);
46097
+ break;
46098
+ }
45181
46099
  }
45182
46100
  break;
45183
46101
  }
@@ -45198,12 +46116,14 @@ ${user}:`]
45198
46116
  case "none":
45199
46117
  case "required":
45200
46118
  return { tools: openaiTools2, toolChoice: type2, toolWarnings };
45201
- case "tool":
46119
+ case "tool": {
46120
+ const resolvedToolName = (_a10 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a10 : toolChoice.toolName;
45202
46121
  return {
45203
46122
  tools: openaiTools2,
45204
- 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 },
46123
+ 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 },
45205
46124
  toolWarnings
45206
46125
  };
46126
+ }
45207
46127
  default: {
45208
46128
  const _exhaustiveCheck = type2;
45209
46129
  throw new UnsupportedFunctionalityError$1({
@@ -45212,6 +46132,52 @@ ${user}:`]
45212
46132
  }
45213
46133
  }
45214
46134
  }
46135
+ function mapShellEnvironment(environment) {
46136
+ if (environment.type === "containerReference") {
46137
+ const env2 = environment;
46138
+ return {
46139
+ type: "container_reference",
46140
+ container_id: env2.containerId
46141
+ };
46142
+ }
46143
+ if (environment.type === "containerAuto") {
46144
+ const env2 = environment;
46145
+ return {
46146
+ type: "container_auto",
46147
+ file_ids: env2.fileIds,
46148
+ memory_limit: env2.memoryLimit,
46149
+ network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
46150
+ type: "allowlist",
46151
+ allowed_domains: env2.networkPolicy.allowedDomains,
46152
+ domain_secrets: env2.networkPolicy.domainSecrets
46153
+ },
46154
+ skills: mapShellSkills(env2.skills)
46155
+ };
46156
+ }
46157
+ const env = environment;
46158
+ return {
46159
+ type: "local",
46160
+ skills: env.skills
46161
+ };
46162
+ }
46163
+ function mapShellSkills(skills) {
46164
+ return skills == null ? void 0 : skills.map(
46165
+ (skill) => skill.type === "skillReference" ? {
46166
+ type: "skill_reference",
46167
+ skill_id: skill.skillId,
46168
+ version: skill.version
46169
+ } : {
46170
+ type: "inline",
46171
+ name: skill.name,
46172
+ description: skill.description,
46173
+ source: {
46174
+ type: "base64",
46175
+ media_type: skill.source.mediaType,
46176
+ data: skill.source.data
46177
+ }
46178
+ }
46179
+ );
46180
+ }
45215
46181
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
45216
46182
  var _a10, _b9;
45217
46183
  const mapping = {};
@@ -45255,7 +46221,7 @@ ${user}:`]
45255
46221
  toolChoice,
45256
46222
  responseFormat
45257
46223
  }) {
45258
- var _a10, _b9, _c, _d, _e, _f;
46224
+ var _a10, _b9, _c, _d, _e, _f, _g, _h, _i;
45259
46225
  const warnings = [];
45260
46226
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
45261
46227
  if (topK != null) {
@@ -45306,7 +46272,19 @@ ${user}:`]
45306
46272
  "openai.web_search_preview": "web_search_preview",
45307
46273
  "openai.mcp": "mcp",
45308
46274
  "openai.apply_patch": "apply_patch"
45309
- }
46275
+ },
46276
+ resolveProviderToolName: (tool2) => tool2.id === "openai.custom" ? tool2.args.name : void 0
46277
+ });
46278
+ const customProviderToolNames = /* @__PURE__ */ new Set();
46279
+ const {
46280
+ tools: openaiTools2,
46281
+ toolChoice: openaiToolChoice,
46282
+ toolWarnings
46283
+ } = await prepareResponsesTools({
46284
+ tools,
46285
+ toolChoice,
46286
+ toolNameMapping,
46287
+ customProviderToolNames
45310
46288
  });
45311
46289
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
45312
46290
  prompt,
@@ -45318,7 +46296,8 @@ ${user}:`]
45318
46296
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
45319
46297
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
45320
46298
  hasShellTool: hasOpenAITool("openai.shell"),
45321
- hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
46299
+ hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
46300
+ customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
45322
46301
  });
45323
46302
  warnings.push(...inputWarnings);
45324
46303
  const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
@@ -45451,14 +46430,10 @@ ${user}:`]
45451
46430
  });
45452
46431
  delete baseArgs.service_tier;
45453
46432
  }
45454
- const {
45455
- tools: openaiTools2,
45456
- toolChoice: openaiToolChoice,
45457
- toolWarnings
45458
- } = await prepareResponsesTools({
45459
- tools,
45460
- toolChoice
45461
- });
46433
+ const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
46434
+ (tool2) => tool2.type === "provider" && tool2.id === "openai.shell"
46435
+ )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
46436
+ const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
45462
46437
  return {
45463
46438
  webSearchToolName,
45464
46439
  args: {
@@ -45469,7 +46444,8 @@ ${user}:`]
45469
46444
  warnings: [...warnings, ...toolWarnings],
45470
46445
  store,
45471
46446
  toolNameMapping,
45472
- providerOptionsName
46447
+ providerOptionsName,
46448
+ isShellProviderExecuted
45473
46449
  };
45474
46450
  }
45475
46451
  async doGenerate(options) {
@@ -45479,7 +46455,8 @@ ${user}:`]
45479
46455
  warnings,
45480
46456
  webSearchToolName,
45481
46457
  toolNameMapping,
45482
- providerOptionsName
46458
+ providerOptionsName,
46459
+ isShellProviderExecuted
45483
46460
  } = await this.getArgs(options);
45484
46461
  const url2 = this.config.url({
45485
46462
  path: "/responses",
@@ -45579,6 +46556,7 @@ ${user}:`]
45579
46556
  commands: part.action.commands
45580
46557
  }
45581
46558
  }),
46559
+ ...isShellProviderExecuted && { providerExecuted: true },
45582
46560
  providerMetadata: {
45583
46561
  [providerOptionsName]: {
45584
46562
  itemId: part.id
@@ -45587,6 +46565,24 @@ ${user}:`]
45587
46565
  });
45588
46566
  break;
45589
46567
  }
46568
+ case "shell_call_output": {
46569
+ content.push({
46570
+ type: "tool-result",
46571
+ toolCallId: part.call_id,
46572
+ toolName: toolNameMapping.toCustomToolName("shell"),
46573
+ result: {
46574
+ output: part.output.map((item) => ({
46575
+ stdout: item.stdout,
46576
+ stderr: item.stderr,
46577
+ outcome: item.outcome.type === "exit" ? {
46578
+ type: "exit",
46579
+ exitCode: item.outcome.exit_code
46580
+ } : { type: "timeout" }
46581
+ }))
46582
+ }
46583
+ });
46584
+ break;
46585
+ }
45590
46586
  case "message": {
45591
46587
  for (const contentPart of part.content) {
45592
46588
  if (((_c = (_b9 = options.providerOptions) == null ? void 0 : _b9[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
@@ -45594,6 +46590,7 @@ ${user}:`]
45594
46590
  }
45595
46591
  const providerMetadata2 = {
45596
46592
  itemId: part.id,
46593
+ ...part.phase != null && { phase: part.phase },
45597
46594
  ...contentPart.annotations.length > 0 && {
45598
46595
  annotations: contentPart.annotations
45599
46596
  }
@@ -45682,6 +46679,22 @@ ${user}:`]
45682
46679
  });
45683
46680
  break;
45684
46681
  }
46682
+ case "custom_tool_call": {
46683
+ hasFunctionCall = true;
46684
+ const toolName = toolNameMapping.toCustomToolName(part.name);
46685
+ content.push({
46686
+ type: "tool-call",
46687
+ toolCallId: part.call_id,
46688
+ toolName,
46689
+ input: JSON.stringify(part.input),
46690
+ providerMetadata: {
46691
+ [providerOptionsName]: {
46692
+ itemId: part.id
46693
+ }
46694
+ }
46695
+ });
46696
+ break;
46697
+ }
45685
46698
  case "web_search_call": {
45686
46699
  content.push({
45687
46700
  type: "tool-call",
@@ -45876,7 +46889,8 @@ ${user}:`]
45876
46889
  webSearchToolName,
45877
46890
  toolNameMapping,
45878
46891
  store,
45879
- providerOptionsName
46892
+ providerOptionsName,
46893
+ isShellProviderExecuted
45880
46894
  } = await this.getArgs(options);
45881
46895
  const { responseHeaders, value: response } = await postJsonToApi$1({
45882
46896
  url: this.config.url({
@@ -45907,6 +46921,7 @@ ${user}:`]
45907
46921
  let responseId = null;
45908
46922
  const ongoingToolCalls = {};
45909
46923
  const ongoingAnnotations = [];
46924
+ let activeMessagePhase;
45910
46925
  let hasFunctionCall = false;
45911
46926
  const activeReasoning = {};
45912
46927
  let serviceTier;
@@ -45917,7 +46932,7 @@ ${user}:`]
45917
46932
  controller.enqueue({ type: "stream-start", warnings });
45918
46933
  },
45919
46934
  transform(chunk, controller) {
45920
- 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;
46935
+ 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;
45921
46936
  if (options.includeRawChunks) {
45922
46937
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
45923
46938
  }
@@ -45938,6 +46953,19 @@ ${user}:`]
45938
46953
  id: value.item.call_id,
45939
46954
  toolName: value.item.name
45940
46955
  });
46956
+ } else if (value.item.type === "custom_tool_call") {
46957
+ const toolName = toolNameMapping.toCustomToolName(
46958
+ value.item.name
46959
+ );
46960
+ ongoingToolCalls[value.output_index] = {
46961
+ toolName,
46962
+ toolCallId: value.item.call_id
46963
+ };
46964
+ controller.enqueue({
46965
+ type: "tool-input-start",
46966
+ id: value.item.call_id,
46967
+ toolName
46968
+ });
45941
46969
  } else if (value.item.type === "web_search_call") {
45942
46970
  ongoingToolCalls[value.output_index] = {
45943
46971
  toolName: toolNameMapping.toCustomToolName(
@@ -46055,14 +47083,19 @@ ${user}:`]
46055
47083
  toolName: toolNameMapping.toCustomToolName("shell"),
46056
47084
  toolCallId: value.item.call_id
46057
47085
  };
46058
- } else if (value.item.type === "message") {
47086
+ } else if (value.item.type === "shell_call_output") ;
47087
+ else if (value.item.type === "message") {
46059
47088
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
47089
+ activeMessagePhase = (_a10 = value.item.phase) != null ? _a10 : void 0;
46060
47090
  controller.enqueue({
46061
47091
  type: "text-start",
46062
47092
  id: value.item.id,
46063
47093
  providerMetadata: {
46064
47094
  [providerOptionsName]: {
46065
- itemId: value.item.id
47095
+ itemId: value.item.id,
47096
+ ...value.item.phase != null && {
47097
+ phase: value.item.phase
47098
+ }
46066
47099
  }
46067
47100
  }
46068
47101
  });
@@ -46077,19 +47110,22 @@ ${user}:`]
46077
47110
  providerMetadata: {
46078
47111
  [providerOptionsName]: {
46079
47112
  itemId: value.item.id,
46080
- reasoningEncryptedContent: (_a10 = value.item.encrypted_content) != null ? _a10 : null
47113
+ reasoningEncryptedContent: (_b9 = value.item.encrypted_content) != null ? _b9 : null
46081
47114
  }
46082
47115
  }
46083
47116
  });
46084
47117
  }
46085
47118
  } else if (isResponseOutputItemDoneChunk(value)) {
46086
47119
  if (value.item.type === "message") {
47120
+ const phase = (_c = value.item.phase) != null ? _c : activeMessagePhase;
47121
+ activeMessagePhase = void 0;
46087
47122
  controller.enqueue({
46088
47123
  type: "text-end",
46089
47124
  id: value.item.id,
46090
47125
  providerMetadata: {
46091
47126
  [providerOptionsName]: {
46092
47127
  itemId: value.item.id,
47128
+ ...phase != null && { phase },
46093
47129
  ...ongoingAnnotations.length > 0 && {
46094
47130
  annotations: ongoingAnnotations
46095
47131
  }
@@ -46114,6 +47150,27 @@ ${user}:`]
46114
47150
  }
46115
47151
  }
46116
47152
  });
47153
+ } else if (value.item.type === "custom_tool_call") {
47154
+ ongoingToolCalls[value.output_index] = void 0;
47155
+ hasFunctionCall = true;
47156
+ const toolName = toolNameMapping.toCustomToolName(
47157
+ value.item.name
47158
+ );
47159
+ controller.enqueue({
47160
+ type: "tool-input-end",
47161
+ id: value.item.call_id
47162
+ });
47163
+ controller.enqueue({
47164
+ type: "tool-call",
47165
+ toolCallId: value.item.call_id,
47166
+ toolName,
47167
+ input: JSON.stringify(value.item.input),
47168
+ providerMetadata: {
47169
+ [providerOptionsName]: {
47170
+ itemId: value.item.id
47171
+ }
47172
+ }
47173
+ });
46117
47174
  } else if (value.item.type === "web_search_call") {
46118
47175
  ongoingToolCalls[value.output_index] = void 0;
46119
47176
  controller.enqueue({
@@ -46154,13 +47211,13 @@ ${user}:`]
46154
47211
  toolName: toolNameMapping.toCustomToolName("file_search"),
46155
47212
  result: {
46156
47213
  queries: value.item.queries,
46157
- results: (_c = (_b9 = value.item.results) == null ? void 0 : _b9.map((result) => ({
47214
+ results: (_e = (_d = value.item.results) == null ? void 0 : _d.map((result) => ({
46158
47215
  attributes: result.attributes,
46159
47216
  fileId: result.file_id,
46160
47217
  filename: result.filename,
46161
47218
  score: result.score,
46162
47219
  text: result.text
46163
- }))) != null ? _c : null
47220
+ }))) != null ? _e : null
46164
47221
  }
46165
47222
  });
46166
47223
  } else if (value.item.type === "code_interpreter_call") {
@@ -46184,10 +47241,10 @@ ${user}:`]
46184
47241
  });
46185
47242
  } else if (value.item.type === "mcp_call") {
46186
47243
  ongoingToolCalls[value.output_index] = void 0;
46187
- const approvalRequestId = (_d = value.item.approval_request_id) != null ? _d : void 0;
46188
- const aliasedToolCallId = approvalRequestId != null ? (_f = (_e = approvalRequestIdToDummyToolCallIdFromStream.get(
47244
+ const approvalRequestId = (_f = value.item.approval_request_id) != null ? _f : void 0;
47245
+ const aliasedToolCallId = approvalRequestId != null ? (_h = (_g = approvalRequestIdToDummyToolCallIdFromStream.get(
46189
47246
  approvalRequestId
46190
- )) != null ? _e : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _f : value.item.id : value.item.id;
47247
+ )) != null ? _g : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _h : value.item.id : value.item.id;
46191
47248
  const toolName = `mcp.${value.item.name}`;
46192
47249
  controller.enqueue({
46193
47250
  type: "tool-call",
@@ -46257,8 +47314,8 @@ ${user}:`]
46257
47314
  ongoingToolCalls[value.output_index] = void 0;
46258
47315
  } else if (value.item.type === "mcp_approval_request") {
46259
47316
  ongoingToolCalls[value.output_index] = void 0;
46260
- const dummyToolCallId = (_i = (_h = (_g = self2.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId$1();
46261
- const approvalRequestId = (_j = value.item.approval_request_id) != null ? _j : value.item.id;
47317
+ const dummyToolCallId = (_k = (_j = (_i = self2.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId$1();
47318
+ const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : value.item.id;
46262
47319
  approvalRequestIdToDummyToolCallIdFromStream.set(
46263
47320
  approvalRequestId,
46264
47321
  dummyToolCallId
@@ -46308,10 +47365,31 @@ ${user}:`]
46308
47365
  commands: value.item.action.commands
46309
47366
  }
46310
47367
  }),
47368
+ ...isShellProviderExecuted && {
47369
+ providerExecuted: true
47370
+ },
46311
47371
  providerMetadata: {
46312
47372
  [providerOptionsName]: { itemId: value.item.id }
46313
47373
  }
46314
47374
  });
47375
+ } else if (value.item.type === "shell_call_output") {
47376
+ controller.enqueue({
47377
+ type: "tool-result",
47378
+ toolCallId: value.item.call_id,
47379
+ toolName: toolNameMapping.toCustomToolName("shell"),
47380
+ result: {
47381
+ output: value.item.output.map(
47382
+ (item) => ({
47383
+ stdout: item.stdout,
47384
+ stderr: item.stderr,
47385
+ outcome: item.outcome.type === "exit" ? {
47386
+ type: "exit",
47387
+ exitCode: item.outcome.exit_code
47388
+ } : { type: "timeout" }
47389
+ })
47390
+ )
47391
+ }
47392
+ });
46315
47393
  } else if (value.item.type === "reasoning") {
46316
47394
  const activeReasoningPart = activeReasoning[value.item.id];
46317
47395
  const summaryPartIndices = Object.entries(
@@ -46326,7 +47404,7 @@ ${user}:`]
46326
47404
  providerMetadata: {
46327
47405
  [providerOptionsName]: {
46328
47406
  itemId: value.item.id,
46329
- reasoningEncryptedContent: (_k = value.item.encrypted_content) != null ? _k : null
47407
+ reasoningEncryptedContent: (_m = value.item.encrypted_content) != null ? _m : null
46330
47408
  }
46331
47409
  }
46332
47410
  });
@@ -46342,6 +47420,15 @@ ${user}:`]
46342
47420
  delta: value.delta
46343
47421
  });
46344
47422
  }
47423
+ } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
47424
+ const toolCall = ongoingToolCalls[value.output_index];
47425
+ if (toolCall != null) {
47426
+ controller.enqueue({
47427
+ type: "tool-input-delta",
47428
+ id: toolCall.toolCallId,
47429
+ delta: value.delta
47430
+ });
47431
+ }
46345
47432
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
46346
47433
  const toolCall = ongoingToolCalls[value.output_index];
46347
47434
  if (toolCall == null ? void 0 : toolCall.applyPatch) {
@@ -46430,7 +47517,7 @@ ${user}:`]
46430
47517
  id: value.item_id,
46431
47518
  delta: value.delta
46432
47519
  });
46433
- if (((_m = (_l = options.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.logprobs) && value.logprobs) {
47520
+ if (((_o = (_n = options.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.logprobs) && value.logprobs) {
46434
47521
  logprobs.push(value.logprobs);
46435
47522
  }
46436
47523
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -46459,7 +47546,7 @@ ${user}:`]
46459
47546
  providerMetadata: {
46460
47547
  [providerOptionsName]: {
46461
47548
  itemId: value.item_id,
46462
- reasoningEncryptedContent: (_o = (_n = activeReasoning[value.item_id]) == null ? void 0 : _n.encryptedContent) != null ? _o : null
47549
+ reasoningEncryptedContent: (_q = (_p = activeReasoning[value.item_id]) == null ? void 0 : _p.encryptedContent) != null ? _q : null
46463
47550
  }
46464
47551
  }
46465
47552
  });
@@ -46493,10 +47580,10 @@ ${user}:`]
46493
47580
  } else if (isResponseFinishedChunk(value)) {
46494
47581
  finishReason = {
46495
47582
  unified: mapOpenAIResponseFinishReason({
46496
- finishReason: (_p = value.response.incomplete_details) == null ? void 0 : _p.reason,
47583
+ finishReason: (_r = value.response.incomplete_details) == null ? void 0 : _r.reason,
46497
47584
  hasFunctionCall
46498
47585
  }),
46499
- raw: (_r = (_q = value.response.incomplete_details) == null ? void 0 : _q.reason) != null ? _r : void 0
47586
+ raw: (_t = (_s = value.response.incomplete_details) == null ? void 0 : _s.reason) != null ? _t : void 0
46500
47587
  };
46501
47588
  usage = value.response.usage;
46502
47589
  if (typeof value.response.service_tier === "string") {
@@ -46508,7 +47595,7 @@ ${user}:`]
46508
47595
  controller.enqueue({
46509
47596
  type: "source",
46510
47597
  sourceType: "url",
46511
- id: (_u = (_t = (_s = self2.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId$1(),
47598
+ id: (_w = (_v = (_u = self2.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId$1(),
46512
47599
  url: value.annotation.url,
46513
47600
  title: value.annotation.title
46514
47601
  });
@@ -46516,7 +47603,7 @@ ${user}:`]
46516
47603
  controller.enqueue({
46517
47604
  type: "source",
46518
47605
  sourceType: "document",
46519
- id: (_x = (_w = (_v = self2.config).generateId) == null ? void 0 : _w.call(_v)) != null ? _x : generateId$1(),
47606
+ id: (_z = (_y = (_x = self2.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId$1(),
46520
47607
  mediaType: "text/plain",
46521
47608
  title: value.annotation.filename,
46522
47609
  filename: value.annotation.filename,
@@ -46532,7 +47619,7 @@ ${user}:`]
46532
47619
  controller.enqueue({
46533
47620
  type: "source",
46534
47621
  sourceType: "document",
46535
- id: (_A = (_z = (_y = self2.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : generateId$1(),
47622
+ id: (_C = (_B = (_A = self2.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId$1(),
46536
47623
  mediaType: "text/plain",
46537
47624
  title: value.annotation.filename,
46538
47625
  filename: value.annotation.filename,
@@ -46548,7 +47635,7 @@ ${user}:`]
46548
47635
  controller.enqueue({
46549
47636
  type: "source",
46550
47637
  sourceType: "document",
46551
- id: (_D = (_C = (_B = self2.config).generateId) == null ? void 0 : _C.call(_B)) != null ? _D : generateId$1(),
47638
+ id: (_F = (_E = (_D = self2.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId$1(),
46552
47639
  mediaType: "application/octet-stream",
46553
47640
  title: value.annotation.file_id,
46554
47641
  filename: value.annotation.file_id,
@@ -46602,6 +47689,9 @@ ${user}:`]
46602
47689
  function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
46603
47690
  return chunk.type === "response.function_call_arguments.delta";
46604
47691
  }
47692
+ function isResponseCustomToolCallInputDeltaChunk(chunk) {
47693
+ return chunk.type === "response.custom_tool_call_input.delta";
47694
+ }
46605
47695
  function isResponseImageGenerationCallPartialImageChunk(chunk) {
46606
47696
  return chunk.type === "response.image_generation_call.partial_image";
46607
47697
  }
@@ -46628,6 +47718,9 @@ ${user}:`]
46628
47718
  }
46629
47719
  function mapWebSearchOutput(action) {
46630
47720
  var _a10;
47721
+ if (action == null) {
47722
+ return {};
47723
+ }
46631
47724
  switch (action.type) {
46632
47725
  case "search":
46633
47726
  return {
@@ -46980,7 +48073,7 @@ ${user}:`]
46980
48073
  };
46981
48074
  }
46982
48075
  };
46983
- var VERSION$2 = "3.0.28";
48076
+ var VERSION$2 = "3.0.41";
46984
48077
  function createOpenAI(options = {}) {
46985
48078
  var _a10, _b9;
46986
48079
  const baseURL = (_a10 = withoutTrailingSlash$1(
@@ -48800,9 +49893,13 @@ Error message: ${getErrorMessage(cause)}`,
48800
49893
  if (toolEntries.length === 0) {
48801
49894
  return "";
48802
49895
  }
48803
- let prompt = "\n\n# 工具调用\n\n";
48804
- prompt += "你可以根据需要调用以下工具:\n\n";
48805
- prompt += "<tools>\n";
49896
+ let prompt = `
49897
+ # 工具调用
49898
+
49899
+ 你可以根据需要调用以下工具:
49900
+
49901
+ <tools>
49902
+ `;
48806
49903
  toolEntries.forEach(([toolName, tool2]) => {
48807
49904
  const toolInfo = tool2;
48808
49905
  const description2 = toolInfo.description || "无描述";
@@ -48815,23 +49912,36 @@ Error message: ${getErrorMessage(cause)}`,
48815
49912
  prompt += `${JSON.stringify(toolJson, null, 2)}
48816
49913
  `;
48817
49914
  });
48818
- prompt += "</tools>\n\n";
48819
- prompt += "## 工具调用格式\n\n";
48820
- prompt += "要调用工具,请使用以下 XML 格式:\n";
48821
- prompt += "Thought: [你的思考过程]\n";
48822
- prompt += '<tool_call>{"name": "toolName", "arguments": {"arg1": "value1"}}</tool_call>\n\n';
48823
- prompt += "工具执行后,你将收到 <tool_response> 格式的结果。你可以继续思考或调用其他工具。\n\n";
48824
- prompt += "## 使用示例\n\n";
48825
- prompt += '如果用户要求"获取今天的日期",你可以这样调用工具:\n';
48826
- prompt += "Thought: 用户想要获取今天的日期,我需要调用日期相关的工具。\n";
48827
- prompt += '<tool_call>{"name": "get-today", "arguments": {}}</tool_call>\n\n';
48828
- prompt += "然后等待工具返回结果(Observation),再根据结果给出最终答案。\n\n";
48829
- prompt += "## 任务完成\n\n";
48830
- prompt += "当任务完成或无法继续时,直接给出最终答案即可。\n\n";
48831
- prompt += "**重要提示**:\n";
48832
- prompt += "- 必须严格按照 XML 格式调用工具\n";
48833
- prompt += "- arguments 必须是有效的 JSON 格式\n";
48834
- prompt += "- 如果不需要调用工具,直接给出最终答案即可\n";
49915
+ prompt += `
49916
+ </tools>
49917
+
49918
+ ## 工具调用格式
49919
+
49920
+ 要调用工具,请使用以下 XML 格式:
49921
+ Thought: [你的思考过程]
49922
+ <tool_call>
49923
+ {"name": "toolName", "arguments": {"arg1": "value1"}}
49924
+ </tool_call>
49925
+
49926
+ 工具执行后,你将收到 <tool_response> 格式的结果。你可以继续思考或调用其他工具。
49927
+
49928
+ ## 使用示例
49929
+
49930
+ 如果用户要求"获取今天的日期",你可以这样调用工具:
49931
+ Thought: 用户想要获取今天的日期,我需要调用日期相关的工具。
49932
+ <tool_call>{"name": "get-today", "arguments": {}}</tool_call>
49933
+
49934
+ 然后等待工具返回结果(Observation),再根据结果给出最终答案。
49935
+
49936
+ ## 任务完成
49937
+
49938
+ 当任务完成或无法继续时,直接给出最终答案即可。
49939
+
49940
+ **重要提示**:
49941
+ - 必须严格按照 XML 格式调用工具
49942
+ - arguments 必须是有效的 JSON 格式
49943
+ - 如果不需要调用工具,直接给出最终答案即可
49944
+ `;
48835
49945
  return prompt;
48836
49946
  }
48837
49947
  function parseReActAction(text2, availableTools) {
@@ -49438,6 +50548,122 @@ ${observationText}
49438
50548
  return this._chat(streamText, options);
49439
50549
  }
49440
50550
  }
50551
+ const MSG_TOOL_CALL = "next-sdk:tool-call";
50552
+ const MSG_TOOL_RESPONSE = "next-sdk:tool-response";
50553
+ const MSG_PAGE_READY = "next-sdk:page-ready";
50554
+ const activePages = /* @__PURE__ */ new Map();
50555
+ let _navigator = null;
50556
+ function setNavigator(fn) {
50557
+ _navigator = fn;
50558
+ }
50559
+ function buildPageHandler(name16, route, timeout = 3e4) {
50560
+ return (input) => {
50561
+ const callId = randomUUID();
50562
+ return new Promise((resolve2, reject) => {
50563
+ let timer;
50564
+ let readyHandler;
50565
+ const cleanup = () => {
50566
+ clearTimeout(timer);
50567
+ window.removeEventListener("message", responseHandler);
50568
+ if (readyHandler) {
50569
+ window.removeEventListener("message", readyHandler);
50570
+ }
50571
+ };
50572
+ timer = setTimeout(() => {
50573
+ cleanup();
50574
+ reject(new Error(`工具 [${name16}] 调用超时 (${timeout}ms),请检查目标页面是否正确调用了 registerPageTool`));
50575
+ }, timeout);
50576
+ const responseHandler = (event) => {
50577
+ if (event.source === window && event.data?.type === MSG_TOOL_RESPONSE && event.data.callId === callId) {
50578
+ cleanup();
50579
+ event.data.error ? reject(new Error(event.data.error)) : resolve2(event.data.result);
50580
+ }
50581
+ };
50582
+ window.addEventListener("message", responseHandler);
50583
+ const sendCall = () => {
50584
+ window.postMessage({ type: MSG_TOOL_CALL, callId, toolName: name16, route, input }, window.location.origin || "*");
50585
+ };
50586
+ let callSent = false;
50587
+ const sendCallOnce = () => {
50588
+ if (callSent) return;
50589
+ callSent = true;
50590
+ sendCall();
50591
+ };
50592
+ const run = async () => {
50593
+ try {
50594
+ if (activePages.get(route)) {
50595
+ sendCallOnce();
50596
+ return;
50597
+ }
50598
+ readyHandler = (event) => {
50599
+ if (event.source === window && event.data?.type === MSG_PAGE_READY && event.data.route === route) {
50600
+ window.removeEventListener("message", readyHandler);
50601
+ sendCallOnce();
50602
+ }
50603
+ };
50604
+ window.addEventListener("message", readyHandler);
50605
+ if (_navigator) {
50606
+ await _navigator(route);
50607
+ }
50608
+ if (activePages.get(route)) {
50609
+ window.removeEventListener("message", readyHandler);
50610
+ sendCallOnce();
50611
+ }
50612
+ } catch (err) {
50613
+ cleanup();
50614
+ reject(err instanceof Error ? err : new Error(String(err)));
50615
+ }
50616
+ };
50617
+ void run();
50618
+ });
50619
+ };
50620
+ }
50621
+ function withPageTools(server) {
50622
+ return new Proxy(server, {
50623
+ get(target, prop, receiver) {
50624
+ if (prop === "registerTool") {
50625
+ return (name16, config2, handlerOrRoute) => {
50626
+ if (typeof handlerOrRoute === "function") {
50627
+ return target.registerTool(name16, config2, handlerOrRoute);
50628
+ }
50629
+ const { route, timeout } = handlerOrRoute;
50630
+ return target.registerTool(name16, config2, buildPageHandler(name16, route, timeout));
50631
+ };
50632
+ }
50633
+ return Reflect.get(target, prop, receiver);
50634
+ }
50635
+ });
50636
+ }
50637
+ function registerPageTool(options) {
50638
+ const { handlers } = options;
50639
+ const route = window.location.pathname;
50640
+ const handleMessage = async (event) => {
50641
+ if (event.source !== window || event.data?.type !== MSG_TOOL_CALL || event.data?.route !== route || !(event.data.toolName in handlers)) {
50642
+ return;
50643
+ }
50644
+ const { callId, toolName, input } = event.data;
50645
+ try {
50646
+ const result = await handlers[toolName](input);
50647
+ window.postMessage({ type: MSG_TOOL_RESPONSE, callId, result }, window.location.origin || "*");
50648
+ } catch (err) {
50649
+ window.postMessage(
50650
+ {
50651
+ type: MSG_TOOL_RESPONSE,
50652
+ callId,
50653
+ error: err instanceof Error ? err.message : String(err)
50654
+ },
50655
+ window.location.origin || "*"
50656
+ );
50657
+ }
50658
+ };
50659
+ activePages.set(route, true);
50660
+ window.addEventListener("message", handleMessage);
50661
+ window.postMessage({ type: MSG_PAGE_READY, route }, window.location.origin || "*");
50662
+ return () => {
50663
+ activePages.delete(route);
50664
+ window.removeEventListener("message", handleMessage);
50665
+ };
50666
+ }
49441
50667
  const MAIN_SKILL_PATH_REG = /^\.\/[^/]+\/SKILL\.md$/;
49442
50668
  const FRONT_MATTER_BLOCK_REG = /^---\s*\n([\s\S]+?)\s*\n---/;
49443
50669
  function parseSkillFrontMatter(content) {
@@ -49450,14 +50676,27 @@ ${observationText}
49450
50676
  const description2 = descMatch?.[1]?.trim();
49451
50677
  return name16 && description2 ? { name: name16, description: description2 } : null;
49452
50678
  }
50679
+ function normalizeSkillModuleKeys(modules) {
50680
+ const result = {};
50681
+ for (const [key, content] of Object.entries(modules)) {
50682
+ const normalizedKey = key.replace(/\\/g, "/");
50683
+ const skillsIndex = normalizedKey.lastIndexOf("skills/");
50684
+ const relativePath = skillsIndex >= 0 ? normalizedKey.slice(skillsIndex + 7) : normalizedKey;
50685
+ const standardPath = relativePath.startsWith("./") ? relativePath : `./${relativePath}`;
50686
+ result[standardPath] = content;
50687
+ }
50688
+ return result;
50689
+ }
49453
50690
  function getMainSkillPaths(modules) {
49454
- return Object.keys(modules).filter((path) => MAIN_SKILL_PATH_REG.test(path));
50691
+ const normalized = normalizeSkillModuleKeys(modules);
50692
+ return Object.keys(normalized).filter((path) => MAIN_SKILL_PATH_REG.test(path));
49455
50693
  }
49456
50694
  function getSkillOverviews(modules) {
49457
- const mainPaths = getMainSkillPaths(modules);
50695
+ const normalized = normalizeSkillModuleKeys(modules);
50696
+ const mainPaths = Object.keys(normalized).filter((path) => MAIN_SKILL_PATH_REG.test(path));
49458
50697
  const list = [];
49459
50698
  for (const path of mainPaths) {
49460
- const content = modules[path];
50699
+ const content = normalized[path];
49461
50700
  if (!content) continue;
49462
50701
  const parsed = parseSkillFrontMatter(content);
49463
50702
  if (!parsed) continue;
@@ -49479,34 +50718,38 @@ ${lines.join("\n")}
49479
50718
  当需要用到某技能时,请使用 get_skill_content 工具获取该技能的完整文档内容。`;
49480
50719
  }
49481
50720
  function getSkillMdPaths(modules) {
49482
- return Object.keys(modules);
50721
+ const normalized = normalizeSkillModuleKeys(modules);
50722
+ return Object.keys(normalized);
49483
50723
  }
49484
50724
  function getSkillMdContent(modules, path) {
49485
- return modules[path];
50725
+ const normalized = normalizeSkillModuleKeys(modules);
50726
+ return normalized[path];
49486
50727
  }
49487
50728
  function getMainSkillPathByName(modules, name16) {
49488
50729
  return getMainSkillPaths(modules).find((p) => p.startsWith(`./${name16}/SKILL.md`));
49489
50730
  }
50731
+ const SKILL_INPUT_SCHEMA = objectType({
50732
+ skillName: stringType().optional().describe("技能名称,与目录名一致,如 calculator"),
50733
+ path: stringType().optional().describe("文档相对路径,如 ./calculator/SKILL.md 或 ./product-guide/reference/xxx.json")
50734
+ });
49490
50735
  function createSkillTools(modules) {
50736
+ const normalizedModules = normalizeSkillModuleKeys(modules);
49491
50737
  const getSkillContent = tool({
49492
- description: "根据技能名称或文档路径获取该技能的完整 Markdown 文档内容。传入 skillName(如 calculator)或 path(如 ./calculator/SKILL.md",
49493
- inputSchema: objectType({
49494
- skillName: stringType().optional().describe("技能名称,与目录名一致,如 calculator"),
49495
- path: stringType().optional().describe("文档相对路径,如 ./calculator/SKILL.md 或 ./product-guide/reference/xxx.md")
49496
- }),
50738
+ description: "根据技能名称或文档路径获取该技能的完整文档内容。传入 skillName(如 calculator)或 path(如 ./calculator/SKILL.md)。支持 .md、.json、.xml 等各类文本格式文件。",
50739
+ inputSchema: SKILL_INPUT_SCHEMA,
49497
50740
  execute: (args) => {
49498
50741
  const { skillName, path: pathArg } = args;
49499
50742
  let content;
49500
50743
  if (pathArg) {
49501
- content = getSkillMdContent(modules, pathArg);
50744
+ content = getSkillMdContent(normalizedModules, pathArg);
49502
50745
  } else if (skillName) {
49503
- const mainPath = getMainSkillPathByName(modules, skillName);
49504
- content = mainPath ? getSkillMdContent(modules, mainPath) : void 0;
50746
+ const mainPath = getMainSkillPathByName(normalizedModules, skillName);
50747
+ content = mainPath ? getSkillMdContent(normalizedModules, mainPath) : void 0;
49505
50748
  }
49506
50749
  if (content === void 0) {
49507
50750
  return { error: "未找到对应技能文档", skillName: skillName ?? pathArg };
49508
50751
  }
49509
- return { content, path: pathArg ?? getMainSkillPathByName(modules, skillName) };
50752
+ return { content, path: pathArg ?? getMainSkillPathByName(normalizedModules, skillName) };
49510
50753
  }
49511
50754
  });
49512
50755
  return {
@@ -49548,6 +50791,9 @@ ${lines.join("\n")}
49548
50791
  exports2.isSSEClientTransport = isSSEClientTransport;
49549
50792
  exports2.isStreamableHTTPClientTransport = isStreamableHTTPClientTransport;
49550
50793
  exports2.parseSkillFrontMatter = parseSkillFrontMatter;
50794
+ exports2.registerPageTool = registerPageTool;
50795
+ exports2.setNavigator = setNavigator;
50796
+ exports2.withPageTools = withPageTools;
49551
50797
  exports2.z = z;
49552
50798
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
49553
50799
  }));