swixter 0.1.5 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +21 -0
  2. package/dist/cli/index.js +1376 -221
  3. package/package.json +3 -11
package/dist/cli/index.js CHANGED
@@ -47,7 +47,7 @@ var __export = (target, all) => {
47
47
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
48
48
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
49
49
 
50
- // node_modules/picocolors/picocolors.js
50
+ // ../../node_modules/picocolors/picocolors.js
51
51
  var require_picocolors = __commonJS((exports, module) => {
52
52
  var p = process || {};
53
53
  var argv = p.argv || [];
@@ -117,7 +117,7 @@ var require_picocolors = __commonJS((exports, module) => {
117
117
  module.exports.createColors = createColors;
118
118
  });
119
119
 
120
- // node_modules/sisteransi/src/index.js
120
+ // ../../node_modules/sisteransi/src/index.js
121
121
  var require_src = __commonJS((exports, module) => {
122
122
  var ESC = "\x1B";
123
123
  var CSI = `${ESC}[`;
@@ -175,7 +175,7 @@ var require_src = __commonJS((exports, module) => {
175
175
  module.exports = { cursor, scroll, erase, beep };
176
176
  });
177
177
 
178
- // node_modules/@clack/core/dist/index.mjs
178
+ // ../../node_modules/@clack/core/dist/index.mjs
179
179
  import { stdin as j, stdout as M } from "node:process";
180
180
  import * as g from "node:readline";
181
181
  import O from "node:readline";
@@ -632,7 +632,7 @@ var init_dist = __esm(() => {
632
632
  };
633
633
  });
634
634
 
635
- // node_modules/@clack/prompts/dist/index.mjs
635
+ // ../../node_modules/@clack/prompts/dist/index.mjs
636
636
  import y2 from "node:process";
637
637
  function ce() {
638
638
  return y2.platform !== "win32" ? y2.env.TERM !== "linux" : !!y2.env.CI || !!y2.env.WT_SESSION || !!y2.env.TERMINUS_SUBLIME || y2.env.ConEmuTask === "{cmd::Cmder}" || y2.env.TERM_PROGRAM === "Terminus-Sublime" || y2.env.TERM_PROGRAM === "vscode" || y2.env.TERM === "xterm-256color" || y2.env.TERM === "alacritty" || y2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
@@ -880,7 +880,7 @@ var init_dist2 = __esm(() => {
880
880
  J2 = `${import_picocolors2.default.gray(o)} `;
881
881
  });
882
882
 
883
- // node_modules/zod/v4/core/core.js
883
+ // ../../node_modules/zod/v4/core/core.js
884
884
  function $constructor(name, initializer, params) {
885
885
  function init(inst, def) {
886
886
  var _a;
@@ -949,7 +949,7 @@ var init_core = __esm(() => {
949
949
  globalConfig = {};
950
950
  });
951
951
 
952
- // node_modules/zod/v4/core/util.js
952
+ // ../../node_modules/zod/v4/core/util.js
953
953
  var exports_util = {};
954
954
  __export(exports_util, {
955
955
  unwrapMessage: () => unwrapMessage,
@@ -1580,7 +1580,7 @@ var init_util = __esm(() => {
1580
1580
  };
1581
1581
  });
1582
1582
 
1583
- // node_modules/zod/v4/core/errors.js
1583
+ // ../../node_modules/zod/v4/core/errors.js
1584
1584
  function flattenError(error, mapper = (issue2) => issue2.message) {
1585
1585
  const fieldErrors = {};
1586
1586
  const formErrors = [];
@@ -1721,7 +1721,7 @@ var init_errors = __esm(() => {
1721
1721
  $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
1722
1722
  });
1723
1723
 
1724
- // node_modules/zod/v4/core/parse.js
1724
+ // ../../node_modules/zod/v4/core/parse.js
1725
1725
  var _parse = (_Err) => (schema, value, _ctx, _params) => {
1726
1726
  const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
1727
1727
  const result = schema._zod.run({ value, issues: [] }, ctx);
@@ -1803,7 +1803,7 @@ var init_parse = __esm(() => {
1803
1803
  safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync($ZodRealError);
1804
1804
  });
1805
1805
 
1806
- // node_modules/zod/v4/core/regexes.js
1806
+ // ../../node_modules/zod/v4/core/regexes.js
1807
1807
  var exports_regexes = {};
1808
1808
  __export(exports_regexes, {
1809
1809
  xid: () => xid,
@@ -1954,7 +1954,7 @@ var init_regexes = __esm(() => {
1954
1954
  sha512_base64url = /* @__PURE__ */ fixedBase64url(86);
1955
1955
  });
1956
1956
 
1957
- // node_modules/zod/v4/core/checks.js
1957
+ // ../../node_modules/zod/v4/core/checks.js
1958
1958
  function handleCheckPropertyResult(result, payload, property) {
1959
1959
  if (result.issues.length) {
1960
1960
  payload.issues.push(...prefixIssues(property, result.issues));
@@ -2501,7 +2501,7 @@ var init_checks = __esm(() => {
2501
2501
  });
2502
2502
  });
2503
2503
 
2504
- // node_modules/zod/v4/core/doc.js
2504
+ // ../../node_modules/zod/v4/core/doc.js
2505
2505
  class Doc {
2506
2506
  constructor(args = []) {
2507
2507
  this.content = [];
@@ -2539,7 +2539,7 @@ class Doc {
2539
2539
  }
2540
2540
  }
2541
2541
 
2542
- // node_modules/zod/v4/core/versions.js
2542
+ // ../../node_modules/zod/v4/core/versions.js
2543
2543
  var version;
2544
2544
  var init_versions = __esm(() => {
2545
2545
  version = {
@@ -2549,7 +2549,7 @@ var init_versions = __esm(() => {
2549
2549
  };
2550
2550
  });
2551
2551
 
2552
- // node_modules/zod/v4/core/schemas.js
2552
+ // ../../node_modules/zod/v4/core/schemas.js
2553
2553
  function isValidBase64(data) {
2554
2554
  if (data === "")
2555
2555
  return true;
@@ -4396,7 +4396,7 @@ var init_schemas = __esm(() => {
4396
4396
  });
4397
4397
  });
4398
4398
 
4399
- // node_modules/zod/v4/locales/ar.js
4399
+ // ../../node_modules/zod/v4/locales/ar.js
4400
4400
  function ar_default() {
4401
4401
  return {
4402
4402
  localeError: error()
@@ -4516,7 +4516,7 @@ var init_ar = __esm(() => {
4516
4516
  init_util();
4517
4517
  });
4518
4518
 
4519
- // node_modules/zod/v4/locales/az.js
4519
+ // ../../node_modules/zod/v4/locales/az.js
4520
4520
  function az_default() {
4521
4521
  return {
4522
4522
  localeError: error2()
@@ -4635,7 +4635,7 @@ var init_az = __esm(() => {
4635
4635
  init_util();
4636
4636
  });
4637
4637
 
4638
- // node_modules/zod/v4/locales/be.js
4638
+ // ../../node_modules/zod/v4/locales/be.js
4639
4639
  function getBelarusianPlural(count, one, few, many) {
4640
4640
  const absCount = Math.abs(count);
4641
4641
  const lastDigit = absCount % 10;
@@ -4803,7 +4803,7 @@ var init_be = __esm(() => {
4803
4803
  init_util();
4804
4804
  });
4805
4805
 
4806
- // node_modules/zod/v4/locales/bg.js
4806
+ // ../../node_modules/zod/v4/locales/bg.js
4807
4807
  function bg_default() {
4808
4808
  return {
4809
4809
  localeError: error4()
@@ -4934,7 +4934,7 @@ var init_bg = __esm(() => {
4934
4934
  init_util();
4935
4935
  });
4936
4936
 
4937
- // node_modules/zod/v4/locales/ca.js
4937
+ // ../../node_modules/zod/v4/locales/ca.js
4938
4938
  function ca_default() {
4939
4939
  return {
4940
4940
  localeError: error5()
@@ -5055,7 +5055,7 @@ var init_ca = __esm(() => {
5055
5055
  init_util();
5056
5056
  });
5057
5057
 
5058
- // node_modules/zod/v4/locales/cs.js
5058
+ // ../../node_modules/zod/v4/locales/cs.js
5059
5059
  function cs_default() {
5060
5060
  return {
5061
5061
  localeError: error6()
@@ -5194,7 +5194,7 @@ var init_cs = __esm(() => {
5194
5194
  init_util();
5195
5195
  });
5196
5196
 
5197
- // node_modules/zod/v4/locales/da.js
5197
+ // ../../node_modules/zod/v4/locales/da.js
5198
5198
  function da_default() {
5199
5199
  return {
5200
5200
  localeError: error7()
@@ -5329,7 +5329,7 @@ var init_da = __esm(() => {
5329
5329
  init_util();
5330
5330
  });
5331
5331
 
5332
- // node_modules/zod/v4/locales/de.js
5332
+ // ../../node_modules/zod/v4/locales/de.js
5333
5333
  function de_default() {
5334
5334
  return {
5335
5335
  localeError: error8()
@@ -5449,7 +5449,7 @@ var init_de = __esm(() => {
5449
5449
  init_util();
5450
5450
  });
5451
5451
 
5452
- // node_modules/zod/v4/locales/en.js
5452
+ // ../../node_modules/zod/v4/locales/en.js
5453
5453
  function en_default() {
5454
5454
  return {
5455
5455
  localeError: error9()
@@ -5569,7 +5569,7 @@ var init_en = __esm(() => {
5569
5569
  init_util();
5570
5570
  });
5571
5571
 
5572
- // node_modules/zod/v4/locales/eo.js
5572
+ // ../../node_modules/zod/v4/locales/eo.js
5573
5573
  function eo_default() {
5574
5574
  return {
5575
5575
  localeError: error10()
@@ -5688,7 +5688,7 @@ var init_eo = __esm(() => {
5688
5688
  init_util();
5689
5689
  });
5690
5690
 
5691
- // node_modules/zod/v4/locales/es.js
5691
+ // ../../node_modules/zod/v4/locales/es.js
5692
5692
  function es_default() {
5693
5693
  return {
5694
5694
  localeError: error11()
@@ -5840,7 +5840,7 @@ var init_es = __esm(() => {
5840
5840
  init_util();
5841
5841
  });
5842
5842
 
5843
- // node_modules/zod/v4/locales/fa.js
5843
+ // ../../node_modules/zod/v4/locales/fa.js
5844
5844
  function fa_default() {
5845
5845
  return {
5846
5846
  localeError: error12()
@@ -5966,7 +5966,7 @@ var init_fa = __esm(() => {
5966
5966
  init_util();
5967
5967
  });
5968
5968
 
5969
- // node_modules/zod/v4/locales/fi.js
5969
+ // ../../node_modules/zod/v4/locales/fi.js
5970
5970
  function fi_default() {
5971
5971
  return {
5972
5972
  localeError: error13()
@@ -6092,7 +6092,7 @@ var init_fi = __esm(() => {
6092
6092
  init_util();
6093
6093
  });
6094
6094
 
6095
- // node_modules/zod/v4/locales/fr.js
6095
+ // ../../node_modules/zod/v4/locales/fr.js
6096
6096
  function fr_default() {
6097
6097
  return {
6098
6098
  localeError: error14()
@@ -6212,7 +6212,7 @@ var init_fr = __esm(() => {
6212
6212
  init_util();
6213
6213
  });
6214
6214
 
6215
- // node_modules/zod/v4/locales/fr-CA.js
6215
+ // ../../node_modules/zod/v4/locales/fr-CA.js
6216
6216
  function fr_CA_default() {
6217
6217
  return {
6218
6218
  localeError: error15()
@@ -6333,7 +6333,7 @@ var init_fr_CA = __esm(() => {
6333
6333
  init_util();
6334
6334
  });
6335
6335
 
6336
- // node_modules/zod/v4/locales/he.js
6336
+ // ../../node_modules/zod/v4/locales/he.js
6337
6337
  function he_default() {
6338
6338
  return {
6339
6339
  localeError: error16()
@@ -6453,7 +6453,7 @@ var init_he = __esm(() => {
6453
6453
  init_util();
6454
6454
  });
6455
6455
 
6456
- // node_modules/zod/v4/locales/hu.js
6456
+ // ../../node_modules/zod/v4/locales/hu.js
6457
6457
  function hu_default() {
6458
6458
  return {
6459
6459
  localeError: error17()
@@ -6573,7 +6573,7 @@ var init_hu = __esm(() => {
6573
6573
  init_util();
6574
6574
  });
6575
6575
 
6576
- // node_modules/zod/v4/locales/id.js
6576
+ // ../../node_modules/zod/v4/locales/id.js
6577
6577
  function id_default() {
6578
6578
  return {
6579
6579
  localeError: error18()
@@ -6693,7 +6693,7 @@ var init_id = __esm(() => {
6693
6693
  init_util();
6694
6694
  });
6695
6695
 
6696
- // node_modules/zod/v4/locales/is.js
6696
+ // ../../node_modules/zod/v4/locales/is.js
6697
6697
  function is_default() {
6698
6698
  return {
6699
6699
  localeError: error19()
@@ -6813,7 +6813,7 @@ var init_is = __esm(() => {
6813
6813
  init_util();
6814
6814
  });
6815
6815
 
6816
- // node_modules/zod/v4/locales/it.js
6816
+ // ../../node_modules/zod/v4/locales/it.js
6817
6817
  function it_default() {
6818
6818
  return {
6819
6819
  localeError: error20()
@@ -6933,7 +6933,7 @@ var init_it = __esm(() => {
6933
6933
  init_util();
6934
6934
  });
6935
6935
 
6936
- // node_modules/zod/v4/locales/ja.js
6936
+ // ../../node_modules/zod/v4/locales/ja.js
6937
6937
  function ja_default() {
6938
6938
  return {
6939
6939
  localeError: error21()
@@ -7052,7 +7052,7 @@ var init_ja = __esm(() => {
7052
7052
  init_util();
7053
7053
  });
7054
7054
 
7055
- // node_modules/zod/v4/locales/ka.js
7055
+ // ../../node_modules/zod/v4/locales/ka.js
7056
7056
  function ka_default() {
7057
7057
  return {
7058
7058
  localeError: error22()
@@ -7180,7 +7180,7 @@ var init_ka = __esm(() => {
7180
7180
  init_util();
7181
7181
  });
7182
7182
 
7183
- // node_modules/zod/v4/locales/km.js
7183
+ // ../../node_modules/zod/v4/locales/km.js
7184
7184
  function km_default() {
7185
7185
  return {
7186
7186
  localeError: error23()
@@ -7301,7 +7301,7 @@ var init_km = __esm(() => {
7301
7301
  init_util();
7302
7302
  });
7303
7303
 
7304
- // node_modules/zod/v4/locales/kh.js
7304
+ // ../../node_modules/zod/v4/locales/kh.js
7305
7305
  function kh_default() {
7306
7306
  return km_default();
7307
7307
  }
@@ -7309,7 +7309,7 @@ var init_kh = __esm(() => {
7309
7309
  init_km();
7310
7310
  });
7311
7311
 
7312
- // node_modules/zod/v4/locales/ko.js
7312
+ // ../../node_modules/zod/v4/locales/ko.js
7313
7313
  function ko_default() {
7314
7314
  return {
7315
7315
  localeError: error24()
@@ -7434,7 +7434,7 @@ var init_ko = __esm(() => {
7434
7434
  init_util();
7435
7435
  });
7436
7436
 
7437
- // node_modules/zod/v4/locales/lt.js
7437
+ // ../../node_modules/zod/v4/locales/lt.js
7438
7438
  function getUnitTypeFromNumber(number2) {
7439
7439
  const abs = Math.abs(number2);
7440
7440
  const last = abs % 10;
@@ -7664,7 +7664,7 @@ var init_lt = __esm(() => {
7664
7664
  init_util();
7665
7665
  });
7666
7666
 
7667
- // node_modules/zod/v4/locales/mk.js
7667
+ // ../../node_modules/zod/v4/locales/mk.js
7668
7668
  function mk_default() {
7669
7669
  return {
7670
7670
  localeError: error26()
@@ -7785,7 +7785,7 @@ var init_mk = __esm(() => {
7785
7785
  init_util();
7786
7786
  });
7787
7787
 
7788
- // node_modules/zod/v4/locales/ms.js
7788
+ // ../../node_modules/zod/v4/locales/ms.js
7789
7789
  function ms_default() {
7790
7790
  return {
7791
7791
  localeError: error27()
@@ -7905,7 +7905,7 @@ var init_ms = __esm(() => {
7905
7905
  init_util();
7906
7906
  });
7907
7907
 
7908
- // node_modules/zod/v4/locales/nl.js
7908
+ // ../../node_modules/zod/v4/locales/nl.js
7909
7909
  function nl_default() {
7910
7910
  return {
7911
7911
  localeError: error28()
@@ -8026,7 +8026,7 @@ var init_nl = __esm(() => {
8026
8026
  init_util();
8027
8027
  });
8028
8028
 
8029
- // node_modules/zod/v4/locales/no.js
8029
+ // ../../node_modules/zod/v4/locales/no.js
8030
8030
  function no_default() {
8031
8031
  return {
8032
8032
  localeError: error29()
@@ -8146,7 +8146,7 @@ var init_no = __esm(() => {
8146
8146
  init_util();
8147
8147
  });
8148
8148
 
8149
- // node_modules/zod/v4/locales/ota.js
8149
+ // ../../node_modules/zod/v4/locales/ota.js
8150
8150
  function ota_default() {
8151
8151
  return {
8152
8152
  localeError: error30()
@@ -8266,7 +8266,7 @@ var init_ota = __esm(() => {
8266
8266
  init_util();
8267
8267
  });
8268
8268
 
8269
- // node_modules/zod/v4/locales/ps.js
8269
+ // ../../node_modules/zod/v4/locales/ps.js
8270
8270
  function ps_default() {
8271
8271
  return {
8272
8272
  localeError: error31()
@@ -8392,7 +8392,7 @@ var init_ps = __esm(() => {
8392
8392
  init_util();
8393
8393
  });
8394
8394
 
8395
- // node_modules/zod/v4/locales/pl.js
8395
+ // ../../node_modules/zod/v4/locales/pl.js
8396
8396
  function pl_default() {
8397
8397
  return {
8398
8398
  localeError: error32()
@@ -8513,7 +8513,7 @@ var init_pl = __esm(() => {
8513
8513
  init_util();
8514
8514
  });
8515
8515
 
8516
- // node_modules/zod/v4/locales/pt.js
8516
+ // ../../node_modules/zod/v4/locales/pt.js
8517
8517
  function pt_default() {
8518
8518
  return {
8519
8519
  localeError: error33()
@@ -8633,7 +8633,7 @@ var init_pt = __esm(() => {
8633
8633
  init_util();
8634
8634
  });
8635
8635
 
8636
- // node_modules/zod/v4/locales/ru.js
8636
+ // ../../node_modules/zod/v4/locales/ru.js
8637
8637
  function getRussianPlural(count, one, few, many) {
8638
8638
  const absCount = Math.abs(count);
8639
8639
  const lastDigit = absCount % 10;
@@ -8801,7 +8801,7 @@ var init_ru = __esm(() => {
8801
8801
  init_util();
8802
8802
  });
8803
8803
 
8804
- // node_modules/zod/v4/locales/sl.js
8804
+ // ../../node_modules/zod/v4/locales/sl.js
8805
8805
  function sl_default() {
8806
8806
  return {
8807
8807
  localeError: error35()
@@ -8922,7 +8922,7 @@ var init_sl = __esm(() => {
8922
8922
  init_util();
8923
8923
  });
8924
8924
 
8925
- // node_modules/zod/v4/locales/sv.js
8925
+ // ../../node_modules/zod/v4/locales/sv.js
8926
8926
  function sv_default() {
8927
8927
  return {
8928
8928
  localeError: error36()
@@ -9044,7 +9044,7 @@ var init_sv = __esm(() => {
9044
9044
  init_util();
9045
9045
  });
9046
9046
 
9047
- // node_modules/zod/v4/locales/ta.js
9047
+ // ../../node_modules/zod/v4/locales/ta.js
9048
9048
  function ta_default() {
9049
9049
  return {
9050
9050
  localeError: error37()
@@ -9165,7 +9165,7 @@ var init_ta = __esm(() => {
9165
9165
  init_util();
9166
9166
  });
9167
9167
 
9168
- // node_modules/zod/v4/locales/th.js
9168
+ // ../../node_modules/zod/v4/locales/th.js
9169
9169
  function th_default() {
9170
9170
  return {
9171
9171
  localeError: error38()
@@ -9286,7 +9286,7 @@ var init_th = __esm(() => {
9286
9286
  init_util();
9287
9287
  });
9288
9288
 
9289
- // node_modules/zod/v4/locales/tr.js
9289
+ // ../../node_modules/zod/v4/locales/tr.js
9290
9290
  function tr_default() {
9291
9291
  return {
9292
9292
  localeError: error39()
@@ -9404,7 +9404,7 @@ var init_tr = __esm(() => {
9404
9404
  init_util();
9405
9405
  });
9406
9406
 
9407
- // node_modules/zod/v4/locales/uk.js
9407
+ // ../../node_modules/zod/v4/locales/uk.js
9408
9408
  function uk_default() {
9409
9409
  return {
9410
9410
  localeError: error40()
@@ -9524,7 +9524,7 @@ var init_uk = __esm(() => {
9524
9524
  init_util();
9525
9525
  });
9526
9526
 
9527
- // node_modules/zod/v4/locales/ua.js
9527
+ // ../../node_modules/zod/v4/locales/ua.js
9528
9528
  function ua_default() {
9529
9529
  return uk_default();
9530
9530
  }
@@ -9532,7 +9532,7 @@ var init_ua = __esm(() => {
9532
9532
  init_uk();
9533
9533
  });
9534
9534
 
9535
- // node_modules/zod/v4/locales/ur.js
9535
+ // ../../node_modules/zod/v4/locales/ur.js
9536
9536
  function ur_default() {
9537
9537
  return {
9538
9538
  localeError: error41()
@@ -9653,7 +9653,7 @@ var init_ur = __esm(() => {
9653
9653
  init_util();
9654
9654
  });
9655
9655
 
9656
- // node_modules/zod/v4/locales/vi.js
9656
+ // ../../node_modules/zod/v4/locales/vi.js
9657
9657
  function vi_default() {
9658
9658
  return {
9659
9659
  localeError: error42()
@@ -9773,7 +9773,7 @@ var init_vi = __esm(() => {
9773
9773
  init_util();
9774
9774
  });
9775
9775
 
9776
- // node_modules/zod/v4/locales/zh-CN.js
9776
+ // ../../node_modules/zod/v4/locales/zh-CN.js
9777
9777
  function zh_CN_default() {
9778
9778
  return {
9779
9779
  localeError: error43()
@@ -9893,7 +9893,7 @@ var init_zh_CN = __esm(() => {
9893
9893
  init_util();
9894
9894
  });
9895
9895
 
9896
- // node_modules/zod/v4/locales/zh-TW.js
9896
+ // ../../node_modules/zod/v4/locales/zh-TW.js
9897
9897
  function zh_TW_default() {
9898
9898
  return {
9899
9899
  localeError: error44()
@@ -10014,7 +10014,7 @@ var init_zh_TW = __esm(() => {
10014
10014
  init_util();
10015
10015
  });
10016
10016
 
10017
- // node_modules/zod/v4/locales/yo.js
10017
+ // ../../node_modules/zod/v4/locales/yo.js
10018
10018
  function yo_default() {
10019
10019
  return {
10020
10020
  localeError: error45()
@@ -10133,7 +10133,7 @@ var init_yo = __esm(() => {
10133
10133
  init_util();
10134
10134
  });
10135
10135
 
10136
- // node_modules/zod/v4/locales/index.js
10136
+ // ../../node_modules/zod/v4/locales/index.js
10137
10137
  var exports_locales = {};
10138
10138
  __export(exports_locales, {
10139
10139
  zhTW: () => zh_TW_default,
@@ -10234,7 +10234,7 @@ var init_locales = __esm(() => {
10234
10234
  init_yo();
10235
10235
  });
10236
10236
 
10237
- // node_modules/zod/v4/core/registries.js
10237
+ // ../../node_modules/zod/v4/core/registries.js
10238
10238
  class $ZodRegistry {
10239
10239
  constructor() {
10240
10240
  this._map = new WeakMap;
@@ -10288,7 +10288,7 @@ var init_registries = __esm(() => {
10288
10288
  globalRegistry = /* @__PURE__ */ registry();
10289
10289
  });
10290
10290
 
10291
- // node_modules/zod/v4/core/api.js
10291
+ // ../../node_modules/zod/v4/core/api.js
10292
10292
  function _string(Class2, params) {
10293
10293
  return new Class2({
10294
10294
  type: "string",
@@ -11173,7 +11173,7 @@ var init_api = __esm(() => {
11173
11173
  };
11174
11174
  });
11175
11175
 
11176
- // node_modules/zod/v4/core/to-json-schema.js
11176
+ // ../../node_modules/zod/v4/core/to-json-schema.js
11177
11177
  class JSONSchemaGenerator {
11178
11178
  constructor(params) {
11179
11179
  this.counter = 0;
@@ -11511,7 +11511,7 @@ class JSONSchemaGenerator {
11511
11511
  if (val === undefined) {
11512
11512
  if (this.unrepresentable === "throw") {
11513
11513
  throw new Error("Literal `undefined` cannot be represented in JSON Schema");
11514
- } else {}
11514
+ }
11515
11515
  } else if (typeof val === "bigint") {
11516
11516
  if (this.unrepresentable === "throw") {
11517
11517
  throw new Error("BigInt literals cannot be represented in JSON Schema");
@@ -11982,11 +11982,11 @@ var init_to_json_schema = __esm(() => {
11982
11982
  init_util();
11983
11983
  });
11984
11984
 
11985
- // node_modules/zod/v4/core/json-schema.js
11985
+ // ../../node_modules/zod/v4/core/json-schema.js
11986
11986
  var exports_json_schema = {};
11987
11987
  var init_json_schema = () => {};
11988
11988
 
11989
- // node_modules/zod/v4/core/index.js
11989
+ // ../../node_modules/zod/v4/core/index.js
11990
11990
  var exports_core2 = {};
11991
11991
  __export(exports_core2, {
11992
11992
  version: () => version,
@@ -12265,12 +12265,12 @@ var init_core2 = __esm(() => {
12265
12265
  init_to_json_schema();
12266
12266
  });
12267
12267
 
12268
- // node_modules/zod/v4/classic/checks.js
12268
+ // ../../node_modules/zod/v4/classic/checks.js
12269
12269
  var init_checks2 = __esm(() => {
12270
12270
  init_core2();
12271
12271
  });
12272
12272
 
12273
- // node_modules/zod/v4/classic/iso.js
12273
+ // ../../node_modules/zod/v4/classic/iso.js
12274
12274
  var exports_iso = {};
12275
12275
  __export(exports_iso, {
12276
12276
  time: () => time2,
@@ -12316,7 +12316,7 @@ var init_iso = __esm(() => {
12316
12316
  });
12317
12317
  });
12318
12318
 
12319
- // node_modules/zod/v4/classic/errors.js
12319
+ // ../../node_modules/zod/v4/classic/errors.js
12320
12320
  var initializer2 = (inst, issues) => {
12321
12321
  $ZodError.init(inst, issues);
12322
12322
  inst.name = "ZodError";
@@ -12356,7 +12356,7 @@ var init_errors2 = __esm(() => {
12356
12356
  });
12357
12357
  });
12358
12358
 
12359
- // node_modules/zod/v4/classic/parse.js
12359
+ // ../../node_modules/zod/v4/classic/parse.js
12360
12360
  var parse3, parseAsync2, safeParse2, safeParseAsync2, encode2, decode2, encodeAsync2, decodeAsync2, safeEncode2, safeDecode2, safeEncodeAsync2, safeDecodeAsync2;
12361
12361
  var init_parse2 = __esm(() => {
12362
12362
  init_core2();
@@ -12375,7 +12375,7 @@ var init_parse2 = __esm(() => {
12375
12375
  safeDecodeAsync2 = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
12376
12376
  });
12377
12377
 
12378
- // node_modules/zod/v4/classic/schemas.js
12378
+ // ../../node_modules/zod/v4/classic/schemas.js
12379
12379
  function string2(params) {
12380
12380
  return _string(ZodString, params);
12381
12381
  }
@@ -13350,7 +13350,7 @@ var init_schemas2 = __esm(() => {
13350
13350
  });
13351
13351
  });
13352
13352
 
13353
- // node_modules/zod/v4/classic/compat.js
13353
+ // ../../node_modules/zod/v4/classic/compat.js
13354
13354
  function setErrorMap(map2) {
13355
13355
  config({
13356
13356
  customError: map2
@@ -13378,7 +13378,7 @@ var init_compat = __esm(() => {
13378
13378
  (function(ZodFirstPartyTypeKind2) {})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
13379
13379
  });
13380
13380
 
13381
- // node_modules/zod/v4/classic/coerce.js
13381
+ // ../../node_modules/zod/v4/classic/coerce.js
13382
13382
  var exports_coerce = {};
13383
13383
  __export(exports_coerce, {
13384
13384
  string: () => string3,
@@ -13407,7 +13407,7 @@ var init_coerce = __esm(() => {
13407
13407
  init_schemas2();
13408
13408
  });
13409
13409
 
13410
- // node_modules/zod/v4/classic/external.js
13410
+ // ../../node_modules/zod/v4/classic/external.js
13411
13411
  var exports_external = {};
13412
13412
  __export(exports_external, {
13413
13413
  xid: () => xid2,
@@ -13653,7 +13653,7 @@ var init_external = __esm(() => {
13653
13653
  config(en_default());
13654
13654
  });
13655
13655
 
13656
- // node_modules/zod/index.js
13656
+ // ../../node_modules/zod/index.js
13657
13657
  var init_zod = __esm(() => {
13658
13658
  init_external();
13659
13659
  init_external();
@@ -13674,10 +13674,17 @@ var init_types = __esm(() => {
13674
13674
  });
13675
13675
 
13676
13676
  // src/types.ts
13677
- var ProviderPresetSchema, ClaudeCodeProfileSchema, CoderConfigSchema, SyncMetaSchema, ConfigFileSchema, ExportConfigSchema;
13677
+ var API_FORMATS, ProviderPresetSchema, ClaudeCodeProfileSchema, CoderConfigSchema, SyncMetaSchema, ConfigFileSchema, ExportConfigSchema;
13678
13678
  var init_types2 = __esm(() => {
13679
13679
  init_zod();
13680
13680
  init_types();
13681
+ API_FORMATS = [
13682
+ "anthropic_messages",
13683
+ "anthropic_responses",
13684
+ "openai_chat",
13685
+ "openai_responses",
13686
+ "gemini_native"
13687
+ ];
13681
13688
  ProviderPresetSchema = exports_external.object({
13682
13689
  id: exports_external.string(),
13683
13690
  name: exports_external.string(),
@@ -13692,6 +13699,14 @@ var init_types2 = __esm(() => {
13692
13699
  }).optional(),
13693
13700
  docs: exports_external.string().url().optional(),
13694
13701
  isChinese: exports_external.boolean().optional(),
13702
+ defaultApiFormat: exports_external.enum([
13703
+ "anthropic_messages",
13704
+ "anthropic_responses",
13705
+ "openai_chat",
13706
+ "openai_responses",
13707
+ "gemini_native"
13708
+ ]).optional(),
13709
+ baseURLChat: exports_external.string().optional(),
13695
13710
  wire_api: exports_external.enum(["chat", "responses"]).optional(),
13696
13711
  env_key: exports_external.string().optional(),
13697
13712
  modelFamilies: exports_external.array(exports_external.object({
@@ -13716,6 +13731,13 @@ var init_types2 = __esm(() => {
13716
13731
  }).optional(),
13717
13732
  envKey: exports_external.string().optional(),
13718
13733
  headers: exports_external.record(exports_external.string(), exports_external.string()).optional(),
13734
+ apiFormat: exports_external.enum([
13735
+ "anthropic_messages",
13736
+ "anthropic_responses",
13737
+ "openai_chat",
13738
+ "openai_responses",
13739
+ "gemini_native"
13740
+ ]).optional(),
13719
13741
  createdAt: exports_external.string(),
13720
13742
  updatedAt: exports_external.string()
13721
13743
  });
@@ -13999,7 +14021,7 @@ var CONFIG_VERSION = "2.0.0", EXPORT_VERSION = "1.0.0";
13999
14021
  var init_versions2 = () => {};
14000
14022
 
14001
14023
  // src/constants/meta.ts
14002
- var APP_VERSION = "0.1.5";
14024
+ var APP_VERSION = "0.1.8";
14003
14025
  var init_meta = () => {};
14004
14026
 
14005
14027
  // src/constants/install.ts
@@ -14320,6 +14342,7 @@ var init_presets = __esm(() => {
14320
14342
  "anthropic-version": "2023-06-01"
14321
14343
  },
14322
14344
  docs: "https://docs.anthropic.com/",
14345
+ defaultApiFormat: "anthropic_messages",
14323
14346
  wire_api: "responses",
14324
14347
  env_key: "ANTHROPIC_API_KEY"
14325
14348
  };
@@ -14337,6 +14360,7 @@ var init_presets = __esm(() => {
14337
14360
  ],
14338
14361
  authType: "custom",
14339
14362
  docs: "https://ollama.com/library",
14363
+ defaultApiFormat: "openai_chat",
14340
14364
  wire_api: "chat",
14341
14365
  env_key: "OLLAMA_API_KEY"
14342
14366
  };
@@ -14352,6 +14376,7 @@ var init_presets = __esm(() => {
14352
14376
  ],
14353
14377
  authType: "api-key",
14354
14378
  docs: "https://console.groq.com/docs",
14379
+ defaultApiFormat: "openai_chat",
14355
14380
  wire_api: "chat",
14356
14381
  env_key: "GROQ_API_KEY"
14357
14382
  };
@@ -14367,6 +14392,7 @@ var init_presets = __esm(() => {
14367
14392
  ],
14368
14393
  authType: "api-key",
14369
14394
  docs: "https://platform.deepseek.com/",
14395
+ defaultApiFormat: "anthropic_messages",
14370
14396
  wire_api: "chat",
14371
14397
  env_key: "DEEPSEEK_API_KEY"
14372
14398
  };
@@ -14382,6 +14408,7 @@ var init_presets = __esm(() => {
14382
14408
  ],
14383
14409
  authType: "api-key",
14384
14410
  docs: "https://platform.moonshot.cn/",
14411
+ defaultApiFormat: "openai_chat",
14385
14412
  wire_api: "chat",
14386
14413
  env_key: "MOONSHOT_API_KEY"
14387
14414
  };
@@ -14393,6 +14420,7 @@ var init_presets = __esm(() => {
14393
14420
  defaultModels: [],
14394
14421
  authType: "api-key",
14395
14422
  docs: "https://docs.together.ai/",
14423
+ defaultApiFormat: "openai_chat",
14396
14424
  wire_api: "chat",
14397
14425
  env_key: "TOGETHER_API_KEY"
14398
14426
  };
@@ -14407,6 +14435,7 @@ var init_presets = __esm(() => {
14407
14435
  ],
14408
14436
  authType: "api-key",
14409
14437
  docs: "https://docs.fireworks.ai/",
14438
+ defaultApiFormat: "openai_chat",
14410
14439
  wire_api: "chat",
14411
14440
  env_key: "FIREWORKS_API_KEY"
14412
14441
  };
@@ -14421,6 +14450,7 @@ var init_presets = __esm(() => {
14421
14450
  ],
14422
14451
  authType: "api-key",
14423
14452
  docs: "https://platform.01.ai/",
14453
+ defaultApiFormat: "openai_chat",
14424
14454
  wire_api: "chat",
14425
14455
  env_key: "ZEROONE_API_KEY"
14426
14456
  };
@@ -14434,6 +14464,7 @@ var init_presets = __esm(() => {
14434
14464
  ],
14435
14465
  authType: "api-key",
14436
14466
  docs: "https://platform.minimaxi.com/",
14467
+ defaultApiFormat: "anthropic_messages",
14437
14468
  wire_api: "responses",
14438
14469
  env_key: "ANTHROPIC_API_KEY",
14439
14470
  isChinese: true
@@ -14448,6 +14479,7 @@ var init_presets = __esm(() => {
14448
14479
  ],
14449
14480
  authType: "api-key",
14450
14481
  docs: "https://platform.minimax.io/",
14482
+ defaultApiFormat: "anthropic_messages",
14451
14483
  wire_api: "responses",
14452
14484
  env_key: "ANTHROPIC_API_KEY"
14453
14485
  };
@@ -14462,6 +14494,7 @@ var init_presets = __esm(() => {
14462
14494
  ],
14463
14495
  authType: "api-key",
14464
14496
  docs: "https://open.bigmodel.cn/",
14497
+ defaultApiFormat: "anthropic_messages",
14465
14498
  wire_api: "responses",
14466
14499
  env_key: "ANTHROPIC_API_KEY",
14467
14500
  isChinese: true
@@ -14477,6 +14510,7 @@ var init_presets = __esm(() => {
14477
14510
  ],
14478
14511
  authType: "api-key",
14479
14512
  docs: "https://docs.z.ai/",
14513
+ defaultApiFormat: "anthropic_messages",
14480
14514
  wire_api: "responses",
14481
14515
  env_key: "ANTHROPIC_AUTH_TOKEN"
14482
14516
  };
@@ -14491,6 +14525,7 @@ var init_presets = __esm(() => {
14491
14525
  ],
14492
14526
  authType: "api-key",
14493
14527
  docs: "https://bailian.console.aliyun.com/",
14528
+ defaultApiFormat: "openai_chat",
14494
14529
  wire_api: "chat",
14495
14530
  env_key: "DASHSCOPE_API_KEY",
14496
14531
  isChinese: true
@@ -14514,6 +14549,7 @@ var init_presets = __esm(() => {
14514
14549
  defaultModels: ["step-3.5-flash"],
14515
14550
  authType: "api-key",
14516
14551
  docs: "https://platform.stepfun.ai",
14552
+ defaultApiFormat: "openai_chat",
14517
14553
  wire_api: "chat",
14518
14554
  env_key: "ANTHROPIC_AUTH_TOKEN",
14519
14555
  isChinese: true
@@ -14526,6 +14562,7 @@ var init_presets = __esm(() => {
14526
14562
  defaultModels: ["ZhipuAI/GLM-5"],
14527
14563
  authType: "api-key",
14528
14564
  docs: "https://modelscope.cn",
14565
+ defaultApiFormat: "anthropic_messages",
14529
14566
  wire_api: "responses",
14530
14567
  env_key: "ANTHROPIC_AUTH_TOKEN",
14531
14568
  isChinese: true
@@ -14538,6 +14575,7 @@ var init_presets = __esm(() => {
14538
14575
  defaultModels: ["LongCat-Flash-Chat"],
14539
14576
  authType: "api-key",
14540
14577
  docs: "https://longcat.chat/platform",
14578
+ defaultApiFormat: "anthropic_messages",
14541
14579
  wire_api: "responses",
14542
14580
  env_key: "ANTHROPIC_AUTH_TOKEN",
14543
14581
  isChinese: true
@@ -14550,6 +14588,7 @@ var init_presets = __esm(() => {
14550
14588
  defaultModels: ["Ling-2.5-1T"],
14551
14589
  authType: "api-key",
14552
14590
  docs: "https://alipaytbox.yuque.com/sxs0ba/ling/get_started",
14591
+ defaultApiFormat: "anthropic_messages",
14553
14592
  wire_api: "responses",
14554
14593
  env_key: "ANTHROPIC_AUTH_TOKEN",
14555
14594
  isChinese: true
@@ -14562,6 +14601,7 @@ var init_presets = __esm(() => {
14562
14601
  defaultModels: ["Pro/MiniMaxAI/MiniMax-M2.7"],
14563
14602
  authType: "api-key",
14564
14603
  docs: "https://siliconflow.cn",
14604
+ defaultApiFormat: "anthropic_messages",
14565
14605
  wire_api: "responses",
14566
14606
  env_key: "ANTHROPIC_AUTH_TOKEN",
14567
14607
  isChinese: true
@@ -14574,6 +14614,7 @@ var init_presets = __esm(() => {
14574
14614
  defaultModels: ["MiniMaxAI/MiniMax-M2.7"],
14575
14615
  authType: "api-key",
14576
14616
  docs: "https://siliconflow.com",
14617
+ defaultApiFormat: "anthropic_messages",
14577
14618
  wire_api: "responses",
14578
14619
  env_key: "ANTHROPIC_AUTH_TOKEN"
14579
14620
  };
@@ -14585,6 +14626,7 @@ var init_presets = __esm(() => {
14585
14626
  defaultModels: [],
14586
14627
  authType: "api-key",
14587
14628
  docs: "https://www.dmxapi.cn",
14629
+ defaultApiFormat: "anthropic_messages",
14588
14630
  wire_api: "responses",
14589
14631
  env_key: "ANTHROPIC_AUTH_TOKEN",
14590
14632
  isChinese: true
@@ -14597,6 +14639,7 @@ var init_presets = __esm(() => {
14597
14639
  defaultModels: [],
14598
14640
  authType: "api-key",
14599
14641
  docs: "https://www.packyapi.com",
14642
+ defaultApiFormat: "anthropic_messages",
14600
14643
  wire_api: "responses",
14601
14644
  env_key: "ANTHROPIC_AUTH_TOKEN",
14602
14645
  isChinese: true
@@ -14609,6 +14652,7 @@ var init_presets = __esm(() => {
14609
14652
  defaultModels: [],
14610
14653
  authType: "api-key",
14611
14654
  docs: "https://cubence.com",
14655
+ defaultApiFormat: "anthropic_messages",
14612
14656
  wire_api: "responses",
14613
14657
  env_key: "ANTHROPIC_AUTH_TOKEN",
14614
14658
  isChinese: true
@@ -14621,6 +14665,7 @@ var init_presets = __esm(() => {
14621
14665
  defaultModels: [],
14622
14666
  authType: "api-key",
14623
14667
  docs: "https://aigocode.com",
14668
+ defaultApiFormat: "anthropic_messages",
14624
14669
  wire_api: "responses",
14625
14670
  env_key: "ANTHROPIC_AUTH_TOKEN",
14626
14671
  isChinese: true
@@ -14633,6 +14678,7 @@ var init_presets = __esm(() => {
14633
14678
  defaultModels: [],
14634
14679
  authType: "api-key",
14635
14680
  docs: "https://www.right.codes",
14681
+ defaultApiFormat: "anthropic_messages",
14636
14682
  wire_api: "responses",
14637
14683
  env_key: "ANTHROPIC_AUTH_TOKEN",
14638
14684
  isChinese: true
@@ -14645,6 +14691,7 @@ var init_presets = __esm(() => {
14645
14691
  defaultModels: [],
14646
14692
  authType: "api-key",
14647
14693
  docs: "https://www.aicodemirror.com",
14694
+ defaultApiFormat: "anthropic_messages",
14648
14695
  wire_api: "responses",
14649
14696
  env_key: "ANTHROPIC_AUTH_TOKEN",
14650
14697
  isChinese: true
@@ -14657,6 +14704,7 @@ var init_presets = __esm(() => {
14657
14704
  defaultModels: [],
14658
14705
  authType: "api-key",
14659
14706
  docs: "https://aicoding.sh",
14707
+ defaultApiFormat: "anthropic_messages",
14660
14708
  wire_api: "responses",
14661
14709
  env_key: "ANTHROPIC_AUTH_TOKEN",
14662
14710
  isChinese: true
@@ -14669,6 +14717,7 @@ var init_presets = __esm(() => {
14669
14717
  defaultModels: [],
14670
14718
  authType: "api-key",
14671
14719
  docs: "https://www.crazyrouter.com",
14720
+ defaultApiFormat: "anthropic_messages",
14672
14721
  wire_api: "responses",
14673
14722
  env_key: "ANTHROPIC_AUTH_TOKEN",
14674
14723
  isChinese: true
@@ -14681,6 +14730,7 @@ var init_presets = __esm(() => {
14681
14730
  defaultModels: [],
14682
14731
  authType: "api-key",
14683
14732
  docs: "https://www.sssaicode.com",
14733
+ defaultApiFormat: "anthropic_messages",
14684
14734
  wire_api: "responses",
14685
14735
  env_key: "ANTHROPIC_AUTH_TOKEN",
14686
14736
  isChinese: true
@@ -14693,6 +14743,7 @@ var init_presets = __esm(() => {
14693
14743
  defaultModels: [],
14694
14744
  authType: "api-key",
14695
14745
  docs: "https://www.compshare.cn",
14746
+ defaultApiFormat: "anthropic_messages",
14696
14747
  wire_api: "responses",
14697
14748
  env_key: "ANTHROPIC_AUTH_TOKEN",
14698
14749
  isChinese: true
@@ -14705,6 +14756,7 @@ var init_presets = __esm(() => {
14705
14756
  defaultModels: [],
14706
14757
  authType: "api-key",
14707
14758
  docs: "https://www.openclaudecode.cn",
14759
+ defaultApiFormat: "anthropic_messages",
14708
14760
  wire_api: "responses",
14709
14761
  env_key: "ANTHROPIC_AUTH_TOKEN",
14710
14762
  isChinese: true
@@ -14717,6 +14769,7 @@ var init_presets = __esm(() => {
14717
14769
  defaultModels: [],
14718
14770
  authType: "api-key",
14719
14771
  docs: "https://x-code.cc",
14772
+ defaultApiFormat: "anthropic_messages",
14720
14773
  wire_api: "responses",
14721
14774
  env_key: "ANTHROPIC_AUTH_TOKEN",
14722
14775
  isChinese: true
@@ -14729,6 +14782,7 @@ var init_presets = __esm(() => {
14729
14782
  defaultModels: [],
14730
14783
  authType: "api-key",
14731
14784
  docs: "https://ctok.ai",
14785
+ defaultApiFormat: "anthropic_messages",
14732
14786
  wire_api: "responses",
14733
14787
  env_key: "ANTHROPIC_AUTH_TOKEN",
14734
14788
  isChinese: true
@@ -14742,6 +14796,7 @@ var init_presets = __esm(() => {
14742
14796
  defaultModels: ["anthropic/claude-sonnet-4.6"],
14743
14797
  authType: "api-key",
14744
14798
  docs: "https://openrouter.ai",
14799
+ defaultApiFormat: "anthropic_messages",
14745
14800
  wire_api: "chat",
14746
14801
  env_key: "OPENAI_API_KEY"
14747
14802
  };
@@ -14753,6 +14808,7 @@ var init_presets = __esm(() => {
14753
14808
  defaultModels: ["zai-org/glm-5"],
14754
14809
  authType: "api-key",
14755
14810
  docs: "https://novita.ai",
14811
+ defaultApiFormat: "anthropic_messages",
14756
14812
  wire_api: "responses",
14757
14813
  env_key: "ANTHROPIC_AUTH_TOKEN"
14758
14814
  };
@@ -14764,6 +14820,7 @@ var init_presets = __esm(() => {
14764
14820
  defaultModels: ["claude-opus-4.6"],
14765
14821
  authType: "api-key",
14766
14822
  docs: "https://github.com/features/copilot",
14823
+ defaultApiFormat: "openai_chat",
14767
14824
  wire_api: "chat",
14768
14825
  env_key: "ANTHROPIC_AUTH_TOKEN"
14769
14826
  };
@@ -14775,6 +14832,7 @@ var init_presets = __esm(() => {
14775
14832
  defaultModels: ["moonshotai/kimi-k2.5"],
14776
14833
  authType: "api-key",
14777
14834
  docs: "https://build.nvidia.com",
14835
+ defaultApiFormat: "openai_chat",
14778
14836
  wire_api: "chat",
14779
14837
  env_key: "ANTHROPIC_AUTH_TOKEN"
14780
14838
  };
@@ -14786,6 +14844,7 @@ var init_presets = __esm(() => {
14786
14844
  defaultModels: ["mimo-v2-pro"],
14787
14845
  authType: "api-key",
14788
14846
  docs: "https://platform.xiaomimimo.com",
14847
+ defaultApiFormat: "anthropic_messages",
14789
14848
  wire_api: "responses",
14790
14849
  env_key: "ANTHROPIC_AUTH_TOKEN",
14791
14850
  isChinese: true
@@ -14798,6 +14857,7 @@ var init_presets = __esm(() => {
14798
14857
  defaultModels: [],
14799
14858
  authType: "api-key",
14800
14859
  docs: "https://bailian.console.aliyun.com",
14860
+ defaultApiFormat: "anthropic_messages",
14801
14861
  wire_api: "responses",
14802
14862
  env_key: "ANTHROPIC_AUTH_TOKEN",
14803
14863
  isChinese: true
@@ -14810,6 +14870,7 @@ var init_presets = __esm(() => {
14810
14870
  defaultModels: [],
14811
14871
  authType: "api-key",
14812
14872
  docs: "https://www.kimi.com/coding/docs/",
14873
+ defaultApiFormat: "anthropic_messages",
14813
14874
  wire_api: "responses",
14814
14875
  env_key: "ANTHROPIC_AUTH_TOKEN",
14815
14876
  isChinese: true
@@ -14822,6 +14883,7 @@ var init_presets = __esm(() => {
14822
14883
  defaultModels: ["doubao-seed-2-0-code-preview-latest"],
14823
14884
  authType: "api-key",
14824
14885
  docs: "https://www.volcengine.com/product/doubao",
14886
+ defaultApiFormat: "anthropic_messages",
14825
14887
  wire_api: "responses",
14826
14888
  env_key: "ANTHROPIC_AUTH_TOKEN",
14827
14889
  isChinese: true
@@ -14834,6 +14896,7 @@ var init_presets = __esm(() => {
14834
14896
  defaultModels: [],
14835
14897
  authType: "api-key",
14836
14898
  docs: "https://aihubmix.com",
14899
+ defaultApiFormat: "anthropic_messages",
14837
14900
  wire_api: "responses",
14838
14901
  env_key: "ANTHROPIC_API_KEY",
14839
14902
  isChinese: true
@@ -15026,7 +15089,7 @@ var init_claude = __esm(() => {
15026
15089
  init_model_helper();
15027
15090
  });
15028
15091
 
15029
- // node_modules/js-yaml/dist/js-yaml.mjs
15092
+ // ../../node_modules/js-yaml/dist/js-yaml.mjs
15030
15093
  function isNothing(subject) {
15031
15094
  return typeof subject === "undefined" || subject === null;
15032
15095
  }
@@ -17753,7 +17816,7 @@ var init_continue = __esm(() => {
17753
17816
  };
17754
17817
  });
17755
17818
 
17756
- // node_modules/smol-toml/dist/error.js
17819
+ // ../../node_modules/smol-toml/dist/error.js
17757
17820
  function getLineColFromPtr(string4, ptr) {
17758
17821
  let lines = string4.slice(0, ptr).split(/\r\n|\n|\r/g);
17759
17822
  return [lines.length, lines.pop().length + 1];
@@ -17825,7 +17888,7 @@ ${codeblock}`, options);
17825
17888
  };
17826
17889
  });
17827
17890
 
17828
- // node_modules/smol-toml/dist/util.js
17891
+ // ../../node_modules/smol-toml/dist/util.js
17829
17892
  function isEscaped(str2, ptr) {
17830
17893
  let i2 = 0;
17831
17894
  while (str2[ptr - ++i2] === "\\")
@@ -17936,7 +17999,7 @@ var init_util2 = __esm(() => {
17936
17999
  */
17937
18000
  });
17938
18001
 
17939
- // node_modules/smol-toml/dist/date.js
18002
+ // ../../node_modules/smol-toml/dist/date.js
17940
18003
  var DATE_TIME_RE, TomlDate;
17941
18004
  var init_date = __esm(() => {
17942
18005
  /*!
@@ -18058,7 +18121,7 @@ var init_date = __esm(() => {
18058
18121
  };
18059
18122
  });
18060
18123
 
18061
- // node_modules/smol-toml/dist/primitive.js
18124
+ // ../../node_modules/smol-toml/dist/primitive.js
18062
18125
  function parseString(str2, ptr = 0, endPtr = str2.length) {
18063
18126
  let isLiteral = str2[ptr] === "'";
18064
18127
  let isMultiline = str2[ptr++] === str2[ptr] && str2[ptr] === str2[ptr + 1];
@@ -18235,7 +18298,7 @@ var init_primitive = __esm(() => {
18235
18298
  };
18236
18299
  });
18237
18300
 
18238
- // node_modules/smol-toml/dist/extract.js
18301
+ // ../../node_modules/smol-toml/dist/extract.js
18239
18302
  function sliceAndTrimEndOf(str2, startPtr, endPtr, allowNewLines) {
18240
18303
  let value = str2.slice(startPtr, endPtr);
18241
18304
  let commentIdx = value.indexOf("#");
@@ -18346,7 +18409,7 @@ var init_extract = __esm(() => {
18346
18409
  */
18347
18410
  });
18348
18411
 
18349
- // node_modules/smol-toml/dist/struct.js
18412
+ // ../../node_modules/smol-toml/dist/struct.js
18350
18413
  function parseKey(str2, ptr, end = "=") {
18351
18414
  let dot = ptr - 1;
18352
18415
  let parsed = [];
@@ -18538,7 +18601,7 @@ var init_struct = __esm(() => {
18538
18601
  KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
18539
18602
  });
18540
18603
 
18541
- // node_modules/smol-toml/dist/parse.js
18604
+ // ../../node_modules/smol-toml/dist/parse.js
18542
18605
  function peekTable(key, table, meta2, type2) {
18543
18606
  let t = table;
18544
18607
  let m2 = meta2;
@@ -18685,7 +18748,7 @@ var init_parse3 = __esm(() => {
18685
18748
  */
18686
18749
  });
18687
18750
 
18688
- // node_modules/smol-toml/dist/stringify.js
18751
+ // ../../node_modules/smol-toml/dist/stringify.js
18689
18752
  function extendedTypeOf(obj) {
18690
18753
  let type2 = typeof obj;
18691
18754
  if (type2 === "object") {
@@ -18862,7 +18925,7 @@ var init_stringify = __esm(() => {
18862
18925
  BARE_KEY = /^[a-z0-9-_]+$/i;
18863
18926
  });
18864
18927
 
18865
- // node_modules/smol-toml/dist/index.js
18928
+ // ../../node_modules/smol-toml/dist/index.js
18866
18929
  var init_dist3 = __esm(() => {
18867
18930
  init_parse3();
18868
18931
  init_stringify();
@@ -18915,7 +18978,7 @@ var init_env_key_helper = __esm(() => {
18915
18978
  });
18916
18979
 
18917
18980
  // src/adapters/codex.ts
18918
- import { mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
18981
+ import { mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4, unlink } from "node:fs/promises";
18919
18982
  import { existsSync as existsSync4 } from "node:fs";
18920
18983
  import { homedir as homedir2 } from "node:os";
18921
18984
  import { join as join3, dirname as dirname4 } from "node:path";
@@ -18923,8 +18986,10 @@ import { join as join3, dirname as dirname4 } from "node:path";
18923
18986
  class CodexAdapter {
18924
18987
  name = "codex";
18925
18988
  configPath;
18989
+ authPath;
18926
18990
  constructor() {
18927
18991
  this.configPath = join3(homedir2(), ".codex", "config.toml");
18992
+ this.authPath = join3(homedir2(), ".codex", "auth.json");
18928
18993
  }
18929
18994
  async apply(profile) {
18930
18995
  try {
@@ -18962,6 +19027,7 @@ class CodexAdapter {
18962
19027
  config2.model_provider = providerName;
18963
19028
  const tomlContent = stringify(config2);
18964
19029
  await writeFile4(this.configPath, tomlContent, "utf-8");
19030
+ await this.writeAuthJson(profile);
18965
19031
  } catch (error46) {
18966
19032
  throw new Error(`Failed to apply Codex configuration: ${error46 instanceof Error ? error46.message : String(error46)}`);
18967
19033
  }
@@ -18984,6 +19050,22 @@ class CodexAdapter {
18984
19050
  if (!config2.model_providers || !config2.model_providers[providerName]) {
18985
19051
  return false;
18986
19052
  }
19053
+ if (profile.apiKey) {
19054
+ const envKey = await getEnvKey(profile);
19055
+ if (existsSync4(this.authPath)) {
19056
+ try {
19057
+ const authContent = await readFile4(this.authPath, "utf-8");
19058
+ const auth = JSON.parse(authContent);
19059
+ if (auth[envKey] !== profile.apiKey) {
19060
+ return false;
19061
+ }
19062
+ } catch {
19063
+ return false;
19064
+ }
19065
+ } else {
19066
+ return false;
19067
+ }
19068
+ }
18987
19069
  return true;
18988
19070
  } catch (error46) {
18989
19071
  return false;
@@ -18994,7 +19076,8 @@ class CodexAdapter {
18994
19076
  const providerTable = {
18995
19077
  name: preset.displayName,
18996
19078
  base_url: profile.baseURL || baseUrl,
18997
- wire_api: preset.wire_api || "chat"
19079
+ wire_api: "responses",
19080
+ requires_openai_auth: true
18998
19081
  };
18999
19082
  providerTable.env_key = await getEnvKey(profile);
19000
19083
  if (preset.headers) {
@@ -19017,6 +19100,31 @@ class CodexAdapter {
19017
19100
  }
19018
19101
  return profileTable;
19019
19102
  }
19103
+ async writeAuthJson(profile) {
19104
+ const envKey = await getEnvKey(profile);
19105
+ let auth = {};
19106
+ if (existsSync4(this.authPath)) {
19107
+ try {
19108
+ const content = await readFile4(this.authPath, "utf-8");
19109
+ const parsed = JSON.parse(content);
19110
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
19111
+ auth = parsed;
19112
+ }
19113
+ } catch {
19114
+ auth = {};
19115
+ }
19116
+ }
19117
+ if (profile.apiKey) {
19118
+ auth[envKey] = profile.apiKey;
19119
+ } else {
19120
+ delete auth[envKey];
19121
+ }
19122
+ if (Object.keys(auth).length > 0) {
19123
+ await writeFile4(this.authPath, JSON.stringify(auth, null, 2), "utf-8");
19124
+ } else if (existsSync4(this.authPath)) {
19125
+ await unlink(this.authPath);
19126
+ }
19127
+ }
19020
19128
  async getEnvExportCommands(profile) {
19021
19129
  const commands = await getEnvExportCommands(profile);
19022
19130
  const modelValue = getOpenAIModel(profile);
@@ -19035,7 +19143,9 @@ class CodexAdapter {
19035
19143
  const providerKey = `swixter-${profileName}`;
19036
19144
  const profileKey = `swixter-${profileName}`;
19037
19145
  let modified = false;
19146
+ let envKeyToRemove;
19038
19147
  if (config2.model_providers && config2.model_providers[providerKey]) {
19148
+ envKeyToRemove = config2.model_providers[providerKey].env_key;
19039
19149
  delete config2.model_providers[providerKey];
19040
19150
  modified = true;
19041
19151
  }
@@ -19052,6 +19162,14 @@ class CodexAdapter {
19052
19162
  const tomlContent = stringify(config2);
19053
19163
  await writeFile4(this.configPath, tomlContent, "utf-8");
19054
19164
  }
19165
+ if (envKeyToRemove && existsSync4(this.authPath)) {
19166
+ try {
19167
+ const authContent = await readFile4(this.authPath, "utf-8");
19168
+ const auth = JSON.parse(authContent);
19169
+ delete auth[envKeyToRemove];
19170
+ await writeFile4(this.authPath, JSON.stringify(auth, null, 2), "utf-8");
19171
+ } catch {}
19172
+ }
19055
19173
  } catch (error46) {
19056
19174
  console.warn(`Failed to remove profile from Codex config: ${error46}`);
19057
19175
  }
@@ -19756,7 +19874,7 @@ var init_install2 = __esm(() => {
19756
19874
  import_picocolors6 = __toESM(require_picocolors(), 1);
19757
19875
  });
19758
19876
 
19759
- // node_modules/semver/internal/constants.js
19877
+ // ../../node_modules/semver/internal/constants.js
19760
19878
  var require_constants = __commonJS((exports, module) => {
19761
19879
  var SEMVER_SPEC_VERSION = "2.0.0";
19762
19880
  var MAX_LENGTH = 256;
@@ -19784,13 +19902,13 @@ var require_constants = __commonJS((exports, module) => {
19784
19902
  };
19785
19903
  });
19786
19904
 
19787
- // node_modules/semver/internal/debug.js
19905
+ // ../../node_modules/semver/internal/debug.js
19788
19906
  var require_debug = __commonJS((exports, module) => {
19789
19907
  var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
19790
19908
  module.exports = debug;
19791
19909
  });
19792
19910
 
19793
- // node_modules/semver/internal/re.js
19911
+ // ../../node_modules/semver/internal/re.js
19794
19912
  var require_re = __commonJS((exports, module) => {
19795
19913
  var {
19796
19914
  MAX_SAFE_COMPONENT_LENGTH,
@@ -19875,7 +19993,7 @@ var require_re = __commonJS((exports, module) => {
19875
19993
  createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
19876
19994
  });
19877
19995
 
19878
- // node_modules/semver/internal/parse-options.js
19996
+ // ../../node_modules/semver/internal/parse-options.js
19879
19997
  var require_parse_options = __commonJS((exports, module) => {
19880
19998
  var looseOption = Object.freeze({ loose: true });
19881
19999
  var emptyOpts = Object.freeze({});
@@ -19891,7 +20009,7 @@ var require_parse_options = __commonJS((exports, module) => {
19891
20009
  module.exports = parseOptions;
19892
20010
  });
19893
20011
 
19894
- // node_modules/semver/internal/identifiers.js
20012
+ // ../../node_modules/semver/internal/identifiers.js
19895
20013
  var require_identifiers = __commonJS((exports, module) => {
19896
20014
  var numeric = /^[0-9]+$/;
19897
20015
  var compareIdentifiers = (a, b3) => {
@@ -19913,7 +20031,7 @@ var require_identifiers = __commonJS((exports, module) => {
19913
20031
  };
19914
20032
  });
19915
20033
 
19916
- // node_modules/semver/classes/semver.js
20034
+ // ../../node_modules/semver/classes/semver.js
19917
20035
  var require_semver = __commonJS((exports, module) => {
19918
20036
  var debug = require_debug();
19919
20037
  var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
@@ -20182,7 +20300,7 @@ var require_semver = __commonJS((exports, module) => {
20182
20300
  module.exports = SemVer;
20183
20301
  });
20184
20302
 
20185
- // node_modules/semver/functions/parse.js
20303
+ // ../../node_modules/semver/functions/parse.js
20186
20304
  var require_parse = __commonJS((exports, module) => {
20187
20305
  var SemVer = require_semver();
20188
20306
  var parse6 = (version2, options, throwErrors = false) => {
@@ -20201,7 +20319,7 @@ var require_parse = __commonJS((exports, module) => {
20201
20319
  module.exports = parse6;
20202
20320
  });
20203
20321
 
20204
- // node_modules/semver/functions/valid.js
20322
+ // ../../node_modules/semver/functions/valid.js
20205
20323
  var require_valid = __commonJS((exports, module) => {
20206
20324
  var parse6 = require_parse();
20207
20325
  var valid = (version2, options) => {
@@ -20211,7 +20329,7 @@ var require_valid = __commonJS((exports, module) => {
20211
20329
  module.exports = valid;
20212
20330
  });
20213
20331
 
20214
- // node_modules/semver/functions/clean.js
20332
+ // ../../node_modules/semver/functions/clean.js
20215
20333
  var require_clean = __commonJS((exports, module) => {
20216
20334
  var parse6 = require_parse();
20217
20335
  var clean = (version2, options) => {
@@ -20221,7 +20339,7 @@ var require_clean = __commonJS((exports, module) => {
20221
20339
  module.exports = clean;
20222
20340
  });
20223
20341
 
20224
- // node_modules/semver/functions/inc.js
20342
+ // ../../node_modules/semver/functions/inc.js
20225
20343
  var require_inc = __commonJS((exports, module) => {
20226
20344
  var SemVer = require_semver();
20227
20345
  var inc = (version2, release, options, identifier, identifierBase) => {
@@ -20239,7 +20357,7 @@ var require_inc = __commonJS((exports, module) => {
20239
20357
  module.exports = inc;
20240
20358
  });
20241
20359
 
20242
- // node_modules/semver/functions/diff.js
20360
+ // ../../node_modules/semver/functions/diff.js
20243
20361
  var require_diff = __commonJS((exports, module) => {
20244
20362
  var parse6 = require_parse();
20245
20363
  var diff = (version1, version2) => {
@@ -20280,28 +20398,28 @@ var require_diff = __commonJS((exports, module) => {
20280
20398
  module.exports = diff;
20281
20399
  });
20282
20400
 
20283
- // node_modules/semver/functions/major.js
20401
+ // ../../node_modules/semver/functions/major.js
20284
20402
  var require_major = __commonJS((exports, module) => {
20285
20403
  var SemVer = require_semver();
20286
20404
  var major = (a, loose) => new SemVer(a, loose).major;
20287
20405
  module.exports = major;
20288
20406
  });
20289
20407
 
20290
- // node_modules/semver/functions/minor.js
20408
+ // ../../node_modules/semver/functions/minor.js
20291
20409
  var require_minor = __commonJS((exports, module) => {
20292
20410
  var SemVer = require_semver();
20293
20411
  var minor = (a, loose) => new SemVer(a, loose).minor;
20294
20412
  module.exports = minor;
20295
20413
  });
20296
20414
 
20297
- // node_modules/semver/functions/patch.js
20415
+ // ../../node_modules/semver/functions/patch.js
20298
20416
  var require_patch = __commonJS((exports, module) => {
20299
20417
  var SemVer = require_semver();
20300
20418
  var patch = (a, loose) => new SemVer(a, loose).patch;
20301
20419
  module.exports = patch;
20302
20420
  });
20303
20421
 
20304
- // node_modules/semver/functions/prerelease.js
20422
+ // ../../node_modules/semver/functions/prerelease.js
20305
20423
  var require_prerelease = __commonJS((exports, module) => {
20306
20424
  var parse6 = require_parse();
20307
20425
  var prerelease = (version2, options) => {
@@ -20311,28 +20429,28 @@ var require_prerelease = __commonJS((exports, module) => {
20311
20429
  module.exports = prerelease;
20312
20430
  });
20313
20431
 
20314
- // node_modules/semver/functions/compare.js
20432
+ // ../../node_modules/semver/functions/compare.js
20315
20433
  var require_compare = __commonJS((exports, module) => {
20316
20434
  var SemVer = require_semver();
20317
20435
  var compare = (a, b3, loose) => new SemVer(a, loose).compare(new SemVer(b3, loose));
20318
20436
  module.exports = compare;
20319
20437
  });
20320
20438
 
20321
- // node_modules/semver/functions/rcompare.js
20439
+ // ../../node_modules/semver/functions/rcompare.js
20322
20440
  var require_rcompare = __commonJS((exports, module) => {
20323
20441
  var compare = require_compare();
20324
20442
  var rcompare = (a, b3, loose) => compare(b3, a, loose);
20325
20443
  module.exports = rcompare;
20326
20444
  });
20327
20445
 
20328
- // node_modules/semver/functions/compare-loose.js
20446
+ // ../../node_modules/semver/functions/compare-loose.js
20329
20447
  var require_compare_loose = __commonJS((exports, module) => {
20330
20448
  var compare = require_compare();
20331
20449
  var compareLoose = (a, b3) => compare(a, b3, true);
20332
20450
  module.exports = compareLoose;
20333
20451
  });
20334
20452
 
20335
- // node_modules/semver/functions/compare-build.js
20453
+ // ../../node_modules/semver/functions/compare-build.js
20336
20454
  var require_compare_build = __commonJS((exports, module) => {
20337
20455
  var SemVer = require_semver();
20338
20456
  var compareBuild = (a, b3, loose) => {
@@ -20343,63 +20461,63 @@ var require_compare_build = __commonJS((exports, module) => {
20343
20461
  module.exports = compareBuild;
20344
20462
  });
20345
20463
 
20346
- // node_modules/semver/functions/sort.js
20464
+ // ../../node_modules/semver/functions/sort.js
20347
20465
  var require_sort = __commonJS((exports, module) => {
20348
20466
  var compareBuild = require_compare_build();
20349
20467
  var sort = (list, loose) => list.sort((a, b3) => compareBuild(a, b3, loose));
20350
20468
  module.exports = sort;
20351
20469
  });
20352
20470
 
20353
- // node_modules/semver/functions/rsort.js
20471
+ // ../../node_modules/semver/functions/rsort.js
20354
20472
  var require_rsort = __commonJS((exports, module) => {
20355
20473
  var compareBuild = require_compare_build();
20356
20474
  var rsort = (list, loose) => list.sort((a, b3) => compareBuild(b3, a, loose));
20357
20475
  module.exports = rsort;
20358
20476
  });
20359
20477
 
20360
- // node_modules/semver/functions/gt.js
20478
+ // ../../node_modules/semver/functions/gt.js
20361
20479
  var require_gt = __commonJS((exports, module) => {
20362
20480
  var compare = require_compare();
20363
20481
  var gt = (a, b3, loose) => compare(a, b3, loose) > 0;
20364
20482
  module.exports = gt;
20365
20483
  });
20366
20484
 
20367
- // node_modules/semver/functions/lt.js
20485
+ // ../../node_modules/semver/functions/lt.js
20368
20486
  var require_lt = __commonJS((exports, module) => {
20369
20487
  var compare = require_compare();
20370
20488
  var lt = (a, b3, loose) => compare(a, b3, loose) < 0;
20371
20489
  module.exports = lt;
20372
20490
  });
20373
20491
 
20374
- // node_modules/semver/functions/eq.js
20492
+ // ../../node_modules/semver/functions/eq.js
20375
20493
  var require_eq = __commonJS((exports, module) => {
20376
20494
  var compare = require_compare();
20377
20495
  var eq = (a, b3, loose) => compare(a, b3, loose) === 0;
20378
20496
  module.exports = eq;
20379
20497
  });
20380
20498
 
20381
- // node_modules/semver/functions/neq.js
20499
+ // ../../node_modules/semver/functions/neq.js
20382
20500
  var require_neq = __commonJS((exports, module) => {
20383
20501
  var compare = require_compare();
20384
20502
  var neq = (a, b3, loose) => compare(a, b3, loose) !== 0;
20385
20503
  module.exports = neq;
20386
20504
  });
20387
20505
 
20388
- // node_modules/semver/functions/gte.js
20506
+ // ../../node_modules/semver/functions/gte.js
20389
20507
  var require_gte = __commonJS((exports, module) => {
20390
20508
  var compare = require_compare();
20391
20509
  var gte = (a, b3, loose) => compare(a, b3, loose) >= 0;
20392
20510
  module.exports = gte;
20393
20511
  });
20394
20512
 
20395
- // node_modules/semver/functions/lte.js
20513
+ // ../../node_modules/semver/functions/lte.js
20396
20514
  var require_lte = __commonJS((exports, module) => {
20397
20515
  var compare = require_compare();
20398
20516
  var lte = (a, b3, loose) => compare(a, b3, loose) <= 0;
20399
20517
  module.exports = lte;
20400
20518
  });
20401
20519
 
20402
- // node_modules/semver/functions/cmp.js
20520
+ // ../../node_modules/semver/functions/cmp.js
20403
20521
  var require_cmp = __commonJS((exports, module) => {
20404
20522
  var eq = require_eq();
20405
20523
  var neq = require_neq();
@@ -20446,7 +20564,7 @@ var require_cmp = __commonJS((exports, module) => {
20446
20564
  module.exports = cmp;
20447
20565
  });
20448
20566
 
20449
- // node_modules/semver/functions/coerce.js
20567
+ // ../../node_modules/semver/functions/coerce.js
20450
20568
  var require_coerce = __commonJS((exports, module) => {
20451
20569
  var SemVer = require_semver();
20452
20570
  var parse6 = require_parse();
@@ -20489,7 +20607,7 @@ var require_coerce = __commonJS((exports, module) => {
20489
20607
  module.exports = coerce;
20490
20608
  });
20491
20609
 
20492
- // node_modules/semver/internal/lrucache.js
20610
+ // ../../node_modules/semver/internal/lrucache.js
20493
20611
  var require_lrucache = __commonJS((exports, module) => {
20494
20612
  class LRUCache {
20495
20613
  constructor() {
@@ -20524,7 +20642,7 @@ var require_lrucache = __commonJS((exports, module) => {
20524
20642
  module.exports = LRUCache;
20525
20643
  });
20526
20644
 
20527
- // node_modules/semver/classes/range.js
20645
+ // ../../node_modules/semver/classes/range.js
20528
20646
  var require_range = __commonJS((exports, module) => {
20529
20647
  var SPACE_CHARACTERS = /\s+/g;
20530
20648
 
@@ -20898,7 +21016,7 @@ var require_range = __commonJS((exports, module) => {
20898
21016
  };
20899
21017
  });
20900
21018
 
20901
- // node_modules/semver/classes/comparator.js
21019
+ // ../../node_modules/semver/classes/comparator.js
20902
21020
  var require_comparator = __commonJS((exports, module) => {
20903
21021
  var ANY = Symbol("SemVer ANY");
20904
21022
 
@@ -21009,7 +21127,7 @@ var require_comparator = __commonJS((exports, module) => {
21009
21127
  var Range = require_range();
21010
21128
  });
21011
21129
 
21012
- // node_modules/semver/functions/satisfies.js
21130
+ // ../../node_modules/semver/functions/satisfies.js
21013
21131
  var require_satisfies = __commonJS((exports, module) => {
21014
21132
  var Range = require_range();
21015
21133
  var satisfies = (version2, range, options) => {
@@ -21023,14 +21141,14 @@ var require_satisfies = __commonJS((exports, module) => {
21023
21141
  module.exports = satisfies;
21024
21142
  });
21025
21143
 
21026
- // node_modules/semver/ranges/to-comparators.js
21144
+ // ../../node_modules/semver/ranges/to-comparators.js
21027
21145
  var require_to_comparators = __commonJS((exports, module) => {
21028
21146
  var Range = require_range();
21029
21147
  var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
21030
21148
  module.exports = toComparators;
21031
21149
  });
21032
21150
 
21033
- // node_modules/semver/ranges/max-satisfying.js
21151
+ // ../../node_modules/semver/ranges/max-satisfying.js
21034
21152
  var require_max_satisfying = __commonJS((exports, module) => {
21035
21153
  var SemVer = require_semver();
21036
21154
  var Range = require_range();
@@ -21056,7 +21174,7 @@ var require_max_satisfying = __commonJS((exports, module) => {
21056
21174
  module.exports = maxSatisfying;
21057
21175
  });
21058
21176
 
21059
- // node_modules/semver/ranges/min-satisfying.js
21177
+ // ../../node_modules/semver/ranges/min-satisfying.js
21060
21178
  var require_min_satisfying = __commonJS((exports, module) => {
21061
21179
  var SemVer = require_semver();
21062
21180
  var Range = require_range();
@@ -21082,7 +21200,7 @@ var require_min_satisfying = __commonJS((exports, module) => {
21082
21200
  module.exports = minSatisfying;
21083
21201
  });
21084
21202
 
21085
- // node_modules/semver/ranges/min-version.js
21203
+ // ../../node_modules/semver/ranges/min-version.js
21086
21204
  var require_min_version = __commonJS((exports, module) => {
21087
21205
  var SemVer = require_semver();
21088
21206
  var Range = require_range();
@@ -21136,7 +21254,7 @@ var require_min_version = __commonJS((exports, module) => {
21136
21254
  module.exports = minVersion;
21137
21255
  });
21138
21256
 
21139
- // node_modules/semver/ranges/valid.js
21257
+ // ../../node_modules/semver/ranges/valid.js
21140
21258
  var require_valid2 = __commonJS((exports, module) => {
21141
21259
  var Range = require_range();
21142
21260
  var validRange = (range, options) => {
@@ -21149,7 +21267,7 @@ var require_valid2 = __commonJS((exports, module) => {
21149
21267
  module.exports = validRange;
21150
21268
  });
21151
21269
 
21152
- // node_modules/semver/ranges/outside.js
21270
+ // ../../node_modules/semver/ranges/outside.js
21153
21271
  var require_outside = __commonJS((exports, module) => {
21154
21272
  var SemVer = require_semver();
21155
21273
  var Comparator = require_comparator();
@@ -21215,21 +21333,21 @@ var require_outside = __commonJS((exports, module) => {
21215
21333
  module.exports = outside;
21216
21334
  });
21217
21335
 
21218
- // node_modules/semver/ranges/gtr.js
21336
+ // ../../node_modules/semver/ranges/gtr.js
21219
21337
  var require_gtr = __commonJS((exports, module) => {
21220
21338
  var outside = require_outside();
21221
21339
  var gtr = (version2, range, options) => outside(version2, range, ">", options);
21222
21340
  module.exports = gtr;
21223
21341
  });
21224
21342
 
21225
- // node_modules/semver/ranges/ltr.js
21343
+ // ../../node_modules/semver/ranges/ltr.js
21226
21344
  var require_ltr = __commonJS((exports, module) => {
21227
21345
  var outside = require_outside();
21228
21346
  var ltr = (version2, range, options) => outside(version2, range, "<", options);
21229
21347
  module.exports = ltr;
21230
21348
  });
21231
21349
 
21232
- // node_modules/semver/ranges/intersects.js
21350
+ // ../../node_modules/semver/ranges/intersects.js
21233
21351
  var require_intersects = __commonJS((exports, module) => {
21234
21352
  var Range = require_range();
21235
21353
  var intersects = (r1, r2, options) => {
@@ -21240,7 +21358,7 @@ var require_intersects = __commonJS((exports, module) => {
21240
21358
  module.exports = intersects;
21241
21359
  });
21242
21360
 
21243
- // node_modules/semver/ranges/simplify.js
21361
+ // ../../node_modules/semver/ranges/simplify.js
21244
21362
  var require_simplify = __commonJS((exports, module) => {
21245
21363
  var satisfies = require_satisfies();
21246
21364
  var compare = require_compare();
@@ -21287,7 +21405,7 @@ var require_simplify = __commonJS((exports, module) => {
21287
21405
  };
21288
21406
  });
21289
21407
 
21290
- // node_modules/semver/ranges/subset.js
21408
+ // ../../node_modules/semver/ranges/subset.js
21291
21409
  var require_subset = __commonJS((exports, module) => {
21292
21410
  var Range = require_range();
21293
21411
  var Comparator = require_comparator();
@@ -21447,7 +21565,7 @@ var require_subset = __commonJS((exports, module) => {
21447
21565
  module.exports = subset;
21448
21566
  });
21449
21567
 
21450
- // node_modules/semver/index.js
21568
+ // ../../node_modules/semver/index.js
21451
21569
  var require_semver2 = __commonJS((exports, module) => {
21452
21570
  var internalRe = require_re();
21453
21571
  var constants = require_constants();
@@ -21834,7 +21952,7 @@ ${import_picocolors8.default.bold("Create profile (interactive):")}
21834
21952
  ${import_picocolors8.default.green(`swixter ${CODER_NAME} create`)}
21835
21953
 
21836
21954
  ${import_picocolors8.default.bold("Create profile (non-interactive):")}
21837
- ${import_picocolors8.default.green(`swixter ${CODER_NAME} create --quiet --name <name> --provider <id> --api-key <key> [--base-url <url>] [--anthropic-model <model>] [--default-haiku-model <model>] [--default-opus-model <model>] [--default-sonnet-model <model>] [--apply]`)}
21955
+ ${import_picocolors8.default.green(`swixter ${CODER_NAME} create --quiet --name <name> --provider <id> --api-key <key> [--base-url <url>] [--anthropic-model <model>] [--default-haiku-model <model>] [--default-opus-model <model>] [--default-sonnet-model <model>] [--api-format <format>] [--apply]`)}
21838
21956
 
21839
21957
  ${import_picocolors8.default.bold("Examples:")}
21840
21958
  ${import_picocolors8.default.dim("# Interactive profile creation")}
@@ -21928,6 +22046,23 @@ async function cmdCreateInteractive() {
21928
22046
  xe(ERRORS.cancelled);
21929
22047
  process.exit(EXIT_CODES.cancelled);
21930
22048
  }
22049
+ let apiFormat = null;
22050
+ if (providerId === "custom") {
22051
+ apiFormat = await ve({
22052
+ message: "Select the API format for this provider",
22053
+ options: [
22054
+ { value: "openai_chat", label: "OpenAI Chat", hint: "OpenAI-compatible /v1/chat/completions" },
22055
+ { value: "anthropic_messages", label: "Anthropic Messages", hint: "Anthropic /v1/messages" },
22056
+ { value: "openai_responses", label: "OpenAI Responses", hint: "OpenAI Responses API" },
22057
+ { value: "anthropic_responses", label: "Anthropic Responses", hint: "Anthropic Responses API" },
22058
+ { value: "gemini_native", label: "Gemini Native", hint: "Google Gemini API" }
22059
+ ]
22060
+ });
22061
+ if (pD(apiFormat)) {
22062
+ xe(ERRORS.cancelled);
22063
+ process.exit(EXIT_CODES.cancelled);
22064
+ }
22065
+ }
21931
22066
  let models = undefined;
21932
22067
  const configureModels = await ye({
21933
22068
  message: PROMPTS.configureModels,
@@ -22005,6 +22140,9 @@ async function cmdCreateInteractive() {
22005
22140
  if (models) {
22006
22141
  profile.models = models;
22007
22142
  }
22143
+ if (apiFormat) {
22144
+ profile.apiFormat = apiFormat;
22145
+ }
22008
22146
  await upsertProfile(profile, CODER_NAME);
22009
22147
  spinner.stop("Profile created successfully!");
22010
22148
  console.log();
@@ -22024,7 +22162,7 @@ async function cmdCreateInteractive() {
22024
22162
  async function cmdCreateQuiet(params) {
22025
22163
  if (!params.name || !params.provider) {
22026
22164
  console.log(import_picocolors8.default.red("Error: Missing required parameters"));
22027
- console.log(import_picocolors8.default.dim("Usage: swixter claude create --quiet --name <name> --provider <id> [--api-key <key>] [--auth-token <token>] [--base-url <url>] [--anthropic-model <model>] [--default-haiku-model <model>] [--default-opus-model <model>] [--default-sonnet-model <model>] [--apply]"));
22165
+ console.log(import_picocolors8.default.dim("Usage: swixter claude create --quiet --name <name> --provider <id> [--api-key <key>] [--auth-token <token>] [--base-url <url>] [--anthropic-model <model>] [--default-haiku-model <model>] [--default-opus-model <model>] [--default-sonnet-model <model>] [--api-format <format>] [--apply]"));
22028
22166
  process.exit(1);
22029
22167
  }
22030
22168
  const preset = await getPresetByIdAsync(params.provider);
@@ -22033,6 +22171,12 @@ async function cmdCreateQuiet(params) {
22033
22171
  console.log(import_picocolors8.default.dim("Run 'swixter providers' to see all supported providers"));
22034
22172
  process.exit(1);
22035
22173
  }
22174
+ const apiFormat = params["api-format"];
22175
+ if (apiFormat && !API_FORMATS.includes(apiFormat)) {
22176
+ console.log(import_picocolors8.default.red(`Invalid apiFormat: ${apiFormat}`));
22177
+ console.log(import_picocolors8.default.dim(`Valid values: ${API_FORMATS.join(", ")}`));
22178
+ process.exit(EXIT_CODES.invalidArguments);
22179
+ }
22036
22180
  try {
22037
22181
  const finalBaseURL = params["base-url"] || preset.baseURL;
22038
22182
  const profile = {
@@ -22060,6 +22204,9 @@ async function cmdCreateQuiet(params) {
22060
22204
  ...defaultSonnetModel && { defaultSonnetModel }
22061
22205
  };
22062
22206
  }
22207
+ if (apiFormat) {
22208
+ profile.apiFormat = apiFormat;
22209
+ }
22063
22210
  await upsertProfile(profile, CODER_NAME);
22064
22211
  console.log();
22065
22212
  console.log(import_picocolors8.default.green("✓") + " Profile created successfully!");
@@ -22254,6 +22401,21 @@ async function cmdEdit(profileName) {
22254
22401
  xe(ERRORS.cancelled);
22255
22402
  return;
22256
22403
  }
22404
+ const currentApiFormat = profile.apiFormat || "auto-detect";
22405
+ const apiFormatOptions = [
22406
+ { value: "", label: "Keep current" },
22407
+ { value: "clear", label: "Auto-detect (clear explicit format)" },
22408
+ ...API_FORMATS.map((f) => ({ value: f, label: f }))
22409
+ ];
22410
+ const newApiFormat = await ve({
22411
+ message: `Select target API format (current: ${currentApiFormat})`,
22412
+ options: apiFormatOptions,
22413
+ initialValue: profile.apiFormat || ""
22414
+ });
22415
+ if (pD(newApiFormat)) {
22416
+ xe(ERRORS.cancelled);
22417
+ return;
22418
+ }
22257
22419
  let models = undefined;
22258
22420
  let editedModels = false;
22259
22421
  const currentModelsInfo = profile.models ? `Current: ${Object.entries(profile.models).filter(([, v2]) => v2).map(([k3, v2]) => `${k3}=${v2}`).join(", ")}` : "No models configured";
@@ -22343,6 +22505,13 @@ async function cmdEdit(profileName) {
22343
22505
  } else if (profile.models) {
22344
22506
  updatedProfile.models = profile.models;
22345
22507
  }
22508
+ if (newApiFormat === "clear") {} else if (newApiFormat) {
22509
+ updatedProfile.apiFormat = newApiFormat;
22510
+ } else {
22511
+ if (profile.apiFormat) {
22512
+ updatedProfile.apiFormat = profile.apiFormat;
22513
+ }
22514
+ }
22346
22515
  const finalBaseURL = updatedProfile.baseURL || newPreset?.baseURL || "";
22347
22516
  await upsertProfile(updatedProfile, CODER_NAME);
22348
22517
  spinner.stop("Profile updated successfully!");
@@ -22626,6 +22795,7 @@ var init_claude2 = __esm(() => {
22626
22795
  init_manager();
22627
22796
  init_presets();
22628
22797
  init_adapters();
22798
+ init_types2();
22629
22799
  init_constants();
22630
22800
  init_ui();
22631
22801
  init_validation();
@@ -22639,7 +22809,7 @@ var init_claude2 = __esm(() => {
22639
22809
  CODER_CONFIG = CODER_REGISTRY[CODER_NAME];
22640
22810
  });
22641
22811
 
22642
- // node_modules/ws/lib/constants.js
22812
+ // ../../node_modules/ws/lib/constants.js
22643
22813
  var require_constants2 = __commonJS((exports, module) => {
22644
22814
  var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
22645
22815
  var hasBlob = typeof Blob !== "undefined";
@@ -22659,7 +22829,7 @@ var require_constants2 = __commonJS((exports, module) => {
22659
22829
  };
22660
22830
  });
22661
22831
 
22662
- // node_modules/ws/lib/buffer-util.js
22832
+ // ../../node_modules/ws/lib/buffer-util.js
22663
22833
  var require_buffer_util = __commonJS((exports, module) => {
22664
22834
  var { EMPTY_BUFFER } = require_constants2();
22665
22835
  var FastBuffer = Buffer[Symbol.species];
@@ -22737,7 +22907,7 @@ var require_buffer_util = __commonJS((exports, module) => {
22737
22907
  }
22738
22908
  });
22739
22909
 
22740
- // node_modules/ws/lib/limiter.js
22910
+ // ../../node_modules/ws/lib/limiter.js
22741
22911
  var require_limiter = __commonJS((exports, module) => {
22742
22912
  var kDone = Symbol("kDone");
22743
22913
  var kRun = Symbol("kRun");
@@ -22769,7 +22939,7 @@ var require_limiter = __commonJS((exports, module) => {
22769
22939
  module.exports = Limiter;
22770
22940
  });
22771
22941
 
22772
- // node_modules/ws/lib/permessage-deflate.js
22942
+ // ../../node_modules/ws/lib/permessage-deflate.js
22773
22943
  var require_permessage_deflate = __commonJS((exports, module) => {
22774
22944
  var zlib = __require("zlib");
22775
22945
  var bufferUtil = require_buffer_util();
@@ -23033,7 +23203,7 @@ var require_permessage_deflate = __commonJS((exports, module) => {
23033
23203
  }
23034
23204
  });
23035
23205
 
23036
- // node_modules/ws/lib/validation.js
23206
+ // ../../node_modules/ws/lib/validation.js
23037
23207
  var require_validation = __commonJS((exports, module) => {
23038
23208
  var { isUtf8 } = __require("buffer");
23039
23209
  var { hasBlob } = require_constants2();
@@ -23220,7 +23390,7 @@ var require_validation = __commonJS((exports, module) => {
23220
23390
  }
23221
23391
  });
23222
23392
 
23223
- // node_modules/ws/lib/receiver.js
23393
+ // ../../node_modules/ws/lib/receiver.js
23224
23394
  var require_receiver = __commonJS((exports, module) => {
23225
23395
  var { Writable } = __require("stream");
23226
23396
  var PerMessageDeflate = require_permessage_deflate();
@@ -23601,7 +23771,7 @@ var require_receiver = __commonJS((exports, module) => {
23601
23771
  module.exports = Receiver;
23602
23772
  });
23603
23773
 
23604
- // node_modules/ws/lib/sender.js
23774
+ // ../../node_modules/ws/lib/sender.js
23605
23775
  var require_sender = __commonJS((exports, module) => {
23606
23776
  var { Duplex } = __require("stream");
23607
23777
  var { randomFillSync } = __require("crypto");
@@ -23955,7 +24125,7 @@ var require_sender = __commonJS((exports, module) => {
23955
24125
  }
23956
24126
  });
23957
24127
 
23958
- // node_modules/ws/lib/event-target.js
24128
+ // ../../node_modules/ws/lib/event-target.js
23959
24129
  var require_event_target = __commonJS((exports, module) => {
23960
24130
  var { kForOnEventAttribute, kListener } = require_constants2();
23961
24131
  var kCode = Symbol("kCode");
@@ -24106,7 +24276,7 @@ var require_event_target = __commonJS((exports, module) => {
24106
24276
  }
24107
24277
  });
24108
24278
 
24109
- // node_modules/ws/lib/extension.js
24279
+ // ../../node_modules/ws/lib/extension.js
24110
24280
  var require_extension = __commonJS((exports, module) => {
24111
24281
  var { tokenChars } = require_validation();
24112
24282
  function push(dest, name, elem) {
@@ -24271,7 +24441,7 @@ var require_extension = __commonJS((exports, module) => {
24271
24441
  module.exports = { format, parse: parse6 };
24272
24442
  });
24273
24443
 
24274
- // node_modules/ws/lib/websocket.js
24444
+ // ../../node_modules/ws/lib/websocket.js
24275
24445
  var require_websocket = __commonJS((exports, module) => {
24276
24446
  var EventEmitter = __require("events");
24277
24447
  var https = __require("https");
@@ -25037,7 +25207,7 @@ var require_websocket = __commonJS((exports, module) => {
25037
25207
  }
25038
25208
  });
25039
25209
 
25040
- // node_modules/ws/lib/stream.js
25210
+ // ../../node_modules/ws/lib/stream.js
25041
25211
  var require_stream = __commonJS((exports, module) => {
25042
25212
  var WebSocket = require_websocket();
25043
25213
  var { Duplex } = __require("stream");
@@ -25140,7 +25310,7 @@ var require_stream = __commonJS((exports, module) => {
25140
25310
  module.exports = createWebSocketStream;
25141
25311
  });
25142
25312
 
25143
- // node_modules/ws/lib/subprotocol.js
25313
+ // ../../node_modules/ws/lib/subprotocol.js
25144
25314
  var require_subprotocol = __commonJS((exports, module) => {
25145
25315
  var { tokenChars } = require_validation();
25146
25316
  function parse6(header) {
@@ -25185,7 +25355,7 @@ var require_subprotocol = __commonJS((exports, module) => {
25185
25355
  module.exports = { parse: parse6 };
25186
25356
  });
25187
25357
 
25188
- // node_modules/ws/lib/websocket-server.js
25358
+ // ../../node_modules/ws/lib/websocket-server.js
25189
25359
  var require_websocket_server = __commonJS((exports, module) => {
25190
25360
  var EventEmitter = __require("events");
25191
25361
  var http = __require("http");
@@ -25525,6 +25695,711 @@ var init_events = __esm(() => {
25525
25695
  handlers = new Set;
25526
25696
  });
25527
25697
 
25698
+ // src/proxy/transform/utils.ts
25699
+ function parseSSEEvents(chunk) {
25700
+ const events = [];
25701
+ const lines = chunk.split(`
25702
+ `);
25703
+ let currentEvent = "";
25704
+ let currentDataLines = [];
25705
+ function flushEvent() {
25706
+ if (currentDataLines.length > 0) {
25707
+ const dataStr = currentDataLines.join(`
25708
+ `);
25709
+ try {
25710
+ const data = JSON.parse(dataStr);
25711
+ events.push({ event: currentEvent, data });
25712
+ } catch {}
25713
+ }
25714
+ currentEvent = "";
25715
+ currentDataLines = [];
25716
+ }
25717
+ for (const line of lines) {
25718
+ if (line.startsWith("event: ")) {
25719
+ currentEvent = line.slice("event: ".length);
25720
+ } else if (line.startsWith("data: ")) {
25721
+ currentDataLines.push(line.slice("data: ".length));
25722
+ } else if (line === "") {
25723
+ flushEvent();
25724
+ }
25725
+ }
25726
+ return events;
25727
+ }
25728
+ function serializeSSEEvent(eventName, data) {
25729
+ const dataStr = typeof data === "string" ? data : JSON.stringify(data);
25730
+ if (eventName) {
25731
+ return `event: ${eventName}
25732
+ data: ${dataStr}
25733
+
25734
+ `;
25735
+ }
25736
+ return `data: ${dataStr}
25737
+
25738
+ `;
25739
+ }
25740
+ function convertAnthropicImageToOpenAI(imageBlock) {
25741
+ const source = imageBlock.source;
25742
+ if (!source) {
25743
+ return { type: "image_url", image_url: { url: "" } };
25744
+ }
25745
+ const mediaType = source.media_type || "image/png";
25746
+ const data = source.data || "";
25747
+ return {
25748
+ type: "image_url",
25749
+ image_url: {
25750
+ url: `data:${mediaType};base64,${data}`
25751
+ }
25752
+ };
25753
+ }
25754
+ function convertOpenAIToolCallsToAnthropic(toolCalls) {
25755
+ return toolCalls.map((tc) => {
25756
+ const func = tc.function;
25757
+ return {
25758
+ type: "tool_use",
25759
+ id: tc.id,
25760
+ name: func?.name || "",
25761
+ input: func?.arguments ? JSON.parse(func.arguments) : {}
25762
+ };
25763
+ });
25764
+ }
25765
+ function convertAnthropicToolUseToOpenAI(toolUses) {
25766
+ return toolUses.map((tu) => ({
25767
+ id: tu.id,
25768
+ type: "function",
25769
+ function: {
25770
+ name: tu.name,
25771
+ arguments: JSON.stringify(tu.input || {})
25772
+ }
25773
+ }));
25774
+ }
25775
+ function mergeSystemBlocks(system) {
25776
+ if (typeof system === "string") {
25777
+ return system;
25778
+ }
25779
+ if (Array.isArray(system)) {
25780
+ return system.filter((s) => s.type === "text").map((s) => s.text).filter(Boolean).join(`
25781
+ `);
25782
+ }
25783
+ return "";
25784
+ }
25785
+
25786
+ // src/proxy/transform/streaming/base.ts
25787
+ class SSEStreamTransformer {
25788
+ ctx;
25789
+ encoder = new TextEncoder;
25790
+ decoder = new TextDecoder("utf-8", { fatal: false });
25791
+ buffer = "";
25792
+ constructor(ctx) {
25793
+ this.ctx = ctx;
25794
+ }
25795
+ transformChunk(chunk) {
25796
+ const text = this.decoder.decode(chunk, { stream: true });
25797
+ this.buffer += text;
25798
+ const lastDoubleNewline = this.buffer.lastIndexOf(`
25799
+
25800
+ `);
25801
+ if (lastDoubleNewline === -1) {
25802
+ return new Uint8Array(0);
25803
+ }
25804
+ const completeText = this.buffer.slice(0, lastDoubleNewline + 2);
25805
+ this.buffer = this.buffer.slice(lastDoubleNewline + 2);
25806
+ const events = parseSSEEvents(completeText);
25807
+ const outputEvents = [];
25808
+ for (const event of events) {
25809
+ const converted = this.convertEvent(event);
25810
+ if (converted) {
25811
+ if (Array.isArray(converted)) {
25812
+ outputEvents.push(...converted);
25813
+ } else {
25814
+ outputEvents.push(converted);
25815
+ }
25816
+ }
25817
+ }
25818
+ if (outputEvents.length === 0) {
25819
+ return new Uint8Array(0);
25820
+ }
25821
+ const outputText = outputEvents.map((e2) => serializeSSEEvent(e2.event, e2.data)).join("");
25822
+ return this.encoder.encode(outputText);
25823
+ }
25824
+ flush() {
25825
+ if (this.buffer.trim().length > 0) {
25826
+ const events = parseSSEEvents(this.buffer + `
25827
+
25828
+ `);
25829
+ const outputEvents = [];
25830
+ for (const event of events) {
25831
+ const converted = this.convertEvent(event);
25832
+ if (converted) {
25833
+ if (Array.isArray(converted)) {
25834
+ outputEvents.push(...converted);
25835
+ } else {
25836
+ outputEvents.push(converted);
25837
+ }
25838
+ }
25839
+ }
25840
+ this.buffer = "";
25841
+ if (outputEvents.length > 0) {
25842
+ const outputText = outputEvents.map((e2) => serializeSSEEvent(e2.event, e2.data)).join("");
25843
+ return this.encoder.encode(outputText);
25844
+ }
25845
+ }
25846
+ return new Uint8Array(0);
25847
+ }
25848
+ }
25849
+ function createSSETransformStream(transformer) {
25850
+ return new TransformStream({
25851
+ transform(chunk, controller) {
25852
+ const output = transformer.transformChunk(chunk);
25853
+ if (output.length > 0) {
25854
+ controller.enqueue(output);
25855
+ }
25856
+ },
25857
+ flush(controller) {
25858
+ const output = transformer.flush();
25859
+ if (output.length > 0) {
25860
+ controller.enqueue(output);
25861
+ }
25862
+ }
25863
+ });
25864
+ }
25865
+ var init_base = () => {};
25866
+
25867
+ // src/proxy/transform/index.ts
25868
+ function registerTransformer(entry) {
25869
+ const existingIndex = TRANSFORMER_REGISTRY.findIndex((t) => t.clientFormat === entry.clientFormat && t.targetFormat === entry.targetFormat);
25870
+ if (existingIndex >= 0) {
25871
+ TRANSFORMER_REGISTRY.splice(existingIndex, 1);
25872
+ }
25873
+ TRANSFORMER_REGISTRY.push(entry);
25874
+ }
25875
+ function inferClientFormat(endpoint) {
25876
+ if (endpoint.includes("/v1/chat/completions")) {
25877
+ return "openai_chat";
25878
+ }
25879
+ if (endpoint.includes("/v1/responses")) {
25880
+ return "anthropic_responses";
25881
+ }
25882
+ if (endpoint.includes("/anthropic/") || endpoint.includes("/v1/messages")) {
25883
+ return "anthropic_messages";
25884
+ }
25885
+ return "anthropic_messages";
25886
+ }
25887
+ function inferApiFormatFromBaseURL(baseURL) {
25888
+ try {
25889
+ const url2 = new URL(baseURL);
25890
+ const path = url2.pathname.toLowerCase();
25891
+ if (path.includes("/anthropic"))
25892
+ return "anthropic_messages";
25893
+ if (path.includes("/responses"))
25894
+ return "anthropic_responses";
25895
+ if (path.includes("/openai"))
25896
+ return "openai_chat";
25897
+ return null;
25898
+ } catch {
25899
+ return null;
25900
+ }
25901
+ }
25902
+ function inferTargetApiFormat(profile, preset) {
25903
+ if (profile.apiFormat) {
25904
+ return profile.apiFormat;
25905
+ }
25906
+ const baseURL = profile.baseURL || preset?.baseURL || "";
25907
+ const fromURL = inferApiFormatFromBaseURL(baseURL);
25908
+ if (fromURL) {
25909
+ return fromURL;
25910
+ }
25911
+ if (preset?.defaultApiFormat) {
25912
+ return preset.defaultApiFormat;
25913
+ }
25914
+ switch (preset.wire_api) {
25915
+ case "chat":
25916
+ return "openai_chat";
25917
+ case "responses":
25918
+ return "anthropic_messages";
25919
+ default:
25920
+ return "openai_chat";
25921
+ }
25922
+ }
25923
+ function getTransformer(clientFormat, targetFormat) {
25924
+ if (clientFormat === targetFormat) {
25925
+ return null;
25926
+ }
25927
+ const entry = TRANSFORMER_REGISTRY.find((t) => t.clientFormat === clientFormat && t.targetFormat === targetFormat);
25928
+ return entry ?? null;
25929
+ }
25930
+ function transformRequest(body, ctx) {
25931
+ const transformer = getTransformer(ctx.clientFormat, ctx.targetFormat);
25932
+ if (!transformer) {
25933
+ return { body, targetEndpoint: ctx.endpoint };
25934
+ }
25935
+ return transformer.requestTransform(body, ctx);
25936
+ }
25937
+ function transformResponse(body, ctx) {
25938
+ const transformer = getTransformer(ctx.clientFormat, ctx.targetFormat);
25939
+ if (!transformer) {
25940
+ return body;
25941
+ }
25942
+ return transformer.responseTransform(body, ctx);
25943
+ }
25944
+ function transformStream(stream, ctx) {
25945
+ const transformer = getTransformer(ctx.clientFormat, ctx.targetFormat);
25946
+ if (!transformer) {
25947
+ return stream;
25948
+ }
25949
+ return transformer.streamTransform(stream, ctx);
25950
+ }
25951
+ var TRANSFORMER_REGISTRY;
25952
+ var init_transform = __esm(() => {
25953
+ TRANSFORMER_REGISTRY = [];
25954
+ });
25955
+
25956
+ // src/proxy/transform/request/anthropic-to-openai-chat.ts
25957
+ function anthropicToOpenAIChatRequest(body, _ctx) {
25958
+ const anthropic = body;
25959
+ const openaiBody = {
25960
+ model: anthropic.model,
25961
+ messages: convertMessages(anthropic.messages)
25962
+ };
25963
+ if (anthropic.system !== undefined) {
25964
+ const systemText = mergeSystemBlocks(anthropic.system);
25965
+ if (systemText) {
25966
+ const messages2 = openaiBody.messages;
25967
+ messages2.unshift({ role: "system", content: systemText });
25968
+ }
25969
+ }
25970
+ if (anthropic.max_tokens !== undefined) {
25971
+ openaiBody.max_tokens = anthropic.max_tokens;
25972
+ }
25973
+ if (anthropic.temperature !== undefined) {
25974
+ openaiBody.temperature = anthropic.temperature;
25975
+ }
25976
+ if (anthropic.top_p !== undefined) {
25977
+ openaiBody.top_p = anthropic.top_p;
25978
+ }
25979
+ if (anthropic.stream !== undefined) {
25980
+ openaiBody.stream = anthropic.stream;
25981
+ }
25982
+ if (anthropic.stop_sequences !== undefined) {
25983
+ openaiBody.stop = anthropic.stop_sequences;
25984
+ }
25985
+ if (anthropic.tools !== undefined) {
25986
+ const tools = anthropic.tools;
25987
+ openaiBody.tools = tools.map((tool) => ({
25988
+ type: "function",
25989
+ function: {
25990
+ name: tool.name,
25991
+ description: tool.description,
25992
+ parameters: tool.input_schema
25993
+ }
25994
+ }));
25995
+ }
25996
+ if (anthropic.tool_choice !== undefined) {
25997
+ openaiBody.tool_choice = convertToolChoice(anthropic.tool_choice);
25998
+ }
25999
+ if (anthropic.thinking !== undefined) {
26000
+ const thinking = anthropic.thinking;
26001
+ if (thinking.budget_tokens !== undefined) {
26002
+ openaiBody.reasoning_effort = mapThinkingBudgetToEffort(Number(thinking.budget_tokens));
26003
+ }
26004
+ }
26005
+ return {
26006
+ body: openaiBody,
26007
+ targetEndpoint: "/v1/chat/completions"
26008
+ };
26009
+ }
26010
+ function convertMessages(messages2) {
26011
+ if (!messages2)
26012
+ return [];
26013
+ return messages2.map((msg) => {
26014
+ const role = msg.role;
26015
+ const content = msg.content;
26016
+ if (Array.isArray(content)) {
26017
+ const convertedContent = content.map((block) => {
26018
+ switch (block.type) {
26019
+ case "text":
26020
+ return { type: "text", text: block.text };
26021
+ case "image":
26022
+ return convertAnthropicImageToOpenAI(block);
26023
+ case "tool_use":
26024
+ return null;
26025
+ case "tool_result":
26026
+ return null;
26027
+ default:
26028
+ return block;
26029
+ }
26030
+ }).filter(Boolean);
26031
+ const toolUses = content.filter((b3) => b3.type === "tool_use");
26032
+ if (toolUses.length > 0 && role === "assistant") {
26033
+ return {
26034
+ role: "assistant",
26035
+ content: convertedContent.length > 0 ? convertedContent : null,
26036
+ tool_calls: convertAnthropicToolUseToOpenAI(toolUses)
26037
+ };
26038
+ }
26039
+ const toolResults = content.filter((b3) => b3.type === "tool_result");
26040
+ if (toolResults.length > 0 && role === "user") {
26041
+ return toolResults.map((tr) => ({
26042
+ role: "tool",
26043
+ tool_call_id: tr.tool_use_id,
26044
+ content: typeof tr.content === "string" ? tr.content : JSON.stringify(tr.content)
26045
+ }));
26046
+ }
26047
+ return { role, content: convertedContent };
26048
+ }
26049
+ return { role, content };
26050
+ }).flat();
26051
+ }
26052
+ function convertToolChoice(toolChoice) {
26053
+ if (typeof toolChoice === "string") {
26054
+ switch (toolChoice) {
26055
+ case "any":
26056
+ return "required";
26057
+ case "none":
26058
+ return "none";
26059
+ case "auto":
26060
+ default:
26061
+ return "auto";
26062
+ }
26063
+ }
26064
+ if (typeof toolChoice === "object" && toolChoice !== null) {
26065
+ const tc = toolChoice;
26066
+ if (tc.type === "tool") {
26067
+ return {
26068
+ type: "function",
26069
+ function: { name: tc.name }
26070
+ };
26071
+ }
26072
+ }
26073
+ return toolChoice;
26074
+ }
26075
+ function mapThinkingBudgetToEffort(budgetTokens) {
26076
+ if (budgetTokens >= 32000)
26077
+ return "high";
26078
+ if (budgetTokens >= 16000)
26079
+ return "medium";
26080
+ return "low";
26081
+ }
26082
+ var init_anthropic_to_openai_chat = () => {};
26083
+
26084
+ // src/proxy/transform/response/openai-chat-to-anthropic.ts
26085
+ function openAIChatToAnthropicResponse(body, _ctx) {
26086
+ const openai = body;
26087
+ const choices = openai.choices;
26088
+ if (!choices || choices.length === 0) {
26089
+ return body;
26090
+ }
26091
+ const choice = choices[0];
26092
+ const message = choice.message;
26093
+ if (!message) {
26094
+ return body;
26095
+ }
26096
+ const content = [];
26097
+ if (message.reasoning_content) {
26098
+ content.push({
26099
+ type: "thinking",
26100
+ thinking: message.reasoning_content
26101
+ });
26102
+ }
26103
+ if (message.tool_calls) {
26104
+ const toolCalls = message.tool_calls;
26105
+ content.push(...convertOpenAIToolCallsToAnthropic(toolCalls));
26106
+ }
26107
+ if (message.content && message.content !== null) {
26108
+ const textContent = message.content;
26109
+ if (textContent.length > 0) {
26110
+ content.push({ type: "text", text: textContent });
26111
+ }
26112
+ }
26113
+ const usage = openai.usage;
26114
+ const anthropicUsage = {};
26115
+ if (usage) {
26116
+ anthropicUsage.input_tokens = usage.prompt_tokens || 0;
26117
+ anthropicUsage.output_tokens = usage.completion_tokens || 0;
26118
+ if (usage.prompt_tokens_details) {
26119
+ const details = usage.prompt_tokens_details;
26120
+ if (details.cached_tokens) {
26121
+ anthropicUsage.cache_read_input_tokens = details.cached_tokens;
26122
+ }
26123
+ }
26124
+ }
26125
+ return {
26126
+ id: openai.id || `msg_${Date.now()}`,
26127
+ type: "message",
26128
+ role: "assistant",
26129
+ model: openai.model || "unknown",
26130
+ content,
26131
+ stop_reason: mapFinishReason(choice.finish_reason),
26132
+ stop_sequence: null,
26133
+ usage: anthropicUsage
26134
+ };
26135
+ }
26136
+ function mapFinishReason(finishReason) {
26137
+ if (!finishReason)
26138
+ return null;
26139
+ switch (finishReason) {
26140
+ case "stop":
26141
+ return "end_turn";
26142
+ case "length":
26143
+ return "max_tokens";
26144
+ case "tool_calls":
26145
+ return "tool_use";
26146
+ case "function_call":
26147
+ return "tool_use";
26148
+ case "content_filter":
26149
+ return "end_turn";
26150
+ default:
26151
+ return finishReason;
26152
+ }
26153
+ }
26154
+ var init_openai_chat_to_anthropic = () => {};
26155
+
26156
+ // src/proxy/transform/streaming/openai-chat-to-anthropic.ts
26157
+ function createOpenAIChatToAnthropicStreamTransform(ctx) {
26158
+ const transformer = new OpenAIChatToAnthropicStreamTransformer(ctx);
26159
+ return createSSETransformStream(transformer);
26160
+ }
26161
+ var OpenAIChatToAnthropicStreamTransformer;
26162
+ var init_openai_chat_to_anthropic2 = __esm(() => {
26163
+ init_base();
26164
+ init_transform();
26165
+ init_anthropic_to_openai_chat();
26166
+ init_openai_chat_to_anthropic();
26167
+ OpenAIChatToAnthropicStreamTransformer = class OpenAIChatToAnthropicStreamTransformer extends SSEStreamTransformer {
26168
+ messageId = "";
26169
+ currentModel = "";
26170
+ hasSentMessageStart = false;
26171
+ contentBlockIndex = 0;
26172
+ currentTextBlockIndex = -1;
26173
+ currentThinkingBlockIndex = -1;
26174
+ hasStartedTextBlock = false;
26175
+ hasStartedThinkingBlock = false;
26176
+ toolBlockIndexMap = new Map;
26177
+ openToolBlockIndices = new Set;
26178
+ pendingToolData = new Map;
26179
+ lastEmittedArgsLength = new Map;
26180
+ hasEmittedMessageDelta = false;
26181
+ convertEvent(event) {
26182
+ if (event.data === "[DONE]") {
26183
+ return null;
26184
+ }
26185
+ const data = event.data;
26186
+ const choices = data.choices;
26187
+ if (!choices || choices.length === 0) {
26188
+ return null;
26189
+ }
26190
+ const choice = choices[0];
26191
+ const delta = choice.delta;
26192
+ const finishReason = choice.finish_reason;
26193
+ if (!this.hasSentMessageStart && data.id) {
26194
+ this.messageId = data.id;
26195
+ this.currentModel = data.model || "unknown";
26196
+ }
26197
+ const events = [];
26198
+ if (!this.hasSentMessageStart) {
26199
+ this.hasSentMessageStart = true;
26200
+ events.push({
26201
+ event: "message_start",
26202
+ data: {
26203
+ type: "message_start",
26204
+ message: {
26205
+ id: this.messageId || `msg_${Date.now()}`,
26206
+ type: "message",
26207
+ role: "assistant",
26208
+ model: this.currentModel,
26209
+ content: [],
26210
+ stop_reason: null,
26211
+ stop_sequence: null,
26212
+ usage: { input_tokens: 0, output_tokens: 0 }
26213
+ }
26214
+ }
26215
+ });
26216
+ }
26217
+ if (delta) {
26218
+ if (typeof delta.content === "string" && delta.content.length > 0) {
26219
+ const textBlockIndex = this.ensureTextBlock();
26220
+ if (!this.hasStartedTextBlock) {
26221
+ this.hasStartedTextBlock = true;
26222
+ events.push({
26223
+ event: "content_block_start",
26224
+ data: {
26225
+ type: "content_block_start",
26226
+ index: textBlockIndex,
26227
+ content_block: { type: "text" }
26228
+ }
26229
+ });
26230
+ }
26231
+ events.push({
26232
+ event: "content_block_delta",
26233
+ data: {
26234
+ type: "content_block_delta",
26235
+ index: textBlockIndex,
26236
+ delta: { type: "text_delta", text: delta.content }
26237
+ }
26238
+ });
26239
+ }
26240
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
26241
+ const thinkingBlockIndex = this.ensureThinkingBlock();
26242
+ if (!this.hasStartedThinkingBlock) {
26243
+ this.hasStartedThinkingBlock = true;
26244
+ events.push({
26245
+ event: "content_block_start",
26246
+ data: {
26247
+ type: "content_block_start",
26248
+ index: thinkingBlockIndex,
26249
+ content_block: { type: "thinking" }
26250
+ }
26251
+ });
26252
+ }
26253
+ events.push({
26254
+ event: "content_block_delta",
26255
+ data: {
26256
+ type: "content_block_delta",
26257
+ index: thinkingBlockIndex,
26258
+ delta: { type: "thinking_delta", thinking: delta.reasoning_content }
26259
+ }
26260
+ });
26261
+ }
26262
+ if (delta.tool_calls) {
26263
+ const toolCalls = delta.tool_calls;
26264
+ for (const tc of toolCalls) {
26265
+ const toolEvents = this.handleToolCallDelta(tc);
26266
+ events.push(...toolEvents);
26267
+ }
26268
+ }
26269
+ }
26270
+ if (finishReason && !this.hasEmittedMessageDelta) {
26271
+ this.hasEmittedMessageDelta = true;
26272
+ for (const idx of this.openToolBlockIndices) {
26273
+ events.push({
26274
+ event: "content_block_stop",
26275
+ data: { type: "content_block_stop", index: idx }
26276
+ });
26277
+ }
26278
+ this.openToolBlockIndices.clear();
26279
+ if (this.currentTextBlockIndex >= 0) {
26280
+ events.push({
26281
+ event: "content_block_stop",
26282
+ data: { type: "content_block_stop", index: this.currentTextBlockIndex }
26283
+ });
26284
+ this.currentTextBlockIndex = -1;
26285
+ }
26286
+ if (this.currentThinkingBlockIndex >= 0) {
26287
+ events.push({
26288
+ event: "content_block_stop",
26289
+ data: { type: "content_block_stop", index: this.currentThinkingBlockIndex }
26290
+ });
26291
+ this.currentThinkingBlockIndex = -1;
26292
+ }
26293
+ events.push({
26294
+ event: "message_delta",
26295
+ data: {
26296
+ type: "message_delta",
26297
+ delta: { stop_reason: this.mapStopReason(finishReason), stop_sequence: null },
26298
+ usage: { output_tokens: 0 }
26299
+ }
26300
+ });
26301
+ events.push({
26302
+ event: "message_stop",
26303
+ data: { type: "message_stop" }
26304
+ });
26305
+ }
26306
+ return events;
26307
+ }
26308
+ ensureTextBlock() {
26309
+ if (this.currentTextBlockIndex < 0) {
26310
+ this.currentTextBlockIndex = this.contentBlockIndex++;
26311
+ }
26312
+ return this.currentTextBlockIndex;
26313
+ }
26314
+ ensureThinkingBlock() {
26315
+ if (this.currentThinkingBlockIndex < 0) {
26316
+ this.currentThinkingBlockIndex = this.contentBlockIndex++;
26317
+ }
26318
+ return this.currentThinkingBlockIndex;
26319
+ }
26320
+ handleToolCallDelta(tc) {
26321
+ const index = tc.index;
26322
+ const toolIndex = this.getOrCreateToolBlockIndex(index);
26323
+ const events = [];
26324
+ let pending = this.pendingToolData.get(index);
26325
+ if (!pending) {
26326
+ pending = { id: "", name: "", args: "" };
26327
+ this.pendingToolData.set(index, pending);
26328
+ }
26329
+ if (tc.id)
26330
+ pending.id = tc.id;
26331
+ if (tc.function) {
26332
+ const func = tc.function;
26333
+ if (func.name)
26334
+ pending.name = func.name;
26335
+ if (func.arguments)
26336
+ pending.args += func.arguments;
26337
+ }
26338
+ if (pending.id && pending.name && !this.openToolBlockIndices.has(toolIndex)) {
26339
+ this.openToolBlockIndices.add(toolIndex);
26340
+ events.push({
26341
+ event: "content_block_start",
26342
+ data: {
26343
+ type: "content_block_start",
26344
+ index: toolIndex,
26345
+ content_block: { type: "tool_use", id: pending.id, name: pending.name, input: {} }
26346
+ }
26347
+ });
26348
+ }
26349
+ if (this.openToolBlockIndices.has(toolIndex) && pending.args.length > 0) {
26350
+ const lastEmitted = this.lastEmittedArgsLength.get(index) || 0;
26351
+ if (pending.args.length > lastEmitted) {
26352
+ const newArgs = pending.args.slice(lastEmitted);
26353
+ this.lastEmittedArgsLength.set(index, pending.args.length);
26354
+ events.push({
26355
+ event: "content_block_delta",
26356
+ data: {
26357
+ type: "content_block_delta",
26358
+ index: toolIndex,
26359
+ delta: { type: "input_json_delta", partial_json: newArgs }
26360
+ }
26361
+ });
26362
+ }
26363
+ }
26364
+ return events;
26365
+ }
26366
+ getOrCreateToolBlockIndex(openaiIndex) {
26367
+ let idx = this.toolBlockIndexMap.get(openaiIndex);
26368
+ if (idx === undefined) {
26369
+ idx = this.contentBlockIndex++;
26370
+ this.toolBlockIndexMap.set(openaiIndex, idx);
26371
+ }
26372
+ return idx;
26373
+ }
26374
+ mapStopReason(reason) {
26375
+ switch (reason) {
26376
+ case "stop":
26377
+ return "end_turn";
26378
+ case "length":
26379
+ return "max_tokens";
26380
+ case "tool_calls":
26381
+ return "tool_use";
26382
+ case "function_call":
26383
+ return "tool_use";
26384
+ case "content_filter":
26385
+ return "end_turn";
26386
+ default:
26387
+ return reason;
26388
+ }
26389
+ }
26390
+ };
26391
+ registerTransformer({
26392
+ clientFormat: "anthropic_messages",
26393
+ targetFormat: "openai_chat",
26394
+ requestTransform: anthropicToOpenAIChatRequest,
26395
+ responseTransform: openAIChatToAnthropicResponse,
26396
+ streamTransform: (stream, ctx) => {
26397
+ const transform2 = createOpenAIChatToAnthropicStreamTransform(ctx);
26398
+ return stream.pipeThrough(transform2);
26399
+ }
26400
+ });
26401
+ });
26402
+
25528
26403
  // src/proxy/router.ts
25529
26404
  class ProxyRouter {
25530
26405
  routes = [];
@@ -25619,7 +26494,8 @@ class ProxyForwarder {
25619
26494
  }));
25620
26495
  const credential = profile.authToken || profile.apiKey || "";
25621
26496
  if (credential) {
25622
- if (preset?.wire_api === "responses") {
26497
+ const targetFormat = inferTargetApiFormat(profile, preset || {});
26498
+ if (targetFormat === "anthropic_messages" || targetFormat === "anthropic_responses") {
25623
26499
  headers["x-api-key"] = credential;
25624
26500
  } else {
25625
26501
  headers.authorization = `Bearer ${credential}`;
@@ -25669,6 +26545,7 @@ class ProxyForwarder {
25669
26545
  var init_forwarder = __esm(() => {
25670
26546
  init_presets();
25671
26547
  init_logger();
26548
+ init_transform();
25672
26549
  });
25673
26550
 
25674
26551
  // src/proxy/circuit-breaker.ts
@@ -25865,14 +26742,16 @@ class ProxyHandler {
25865
26742
  timeoutMs;
25866
26743
  instanceId;
25867
26744
  groupName;
26745
+ profileName;
25868
26746
  logger;
25869
- constructor(timeoutMs, instanceId, groupName) {
26747
+ constructor(timeoutMs, instanceId, groupName, profileName) {
25870
26748
  this.router = new ProxyRouter;
25871
26749
  this.forwarder = new ProxyForwarder;
25872
26750
  this.circuitBreaker = new CircuitBreaker;
25873
26751
  this.timeoutMs = timeoutMs;
25874
26752
  this.instanceId = instanceId || "default";
25875
26753
  this.groupName = groupName;
26754
+ this.profileName = profileName;
25876
26755
  this.logger = createProxyLogger(this.instanceId);
25877
26756
  this.setupRoutes();
25878
26757
  }
@@ -25976,7 +26855,117 @@ class ProxyHandler {
25976
26855
  return new Uint8Array(bodyBuffer);
25977
26856
  }
25978
26857
  }
26858
+ async forwardSingleProfile(request, profileName, _format) {
26859
+ const profile = await getProfile(profileName);
26860
+ if (!profile) {
26861
+ this.logger.warn("Profile not found", { profileName });
26862
+ return new Response(JSON.stringify({ error: `Profile not found: ${profileName}` }), {
26863
+ status: 503,
26864
+ headers: { "Content-Type": "application/json" }
26865
+ });
26866
+ }
26867
+ let bodyBuffer;
26868
+ try {
26869
+ bodyBuffer = await request.arrayBuffer();
26870
+ } catch (error46) {
26871
+ this.logger.error("Failed to read request body", error46);
26872
+ return new Response(JSON.stringify({ error: "Failed to read request body" }), {
26873
+ status: 400,
26874
+ headers: { "Content-Type": "application/json" }
26875
+ });
26876
+ }
26877
+ const preset = getPresetById(profile.providerId);
26878
+ const endpoint = new URL(request.url).pathname + new URL(request.url).search;
26879
+ const clientFormat = inferClientFormat(endpoint);
26880
+ const targetFormat = inferTargetApiFormat(profile, preset || {});
26881
+ let transformedBodyBuffer = bodyBuffer;
26882
+ let targetEndpoint = endpoint;
26883
+ let ctx = null;
26884
+ if (clientFormat !== targetFormat) {
26885
+ try {
26886
+ const bodyText = Buffer.from(bodyBuffer).toString("utf-8");
26887
+ const parsedBody = bodyText ? JSON.parse(bodyText) : {};
26888
+ ctx = {
26889
+ endpoint,
26890
+ clientFormat,
26891
+ targetFormat,
26892
+ profile,
26893
+ preset: preset || {},
26894
+ stream: parsedBody.stream === true
26895
+ };
26896
+ const transformed = transformRequest(parsedBody, ctx);
26897
+ transformedBodyBuffer = Buffer.from(JSON.stringify(transformed.body));
26898
+ targetEndpoint = transformed.targetEndpoint || endpoint;
26899
+ } catch (error46) {
26900
+ this.logger.error("Request transform failed, falling back to passthrough", error46);
26901
+ }
26902
+ }
26903
+ const rewrittenBody = this.rewriteRequestBodyForProfile(transformedBodyBuffer, profile);
26904
+ const clonedRequest = {
26905
+ method: request.method,
26906
+ path: targetEndpoint,
26907
+ headers: Object.fromEntries(request.headers.entries()),
26908
+ body: rewrittenBody
26909
+ };
26910
+ try {
26911
+ const forwardResponse = await this.forwarder.forward(clonedRequest, profile, this.timeoutMs);
26912
+ const isSuccess = forwardResponse.status >= 200 && forwardResponse.status < 300;
26913
+ if (!isSuccess) {
26914
+ this.logger.warn("Provider returned upstream status", {
26915
+ profileName,
26916
+ status: forwardResponse.status
26917
+ });
26918
+ return new Response(forwardResponse.body, {
26919
+ status: forwardResponse.status,
26920
+ headers: forwardResponse.headers
26921
+ });
26922
+ }
26923
+ if (ctx && clientFormat !== targetFormat) {
26924
+ if (forwardResponse.isStream && forwardResponse.body) {
26925
+ const transformedStream = transformStream(forwardResponse.body, ctx);
26926
+ return new Response(transformedStream, {
26927
+ status: forwardResponse.status,
26928
+ headers: forwardResponse.headers
26929
+ });
26930
+ }
26931
+ try {
26932
+ const responseText = forwardResponse.body;
26933
+ const responseParsed = responseText ? JSON.parse(responseText) : {};
26934
+ const transformedResponse = transformResponse(responseParsed, ctx);
26935
+ return new Response(JSON.stringify(transformedResponse), {
26936
+ status: forwardResponse.status,
26937
+ headers: forwardResponse.headers
26938
+ });
26939
+ } catch (error46) {
26940
+ this.logger.error("Response transform failed, returning raw response", error46);
26941
+ return new Response(forwardResponse.body, {
26942
+ status: forwardResponse.status,
26943
+ headers: forwardResponse.headers
26944
+ });
26945
+ }
26946
+ }
26947
+ if (forwardResponse.isStream) {
26948
+ return new Response(forwardResponse.body, {
26949
+ status: forwardResponse.status,
26950
+ headers: forwardResponse.headers
26951
+ });
26952
+ }
26953
+ return new Response(forwardResponse.body, {
26954
+ status: forwardResponse.status,
26955
+ headers: forwardResponse.headers
26956
+ });
26957
+ } catch (error46) {
26958
+ this.logger.error("Provider request failed", error46, { profileName });
26959
+ return new Response(JSON.stringify({ error: error46.message }), {
26960
+ status: 502,
26961
+ headers: { "Content-Type": "application/json" }
26962
+ });
26963
+ }
26964
+ }
25979
26965
  async forwardToProvider(request, format) {
26966
+ if (this.profileName) {
26967
+ return this.forwardSingleProfile(request, this.profileName, format);
26968
+ }
25980
26969
  const group = this.groupName ? await getGroup(this.groupName) : await getActiveGroup();
25981
26970
  if (!group || group.profiles.length === 0) {
25982
26971
  this.logger.warn("No active group or profiles");
@@ -26008,15 +26997,42 @@ class ProxyHandler {
26008
26997
  continue;
26009
26998
  }
26010
26999
  const preset = getPresetById(profile.providerId);
26011
- if (format === "chat" && preset?.wire_api === "responses") {
26012
- this.logger.info("Skipping responses-only provider for chat endpoint", { profileId, wire_api: preset.wire_api });
26013
- continue;
27000
+ const endpoint = new URL(request.url).pathname + new URL(request.url).search;
27001
+ const clientFormat = inferClientFormat(endpoint);
27002
+ const targetFormat = inferTargetApiFormat(profile, preset || {});
27003
+ if (clientFormat !== targetFormat) {
27004
+ if (!getTransformer(clientFormat, targetFormat)) {
27005
+ this.logger.info("Skipping provider: no transformer for format pair", { profileId, clientFormat, targetFormat });
27006
+ continue;
27007
+ }
27008
+ }
27009
+ let transformedBodyBuffer = bodyBuffer;
27010
+ let targetEndpoint = endpoint;
27011
+ let ctx = null;
27012
+ if (clientFormat !== targetFormat) {
27013
+ try {
27014
+ const bodyText = Buffer.from(bodyBuffer).toString("utf-8");
27015
+ const parsedBody = bodyText ? JSON.parse(bodyText) : {};
27016
+ ctx = {
27017
+ endpoint,
27018
+ clientFormat,
27019
+ targetFormat,
27020
+ profile,
27021
+ preset: preset || {},
27022
+ stream: parsedBody.stream === true
27023
+ };
27024
+ const transformed = transformRequest(parsedBody, ctx);
27025
+ transformedBodyBuffer = Buffer.from(JSON.stringify(transformed.body));
27026
+ targetEndpoint = transformed.targetEndpoint || endpoint;
27027
+ } catch (error46) {
27028
+ this.logger.error("Request transform failed, falling back to passthrough", error46);
27029
+ }
26014
27030
  }
26015
27031
  try {
26016
- const rewrittenBody = this.rewriteRequestBodyForProfile(bodyBuffer, profile);
27032
+ const rewrittenBody = this.rewriteRequestBodyForProfile(transformedBodyBuffer, profile);
26017
27033
  const clonedRequest = {
26018
27034
  method: request.method,
26019
- path: new URL(request.url).pathname + new URL(request.url).search,
27035
+ path: targetEndpoint,
26020
27036
  headers: Object.fromEntries(request.headers.entries()),
26021
27037
  body: rewrittenBody
26022
27038
  };
@@ -26040,6 +27056,30 @@ class ProxyHandler {
26040
27056
  continue;
26041
27057
  }
26042
27058
  this.circuitBreaker.recordSuccess(profileId);
27059
+ if (ctx && clientFormat !== targetFormat) {
27060
+ if (forwardResponse.isStream && forwardResponse.body) {
27061
+ const transformedStream = transformStream(forwardResponse.body, ctx);
27062
+ return new Response(transformedStream, {
27063
+ status: forwardResponse.status,
27064
+ headers: forwardResponse.headers
27065
+ });
27066
+ }
27067
+ try {
27068
+ const responseText = forwardResponse.body;
27069
+ const responseParsed = responseText ? JSON.parse(responseText) : {};
27070
+ const transformedResponse = transformResponse(responseParsed, ctx);
27071
+ return new Response(JSON.stringify(transformedResponse), {
27072
+ status: forwardResponse.status,
27073
+ headers: forwardResponse.headers
27074
+ });
27075
+ } catch (error46) {
27076
+ this.logger.error("Response transform failed, returning raw response", error46);
27077
+ return new Response(forwardResponse.body, {
27078
+ status: forwardResponse.status,
27079
+ headers: forwardResponse.headers
27080
+ });
27081
+ }
27082
+ }
26043
27083
  if (forwardResponse.isStream) {
26044
27084
  return new Response(forwardResponse.body, {
26045
27085
  status: forwardResponse.status,
@@ -26071,12 +27111,14 @@ class ProxyHandler {
26071
27111
  }
26072
27112
  }
26073
27113
  var init_handler = __esm(() => {
27114
+ init_openai_chat_to_anthropic2();
26074
27115
  init_model_helper();
26075
27116
  init_forwarder();
26076
27117
  init_manager2();
26077
27118
  init_manager();
26078
27119
  init_logger();
26079
27120
  init_presets();
27121
+ init_transform();
26080
27122
  });
26081
27123
 
26082
27124
  // src/proxy/server.ts
@@ -26243,7 +27285,7 @@ async function startProxyServer(config2) {
26243
27285
  if (existing) {
26244
27286
  throw new Error(`Port ${config2.port} already in use by instance "${existing.instanceId}"`);
26245
27287
  }
26246
- const handler = new ProxyHandler(config2.timeout, config2.instanceId, config2.groupName);
27288
+ const handler = new ProxyHandler(config2.timeout, config2.instanceId, config2.groupName, config2.profileName);
26247
27289
  const server = http.createServer(async (req, res) => {
26248
27290
  const status2 = statuses.get(instanceId);
26249
27291
  if (status2) {
@@ -26284,6 +27326,7 @@ async function startProxyServer(config2) {
26284
27326
  port: config2.port,
26285
27327
  groupName: config2.groupName,
26286
27328
  activeGroup: config2.groupName,
27329
+ profileName: config2.profileName,
26287
27330
  pid: process.pid,
26288
27331
  startTime: new Date().toISOString(),
26289
27332
  requestCount: 0,
@@ -26529,7 +27572,7 @@ var init_client = __esm(() => {
26529
27572
 
26530
27573
  // src/auth/token.ts
26531
27574
  import { existsSync as existsSync13 } from "node:fs";
26532
- import { readFile as readFile10, writeFile as writeFile9, unlink as unlink3 } from "node:fs/promises";
27575
+ import { readFile as readFile10, writeFile as writeFile9, unlink as unlink4 } from "node:fs/promises";
26533
27576
  import { join as join11 } from "node:path";
26534
27577
  function getAuthFilePath() {
26535
27578
  return join11(getConfigDir("swixter"), AUTH_FILE);
@@ -26552,7 +27595,7 @@ async function saveAuthState(state) {
26552
27595
  async function clearAuthState() {
26553
27596
  const authPath = getAuthFilePath();
26554
27597
  if (existsSync13(authPath)) {
26555
- await unlink3(authPath);
27598
+ await unlink4(authPath);
26556
27599
  }
26557
27600
  }
26558
27601
  function isExpired(expiresAt) {
@@ -27375,7 +28418,7 @@ function resolveProxyRuntimeBinding(input) {
27375
28418
  reuseExisting: false
27376
28419
  };
27377
28420
  }
27378
- const existing = input.allInstances.find((s) => s.running && s.groupName === input.groupName);
28421
+ const existing = input.allInstances.find((s) => s.running && (input.groupName && s.groupName === input.groupName || input.profileName && s.profileName === input.profileName));
27379
28422
  if (existing) {
27380
28423
  return {
27381
28424
  host: existing.host,
@@ -27466,6 +28509,7 @@ async function handleProxyCommand(args) {
27466
28509
  }
27467
28510
  async function cmdStart(args) {
27468
28511
  let groupName;
28512
+ let profileName;
27469
28513
  let port;
27470
28514
  let host = "127.0.0.1";
27471
28515
  let timeout = 3000000;
@@ -27474,6 +28518,9 @@ async function cmdStart(args) {
27474
28518
  if (args[i2] === "--group" && args[i2 + 1]) {
27475
28519
  groupName = args[i2 + 1];
27476
28520
  i2++;
28521
+ } else if (args[i2] === "--profile" && args[i2 + 1]) {
28522
+ profileName = args[i2 + 1];
28523
+ i2++;
27477
28524
  } else if (args[i2] === "--port" && args[i2 + 1]) {
27478
28525
  port = parseInt(args[i2 + 1], 10);
27479
28526
  i2++;
@@ -27487,6 +28534,11 @@ async function cmdStart(args) {
27487
28534
  daemon = true;
27488
28535
  }
27489
28536
  }
28537
+ if (groupName && profileName) {
28538
+ console.log(import_picocolors18.default.red("Cannot specify both --group and --profile"));
28539
+ process.exit(EXIT_CODES.invalidArguments);
28540
+ return;
28541
+ }
27490
28542
  if (groupName) {
27491
28543
  const group = await getGroup(groupName);
27492
28544
  if (!group) {
@@ -27495,12 +28547,20 @@ async function cmdStart(args) {
27495
28547
  return;
27496
28548
  }
27497
28549
  }
28550
+ if (profileName) {
28551
+ const profile = await getProfile(profileName);
28552
+ if (!profile) {
28553
+ console.log(import_picocolors18.default.red(`Profile "${profileName}" not found`));
28554
+ process.exit(EXIT_CODES.notFound);
28555
+ return;
28556
+ }
28557
+ }
27498
28558
  const defaultStatus = getProxyStatus("default");
27499
28559
  if (defaultStatus.running) {
27500
28560
  console.log(import_picocolors18.default.yellow(`Default proxy already running on ${defaultStatus.host}:${defaultStatus.port}`));
27501
28561
  return;
27502
28562
  }
27503
- if (!groupName) {
28563
+ if (!groupName && !profileName) {
27504
28564
  const activeGroup = await getActiveGroup();
27505
28565
  if (activeGroup) {
27506
28566
  groupName = activeGroup.name;
@@ -27509,9 +28569,9 @@ async function cmdStart(args) {
27509
28569
  }
27510
28570
  const resolvedPort = port || DEFAULT_PROXY_PORT;
27511
28571
  if (daemon) {
27512
- await cmdStartDaemon({ host, port: resolvedPort, timeout, groupName });
28572
+ await cmdStartDaemon({ host, port: resolvedPort, timeout, groupName, profileName });
27513
28573
  } else {
27514
- await cmdStartBlocking({ host, port: resolvedPort, timeout, groupName });
28574
+ await cmdStartBlocking({ host, port: resolvedPort, timeout, groupName, profileName });
27515
28575
  }
27516
28576
  }
27517
28577
  async function cmdStartBlocking(config2) {
@@ -27522,7 +28582,8 @@ async function cmdStartBlocking(config2) {
27522
28582
  host: config2.host,
27523
28583
  port: config2.port,
27524
28584
  timeout: config2.timeout,
27525
- groupName: config2.groupName
28585
+ groupName: config2.groupName,
28586
+ profileName: config2.profileName
27526
28587
  });
27527
28588
  console.log();
27528
28589
  console.log(import_picocolors18.default.green("✓ Proxy server started"));
@@ -27530,6 +28591,7 @@ async function cmdStartBlocking(config2) {
27530
28591
  console.log(` Address: ${config2.host}:${config2.port}`);
27531
28592
  console.log(` Timeout: ${config2.timeout}ms`);
27532
28593
  console.log(import_picocolors18.default.dim(` Group: ${config2.groupName || "none"}`));
28594
+ console.log(import_picocolors18.default.dim(` Profile: ${config2.profileName || "none"}`));
27533
28595
  console.log(import_picocolors18.default.dim(` Endpoints:`));
27534
28596
  console.log(import_picocolors18.default.dim(` - /v1/chat/completions (OpenAI)`));
27535
28597
  console.log(import_picocolors18.default.dim(` - /v1/messages (Anthropic)`));
@@ -27559,6 +28621,9 @@ async function cmdStartDaemon(config2) {
27559
28621
  if (config2.groupName) {
27560
28622
  args.push("--group", config2.groupName);
27561
28623
  }
28624
+ if (config2.profileName) {
28625
+ args.push("--profile", config2.profileName);
28626
+ }
27562
28627
  const child = spawn4(process.execPath, [process.argv[1], ...args], {
27563
28628
  detached: true,
27564
28629
  stdio: "ignore"
@@ -27589,44 +28654,64 @@ async function cmdStop(args) {
27589
28654
  }
27590
28655
  async function cmdRun4(args) {
27591
28656
  const doubleDash = args.indexOf("--");
27592
- let groupArgs = [];
28657
+ let proxyArgs = [];
27593
28658
  let coderArgs = [];
27594
28659
  if (doubleDash >= 0) {
27595
- groupArgs = args.slice(0, doubleDash);
28660
+ proxyArgs = args.slice(0, doubleDash);
27596
28661
  coderArgs = args.slice(doubleDash + 1);
27597
28662
  } else {
27598
- groupArgs = args;
28663
+ proxyArgs = args;
27599
28664
  }
27600
28665
  let groupName;
28666
+ let profileName;
27601
28667
  let requestedPort;
27602
- for (let i2 = 0;i2 < groupArgs.length; i2++) {
27603
- if (groupArgs[i2] === "--group" && groupArgs[i2 + 1]) {
27604
- groupName = groupArgs[i2 + 1];
28668
+ for (let i2 = 0;i2 < proxyArgs.length; i2++) {
28669
+ if (proxyArgs[i2] === "--group" && proxyArgs[i2 + 1]) {
28670
+ groupName = proxyArgs[i2 + 1];
28671
+ i2++;
28672
+ } else if (proxyArgs[i2] === "--profile" && proxyArgs[i2 + 1]) {
28673
+ profileName = proxyArgs[i2 + 1];
27605
28674
  i2++;
27606
- } else if (groupArgs[i2] === "--port" && groupArgs[i2 + 1]) {
27607
- requestedPort = parseInt(groupArgs[i2 + 1], 10);
28675
+ } else if (proxyArgs[i2] === "--port" && proxyArgs[i2 + 1]) {
28676
+ requestedPort = parseInt(proxyArgs[i2 + 1], 10);
27608
28677
  i2++;
27609
28678
  }
27610
28679
  }
27611
- if (!groupName) {
28680
+ if (groupName && profileName) {
28681
+ console.log(import_picocolors18.default.red("Cannot specify both --group and --profile"));
28682
+ process.exit(EXIT_CODES.invalidArguments);
28683
+ return;
28684
+ }
28685
+ if (groupName) {
28686
+ const group = await getGroup(groupName);
28687
+ if (!group) {
28688
+ console.log(import_picocolors18.default.red(`Group "${groupName}" not found`));
28689
+ process.exit(EXIT_CODES.notFound);
28690
+ return;
28691
+ }
28692
+ }
28693
+ if (profileName) {
28694
+ const profile = await getProfile(profileName);
28695
+ if (!profile) {
28696
+ console.log(import_picocolors18.default.red(`Profile "${profileName}" not found`));
28697
+ process.exit(EXIT_CODES.notFound);
28698
+ return;
28699
+ }
28700
+ }
28701
+ if (!groupName && !profileName) {
27612
28702
  const activeGroup = await getActiveGroup();
27613
28703
  groupName = activeGroup?.name;
27614
28704
  }
27615
- if (!groupName) {
27616
- console.log(import_picocolors18.default.red("No group specified and no default group set"));
27617
- console.log(import_picocolors18.default.dim("Use --group or create a default group first"));
27618
- return;
27619
- }
27620
- const group = await getGroup(groupName);
27621
- if (!group) {
27622
- console.log(import_picocolors18.default.red(`Group "${groupName}" not found`));
27623
- process.exit(EXIT_CODES.notFound);
28705
+ if (!groupName && !profileName) {
28706
+ console.log(import_picocolors18.default.red("No group or profile specified, and no default group set"));
28707
+ console.log(import_picocolors18.default.dim("Use --group, --profile, or create a default group first"));
27624
28708
  return;
27625
28709
  }
27626
28710
  console.log(import_picocolors18.default.cyan("Starting proxy server..."));
27627
28711
  const allInstances = listProxyInstances();
27628
28712
  const runtimeBinding = resolveProxyRuntimeBinding({
27629
28713
  groupName,
28714
+ profileName,
27630
28715
  requestedPort,
27631
28716
  allInstances
27632
28717
  });
@@ -27637,7 +28722,8 @@ async function cmdRun4(args) {
27637
28722
  type: "run",
27638
28723
  host: runtimeBinding.host,
27639
28724
  port: runtimeBinding.port,
27640
- groupName
28725
+ groupName,
28726
+ profileName
27641
28727
  });
27642
28728
  }
27643
28729
  const coder = coderArgs[0];
@@ -27651,15 +28737,21 @@ async function cmdRun4(args) {
27651
28737
  console.log(import_picocolors18.default.green(`✓ Running: ${coder} ${coderArgs.slice(1).join(" ")}`));
27652
28738
  console.log(import_picocolors18.default.dim(` Instance: ${instanceId} (run)`));
27653
28739
  console.log(import_picocolors18.default.dim(` Proxy: ${runtimeBinding.host}:${runtimeBinding.port}`));
28740
+ if (groupName) {
28741
+ console.log(import_picocolors18.default.dim(` Group: ${groupName}`));
28742
+ }
28743
+ if (profileName) {
28744
+ console.log(import_picocolors18.default.dim(` Profile: ${profileName}`));
28745
+ }
27654
28746
  if (coder === "claude") {
27655
- const firstProfile = group.profiles[0] ? await getProfile(group.profiles[0]) : null;
28747
+ const targetProfile = profileName ? await getProfile(profileName) : groupName ? (await getGroup(groupName))?.profiles[0] ? await getProfile((await getGroup(groupName)).profiles[0]) : null : null;
27656
28748
  const proxyProfile = {
27657
- name: `proxy-${groupName}`,
28749
+ name: profileName ? `proxy-${profileName}` : `proxy-${groupName}`,
27658
28750
  providerId: "anthropic",
27659
28751
  apiKey: "",
27660
28752
  authToken: SWIXTER_PROXY_AUTH_TOKEN,
27661
28753
  baseURL: `http://${runtimeBinding.host}:${runtimeBinding.port}`,
27662
- models: firstProfile ? buildClaudeProxyMarkerModels(firstProfile) : undefined,
28754
+ models: targetProfile ? buildClaudeProxyMarkerModels(targetProfile) : undefined,
27663
28755
  createdAt: new Date().toISOString(),
27664
28756
  updatedAt: new Date().toISOString()
27665
28757
  };
@@ -27702,6 +28794,7 @@ async function cmdStatus3() {
27702
28794
  console.log(` ${import_picocolors18.default.green("●")} ${import_picocolors18.default.bold(status.instanceId)} (${typeLabel})`);
27703
28795
  console.log(` Address: ${status.host}:${status.port}`);
27704
28796
  console.log(` Group: ${status.groupName || "none"}`);
28797
+ console.log(` Profile: ${status.profileName || "none"}`);
27705
28798
  console.log(` Requests: ${status.requestCount} | Errors: ${status.errorCount}`);
27706
28799
  if (status.startTime) {
27707
28800
  console.log(` Started: ${status.startTime}`);
@@ -27724,6 +28817,7 @@ ${import_picocolors18.default.bold("Commands:")}
27724
28817
 
27725
28818
  ${import_picocolors18.default.bold("Options:")}
27726
28819
  ${import_picocolors18.default.dim("--group <name>")} Use specified group
28820
+ ${import_picocolors18.default.dim("--profile <name>")} Use specified profile (single-profile gateway mode)
27727
28821
  ${import_picocolors18.default.dim("--port <port>")} Proxy port (default: 15721)
27728
28822
  ${import_picocolors18.default.dim("--host <host>")} Proxy host (default: 127.0.0.1)
27729
28823
  ${import_picocolors18.default.dim("--timeout <ms>")} Request timeout in ms (default: 3000000)
@@ -27733,7 +28827,9 @@ ${import_picocolors18.default.bold("Examples:")}
27733
28827
  ${import_picocolors18.default.green("swixter proxy start")}
27734
28828
  ${import_picocolors18.default.green("swixter proxy start --daemon")}
27735
28829
  ${import_picocolors18.default.green("swixter proxy start --group my-group")}
28830
+ ${import_picocolors18.default.green("swixter proxy start --profile my-profile")}
27736
28831
  ${import_picocolors18.default.green("swixter proxy run --group my-group -- claude")}
28832
+ ${import_picocolors18.default.green("swixter proxy run --profile my-profile -- claude")}
27737
28833
  ${import_picocolors18.default.green("swixter proxy stop")}
27738
28834
  ${import_picocolors18.default.green("swixter proxy stop run-15722")}
27739
28835
  ${import_picocolors18.default.dim(" # Stop a specific run instance")}
@@ -28523,6 +29619,7 @@ init_dist2();
28523
29619
  init_manager();
28524
29620
  init_presets();
28525
29621
  init_adapters();
29622
+ init_types2();
28526
29623
  init_constants();
28527
29624
  init_ui();
28528
29625
  init_validation();
@@ -28612,7 +29709,7 @@ ${import_picocolors10.default.bold("Create profile (interactive):")}
28612
29709
  ${import_picocolors10.default.green(`swixter ${CODER_NAME3} create`)}
28613
29710
 
28614
29711
  ${import_picocolors10.default.bold("Create profile (non-interactive):")}
28615
- ${import_picocolors10.default.green(`swixter ${CODER_NAME3} create --quiet --name <name> --provider <id> --api-key <key> [--base-url <url>] [--model <model>] [--env-key <var>] [--apply]`)}
29712
+ ${import_picocolors10.default.green(`swixter ${CODER_NAME3} create --quiet --name <name> --provider <id> --api-key <key> [--base-url <url>] [--model <model>] [--env-key <var>] [--api-format <format>] [--apply]`)}
28616
29713
 
28617
29714
  ${import_picocolors10.default.bold("Examples:")}
28618
29715
  ${import_picocolors10.default.dim("# Interactive profile creation")}
@@ -28655,8 +29752,8 @@ async function cmdCreateInteractive3() {
28655
29752
  console.log();
28656
29753
  console.log(import_picocolors10.default.bold(import_picocolors10.default.cyan(PROMPTS.createProfile(CODER_CONFIG3.displayName))));
28657
29754
  console.log();
28658
- const { getProvidersByWireApi: getProvidersByWireApi2 } = await Promise.resolve().then(() => (init_presets(), exports_presets));
28659
- const presets = await getProvidersByWireApi2("chat");
29755
+ const { getAllPresets: getAllPresets2 } = await Promise.resolve().then(() => (init_presets(), exports_presets));
29756
+ const presets = await getAllPresets2();
28660
29757
  const name = await he({
28661
29758
  message: PROMPTS.configName,
28662
29759
  placeholder: DEFAULT_PLACEHOLDERS.configName,
@@ -28706,6 +29803,23 @@ async function cmdCreateInteractive3() {
28706
29803
  xe(ERRORS.cancelled);
28707
29804
  process.exit(EXIT_CODES.cancelled);
28708
29805
  }
29806
+ let apiFormat = null;
29807
+ if (providerId === "custom") {
29808
+ apiFormat = await ve({
29809
+ message: "Select the API format for this provider",
29810
+ options: [
29811
+ { value: "openai_chat", label: "OpenAI Chat", hint: "OpenAI-compatible /v1/chat/completions" },
29812
+ { value: "anthropic_messages", label: "Anthropic Messages", hint: "Anthropic /v1/messages" },
29813
+ { value: "openai_responses", label: "OpenAI Responses", hint: "OpenAI Responses API" },
29814
+ { value: "anthropic_responses", label: "Anthropic Responses", hint: "Anthropic Responses API" },
29815
+ { value: "gemini_native", label: "Gemini Native", hint: "Google Gemini API" }
29816
+ ]
29817
+ });
29818
+ if (pD(apiFormat)) {
29819
+ xe(ERRORS.cancelled);
29820
+ process.exit(EXIT_CODES.cancelled);
29821
+ }
29822
+ }
28709
29823
  let modelName = "";
28710
29824
  if (preset && preset.defaultModels && preset.defaultModels.length > 0) {
28711
29825
  modelName = await ve({
@@ -28793,6 +29907,9 @@ async function cmdCreateInteractive3() {
28793
29907
  if (customEnvKey && customEnvKey.trim() !== "") {
28794
29908
  profile.envKey = customEnvKey.trim();
28795
29909
  }
29910
+ if (apiFormat) {
29911
+ profile.apiFormat = apiFormat;
29912
+ }
28796
29913
  await upsertProfile(profile, CODER_NAME3);
28797
29914
  spinner.stop("Profile created successfully!");
28798
29915
  console.log();
@@ -28815,7 +29932,7 @@ async function cmdCreateInteractive3() {
28815
29932
  async function cmdCreateQuiet3(params) {
28816
29933
  if (!params.name || !params.provider) {
28817
29934
  console.log(import_picocolors10.default.red("Error: Missing required parameters"));
28818
- console.log(import_picocolors10.default.dim(`Usage: swixter ${CODER_NAME3} create --quiet --name <name> --provider <id> [--api-key <key>] [--base-url <url>] [--model <model>] [--env-key <var>] [--apply]`));
29935
+ console.log(import_picocolors10.default.dim(`Usage: swixter ${CODER_NAME3} create --quiet --name <name> --provider <id> [--api-key <key>] [--base-url <url>] [--model <model>] [--env-key <var>] [--api-format <format>] [--apply]`));
28819
29936
  process.exit(1);
28820
29937
  }
28821
29938
  const preset = await getPresetByIdAsync(params.provider);
@@ -28824,16 +29941,16 @@ async function cmdCreateQuiet3(params) {
28824
29941
  console.log(import_picocolors10.default.dim("Run 'swixter providers' to see all supported providers"));
28825
29942
  process.exit(1);
28826
29943
  }
28827
- if (preset.wire_api !== "chat") {
28828
- console.log(import_picocolors10.default.red(`Error: Provider "${preset.displayName}" is not compatible with ${CODER_CONFIG3.displayName}`));
28829
- console.log(import_picocolors10.default.dim(`${CODER_CONFIG3.displayName} only supports OpenAI-compatible providers (chat API).`));
28830
- console.log(import_picocolors10.default.dim("Use 'ollama' or 'custom' provider instead."));
28831
- process.exit(1);
28832
- }
28833
29944
  if (params.provider !== "ollama" && !params["api-key"]) {
28834
29945
  console.log(import_picocolors10.default.red("Error: This provider requires --api-key parameter"));
28835
29946
  process.exit(1);
28836
29947
  }
29948
+ const apiFormat = params["api-format"];
29949
+ if (apiFormat && !API_FORMATS.includes(apiFormat)) {
29950
+ console.log(import_picocolors10.default.red(`Invalid apiFormat: ${apiFormat}`));
29951
+ console.log(import_picocolors10.default.dim(`Valid values: ${API_FORMATS.join(", ")}`));
29952
+ process.exit(EXIT_CODES.invalidArguments);
29953
+ }
28837
29954
  try {
28838
29955
  const finalBaseURL = params["base-url"] || preset.baseURLChat || preset.baseURL;
28839
29956
  const finalModel = params.model;
@@ -28853,6 +29970,9 @@ async function cmdCreateQuiet3(params) {
28853
29970
  if (params["env-key"]) {
28854
29971
  profile.envKey = params["env-key"];
28855
29972
  }
29973
+ if (apiFormat) {
29974
+ profile.apiFormat = apiFormat;
29975
+ }
28856
29976
  await upsertProfile(profile, CODER_NAME3);
28857
29977
  console.log();
28858
29978
  console.log(import_picocolors10.default.green("✓") + " Profile created successfully!");
@@ -28993,8 +30113,8 @@ async function cmdEdit3(profileName) {
28993
30113
  console.log();
28994
30114
  console.log(import_picocolors10.default.bold(import_picocolors10.default.cyan(`Edit profile: ${profileName}`)));
28995
30115
  console.log();
28996
- const { getProvidersByWireApi: getProvidersByWireApi2 } = await Promise.resolve().then(() => (init_presets(), exports_presets));
28997
- const presets = await getProvidersByWireApi2("chat");
30116
+ const { getAllPresets: getAllPresets2 } = await Promise.resolve().then(() => (init_presets(), exports_presets));
30117
+ const presets = await getAllPresets2();
28998
30118
  const currentPreset = await getPresetByIdAsync(profile.providerId);
28999
30119
  const shouldChangeProvider = await ye({
29000
30120
  message: `Change provider? Current: ${currentPreset?.displayName}`,
@@ -29104,6 +30224,21 @@ async function cmdEdit3(profileName) {
29104
30224
  xe(ERRORS.cancelled);
29105
30225
  return;
29106
30226
  }
30227
+ const currentApiFormat = profile.apiFormat || "auto-detect";
30228
+ const apiFormatOptions = [
30229
+ { value: "", label: "Keep current" },
30230
+ { value: "clear", label: "Auto-detect (clear explicit format)" },
30231
+ ...API_FORMATS.map((f) => ({ value: f, label: f }))
30232
+ ];
30233
+ const newApiFormat = await ve({
30234
+ message: `Select target API format (current: ${currentApiFormat})`,
30235
+ options: apiFormatOptions,
30236
+ initialValue: profile.apiFormat || ""
30237
+ });
30238
+ if (pD(newApiFormat)) {
30239
+ xe(ERRORS.cancelled);
30240
+ return;
30241
+ }
29107
30242
  const shouldApply = await ye({
29108
30243
  message: `Apply this profile to ${CODER_CONFIG3.displayName} now?`,
29109
30244
  initialValue: false
@@ -29143,6 +30278,13 @@ async function cmdEdit3(profileName) {
29143
30278
  updatedProfile.envKey = profile.envKey;
29144
30279
  }
29145
30280
  }
30281
+ if (newApiFormat === "clear") {} else if (newApiFormat) {
30282
+ updatedProfile.apiFormat = newApiFormat;
30283
+ } else {
30284
+ if (profile.apiFormat) {
30285
+ updatedProfile.apiFormat = profile.apiFormat;
30286
+ }
30287
+ }
29146
30288
  const finalBaseURL = updatedProfile.baseURL || newPreset?.baseURL || "";
29147
30289
  await upsertProfile(updatedProfile, CODER_NAME3);
29148
30290
  spinner.stop("Profile updated successfully!");
@@ -29184,19 +30326,10 @@ async function cmdApply3() {
29184
30326
  console.log(` Provider: ${import_picocolors10.default.yellow(preset?.displayName)}`);
29185
30327
  console.log(` Config file: ${import_picocolors10.default.dim(adapter.configPath)}`);
29186
30328
  console.log();
29187
- if (adapter.name === "codex" && "getEnvExportCommands" in adapter) {
29188
- const envCommands = await adapter.getEnvExportCommands(profile);
29189
- if (envCommands.length > 0) {
29190
- console.log(import_picocolors10.default.bold("To use this profile, set environment variables:"));
29191
- console.log();
29192
- envCommands.forEach((cmd) => {
29193
- console.log(` ${import_picocolors10.default.green(cmd)}`);
29194
- });
29195
- console.log();
29196
- console.log(import_picocolors10.default.dim(`Then run: ${import_picocolors10.default.cyan("codex")}`));
29197
- console.log();
29198
- }
29199
- }
30329
+ console.log(import_picocolors10.default.bold("Run Codex now: ") + import_picocolors10.default.cyan("codex"));
30330
+ console.log();
30331
+ console.log(import_picocolors10.default.dim("Environment variables are automatically managed via auth.json."));
30332
+ console.log();
29200
30333
  } else {
29201
30334
  console.log(import_picocolors10.default.yellow("⚠ Profile written, but verification failed"));
29202
30335
  console.log(import_picocolors10.default.dim("Please check config file format"));
@@ -29436,7 +30569,7 @@ import { existsSync as existsSync11 } from "node:fs";
29436
30569
  import { dirname as dirname9, join as join9 } from "node:path";
29437
30570
  import { fileURLToPath } from "node:url";
29438
30571
 
29439
- // node_modules/ws/wrapper.mjs
30572
+ // ../../node_modules/ws/wrapper.mjs
29440
30573
  var import_stream = __toESM(require_stream(), 1);
29441
30574
  var import_extension = __toESM(require_extension(), 1);
29442
30575
  var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
@@ -30112,7 +31245,7 @@ init_versions2();
30112
31245
  init_paths();
30113
31246
  init_export();
30114
31247
  import { existsSync as existsSync9, statSync as statSync2 } from "node:fs";
30115
- import { readFile as readFile8, writeFile as writeFile7, unlink } from "node:fs/promises";
31248
+ import { readFile as readFile8, writeFile as writeFile7, unlink as unlink2 } from "node:fs/promises";
30116
31249
  import { join as join8 } from "node:path";
30117
31250
  async function getVersion(req, res) {
30118
31251
  sendJson(res, {
@@ -30175,7 +31308,7 @@ async function exportConfigFile(req, res) {
30175
31308
  res.end(content);
30176
31309
  } finally {
30177
31310
  try {
30178
- await unlink(tempPath);
31311
+ await unlink2(tempPath);
30179
31312
  } catch {}
30180
31313
  }
30181
31314
  } catch (error46) {
@@ -30197,7 +31330,7 @@ async function importConfigFile(req, res) {
30197
31330
  sendJson(res, { success: true, ...result });
30198
31331
  } finally {
30199
31332
  try {
30200
- await unlink(tempPath);
31333
+ await unlink2(tempPath);
30201
31334
  } catch {}
30202
31335
  }
30203
31336
  } catch (error46) {
@@ -30546,7 +31679,7 @@ async function startServer(portArg, options) {
30546
31679
  // src/utils/daemon.ts
30547
31680
  init_paths();
30548
31681
  import { existsSync as existsSync12 } from "node:fs";
30549
- import { readFile as readFile9, writeFile as writeFile8, unlink as unlink2 } from "node:fs/promises";
31682
+ import { readFile as readFile9, writeFile as writeFile8, unlink as unlink3 } from "node:fs/promises";
30550
31683
  import { join as join10 } from "node:path";
30551
31684
  function getPidFilePath() {
30552
31685
  return join10(getConfigDir("swixter"), "ui.pid");
@@ -30573,7 +31706,7 @@ async function writePidFile(pid, port) {
30573
31706
  async function removePidFile() {
30574
31707
  const path = getPidFilePath();
30575
31708
  if (existsSync12(path)) {
30576
- await unlink2(path).catch(() => {});
31709
+ await unlink3(path).catch(() => {});
30577
31710
  }
30578
31711
  }
30579
31712
  function isProcessAlive2(pid) {
@@ -30613,12 +31746,22 @@ async function stopDaemon() {
30613
31746
  }
30614
31747
  try {
30615
31748
  process.kill(data.pid, "SIGTERM");
30616
- await removePidFile();
30617
- return { success: true, message: `Daemon process ${data.pid} stopped.` };
30618
31749
  } catch {
30619
31750
  await removePidFile();
30620
31751
  return { success: false, message: "Failed to stop daemon process (PID file removed)." };
30621
31752
  }
31753
+ for (let i2 = 0;i2 < 50; i2++) {
31754
+ if (!isProcessAlive2(data.pid))
31755
+ break;
31756
+ await new Promise((r2) => setTimeout(r2, 100));
31757
+ }
31758
+ if (isProcessAlive2(data.pid)) {
31759
+ try {
31760
+ process.kill(data.pid, "SIGKILL");
31761
+ } catch {}
31762
+ }
31763
+ await removePidFile();
31764
+ return { success: true, message: `Daemon process ${data.pid} stopped.` };
30622
31765
  }
30623
31766
 
30624
31767
  // src/cli/ui.ts
@@ -30658,6 +31801,7 @@ async function showStatus() {
30658
31801
  console.log(` URL: ${import_picocolors12.default.cyan(`http://127.0.0.1:${data.port}`)}`);
30659
31802
  console.log(` Started: ${import_picocolors12.default.dim(data.startTime)}`);
30660
31803
  } else {
31804
+ await removePidFile();
30661
31805
  console.log(import_picocolors12.default.yellow("⚠ Swixter UI is not running (stale PID file removed)."));
30662
31806
  }
30663
31807
  console.log();
@@ -30684,18 +31828,19 @@ async function startDaemon(portArg) {
30684
31828
  env: { ...process.env, SWIXTER_UI_DAEMON: "1" }
30685
31829
  });
30686
31830
  child.unref();
31831
+ await writePidFile(child.pid, port);
30687
31832
  const url2 = `http://127.0.0.1:${port}`;
30688
31833
  const started = await waitForServer(url2, 1e4);
30689
31834
  if (!started) {
30690
31835
  try {
30691
31836
  process.kill(child.pid, "SIGTERM");
30692
31837
  } catch {}
31838
+ await removePidFile();
30693
31839
  console.log();
30694
31840
  console.log(import_picocolors12.default.red("✗ Failed to start daemon (timed out waiting for server)."));
30695
31841
  console.log();
30696
31842
  process.exit(1);
30697
31843
  }
30698
- await writePidFile(child.pid, port);
30699
31844
  console.log();
30700
31845
  console.log(import_picocolors12.default.green("✓ Swixter UI daemon started"));
30701
31846
  console.log(` PID: ${import_picocolors12.default.cyan(String(child.pid))}`);
@@ -30731,6 +31876,16 @@ async function runForeground(portArg) {
30731
31876
  };
30732
31877
  process.on("SIGINT", shutdown);
30733
31878
  process.on("SIGTERM", shutdown);
31879
+ process.on("uncaughtException", async (err) => {
31880
+ console.error("Unexpected error:", err);
31881
+ await removePidFile();
31882
+ process.exit(1);
31883
+ });
31884
+ process.on("unhandledRejection", async (err) => {
31885
+ console.error("Unhandled rejection:", err);
31886
+ await removePidFile();
31887
+ process.exit(1);
31888
+ });
30734
31889
  process.stdin.resume();
30735
31890
  }
30736
31891
  async function waitForServer(url2, timeoutMs) {