@liberseek/boft-cli-win32-arm64 0.7.3 → 0.7.5

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.
@@ -776,10 +776,10 @@ function mergeDefs(...defs) {
776
776
  function cloneDef(schema) {
777
777
  return mergeDefs(schema._zod.def);
778
778
  }
779
- function getElementAtPath(obj, path7) {
780
- if (!path7)
779
+ function getElementAtPath(obj, path9) {
780
+ if (!path9)
781
781
  return obj;
782
- return path7.reduce((acc, key) => acc?.[key], obj);
782
+ return path9.reduce((acc, key) => acc?.[key], obj);
783
783
  }
784
784
  function promiseAllObject(promisesObj) {
785
785
  const keys = Object.keys(promisesObj);
@@ -1188,11 +1188,11 @@ function explicitlyAborted(x, startIndex = 0) {
1188
1188
  }
1189
1189
  return false;
1190
1190
  }
1191
- function prefixIssues(path7, issues) {
1191
+ function prefixIssues(path9, issues) {
1192
1192
  return issues.map((iss) => {
1193
1193
  var _a3;
1194
1194
  (_a3 = iss).path ?? (_a3.path = []);
1195
- iss.path.unshift(path7);
1195
+ iss.path.unshift(path9);
1196
1196
  return iss;
1197
1197
  });
1198
1198
  }
@@ -1339,16 +1339,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1339
1339
  }
1340
1340
  function formatError(error51, mapper = (issue2) => issue2.message) {
1341
1341
  const fieldErrors = { _errors: [] };
1342
- const processError = (error52, path7 = []) => {
1342
+ const processError = (error52, path9 = []) => {
1343
1343
  for (const issue2 of error52.issues) {
1344
1344
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1345
- issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
1345
+ issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1346
1346
  } else if (issue2.code === "invalid_key") {
1347
- processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1347
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1348
1348
  } else if (issue2.code === "invalid_element") {
1349
- processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1349
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1350
1350
  } else {
1351
- const fullpath = [...path7, ...issue2.path];
1351
+ const fullpath = [...path9, ...issue2.path];
1352
1352
  if (fullpath.length === 0) {
1353
1353
  fieldErrors._errors.push(mapper(issue2));
1354
1354
  } else {
@@ -1375,17 +1375,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1375
1375
  }
1376
1376
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1377
1377
  const result = { errors: [] };
1378
- const processError = (error52, path7 = []) => {
1378
+ const processError = (error52, path9 = []) => {
1379
1379
  var _a3, _b;
1380
1380
  for (const issue2 of error52.issues) {
1381
1381
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1382
- issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
1382
+ issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1383
1383
  } else if (issue2.code === "invalid_key") {
1384
- processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1384
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1385
1385
  } else if (issue2.code === "invalid_element") {
1386
- processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1386
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1387
1387
  } else {
1388
- const fullpath = [...path7, ...issue2.path];
1388
+ const fullpath = [...path9, ...issue2.path];
1389
1389
  if (fullpath.length === 0) {
1390
1390
  result.errors.push(mapper(issue2));
1391
1391
  continue;
@@ -1417,8 +1417,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
1417
1417
  }
1418
1418
  function toDotPath(_path) {
1419
1419
  const segs = [];
1420
- const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
- for (const seg of path7) {
1420
+ const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
+ for (const seg of path9) {
1422
1422
  if (typeof seg === "number")
1423
1423
  segs.push(`[${seg}]`);
1424
1424
  else if (typeof seg === "symbol")
@@ -11788,29 +11788,29 @@ var formatMap = {
11788
11788
  // do not set
11789
11789
  };
11790
11790
  var stringProcessor = (schema, ctx, _json, _params) => {
11791
- const json2 = _json;
11792
- json2.type = "string";
11791
+ const json3 = _json;
11792
+ json3.type = "string";
11793
11793
  const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
11794
11794
  if (typeof minimum === "number")
11795
- json2.minLength = minimum;
11795
+ json3.minLength = minimum;
11796
11796
  if (typeof maximum === "number")
11797
- json2.maxLength = maximum;
11797
+ json3.maxLength = maximum;
11798
11798
  if (format) {
11799
- json2.format = formatMap[format] ?? format;
11800
- if (json2.format === "")
11801
- delete json2.format;
11799
+ json3.format = formatMap[format] ?? format;
11800
+ if (json3.format === "")
11801
+ delete json3.format;
11802
11802
  if (format === "time") {
11803
- delete json2.format;
11803
+ delete json3.format;
11804
11804
  }
11805
11805
  }
11806
11806
  if (contentEncoding)
11807
- json2.contentEncoding = contentEncoding;
11807
+ json3.contentEncoding = contentEncoding;
11808
11808
  if (patterns && patterns.size > 0) {
11809
11809
  const regexes = [...patterns];
11810
11810
  if (regexes.length === 1)
11811
- json2.pattern = regexes[0].source;
11811
+ json3.pattern = regexes[0].source;
11812
11812
  else if (regexes.length > 1) {
11813
- json2.allOf = [
11813
+ json3.allOf = [
11814
11814
  ...regexes.map((regex) => ({
11815
11815
  ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
11816
11816
  pattern: regex.source
@@ -11820,40 +11820,40 @@ var stringProcessor = (schema, ctx, _json, _params) => {
11820
11820
  }
11821
11821
  };
11822
11822
  var numberProcessor = (schema, ctx, _json, _params) => {
11823
- const json2 = _json;
11823
+ const json3 = _json;
11824
11824
  const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
11825
11825
  if (typeof format === "string" && format.includes("int"))
11826
- json2.type = "integer";
11826
+ json3.type = "integer";
11827
11827
  else
11828
- json2.type = "number";
11828
+ json3.type = "number";
11829
11829
  const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
11830
11830
  const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
11831
11831
  const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
11832
11832
  if (exMin) {
11833
11833
  if (legacy) {
11834
- json2.minimum = exclusiveMinimum;
11835
- json2.exclusiveMinimum = true;
11834
+ json3.minimum = exclusiveMinimum;
11835
+ json3.exclusiveMinimum = true;
11836
11836
  } else {
11837
- json2.exclusiveMinimum = exclusiveMinimum;
11837
+ json3.exclusiveMinimum = exclusiveMinimum;
11838
11838
  }
11839
11839
  } else if (typeof minimum === "number") {
11840
- json2.minimum = minimum;
11840
+ json3.minimum = minimum;
11841
11841
  }
11842
11842
  if (exMax) {
11843
11843
  if (legacy) {
11844
- json2.maximum = exclusiveMaximum;
11845
- json2.exclusiveMaximum = true;
11844
+ json3.maximum = exclusiveMaximum;
11845
+ json3.exclusiveMaximum = true;
11846
11846
  } else {
11847
- json2.exclusiveMaximum = exclusiveMaximum;
11847
+ json3.exclusiveMaximum = exclusiveMaximum;
11848
11848
  }
11849
11849
  } else if (typeof maximum === "number") {
11850
- json2.maximum = maximum;
11850
+ json3.maximum = maximum;
11851
11851
  }
11852
11852
  if (typeof multipleOf === "number")
11853
- json2.multipleOf = multipleOf;
11853
+ json3.multipleOf = multipleOf;
11854
11854
  };
11855
- var booleanProcessor = (_schema, _ctx, json2, _params) => {
11856
- json2.type = "boolean";
11855
+ var booleanProcessor = (_schema, _ctx, json3, _params) => {
11856
+ json3.type = "boolean";
11857
11857
  };
11858
11858
  var bigintProcessor = (_schema, ctx, _json, _params) => {
11859
11859
  if (ctx.unrepresentable === "throw") {
@@ -11865,13 +11865,13 @@ var symbolProcessor = (_schema, ctx, _json, _params) => {
11865
11865
  throw new Error("Symbols cannot be represented in JSON Schema");
11866
11866
  }
11867
11867
  };
11868
- var nullProcessor = (_schema, ctx, json2, _params) => {
11868
+ var nullProcessor = (_schema, ctx, json3, _params) => {
11869
11869
  if (ctx.target === "openapi-3.0") {
11870
- json2.type = "string";
11871
- json2.nullable = true;
11872
- json2.enum = [null];
11870
+ json3.type = "string";
11871
+ json3.nullable = true;
11872
+ json3.enum = [null];
11873
11873
  } else {
11874
- json2.type = "null";
11874
+ json3.type = "null";
11875
11875
  }
11876
11876
  };
11877
11877
  var undefinedProcessor = (_schema, ctx, _json, _params) => {
@@ -11884,8 +11884,8 @@ var voidProcessor = (_schema, ctx, _json, _params) => {
11884
11884
  throw new Error("Void cannot be represented in JSON Schema");
11885
11885
  }
11886
11886
  };
11887
- var neverProcessor = (_schema, _ctx, json2, _params) => {
11888
- json2.not = {};
11887
+ var neverProcessor = (_schema, _ctx, json3, _params) => {
11888
+ json3.not = {};
11889
11889
  };
11890
11890
  var anyProcessor = (_schema, _ctx, _json, _params) => {
11891
11891
  };
@@ -11896,16 +11896,16 @@ var dateProcessor = (_schema, ctx, _json, _params) => {
11896
11896
  throw new Error("Date cannot be represented in JSON Schema");
11897
11897
  }
11898
11898
  };
11899
- var enumProcessor = (schema, _ctx, json2, _params) => {
11899
+ var enumProcessor = (schema, _ctx, json3, _params) => {
11900
11900
  const def = schema._zod.def;
11901
11901
  const values = getEnumValues(def.entries);
11902
11902
  if (values.every((v) => typeof v === "number"))
11903
- json2.type = "number";
11903
+ json3.type = "number";
11904
11904
  if (values.every((v) => typeof v === "string"))
11905
- json2.type = "string";
11906
- json2.enum = values;
11905
+ json3.type = "string";
11906
+ json3.enum = values;
11907
11907
  };
11908
- var literalProcessor = (schema, ctx, json2, _params) => {
11908
+ var literalProcessor = (schema, ctx, json3, _params) => {
11909
11909
  const def = schema._zod.def;
11910
11910
  const vals = [];
11911
11911
  for (const val of def.values) {
@@ -11927,22 +11927,22 @@ var literalProcessor = (schema, ctx, json2, _params) => {
11927
11927
  if (vals.length === 0) {
11928
11928
  } else if (vals.length === 1) {
11929
11929
  const val = vals[0];
11930
- json2.type = val === null ? "null" : typeof val;
11930
+ json3.type = val === null ? "null" : typeof val;
11931
11931
  if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
11932
- json2.enum = [val];
11932
+ json3.enum = [val];
11933
11933
  } else {
11934
- json2.const = val;
11934
+ json3.const = val;
11935
11935
  }
11936
11936
  } else {
11937
11937
  if (vals.every((v) => typeof v === "number"))
11938
- json2.type = "number";
11938
+ json3.type = "number";
11939
11939
  if (vals.every((v) => typeof v === "string"))
11940
- json2.type = "string";
11940
+ json3.type = "string";
11941
11941
  if (vals.every((v) => typeof v === "boolean"))
11942
- json2.type = "boolean";
11942
+ json3.type = "boolean";
11943
11943
  if (vals.every((v) => v === null))
11944
- json2.type = "null";
11945
- json2.enum = vals;
11944
+ json3.type = "null";
11945
+ json3.enum = vals;
11946
11946
  }
11947
11947
  };
11948
11948
  var nanProcessor = (_schema, ctx, _json, _params) => {
@@ -11950,16 +11950,16 @@ var nanProcessor = (_schema, ctx, _json, _params) => {
11950
11950
  throw new Error("NaN cannot be represented in JSON Schema");
11951
11951
  }
11952
11952
  };
11953
- var templateLiteralProcessor = (schema, _ctx, json2, _params) => {
11954
- const _json = json2;
11953
+ var templateLiteralProcessor = (schema, _ctx, json3, _params) => {
11954
+ const _json = json3;
11955
11955
  const pattern = schema._zod.pattern;
11956
11956
  if (!pattern)
11957
11957
  throw new Error("Pattern not found in template literal");
11958
11958
  _json.type = "string";
11959
11959
  _json.pattern = pattern.source;
11960
11960
  };
11961
- var fileProcessor = (schema, _ctx, json2, _params) => {
11962
- const _json = json2;
11961
+ var fileProcessor = (schema, _ctx, json3, _params) => {
11962
+ const _json = json3;
11963
11963
  const file2 = {
11964
11964
  type: "string",
11965
11965
  format: "binary",
@@ -11982,8 +11982,8 @@ var fileProcessor = (schema, _ctx, json2, _params) => {
11982
11982
  Object.assign(_json, file2);
11983
11983
  }
11984
11984
  };
11985
- var successProcessor = (_schema, _ctx, json2, _params) => {
11986
- json2.type = "boolean";
11985
+ var successProcessor = (_schema, _ctx, json3, _params) => {
11986
+ json3.type = "boolean";
11987
11987
  };
11988
11988
  var customProcessor = (_schema, ctx, _json, _params) => {
11989
11989
  if (ctx.unrepresentable === "throw") {
@@ -12011,27 +12011,27 @@ var setProcessor = (_schema, ctx, _json, _params) => {
12011
12011
  }
12012
12012
  };
12013
12013
  var arrayProcessor = (schema, ctx, _json, params) => {
12014
- const json2 = _json;
12014
+ const json3 = _json;
12015
12015
  const def = schema._zod.def;
12016
12016
  const { minimum, maximum } = schema._zod.bag;
12017
12017
  if (typeof minimum === "number")
12018
- json2.minItems = minimum;
12018
+ json3.minItems = minimum;
12019
12019
  if (typeof maximum === "number")
12020
- json2.maxItems = maximum;
12021
- json2.type = "array";
12022
- json2.items = process2(def.element, ctx, {
12020
+ json3.maxItems = maximum;
12021
+ json3.type = "array";
12022
+ json3.items = process2(def.element, ctx, {
12023
12023
  ...params,
12024
12024
  path: [...params.path, "items"]
12025
12025
  });
12026
12026
  };
12027
12027
  var objectProcessor = (schema, ctx, _json, params) => {
12028
- const json2 = _json;
12028
+ const json3 = _json;
12029
12029
  const def = schema._zod.def;
12030
- json2.type = "object";
12031
- json2.properties = {};
12030
+ json3.type = "object";
12031
+ json3.properties = {};
12032
12032
  const shape = def.shape;
12033
12033
  for (const key in shape) {
12034
- json2.properties[key] = process2(shape[key], ctx, {
12034
+ json3.properties[key] = process2(shape[key], ctx, {
12035
12035
  ...params,
12036
12036
  path: [...params.path, "properties", key]
12037
12037
  });
@@ -12046,21 +12046,21 @@ var objectProcessor = (schema, ctx, _json, params) => {
12046
12046
  }
12047
12047
  }));
12048
12048
  if (requiredKeys.size > 0) {
12049
- json2.required = Array.from(requiredKeys);
12049
+ json3.required = Array.from(requiredKeys);
12050
12050
  }
12051
12051
  if (def.catchall?._zod.def.type === "never") {
12052
- json2.additionalProperties = false;
12052
+ json3.additionalProperties = false;
12053
12053
  } else if (!def.catchall) {
12054
12054
  if (ctx.io === "output")
12055
- json2.additionalProperties = false;
12055
+ json3.additionalProperties = false;
12056
12056
  } else if (def.catchall) {
12057
- json2.additionalProperties = process2(def.catchall, ctx, {
12057
+ json3.additionalProperties = process2(def.catchall, ctx, {
12058
12058
  ...params,
12059
12059
  path: [...params.path, "additionalProperties"]
12060
12060
  });
12061
12061
  }
12062
12062
  };
12063
- var unionProcessor = (schema, ctx, json2, params) => {
12063
+ var unionProcessor = (schema, ctx, json3, params) => {
12064
12064
  const def = schema._zod.def;
12065
12065
  const isExclusive = def.inclusive === false;
12066
12066
  const options = def.options.map((x, i) => process2(x, ctx, {
@@ -12068,12 +12068,12 @@ var unionProcessor = (schema, ctx, json2, params) => {
12068
12068
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
12069
12069
  }));
12070
12070
  if (isExclusive) {
12071
- json2.oneOf = options;
12071
+ json3.oneOf = options;
12072
12072
  } else {
12073
- json2.anyOf = options;
12073
+ json3.anyOf = options;
12074
12074
  }
12075
12075
  };
12076
- var intersectionProcessor = (schema, ctx, json2, params) => {
12076
+ var intersectionProcessor = (schema, ctx, json3, params) => {
12077
12077
  const def = schema._zod.def;
12078
12078
  const a = process2(def.left, ctx, {
12079
12079
  ...params,
@@ -12088,12 +12088,12 @@ var intersectionProcessor = (schema, ctx, json2, params) => {
12088
12088
  ...isSimpleIntersection(a) ? a.allOf : [a],
12089
12089
  ...isSimpleIntersection(b) ? b.allOf : [b]
12090
12090
  ];
12091
- json2.allOf = allOf;
12091
+ json3.allOf = allOf;
12092
12092
  };
12093
12093
  var tupleProcessor = (schema, ctx, _json, params) => {
12094
- const json2 = _json;
12094
+ const json3 = _json;
12095
12095
  const def = schema._zod.def;
12096
- json2.type = "array";
12096
+ json3.type = "array";
12097
12097
  const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
12098
12098
  const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
12099
12099
  const prefixItems = def.items.map((x, i) => process2(x, ctx, {
@@ -12105,37 +12105,37 @@ var tupleProcessor = (schema, ctx, _json, params) => {
12105
12105
  path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
12106
12106
  }) : null;
12107
12107
  if (ctx.target === "draft-2020-12") {
12108
- json2.prefixItems = prefixItems;
12108
+ json3.prefixItems = prefixItems;
12109
12109
  if (rest) {
12110
- json2.items = rest;
12110
+ json3.items = rest;
12111
12111
  }
12112
12112
  } else if (ctx.target === "openapi-3.0") {
12113
- json2.items = {
12113
+ json3.items = {
12114
12114
  anyOf: prefixItems
12115
12115
  };
12116
12116
  if (rest) {
12117
- json2.items.anyOf.push(rest);
12117
+ json3.items.anyOf.push(rest);
12118
12118
  }
12119
- json2.minItems = prefixItems.length;
12119
+ json3.minItems = prefixItems.length;
12120
12120
  if (!rest) {
12121
- json2.maxItems = prefixItems.length;
12121
+ json3.maxItems = prefixItems.length;
12122
12122
  }
12123
12123
  } else {
12124
- json2.items = prefixItems;
12124
+ json3.items = prefixItems;
12125
12125
  if (rest) {
12126
- json2.additionalItems = rest;
12126
+ json3.additionalItems = rest;
12127
12127
  }
12128
12128
  }
12129
12129
  const { minimum, maximum } = schema._zod.bag;
12130
12130
  if (typeof minimum === "number")
12131
- json2.minItems = minimum;
12131
+ json3.minItems = minimum;
12132
12132
  if (typeof maximum === "number")
12133
- json2.maxItems = maximum;
12133
+ json3.maxItems = maximum;
12134
12134
  };
12135
12135
  var recordProcessor = (schema, ctx, _json, params) => {
12136
- const json2 = _json;
12136
+ const json3 = _json;
12137
12137
  const def = schema._zod.def;
12138
- json2.type = "object";
12138
+ json3.type = "object";
12139
12139
  const keyType = def.keyType;
12140
12140
  const keyBag = keyType._zod.bag;
12141
12141
  const patterns = keyBag?.patterns;
@@ -12144,18 +12144,18 @@ var recordProcessor = (schema, ctx, _json, params) => {
12144
12144
  ...params,
12145
12145
  path: [...params.path, "patternProperties", "*"]
12146
12146
  });
12147
- json2.patternProperties = {};
12147
+ json3.patternProperties = {};
12148
12148
  for (const pattern of patterns) {
12149
- json2.patternProperties[pattern.source] = valueSchema;
12149
+ json3.patternProperties[pattern.source] = valueSchema;
12150
12150
  }
12151
12151
  } else {
12152
12152
  if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
12153
- json2.propertyNames = process2(def.keyType, ctx, {
12153
+ json3.propertyNames = process2(def.keyType, ctx, {
12154
12154
  ...params,
12155
12155
  path: [...params.path, "propertyNames"]
12156
12156
  });
12157
12157
  }
12158
- json2.additionalProperties = process2(def.valueType, ctx, {
12158
+ json3.additionalProperties = process2(def.valueType, ctx, {
12159
12159
  ...params,
12160
12160
  path: [...params.path, "additionalProperties"]
12161
12161
  });
@@ -12164,19 +12164,19 @@ var recordProcessor = (schema, ctx, _json, params) => {
12164
12164
  if (keyValues) {
12165
12165
  const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
12166
12166
  if (validKeyValues.length > 0) {
12167
- json2.required = validKeyValues;
12167
+ json3.required = validKeyValues;
12168
12168
  }
12169
12169
  }
12170
12170
  };
12171
- var nullableProcessor = (schema, ctx, json2, params) => {
12171
+ var nullableProcessor = (schema, ctx, json3, params) => {
12172
12172
  const def = schema._zod.def;
12173
12173
  const inner = process2(def.innerType, ctx, params);
12174
12174
  const seen = ctx.seen.get(schema);
12175
12175
  if (ctx.target === "openapi-3.0") {
12176
12176
  seen.ref = def.innerType;
12177
- json2.nullable = true;
12177
+ json3.nullable = true;
12178
12178
  } else {
12179
- json2.anyOf = [inner, { type: "null" }];
12179
+ json3.anyOf = [inner, { type: "null" }];
12180
12180
  }
12181
12181
  };
12182
12182
  var nonoptionalProcessor = (schema, ctx, _json, params) => {
@@ -12185,22 +12185,22 @@ var nonoptionalProcessor = (schema, ctx, _json, params) => {
12185
12185
  const seen = ctx.seen.get(schema);
12186
12186
  seen.ref = def.innerType;
12187
12187
  };
12188
- var defaultProcessor = (schema, ctx, json2, params) => {
12188
+ var defaultProcessor = (schema, ctx, json3, params) => {
12189
12189
  const def = schema._zod.def;
12190
12190
  process2(def.innerType, ctx, params);
12191
12191
  const seen = ctx.seen.get(schema);
12192
12192
  seen.ref = def.innerType;
12193
- json2.default = JSON.parse(JSON.stringify(def.defaultValue));
12193
+ json3.default = JSON.parse(JSON.stringify(def.defaultValue));
12194
12194
  };
12195
- var prefaultProcessor = (schema, ctx, json2, params) => {
12195
+ var prefaultProcessor = (schema, ctx, json3, params) => {
12196
12196
  const def = schema._zod.def;
12197
12197
  process2(def.innerType, ctx, params);
12198
12198
  const seen = ctx.seen.get(schema);
12199
12199
  seen.ref = def.innerType;
12200
12200
  if (ctx.io === "input")
12201
- json2._prefault = JSON.parse(JSON.stringify(def.defaultValue));
12201
+ json3._prefault = JSON.parse(JSON.stringify(def.defaultValue));
12202
12202
  };
12203
- var catchProcessor = (schema, ctx, json2, params) => {
12203
+ var catchProcessor = (schema, ctx, json3, params) => {
12204
12204
  const def = schema._zod.def;
12205
12205
  process2(def.innerType, ctx, params);
12206
12206
  const seen = ctx.seen.get(schema);
@@ -12211,7 +12211,7 @@ var catchProcessor = (schema, ctx, json2, params) => {
12211
12211
  } catch {
12212
12212
  throw new Error("Dynamic catch values are not supported in JSON Schema");
12213
12213
  }
12214
- json2.default = catchValue;
12214
+ json3.default = catchValue;
12215
12215
  };
12216
12216
  var pipeProcessor = (schema, ctx, _json, params) => {
12217
12217
  const def = schema._zod.def;
@@ -12221,12 +12221,12 @@ var pipeProcessor = (schema, ctx, _json, params) => {
12221
12221
  const seen = ctx.seen.get(schema);
12222
12222
  seen.ref = innerType;
12223
12223
  };
12224
- var readonlyProcessor = (schema, ctx, json2, params) => {
12224
+ var readonlyProcessor = (schema, ctx, json3, params) => {
12225
12225
  const def = schema._zod.def;
12226
12226
  process2(def.innerType, ctx, params);
12227
12227
  const seen = ctx.seen.get(schema);
12228
12228
  seen.ref = def.innerType;
12229
- json2.readOnly = true;
12229
+ json3.readOnly = true;
12230
12230
  };
12231
12231
  var promiseProcessor = (schema, ctx, _json, params) => {
12232
12232
  const def = schema._zod.def;
@@ -12870,7 +12870,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
12870
12870
  var _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
12871
12871
  $ZodString.init(inst, def);
12872
12872
  ZodType.init(inst, def);
12873
- inst._zod.processJSONSchema = (ctx, json2, params) => stringProcessor(inst, ctx, json2, params);
12873
+ inst._zod.processJSONSchema = (ctx, json3, params) => stringProcessor(inst, ctx, json3, params);
12874
12874
  const bag = inst._zod.bag;
12875
12875
  inst.format = bag.format ?? null;
12876
12876
  inst.minLength = bag.minimum ?? null;
@@ -13141,7 +13141,7 @@ function hash(alg, params) {
13141
13141
  var ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
13142
13142
  $ZodNumber.init(inst, def);
13143
13143
  ZodType.init(inst, def);
13144
- inst._zod.processJSONSchema = (ctx, json2, params) => numberProcessor(inst, ctx, json2, params);
13144
+ inst._zod.processJSONSchema = (ctx, json3, params) => numberProcessor(inst, ctx, json3, params);
13145
13145
  _installLazyMethods(inst, "ZodNumber", {
13146
13146
  gt(value, params) {
13147
13147
  return this.check(_gt(value, params));
@@ -13221,7 +13221,7 @@ function uint32(params) {
13221
13221
  var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
13222
13222
  $ZodBoolean.init(inst, def);
13223
13223
  ZodType.init(inst, def);
13224
- inst._zod.processJSONSchema = (ctx, json2, params) => booleanProcessor(inst, ctx, json2, params);
13224
+ inst._zod.processJSONSchema = (ctx, json3, params) => booleanProcessor(inst, ctx, json3, params);
13225
13225
  });
13226
13226
  function boolean2(params) {
13227
13227
  return _boolean(ZodBoolean, params);
@@ -13229,7 +13229,7 @@ function boolean2(params) {
13229
13229
  var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
13230
13230
  $ZodBigInt.init(inst, def);
13231
13231
  ZodType.init(inst, def);
13232
- inst._zod.processJSONSchema = (ctx, json2, params) => bigintProcessor(inst, ctx, json2, params);
13232
+ inst._zod.processJSONSchema = (ctx, json3, params) => bigintProcessor(inst, ctx, json3, params);
13233
13233
  inst.gte = (value, params) => inst.check(_gte(value, params));
13234
13234
  inst.min = (value, params) => inst.check(_gte(value, params));
13235
13235
  inst.gt = (value, params) => inst.check(_gt(value, params));
@@ -13264,7 +13264,7 @@ function uint64(params) {
13264
13264
  var ZodSymbol = /* @__PURE__ */ $constructor("ZodSymbol", (inst, def) => {
13265
13265
  $ZodSymbol.init(inst, def);
13266
13266
  ZodType.init(inst, def);
13267
- inst._zod.processJSONSchema = (ctx, json2, params) => symbolProcessor(inst, ctx, json2, params);
13267
+ inst._zod.processJSONSchema = (ctx, json3, params) => symbolProcessor(inst, ctx, json3, params);
13268
13268
  });
13269
13269
  function symbol(params) {
13270
13270
  return _symbol(ZodSymbol, params);
@@ -13272,7 +13272,7 @@ function symbol(params) {
13272
13272
  var ZodUndefined = /* @__PURE__ */ $constructor("ZodUndefined", (inst, def) => {
13273
13273
  $ZodUndefined.init(inst, def);
13274
13274
  ZodType.init(inst, def);
13275
- inst._zod.processJSONSchema = (ctx, json2, params) => undefinedProcessor(inst, ctx, json2, params);
13275
+ inst._zod.processJSONSchema = (ctx, json3, params) => undefinedProcessor(inst, ctx, json3, params);
13276
13276
  });
13277
13277
  function _undefined3(params) {
13278
13278
  return _undefined2(ZodUndefined, params);
@@ -13280,7 +13280,7 @@ function _undefined3(params) {
13280
13280
  var ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
13281
13281
  $ZodNull.init(inst, def);
13282
13282
  ZodType.init(inst, def);
13283
- inst._zod.processJSONSchema = (ctx, json2, params) => nullProcessor(inst, ctx, json2, params);
13283
+ inst._zod.processJSONSchema = (ctx, json3, params) => nullProcessor(inst, ctx, json3, params);
13284
13284
  });
13285
13285
  function _null3(params) {
13286
13286
  return _null2(ZodNull, params);
@@ -13288,7 +13288,7 @@ function _null3(params) {
13288
13288
  var ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
13289
13289
  $ZodAny.init(inst, def);
13290
13290
  ZodType.init(inst, def);
13291
- inst._zod.processJSONSchema = (ctx, json2, params) => anyProcessor(inst, ctx, json2, params);
13291
+ inst._zod.processJSONSchema = (ctx, json3, params) => anyProcessor(inst, ctx, json3, params);
13292
13292
  });
13293
13293
  function any() {
13294
13294
  return _any(ZodAny);
@@ -13296,7 +13296,7 @@ function any() {
13296
13296
  var ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
13297
13297
  $ZodUnknown.init(inst, def);
13298
13298
  ZodType.init(inst, def);
13299
- inst._zod.processJSONSchema = (ctx, json2, params) => unknownProcessor(inst, ctx, json2, params);
13299
+ inst._zod.processJSONSchema = (ctx, json3, params) => unknownProcessor(inst, ctx, json3, params);
13300
13300
  });
13301
13301
  function unknown() {
13302
13302
  return _unknown(ZodUnknown);
@@ -13304,7 +13304,7 @@ function unknown() {
13304
13304
  var ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
13305
13305
  $ZodNever.init(inst, def);
13306
13306
  ZodType.init(inst, def);
13307
- inst._zod.processJSONSchema = (ctx, json2, params) => neverProcessor(inst, ctx, json2, params);
13307
+ inst._zod.processJSONSchema = (ctx, json3, params) => neverProcessor(inst, ctx, json3, params);
13308
13308
  });
13309
13309
  function never(params) {
13310
13310
  return _never(ZodNever, params);
@@ -13312,7 +13312,7 @@ function never(params) {
13312
13312
  var ZodVoid = /* @__PURE__ */ $constructor("ZodVoid", (inst, def) => {
13313
13313
  $ZodVoid.init(inst, def);
13314
13314
  ZodType.init(inst, def);
13315
- inst._zod.processJSONSchema = (ctx, json2, params) => voidProcessor(inst, ctx, json2, params);
13315
+ inst._zod.processJSONSchema = (ctx, json3, params) => voidProcessor(inst, ctx, json3, params);
13316
13316
  });
13317
13317
  function _void2(params) {
13318
13318
  return _void(ZodVoid, params);
@@ -13320,7 +13320,7 @@ function _void2(params) {
13320
13320
  var ZodDate = /* @__PURE__ */ $constructor("ZodDate", (inst, def) => {
13321
13321
  $ZodDate.init(inst, def);
13322
13322
  ZodType.init(inst, def);
13323
- inst._zod.processJSONSchema = (ctx, json2, params) => dateProcessor(inst, ctx, json2, params);
13323
+ inst._zod.processJSONSchema = (ctx, json3, params) => dateProcessor(inst, ctx, json3, params);
13324
13324
  inst.min = (value, params) => inst.check(_gte(value, params));
13325
13325
  inst.max = (value, params) => inst.check(_lte(value, params));
13326
13326
  const c = inst._zod.bag;
@@ -13333,7 +13333,7 @@ function date3(params) {
13333
13333
  var ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
13334
13334
  $ZodArray.init(inst, def);
13335
13335
  ZodType.init(inst, def);
13336
- inst._zod.processJSONSchema = (ctx, json2, params) => arrayProcessor(inst, ctx, json2, params);
13336
+ inst._zod.processJSONSchema = (ctx, json3, params) => arrayProcessor(inst, ctx, json3, params);
13337
13337
  inst.element = def.element;
13338
13338
  _installLazyMethods(inst, "ZodArray", {
13339
13339
  min(n, params) {
@@ -13363,7 +13363,7 @@ function keyof(schema) {
13363
13363
  var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
13364
13364
  $ZodObjectJIT.init(inst, def);
13365
13365
  ZodType.init(inst, def);
13366
- inst._zod.processJSONSchema = (ctx, json2, params) => objectProcessor(inst, ctx, json2, params);
13366
+ inst._zod.processJSONSchema = (ctx, json3, params) => objectProcessor(inst, ctx, json3, params);
13367
13367
  util_exports.defineLazy(inst, "shape", () => {
13368
13368
  return def.shape;
13369
13369
  });
@@ -13436,7 +13436,7 @@ function looseObject(shape, params) {
13436
13436
  var ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
13437
13437
  $ZodUnion.init(inst, def);
13438
13438
  ZodType.init(inst, def);
13439
- inst._zod.processJSONSchema = (ctx, json2, params) => unionProcessor(inst, ctx, json2, params);
13439
+ inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
13440
13440
  inst.options = def.options;
13441
13441
  });
13442
13442
  function union(options, params) {
@@ -13449,7 +13449,7 @@ function union(options, params) {
13449
13449
  var ZodXor = /* @__PURE__ */ $constructor("ZodXor", (inst, def) => {
13450
13450
  ZodUnion.init(inst, def);
13451
13451
  $ZodXor.init(inst, def);
13452
- inst._zod.processJSONSchema = (ctx, json2, params) => unionProcessor(inst, ctx, json2, params);
13452
+ inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
13453
13453
  inst.options = def.options;
13454
13454
  });
13455
13455
  function xor(options, params) {
@@ -13475,7 +13475,7 @@ function discriminatedUnion(discriminator, options, params) {
13475
13475
  var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
13476
13476
  $ZodIntersection.init(inst, def);
13477
13477
  ZodType.init(inst, def);
13478
- inst._zod.processJSONSchema = (ctx, json2, params) => intersectionProcessor(inst, ctx, json2, params);
13478
+ inst._zod.processJSONSchema = (ctx, json3, params) => intersectionProcessor(inst, ctx, json3, params);
13479
13479
  });
13480
13480
  function intersection(left, right) {
13481
13481
  return new ZodIntersection({
@@ -13487,7 +13487,7 @@ function intersection(left, right) {
13487
13487
  var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
13488
13488
  $ZodTuple.init(inst, def);
13489
13489
  ZodType.init(inst, def);
13490
- inst._zod.processJSONSchema = (ctx, json2, params) => tupleProcessor(inst, ctx, json2, params);
13490
+ inst._zod.processJSONSchema = (ctx, json3, params) => tupleProcessor(inst, ctx, json3, params);
13491
13491
  inst.rest = (rest) => inst.clone({
13492
13492
  ...inst._zod.def,
13493
13493
  rest
@@ -13507,7 +13507,7 @@ function tuple(items, _paramsOrRest, _params) {
13507
13507
  var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
13508
13508
  $ZodRecord.init(inst, def);
13509
13509
  ZodType.init(inst, def);
13510
- inst._zod.processJSONSchema = (ctx, json2, params) => recordProcessor(inst, ctx, json2, params);
13510
+ inst._zod.processJSONSchema = (ctx, json3, params) => recordProcessor(inst, ctx, json3, params);
13511
13511
  inst.keyType = def.keyType;
13512
13512
  inst.valueType = def.valueType;
13513
13513
  });
@@ -13549,7 +13549,7 @@ function looseRecord(keyType, valueType, params) {
13549
13549
  var ZodMap = /* @__PURE__ */ $constructor("ZodMap", (inst, def) => {
13550
13550
  $ZodMap.init(inst, def);
13551
13551
  ZodType.init(inst, def);
13552
- inst._zod.processJSONSchema = (ctx, json2, params) => mapProcessor(inst, ctx, json2, params);
13552
+ inst._zod.processJSONSchema = (ctx, json3, params) => mapProcessor(inst, ctx, json3, params);
13553
13553
  inst.keyType = def.keyType;
13554
13554
  inst.valueType = def.valueType;
13555
13555
  inst.min = (...args) => inst.check(_minSize(...args));
@@ -13568,7 +13568,7 @@ function map(keyType, valueType, params) {
13568
13568
  var ZodSet = /* @__PURE__ */ $constructor("ZodSet", (inst, def) => {
13569
13569
  $ZodSet.init(inst, def);
13570
13570
  ZodType.init(inst, def);
13571
- inst._zod.processJSONSchema = (ctx, json2, params) => setProcessor(inst, ctx, json2, params);
13571
+ inst._zod.processJSONSchema = (ctx, json3, params) => setProcessor(inst, ctx, json3, params);
13572
13572
  inst.min = (...args) => inst.check(_minSize(...args));
13573
13573
  inst.nonempty = (params) => inst.check(_minSize(1, params));
13574
13574
  inst.max = (...args) => inst.check(_maxSize(...args));
@@ -13584,7 +13584,7 @@ function set(valueType, params) {
13584
13584
  var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
13585
13585
  $ZodEnum.init(inst, def);
13586
13586
  ZodType.init(inst, def);
13587
- inst._zod.processJSONSchema = (ctx, json2, params) => enumProcessor(inst, ctx, json2, params);
13587
+ inst._zod.processJSONSchema = (ctx, json3, params) => enumProcessor(inst, ctx, json3, params);
13588
13588
  inst.enum = def.entries;
13589
13589
  inst.options = Object.values(def.entries);
13590
13590
  const keys = new Set(Object.keys(def.entries));
@@ -13637,7 +13637,7 @@ function nativeEnum(entries, params) {
13637
13637
  var ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
13638
13638
  $ZodLiteral.init(inst, def);
13639
13639
  ZodType.init(inst, def);
13640
- inst._zod.processJSONSchema = (ctx, json2, params) => literalProcessor(inst, ctx, json2, params);
13640
+ inst._zod.processJSONSchema = (ctx, json3, params) => literalProcessor(inst, ctx, json3, params);
13641
13641
  inst.values = new Set(def.values);
13642
13642
  Object.defineProperty(inst, "value", {
13643
13643
  get() {
@@ -13658,7 +13658,7 @@ function literal(value, params) {
13658
13658
  var ZodFile = /* @__PURE__ */ $constructor("ZodFile", (inst, def) => {
13659
13659
  $ZodFile.init(inst, def);
13660
13660
  ZodType.init(inst, def);
13661
- inst._zod.processJSONSchema = (ctx, json2, params) => fileProcessor(inst, ctx, json2, params);
13661
+ inst._zod.processJSONSchema = (ctx, json3, params) => fileProcessor(inst, ctx, json3, params);
13662
13662
  inst.min = (size, params) => inst.check(_minSize(size, params));
13663
13663
  inst.max = (size, params) => inst.check(_maxSize(size, params));
13664
13664
  inst.mime = (types, params) => inst.check(_mime(Array.isArray(types) ? types : [types], params));
@@ -13669,7 +13669,7 @@ function file(params) {
13669
13669
  var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
13670
13670
  $ZodTransform.init(inst, def);
13671
13671
  ZodType.init(inst, def);
13672
- inst._zod.processJSONSchema = (ctx, json2, params) => transformProcessor(inst, ctx, json2, params);
13672
+ inst._zod.processJSONSchema = (ctx, json3, params) => transformProcessor(inst, ctx, json3, params);
13673
13673
  inst._zod.parse = (payload, _ctx) => {
13674
13674
  if (_ctx.direction === "backward") {
13675
13675
  throw new $ZodEncodeError(inst.constructor.name);
@@ -13709,7 +13709,7 @@ function transform(fn) {
13709
13709
  var ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
13710
13710
  $ZodOptional.init(inst, def);
13711
13711
  ZodType.init(inst, def);
13712
- inst._zod.processJSONSchema = (ctx, json2, params) => optionalProcessor(inst, ctx, json2, params);
13712
+ inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
13713
13713
  inst.unwrap = () => inst._zod.def.innerType;
13714
13714
  });
13715
13715
  function optional(innerType) {
@@ -13721,7 +13721,7 @@ function optional(innerType) {
13721
13721
  var ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
13722
13722
  $ZodExactOptional.init(inst, def);
13723
13723
  ZodType.init(inst, def);
13724
- inst._zod.processJSONSchema = (ctx, json2, params) => optionalProcessor(inst, ctx, json2, params);
13724
+ inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
13725
13725
  inst.unwrap = () => inst._zod.def.innerType;
13726
13726
  });
13727
13727
  function exactOptional(innerType) {
@@ -13733,7 +13733,7 @@ function exactOptional(innerType) {
13733
13733
  var ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
13734
13734
  $ZodNullable.init(inst, def);
13735
13735
  ZodType.init(inst, def);
13736
- inst._zod.processJSONSchema = (ctx, json2, params) => nullableProcessor(inst, ctx, json2, params);
13736
+ inst._zod.processJSONSchema = (ctx, json3, params) => nullableProcessor(inst, ctx, json3, params);
13737
13737
  inst.unwrap = () => inst._zod.def.innerType;
13738
13738
  });
13739
13739
  function nullable(innerType) {
@@ -13748,7 +13748,7 @@ function nullish2(innerType) {
13748
13748
  var ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
13749
13749
  $ZodDefault.init(inst, def);
13750
13750
  ZodType.init(inst, def);
13751
- inst._zod.processJSONSchema = (ctx, json2, params) => defaultProcessor(inst, ctx, json2, params);
13751
+ inst._zod.processJSONSchema = (ctx, json3, params) => defaultProcessor(inst, ctx, json3, params);
13752
13752
  inst.unwrap = () => inst._zod.def.innerType;
13753
13753
  inst.removeDefault = inst.unwrap;
13754
13754
  });
@@ -13764,7 +13764,7 @@ function _default2(innerType, defaultValue) {
13764
13764
  var ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
13765
13765
  $ZodPrefault.init(inst, def);
13766
13766
  ZodType.init(inst, def);
13767
- inst._zod.processJSONSchema = (ctx, json2, params) => prefaultProcessor(inst, ctx, json2, params);
13767
+ inst._zod.processJSONSchema = (ctx, json3, params) => prefaultProcessor(inst, ctx, json3, params);
13768
13768
  inst.unwrap = () => inst._zod.def.innerType;
13769
13769
  });
13770
13770
  function prefault(innerType, defaultValue) {
@@ -13779,7 +13779,7 @@ function prefault(innerType, defaultValue) {
13779
13779
  var ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
13780
13780
  $ZodNonOptional.init(inst, def);
13781
13781
  ZodType.init(inst, def);
13782
- inst._zod.processJSONSchema = (ctx, json2, params) => nonoptionalProcessor(inst, ctx, json2, params);
13782
+ inst._zod.processJSONSchema = (ctx, json3, params) => nonoptionalProcessor(inst, ctx, json3, params);
13783
13783
  inst.unwrap = () => inst._zod.def.innerType;
13784
13784
  });
13785
13785
  function nonoptional(innerType, params) {
@@ -13792,7 +13792,7 @@ function nonoptional(innerType, params) {
13792
13792
  var ZodSuccess = /* @__PURE__ */ $constructor("ZodSuccess", (inst, def) => {
13793
13793
  $ZodSuccess.init(inst, def);
13794
13794
  ZodType.init(inst, def);
13795
- inst._zod.processJSONSchema = (ctx, json2, params) => successProcessor(inst, ctx, json2, params);
13795
+ inst._zod.processJSONSchema = (ctx, json3, params) => successProcessor(inst, ctx, json3, params);
13796
13796
  inst.unwrap = () => inst._zod.def.innerType;
13797
13797
  });
13798
13798
  function success(innerType) {
@@ -13804,7 +13804,7 @@ function success(innerType) {
13804
13804
  var ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
13805
13805
  $ZodCatch.init(inst, def);
13806
13806
  ZodType.init(inst, def);
13807
- inst._zod.processJSONSchema = (ctx, json2, params) => catchProcessor(inst, ctx, json2, params);
13807
+ inst._zod.processJSONSchema = (ctx, json3, params) => catchProcessor(inst, ctx, json3, params);
13808
13808
  inst.unwrap = () => inst._zod.def.innerType;
13809
13809
  inst.removeCatch = inst.unwrap;
13810
13810
  });
@@ -13818,7 +13818,7 @@ function _catch2(innerType, catchValue) {
13818
13818
  var ZodNaN = /* @__PURE__ */ $constructor("ZodNaN", (inst, def) => {
13819
13819
  $ZodNaN.init(inst, def);
13820
13820
  ZodType.init(inst, def);
13821
- inst._zod.processJSONSchema = (ctx, json2, params) => nanProcessor(inst, ctx, json2, params);
13821
+ inst._zod.processJSONSchema = (ctx, json3, params) => nanProcessor(inst, ctx, json3, params);
13822
13822
  });
13823
13823
  function nan(params) {
13824
13824
  return _nan(ZodNaN, params);
@@ -13826,7 +13826,7 @@ function nan(params) {
13826
13826
  var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
13827
13827
  $ZodPipe.init(inst, def);
13828
13828
  ZodType.init(inst, def);
13829
- inst._zod.processJSONSchema = (ctx, json2, params) => pipeProcessor(inst, ctx, json2, params);
13829
+ inst._zod.processJSONSchema = (ctx, json3, params) => pipeProcessor(inst, ctx, json3, params);
13830
13830
  inst.in = def.in;
13831
13831
  inst.out = def.out;
13832
13832
  });
@@ -13868,7 +13868,7 @@ var ZodPreprocess = /* @__PURE__ */ $constructor("ZodPreprocess", (inst, def) =>
13868
13868
  var ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
13869
13869
  $ZodReadonly.init(inst, def);
13870
13870
  ZodType.init(inst, def);
13871
- inst._zod.processJSONSchema = (ctx, json2, params) => readonlyProcessor(inst, ctx, json2, params);
13871
+ inst._zod.processJSONSchema = (ctx, json3, params) => readonlyProcessor(inst, ctx, json3, params);
13872
13872
  inst.unwrap = () => inst._zod.def.innerType;
13873
13873
  });
13874
13874
  function readonly(innerType) {
@@ -13880,7 +13880,7 @@ function readonly(innerType) {
13880
13880
  var ZodTemplateLiteral = /* @__PURE__ */ $constructor("ZodTemplateLiteral", (inst, def) => {
13881
13881
  $ZodTemplateLiteral.init(inst, def);
13882
13882
  ZodType.init(inst, def);
13883
- inst._zod.processJSONSchema = (ctx, json2, params) => templateLiteralProcessor(inst, ctx, json2, params);
13883
+ inst._zod.processJSONSchema = (ctx, json3, params) => templateLiteralProcessor(inst, ctx, json3, params);
13884
13884
  });
13885
13885
  function templateLiteral(parts, params) {
13886
13886
  return new ZodTemplateLiteral({
@@ -13892,7 +13892,7 @@ function templateLiteral(parts, params) {
13892
13892
  var ZodLazy = /* @__PURE__ */ $constructor("ZodLazy", (inst, def) => {
13893
13893
  $ZodLazy.init(inst, def);
13894
13894
  ZodType.init(inst, def);
13895
- inst._zod.processJSONSchema = (ctx, json2, params) => lazyProcessor(inst, ctx, json2, params);
13895
+ inst._zod.processJSONSchema = (ctx, json3, params) => lazyProcessor(inst, ctx, json3, params);
13896
13896
  inst.unwrap = () => inst._zod.def.getter();
13897
13897
  });
13898
13898
  function lazy(getter) {
@@ -13904,7 +13904,7 @@ function lazy(getter) {
13904
13904
  var ZodPromise = /* @__PURE__ */ $constructor("ZodPromise", (inst, def) => {
13905
13905
  $ZodPromise.init(inst, def);
13906
13906
  ZodType.init(inst, def);
13907
- inst._zod.processJSONSchema = (ctx, json2, params) => promiseProcessor(inst, ctx, json2, params);
13907
+ inst._zod.processJSONSchema = (ctx, json3, params) => promiseProcessor(inst, ctx, json3, params);
13908
13908
  inst.unwrap = () => inst._zod.def.innerType;
13909
13909
  });
13910
13910
  function promise(innerType) {
@@ -13916,7 +13916,7 @@ function promise(innerType) {
13916
13916
  var ZodFunction = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
13917
13917
  $ZodFunction.init(inst, def);
13918
13918
  ZodType.init(inst, def);
13919
- inst._zod.processJSONSchema = (ctx, json2, params) => functionProcessor(inst, ctx, json2, params);
13919
+ inst._zod.processJSONSchema = (ctx, json3, params) => functionProcessor(inst, ctx, json3, params);
13920
13920
  });
13921
13921
  function _function(params) {
13922
13922
  return new ZodFunction({
@@ -13928,7 +13928,7 @@ function _function(params) {
13928
13928
  var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
13929
13929
  $ZodCustom.init(inst, def);
13930
13930
  ZodType.init(inst, def);
13931
- inst._zod.processJSONSchema = (ctx, json2, params) => customProcessor(inst, ctx, json2, params);
13931
+ inst._zod.processJSONSchema = (ctx, json3, params) => customProcessor(inst, ctx, json3, params);
13932
13932
  });
13933
13933
  function check(fn) {
13934
13934
  const ch = new $ZodCheck({
@@ -14110,13 +14110,13 @@ function resolveRef(ref, ctx) {
14110
14110
  if (!ref.startsWith("#")) {
14111
14111
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14112
14112
  }
14113
- const path7 = ref.slice(1).split("/").filter(Boolean);
14114
- if (path7.length === 0) {
14113
+ const path9 = ref.slice(1).split("/").filter(Boolean);
14114
+ if (path9.length === 0) {
14115
14115
  return ctx.rootSchema;
14116
14116
  }
14117
14117
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14118
- if (path7[0] === defsKey) {
14119
- const key = path7[1];
14118
+ if (path9[0] === defsKey) {
14119
+ const key = path9[1];
14120
14120
  if (!key || !ctx.defs[key]) {
14121
14121
  throw new Error(`Reference not found: ${ref}`);
14122
14122
  }
@@ -15521,8 +15521,8 @@ function validateHostQuestionResponse(interaction, response) {
15521
15521
  if (!question.multiple && answers.length > 1) {
15522
15522
  return invalidRequest2("Single-choice Question accepts at most one answer");
15523
15523
  }
15524
- const declared = new Set(question.options.map(({ value }) => value));
15525
- if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
15524
+ const declared2 = new Set(question.options.map(({ value }) => value));
15525
+ if (!question.allowOther && answers.some((answer) => !declared2.has(answer))) {
15526
15526
  return invalidRequest2("Question Response contains an undeclared choice");
15527
15527
  }
15528
15528
  }
@@ -16334,7 +16334,7 @@ var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueO
16334
16334
 
16335
16335
  // ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/utils.gen.js
16336
16336
  var PATH_PARAM_RE = /\{[^{}]+\}/g;
16337
- var defaultPathSerializer = ({ path: path7, url: _url2 }) => {
16337
+ var defaultPathSerializer = ({ path: path9, url: _url2 }) => {
16338
16338
  let url2 = _url2;
16339
16339
  const matches = _url2.match(PATH_PARAM_RE);
16340
16340
  if (matches) {
@@ -16353,7 +16353,7 @@ var defaultPathSerializer = ({ path: path7, url: _url2 }) => {
16353
16353
  name = name.substring(1);
16354
16354
  style = "matrix";
16355
16355
  }
16356
- const value = path7[name];
16356
+ const value = path9[name];
16357
16357
  if (value === void 0 || value === null) {
16358
16358
  continue;
16359
16359
  }
@@ -16384,11 +16384,11 @@ var defaultPathSerializer = ({ path: path7, url: _url2 }) => {
16384
16384
  }
16385
16385
  return url2;
16386
16386
  };
16387
- var getUrl = ({ baseUrl, path: path7, query, querySerializer, url: _url2 }) => {
16387
+ var getUrl = ({ baseUrl, path: path9, query, querySerializer, url: _url2 }) => {
16388
16388
  const pathUrl = _url2.startsWith("/") ? _url2 : `/${_url2}`;
16389
16389
  let url2 = (baseUrl ?? "") + pathUrl;
16390
- if (path7) {
16391
- url2 = defaultPathSerializer({ path: path7, url: url2 });
16390
+ if (path9) {
16391
+ url2 = defaultPathSerializer({ path: path9, url: url2 });
16392
16392
  }
16393
16393
  let search = query ? querySerializer(query) : "";
16394
16394
  if (search.startsWith("?")) {
@@ -22518,6 +22518,11 @@ function semanticHistory(snapshot) {
22518
22518
  items: turn.items.map(({ item, outcome }) => {
22519
22519
  const { itemId: _itemId, ...content } = item;
22520
22520
  void _itemId;
22521
+ if (content.type === "fileChange") {
22522
+ const { sourceItemIds: _sourceItemIds, ...change } = content;
22523
+ void _sourceItemIds;
22524
+ return { item: change, outcome };
22525
+ }
22521
22526
  return { item: content, outcome };
22522
22527
  }),
22523
22528
  outcome: turn.outcome,
@@ -23980,11 +23985,3012 @@ var OpenCodeAdapter = class {
23980
23985
  }
23981
23986
  };
23982
23987
 
23988
+ // dist/version.js
23989
+ import { execFile } from "node:child_process";
23990
+ import { promisify } from "node:util";
23991
+ function openCodeMajor(version2) {
23992
+ const match = /^(?:opencode\s+)?v?([12])\.\d+\.\d+(?:[-+][\w.-]+)?$/u.exec(version2.trim());
23993
+ if (!match)
23994
+ throw new Error(`Unsupported OpenCode version: ${version2.trim().slice(0, 100)}`);
23995
+ return match[1] === "1" ? 1 : 2;
23996
+ }
23997
+ async function detectOpenCode(options) {
23998
+ const environment = options.environment ?? process.env;
23999
+ const executable = resolveOpenCodeExecutable({
24000
+ ...options.command ? { command: options.command } : {},
24001
+ environment
24002
+ });
24003
+ const invocation = commandInvocation(executable, ["--version"], environment);
24004
+ const { stdout } = await promisify(execFile)(invocation.command, invocation.arguments, {
24005
+ env: environment,
24006
+ timeout: options.startupTimeoutMs ?? 2e4,
24007
+ maxBuffer: 16384,
24008
+ windowsHide: true,
24009
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments
24010
+ });
24011
+ return { executable, major: openCodeMajor(stdout) };
24012
+ }
24013
+
24014
+ // dist/v2/adapter.js
24015
+ import fs6 from "node:fs";
24016
+ import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
24017
+
24018
+ // dist/v2/state.js
24019
+ import fs5 from "node:fs";
24020
+ import path7 from "node:path";
24021
+ var harnessId = harnessIdSchema.parse("opencode");
24022
+ function failure(message, code = "nativeFailure") {
24023
+ return {
24024
+ code,
24025
+ message,
24026
+ retryable: ["nativeFailure", "unavailable", "sessionBusy"].includes(code)
24027
+ };
24028
+ }
24029
+ function errorResult(error51) {
24030
+ return {
24031
+ ok: false,
24032
+ error: failure(error51 instanceof Error ? error51.message : String(error51))
24033
+ };
24034
+ }
24035
+ function sameDirectory(left, right) {
24036
+ const canonical = (value) => {
24037
+ try {
24038
+ return fs5.realpathSync(value);
24039
+ } catch {
24040
+ return path7.resolve(value);
24041
+ }
24042
+ };
24043
+ return canonical(left) === canonical(right);
24044
+ }
24045
+ function v2Ref(session, executionPolicy) {
24046
+ return nativeSessionRefSchema.parse({
24047
+ harnessId,
24048
+ nativeSessionId: session.id,
24049
+ formatVersion: 1,
24050
+ locator: { protocol: 2, directory: session.location.directory, executionPolicy }
24051
+ });
24052
+ }
24053
+ function v2Locator(ref) {
24054
+ nativeSessionRefSchema.parse(ref);
24055
+ const locator = ref.locator;
24056
+ if (ref.harnessId !== harnessId || !locator || typeof locator !== "object" || Array.isArray(locator) || locator.protocol !== 2 || typeof locator.directory !== "string" || !locator.directory || locator.executionPolicy !== "default" && locator.executionPolicy !== "unattended-full-access") {
24057
+ throw new Error("This Session requires an OpenCode v2 Native Ref; v1 histories are not migrated by codexhost");
24058
+ }
24059
+ return { directory: locator.directory, executionPolicy: locator.executionPolicy };
24060
+ }
24061
+ function v2Catalog(models, defaultModel) {
24062
+ const enabled = models.filter((model) => model.enabled);
24063
+ const variants = [...new Set(enabled.flatMap((model) => model.variants.map((v) => v.id)))].sort();
24064
+ const ref = (model) => encodeOpenCodeModelRef({ providerID: model.providerID, modelID: model.id });
24065
+ return harnessModelCatalogSchema.parse({
24066
+ models: enabled.map((model) => ({
24067
+ ref: ref(model),
24068
+ label: `${model.providerID} / ${model.name}`,
24069
+ resolvedModelLabel: `${model.providerID}/${model.id}`,
24070
+ supportedThinkingOptionIds: [
24071
+ encodeOpenCodeVariant(void 0),
24072
+ ...model.variants.map((v) => encodeOpenCodeVariant(v.id))
24073
+ ]
24074
+ })),
24075
+ ...defaultModel && enabled.some((m) => ref(m).id === ref(defaultModel).id) ? { defaultModel: ref(defaultModel) } : {},
24076
+ thinkingOptions: [void 0, ...variants].map((v) => ({
24077
+ id: encodeOpenCodeVariant(v),
24078
+ label: v ?? "Default"
24079
+ })),
24080
+ defaultThinkingOptionId: encodeOpenCodeVariant(void 0)
24081
+ });
24082
+ }
24083
+ function v2Permissions(current = [], mode) {
24084
+ const selected = decodeOpenCodePermissionModeId(mode);
24085
+ const rules = current.filter((rule) => !(rule.action === "*" && rule.resource === "*" && ["allow", "ask"].includes(rule.effect)));
24086
+ return selected === "default" ? rules : [...rules, { action: "*", resource: "*", effect: selected }];
24087
+ }
24088
+ function v2State(session, catalog, policy) {
24089
+ const model = session.model ? encodeOpenCodeModelRef({ providerID: session.model.providerID, modelID: session.model.id }) : void 0;
24090
+ const entry = catalog.models.find((candidate) => candidate.ref.id === model?.id);
24091
+ const mode = session.permissions?.findLast((rule) => rule.action === "*" && rule.resource === "*");
24092
+ return {
24093
+ nativeRef: v2Ref(session, policy),
24094
+ ...model ? { effectiveModel: model } : {},
24095
+ ...entry ? {
24096
+ resolvedModelLabel: entry.resolvedModelLabel ?? entry.label,
24097
+ availableThinkingOptions: catalog.thinkingOptions.filter((v) => entry.supportedThinkingOptionIds?.includes(v.id)),
24098
+ effectiveThinkingOptionId: encodeOpenCodeVariant(session.model?.variant)
24099
+ } : {},
24100
+ effectivePermissionModeId: decodeMode(mode?.effect)
24101
+ };
24102
+ }
24103
+ function decodeMode(effect) {
24104
+ return effect === "allow" || effect === "ask" ? harnessPermissionModeIdSchema.parse(effect) : harnessPermissionModeIdSchema.parse("default");
24105
+ }
24106
+ function v2Usage(session) {
24107
+ const tokens = session.tokens;
24108
+ return parseHostUsage({
24109
+ inputTokens: tokens.input,
24110
+ outputTokens: tokens.output,
24111
+ reasoningOutputTokens: tokens.reasoning,
24112
+ cachedInputTokens: tokens.cache.read,
24113
+ cacheWriteInputTokens: tokens.cache.write,
24114
+ totalCostUsd: session.cost
24115
+ });
24116
+ }
24117
+
24118
+ // dist/v2/catalog.js
24119
+ async function readCatalog(client2, cwd, timeoutMs) {
24120
+ const location = { directory: cwd };
24121
+ const deadline = Date.now() + timeoutMs;
24122
+ const required2 = ["opencode.config.provider", "opencode.config.agent", "opencode.config.policy"];
24123
+ while (true) {
24124
+ const { data: plugins } = await client2.plugin.list({ location });
24125
+ const config2 = required2.map((id) => plugins.find((plugin) => plugin.id === id));
24126
+ const failed = config2.find((plugin) => plugin?.state.status === "failed");
24127
+ if (failed?.state.status === "failed")
24128
+ throw new Error(`OpenCode configuration failed: ${failed.state.error}`);
24129
+ if (config2.every((plugin) => plugin?.state.status === "active"))
24130
+ break;
24131
+ if (Date.now() >= deadline)
24132
+ throw new Error("OpenCode v2 configuration plugins did not become ready");
24133
+ await new Promise((resolve) => setTimeout(resolve, 50));
24134
+ }
24135
+ const [models, selected] = await Promise.all([
24136
+ client2.model.list({ location }),
24137
+ client2.model.default({ location })
24138
+ ]);
24139
+ return v2Catalog(models.data, selected.data);
24140
+ }
24141
+
24142
+ // dist/v2/connection.js
24143
+ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
24144
+ import { randomBytes as randomBytes2 } from "node:crypto";
24145
+
24146
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-9rqn6x4v.js
24147
+ var __defProp2 = Object.defineProperty;
24148
+ var __returnValue = (v) => v;
24149
+ function __exportSetter(name, newValue) {
24150
+ this[name] = __returnValue.bind(null, newValue);
24151
+ }
24152
+ var __export2 = (target, all) => {
24153
+ for (var name in all)
24154
+ __defProp2(target, name, {
24155
+ get: all[name],
24156
+ enumerable: true,
24157
+ configurable: true,
24158
+ set: __exportSetter.bind(all, name)
24159
+ });
24160
+ };
24161
+
24162
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-frbwqjmf.js
24163
+ var exports_shared_events = {};
24164
+ __export2(exports_shared_events, {
24165
+ SharedEvents: () => exports_shared_events,
24166
+ make: () => make7
24167
+ });
24168
+ function make7(connect) {
24169
+ let current;
24170
+ const capacity = 4096;
24171
+ function stop(connection) {
24172
+ connection.connected = void 0;
24173
+ connection.controller.abort();
24174
+ if (current === connection)
24175
+ current = void 0;
24176
+ }
24177
+ async function run(connection) {
24178
+ let iterator;
24179
+ let completion = {};
24180
+ try {
24181
+ if (connection.controller.signal.aborted)
24182
+ return;
24183
+ iterator = connect(connection.controller.signal, () => {
24184
+ connection.subscribers.forEach((subscriber) => subscriber.activity?.());
24185
+ })[Symbol.asyncIterator]();
24186
+ while (!connection.controller.signal.aborted) {
24187
+ const item = await iterator.next();
24188
+ if (item.done || connection.controller.signal.aborted)
24189
+ break;
24190
+ if (item.value.type === "server.connected")
24191
+ connection.connected = item.value;
24192
+ connection.subscribers.forEach((subscriber) => subscriber.push(item.value));
24193
+ }
24194
+ } catch (error51) {
24195
+ completion = { error: error51 };
24196
+ } finally {
24197
+ stop(connection);
24198
+ try {
24199
+ await iterator?.return?.();
24200
+ } catch (error51) {
24201
+ if (!("error" in completion))
24202
+ completion = { error: error51 };
24203
+ }
24204
+ connection.subscribers.forEach((subscriber) => subscriber.finish(completion));
24205
+ }
24206
+ }
24207
+ return {
24208
+ subscribe(options) {
24209
+ return {
24210
+ [Symbol.asyncIterator]() {
24211
+ const pending = [];
24212
+ const queued = [];
24213
+ let started = false;
24214
+ let completion;
24215
+ let connection;
24216
+ function finish(result, discard = true) {
24217
+ completion = result;
24218
+ if (discard)
24219
+ queued.length = 0;
24220
+ options?.signal?.removeEventListener("abort", abort);
24221
+ if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
24222
+ stop(connection);
24223
+ pending.splice(0).forEach((request) => {
24224
+ if ("error" in result)
24225
+ request.reject(result.error);
24226
+ else
24227
+ request.resolve({ done: true, value: void 0 });
24228
+ });
24229
+ }
24230
+ function abort() {
24231
+ finish({});
24232
+ }
24233
+ const subscriber = {
24234
+ activity: options?.onActivity,
24235
+ finish(result) {
24236
+ finish(result, false);
24237
+ },
24238
+ push(value) {
24239
+ if (completion)
24240
+ return;
24241
+ const request = pending.shift();
24242
+ if (request) {
24243
+ request.resolve({ done: false, value });
24244
+ return;
24245
+ }
24246
+ if (queued.length === capacity) {
24247
+ finish({ error: new Error(`Event subscriber exceeded its ${capacity}-event capacity`) });
24248
+ return;
24249
+ }
24250
+ queued.push(value);
24251
+ }
24252
+ };
24253
+ function start() {
24254
+ if (completion)
24255
+ return;
24256
+ const fresh = !current;
24257
+ connection = current ?? {
24258
+ controller: new AbortController(),
24259
+ subscribers: /* @__PURE__ */ new Set()
24260
+ };
24261
+ current = connection;
24262
+ connection.subscribers.add(subscriber);
24263
+ if (connection.connected)
24264
+ subscriber.push(connection.connected);
24265
+ if (fresh)
24266
+ run(connection);
24267
+ }
24268
+ return {
24269
+ next() {
24270
+ const value = queued.shift();
24271
+ if (value)
24272
+ return Promise.resolve({ done: false, value });
24273
+ if (completion) {
24274
+ if ("error" in completion)
24275
+ return Promise.reject(completion.error);
24276
+ return Promise.resolve({ done: true, value: void 0 });
24277
+ }
24278
+ if (options?.signal?.aborted) {
24279
+ abort();
24280
+ return Promise.resolve({ done: true, value: void 0 });
24281
+ }
24282
+ const request = Promise.withResolvers();
24283
+ pending.push(request);
24284
+ if (!started) {
24285
+ started = true;
24286
+ options?.signal?.addEventListener("abort", abort, { once: true });
24287
+ start();
24288
+ }
24289
+ return request.promise;
24290
+ },
24291
+ return() {
24292
+ finish({});
24293
+ return Promise.resolve({ done: true, value: void 0 });
24294
+ }
24295
+ };
24296
+ }
24297
+ };
24298
+ }
24299
+ };
24300
+ }
24301
+
24302
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-nwcpakzx.js
24303
+ var ClientError3 = class extends Error {
24304
+ reason;
24305
+ name = "ClientError";
24306
+ constructor(reason, options) {
24307
+ const detail = options?.detail ?? (options?.cause instanceof Error ? options.cause.message : void 0);
24308
+ super(detail ? `${reason}: ${detail}` : reason, options);
24309
+ this.reason = reason;
24310
+ }
24311
+ };
24312
+
24313
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-bpdjd9xk.js
24314
+ var exports_client4 = {};
24315
+ __export2(exports_client4, {
24316
+ make: () => make6
24317
+ });
24318
+ var maxSseEventBytes = 16 * 1024 * 1024;
24319
+ function make6(options) {
24320
+ const fetch2 = options.fetch ?? globalThis.fetch;
24321
+ const prepare = (descriptor, requestOptions) => {
24322
+ const baseUrl = new URL(options.baseUrl);
24323
+ if (!baseUrl.pathname.endsWith("/"))
24324
+ baseUrl.pathname += "/";
24325
+ const url2 = new URL(descriptor.path.slice(1), baseUrl);
24326
+ for (const [key, value] of Object.entries(descriptor.query ?? {}))
24327
+ appendQuery(url2.searchParams, key, value);
24328
+ const headers = new Headers(options.headers);
24329
+ for (const [key, value] of Object.entries(descriptor.headers ?? {})) {
24330
+ if (value !== void 0 && value !== null)
24331
+ headers.set(key, String(value));
24332
+ }
24333
+ for (const [key, value] of new Headers(requestOptions?.headers))
24334
+ headers.set(key, value);
24335
+ if (descriptor.body !== void 0 && !headers.has("content-type"))
24336
+ headers.set("content-type", descriptor.binaryBody ? "application/octet-stream" : "application/json");
24337
+ return {
24338
+ url: url2,
24339
+ init: {
24340
+ method: descriptor.method,
24341
+ signal: requestOptions?.signal,
24342
+ headers,
24343
+ body: descriptor.body === void 0 ? void 0 : descriptor.binaryBody ? descriptor.body : JSON.stringify(descriptor.body)
24344
+ }
24345
+ };
24346
+ };
24347
+ const execute = async (descriptor, requestOptions) => {
24348
+ try {
24349
+ const prepared = prepare(descriptor, requestOptions);
24350
+ return await fetch2(prepared.url, prepared.init);
24351
+ } catch (cause) {
24352
+ throw new ClientError3("Transport", { cause });
24353
+ }
24354
+ };
24355
+ const responseError = async (response, descriptor) => {
24356
+ if (descriptor.declaredStatuses.includes(response.status))
24357
+ throw declared(await json2(response));
24358
+ try {
24359
+ await response.body?.cancel();
24360
+ } catch {
24361
+ }
24362
+ throw new ClientError3("UnexpectedStatus", { cause: { status: response.status }, detail: String(response.status) });
24363
+ };
24364
+ const request = async (descriptor, requestOptions) => {
24365
+ const response = await execute(descriptor, requestOptions);
24366
+ if (response.status !== descriptor.successStatus)
24367
+ return responseError(response, descriptor);
24368
+ if (descriptor.binary)
24369
+ return new Uint8Array(await response.arrayBuffer());
24370
+ if (descriptor.empty) {
24371
+ try {
24372
+ await response.body?.cancel();
24373
+ } catch {
24374
+ }
24375
+ return;
24376
+ }
24377
+ return await json2(response);
24378
+ };
24379
+ const sse = (descriptor, requestOptions) => ({
24380
+ async *[Symbol.asyncIterator]() {
24381
+ const response = await execute(descriptor, requestOptions);
24382
+ if (response.status !== descriptor.successStatus)
24383
+ await responseError(response, descriptor);
24384
+ if (!isContentType(response, "text/event-stream")) {
24385
+ try {
24386
+ await response.body?.cancel();
24387
+ } catch {
24388
+ }
24389
+ throw new ClientError3("UnsupportedContentType", { detail: response.headers.get("content-type") });
24390
+ }
24391
+ if (response.body === null)
24392
+ throw new ClientError3("MalformedResponse");
24393
+ const reader = response.body.getReader();
24394
+ const decoder = new TextDecoder();
24395
+ let buffer = "";
24396
+ try {
24397
+ while (true) {
24398
+ let next;
24399
+ try {
24400
+ next = await reader.read();
24401
+ } catch (cause) {
24402
+ throw new ClientError3("Transport", { cause });
24403
+ }
24404
+ if (!next.done)
24405
+ requestOptions?.onActivity?.();
24406
+ buffer += decoder.decode(next.value, { stream: !next.done });
24407
+ if (buffer.length > maxSseEventBytes)
24408
+ throw new ClientError3("SseEventTooLarge");
24409
+ const trailingCarriageReturn = !next.done && buffer.endsWith("\r");
24410
+ if (trailingCarriageReturn)
24411
+ buffer = buffer.slice(0, -1);
24412
+ buffer = buffer.replaceAll(`\r
24413
+ `, `
24414
+ `).replaceAll("\r", `
24415
+ `);
24416
+ if (trailingCarriageReturn)
24417
+ buffer += "\r";
24418
+ if (next.done && buffer !== "")
24419
+ buffer += `
24420
+
24421
+ `;
24422
+ let boundary = buffer.indexOf(`
24423
+
24424
+ `);
24425
+ while (boundary >= 0) {
24426
+ const block = buffer.slice(0, boundary);
24427
+ buffer = buffer.slice(boundary + 2);
24428
+ const data = block.split(`
24429
+ `).flatMap((line) => line.startsWith("data:") ? [line.slice(5).trimStart()] : []).join(`
24430
+ `);
24431
+ if (data !== "") {
24432
+ try {
24433
+ yield JSON.parse(data);
24434
+ } catch (cause) {
24435
+ throw new ClientError3("MalformedResponse", { cause });
24436
+ }
24437
+ }
24438
+ boundary = buffer.indexOf(`
24439
+
24440
+ `);
24441
+ }
24442
+ if (next.done)
24443
+ return;
24444
+ }
24445
+ } finally {
24446
+ try {
24447
+ await reader.cancel();
24448
+ } catch {
24449
+ }
24450
+ reader.releaseLock();
24451
+ }
24452
+ }
24453
+ });
24454
+ return {
24455
+ server: {
24456
+ info: (requestOptions) => request({ method: "GET", path: `/api/info`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions)
24457
+ },
24458
+ location: {
24459
+ get: (input, requestOptions) => request({
24460
+ method: "GET",
24461
+ path: `/api/location`,
24462
+ query: { location: input?.["location"] },
24463
+ successStatus: 200,
24464
+ declaredStatuses: [400, 401],
24465
+ empty: false
24466
+ }, requestOptions),
24467
+ reload: (requestOptions) => request({
24468
+ method: "POST",
24469
+ path: `/api/location/reload`,
24470
+ successStatus: 204,
24471
+ declaredStatuses: [400, 401, 503],
24472
+ empty: true
24473
+ }, requestOptions)
24474
+ },
24475
+ agent: {
24476
+ list: (input, requestOptions) => request({
24477
+ method: "GET",
24478
+ path: `/api/agent`,
24479
+ query: { location: input?.["location"] },
24480
+ successStatus: 200,
24481
+ declaredStatuses: [400, 401],
24482
+ empty: false
24483
+ }, requestOptions),
24484
+ get: (input, requestOptions) => request({
24485
+ method: "GET",
24486
+ path: `/api/agent/${encodeURIComponent(input.agentID)}`,
24487
+ query: { location: input["location"] },
24488
+ successStatus: 200,
24489
+ declaredStatuses: [400, 401, 404],
24490
+ empty: false
24491
+ }, requestOptions)
24492
+ },
24493
+ plugin: {
24494
+ list: (input, requestOptions) => request({
24495
+ method: "GET",
24496
+ path: `/api/plugin`,
24497
+ query: { location: input?.["location"] },
24498
+ successStatus: 200,
24499
+ declaredStatuses: [400, 401],
24500
+ empty: false
24501
+ }, requestOptions),
24502
+ check: (input, requestOptions) => request({
24503
+ method: "POST",
24504
+ path: `/api/plugin/check`,
24505
+ query: { location: input?.["location"] },
24506
+ body: { target: input?.["target"] },
24507
+ successStatus: 200,
24508
+ declaredStatuses: [400, 401],
24509
+ empty: false
24510
+ }, requestOptions),
24511
+ update: (input, requestOptions) => request({
24512
+ method: "POST",
24513
+ path: `/api/plugin/update`,
24514
+ query: { location: input["location"] },
24515
+ body: { targets: input["targets"] },
24516
+ successStatus: 204,
24517
+ declaredStatuses: [400, 401, 503],
24518
+ empty: true
24519
+ }, requestOptions)
24520
+ },
24521
+ session: {
24522
+ list: (input, requestOptions) => request({
24523
+ method: "GET",
24524
+ path: `/api/session`,
24525
+ query: {
24526
+ limit: input?.["limit"],
24527
+ order: input?.["order"],
24528
+ search: input?.["search"],
24529
+ parentID: input?.["parentID"],
24530
+ directory: input?.["directory"],
24531
+ project: input?.["project"],
24532
+ subpath: input?.["subpath"],
24533
+ cursor: input?.["cursor"]
24534
+ },
24535
+ successStatus: 200,
24536
+ declaredStatuses: [400, 401],
24537
+ empty: false
24538
+ }, requestOptions),
24539
+ stats: (input, requestOptions) => request({
24540
+ method: "GET",
24541
+ path: `/api/experimental/session/stats`,
24542
+ query: {
24543
+ from: input?.["from"],
24544
+ to: input?.["to"],
24545
+ project: input?.["project"],
24546
+ timezone: input?.["timezone"],
24547
+ tools: input?.["tools"]
24548
+ },
24549
+ successStatus: 200,
24550
+ declaredStatuses: [400, 401],
24551
+ empty: false
24552
+ }, requestOptions).then((value) => value.data),
24553
+ create: (input, requestOptions) => request({
24554
+ method: "POST",
24555
+ path: `/api/session`,
24556
+ body: {
24557
+ id: input?.["id"],
24558
+ title: input?.["title"],
24559
+ agent: input?.["agent"],
24560
+ model: input?.["model"],
24561
+ location: input?.["location"],
24562
+ metadata: input?.["metadata"],
24563
+ permissions: input?.["permissions"]
24564
+ },
24565
+ successStatus: 200,
24566
+ declaredStatuses: [400, 401],
24567
+ empty: false
24568
+ }, requestOptions).then((value) => value.data),
24569
+ import: (input, requestOptions) => request({
24570
+ method: "POST",
24571
+ path: `/api/experimental/session/import`,
24572
+ body: { info: input["info"], messages: input["messages"], location: input["location"] },
24573
+ successStatus: 200,
24574
+ declaredStatuses: [400, 401, 404, 409],
24575
+ empty: false
24576
+ }, requestOptions).then((value) => value.data),
24577
+ export: (input, requestOptions) => request({
24578
+ method: "GET",
24579
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/export`,
24580
+ query: { sanitize: input["sanitize"] },
24581
+ successStatus: 200,
24582
+ declaredStatuses: [400, 401, 404, 500],
24583
+ empty: false
24584
+ }, requestOptions).then((value) => value.data),
24585
+ active: (requestOptions) => request({
24586
+ method: "GET",
24587
+ path: `/api/session/active`,
24588
+ successStatus: 200,
24589
+ declaredStatuses: [400, 401],
24590
+ empty: false
24591
+ }, requestOptions).then((value) => value.data),
24592
+ get: (input, requestOptions) => request({
24593
+ method: "GET",
24594
+ path: `/api/session/${encodeURIComponent(input.sessionID)}`,
24595
+ successStatus: 200,
24596
+ declaredStatuses: [400, 401, 404],
24597
+ empty: false
24598
+ }, requestOptions).then((value) => value.data),
24599
+ remove: (input, requestOptions) => request({
24600
+ method: "DELETE",
24601
+ path: `/api/session/${encodeURIComponent(input.sessionID)}`,
24602
+ successStatus: 204,
24603
+ declaredStatuses: [400, 401, 404],
24604
+ empty: true
24605
+ }, requestOptions),
24606
+ fork: (input, requestOptions) => request({
24607
+ method: "POST",
24608
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/fork`,
24609
+ body: { before: input["before"] },
24610
+ successStatus: 200,
24611
+ declaredStatuses: [400, 401, 404],
24612
+ empty: false
24613
+ }, requestOptions).then((value) => value.data),
24614
+ switchAgent: (input, requestOptions) => request({
24615
+ method: "POST",
24616
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/agent`,
24617
+ body: { agent: input["agent"] },
24618
+ successStatus: 204,
24619
+ declaredStatuses: [400, 401, 404],
24620
+ empty: true
24621
+ }, requestOptions),
24622
+ switchModel: (input, requestOptions) => request({
24623
+ method: "POST",
24624
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/model`,
24625
+ body: { model: input["model"] },
24626
+ successStatus: 204,
24627
+ declaredStatuses: [400, 401, 404],
24628
+ empty: true
24629
+ }, requestOptions),
24630
+ update: (input, requestOptions) => request({
24631
+ method: "PATCH",
24632
+ path: `/api/session/${encodeURIComponent(input.sessionID)}`,
24633
+ body: { title: input["title"], metadata: input["metadata"], permissions: input["permissions"] },
24634
+ successStatus: 204,
24635
+ declaredStatuses: [400, 401, 404],
24636
+ empty: true
24637
+ }, requestOptions),
24638
+ move: (input, requestOptions) => request({
24639
+ method: "POST",
24640
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/move`,
24641
+ body: { directory: input["directory"], delivery: input["delivery"] },
24642
+ successStatus: 204,
24643
+ declaredStatuses: [400, 401, 404],
24644
+ empty: true
24645
+ }, requestOptions),
24646
+ prompt: (input, requestOptions) => request({
24647
+ method: "POST",
24648
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/prompt`,
24649
+ body: {
24650
+ id: input["id"],
24651
+ text: input["text"],
24652
+ files: input["files"],
24653
+ agents: input["agents"],
24654
+ skills: input["skills"],
24655
+ metadata: input["metadata"],
24656
+ delivery: input["delivery"],
24657
+ resume: input["resume"]
24658
+ },
24659
+ successStatus: 200,
24660
+ declaredStatuses: [400, 401, 404, 409],
24661
+ empty: false
24662
+ }, requestOptions).then((value) => value.data),
24663
+ command: (input, requestOptions) => request({
24664
+ method: "POST",
24665
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/command`,
24666
+ body: {
24667
+ name: input["name"],
24668
+ text: input["text"],
24669
+ files: input["files"],
24670
+ agents: input["agents"],
24671
+ skills: input["skills"],
24672
+ delivery: input["delivery"]
24673
+ },
24674
+ successStatus: 204,
24675
+ declaredStatuses: [400, 401, 404, 500],
24676
+ empty: true
24677
+ }, requestOptions),
24678
+ skill: (input, requestOptions) => request({
24679
+ method: "POST",
24680
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/skill`,
24681
+ body: { id: input["id"], resume: input["resume"] },
24682
+ successStatus: 204,
24683
+ declaredStatuses: [400, 401, 404],
24684
+ empty: true
24685
+ }, requestOptions),
24686
+ synthetic: (input, requestOptions) => request({
24687
+ method: "POST",
24688
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/synthetic`,
24689
+ body: {
24690
+ id: input["id"],
24691
+ text: input["text"],
24692
+ description: input["description"],
24693
+ metadata: input["metadata"],
24694
+ delivery: input["delivery"],
24695
+ resume: input["resume"]
24696
+ },
24697
+ successStatus: 200,
24698
+ declaredStatuses: [400, 401, 404, 409],
24699
+ empty: false
24700
+ }, requestOptions).then((value) => value.data),
24701
+ shell: (input, requestOptions) => request({
24702
+ method: "POST",
24703
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/shell`,
24704
+ body: { id: input["id"], command: input["command"] },
24705
+ successStatus: 204,
24706
+ declaredStatuses: [400, 401, 404],
24707
+ empty: true
24708
+ }, requestOptions),
24709
+ compact: (input, requestOptions) => request({
24710
+ method: "POST",
24711
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/compact`,
24712
+ body: { id: input["id"], delivery: input["delivery"] },
24713
+ successStatus: 200,
24714
+ declaredStatuses: [400, 401, 404, 409],
24715
+ empty: false
24716
+ }, requestOptions).then((value) => value.data),
24717
+ wait: (input, requestOptions) => request({
24718
+ method: "POST",
24719
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/wait`,
24720
+ successStatus: 204,
24721
+ declaredStatuses: [400, 401, 404, 503],
24722
+ empty: true
24723
+ }, requestOptions),
24724
+ revert: {
24725
+ stage: (input, requestOptions) => request({
24726
+ method: "POST",
24727
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/revert/stage`,
24728
+ body: { messageID: input["messageID"], files: input["files"] },
24729
+ successStatus: 200,
24730
+ declaredStatuses: [400, 401, 404, 409, 500],
24731
+ empty: false
24732
+ }, requestOptions).then((value) => value.data),
24733
+ clear: (input, requestOptions) => request({
24734
+ method: "DELETE",
24735
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/revert`,
24736
+ successStatus: 204,
24737
+ declaredStatuses: [400, 401, 404, 409, 500],
24738
+ empty: true
24739
+ }, requestOptions),
24740
+ commit: (input, requestOptions) => request({
24741
+ method: "POST",
24742
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/revert/commit`,
24743
+ successStatus: 204,
24744
+ declaredStatuses: [400, 401, 404, 409],
24745
+ empty: true
24746
+ }, requestOptions)
24747
+ },
24748
+ context: (input, requestOptions) => request({
24749
+ method: "GET",
24750
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/context`,
24751
+ successStatus: 200,
24752
+ declaredStatuses: [400, 401, 404, 500],
24753
+ empty: false
24754
+ }, requestOptions).then((value) => value.data),
24755
+ diff: (input, requestOptions) => request({
24756
+ method: "GET",
24757
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/diff`,
24758
+ query: { from: input["from"], to: input["to"], context: input["context"] },
24759
+ successStatus: 200,
24760
+ declaredStatuses: [400, 401, 404, 500],
24761
+ empty: false
24762
+ }, requestOptions).then((value) => value.data),
24763
+ inbox: {
24764
+ list: (input, requestOptions) => request({
24765
+ method: "GET",
24766
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/inbox`,
24767
+ successStatus: 200,
24768
+ declaredStatuses: [400, 401, 404],
24769
+ empty: false
24770
+ }, requestOptions).then((value) => value.data),
24771
+ cancel: (input, requestOptions) => request({
24772
+ method: "DELETE",
24773
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/inbox/${encodeURIComponent(input.inboxID)}`,
24774
+ successStatus: 204,
24775
+ declaredStatuses: [400, 401, 404],
24776
+ empty: true
24777
+ }, requestOptions),
24778
+ update: (input, requestOptions) => request({
24779
+ method: "PATCH",
24780
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/inbox/${encodeURIComponent(input.inboxID)}`,
24781
+ body: { delivery: input["delivery"] },
24782
+ successStatus: 204,
24783
+ declaredStatuses: [400, 401, 404, 409],
24784
+ empty: true
24785
+ }, requestOptions)
24786
+ },
24787
+ instructions: {
24788
+ entry: {
24789
+ list: (input, requestOptions) => request({
24790
+ method: "GET",
24791
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries`,
24792
+ successStatus: 200,
24793
+ declaredStatuses: [400, 401, 404],
24794
+ empty: false
24795
+ }, requestOptions).then((value) => value.data),
24796
+ put: (input, requestOptions) => request({
24797
+ method: "PUT",
24798
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`,
24799
+ body: { value: input["value"] },
24800
+ successStatus: 204,
24801
+ declaredStatuses: [400, 401, 404, 413],
24802
+ empty: true
24803
+ }, requestOptions),
24804
+ remove: (input, requestOptions) => request({
24805
+ method: "DELETE",
24806
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`,
24807
+ successStatus: 204,
24808
+ declaredStatuses: [400, 401, 404],
24809
+ empty: true
24810
+ }, requestOptions)
24811
+ }
24812
+ },
24813
+ generate: (input, requestOptions) => request({
24814
+ method: "POST",
24815
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/generate`,
24816
+ body: { prompt: input["prompt"] },
24817
+ successStatus: 200,
24818
+ declaredStatuses: [400, 401, 404, 503],
24819
+ empty: false
24820
+ }, requestOptions).then((value) => value.data),
24821
+ log: (input, requestOptions) => sse({
24822
+ method: "GET",
24823
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/log`,
24824
+ query: { after: input["after"], follow: input["follow"] },
24825
+ successStatus: 200,
24826
+ declaredStatuses: [400, 401, 404],
24827
+ empty: false
24828
+ }, requestOptions),
24829
+ interrupt: (input, requestOptions) => request({
24830
+ method: "POST",
24831
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/interrupt`,
24832
+ query: { resume: input["resume"] },
24833
+ successStatus: 200,
24834
+ declaredStatuses: [400, 401, 404],
24835
+ empty: false
24836
+ }, requestOptions),
24837
+ background: (input, requestOptions) => request({
24838
+ method: "POST",
24839
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/background`,
24840
+ successStatus: 204,
24841
+ declaredStatuses: [400, 401, 404],
24842
+ empty: true
24843
+ }, requestOptions),
24844
+ message: {
24845
+ get: (input, requestOptions) => request({
24846
+ method: "GET",
24847
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/message/${encodeURIComponent(input.messageID)}`,
24848
+ successStatus: 200,
24849
+ declaredStatuses: [400, 401, 404],
24850
+ empty: false
24851
+ }, requestOptions).then((value) => value.data)
24852
+ },
24853
+ form: {
24854
+ list: (input, requestOptions) => request({
24855
+ method: "GET",
24856
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form`,
24857
+ successStatus: 200,
24858
+ declaredStatuses: [400, 401, 404],
24859
+ empty: false
24860
+ }, requestOptions).then((value) => value.data),
24861
+ create: (input, requestOptions) => request({
24862
+ method: "POST",
24863
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form`,
24864
+ body: { id: input["id"], title: input["title"], metadata: input["metadata"], fields: input["fields"] },
24865
+ successStatus: 200,
24866
+ declaredStatuses: [400, 401, 404, 409],
24867
+ empty: false
24868
+ }, requestOptions).then((value) => value.data),
24869
+ get: (input, requestOptions) => request({
24870
+ method: "GET",
24871
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form/${encodeURIComponent(input.formID)}`,
24872
+ successStatus: 200,
24873
+ declaredStatuses: [400, 401, 404],
24874
+ empty: false
24875
+ }, requestOptions).then((value) => value.data),
24876
+ reply: (input, requestOptions) => request({
24877
+ method: "POST",
24878
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form/${encodeURIComponent(input.formID)}/reply`,
24879
+ body: { answer: input["answer"] },
24880
+ successStatus: 204,
24881
+ declaredStatuses: [400, 401, 404, 409],
24882
+ empty: true
24883
+ }, requestOptions),
24884
+ cancel: (input, requestOptions) => request({
24885
+ method: "DELETE",
24886
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form/${encodeURIComponent(input.formID)}`,
24887
+ successStatus: 204,
24888
+ declaredStatuses: [400, 401, 404, 409],
24889
+ empty: true
24890
+ }, requestOptions)
24891
+ },
24892
+ environment: (input, requestOptions) => request({
24893
+ method: "PUT",
24894
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/environment`,
24895
+ body: { variables: input["variables"] },
24896
+ successStatus: 204,
24897
+ declaredStatuses: [400, 401, 404],
24898
+ empty: true
24899
+ }, requestOptions),
24900
+ view: (input, requestOptions) => request({
24901
+ method: "POST",
24902
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/view`,
24903
+ body: { idle: input["idle"] },
24904
+ successStatus: 204,
24905
+ declaredStatuses: [400, 401, 404],
24906
+ empty: true
24907
+ }, requestOptions)
24908
+ },
24909
+ message: {
24910
+ list: (input, requestOptions) => request({
24911
+ method: "GET",
24912
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/message`,
24913
+ query: { limit: input["limit"], order: input["order"], cursor: input["cursor"], type: input["type"] },
24914
+ successStatus: 200,
24915
+ declaredStatuses: [400, 401, 404, 500],
24916
+ empty: false
24917
+ }, requestOptions)
24918
+ },
24919
+ model: {
24920
+ list: (input, requestOptions) => request({
24921
+ method: "GET",
24922
+ path: `/api/model`,
24923
+ query: { location: input?.["location"] },
24924
+ successStatus: 200,
24925
+ declaredStatuses: [400, 401, 503],
24926
+ empty: false
24927
+ }, requestOptions),
24928
+ default: (input, requestOptions) => request({
24929
+ method: "GET",
24930
+ path: `/api/model/default`,
24931
+ query: { location: input?.["location"] },
24932
+ successStatus: 200,
24933
+ declaredStatuses: [400, 401, 503],
24934
+ empty: false
24935
+ }, requestOptions)
24936
+ },
24937
+ generate: {
24938
+ text: (input, requestOptions) => request({
24939
+ method: "POST",
24940
+ path: `/api/experimental/generate`,
24941
+ body: { prompt: input["prompt"], model: input["model"] },
24942
+ successStatus: 200,
24943
+ declaredStatuses: [400, 401, 503],
24944
+ empty: false
24945
+ }, requestOptions).then((value) => value.data)
24946
+ },
24947
+ provider: {
24948
+ list: (input, requestOptions) => request({
24949
+ method: "GET",
24950
+ path: `/api/provider`,
24951
+ query: { location: input?.["location"] },
24952
+ successStatus: 200,
24953
+ declaredStatuses: [400, 401, 503],
24954
+ empty: false
24955
+ }, requestOptions),
24956
+ get: (input, requestOptions) => request({
24957
+ method: "GET",
24958
+ path: `/api/provider/${encodeURIComponent(input.providerID)}`,
24959
+ query: { location: input["location"] },
24960
+ successStatus: 200,
24961
+ declaredStatuses: [400, 401, 404, 503],
24962
+ empty: false
24963
+ }, requestOptions)
24964
+ },
24965
+ integration: {
24966
+ list: (input, requestOptions) => request({
24967
+ method: "GET",
24968
+ path: `/api/integration`,
24969
+ query: { location: input?.["location"] },
24970
+ successStatus: 200,
24971
+ declaredStatuses: [400, 401],
24972
+ empty: false
24973
+ }, requestOptions),
24974
+ get: (input, requestOptions) => request({
24975
+ method: "GET",
24976
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}`,
24977
+ query: { location: input["location"] },
24978
+ successStatus: 200,
24979
+ declaredStatuses: [400, 401, 404],
24980
+ empty: false
24981
+ }, requestOptions),
24982
+ wellknown: {
24983
+ add: (input, requestOptions) => request({
24984
+ method: "POST",
24985
+ path: `/api/experimental/integration/wellknown`,
24986
+ query: { location: input["location"] },
24987
+ body: { url: input["url"] },
24988
+ successStatus: 204,
24989
+ declaredStatuses: [400, 401],
24990
+ empty: true
24991
+ }, requestOptions)
24992
+ },
24993
+ connect: {
24994
+ key: (input, requestOptions) => request({
24995
+ method: "POST",
24996
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/key`,
24997
+ query: { location: input["location"] },
24998
+ body: { key: input["key"], answer: input["answer"], label: input["label"] },
24999
+ successStatus: 204,
25000
+ declaredStatuses: [400, 401, 404],
25001
+ empty: true
25002
+ }, requestOptions)
25003
+ },
25004
+ oauth: {
25005
+ connect: (input, requestOptions) => request({
25006
+ method: "POST",
25007
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth`,
25008
+ query: { location: input["location"] },
25009
+ body: { methodID: input["methodID"], answer: input["answer"], label: input["label"] },
25010
+ successStatus: 200,
25011
+ declaredStatuses: [400, 401],
25012
+ empty: false
25013
+ }, requestOptions),
25014
+ status: (input, requestOptions) => request({
25015
+ method: "GET",
25016
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth/${encodeURIComponent(input.attemptID)}`,
25017
+ query: { location: input["location"] },
25018
+ successStatus: 200,
25019
+ declaredStatuses: [400, 401, 404],
25020
+ empty: false
25021
+ }, requestOptions),
25022
+ complete: (input, requestOptions) => request({
25023
+ method: "POST",
25024
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth/${encodeURIComponent(input.attemptID)}/complete`,
25025
+ query: { location: input["location"] },
25026
+ body: { code: input["code"] },
25027
+ successStatus: 204,
25028
+ declaredStatuses: [400, 401, 404],
25029
+ empty: true
25030
+ }, requestOptions),
25031
+ cancel: (input, requestOptions) => request({
25032
+ method: "DELETE",
25033
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth/${encodeURIComponent(input.attemptID)}`,
25034
+ query: { location: input["location"] },
25035
+ successStatus: 204,
25036
+ declaredStatuses: [400, 401],
25037
+ empty: true
25038
+ }, requestOptions)
25039
+ },
25040
+ command: {
25041
+ connect: (input, requestOptions) => request({
25042
+ method: "POST",
25043
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/command`,
25044
+ query: { location: input["location"] },
25045
+ body: { methodID: input["methodID"], label: input["label"] },
25046
+ successStatus: 200,
25047
+ declaredStatuses: [400, 401, 404],
25048
+ empty: false
25049
+ }, requestOptions),
25050
+ status: (input, requestOptions) => request({
25051
+ method: "GET",
25052
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/command/${encodeURIComponent(input.attemptID)}`,
25053
+ query: { location: input["location"] },
25054
+ successStatus: 200,
25055
+ declaredStatuses: [400, 401, 404],
25056
+ empty: false
25057
+ }, requestOptions),
25058
+ cancel: (input, requestOptions) => request({
25059
+ method: "DELETE",
25060
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/command/${encodeURIComponent(input.attemptID)}`,
25061
+ query: { location: input["location"] },
25062
+ successStatus: 204,
25063
+ declaredStatuses: [400, 401],
25064
+ empty: true
25065
+ }, requestOptions)
25066
+ }
25067
+ },
25068
+ mcp: {
25069
+ list: (input, requestOptions) => request({
25070
+ method: "GET",
25071
+ path: `/api/mcp`,
25072
+ query: { location: input?.["location"] },
25073
+ successStatus: 200,
25074
+ declaredStatuses: [400, 401],
25075
+ empty: false
25076
+ }, requestOptions),
25077
+ add: (input, requestOptions) => request({
25078
+ method: "PUT",
25079
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`,
25080
+ query: { location: input["location"] },
25081
+ body: { config: input["config"] },
25082
+ successStatus: 204,
25083
+ declaredStatuses: [400, 401],
25084
+ empty: true
25085
+ }, requestOptions),
25086
+ remove: (input, requestOptions) => request({
25087
+ method: "DELETE",
25088
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`,
25089
+ query: { location: input["location"] },
25090
+ successStatus: 204,
25091
+ declaredStatuses: [400, 401, 404],
25092
+ empty: true
25093
+ }, requestOptions),
25094
+ connect: (input, requestOptions) => request({
25095
+ method: "POST",
25096
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/connect`,
25097
+ query: { location: input["location"] },
25098
+ successStatus: 204,
25099
+ declaredStatuses: [400, 401, 404],
25100
+ empty: true
25101
+ }, requestOptions),
25102
+ disconnect: (input, requestOptions) => request({
25103
+ method: "POST",
25104
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/disconnect`,
25105
+ query: { location: input["location"] },
25106
+ successStatus: 204,
25107
+ declaredStatuses: [400, 401, 404],
25108
+ empty: true
25109
+ }, requestOptions),
25110
+ resource: {
25111
+ catalog: (input, requestOptions) => request({
25112
+ method: "GET",
25113
+ path: `/api/mcp/resource`,
25114
+ query: { location: input?.["location"] },
25115
+ successStatus: 200,
25116
+ declaredStatuses: [400, 401],
25117
+ empty: false
25118
+ }, requestOptions)
25119
+ }
25120
+ },
25121
+ credential: {
25122
+ update: (input, requestOptions) => request({
25123
+ method: "PATCH",
25124
+ path: `/api/credential/${encodeURIComponent(input.credentialID)}`,
25125
+ body: { label: input["label"] },
25126
+ successStatus: 204,
25127
+ declaredStatuses: [400, 401],
25128
+ empty: true
25129
+ }, requestOptions),
25130
+ activate: (input, requestOptions) => request({
25131
+ method: "POST",
25132
+ path: `/api/credential/${encodeURIComponent(input.credentialID)}/activate`,
25133
+ successStatus: 204,
25134
+ declaredStatuses: [400, 401],
25135
+ empty: true
25136
+ }, requestOptions),
25137
+ remove: (input, requestOptions) => request({
25138
+ method: "DELETE",
25139
+ path: `/api/credential/${encodeURIComponent(input.credentialID)}`,
25140
+ successStatus: 204,
25141
+ declaredStatuses: [400, 401],
25142
+ empty: true
25143
+ }, requestOptions)
25144
+ },
25145
+ project: {
25146
+ list: (requestOptions) => request({ method: "GET", path: `/api/project`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions),
25147
+ update: (input, requestOptions) => request({
25148
+ method: "PATCH",
25149
+ path: `/api/project/${encodeURIComponent(input.projectID)}`,
25150
+ body: {
25151
+ canonical: input["canonical"],
25152
+ name: input["name"],
25153
+ icon: input["icon"],
25154
+ commands: input["commands"]
25155
+ },
25156
+ successStatus: 200,
25157
+ declaredStatuses: [400, 401, 404],
25158
+ empty: false
25159
+ }, requestOptions)
25160
+ },
25161
+ form: {
25162
+ list: (input, requestOptions) => request({
25163
+ method: "GET",
25164
+ path: `/api/form`,
25165
+ query: { location: input?.["location"] },
25166
+ successStatus: 200,
25167
+ declaredStatuses: [400, 401],
25168
+ empty: false
25169
+ }, requestOptions)
25170
+ },
25171
+ permission: {
25172
+ request: {
25173
+ list: (input, requestOptions) => request({
25174
+ method: "GET",
25175
+ path: `/api/permission/request`,
25176
+ query: { location: input?.["location"] },
25177
+ successStatus: 200,
25178
+ declaredStatuses: [400, 401],
25179
+ empty: false
25180
+ }, requestOptions)
25181
+ },
25182
+ saved: {
25183
+ list: (input, requestOptions) => request({
25184
+ method: "GET",
25185
+ path: `/api/permission/saved`,
25186
+ query: { projectID: input?.["projectID"] },
25187
+ successStatus: 200,
25188
+ declaredStatuses: [400, 401],
25189
+ empty: false
25190
+ }, requestOptions).then((value) => value.data),
25191
+ remove: (input, requestOptions) => request({
25192
+ method: "DELETE",
25193
+ path: `/api/permission/saved/${encodeURIComponent(input.id)}`,
25194
+ successStatus: 204,
25195
+ declaredStatuses: [400, 401],
25196
+ empty: true
25197
+ }, requestOptions)
25198
+ },
25199
+ create: (input, requestOptions) => request({
25200
+ method: "POST",
25201
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission`,
25202
+ body: {
25203
+ id: input["id"],
25204
+ action: input["action"],
25205
+ resources: input["resources"],
25206
+ save: input["save"],
25207
+ metadata: input["metadata"],
25208
+ source: input["source"],
25209
+ agent: input["agent"]
25210
+ },
25211
+ successStatus: 200,
25212
+ declaredStatuses: [400, 401, 404],
25213
+ empty: false
25214
+ }, requestOptions).then((value) => value.data),
25215
+ list: (input, requestOptions) => request({
25216
+ method: "GET",
25217
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission`,
25218
+ successStatus: 200,
25219
+ declaredStatuses: [400, 401, 404],
25220
+ empty: false
25221
+ }, requestOptions).then((value) => value.data),
25222
+ get: (input, requestOptions) => request({
25223
+ method: "GET",
25224
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission/${encodeURIComponent(input.requestID)}`,
25225
+ successStatus: 200,
25226
+ declaredStatuses: [400, 401, 404],
25227
+ empty: false
25228
+ }, requestOptions).then((value) => value.data),
25229
+ reply: (input, requestOptions) => request({
25230
+ method: "POST",
25231
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission/${encodeURIComponent(input.requestID)}/reply`,
25232
+ body: { decision: input["decision"], message: input["message"] },
25233
+ successStatus: 204,
25234
+ declaredStatuses: [400, 401, 404],
25235
+ empty: true
25236
+ }, requestOptions)
25237
+ },
25238
+ file: {
25239
+ read: (input, requestOptions) => request({
25240
+ method: "GET",
25241
+ path: `/api/fs/read/${encodePath(input.path)}`,
25242
+ query: { location: input["location"] },
25243
+ successStatus: 200,
25244
+ declaredStatuses: [400, 401, 404],
25245
+ empty: false,
25246
+ binary: true
25247
+ }, requestOptions),
25248
+ list: (input, requestOptions) => request({
25249
+ method: "GET",
25250
+ path: `/api/fs/list`,
25251
+ query: { location: input?.["location"], path: input?.["path"] },
25252
+ successStatus: 200,
25253
+ declaredStatuses: [400, 401],
25254
+ empty: false
25255
+ }, requestOptions),
25256
+ find: (input, requestOptions) => request({
25257
+ method: "GET",
25258
+ path: `/api/fs/find`,
25259
+ query: { location: input["location"], query: input["query"], type: input["type"], limit: input["limit"] },
25260
+ successStatus: 200,
25261
+ declaredStatuses: [400, 401],
25262
+ empty: false
25263
+ }, requestOptions),
25264
+ write: (input, requestOptions) => request({
25265
+ method: "POST",
25266
+ path: `/api/experimental/fs/write`,
25267
+ query: { location: input["location"], path: input["path"] },
25268
+ body: input["payload"],
25269
+ successStatus: 200,
25270
+ declaredStatuses: [400, 401],
25271
+ empty: false,
25272
+ binaryBody: true
25273
+ }, requestOptions)
25274
+ },
25275
+ command: {
25276
+ list: (input, requestOptions) => request({
25277
+ method: "GET",
25278
+ path: `/api/command`,
25279
+ query: { location: input?.["location"] },
25280
+ successStatus: 200,
25281
+ declaredStatuses: [400, 401],
25282
+ empty: false
25283
+ }, requestOptions)
25284
+ },
25285
+ skill: {
25286
+ list: (input, requestOptions) => request({
25287
+ method: "GET",
25288
+ path: `/api/skill`,
25289
+ query: { location: input?.["location"] },
25290
+ successStatus: 200,
25291
+ declaredStatuses: [400, 401],
25292
+ empty: false
25293
+ }, requestOptions)
25294
+ },
25295
+ rpc: {
25296
+ call: (input, requestOptions) => request({
25297
+ method: "POST",
25298
+ path: `/api/rpc/${encodeURIComponent(input.rpcID)}/${encodeURIComponent(input.method)}`,
25299
+ query: { location: input["location"] },
25300
+ body: { input: input["input"] },
25301
+ successStatus: 200,
25302
+ declaredStatuses: [400, 401, 500],
25303
+ empty: false
25304
+ }, requestOptions)
25305
+ },
25306
+ event: {
25307
+ subscribe: (requestOptions) => sse({ method: "GET", path: `/api/event`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions)
25308
+ },
25309
+ pty: {
25310
+ list: (input, requestOptions) => request({
25311
+ method: "GET",
25312
+ path: `/api/pty`,
25313
+ query: { location: input?.["location"] },
25314
+ successStatus: 200,
25315
+ declaredStatuses: [400, 401],
25316
+ empty: false
25317
+ }, requestOptions),
25318
+ create: (input, requestOptions) => request({
25319
+ method: "POST",
25320
+ path: `/api/pty`,
25321
+ query: { location: input?.["location"] },
25322
+ body: {
25323
+ command: input?.["command"],
25324
+ args: input?.["args"],
25325
+ cwd: input?.["cwd"],
25326
+ title: input?.["title"],
25327
+ env: input?.["env"]
25328
+ },
25329
+ successStatus: 200,
25330
+ declaredStatuses: [400, 401],
25331
+ empty: false
25332
+ }, requestOptions),
25333
+ get: (input, requestOptions) => request({
25334
+ method: "GET",
25335
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}`,
25336
+ query: { location: input["location"] },
25337
+ successStatus: 200,
25338
+ declaredStatuses: [400, 401, 404],
25339
+ empty: false
25340
+ }, requestOptions),
25341
+ update: (input, requestOptions) => request({
25342
+ method: "PUT",
25343
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}`,
25344
+ query: { location: input["location"] },
25345
+ body: { title: input["title"], size: input["size"] },
25346
+ successStatus: 200,
25347
+ declaredStatuses: [400, 401, 404],
25348
+ empty: false
25349
+ }, requestOptions),
25350
+ remove: (input, requestOptions) => request({
25351
+ method: "DELETE",
25352
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}`,
25353
+ query: { location: input["location"] },
25354
+ successStatus: 204,
25355
+ declaredStatuses: [400, 401, 404],
25356
+ empty: true
25357
+ }, requestOptions),
25358
+ connect: {
25359
+ token: (input, requestOptions) => request({
25360
+ method: "POST",
25361
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}/connect-token`,
25362
+ query: { location: input["location"] },
25363
+ headers: { "x-opencode-ticket": input["x-opencode-ticket"] },
25364
+ successStatus: 200,
25365
+ declaredStatuses: [400, 401, 403, 404],
25366
+ empty: false
25367
+ }, requestOptions)
25368
+ }
25369
+ },
25370
+ experimental: {
25371
+ persistentPty: {
25372
+ read: (input, requestOptions) => request({
25373
+ method: "GET",
25374
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal/read`,
25375
+ query: { lines: input["lines"] },
25376
+ successStatus: 200,
25377
+ declaredStatuses: [400, 401, 503],
25378
+ empty: false
25379
+ }, requestOptions).then((value) => value.data),
25380
+ list: (input, requestOptions) => request({
25381
+ method: "GET",
25382
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`,
25383
+ successStatus: 200,
25384
+ declaredStatuses: [400, 401, 503],
25385
+ empty: false
25386
+ }, requestOptions).then((value) => value.data),
25387
+ create: (input, requestOptions) => request({
25388
+ method: "POST",
25389
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`,
25390
+ body: {
25391
+ command: input["command"],
25392
+ args: input["args"],
25393
+ cwd: input["cwd"],
25394
+ title: input["title"],
25395
+ env: input["env"],
25396
+ size: input["size"]
25397
+ },
25398
+ successStatus: 200,
25399
+ declaredStatuses: [400, 401, 503],
25400
+ empty: false
25401
+ }, requestOptions).then((value) => value.data),
25402
+ shutdown: (requestOptions) => request({
25403
+ method: "POST",
25404
+ path: `/api/experimental/persistent-pty/shutdown`,
25405
+ successStatus: 204,
25406
+ declaredStatuses: [400, 401, 503],
25407
+ empty: true
25408
+ }, requestOptions),
25409
+ handoff: (requestOptions) => request({
25410
+ method: "POST",
25411
+ path: `/api/experimental/persistent-pty/handoff`,
25412
+ successStatus: 200,
25413
+ declaredStatuses: [400, 401, 503],
25414
+ empty: false
25415
+ }, requestOptions),
25416
+ get: (input, requestOptions) => request({
25417
+ method: "GET",
25418
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`,
25419
+ successStatus: 200,
25420
+ declaredStatuses: [400, 401, 404, 503],
25421
+ empty: false
25422
+ }, requestOptions).then((value) => value.data),
25423
+ update: (input, requestOptions) => request({
25424
+ method: "PUT",
25425
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`,
25426
+ body: { attachmentID: input["attachmentID"], size: input["size"] },
25427
+ successStatus: 200,
25428
+ declaredStatuses: [400, 401, 404, 503],
25429
+ empty: false
25430
+ }, requestOptions).then((value) => value.data),
25431
+ snapshot: (input, requestOptions) => request({
25432
+ method: "GET",
25433
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/snapshot`,
25434
+ successStatus: 200,
25435
+ declaredStatuses: [400, 401, 404, 503],
25436
+ empty: false
25437
+ }, requestOptions).then((value) => value.data),
25438
+ remove: (input, requestOptions) => request({
25439
+ method: "DELETE",
25440
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`,
25441
+ successStatus: 204,
25442
+ declaredStatuses: [400, 401, 404, 503],
25443
+ empty: true
25444
+ }, requestOptions),
25445
+ connectToken: (input, requestOptions) => request({
25446
+ method: "POST",
25447
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect-token`,
25448
+ headers: { "x-opencode-ticket": input["x-opencode-ticket"] },
25449
+ successStatus: 200,
25450
+ declaredStatuses: [400, 401, 403, 404, 503],
25451
+ empty: false
25452
+ }, requestOptions).then((value) => value.data)
25453
+ }
25454
+ },
25455
+ shell: {
25456
+ list: (input, requestOptions) => request({
25457
+ method: "GET",
25458
+ path: `/api/shell`,
25459
+ query: { location: input?.["location"] },
25460
+ successStatus: 200,
25461
+ declaredStatuses: [400, 401],
25462
+ empty: false
25463
+ }, requestOptions),
25464
+ create: (input, requestOptions) => request({
25465
+ method: "POST",
25466
+ path: `/api/shell`,
25467
+ query: { location: input["location"] },
25468
+ body: {
25469
+ command: input["command"],
25470
+ cwd: input["cwd"],
25471
+ timeout: input["timeout"],
25472
+ metadata: input["metadata"]
25473
+ },
25474
+ successStatus: 200,
25475
+ declaredStatuses: [400, 401],
25476
+ empty: false
25477
+ }, requestOptions),
25478
+ get: (input, requestOptions) => request({
25479
+ method: "GET",
25480
+ path: `/api/shell/${encodeURIComponent(input.id)}`,
25481
+ query: { location: input["location"] },
25482
+ successStatus: 200,
25483
+ declaredStatuses: [400, 401, 404],
25484
+ empty: false
25485
+ }, requestOptions),
25486
+ output: (input, requestOptions) => request({
25487
+ method: "GET",
25488
+ path: `/api/shell/${encodeURIComponent(input.id)}/output`,
25489
+ query: { location: input["location"], cursor: input["cursor"], limit: input["limit"] },
25490
+ successStatus: 200,
25491
+ declaredStatuses: [400, 401, 404],
25492
+ empty: false
25493
+ }, requestOptions),
25494
+ remove: (input, requestOptions) => request({
25495
+ method: "DELETE",
25496
+ path: `/api/shell/${encodeURIComponent(input.id)}`,
25497
+ query: { location: input["location"] },
25498
+ successStatus: 204,
25499
+ declaredStatuses: [400, 401],
25500
+ empty: true
25501
+ }, requestOptions)
25502
+ },
25503
+ reference: {
25504
+ list: (input, requestOptions) => request({
25505
+ method: "GET",
25506
+ path: `/api/reference`,
25507
+ query: { location: input?.["location"] },
25508
+ successStatus: 200,
25509
+ declaredStatuses: [400, 401],
25510
+ empty: false
25511
+ }, requestOptions)
25512
+ },
25513
+ worktree: {
25514
+ list: (input, requestOptions) => request({
25515
+ method: "GET",
25516
+ path: `/api/worktree`,
25517
+ query: { projectID: input["projectID"] },
25518
+ successStatus: 200,
25519
+ declaredStatuses: [400, 401, 404],
25520
+ empty: false
25521
+ }, requestOptions),
25522
+ create: (input, requestOptions) => request({
25523
+ method: "POST",
25524
+ path: `/api/worktree`,
25525
+ body: {
25526
+ projectID: input["projectID"],
25527
+ from: input["from"],
25528
+ branch: input["branch"],
25529
+ directory: input["directory"],
25530
+ name: input["name"]
25531
+ },
25532
+ successStatus: 200,
25533
+ declaredStatuses: [400, 401, 404],
25534
+ empty: false
25535
+ }, requestOptions),
25536
+ remove: (input, requestOptions) => request({
25537
+ method: "DELETE",
25538
+ path: `/api/worktree`,
25539
+ body: { projectID: input["projectID"], directory: input["directory"], force: input["force"] },
25540
+ successStatus: 204,
25541
+ declaredStatuses: [400, 401, 404],
25542
+ empty: true
25543
+ }, requestOptions),
25544
+ refresh: (input, requestOptions) => request({
25545
+ method: "POST",
25546
+ path: `/api/worktree/refresh`,
25547
+ body: { projectID: input["projectID"] },
25548
+ successStatus: 204,
25549
+ declaredStatuses: [400, 401, 404],
25550
+ empty: true
25551
+ }, requestOptions)
25552
+ },
25553
+ vcs: {
25554
+ get: (input, requestOptions) => request({
25555
+ method: "GET",
25556
+ path: `/api/vcs`,
25557
+ query: { location: input?.["location"] },
25558
+ successStatus: 200,
25559
+ declaredStatuses: [400, 401],
25560
+ empty: false
25561
+ }, requestOptions),
25562
+ base: (input, requestOptions) => request({
25563
+ method: "GET",
25564
+ path: `/api/vcs/base`,
25565
+ query: { location: input?.["location"] },
25566
+ successStatus: 200,
25567
+ declaredStatuses: [400, 401, 503],
25568
+ empty: false
25569
+ }, requestOptions),
25570
+ status: (input, requestOptions) => request({
25571
+ method: "GET",
25572
+ path: `/api/vcs/status`,
25573
+ query: { location: input?.["location"] },
25574
+ successStatus: 200,
25575
+ declaredStatuses: [400, 401],
25576
+ empty: false
25577
+ }, requestOptions),
25578
+ branch: {
25579
+ list: (input, requestOptions) => request({
25580
+ method: "GET",
25581
+ path: `/api/vcs/branch`,
25582
+ query: { location: input?.["location"], search: input?.["search"], limit: input?.["limit"] },
25583
+ successStatus: 200,
25584
+ declaredStatuses: [400, 401],
25585
+ empty: false
25586
+ }, requestOptions)
25587
+ },
25588
+ diff: (input, requestOptions) => request({
25589
+ method: "GET",
25590
+ path: `/api/vcs/diff`,
25591
+ query: { location: input["location"], mode: input["mode"], base: input["base"], context: input["context"] },
25592
+ successStatus: 200,
25593
+ declaredStatuses: [400, 401, 503],
25594
+ empty: false
25595
+ }, requestOptions)
25596
+ },
25597
+ debug: {
25598
+ location: {
25599
+ list: (requestOptions) => request({
25600
+ method: "GET",
25601
+ path: `/api/debug/location`,
25602
+ successStatus: 200,
25603
+ declaredStatuses: [400, 401],
25604
+ empty: false
25605
+ }, requestOptions),
25606
+ evict: (input, requestOptions) => request({
25607
+ method: "DELETE",
25608
+ path: `/api/debug/location`,
25609
+ query: { location: input?.["location"] },
25610
+ successStatus: 204,
25611
+ declaredStatuses: [400, 401],
25612
+ empty: true
25613
+ }, requestOptions)
25614
+ }
25615
+ },
25616
+ migration: {
25617
+ v1: {
25618
+ status: (requestOptions) => request({
25619
+ method: "GET",
25620
+ path: `/api/experimental/migration/v1`,
25621
+ successStatus: 200,
25622
+ declaredStatuses: [400, 401],
25623
+ empty: false
25624
+ }, requestOptions)
25625
+ }
25626
+ },
25627
+ websearch: {
25628
+ providers: (input, requestOptions) => request({
25629
+ method: "GET",
25630
+ path: `/api/websearch/provider`,
25631
+ query: { location: input?.["location"] },
25632
+ successStatus: 200,
25633
+ declaredStatuses: [400, 401, 503],
25634
+ empty: false
25635
+ }, requestOptions),
25636
+ query: (input, requestOptions) => request({
25637
+ method: "POST",
25638
+ path: `/api/websearch`,
25639
+ query: { location: input["location"] },
25640
+ body: { query: input["query"], providerID: input["providerID"] },
25641
+ successStatus: 200,
25642
+ declaredStatuses: [400, 401, 503],
25643
+ empty: false
25644
+ }, requestOptions)
25645
+ },
25646
+ config: {
25647
+ get: (input, requestOptions) => request({
25648
+ method: "GET",
25649
+ path: `/api/config`,
25650
+ query: { location: input?.["location"] },
25651
+ successStatus: 200,
25652
+ declaredStatuses: [400, 401],
25653
+ empty: false
25654
+ }, requestOptions),
25655
+ shells: (requestOptions) => request({ method: "GET", path: `/api/config/shell`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions),
25656
+ update: (input, requestOptions) => request({
25657
+ method: "PATCH",
25658
+ path: `/api/experimental/config`,
25659
+ body: { shell: input["shell"] },
25660
+ successStatus: 204,
25661
+ declaredStatuses: [400, 401],
25662
+ empty: true
25663
+ }, requestOptions)
25664
+ }
25665
+ };
25666
+ }
25667
+ function encodePath(value) {
25668
+ return value.split("/").map(encodeURIComponent).join("/");
25669
+ }
25670
+ function appendQuery(params, key, value) {
25671
+ if (value === void 0)
25672
+ return;
25673
+ if (value === null) {
25674
+ params.append(key, "null");
25675
+ return;
25676
+ }
25677
+ if (Array.isArray(value)) {
25678
+ for (const item of value)
25679
+ appendQuery(params, key, item);
25680
+ return;
25681
+ }
25682
+ if (typeof value === "object") {
25683
+ for (const [child, item] of Object.entries(value))
25684
+ appendQuery(params, `${key}[${child}]`, item);
25685
+ return;
25686
+ }
25687
+ params.append(key, String(value));
25688
+ }
25689
+ async function json2(response) {
25690
+ if (!isContentType(response, "application/json") && !response.headers.get("content-type")?.includes("+json")) {
25691
+ try {
25692
+ await response.body?.cancel();
25693
+ } catch {
25694
+ }
25695
+ throw new ClientError3("UnsupportedContentType", { detail: response.headers.get("content-type") });
25696
+ }
25697
+ let text;
25698
+ try {
25699
+ text = await response.text();
25700
+ } catch (cause) {
25701
+ throw new ClientError3("Transport", { cause });
25702
+ }
25703
+ if (text === "")
25704
+ throw new ClientError3("MalformedResponse");
25705
+ try {
25706
+ return JSON.parse(text);
25707
+ } catch (cause) {
25708
+ throw new ClientError3("MalformedResponse", { cause });
25709
+ }
25710
+ }
25711
+ function declared(body) {
25712
+ const error51 = Object.assign(new Error(body.message ?? body.data?.message), body);
25713
+ if (body._tag)
25714
+ error51.name = body._tag;
25715
+ return error51;
25716
+ }
25717
+ function isContentType(response, expected) {
25718
+ return response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === expected;
25719
+ }
25720
+
25721
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-4tveyqeh.js
25722
+ var isRpcError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "RpcError";
25723
+ var isRpcInternalError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "RpcInternalError";
25724
+
25725
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-1tbj6z39.js
25726
+ function makeRpc2(raw, events) {
25727
+ return (definition) => {
25728
+ const subscribe = (name, options) => {
25729
+ if (!Object.hasOwn(definition.events, name))
25730
+ throw new Error(`Unknown RPC event: ${definition.id}.${name}`);
25731
+ const type = eventType(definition, name);
25732
+ return {
25733
+ [Symbol.asyncIterator]() {
25734
+ const controller = new AbortController();
25735
+ const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
25736
+ const iterator = (async function* () {
25737
+ try {
25738
+ for await (const published of events.subscribe({ signal })) {
25739
+ if (signal.aborted)
25740
+ return;
25741
+ if (published.type !== type)
25742
+ continue;
25743
+ yield published;
25744
+ }
25745
+ } catch (error51) {
25746
+ if (!signal.aborted)
25747
+ throw error51;
25748
+ } finally {
25749
+ controller.abort();
25750
+ }
25751
+ })();
25752
+ return {
25753
+ next: () => iterator.next(),
25754
+ return: () => {
25755
+ controller.abort();
25756
+ return iterator.return();
25757
+ }
25758
+ };
25759
+ }
25760
+ };
25761
+ };
25762
+ return Object.assign(Object.fromEntries(Object.keys(definition.methods).map((name) => [
25763
+ name,
25764
+ async (input, options) => {
25765
+ try {
25766
+ const result = await raw.rpc.call({
25767
+ rpcID: definition.id,
25768
+ method: name,
25769
+ input,
25770
+ location: options?.location
25771
+ }, { signal: options?.signal, headers: options?.headers });
25772
+ return result.output;
25773
+ } catch (error51) {
25774
+ if (!isRpcError2(error51) && !isRpcInternalError2(error51))
25775
+ throw error51;
25776
+ throw error51.data === void 0 ? { type: error51.type, message: error51.message } : { type: error51.type, message: error51.message, data: error51.data };
25777
+ }
25778
+ }
25779
+ ])), {
25780
+ events: {
25781
+ subscribe,
25782
+ on: (name, handler, options) => {
25783
+ const controller = new AbortController();
25784
+ const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
25785
+ const source = subscribe(name, { signal });
25786
+ (async () => {
25787
+ for await (const event of source)
25788
+ await handler(event);
25789
+ })().catch((error51) => console.error(error51));
25790
+ return () => controller.abort();
25791
+ }
25792
+ }
25793
+ });
25794
+ };
25795
+ }
25796
+ function eventType(definition, name) {
25797
+ return `rpc.${definition.id}.${name}`;
25798
+ }
25799
+
25800
+ // ../../../node_modules/@opencode/client/dist/chunks/service-timing-2twkm0vy.js
25801
+ var exports_client3 = {};
25802
+ __export2(exports_client3, {
25803
+ OpenCode: () => exports_client3,
25804
+ make: () => make5
25805
+ });
25806
+ function make5(options) {
25807
+ const raw = make6(options);
25808
+ const events = make7((signal, onActivity) => raw.event.subscribe({ signal, onActivity }));
25809
+ return {
25810
+ ...raw,
25811
+ rpc: Object.assign(makeRpc2(raw, events), raw.rpc),
25812
+ event: events
25813
+ };
25814
+ }
25815
+
25816
+ // dist/v2/connection.js
25817
+ var V2Connection = class {
25818
+ options;
25819
+ cwd;
25820
+ #child;
25821
+ #starting;
25822
+ #closing;
25823
+ #abort = new AbortController();
25824
+ #stderr = "";
25825
+ constructor(options, cwd) {
25826
+ this.options = options;
25827
+ this.cwd = cwd;
25828
+ }
25829
+ get stderrTail() {
25830
+ return this.#stderr;
25831
+ }
25832
+ client() {
25833
+ if (this.#closing)
25834
+ return Promise.reject(new Error("OpenCode v2 connection is closed"));
25835
+ return this.#starting ??= this.#start();
25836
+ }
25837
+ async #start() {
25838
+ const password = randomBytes2(32).toString("base64url");
25839
+ const env = {
25840
+ ...this.options.environment ?? process.env,
25841
+ OPENCODE_PASSWORD: password,
25842
+ OPENCODE_SERVER_PASSWORD: password
25843
+ };
25844
+ const executable = resolveOpenCodeExecutable({
25845
+ ...this.options.command ? { command: this.options.command } : {},
25846
+ environment: env
25847
+ });
25848
+ const invocation = openCodeServerInvocation(executable, env);
25849
+ const child = spawn2(invocation.command, invocation.arguments, {
25850
+ env,
25851
+ cwd: this.cwd,
25852
+ stdio: "pipe",
25853
+ detached: process.platform !== "win32",
25854
+ windowsHide: true,
25855
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments
25856
+ });
25857
+ this.#child = child;
25858
+ child.stderr.on("data", (chunk) => {
25859
+ this.#stderr = sanitizeDiagnosticTail(this.#stderr + chunk.toString());
25860
+ });
25861
+ try {
25862
+ const baseUrl = await new Promise((resolve, reject) => {
25863
+ let output = "";
25864
+ const timer = setTimeout(() => finish(new Error("OpenCode v2 server startup timed out")), this.options.startupTimeoutMs ?? 2e4);
25865
+ const abort = () => finish(new Error("OpenCode v2 connection closed during startup"));
25866
+ const finish = (error51, url2) => {
25867
+ clearTimeout(timer);
25868
+ this.#abort.signal.removeEventListener("abort", abort);
25869
+ if (error51)
25870
+ reject(error51);
25871
+ else if (url2)
25872
+ resolve(url2);
25873
+ };
25874
+ this.#abort.signal.addEventListener("abort", abort, { once: true });
25875
+ child.once("error", (error51) => finish(error51));
25876
+ child.once("exit", (code, signal) => finish(new Error(`OpenCode v2 server exited (${signal ?? code})`)));
25877
+ child.stdout.on("data", (chunk) => {
25878
+ output += chunk.toString();
25879
+ const lines = output.split(/\r?\n/u);
25880
+ output = (lines.pop() ?? "").slice(-8192);
25881
+ for (const line of lines) {
25882
+ const url2 = /^server listening on (http:\/\/127\.0\.0\.1:\d+)\s*$/u.exec(line)?.[1];
25883
+ if (url2)
25884
+ finish(void 0, url2);
25885
+ }
25886
+ });
25887
+ });
25888
+ const client2 = exports_client3.make({
25889
+ baseUrl,
25890
+ headers: {
25891
+ Authorization: `Basic ${Buffer.from(`opencode:${password}`).toString("base64")}`
25892
+ },
25893
+ fetch: (request, init) => {
25894
+ const signal = AbortSignal.any([
25895
+ this.#abort.signal,
25896
+ ...init?.signal ? [init.signal] : [],
25897
+ // Event streams keep their caller-owned lifetime; ordinary requests are bounded.
25898
+ ...(request instanceof Request ? request.url : String(request)).includes("/event") ? [] : [AbortSignal.timeout(this.options.commandTimeoutMs ?? 2e4)]
25899
+ ]);
25900
+ return fetch(request, { ...init, signal });
25901
+ }
25902
+ });
25903
+ const info = await client2.server.info();
25904
+ if (!/^2\./u.test(info.version))
25905
+ throw new Error(`Expected OpenCode v2 server, received ${info.version}`);
25906
+ return client2;
25907
+ } catch (error51) {
25908
+ await this.#stop();
25909
+ throw error51;
25910
+ }
25911
+ }
25912
+ close() {
25913
+ return this.#closing ??= (async () => {
25914
+ this.#abort.abort();
25915
+ await this.#stop();
25916
+ await this.#starting?.catch(() => void 0);
25917
+ })();
25918
+ }
25919
+ async #stop() {
25920
+ const child = this.#child;
25921
+ if (!child?.pid)
25922
+ return;
25923
+ const pid = child.pid;
25924
+ const kill = (signal) => {
25925
+ try {
25926
+ if (process.platform === "win32")
25927
+ spawnSync2("taskkill.exe", ["/pid", String(child.pid), "/t", "/f"], {
25928
+ windowsHide: true,
25929
+ stdio: "ignore"
25930
+ });
25931
+ else
25932
+ process.kill(-pid, signal);
25933
+ } catch {
25934
+ }
25935
+ };
25936
+ if (child.exitCode === null && child.signalCode === null) {
25937
+ await new Promise((resolve) => {
25938
+ const timer = setTimeout(() => {
25939
+ kill("SIGKILL");
25940
+ resolve();
25941
+ }, this.options.closeTimeoutMs ?? 3e3);
25942
+ child.once("exit", () => {
25943
+ clearTimeout(timer);
25944
+ resolve();
25945
+ });
25946
+ kill("SIGTERM");
25947
+ });
25948
+ }
25949
+ if (this.#child === child)
25950
+ this.#child = void 0;
25951
+ }
25952
+ };
25953
+
25954
+ // dist/v2/history.js
25955
+ import path8 from "node:path";
25956
+ async function readMessages(client2, sessionID) {
25957
+ const messages = [];
25958
+ let cursor;
25959
+ const seen = /* @__PURE__ */ new Set();
25960
+ do {
25961
+ const page = await client2.message.list({
25962
+ sessionID,
25963
+ ...cursor ? { cursor } : { order: "asc", limit: 100 }
25964
+ });
25965
+ messages.push(...page.data);
25966
+ cursor = page.cursor.next ?? void 0;
25967
+ if (cursor && seen.has(cursor))
25968
+ throw new Error("OpenCode v2 transcript pagination did not advance");
25969
+ if (cursor)
25970
+ seen.add(cursor);
25971
+ } while (cursor);
25972
+ return messages;
25973
+ }
25974
+ var contentId = (messageID, index) => hostItemIdSchema.parse(`${messageID}:${index}`);
25975
+ function assistantItems2(message, limit) {
25976
+ return message.content.map((part, index) => {
25977
+ const itemId2 = contentId(message.id, index);
25978
+ if (part.type === "text" || part.type === "reasoning") {
25979
+ return {
25980
+ item: {
25981
+ type: part.type === "text" ? "agentMessage" : "reasoning",
25982
+ itemId: itemId2,
25983
+ text: part.text
25984
+ },
25985
+ outcome: message.error ? { status: "failed", error: failure(message.error.message) } : { status: "succeeded" }
25986
+ };
25987
+ }
25988
+ const state = part.state;
25989
+ const text = "content" in state ? state.content?.map((p) => p.type === "text" ? p.text : `[File: ${p.uri}]`).join("\n") : void 0;
25990
+ return {
25991
+ item: {
25992
+ type: "toolExecution",
25993
+ itemId: itemId2,
25994
+ toolName: part.name,
25995
+ namespace: "opencode",
25996
+ arguments: typeof state.input === "string" ? state.input : state.input,
25997
+ ...text ? {
25998
+ output: {
25999
+ content: [{ type: "text", text: text.slice(0, limit) }],
26000
+ ...text.length > limit ? { truncated: true } : {}
26001
+ }
26002
+ } : {}
26003
+ },
26004
+ outcome: state.status === "error" ? { status: "failed", error: failure(state.error.message) } : state.status === "completed" ? { status: "succeeded" } : { status: "cancelled", reason: "Native Tool did not complete" }
26005
+ };
26006
+ });
26007
+ }
26008
+ function projectHistory(session, messages, limit) {
26009
+ if (session.revert)
26010
+ throw new Error("Clear the staged OpenCode v2 revert before using this Session in codexhost");
26011
+ const turns = [];
26012
+ let turn;
26013
+ for (const message of messages) {
26014
+ if (message.type === "user" && turn) {
26015
+ turn.input.push({ type: "text", text: message.text });
26016
+ } else if (message.type === "user" || message.type === "compaction" && message.reason === "manual" && !turn) {
26017
+ turn = {
26018
+ nativeTurnRef: nativeTurnRefSchema.parse({
26019
+ harnessId,
26020
+ nativeSessionId: session.id,
26021
+ nativeTurnKey: message.id,
26022
+ formatVersion: 1
26023
+ }),
26024
+ input: message.type === "user" ? [{ type: "text", text: message.text }] : [],
26025
+ items: [],
26026
+ outcome: { status: "unknown", reason: "OpenCode execution has no durable terminal" },
26027
+ startedAtMs: message.time.created
26028
+ };
26029
+ turns.push(turn);
26030
+ }
26031
+ if (!turn)
26032
+ continue;
26033
+ if (message.type === "assistant") {
26034
+ turn.items.push(...assistantItems2(message, limit));
26035
+ turn.model = encodeOpenCodeModelRef({
26036
+ providerID: message.model.providerID,
26037
+ modelID: message.model.id
26038
+ });
26039
+ } else if (message.type === "compaction") {
26040
+ turn.items.push({
26041
+ item: { type: "contextCompaction", itemId: hostItemIdSchema.parse(message.id) },
26042
+ outcome: message.status === "failed" ? { status: "failed", error: failure(message.error.message) } : message.status === "completed" ? { status: "succeeded" } : { status: "cancelled", reason: "Compaction is incomplete" }
26043
+ });
26044
+ } else if (message.type === "shell") {
26045
+ turn.items.push({
26046
+ item: {
26047
+ type: "commandExecution",
26048
+ itemId: hostItemIdSchema.parse(message.id),
26049
+ command: message.command,
26050
+ ...message.output ? {
26051
+ output: message.output.output.slice(0, limit),
26052
+ outputTruncated: message.output.truncated || message.output.output.length > limit
26053
+ } : {},
26054
+ ...typeof message.exit === "number" ? { exitCode: message.exit } : {}
26055
+ },
26056
+ outcome: message.status === "killed" ? { status: "cancelled" } : message.exit === 0 ? { status: "succeeded" } : {
26057
+ status: "failed",
26058
+ error: failure(`Shell ${message.status}, exit ${message.exit ?? "unknown"}`)
26059
+ }
26060
+ });
26061
+ } else if (message.type === "idle") {
26062
+ turn.outcome = message.outcome === "interrupted" ? { status: "cancelled" } : message.outcome === "failed" ? { status: "failed", error: failure("OpenCode v2 execution failed") } : { status: "succeeded" };
26063
+ turn.completedAtMs = message.time.created;
26064
+ turn.checkpoint = nativeCheckpointRefSchema.parse({
26065
+ harnessId,
26066
+ nativeSessionId: session.id,
26067
+ checkpointId: message.id,
26068
+ locator: { protocol: 2, userMessageID: turn.nativeTurnRef.nativeTurnKey },
26069
+ formatVersion: 1
26070
+ });
26071
+ turn = void 0;
26072
+ }
26073
+ }
26074
+ return { turns };
26075
+ }
26076
+ function fileChanges(session, turn, diffs) {
26077
+ if (!diffs.length)
26078
+ return void 0;
26079
+ const changes = diffs.map((diff) => {
26080
+ const absolute = path8.resolve(session.location.directory, diff.file);
26081
+ const relative = path8.relative(session.location.directory, absolute);
26082
+ if (relative.startsWith(`..${path8.sep}`) || relative === ".." || path8.isAbsolute(relative))
26083
+ throw new Error("OpenCode v2 diff escaped the Session directory");
26084
+ return {
26085
+ path: absolute,
26086
+ kind: diff.status === "added" ? "add" : diff.status === "deleted" ? "delete" : "update",
26087
+ unifiedDiff: diff.patch
26088
+ };
26089
+ });
26090
+ return {
26091
+ item: {
26092
+ type: "fileChange",
26093
+ itemId: hostItemIdSchema.parse(`${turn.nativeTurnRef.nativeTurnKey}:diff`),
26094
+ changes
26095
+ },
26096
+ outcome: { status: "succeeded" }
26097
+ };
26098
+ }
26099
+ async function readHistory(client2, session, limit) {
26100
+ const messages = await readMessages(client2, session.id);
26101
+ const snapshot = projectHistory(session, messages, limit);
26102
+ for (const turn of snapshot.turns) {
26103
+ if (!turn.checkpoint)
26104
+ continue;
26105
+ const first = messages.findIndex((m) => m.id === turn.nativeTurnRef.nativeTurnKey);
26106
+ const last = messages.findIndex((m) => m.id === turn.checkpoint?.checkpointId);
26107
+ if (!messages.slice(first, last).some((m) => m.type === "assistant" && m.snapshot?.files?.length))
26108
+ continue;
26109
+ const diffs = await client2.session.diff({
26110
+ sessionID: session.id,
26111
+ from: turn.nativeTurnRef.nativeTurnKey
26112
+ });
26113
+ const item = fileChanges(session, turn, diffs);
26114
+ if (item)
26115
+ turn.items.push(item);
26116
+ }
26117
+ return { messages, snapshot };
26118
+ }
26119
+ function terminalItemOutcome(outcome) {
26120
+ return outcome.status === "unknown" ? { status: "failed", error: failure(outcome.reason, "protocolError") } : outcome;
26121
+ }
26122
+
26123
+ // dist/v2/interactions.js
26124
+ function permissionInteraction(request, turnId) {
26125
+ return {
26126
+ request,
26127
+ interaction: {
26128
+ type: "approval",
26129
+ interactionId: hostInteractionIdSchema.parse(`oc2-permission:${request.id}`),
26130
+ turnId,
26131
+ title: request.action,
26132
+ description: request.message ?? request.resources.join("\n"),
26133
+ subject: { type: "nativeAction" },
26134
+ actions: [
26135
+ { id: "once", label: "Allow once", effect: "allowOnce" },
26136
+ { id: "reject", label: "Deny", effect: "deny" }
26137
+ ]
26138
+ }
26139
+ };
26140
+ }
26141
+ function formInteraction(form, turnId) {
26142
+ const questions = form.fields.map((field) => {
26143
+ if (field.type === "external" || field.hidden || field.when?.length) {
26144
+ throw new Error("OpenCode v2 external, hidden or conditional form fields require its native UI");
26145
+ }
26146
+ const base = {
26147
+ id: field.key,
26148
+ prompt: [field.title, field.description].filter(Boolean).join("\n") || field.key,
26149
+ optional: !field.required
26150
+ };
26151
+ if (field.type === "boolean")
26152
+ return {
26153
+ ...base,
26154
+ type: "choice",
26155
+ multiple: false,
26156
+ allowOther: false,
26157
+ options: [
26158
+ { value: "true", label: "Yes" },
26159
+ { value: "false", label: "No" }
26160
+ ]
26161
+ };
26162
+ if (field.type === "multiselect" || field.type === "string" && field.options?.length) {
26163
+ return {
26164
+ ...base,
26165
+ type: "choice",
26166
+ multiple: field.type === "multiselect",
26167
+ allowOther: field.custom ?? false,
26168
+ options: field.options ?? []
26169
+ };
26170
+ }
26171
+ return {
26172
+ ...base,
26173
+ type: "text",
26174
+ multiline: field.type === "string",
26175
+ secret: false,
26176
+ ...field.type === "string" && field.placeholder ? { placeholder: field.placeholder } : {},
26177
+ ...field.default !== void 0 ? { prefill: String(field.default) } : {}
26178
+ };
26179
+ });
26180
+ return {
26181
+ form,
26182
+ interaction: {
26183
+ type: "question",
26184
+ interactionId: hostInteractionIdSchema.parse(`oc2-form:${form.id}`),
26185
+ turnId,
26186
+ title: form.title,
26187
+ questions
26188
+ }
26189
+ };
26190
+ }
26191
+ async function replyInteraction(client2, pending, command) {
26192
+ if (pending.interaction.type === "approval" && pending.request) {
26193
+ if (command.response.type !== "approval")
26194
+ throw new Error("Expected OpenCode approval decision");
26195
+ const validation2 = validateHostApprovalResponse(pending.interaction, command.response);
26196
+ if (validation2)
26197
+ throw new Error(validation2.message);
26198
+ if (command.response.type !== "approval" || !["once", "reject"].includes(command.response.actionId))
26199
+ throw new Error("Invalid OpenCode approval decision");
26200
+ await client2.permission.reply({
26201
+ sessionID: pending.request.sessionID,
26202
+ requestID: pending.request.id,
26203
+ decision: command.response.actionId === "once" ? "once" : "reject"
26204
+ });
26205
+ return;
26206
+ }
26207
+ if (pending.interaction.type !== "question" || !pending.form)
26208
+ throw new Error("Invalid OpenCode interaction");
26209
+ if (command.response.type !== "question")
26210
+ throw new Error("Expected OpenCode form answer");
26211
+ const validation = validateHostQuestionResponse(pending.interaction, command.response);
26212
+ if (validation)
26213
+ throw new Error(validation.message);
26214
+ const form = pending.form;
26215
+ if (command.response.cancelled) {
26216
+ await client2.session.form.cancel({ sessionID: form.sessionID, formID: form.id });
26217
+ return;
26218
+ }
26219
+ const answer = {};
26220
+ for (const field of form.fields) {
26221
+ const values = command.response.answers[field.key] ?? [];
26222
+ if (!values.length)
26223
+ continue;
26224
+ const value = values[0];
26225
+ if (value === void 0)
26226
+ continue;
26227
+ if (field.type === "multiselect")
26228
+ answer[field.key] = values;
26229
+ else if (field.type === "boolean")
26230
+ answer[field.key] = value === "true";
26231
+ else if (field.type === "number" || field.type === "integer") {
26232
+ const number4 = Number(value);
26233
+ if (!value.trim() || !Number.isFinite(number4) || field.type === "integer" && !Number.isInteger(number4))
26234
+ throw new Error(`Invalid number for ${field.key}`);
26235
+ answer[field.key] = number4;
26236
+ } else
26237
+ answer[field.key] = value;
26238
+ }
26239
+ await client2.session.form.reply({ sessionID: form.sessionID, formID: form.id, answer });
26240
+ }
26241
+
26242
+ // dist/v2/session.js
26243
+ function v2Capabilities(catalog) {
26244
+ return {
26245
+ configuration: {
26246
+ selectModel: catalog.models.length > 0,
26247
+ selectThinkingOption: catalog.thinkingOptions.length > 1,
26248
+ selectPermissionMode: true,
26249
+ permissionModeScope: "live"
26250
+ },
26251
+ history: { fork: true, forkAcrossCwd: false, rollbackLastTurn: true }
26252
+ };
26253
+ }
26254
+ var V2Session = class {
26255
+ client;
26256
+ connection;
26257
+ info;
26258
+ catalog;
26259
+ policy;
26260
+ limit;
26261
+ onClosed;
26262
+ harnessId = harnessId;
26263
+ capabilities;
26264
+ initialState;
26265
+ initialUsage;
26266
+ commands;
26267
+ #channel = new HarnessOutputChannel();
26268
+ outputs = this.#channel.outputs;
26269
+ #abort = new AbortController();
26270
+ #active;
26271
+ #closed = false;
26272
+ #closePromise;
26273
+ #pump;
26274
+ #reconciling;
26275
+ #timer;
26276
+ #configuring = false;
26277
+ constructor(client2, connection, info, catalog, policy, limit, onClosed) {
26278
+ this.client = client2;
26279
+ this.connection = connection;
26280
+ this.info = info;
26281
+ this.catalog = catalog;
26282
+ this.policy = policy;
26283
+ this.limit = limit;
26284
+ this.onClosed = onClosed;
26285
+ this.initialState = v2State(info, catalog, policy);
26286
+ this.initialUsage = v2Usage(info);
26287
+ this.capabilities = v2Capabilities(catalog);
26288
+ this.commands = {
26289
+ list: async () => ({ ok: true, value: openCodeCommandCatalog }),
26290
+ execute: async (command) => {
26291
+ if (command.commandId !== "opencode.compact" || Object.keys(command.arguments ?? {}).length)
26292
+ return { ok: false, error: failure("Unsupported OpenCode command", "unsupported") };
26293
+ return this.#start({ type: "turn.start", turnId: command.turnId, input: [] }, true);
26294
+ }
26295
+ };
26296
+ }
26297
+ async start() {
26298
+ await new Promise((resolve, reject) => {
26299
+ const timer = setTimeout(() => reject(new Error("OpenCode v2 event subscription timed out")), this.connection.options.startupTimeoutMs ?? 2e4);
26300
+ this.#pump = (async () => {
26301
+ try {
26302
+ for await (const event of this.client.event.subscribe({ signal: this.#abort.signal })) {
26303
+ if (this.#abort.signal.aborted)
26304
+ break;
26305
+ if (event.type === "server.connected") {
26306
+ clearTimeout(timer);
26307
+ resolve();
26308
+ }
26309
+ this.#onEvent(event);
26310
+ }
26311
+ if (!this.#abort.signal.aborted)
26312
+ throw new Error("OpenCode v2 event stream disconnected");
26313
+ } catch (error51) {
26314
+ clearTimeout(timer);
26315
+ reject(error51);
26316
+ if (!this.#closed)
26317
+ await this.#fault(failure(error51 instanceof Error ? error51.message : String(error51), "processExited"));
26318
+ }
26319
+ })();
26320
+ });
26321
+ this.#timer = setInterval(() => {
26322
+ void this.#refresh();
26323
+ }, 400);
26324
+ }
26325
+ async readSnapshot() {
26326
+ if (this.#closed)
26327
+ return { ok: false, error: failure("OpenCode Session is closed", "invalidState") };
26328
+ if (this.#active || this.#configuring)
26329
+ return { ok: false, error: failure("OpenCode Session is busy", "sessionBusy") };
26330
+ try {
26331
+ this.info = await this.client.session.get({ sessionID: this.info.id });
26332
+ const { snapshot } = await readHistory(this.client, this.info, this.limit);
26333
+ return {
26334
+ ok: true,
26335
+ value: { ...snapshot, state: v2State(this.info, this.catalog, this.policy) }
26336
+ };
26337
+ } catch (error51) {
26338
+ return errorResult(error51);
26339
+ }
26340
+ }
26341
+ async execute(command) {
26342
+ if (this.#closed)
26343
+ return { ok: false, error: failure("OpenCode Session is closed", "invalidState") };
26344
+ if (command.type === "turn.start")
26345
+ return this.#start(command, false);
26346
+ if (command.type === "turn.cancel") {
26347
+ const active = this.#active;
26348
+ if (!active?.admitted || active.turnId !== command.turnId)
26349
+ return { ok: false, error: failure("No matching OpenCode Turn", "invalidState") };
26350
+ try {
26351
+ await this.client.session.interrupt({ sessionID: this.info.id, resume: false });
26352
+ await this.#refresh();
26353
+ return { ok: true, value: { cancellationRequested: true } };
26354
+ } catch (error51) {
26355
+ return errorResult(error51);
26356
+ }
26357
+ }
26358
+ if (command.type === "interaction.respond") {
26359
+ const active = this.#active;
26360
+ const pending = active?.interactions.get(command.interactionId);
26361
+ if (!active || !pending || active.replying.has(command.interactionId))
26362
+ return {
26363
+ ok: false,
26364
+ error: failure("OpenCode interaction is no longer pending", "invalidState")
26365
+ };
26366
+ active.replying.add(command.interactionId);
26367
+ try {
26368
+ await replyInteraction(this.client, pending, command);
26369
+ this.#closeInteraction(active, command.interactionId, command.response.type === "question" && command.response.cancelled ? "cancelled" : "responded");
26370
+ return { ok: true, value: { accepted: true } };
26371
+ } catch (error51) {
26372
+ return errorResult(error51);
26373
+ } finally {
26374
+ active.replying.delete(command.interactionId);
26375
+ }
26376
+ }
26377
+ if (this.#active || this.#configuring)
26378
+ return { ok: false, error: failure("OpenCode Session is busy", "sessionBusy") };
26379
+ this.#configuring = true;
26380
+ try {
26381
+ if ((await this.client.session.active())[this.info.id])
26382
+ throw new Error("OpenCode Session is running");
26383
+ if (command.type === "permissionMode.select") {
26384
+ await this.client.session.update({
26385
+ sessionID: this.info.id,
26386
+ permissions: v2Permissions(this.info.permissions, command.permissionModeId)
26387
+ });
26388
+ } else {
26389
+ let model = this.info.model;
26390
+ if (command.type === "model.select") {
26391
+ if (!this.catalog.models.some((m) => m.ref.id === command.model.id))
26392
+ throw new Error("OpenCode Model is not available");
26393
+ const decoded = decodeOpenCodeModelRef(command.model);
26394
+ model = { providerID: decoded.providerID, id: decoded.modelID };
26395
+ } else {
26396
+ if (!model)
26397
+ throw new Error("Select a Model before a Thinking option");
26398
+ const state = v2State(this.info, this.catalog, this.policy);
26399
+ if (!state.availableThinkingOptions?.some((v) => v.id === command.thinkingOptionId))
26400
+ throw new Error("Thinking option is unavailable for this Model");
26401
+ const variant = decodeOpenCodeVariant(command.thinkingOptionId);
26402
+ model = { providerID: model.providerID, id: model.id, ...variant ? { variant } : {} };
26403
+ }
26404
+ await this.client.session.switchModel({ sessionID: this.info.id, model });
26405
+ }
26406
+ this.info = await this.client.session.get({ sessionID: this.info.id });
26407
+ this.#emit({
26408
+ type: "session.state.changed",
26409
+ state: v2State(this.info, this.catalog, this.policy)
26410
+ });
26411
+ return { ok: true, value: { completed: true } };
26412
+ } catch (error51) {
26413
+ return errorResult(error51);
26414
+ } finally {
26415
+ this.#configuring = false;
26416
+ }
26417
+ }
26418
+ async #start(command, compact) {
26419
+ if (this.#closed || this.#active || this.#configuring)
26420
+ return {
26421
+ ok: false,
26422
+ error: failure("OpenCode Session is closed or busy", this.#closed ? "invalidState" : "sessionBusy")
26423
+ };
26424
+ const text = command.input.filter((part) => part.type === "text").map((part) => part.text).join("\n");
26425
+ if (!compact && !text.trim())
26426
+ return { ok: false, error: failure("OpenCode requires text input", "invalidRequest") };
26427
+ let resolve;
26428
+ const done = new Promise((r) => {
26429
+ resolve = r;
26430
+ });
26431
+ const active = {
26432
+ turnId: command.turnId,
26433
+ compact,
26434
+ admitted: false,
26435
+ baseline: /* @__PURE__ */ new Set(),
26436
+ live: /* @__PURE__ */ new Map(),
26437
+ assistants: /* @__PURE__ */ new Set(),
26438
+ transient: /* @__PURE__ */ new Map(),
26439
+ interactions: /* @__PURE__ */ new Map(),
26440
+ replying: /* @__PURE__ */ new Set(),
26441
+ settledInteractions: /* @__PURE__ */ new Set(),
26442
+ done,
26443
+ resolve
26444
+ };
26445
+ this.#active = active;
26446
+ let attempted = false;
26447
+ try {
26448
+ if ((await this.client.session.active())[this.info.id])
26449
+ throw new Error("OpenCode Session is already running");
26450
+ this.info = await this.client.session.get({ sessionID: this.info.id });
26451
+ const before = await readHistory(this.client, this.info, this.limit);
26452
+ if (before.snapshot.turns.some((turn) => turn.outcome.status === "unknown"))
26453
+ throw new Error("OpenCode history contains an incomplete execution");
26454
+ active.baseline = new Set(before.snapshot.turns.map((t) => t.nativeTurnRef.nativeTurnKey));
26455
+ attempted = true;
26456
+ if (compact)
26457
+ await this.client.session.compact({ sessionID: this.info.id });
26458
+ else
26459
+ await this.client.session.prompt({
26460
+ sessionID: this.info.id,
26461
+ text,
26462
+ delivery: "queue",
26463
+ metadata: { "codexhost.turnId": active.turnId }
26464
+ });
26465
+ if (this.#closed) {
26466
+ await this.client.session.interrupt({ sessionID: this.info.id, resume: false });
26467
+ throw new Error("OpenCode Session closed during admission");
26468
+ }
26469
+ active.admitted = true;
26470
+ this.#emit({ type: "turn.started", turnId: active.turnId });
26471
+ for (const item of active.transient.values())
26472
+ this.#projectItem(active, { item, outcome: { status: "succeeded" } }, false);
26473
+ void this.#refresh();
26474
+ return { ok: true, value: { turnId: active.turnId } };
26475
+ } catch (error51) {
26476
+ if (attempted)
26477
+ await this.client.session.interrupt({ sessionID: this.info.id, resume: false }).catch((interruptError) => this.#fault(errorResult(interruptError).error));
26478
+ if (this.#active === active)
26479
+ this.#active = void 0;
26480
+ active.resolve();
26481
+ return errorResult(error51);
26482
+ }
26483
+ }
26484
+ #onEvent(event) {
26485
+ const active = this.#active;
26486
+ if (!active || !("data" in event) || !("sessionID" in event.data) || event.data.sessionID !== this.info.id)
26487
+ return;
26488
+ if (event.type === "session.step.started")
26489
+ active.assistants.add(event.data.assistantMessageID);
26490
+ if ((event.type === "session.text.delta" || event.type === "session.reasoning.delta") && active.assistants.has(event.data.assistantMessageID)) {
26491
+ const itemId2 = contentId(event.data.assistantMessageID, event.data.ordinal);
26492
+ const type = event.type === "session.text.delta" ? "agentMessage" : "reasoning";
26493
+ const previous = active.transient.get(itemId2);
26494
+ const item = {
26495
+ type,
26496
+ itemId: itemId2,
26497
+ text: (previous?.text ?? "") + event.data.delta
26498
+ };
26499
+ active.transient.set(itemId2, item);
26500
+ if (active.admitted)
26501
+ this.#projectItem(active, { item, outcome: { status: "succeeded" } }, false);
26502
+ }
26503
+ if (!event.type.endsWith(".delta"))
26504
+ void this.#refresh();
26505
+ }
26506
+ #refresh() {
26507
+ if (this.#closed || !this.#active?.admitted)
26508
+ return Promise.resolve();
26509
+ return this.#reconciling ??= this.#reconcile().catch(async (error51) => {
26510
+ await this.#fault(failure(error51 instanceof Error ? error51.message : String(error51), "protocolError"));
26511
+ }).finally(() => {
26512
+ this.#reconciling = void 0;
26513
+ });
26514
+ }
26515
+ async #reconcile() {
26516
+ const active = this.#active;
26517
+ if (!active?.admitted)
26518
+ return;
26519
+ const info = await this.client.session.get({ sessionID: this.info.id });
26520
+ const { snapshot, messages } = await readHistory(this.client, info, this.limit);
26521
+ if (this.#active !== active || this.#closed)
26522
+ return;
26523
+ this.info = info;
26524
+ const turns = snapshot.turns.filter((t) => !active.baseline.has(t.nativeTurnRef.nativeTurnKey));
26525
+ if (turns.length > 1)
26526
+ throw new Error("Concurrent native prompts cannot be assigned to one Host Turn");
26527
+ const turn = turns[0];
26528
+ if (turn) {
26529
+ const prompt = messages.find((message) => message.id === turn.nativeTurnRef.nativeTurnKey);
26530
+ if (active.compact ? turn.input.length !== 0 : prompt?.type !== "user" || prompt.metadata?.["codexhost.turnId"] !== active.turnId || turn.input.length !== 1)
26531
+ throw new Error("Concurrent native input cannot be assigned to this Host Turn");
26532
+ const terminal = turn.outcome.status !== "unknown";
26533
+ for (const item of turn.items)
26534
+ this.#projectItem(active, item, terminal, turn.outcome.status === "cancelled" || turn.outcome.status === "failed");
26535
+ if (terminal) {
26536
+ if ((await this.client.session.active())[info.id])
26537
+ return;
26538
+ if (this.#active === active)
26539
+ this.#finish(active, turn);
26540
+ return;
26541
+ }
26542
+ }
26543
+ const [permissions, forms] = await Promise.all([
26544
+ this.client.permission.list({ sessionID: info.id }),
26545
+ this.client.session.form.list({ sessionID: info.id })
26546
+ ]);
26547
+ if (this.#active !== active || this.#closed)
26548
+ return;
26549
+ const current = /* @__PURE__ */ new Map();
26550
+ for (const request of permissions) {
26551
+ const pending = permissionInteraction(request, active.turnId);
26552
+ current.set(pending.interaction.interactionId, pending);
26553
+ }
26554
+ for (const form of forms) {
26555
+ const pending = formInteraction(form, active.turnId);
26556
+ current.set(pending.interaction.interactionId, pending);
26557
+ }
26558
+ for (const [id, pending] of current)
26559
+ if (!active.interactions.has(id) && !active.settledInteractions.has(id)) {
26560
+ active.interactions.set(id, pending);
26561
+ this.#channel.emit({ kind: "interaction", interaction: pending.interaction });
26562
+ }
26563
+ for (const id of active.interactions.keys())
26564
+ if (!current.has(id) && !active.replying.has(id))
26565
+ this.#closeInteraction(active, id, "expired");
26566
+ }
26567
+ #projectItem(active, snapshot, terminal, interrupted = false) {
26568
+ const item = snapshot.item;
26569
+ const old = active.live.get(item.itemId);
26570
+ if (!old) {
26571
+ active.live.set(item.itemId, item);
26572
+ this.#emit({ type: "item.started", turnId: active.turnId, item });
26573
+ return;
26574
+ }
26575
+ if ((item.type === "agentMessage" || item.type === "reasoning") && "text" in old) {
26576
+ if (old.text.startsWith(item.text) && !terminal)
26577
+ return;
26578
+ if (terminal && interrupted && old.text.startsWith(item.text)) {
26579
+ active.live.set(item.itemId, item);
26580
+ return;
26581
+ }
26582
+ if (!item.text.startsWith(old.text))
26583
+ throw new Error("OpenCode v2 streamed text differs from durable history");
26584
+ const delta = item.text.slice(old.text.length);
26585
+ if (delta)
26586
+ this.#emit({
26587
+ type: "item.updated",
26588
+ turnId: active.turnId,
26589
+ itemId: item.itemId,
26590
+ update: { type: "text.append", text: delta }
26591
+ });
26592
+ } else if (item.type === "toolExecution" && item.output && JSON.stringify(item) !== JSON.stringify(old)) {
26593
+ this.#emit({
26594
+ type: "item.updated",
26595
+ turnId: active.turnId,
26596
+ itemId: item.itemId,
26597
+ update: { type: "output.replace", output: item.output }
26598
+ });
26599
+ }
26600
+ active.live.set(item.itemId, item);
26601
+ }
26602
+ #finish(active, turn) {
26603
+ if (this.#active !== active || turn.outcome.status === "unknown")
26604
+ return;
26605
+ for (const id of active.interactions.keys())
26606
+ this.#closeInteraction(active, id, "cancelled");
26607
+ for (const [id, item] of active.live) {
26608
+ const snapshot = turn.items.find((entry) => entry.item.itemId === id) ?? {
26609
+ item,
26610
+ outcome: terminalItemOutcome(turn.outcome)
26611
+ };
26612
+ this.#emit({ type: "item.completed", turnId: active.turnId, snapshot });
26613
+ }
26614
+ this.#emit({
26615
+ type: "session.state.changed",
26616
+ state: v2State(this.info, this.catalog, this.policy)
26617
+ });
26618
+ this.#emit({
26619
+ type: "session.usage.changed",
26620
+ usage: v2Usage(this.info),
26621
+ observedForTurnId: active.turnId
26622
+ });
26623
+ this.#active = void 0;
26624
+ this.#emit({
26625
+ type: "turn.completed",
26626
+ turnId: active.turnId,
26627
+ nativeTurnRef: turn.nativeTurnRef,
26628
+ outcome: { ...turn.outcome, ...turn.checkpoint ? { checkpoint: turn.checkpoint } : {} }
26629
+ });
26630
+ active.resolve();
26631
+ }
26632
+ #closeInteraction(active, id, reason) {
26633
+ const pending = active.interactions.get(id);
26634
+ if (!pending)
26635
+ return;
26636
+ active.interactions.delete(id);
26637
+ active.settledInteractions.add(id);
26638
+ this.#emit({
26639
+ type: "interaction.closed",
26640
+ interactionId: pending.interaction.interactionId,
26641
+ turnId: active.turnId,
26642
+ reason
26643
+ });
26644
+ }
26645
+ #emit(event) {
26646
+ this.#channel.emit({ kind: "event", event });
26647
+ }
26648
+ async #fault(error51) {
26649
+ if (this.#closed)
26650
+ return;
26651
+ this.#closed = true;
26652
+ if (this.#timer)
26653
+ clearInterval(this.#timer);
26654
+ this.#abort.abort();
26655
+ const active = this.#active;
26656
+ if (active?.admitted) {
26657
+ for (const id of active.interactions.keys())
26658
+ this.#closeInteraction(active, id, "cancelled");
26659
+ for (const item of active.live.values())
26660
+ this.#emit({
26661
+ type: "item.completed",
26662
+ turnId: active.turnId,
26663
+ snapshot: { item, outcome: { status: "failed", error: error51 } }
26664
+ });
26665
+ this.#emit({
26666
+ type: "turn.completed",
26667
+ turnId: active.turnId,
26668
+ outcome: { status: "failed", error: error51 }
26669
+ });
26670
+ }
26671
+ this.#active = void 0;
26672
+ active?.resolve();
26673
+ this.#emit({ type: "session.faulted", error: error51 });
26674
+ this.#channel.end();
26675
+ await this.client.session.interrupt({ sessionID: this.info.id, resume: false }).catch(() => void 0);
26676
+ await this.connection.close();
26677
+ this.onClosed();
26678
+ }
26679
+ close() {
26680
+ return this.#closePromise ??= (async () => {
26681
+ const active = this.#active;
26682
+ if (active?.admitted && !this.#closed) {
26683
+ await this.client.session.interrupt({ sessionID: this.info.id, resume: false }).catch(() => void 0);
26684
+ await this.#refresh();
26685
+ if (this.#active) {
26686
+ let timer;
26687
+ await Promise.race([
26688
+ active.done,
26689
+ new Promise((resolve) => {
26690
+ timer = setTimeout(resolve, this.connection.options.closeTimeoutMs ?? 3e3);
26691
+ })
26692
+ ]).finally(() => {
26693
+ if (timer)
26694
+ clearTimeout(timer);
26695
+ });
26696
+ }
26697
+ if (this.#active)
26698
+ await this.#fault(failure("OpenCode Session closed before native completion was confirmed", "processExited"));
26699
+ }
26700
+ this.#closed = true;
26701
+ if (this.#timer)
26702
+ clearInterval(this.#timer);
26703
+ this.#abort.abort();
26704
+ await this.connection.close();
26705
+ await this.#pump;
26706
+ this.#channel.end();
26707
+ this.onClosed();
26708
+ })();
26709
+ }
26710
+ };
26711
+
26712
+ // dist/v2/adapter.js
26713
+ var V2Adapter = class {
26714
+ options;
26715
+ harnessId = harnessId;
26716
+ commandCatalog = openCodeCommandCatalog;
26717
+ #connections = /* @__PURE__ */ new Set();
26718
+ #sessions = /* @__PURE__ */ new Set();
26719
+ #closed = false;
26720
+ constructor(options) {
26721
+ this.options = options;
26722
+ }
26723
+ async #catalog(client2, cwd) {
26724
+ return readCatalog(client2, cwd, this.options.startupTimeoutMs ?? 2e4);
26725
+ }
26726
+ async inspect(input = {}) {
26727
+ const cwd = input.cwd ?? process.cwd();
26728
+ const connection = new V2Connection(this.options, cwd);
26729
+ this.#connections.add(connection);
26730
+ try {
26731
+ if (this.#closed)
26732
+ throw new Error("OpenCode Adapter is closed");
26733
+ const client2 = await connection.client();
26734
+ const catalog = await this.#catalog(client2, cwd);
26735
+ return {
26736
+ status: "ready",
26737
+ catalog,
26738
+ capabilities: v2Capabilities(catalog),
26739
+ permissionModes: OPENCODE_PERMISSION_MODE_CATALOG
26740
+ };
26741
+ } catch (error51) {
26742
+ return {
26743
+ status: "error",
26744
+ error: {
26745
+ ...errorResult(error51).error,
26746
+ ...connection.stderrTail ? { stderrTail: connection.stderrTail } : {}
26747
+ }
26748
+ };
26749
+ } finally {
26750
+ await connection.close();
26751
+ this.#connections.delete(connection);
26752
+ }
26753
+ }
26754
+ async open(input) {
26755
+ try {
26756
+ input = { ...input, cwd: fs6.realpathSync(input.cwd) };
26757
+ } catch (error51) {
26758
+ return errorResult(error51);
26759
+ }
26760
+ const connection = new V2Connection({
26761
+ ...this.options,
26762
+ environment: { ...this.options.environment ?? process.env, ...input.environment }
26763
+ }, input.cwd);
26764
+ this.#connections.add(connection);
26765
+ let created;
26766
+ let client2;
26767
+ try {
26768
+ if (this.#closed)
26769
+ throw new Error("OpenCode Adapter is closed");
26770
+ if (!input.cwd)
26771
+ throw new Error("OpenCode requires a working directory");
26772
+ let policy = input.kind === "create" ? input.executionPolicy ?? "default" : "default";
26773
+ if (input.kind !== "create") {
26774
+ const locator = v2Locator(input.kind === "resume" ? input.nativeRef : input.sourceRef);
26775
+ if (!sameDirectory(locator.directory, input.cwd))
26776
+ throw new Error("OpenCode cannot resume or derive a Session across directories");
26777
+ policy = locator.executionPolicy;
26778
+ }
26779
+ client2 = await connection.client();
26780
+ const catalog = await this.#catalog(client2, input.cwd);
26781
+ let info;
26782
+ if (input.kind === "create") {
26783
+ const model = selectedModel(input, catalog);
26784
+ info = await client2.session.create({
26785
+ location: { directory: input.cwd },
26786
+ ...model ? { model } : {},
26787
+ permissions: v2Permissions([], input.permissionModeId ?? harnessPermissionModeIdSchema.parse(policy === "unattended-full-access" ? "allow" : "default"))
26788
+ });
26789
+ created = info.id;
26790
+ } else {
26791
+ const ref = input.kind === "resume" ? input.nativeRef : input.sourceRef;
26792
+ info = await client2.session.get({ sessionID: ref.nativeSessionId });
26793
+ if (info.id !== ref.nativeSessionId || !sameDirectory(info.location.directory, input.cwd))
26794
+ throw new Error("OpenCode returned a different Native Session or directory");
26795
+ if ((await client2.session.active())[info.id])
26796
+ throw new Error("OpenCode Session is already running");
26797
+ const source = await readHistory(client2, info, this.options.toolOutputLimit ?? 64e3);
26798
+ if (source.snapshot.turns.some((turn) => turn.outcome.status === "unknown"))
26799
+ throw new Error("OpenCode history contains an incomplete execution");
26800
+ if (input.kind !== "resume") {
26801
+ const parent = info;
26802
+ const turns = source.snapshot.turns;
26803
+ let count;
26804
+ if (input.kind === "rollbackLastTurn") {
26805
+ if (!turns.length)
26806
+ throw new Error("OpenCode history is empty");
26807
+ count = turns.length - 1;
26808
+ } else {
26809
+ if (input.checkpoint.harnessId !== harnessId || input.checkpoint.nativeSessionId !== info.id)
26810
+ throw new Error("Checkpoint belongs to another Session");
26811
+ count = turns.findIndex((turn) => turn.checkpoint?.checkpointId === input.checkpoint.checkpointId) + 1;
26812
+ if (!count || JSON.stringify(turns[count - 1]?.checkpoint) !== JSON.stringify(input.checkpoint))
26813
+ throw new Error("OpenCode checkpoint does not match native history");
26814
+ }
26815
+ const before = turns[count]?.nativeTurnRef.nativeTurnKey;
26816
+ info = await client2.session.fork({ sessionID: parent.id, ...before ? { before } : {} });
26817
+ if (info.id === parent.id)
26818
+ throw new Error("OpenCode fork returned its source Session");
26819
+ created = info.id;
26820
+ if (!sameDirectory(info.location.directory, parent.location.directory))
26821
+ throw new Error("OpenCode fork changed directory");
26822
+ await client2.session.update({
26823
+ sessionID: info.id,
26824
+ permissions: parent.permissions ?? []
26825
+ });
26826
+ if (parent.model)
26827
+ await client2.session.switchModel({ sessionID: info.id, model: parent.model });
26828
+ info = await client2.session.get({ sessionID: info.id });
26829
+ const derived = await readHistory(client2, info, this.options.toolOutputLimit ?? 64e3);
26830
+ if (historyContent(derived.snapshot, false) !== historyContent({ turns: turns.slice(0, count) }, false))
26831
+ throw new Error("OpenCode fork did not preserve the exact history prefix");
26832
+ if (!isDeepStrictEqual2(info.permissions ?? [], parent.permissions ?? []) || !isDeepStrictEqual2(info.model, parent.model))
26833
+ throw new Error("OpenCode fork did not preserve the current configuration");
26834
+ const currentParent = await client2.session.get({ sessionID: parent.id });
26835
+ if (!isDeepStrictEqual2(currentParent.model, parent.model) || !isDeepStrictEqual2(currentParent.permissions, parent.permissions) || !sameDirectory(currentParent.location.directory, parent.location.directory))
26836
+ throw new Error("OpenCode source configuration changed during derivation");
26837
+ const unchanged = await readHistory(client2, currentParent, this.options.toolOutputLimit ?? 64e3);
26838
+ if (historyContent(unchanged.snapshot) !== historyContent(source.snapshot))
26839
+ throw new Error("OpenCode source history changed during derivation");
26840
+ }
26841
+ }
26842
+ if (this.#closed)
26843
+ throw new Error("OpenCode Adapter closed during Session open");
26844
+ const session = new V2Session(client2, connection, info, catalog, policy, this.options.toolOutputLimit ?? 64e3, () => {
26845
+ this.#sessions.delete(session);
26846
+ this.#connections.delete(connection);
26847
+ });
26848
+ this.#sessions.add(session);
26849
+ try {
26850
+ await session.start();
26851
+ } catch (error51) {
26852
+ await session.close();
26853
+ throw error51;
26854
+ }
26855
+ return { ok: true, value: session };
26856
+ } catch (error51) {
26857
+ if (created && client2)
26858
+ await client2.session.remove({ sessionID: created }).catch(() => void 0);
26859
+ await connection.close();
26860
+ this.#connections.delete(connection);
26861
+ return errorResult(error51);
26862
+ }
26863
+ }
26864
+ async close() {
26865
+ this.#closed = true;
26866
+ await Promise.all([...this.#sessions].map((session) => session.close()));
26867
+ await Promise.all([...this.#connections].map((connection) => connection.close()));
26868
+ this.#sessions.clear();
26869
+ this.#connections.clear();
26870
+ }
26871
+ };
26872
+ function selectedModel(input, catalog) {
26873
+ const selected = input.model ?? catalog.defaultModel;
26874
+ if (!selected) {
26875
+ if (input.thinkingOptionId)
26876
+ throw new Error("Thinking selection requires a Model");
26877
+ return void 0;
26878
+ }
26879
+ const entry = catalog.models.find((model2) => model2.ref.id === selected.id);
26880
+ if (!entry)
26881
+ throw new Error("OpenCode Model is not available");
26882
+ if (input.thinkingOptionId && !entry.supportedThinkingOptionIds?.includes(input.thinkingOptionId))
26883
+ throw new Error("OpenCode Thinking option is not available for this Model");
26884
+ const model = decodeOpenCodeModelRef(selected);
26885
+ const variant = input.thinkingOptionId ? decodeOpenCodeVariant(input.thinkingOptionId) : void 0;
26886
+ return { providerID: model.providerID, id: model.modelID, ...variant ? { variant } : {} };
26887
+ }
26888
+ function historyContent(snapshot, identities = true) {
26889
+ return JSON.stringify(snapshot.turns.map((turn) => ({
26890
+ ...identities ? { key: turn.nativeTurnRef.nativeTurnKey } : {},
26891
+ input: turn.input,
26892
+ model: turn.model,
26893
+ checkpoint: Boolean(turn.checkpoint),
26894
+ items: identities ? turn.items : turn.items.map(({ item, ...rest }) => ({
26895
+ ...rest,
26896
+ item: { ...item, itemId: void 0 }
26897
+ })),
26898
+ outcome: turn.outcome
26899
+ })));
26900
+ }
26901
+
26902
+ // dist/versioned-adapter.js
26903
+ var OpenCodeAdapter2 = class {
26904
+ options;
26905
+ dependencies;
26906
+ harnessId = harnessId;
26907
+ commandCatalog = openCodeCommandCatalog;
26908
+ #adapters = /* @__PURE__ */ new Set();
26909
+ #closed = false;
26910
+ constructor(options = {}, dependencies) {
26911
+ this.options = options;
26912
+ this.dependencies = dependencies;
26913
+ }
26914
+ async #select(environment, input) {
26915
+ if (this.#closed)
26916
+ throw new Error("OpenCode Adapter is closed");
26917
+ const options = {
26918
+ ...this.options,
26919
+ environment: { ...this.options.environment ?? process.env, ...environment }
26920
+ };
26921
+ const detected = this.dependencies ? { executable: options.command, major: 1 } : await detectOpenCode(options);
26922
+ if (this.#closed)
26923
+ throw new Error("OpenCode Adapter closed during version detection");
26924
+ if (input && input.kind !== "create") {
26925
+ const ref = input.kind === "resume" ? input.nativeRef : input.sourceRef;
26926
+ const locator = ref.locator;
26927
+ const nativeMajor = locator && typeof locator === "object" && !Array.isArray(locator) && locator.protocol === 2 ? 2 : 1;
26928
+ if (nativeMajor !== detected.major)
26929
+ throw new Error(`This OpenCode Session requires v${nativeMajor}; selected CLI is v${detected.major}. Select the matching installation with CODEXHOST_OPENCODE_COMMAND. codexhost does not migrate histories.`);
26930
+ }
26931
+ const pinned = { ...options, ...detected.executable ? { command: detected.executable } : {} };
26932
+ const adapter = detected.major === 2 ? new V2Adapter(pinned) : new OpenCodeAdapter(pinned, this.dependencies);
26933
+ this.#adapters.add(adapter);
26934
+ return adapter;
26935
+ }
26936
+ async inspect(input = {}) {
26937
+ let adapter;
26938
+ try {
26939
+ adapter = await this.#select();
26940
+ return await adapter.inspect(input);
26941
+ } catch (error51) {
26942
+ return {
26943
+ status: error51 instanceof OpenCodeExecutableError ? "notInstalled" : "error",
26944
+ error: normalize(error51)
26945
+ };
26946
+ } finally {
26947
+ if (adapter) {
26948
+ await adapter.close();
26949
+ this.#adapters.delete(adapter);
26950
+ }
26951
+ }
26952
+ }
26953
+ async open(input) {
26954
+ let adapter;
26955
+ try {
26956
+ adapter = await this.#select(input.environment, input);
26957
+ const result = await adapter.open(input);
26958
+ if (!result.ok) {
26959
+ await adapter.close();
26960
+ this.#adapters.delete(adapter);
26961
+ }
26962
+ if (result.ok) {
26963
+ const owner = adapter;
26964
+ const close = result.value.close.bind(result.value);
26965
+ result.value.close = async () => {
26966
+ await close();
26967
+ this.#adapters.delete(owner);
26968
+ };
26969
+ }
26970
+ return result;
26971
+ } catch (error51) {
26972
+ if (adapter) {
26973
+ await adapter.close();
26974
+ this.#adapters.delete(adapter);
26975
+ }
26976
+ return { ok: false, error: normalize(error51) };
26977
+ }
26978
+ }
26979
+ async close() {
26980
+ this.#closed = true;
26981
+ await Promise.all([...this.#adapters].map((adapter) => adapter.close()));
26982
+ this.#adapters.clear();
26983
+ }
26984
+ };
26985
+ function normalize(error51) {
26986
+ return failure(error51 instanceof Error ? error51.message : String(error51), error51 instanceof OpenCodeExecutableError ? "notInstalled" : "unavailable");
26987
+ }
26988
+
23983
26989
  // dist/plugin.js
23984
26990
  var OPENCODE_COMMAND_ENV = "CODEXHOST_OPENCODE_COMMAND";
23985
26991
  function createHarnessAdapter(context) {
23986
26992
  const environment = { ...context.environment };
23987
- return new OpenCodeAdapter({
26993
+ return new OpenCodeAdapter2({
23988
26994
  ...environment[OPENCODE_COMMAND_ENV] ? { command: environment[OPENCODE_COMMAND_ENV] } : {},
23989
26995
  environment
23990
26996
  });