@seaveyon/harness-switch 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7015,7 +7015,7 @@ var require_public_api = __commonJS((exports) => {
7015
7015
 
7016
7016
  // src/app.ts
7017
7017
  import { existsSync as existsSync3 } from "fs";
7018
- import { join as join8 } from "path";
7018
+ import { join as join9 } from "path";
7019
7019
 
7020
7020
  // ../../node_modules/hono/dist/compose.js
7021
7021
  var compose = (middleware, onError, onNotFound) => {
@@ -9210,7 +9210,8 @@ class EnvironmentService {
9210
9210
  claude: join2(this.homeDir, ".claude"),
9211
9211
  codex: process.env.CODEX_HOME || join2(this.homeDir, ".codex"),
9212
9212
  kimiCode: process.env.KIMI_CODE_HOME || join2(this.homeDir, ".kimi-code"),
9213
- piAgent: process.env.PI_CODING_AGENT_DIR || join2(this.homeDir, ".omp", "agent")
9213
+ piAgent: process.env.PI_CODING_AGENT_DIR || join2(this.homeDir, ".omp", "agent"),
9214
+ dsh: process.env.DSH_HOME || join2(this.homeDir, ".dsh")
9214
9215
  };
9215
9216
  ensureDataDir() {
9216
9217
  mkdirSync(this.dataDir, { recursive: true, mode: 448 });
@@ -10806,12 +10807,24 @@ var SETTINGS = "settings";
10806
10807
  var BASE_URL_VAR = "ANTHROPIC_BASE_URL";
10807
10808
  var MODEL_VAR = "ANTHROPIC_MODEL";
10808
10809
  var AUTH_VARS = ["ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY"];
10810
+ var MODEL_MAPPINGS = [
10811
+ ["haikuModel", "ANTHROPIC_DEFAULT_HAIKU_MODEL"],
10812
+ ["sonnetModel", "ANTHROPIC_DEFAULT_SONNET_MODEL"],
10813
+ ["opusModel", "ANTHROPIC_DEFAULT_OPUS_MODEL"],
10814
+ ["fableModel", "ANTHROPIC_DEFAULT_FABLE_MODEL"],
10815
+ ["subagentModel", "CLAUDE_CODE_SUBAGENT_MODEL"]
10816
+ ];
10809
10817
 
10810
10818
  class ClaudeAdapter {
10811
10819
  environment;
10812
10820
  id = "claude";
10813
10821
  mode = "replace";
10814
- envVarNames = [BASE_URL_VAR, ...AUTH_VARS, MODEL_VAR];
10822
+ envVarNames = [
10823
+ BASE_URL_VAR,
10824
+ ...AUTH_VARS,
10825
+ MODEL_VAR,
10826
+ ...MODEL_MAPPINGS.map(([, envVar]) => envVar)
10827
+ ];
10815
10828
  fields = [
10816
10829
  {
10817
10830
  key: "authVar",
@@ -10824,6 +10837,41 @@ class ClaudeAdapter {
10824
10837
  { value: "ANTHROPIC_API_KEY", label: "ANTHROPIC_API_KEY\uFF08\u5B98\u65B9\uFF09" }
10825
10838
  ]
10826
10839
  },
10840
+ {
10841
+ key: "haikuModel",
10842
+ label: "Haiku \u6A21\u578B\u6620\u5C04",
10843
+ kind: "text",
10844
+ placeholder: "\u4F8B\u5982\uFF1Aglm-5-air",
10845
+ help: "\u5199\u5165 ANTHROPIC_DEFAULT_HAIKU_MODEL\uFF1B\u7559\u7A7A\u4F7F\u7528\u56DE\u9000\u6A21\u578B\u6216 Claude Code \u9ED8\u8BA4\u503C\u3002"
10846
+ },
10847
+ {
10848
+ key: "sonnetModel",
10849
+ label: "Sonnet \u6A21\u578B\u6620\u5C04",
10850
+ kind: "text",
10851
+ placeholder: "\u4F8B\u5982\uFF1Aglm-5",
10852
+ help: "\u5199\u5165 ANTHROPIC_DEFAULT_SONNET_MODEL\u3002"
10853
+ },
10854
+ {
10855
+ key: "opusModel",
10856
+ label: "Opus \u6A21\u578B\u6620\u5C04",
10857
+ kind: "text",
10858
+ placeholder: "\u4F8B\u5982\uFF1Aglm-5",
10859
+ help: "\u5199\u5165 ANTHROPIC_DEFAULT_OPUS_MODEL\u3002"
10860
+ },
10861
+ {
10862
+ key: "fableModel",
10863
+ label: "Fable \u6A21\u578B\u6620\u5C04\uFF08\u53EF\u9009\uFF09",
10864
+ kind: "text",
10865
+ placeholder: "\u4F8B\u5982\uFF1Aglm-5",
10866
+ help: "\u5199\u5165 ANTHROPIC_DEFAULT_FABLE_MODEL\uFF1B\u7528\u4E8E\u652F\u6301 Fable \u6863\u4F4D\u7684\u65B0\u7248 Claude Code\u3002"
10867
+ },
10868
+ {
10869
+ key: "subagentModel",
10870
+ label: "\u5B50\u4EE3\u7406\u6A21\u578B\uFF08\u53EF\u9009\uFF09",
10871
+ kind: "text",
10872
+ placeholder: "\u4F8B\u5982\uFF1Aglm-5-air",
10873
+ help: "\u5199\u5165 CLAUDE_CODE_SUBAGENT_MODEL\uFF0C\u53EF\u8BA9\u5B50\u4EE3\u7406\u4F7F\u7528\u66F4\u5FEB\u6216\u6210\u672C\u66F4\u4F4E\u7684\u6A21\u578B\u3002"
10874
+ },
10827
10875
  {
10828
10876
  key: "extraEnv",
10829
10877
  label: "\u8FFD\u52A0\u73AF\u5883\u53D8\u91CF\uFF08\u53EF\u9009\uFF09",
@@ -10852,6 +10900,11 @@ API_TIMEOUT_MS=3000000`,
10852
10900
  if (profile.model) {
10853
10901
  vars[MODEL_VAR] = profile.model;
10854
10902
  }
10903
+ for (const [field, envVar] of MODEL_MAPPINGS) {
10904
+ if (profile.extras[field]) {
10905
+ vars[envVar] = profile.extras[field];
10906
+ }
10907
+ }
10855
10908
  return vars;
10856
10909
  }
10857
10910
  render(profile, current) {
@@ -10870,11 +10923,38 @@ API_TIMEOUT_MS=3000000`,
10870
10923
  } else {
10871
10924
  delete env[MODEL_VAR];
10872
10925
  }
10926
+ for (const [field, envVar] of MODEL_MAPPINGS) {
10927
+ const value = profile.extras[field]?.trim();
10928
+ if (value) {
10929
+ env[envVar] = value;
10930
+ } else {
10931
+ delete env[envVar];
10932
+ }
10933
+ }
10873
10934
  for (const [key, value] of parseEnvLines(profile.extras.extraEnv)) {
10874
10935
  env[key] = value;
10875
10936
  }
10876
10937
  return { [SETTINGS]: stringifyJson(settings) };
10877
10938
  }
10939
+ renderOfficial(profile, current) {
10940
+ const settings = parseJsonObject(current[SETTINGS]);
10941
+ const env = ensureObject(settings, "env");
10942
+ delete env[BASE_URL_VAR];
10943
+ delete env[MODEL_VAR];
10944
+ for (const authVar of AUTH_VARS) {
10945
+ delete env[authVar];
10946
+ }
10947
+ for (const [, envVar] of MODEL_MAPPINGS) {
10948
+ delete env[envVar];
10949
+ }
10950
+ for (const [key] of parseEnvLines(profile?.extras.extraEnv)) {
10951
+ delete env[key];
10952
+ }
10953
+ if (Object.keys(env).length === 0) {
10954
+ delete settings.env;
10955
+ }
10956
+ return { [SETTINGS]: stringifyJson(settings) };
10957
+ }
10878
10958
  backfill(profile, current) {
10879
10959
  const settings = safeParse(current[SETTINGS]);
10880
10960
  const env = settings.env;
@@ -10883,7 +10963,11 @@ API_TIMEOUT_MS=3000000`,
10883
10963
  return {
10884
10964
  baseUrl: readString(env, BASE_URL_VAR) || profile.baseUrl,
10885
10965
  model: readString(env, MODEL_VAR),
10886
- apiKey: apiKey || profile.apiKey
10966
+ apiKey: apiKey || profile.apiKey,
10967
+ extras: {
10968
+ ...profile.extras,
10969
+ ...Object.fromEntries(MODEL_MAPPINGS.map(([field, envVar]) => [field, readString(env, envVar)]))
10970
+ }
10887
10971
  };
10888
10972
  }
10889
10973
  authVar(profile) {
@@ -11038,6 +11122,31 @@ class CodexAdapter {
11038
11122
  }
11039
11123
  return rendered;
11040
11124
  }
11125
+ renderOfficial(profile, current) {
11126
+ const config = parseTomlObject(current[CONFIG]);
11127
+ const activeProviderId = readString(config, "model_provider");
11128
+ delete config.model_provider;
11129
+ delete config.model;
11130
+ delete config.model_reasoning_effort;
11131
+ if (isPlainObject(config.model_providers)) {
11132
+ if (profile) {
11133
+ delete config.model_providers[this.providerId(profile)];
11134
+ }
11135
+ if (activeProviderId) {
11136
+ delete config.model_providers[activeProviderId];
11137
+ }
11138
+ if (Object.keys(config.model_providers).length === 0) {
11139
+ delete config.model_providers;
11140
+ }
11141
+ }
11142
+ const rendered = { [CONFIG]: stringifyToml(config) };
11143
+ if (profile && this.authMode(profile) === "openai_auth") {
11144
+ const auth = parseJsonObject(current[AUTH]);
11145
+ delete auth[DEFAULT_ENV_KEY];
11146
+ rendered[AUTH] = stringifyJson(auth);
11147
+ }
11148
+ return rendered;
11149
+ }
11041
11150
  backfill(profile, current) {
11042
11151
  let config = {};
11043
11152
  try {
@@ -11075,10 +11184,218 @@ function safeJson(text) {
11075
11184
  }
11076
11185
  }
11077
11186
 
11078
- // src/services/adapters/kimi.ts
11187
+ // src/services/adapters/dsh.ts
11079
11188
  import { join as join6 } from "path";
11080
- var CONFIG2 = "config";
11189
+ var SETTINGS2 = "settings";
11190
+ var CREDENTIALS = "credentials";
11081
11191
  var DEFAULT_CONTEXT = 262144;
11192
+ var DEFAULT_MAX_TOKENS = 32768;
11193
+
11194
+ class DshAdapter {
11195
+ environment;
11196
+ id = "dsh";
11197
+ mode = "additive";
11198
+ envVarNames = [];
11199
+ envNote = "API key \u5B89\u5168\u5199\u5165 DSH \u7684 .credentials.yaml\uFF0C\u5E76\u7531 settings.yaml \u5F15\u7528\u3002";
11200
+ fields = [
11201
+ {
11202
+ key: "providerId",
11203
+ label: "Provider ID\uFF08\u53EF\u9009\uFF09",
11204
+ kind: "text",
11205
+ placeholder: "\u9ED8\u8BA4\u53D6\u914D\u7F6E\u540D\u79F0",
11206
+ help: "DSH \u7684\u6A21\u578B\u8DEF\u7531\u6807\u8BC6\uFF1B\u5FC5\u987B\u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\u3002"
11207
+ },
11208
+ {
11209
+ key: "api",
11210
+ label: "API \u534F\u8BAE",
11211
+ kind: "select",
11212
+ defaultValue: "openai-responses",
11213
+ options: [
11214
+ { value: "openai-responses", label: "openai-responses" },
11215
+ { value: "openai-completions", label: "openai-completions" },
11216
+ { value: "anthropic-messages", label: "anthropic-messages" }
11217
+ ]
11218
+ },
11219
+ {
11220
+ key: "contextWindow",
11221
+ label: "\u4E0A\u4E0B\u6587\u957F\u5EA6",
11222
+ kind: "text",
11223
+ defaultValue: String(DEFAULT_CONTEXT)
11224
+ },
11225
+ {
11226
+ key: "maxTokens",
11227
+ label: "\u6700\u5927\u8F93\u51FA tokens",
11228
+ kind: "text",
11229
+ defaultValue: String(DEFAULT_MAX_TOKENS)
11230
+ },
11231
+ {
11232
+ key: "reasoningEfforts",
11233
+ label: "\u652F\u6301\u7684\u601D\u8003\u7A0B\u5EA6",
11234
+ kind: "select",
11235
+ defaultValue: "",
11236
+ help: "DSH \u53EA\u4F1A\u663E\u793A\u8FD9\u91CC\u58F0\u660E\u4E14\u4E0A\u6E38\u6A21\u578B\u5B9E\u9645\u652F\u6301\u7684\u6863\u4F4D\u3002",
11237
+ options: [
11238
+ { value: "", label: "\u4E0D\u58F0\u660E\uFF08\u63D0\u4F9B\u65B9\u9ED8\u8BA4\uFF09" },
11239
+ { value: "low,medium,high,xhigh,max", label: "Low / Medium / High / XHigh / Max" },
11240
+ { value: "low,medium,high,xhigh", label: "Low / Medium / High / XHigh" },
11241
+ { value: "minimal,low,medium,high", label: "Minimal / Low / Medium / High" },
11242
+ { value: "false", label: "\u6A21\u578B\u4E0D\u652F\u6301\u601D\u8003\u7A0B\u5EA6" }
11243
+ ]
11244
+ }
11245
+ ];
11246
+ constructor(environment) {
11247
+ this.environment = environment;
11248
+ }
11249
+ targets() {
11250
+ return [
11251
+ {
11252
+ key: SETTINGS2,
11253
+ label: "settings.yaml",
11254
+ path: join6(this.environment.harnessHomes.dsh, "settings.yaml"),
11255
+ format: "yaml"
11256
+ },
11257
+ {
11258
+ key: CREDENTIALS,
11259
+ label: ".credentials.yaml",
11260
+ path: join6(this.environment.harnessHomes.dsh, ".credentials.yaml"),
11261
+ format: "yaml"
11262
+ }
11263
+ ];
11264
+ }
11265
+ envVars() {
11266
+ return {};
11267
+ }
11268
+ validate(profile) {
11269
+ if (!profile.model.trim()) {
11270
+ throw new HttpError(400, "DeepSeek Harness \u9700\u8981\u586B\u5199\u6A21\u578B\u540D\u79F0");
11271
+ }
11272
+ if (!profile.apiKey.trim()) {
11273
+ throw new HttpError(400, "DeepSeek Harness \u9700\u8981\u586B\u5199 API key");
11274
+ }
11275
+ }
11276
+ render(profile, current) {
11277
+ this.validate(profile);
11278
+ const providerId = this.providerId(profile);
11279
+ const credentialRef = this.credentialRef(providerId);
11280
+ const settings = parseYamlDocument(current[SETTINGS2]);
11281
+ const model = {
11282
+ id: profile.model,
11283
+ name: profile.model,
11284
+ contextWindow: this.numeric(profile.extras.contextWindow, DEFAULT_CONTEXT),
11285
+ maxTokens: this.numeric(profile.extras.maxTokens, DEFAULT_MAX_TOKENS)
11286
+ };
11287
+ const reasoningEfforts = this.reasoningEfforts(profile.extras.reasoningEfforts);
11288
+ if (reasoningEfforts !== undefined) {
11289
+ model.reasoningEfforts = reasoningEfforts;
11290
+ }
11291
+ settings.setIn(["llm-pi-ai", "providers", providerId], {
11292
+ displayName: profile.name,
11293
+ apiKeyEnv: credentialRef,
11294
+ api: profile.extras.api || "openai-responses",
11295
+ baseURL: profile.baseUrl,
11296
+ models: [model]
11297
+ });
11298
+ settings.setIn(["agent-default-model", "provider"], providerId);
11299
+ settings.setIn(["agent-default-model", "model"], profile.model);
11300
+ settings.deleteIn(["agent-default-model", "reasoningEffort"]);
11301
+ const credentials = parseYamlDocument(current[CREDENTIALS]);
11302
+ credentials.setIn([credentialRef], profile.apiKey);
11303
+ return {
11304
+ [SETTINGS2]: settings.toString(),
11305
+ [CREDENTIALS]: credentials.toString()
11306
+ };
11307
+ }
11308
+ revoke(profile, current) {
11309
+ const providerId = this.providerId(profile);
11310
+ const rendered = {};
11311
+ if (current[SETTINGS2] !== undefined) {
11312
+ try {
11313
+ const settings = parseYamlDocument(current[SETTINGS2]);
11314
+ settings.deleteIn(["llm-pi-ai", "providers", providerId]);
11315
+ if (settings.getIn(["agent-default-model", "provider"]) === providerId) {
11316
+ settings.deleteIn(["agent-default-model"]);
11317
+ }
11318
+ rendered[SETTINGS2] = settings.toString();
11319
+ } catch {}
11320
+ }
11321
+ if (current[CREDENTIALS] !== undefined) {
11322
+ try {
11323
+ const credentials = parseYamlDocument(current[CREDENTIALS]);
11324
+ credentials.deleteIn([this.credentialRef(providerId)]);
11325
+ rendered[CREDENTIALS] = credentials.toString();
11326
+ } catch {}
11327
+ }
11328
+ return rendered;
11329
+ }
11330
+ backfill(profile, current) {
11331
+ try {
11332
+ const providerId = this.providerId(profile);
11333
+ const settings = parseYamlDocument(current[SETTINGS2]);
11334
+ const credentials = parseYamlDocument(current[CREDENTIALS]);
11335
+ const route = toPlain(settings.getIn(["llm-pi-ai", "providers", providerId]));
11336
+ const models = Array.isArray(route?.models) ? route.models : [];
11337
+ const firstModel = toPlain(models[0]);
11338
+ const apiKey = credentials.getIn([this.credentialRef(providerId)]);
11339
+ return {
11340
+ baseUrl: typeof route?.baseURL === "string" ? route.baseURL : profile.baseUrl,
11341
+ apiKey: typeof apiKey === "string" && apiKey ? apiKey : profile.apiKey,
11342
+ model: typeof firstModel?.id === "string" ? firstModel.id : profile.model,
11343
+ extras: {
11344
+ ...profile.extras,
11345
+ api: typeof route?.api === "string" ? route.api : profile.extras.api || "",
11346
+ contextWindow: valueString(firstModel?.contextWindow, profile.extras.contextWindow),
11347
+ maxTokens: valueString(firstModel?.maxTokens, profile.extras.maxTokens),
11348
+ reasoningEfforts: reasoningEffortsString(firstModel?.reasoningEfforts, profile.extras.reasoningEfforts)
11349
+ }
11350
+ };
11351
+ } catch {
11352
+ return {};
11353
+ }
11354
+ }
11355
+ providerId(profile) {
11356
+ const id = slugify(profile.extras.providerId || profile.name, "provider");
11357
+ return /^[a-z]/.test(id) ? id : `provider-${id}`;
11358
+ }
11359
+ credentialRef(providerId) {
11360
+ return `${providerId.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_API_KEY`;
11361
+ }
11362
+ numeric(raw2, fallback) {
11363
+ const parsed = Number(raw2);
11364
+ return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : fallback;
11365
+ }
11366
+ reasoningEfforts(raw2) {
11367
+ if (!raw2) {
11368
+ return;
11369
+ }
11370
+ if (raw2 === "false") {
11371
+ return false;
11372
+ }
11373
+ const levels = raw2.split(",").map((entry) => entry.trim()).filter(Boolean);
11374
+ return levels.length > 0 ? Object.fromEntries(levels.map((level) => [level, level])) : undefined;
11375
+ }
11376
+ }
11377
+ function toPlain(value) {
11378
+ const plain = isYamlNode(value) ? value.toJSON() : value;
11379
+ return typeof plain === "object" && plain !== null && !Array.isArray(plain) ? plain : undefined;
11380
+ }
11381
+ function isYamlNode(value) {
11382
+ return typeof value === "object" && value !== null && "toJSON" in value;
11383
+ }
11384
+ function valueString(value, fallback) {
11385
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : fallback || "";
11386
+ }
11387
+ function reasoningEffortsString(value, fallback) {
11388
+ if (value === false) {
11389
+ return "false";
11390
+ }
11391
+ const plain = toPlain(value);
11392
+ return plain ? Object.keys(plain).join(",") : fallback || "";
11393
+ }
11394
+
11395
+ // src/services/adapters/kimi.ts
11396
+ import { join as join7 } from "path";
11397
+ var CONFIG2 = "config";
11398
+ var DEFAULT_CONTEXT2 = 262144;
11082
11399
 
11083
11400
  class KimiAdapter {
11084
11401
  environment;
@@ -11110,7 +11427,7 @@ class KimiAdapter {
11110
11427
  key: "maxContextSize",
11111
11428
  label: "\u4E0A\u4E0B\u6587\u957F\u5EA6",
11112
11429
  kind: "text",
11113
- defaultValue: String(DEFAULT_CONTEXT),
11430
+ defaultValue: String(DEFAULT_CONTEXT2),
11114
11431
  help: "Kimi Code \u8981\u6C42 models \u6761\u76EE\u5FC5\u987B\u58F0\u660E max_context_size\u3002"
11115
11432
  }
11116
11433
  ];
@@ -11122,7 +11439,7 @@ class KimiAdapter {
11122
11439
  {
11123
11440
  key: CONFIG2,
11124
11441
  label: "config.toml",
11125
- path: join6(this.environment.harnessHomes.kimiCode, "config.toml"),
11442
+ path: join7(this.environment.harnessHomes.kimiCode, "config.toml"),
11126
11443
  format: "toml"
11127
11444
  }
11128
11445
  ];
@@ -11203,16 +11520,16 @@ class KimiAdapter {
11203
11520
  }
11204
11521
  contextSize(profile) {
11205
11522
  const parsed = Number(profile.extras.maxContextSize);
11206
- return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : DEFAULT_CONTEXT;
11523
+ return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : DEFAULT_CONTEXT2;
11207
11524
  }
11208
11525
  }
11209
11526
 
11210
11527
  // src/services/adapters/pi.ts
11211
- import { join as join7 } from "path";
11528
+ import { join as join8 } from "path";
11212
11529
  var MODELS = "models";
11213
11530
  var CONFIG3 = "config";
11214
- var DEFAULT_CONTEXT2 = 200000;
11215
- var DEFAULT_MAX_TOKENS = 8192;
11531
+ var DEFAULT_CONTEXT3 = 200000;
11532
+ var DEFAULT_MAX_TOKENS2 = 8192;
11216
11533
 
11217
11534
  class PiAdapter {
11218
11535
  environment;
@@ -11253,13 +11570,13 @@ class PiAdapter {
11253
11570
  key: "contextWindow",
11254
11571
  label: "\u4E0A\u4E0B\u6587\u957F\u5EA6",
11255
11572
  kind: "text",
11256
- defaultValue: String(DEFAULT_CONTEXT2)
11573
+ defaultValue: String(DEFAULT_CONTEXT3)
11257
11574
  },
11258
11575
  {
11259
11576
  key: "maxTokens",
11260
11577
  label: "\u6700\u5927\u8F93\u51FA tokens",
11261
11578
  kind: "text",
11262
- defaultValue: String(DEFAULT_MAX_TOKENS)
11579
+ defaultValue: String(DEFAULT_MAX_TOKENS2)
11263
11580
  }
11264
11581
  ];
11265
11582
  constructor(environment) {
@@ -11270,13 +11587,13 @@ class PiAdapter {
11270
11587
  {
11271
11588
  key: MODELS,
11272
11589
  label: "models.yml",
11273
- path: join7(this.environment.harnessHomes.piAgent, "models.yml"),
11590
+ path: join8(this.environment.harnessHomes.piAgent, "models.yml"),
11274
11591
  format: "yaml"
11275
11592
  },
11276
11593
  {
11277
11594
  key: CONFIG3,
11278
11595
  label: "config.yml",
11279
- path: join7(this.environment.harnessHomes.piAgent, "config.yml"),
11596
+ path: join8(this.environment.harnessHomes.piAgent, "config.yml"),
11280
11597
  format: "yaml"
11281
11598
  }
11282
11599
  ];
@@ -11301,8 +11618,8 @@ class PiAdapter {
11301
11618
  {
11302
11619
  id: profile.model,
11303
11620
  name: profile.model,
11304
- contextWindow: this.numeric(profile.extras.contextWindow, DEFAULT_CONTEXT2),
11305
- maxTokens: this.numeric(profile.extras.maxTokens, DEFAULT_MAX_TOKENS)
11621
+ contextWindow: this.numeric(profile.extras.contextWindow, DEFAULT_CONTEXT3),
11622
+ maxTokens: this.numeric(profile.extras.maxTokens, DEFAULT_MAX_TOKENS2)
11306
11623
  }
11307
11624
  ]);
11308
11625
  const config = parseYamlDocument(current[CONFIG3]);
@@ -11357,7 +11674,7 @@ class PiAdapter {
11357
11674
  return [id, ...this.toStringArray(existing).filter((entry) => entry !== id)];
11358
11675
  }
11359
11676
  toStringArray(value) {
11360
- const plain = isYamlNode(value) ? value.toJSON() : value;
11677
+ const plain = isYamlNode2(value) ? value.toJSON() : value;
11361
11678
  return Array.isArray(plain) ? plain.filter((entry) => typeof entry === "string") : [];
11362
11679
  }
11363
11680
  numeric(raw2, fallback) {
@@ -11365,7 +11682,7 @@ class PiAdapter {
11365
11682
  return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : fallback;
11366
11683
  }
11367
11684
  }
11368
- function isYamlNode(value) {
11685
+ function isYamlNode2(value) {
11369
11686
  return typeof value === "object" && value !== null && "toJSON" in value;
11370
11687
  }
11371
11688
 
@@ -11383,7 +11700,8 @@ class AdapterRegistry {
11383
11700
  new ClaudeAdapter(environment),
11384
11701
  new CodexAdapter(environment),
11385
11702
  new KimiAdapter(environment),
11386
- new PiAdapter(environment)
11703
+ new PiAdapter(environment),
11704
+ new DshAdapter(environment)
11387
11705
  ];
11388
11706
  this.adapters = new Map(adapters.map((adapter) => [adapter.id, adapter]));
11389
11707
  }
@@ -11462,12 +11780,13 @@ __decoratorMetadata(_init, LiveWriteService);
11462
11780
  let _LiveWriteService = LiveWriteService;
11463
11781
 
11464
11782
  // ../../packages/shared/src/harnesses.ts
11465
- var HARNESS_IDS = ["claude", "codex", "kimi", "pi"];
11783
+ var HARNESS_IDS = ["claude", "codex", "kimi", "pi", "dsh"];
11466
11784
  var HARNESS_LABELS = {
11467
11785
  claude: "Claude Code",
11468
11786
  codex: "Codex",
11469
11787
  kimi: "Kimi Code",
11470
- pi: "oh-my-pi"
11788
+ pi: "oh-my-pi",
11789
+ dsh: "DeepSeek Harness"
11471
11790
  };
11472
11791
  function isHarnessId(value) {
11473
11792
  return HARNESS_IDS.includes(value);
@@ -11524,16 +11843,21 @@ class ProfileService {
11524
11843
  upsert(harness, input, isCreate) {
11525
11844
  this.harnesses.require(harness);
11526
11845
  const name = input.name.trim();
11846
+ const sourceName = isCreate ? name : input.sourceName?.trim() || name;
11527
11847
  this.assertName(name);
11848
+ this.assertName(sourceName);
11528
11849
  const store = this.read();
11529
11850
  store[harness] ||= {};
11530
- const prior = store[harness][name];
11851
+ const prior = store[harness][sourceName];
11531
11852
  if (isCreate && prior) {
11532
11853
  throw new HttpError(409, "profile already exists");
11533
11854
  }
11534
11855
  if (!isCreate && !prior) {
11535
11856
  throw new HttpError(404, "profile not found");
11536
11857
  }
11858
+ if (!isCreate && sourceName !== name && store[harness][name]) {
11859
+ throw new HttpError(409, "profile already exists");
11860
+ }
11537
11861
  const apiKey = input.apiKey || (prior ? this.crypto.decrypt(prior.api_key) : "");
11538
11862
  if (isCreate && !apiKey) {
11539
11863
  throw new HttpError(400, "apiKey is required");
@@ -11555,6 +11879,9 @@ class ProfileService {
11555
11879
  extras: next.extras ?? {}
11556
11880
  });
11557
11881
  store[harness][name] = next;
11882
+ if (sourceName !== name) {
11883
+ delete store[harness][sourceName];
11884
+ }
11558
11885
  this.files.writeJson(this.environment.files.profiles, store);
11559
11886
  return this.toPublic(harness, name, next);
11560
11887
  }
@@ -11595,6 +11922,9 @@ class ProfileService {
11595
11922
  if (values.apiKey) {
11596
11923
  stored.api_key = this.crypto.encrypt(values.apiKey);
11597
11924
  }
11925
+ if (values.extras !== undefined) {
11926
+ stored.extras = { ...stored.extras, ...values.extras };
11927
+ }
11598
11928
  this.files.writeJson(this.environment.files.profiles, store);
11599
11929
  }
11600
11930
  read() {
@@ -11661,7 +11991,8 @@ class ActivationService {
11661
11991
  return {
11662
11992
  name: stored.name,
11663
11993
  baseUrl: stored.base_url || "",
11664
- model: stored.model || ""
11994
+ model: stored.model || "",
11995
+ official: stored.official === true
11665
11996
  };
11666
11997
  }
11667
11998
  activate(harness, name) {
@@ -11678,7 +12009,8 @@ class ActivationService {
11678
12009
  base_url: profile.baseUrl,
11679
12010
  api_key: profile.apiKey,
11680
12011
  model: profile.model,
11681
- extras: profile.extras
12012
+ extras: profile.extras,
12013
+ official: false
11682
12014
  };
11683
12015
  this.files.writeJson(this.environment.files.active, active);
11684
12016
  try {
@@ -11689,6 +12021,45 @@ class ActivationService {
11689
12021
  }
11690
12022
  return { envFile: this.environment.files.env, warnings };
11691
12023
  }
12024
+ activateOfficial(harness) {
12025
+ const adapter = this.adapters.get(harness);
12026
+ if (!adapter.renderOfficial) {
12027
+ throw new HttpError(400, `${this.harnesses.label(harness)} \u4E0D\u652F\u6301\u5B98\u65B9\u8D26\u53F7\u767B\u5F55\u6A21\u5F0F`);
12028
+ }
12029
+ const warnings = [];
12030
+ const active = this.read();
12031
+ const previous = active[harness];
12032
+ const alreadyOfficial = previous?.official === true;
12033
+ if (!alreadyOfficial) {
12034
+ this.backfillPrevious(adapter, previous, "__official__", warnings);
12035
+ }
12036
+ const profile = previous && !alreadyOfficial ? {
12037
+ name: previous.name,
12038
+ baseUrl: previous.base_url,
12039
+ apiKey: previous.api_key,
12040
+ model: previous.model,
12041
+ extras: previous.extras ?? {}
12042
+ } : undefined;
12043
+ const targets = adapter.targets();
12044
+ const rendered = adapter.renderOfficial(profile, this.readCurrent(targets));
12045
+ this.liveWrite.apply(harness, "\u5B98\u65B9\u767B\u5F55", this.toWrites(targets, rendered));
12046
+ active[harness] = {
12047
+ name: "\u5B98\u65B9\u767B\u5F55",
12048
+ base_url: "",
12049
+ api_key: "",
12050
+ model: "",
12051
+ extras: {},
12052
+ official: true
12053
+ };
12054
+ this.files.writeJson(this.environment.files.active, active);
12055
+ try {
12056
+ this.writeEnv(active);
12057
+ } catch (error) {
12058
+ this.log.error("failed to rebuild env file", error);
12059
+ warnings.push("\u5DF2\u6062\u590D\u5B98\u65B9\u767B\u5F55\uFF0C\u4F46\u91CD\u5EFA env.sh \u5931\u8D25");
12060
+ }
12061
+ return { envFile: this.environment.files.env, warnings };
12062
+ }
11692
12063
  preview(harness, name) {
11693
12064
  const adapter = this.adapters.get(harness);
11694
12065
  const profile = this.profiles.decrypt(harness, name);
@@ -11708,11 +12079,19 @@ class ActivationService {
11708
12079
  };
11709
12080
  });
11710
12081
  }
11711
- reapplyIfActive(harness, name) {
11712
- if (this.read()[harness]?.name !== name) {
12082
+ reconcileProfileUpdate(harness, previousName, nextName) {
12083
+ const adapter = this.adapters.get(harness);
12084
+ if (previousName !== nextName && adapter.revoke) {
12085
+ const profile = this.profiles.decrypt(harness, nextName);
12086
+ const previousProfile = { ...profile, name: previousName };
12087
+ const targets = adapter.targets();
12088
+ const rendered = adapter.revoke(previousProfile, this.readCurrent(targets));
12089
+ this.liveWrite.apply(harness, previousName, this.toWrites(targets, rendered));
12090
+ }
12091
+ if (this.read()[harness]?.name !== previousName) {
11713
12092
  return;
11714
12093
  }
11715
- this.activate(harness, name);
12094
+ this.activate(harness, nextName);
11716
12095
  }
11717
12096
  prepareDelete(harness, name) {
11718
12097
  if (this.read()[harness]?.name === name) {
@@ -11732,7 +12111,7 @@ class ActivationService {
11732
12111
  }
11733
12112
  }
11734
12113
  backfillPrevious(adapter, previous, nextName, warnings) {
11735
- if (!adapter.backfill || !previous || previous.name === nextName) {
12114
+ if (!adapter.backfill || !previous || previous.official || previous.name === nextName) {
11736
12115
  return;
11737
12116
  }
11738
12117
  try {
@@ -11795,6 +12174,11 @@ class ActivationService {
11795
12174
  if (!entry) {
11796
12175
  continue;
11797
12176
  }
12177
+ if (entry.official) {
12178
+ lines.push("", `# ${this.harnesses.label(adapter.id)} / \u5B98\u65B9\u767B\u5F55`);
12179
+ lines.push("# \u4F7F\u7528\u5DE5\u5177\u81EA\u8EAB\u7684\u5B98\u65B9\u8D26\u53F7\u767B\u5F55\uFF0C\u4E0D\u6CE8\u5165\u73AF\u5883\u53D8\u91CF\u3002");
12180
+ continue;
12181
+ }
11798
12182
  const profile = {
11799
12183
  name: entry.name,
11800
12184
  baseUrl: entry.base_url,
@@ -11846,7 +12230,8 @@ function createHarnessRoutes(services) {
11846
12230
  fields: adapter.fields,
11847
12231
  targets: adapter.targets(),
11848
12232
  envVars: adapter.envVarNames,
11849
- envNote: adapter.envNote
12233
+ envNote: adapter.envNote,
12234
+ supportsOfficialAuth: adapter.renderOfficial !== undefined
11850
12235
  };
11851
12236
  }
11852
12237
  app.get("/", (c) => c.json({
@@ -11873,7 +12258,8 @@ function createHarnessRoutes(services) {
11873
12258
  const name = decodeURIComponent(c.req.param("name"));
11874
12259
  const body = await readBody(c.req.json.bind(c.req));
11875
12260
  const profile = profiles.upsert(harnessId, {
11876
- name,
12261
+ name: String(body.name ?? name),
12262
+ sourceName: name,
11877
12263
  baseUrl: body.baseUrl,
11878
12264
  apiKey: body.apiKey,
11879
12265
  model: body.model,
@@ -11881,7 +12267,7 @@ function createHarnessRoutes(services) {
11881
12267
  extras: body.extras,
11882
12268
  overrides: body.overrides
11883
12269
  }, false);
11884
- activation.reapplyIfActive(harnessId, name);
12270
+ activation.reconcileProfileUpdate(harnessId, name, profile.name);
11885
12271
  return c.json(profile);
11886
12272
  });
11887
12273
  app.delete("/:harnessId/profiles/:name", (c) => {
@@ -11902,6 +12288,11 @@ function createHarnessRoutes(services) {
11902
12288
  const result = activation.activate(harnessId, name);
11903
12289
  return c.json({ ok: true, envFile: result.envFile, warnings: result.warnings });
11904
12290
  });
12291
+ app.post("/:harnessId/official/activate", (c) => {
12292
+ const harnessId = harnesses.require(c.req.param("harnessId"));
12293
+ const result = activation.activateOfficial(harnessId);
12294
+ return c.json({ ok: true, envFile: result.envFile, warnings: result.warnings });
12295
+ });
11905
12296
  return app;
11906
12297
  }
11907
12298
  async function readBody(read) {
@@ -11934,11 +12325,11 @@ function createApp(services) {
11934
12325
  if (c.req.path.startsWith("/api") || c.req.path === "/healthz") {
11935
12326
  return next();
11936
12327
  }
11937
- const assetPath = join8(publicDir, c.req.path.replace(/^\//, ""));
12328
+ const assetPath = join9(publicDir, c.req.path.replace(/^\//, ""));
11938
12329
  if (c.req.path !== "/" && existsSync3(assetPath)) {
11939
12330
  return serveStatic2({ root: publicDir })(c, next);
11940
12331
  }
11941
- const index = join8(publicDir, "index.html");
12332
+ const index = join9(publicDir, "index.html");
11942
12333
  if (existsSync3(index)) {
11943
12334
  return c.html(await Bun.file(index).text());
11944
12335
  }