@seaveyon/harness-switch 0.28.0 → 0.30.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.
package/dist/harness-switch.js
CHANGED
|
@@ -7062,6 +7062,7 @@ var ERROR_CODES = {
|
|
|
7062
7062
|
adapterApiKeyRequired: "adapter.apiKeyRequired",
|
|
7063
7063
|
officialLoginUnsupported: "activation.officialLoginUnsupported",
|
|
7064
7064
|
officialLoginMissing: "activation.officialLoginMissing",
|
|
7065
|
+
officialApiKeyMissing: "activation.officialApiKeyMissing",
|
|
7065
7066
|
noActiveProfile: "activation.noActiveProfile",
|
|
7066
7067
|
officialProfileCannotAdopt: "activation.officialProfileCannotAdopt",
|
|
7067
7068
|
adoptUnsupported: "activation.adoptUnsupported",
|
|
@@ -7138,7 +7139,9 @@ var DOCTOR_CODES = {
|
|
|
7138
7139
|
probeOfficialLogin: "doctor.check.probeOfficialLogin",
|
|
7139
7140
|
probeMissingCredential: "doctor.check.probeMissingCredential",
|
|
7140
7141
|
probeOk: "doctor.check.probeOk",
|
|
7141
|
-
probeFailed: "doctor.check.probeFailed"
|
|
7142
|
+
probeFailed: "doctor.check.probeFailed",
|
|
7143
|
+
completionOk: "doctor.check.completionOk",
|
|
7144
|
+
completionFailed: "doctor.check.completionFailed"
|
|
7142
7145
|
};
|
|
7143
7146
|
var SCAN_NOTE_CODES = {
|
|
7144
7147
|
unsupported: "scan.note.unsupported",
|
|
@@ -7154,7 +7157,11 @@ var PROBE_CODES = {
|
|
|
7154
7157
|
networkError: "probe.networkError",
|
|
7155
7158
|
unauthorized: "probe.unauthorized",
|
|
7156
7159
|
httpError: "probe.httpError",
|
|
7157
|
-
invalidResponse: "probe.invalidResponse"
|
|
7160
|
+
invalidResponse: "probe.invalidResponse",
|
|
7161
|
+
missingModel: "probe.missingModel",
|
|
7162
|
+
completionUnsupported: "probe.completionUnsupported",
|
|
7163
|
+
completionHttpError: "probe.completionHttpError",
|
|
7164
|
+
completionInvalid: "probe.completionInvalid"
|
|
7158
7165
|
};
|
|
7159
7166
|
var USER_BLOCK_CODES = {
|
|
7160
7167
|
homeUnsearchable: "user.block.homeUnsearchable",
|
|
@@ -7347,7 +7354,7 @@ var en_default = {
|
|
|
7347
7354
|
label: "Provider type",
|
|
7348
7355
|
option: {
|
|
7349
7356
|
custom: "Custom provider",
|
|
7350
|
-
official: "DeepSeek official"
|
|
7357
|
+
official: "DeepSeek official API"
|
|
7351
7358
|
}
|
|
7352
7359
|
},
|
|
7353
7360
|
providerId: {
|
|
@@ -7394,6 +7401,7 @@ var en_default = {
|
|
|
7394
7401
|
providers: "Providers",
|
|
7395
7402
|
profileCount_one: "{{count}} custom profile",
|
|
7396
7403
|
profileCount_other: "{{count}} custom profiles",
|
|
7404
|
+
copy: "Copy {{name}}",
|
|
7397
7405
|
noProfiles: "No profiles yet",
|
|
7398
7406
|
manualOverride: "Manual override",
|
|
7399
7407
|
edit: "Edit {{name}}",
|
|
@@ -7402,12 +7410,14 @@ var en_default = {
|
|
|
7402
7410
|
deleteTitle: "Delete profile?",
|
|
7403
7411
|
deleteBody: "This deletes {{harness}} / {{profile}}. {{extra}}This cannot be undone.",
|
|
7404
7412
|
deleteAdditiveExtra: "Its provider entry in the configuration file is removed as well. ",
|
|
7413
|
+
deleteDshOfficialExtra: "Its native DeepSeek route and credential reference are removed as well. ",
|
|
7405
7414
|
official: "Official login",
|
|
7406
7415
|
officialActive: "In use",
|
|
7407
7416
|
officialSwitch: "Back to official",
|
|
7408
7417
|
officialHintClaude: "Use Claude Code's own Anthropic account login",
|
|
7409
7418
|
officialHintCodex: "Use Codex's own ChatGPT / OpenAI account login",
|
|
7410
7419
|
officialHintKimi: "Use Kimi Code's own Kimi account login (the OAuth credential written by /login)",
|
|
7420
|
+
officialHintDsh: "Detect and switch to DeepSeek Harness's existing official DeepSeek API key configuration",
|
|
7411
7421
|
application: "Application",
|
|
7412
7422
|
writeMode: "Write mode",
|
|
7413
7423
|
modeReplace: "Replace current configuration",
|
|
@@ -7416,6 +7426,7 @@ var en_default = {
|
|
|
7416
7426
|
profile: {
|
|
7417
7427
|
editTitle: "Edit {{harness}} / {{profile}}",
|
|
7418
7428
|
createTitle: "New {{harness}} profile",
|
|
7429
|
+
copyTitle: "Copy {{harness}} / {{profile}}",
|
|
7419
7430
|
intro: "Saving writes to {{targets}}.",
|
|
7420
7431
|
additiveNote: "This tool's config file keeps providers side by side, so switching only moves the current pointer — the other providers you wrote by hand are left alone.",
|
|
7421
7432
|
useSharedProvider: "Use a shared provider (vault)",
|
|
@@ -7439,6 +7450,7 @@ var en_default = {
|
|
|
7439
7450
|
apiKeyKeep: "Leave empty to keep the current key",
|
|
7440
7451
|
apiKeyRequiredPlaceholder: "Required",
|
|
7441
7452
|
apiKeySharedHint: "This profile references a shared provider; rotate the key in the vault instead.",
|
|
7453
|
+
dshOfficialApiKeyHint: "Enter a DeepSeek Platform API key. It is securely written to DSH's .credentials.yaml and referenced as DEEPSEEK_API_KEY from settings.yaml.",
|
|
7442
7454
|
fallbackModel: "Fallback model (ANTHROPIC_MODEL)",
|
|
7443
7455
|
model: "Model",
|
|
7444
7456
|
fallbackModelPlaceholder: "Optional; used when no tier matches, e.g. glm-5",
|
|
@@ -7470,6 +7482,7 @@ var en_default = {
|
|
|
7470
7482
|
nameRequired: "Enter a profile name",
|
|
7471
7483
|
nameSlash: "A profile name cannot contain / or \\",
|
|
7472
7484
|
nameTooLong: "A profile name is at most {{max}} characters",
|
|
7485
|
+
nameDuplicate: "A profile with this name already exists",
|
|
7473
7486
|
baseUrlRequired: "Enter an API base URL",
|
|
7474
7487
|
apiKeyRequired: "Enter an API key",
|
|
7475
7488
|
modelRequired: "Enter a model name",
|
|
@@ -7669,7 +7682,9 @@ var en_default = {
|
|
|
7669
7682
|
probeOfficialLogin: "{{harness}} is on its built-in account login; no custom endpoint to probe",
|
|
7670
7683
|
probeMissingCredential: "Profile {{profile}} has no base URL or API key; cannot probe",
|
|
7671
7684
|
probeOk: "Endpoint of profile {{profile}} is reachable",
|
|
7672
|
-
probeFailed: "Connectivity probe failed for profile {{profile}}"
|
|
7685
|
+
probeFailed: "Connectivity probe failed for profile {{profile}}",
|
|
7686
|
+
completionOk: "Model {{model}} completed a request ({{latencyMs}}ms)",
|
|
7687
|
+
completionFailed: "Model {{model}} failed to complete: the endpoint is reachable, but this model cannot answer"
|
|
7673
7688
|
}
|
|
7674
7689
|
},
|
|
7675
7690
|
notice: {
|
|
@@ -7757,6 +7772,7 @@ var en_default = {
|
|
|
7757
7772
|
activation: {
|
|
7758
7773
|
officialLoginUnsupported: "{{harness}} does not support official account login",
|
|
7759
7774
|
officialLoginMissing: "No official login entry was found for {{harness}}; complete its official login in a terminal once first",
|
|
7775
|
+
officialApiKeyMissing: "No official DeepSeek API key configuration was found for {{harness}}",
|
|
7760
7776
|
noActiveProfile: "This tool has no active profile, so there is nothing to render",
|
|
7761
7777
|
officialProfileCannotAdopt: "The official login is active, so there is no profile to adopt into",
|
|
7762
7778
|
adoptUnsupported: "This tool cannot adopt a live configuration",
|
|
@@ -7838,7 +7854,11 @@ var en_default = {
|
|
|
7838
7854
|
networkError: "Could not reach the endpoint (DNS, refused connection or TLS failure)",
|
|
7839
7855
|
unauthorized: "Endpoint reachable but rejected the credential (HTTP {{status}}); check the API key",
|
|
7840
7856
|
httpError: "Endpoint returned HTTP {{status}}",
|
|
7841
|
-
invalidResponse: "The response is not a recognized model-catalog format"
|
|
7857
|
+
invalidResponse: "The response is not a recognized model-catalog format",
|
|
7858
|
+
missingModel: "No model to complete against: fill in a model name, or fetch the catalog first",
|
|
7859
|
+
completionUnsupported: "The endpoint accepts none of the known completion protocols",
|
|
7860
|
+
completionHttpError: "Model {{model}} returned HTTP {{status}} for a completion: the catalog lists it, but it cannot answer",
|
|
7861
|
+
completionInvalid: "The completion response is not a recognized format, so the model cannot be confirmed to have answered"
|
|
7842
7862
|
}
|
|
7843
7863
|
},
|
|
7844
7864
|
warning: {
|
|
@@ -8076,9 +8096,14 @@ var en_default = {
|
|
|
8076
8096
|
},
|
|
8077
8097
|
probe: {
|
|
8078
8098
|
action: "Test connection",
|
|
8099
|
+
completionAction: "Test completion",
|
|
8100
|
+
completionHint: "Sends one real minimal request to prove the model actually answers (costs a token or two).",
|
|
8079
8101
|
probing: "Testing…",
|
|
8080
8102
|
ok: "Reachable · {{latencyMs}}ms · {{count}} models",
|
|
8081
8103
|
okNoCatalog: "Reachable · {{latencyMs}}ms · no model catalog returned",
|
|
8104
|
+
completionOk: "Model {{model}} answers · {{latencyMs}}ms",
|
|
8105
|
+
completionCached: "Model {{model}} answers · cached {{at}}",
|
|
8106
|
+
completionFailedCached: "cached {{at}}",
|
|
8082
8107
|
catalogHint: "Fetched {{count}} models; click the model field to pick one from the list.",
|
|
8083
8108
|
missingBaseUrl: "Add an endpoint URL before testing."
|
|
8084
8109
|
}
|
|
@@ -8255,7 +8280,7 @@ var zh_CN_default = {
|
|
|
8255
8280
|
label: "提供方类型",
|
|
8256
8281
|
option: {
|
|
8257
8282
|
custom: "自定义提供方",
|
|
8258
|
-
official: "DeepSeek 官方"
|
|
8283
|
+
official: "DeepSeek 官方 API"
|
|
8259
8284
|
}
|
|
8260
8285
|
},
|
|
8261
8286
|
providerId: {
|
|
@@ -8302,6 +8327,7 @@ var zh_CN_default = {
|
|
|
8302
8327
|
providers: "提供方",
|
|
8303
8328
|
profileCount_one: "{{count}} 个自定义配置",
|
|
8304
8329
|
profileCount_other: "{{count}} 个自定义配置",
|
|
8330
|
+
copy: "复制 {{name}}",
|
|
8305
8331
|
noProfiles: "还没有配置档案",
|
|
8306
8332
|
manualOverride: "手动接管",
|
|
8307
8333
|
edit: "编辑 {{name}}",
|
|
@@ -8310,12 +8336,14 @@ var zh_CN_default = {
|
|
|
8310
8336
|
deleteTitle: "删除配置?",
|
|
8311
8337
|
deleteBody: "将删除 {{harness}} / {{profile}}。{{extra}}此操作不可撤销。",
|
|
8312
8338
|
deleteAdditiveExtra: "它在配置文件里的 provider 条目也会被一并摘掉。",
|
|
8339
|
+
deleteDshOfficialExtra: "它的 DeepSeek 原生路由和凭据引用也会被一并移除。",
|
|
8313
8340
|
official: "官方登录",
|
|
8314
8341
|
officialActive: "已使用",
|
|
8315
8342
|
officialSwitch: "切回官方",
|
|
8316
8343
|
officialHintClaude: "使用 Claude Code 自身的 Anthropic 账号登录",
|
|
8317
8344
|
officialHintCodex: "使用 Codex 自身的 ChatGPT / OpenAI 账号登录",
|
|
8318
8345
|
officialHintKimi: "使用 Kimi Code 自身的 Kimi 账号登录(/login 写入的 OAuth 凭据)",
|
|
8346
|
+
officialHintDsh: "检测并切换到 DeepSeek Harness 已有的 DeepSeek 官方 API Key 配置。",
|
|
8319
8347
|
application: "应用",
|
|
8320
8348
|
writeMode: "写入模式",
|
|
8321
8349
|
modeReplace: "替换当前配置",
|
|
@@ -8324,6 +8352,7 @@ var zh_CN_default = {
|
|
|
8324
8352
|
profile: {
|
|
8325
8353
|
editTitle: "编辑 {{harness}} / {{profile}}",
|
|
8326
8354
|
createTitle: "新增 {{harness}} 配置",
|
|
8355
|
+
copyTitle: "复制 {{harness}} / {{profile}}",
|
|
8327
8356
|
intro: "保存后会写入 {{targets}}。",
|
|
8328
8357
|
additiveNote: "该工具的配置文件按 provider 共存,切换只会移动当前指针,不会删除你手写的其他 provider。",
|
|
8329
8358
|
useSharedProvider: "使用共享 Provider(凭据库)",
|
|
@@ -8347,6 +8376,7 @@ var zh_CN_default = {
|
|
|
8347
8376
|
apiKeyKeep: "留空表示保持不变",
|
|
8348
8377
|
apiKeyRequiredPlaceholder: "必填",
|
|
8349
8378
|
apiKeySharedHint: "已引用共享 Provider,密钥在「凭据库」中统一轮换。",
|
|
8379
|
+
dshOfficialApiKeyHint: "填写 DeepSeek 开放平台 API Key;它会安全写入 DSH 的 .credentials.yaml,并以 DEEPSEEK_API_KEY 被 settings.yaml 引用。",
|
|
8350
8380
|
fallbackModel: "回退模型(ANTHROPIC_MODEL)",
|
|
8351
8381
|
model: "模型",
|
|
8352
8382
|
fallbackModelPlaceholder: "可选;各档未匹配时使用,例如 glm-5",
|
|
@@ -8378,6 +8408,7 @@ var zh_CN_default = {
|
|
|
8378
8408
|
nameRequired: "请输入配置名称",
|
|
8379
8409
|
nameSlash: "配置名称不能包含 / 或 \\",
|
|
8380
8410
|
nameTooLong: "配置名称最多 {{max}} 个字符",
|
|
8411
|
+
nameDuplicate: "同名配置已经存在",
|
|
8381
8412
|
baseUrlRequired: "请输入 API Base URL",
|
|
8382
8413
|
apiKeyRequired: "请输入 API Key",
|
|
8383
8414
|
modelRequired: "请输入模型名称",
|
|
@@ -8577,7 +8608,9 @@ var zh_CN_default = {
|
|
|
8577
8608
|
probeOfficialLogin: "{{harness}} 处于官方账号登录状态,无自定义端点可探测",
|
|
8578
8609
|
probeMissingCredential: "配置 {{profile}} 缺少 Base URL 或 API Key,无法探测",
|
|
8579
8610
|
probeOk: "配置 {{profile}} 的端点可达",
|
|
8580
|
-
probeFailed: "配置 {{profile}} 的连通性探测失败"
|
|
8611
|
+
probeFailed: "配置 {{profile}} 的连通性探测失败",
|
|
8612
|
+
completionOk: "模型 {{model}} 补全成功({{latencyMs}}ms)",
|
|
8613
|
+
completionFailed: "模型 {{model}} 补全失败:端点可达,但这个模型无法作答"
|
|
8581
8614
|
}
|
|
8582
8615
|
},
|
|
8583
8616
|
notice: {
|
|
@@ -8665,6 +8698,7 @@ var zh_CN_default = {
|
|
|
8665
8698
|
activation: {
|
|
8666
8699
|
officialLoginUnsupported: "{{harness}} 不支持官方账号登录模式",
|
|
8667
8700
|
officialLoginMissing: "未检测到 {{harness}} 的官方登录条目,请先在终端完成一次官方登录",
|
|
8701
|
+
officialApiKeyMissing: "未检测到 {{harness}} 的 DeepSeek 官方 API Key 配置",
|
|
8668
8702
|
noActiveProfile: "该工具未激活任何配置,无可渲染的内容",
|
|
8669
8703
|
officialProfileCannotAdopt: "当前处于官方登录状态,没有可回填的配置档案",
|
|
8670
8704
|
adoptUnsupported: "该工具不支持采纳现场配置",
|
|
@@ -8746,7 +8780,11 @@ var zh_CN_default = {
|
|
|
8746
8780
|
networkError: "无法连接到端点(DNS、拒绝连接或 TLS 失败)",
|
|
8747
8781
|
unauthorized: "端点可达但拒绝了凭据(HTTP {{status}}),请检查 API Key",
|
|
8748
8782
|
httpError: "端点返回 HTTP {{status}}",
|
|
8749
|
-
invalidResponse: "响应不是已知的模型目录格式"
|
|
8783
|
+
invalidResponse: "响应不是已知的模型目录格式",
|
|
8784
|
+
missingModel: "没有可用于补全测试的模型:请填写模型名称,或先获取模型目录",
|
|
8785
|
+
completionUnsupported: "端点不接受任何已知的补全协议",
|
|
8786
|
+
completionHttpError: "模型 {{model}} 的补全请求返回 HTTP {{status}}:目录里有这个模型,但它无法作答",
|
|
8787
|
+
completionInvalid: "补全响应不是已知的格式,无法确认模型真的作答"
|
|
8750
8788
|
}
|
|
8751
8789
|
},
|
|
8752
8790
|
warning: {
|
|
@@ -8984,9 +9022,14 @@ var zh_CN_default = {
|
|
|
8984
9022
|
},
|
|
8985
9023
|
probe: {
|
|
8986
9024
|
action: "测试连接",
|
|
9025
|
+
completionAction: "测试补全",
|
|
9026
|
+
completionHint: "真实发送一条最小请求,验证模型确实能作答(会消耗一两个 token)。",
|
|
8987
9027
|
probing: "正在测试…",
|
|
8988
9028
|
ok: "连接正常 · {{latencyMs}}ms · {{count}} 个模型",
|
|
8989
9029
|
okNoCatalog: "连接正常 · {{latencyMs}}ms · 端点未提供模型目录",
|
|
9030
|
+
completionOk: "模型 {{model}} 可作答 · {{latencyMs}}ms",
|
|
9031
|
+
completionCached: "模型 {{model}} 可作答 · 缓存于 {{at}}",
|
|
9032
|
+
completionFailedCached: "缓存于 {{at}}",
|
|
8990
9033
|
catalogHint: "已获取 {{count}} 个模型,点击“模型”输入框可从列表选择。",
|
|
8991
9034
|
missingBaseUrl: "请先填写至少一个 endpoint URL 再测试。"
|
|
8992
9035
|
}
|
|
@@ -23287,11 +23330,17 @@ var harnessIdSchema = exports_external.enum(HARNESS_IDS);
|
|
|
23287
23330
|
var extrasSchema = exports_external.record(mapKey, optionalText(MAX_EXTRA_VALUE));
|
|
23288
23331
|
var overridesSchema = exports_external.record(mapKey, optionalText(MAX_OVERRIDE));
|
|
23289
23332
|
var conflictPolicySchema = exports_external.enum(["skip", "overwrite"]);
|
|
23333
|
+
var completionProtocolSchema = exports_external.enum([
|
|
23334
|
+
"openai-chat",
|
|
23335
|
+
"openai-responses",
|
|
23336
|
+
"anthropic-messages"
|
|
23337
|
+
]);
|
|
23290
23338
|
var loginRequestSchema = exports_external.object({
|
|
23291
23339
|
password: exports_external.string().trim().min(1, "password 不能为空").max(MAX_KEY)
|
|
23292
23340
|
});
|
|
23293
23341
|
var createProfileRequestSchema = exports_external.object({
|
|
23294
23342
|
name: entityName,
|
|
23343
|
+
copySourceName: entityName.optional(),
|
|
23295
23344
|
baseUrl: optionalText(MAX_URL).optional(),
|
|
23296
23345
|
apiKey: optionalText(MAX_KEY).optional(),
|
|
23297
23346
|
model: optionalText(MAX_NAME).optional(),
|
|
@@ -23366,10 +23415,17 @@ var scanImportRequestSchema = exports_external.object({
|
|
|
23366
23415
|
var probeRequestSchema = exports_external.object({
|
|
23367
23416
|
baseUrl: exports_external.string().trim().min(1, "baseUrl 不能为空").max(MAX_URL),
|
|
23368
23417
|
apiKey: optionalText(MAX_KEY).optional(),
|
|
23369
|
-
providerId: optionalText(MAX_NAME).optional()
|
|
23418
|
+
providerId: optionalText(MAX_NAME).optional(),
|
|
23419
|
+
completion: exports_external.boolean().optional(),
|
|
23420
|
+
model: optionalText(MAX_NAME).optional(),
|
|
23421
|
+
protocol: completionProtocolSchema.optional()
|
|
23370
23422
|
});
|
|
23371
23423
|
var probeStoredRequestSchema = exports_external.object({
|
|
23372
|
-
endpoint: optionalText(MAX_NAME).optional()
|
|
23424
|
+
endpoint: optionalText(MAX_NAME).optional(),
|
|
23425
|
+
completion: exports_external.boolean().optional(),
|
|
23426
|
+
model: optionalText(MAX_NAME).optional(),
|
|
23427
|
+
protocol: completionProtocolSchema.optional(),
|
|
23428
|
+
refresh: exports_external.boolean().optional()
|
|
23373
23429
|
});
|
|
23374
23430
|
var gitHubDeviceCodeRequestSchema = exports_external.object({
|
|
23375
23431
|
clientId: optionalText(100).optional()
|
|
@@ -25423,7 +25479,8 @@ class EnvironmentService {
|
|
|
25423
25479
|
env: join2(dataDir, "env.sh"),
|
|
25424
25480
|
sessions: join2(dataDir, "sessions.json"),
|
|
25425
25481
|
vault: join2(dataDir, "vault.json"),
|
|
25426
|
-
github: join2(dataDir, "github.json")
|
|
25482
|
+
github: join2(dataDir, "github.json"),
|
|
25483
|
+
probeCache: join2(dataDir, "probe-cache.json")
|
|
25427
25484
|
};
|
|
25428
25485
|
}
|
|
25429
25486
|
get backupsDir() {
|
|
@@ -27388,6 +27445,14 @@ class ClaudeAdapter {
|
|
|
27388
27445
|
MODEL_VAR,
|
|
27389
27446
|
...MODEL_MAPPINGS.flatMap(({ envVar, nameEnvVar }) => nameEnvVar ? [envVar, nameEnvVar] : [envVar])
|
|
27390
27447
|
];
|
|
27448
|
+
official(_current) {
|
|
27449
|
+
return {
|
|
27450
|
+
kind: "account-login",
|
|
27451
|
+
available: true,
|
|
27452
|
+
titleCode: "harness.official",
|
|
27453
|
+
hintCode: "harness.officialHintClaude"
|
|
27454
|
+
};
|
|
27455
|
+
}
|
|
27391
27456
|
fields = [
|
|
27392
27457
|
{
|
|
27393
27458
|
key: "authVar",
|
|
@@ -27557,6 +27622,9 @@ API_TIMEOUT_MS=3000000`,
|
|
|
27557
27622
|
}
|
|
27558
27623
|
return vars;
|
|
27559
27624
|
}
|
|
27625
|
+
completionProtocol() {
|
|
27626
|
+
return "anthropic-messages";
|
|
27627
|
+
}
|
|
27560
27628
|
render(profile, current) {
|
|
27561
27629
|
const settings = parseJsonObject(current[SETTINGS]);
|
|
27562
27630
|
const env = ensureObject(settings, "env");
|
|
@@ -27697,6 +27765,14 @@ class CodexAdapter {
|
|
|
27697
27765
|
envVarNames = [DEFAULT_ENV_KEY];
|
|
27698
27766
|
envNote = "仅「环境变量」认证模式需要 env.sh,其余模式的凭据自包含在 config.toml 里。";
|
|
27699
27767
|
envNoteCode = "harness.field.codex.envNote";
|
|
27768
|
+
official(_current) {
|
|
27769
|
+
return {
|
|
27770
|
+
kind: "account-login",
|
|
27771
|
+
available: true,
|
|
27772
|
+
titleCode: "harness.official",
|
|
27773
|
+
hintCode: "harness.officialHintCodex"
|
|
27774
|
+
};
|
|
27775
|
+
}
|
|
27700
27776
|
fields = [
|
|
27701
27777
|
{
|
|
27702
27778
|
key: "authMode",
|
|
@@ -27787,6 +27863,9 @@ class CodexAdapter {
|
|
|
27787
27863
|
}
|
|
27788
27864
|
return { [this.envKeyName(profile)]: profile.apiKey };
|
|
27789
27865
|
}
|
|
27866
|
+
completionProtocol() {
|
|
27867
|
+
return "openai-responses";
|
|
27868
|
+
}
|
|
27790
27869
|
render(profile, current) {
|
|
27791
27870
|
const providerId2 = this.providerId(profile);
|
|
27792
27871
|
const config2 = parseTomlObject(current[CONFIG]);
|
|
@@ -27892,8 +27971,22 @@ class CodexAdapter {
|
|
|
27892
27971
|
|
|
27893
27972
|
// src/services/adapters/dsh.ts
|
|
27894
27973
|
import { join as join5 } from "node:path";
|
|
27974
|
+
|
|
27975
|
+
// src/services/adapters/protocol.ts
|
|
27976
|
+
var API_FIELD_PROTOCOLS = {
|
|
27977
|
+
"openai-completions": "openai-chat",
|
|
27978
|
+
"openai-responses": "openai-responses",
|
|
27979
|
+
"anthropic-messages": "anthropic-messages"
|
|
27980
|
+
};
|
|
27981
|
+
function apiFieldProtocol(api2, fallback) {
|
|
27982
|
+
const value = api2?.trim();
|
|
27983
|
+
return value ? API_FIELD_PROTOCOLS[value] : fallback;
|
|
27984
|
+
}
|
|
27985
|
+
|
|
27986
|
+
// src/services/adapters/dsh.ts
|
|
27895
27987
|
var SETTINGS2 = "settings";
|
|
27896
27988
|
var CREDENTIALS = "credentials";
|
|
27989
|
+
var DEFAULT_API = "openai-responses";
|
|
27897
27990
|
var DEFAULT_CONTEXT = 262144;
|
|
27898
27991
|
var DEFAULT_MAX_TOKENS = 32768;
|
|
27899
27992
|
|
|
@@ -27905,6 +27998,7 @@ class DshAdapter {
|
|
|
27905
27998
|
envVarNames = [];
|
|
27906
27999
|
envNote = "API key 安全写入 DSH 的 .credentials.yaml,并由 settings.yaml 引用。";
|
|
27907
28000
|
envNoteCode = "harness.field.dsh.envNote";
|
|
28001
|
+
officialNeedsCurrent = true;
|
|
27908
28002
|
fields = [
|
|
27909
28003
|
{
|
|
27910
28004
|
key: "providerType",
|
|
@@ -27951,7 +28045,7 @@ class DshAdapter {
|
|
|
27951
28045
|
label: "API 协议",
|
|
27952
28046
|
labelCode: "harness.field.dsh.api.label",
|
|
27953
28047
|
kind: "select",
|
|
27954
|
-
defaultValue:
|
|
28048
|
+
defaultValue: DEFAULT_API,
|
|
27955
28049
|
options: [
|
|
27956
28050
|
{ value: "openai-responses", label: "openai-responses" },
|
|
27957
28051
|
{ value: "openai-completions", label: "openai-completions" },
|
|
@@ -28019,6 +28113,9 @@ class DshAdapter {
|
|
|
28019
28113
|
envVars() {
|
|
28020
28114
|
return {};
|
|
28021
28115
|
}
|
|
28116
|
+
completionProtocol(profile) {
|
|
28117
|
+
return this.isOfficial(profile) ? "openai-chat" : apiFieldProtocol(profile.extras.api, "openai-responses");
|
|
28118
|
+
}
|
|
28022
28119
|
validate(profile) {
|
|
28023
28120
|
if (!profile.model.trim()) {
|
|
28024
28121
|
throw new HttpError(400, "DeepSeek Harness 需要填写模型名称", {
|
|
@@ -28049,7 +28146,7 @@ class DshAdapter {
|
|
|
28049
28146
|
settings.setIn(["llm-pi-ai", "providers", providerId2], {
|
|
28050
28147
|
displayName: profile.name,
|
|
28051
28148
|
apiKeyEnv: credentialRef,
|
|
28052
|
-
api: profile.extras.api ||
|
|
28149
|
+
api: profile.extras.api || DEFAULT_API,
|
|
28053
28150
|
baseURL: profile.baseUrl,
|
|
28054
28151
|
models
|
|
28055
28152
|
});
|
|
@@ -28078,6 +28175,40 @@ class DshAdapter {
|
|
|
28078
28175
|
rendered[SETTINGS2] = settings.toString();
|
|
28079
28176
|
return rendered;
|
|
28080
28177
|
}
|
|
28178
|
+
renderOfficial(_profile, current) {
|
|
28179
|
+
const official = this.readOfficialRoute(current);
|
|
28180
|
+
if (!official) {
|
|
28181
|
+
throw new HttpError(400, "未检测到 DeepSeek 官方 API Key 配置", {
|
|
28182
|
+
code: ERROR_CODES.officialApiKeyMissing,
|
|
28183
|
+
params: { harness: "DeepSeek Harness" }
|
|
28184
|
+
});
|
|
28185
|
+
}
|
|
28186
|
+
official.settings.setIn(["agent-default-model", "provider"], "deepseek-official");
|
|
28187
|
+
return { [SETTINGS2]: official.settings.toString() };
|
|
28188
|
+
}
|
|
28189
|
+
official(current) {
|
|
28190
|
+
const official = this.readOfficialRoute(current);
|
|
28191
|
+
if (!official)
|
|
28192
|
+
return;
|
|
28193
|
+
return {
|
|
28194
|
+
kind: "native-api",
|
|
28195
|
+
available: true,
|
|
28196
|
+
titleCode: "harness.deepseekOfficial",
|
|
28197
|
+
hintCode: "harness.officialHintDsh",
|
|
28198
|
+
matchesProfile: (profile) => profile.extras.providerType === "official"
|
|
28199
|
+
};
|
|
28200
|
+
}
|
|
28201
|
+
readOfficialRoute(current) {
|
|
28202
|
+
const settings = tryParseYamlDocument(current[SETTINGS2]);
|
|
28203
|
+
const credentials = tryParseYamlDocument(current[CREDENTIALS]);
|
|
28204
|
+
const route = settings ? toPlain(settings.getIn(["llm-deepseek"])) : undefined;
|
|
28205
|
+
const credentialRef = typeof route?.apiKeyEnv === "string" && route.apiKeyEnv ? route.apiKeyEnv : "DEEPSEEK_API_KEY";
|
|
28206
|
+
const apiKey = credentials?.getIn(["refs", credentialRef]) ?? credentials?.getIn([credentialRef]);
|
|
28207
|
+
if (!settings || route === undefined || typeof apiKey !== "string" || !apiKey.trim()) {
|
|
28208
|
+
return;
|
|
28209
|
+
}
|
|
28210
|
+
return { settings, route, credentialRef, apiKey };
|
|
28211
|
+
}
|
|
28081
28212
|
revoke(profile, current) {
|
|
28082
28213
|
const official = this.isOfficial(profile);
|
|
28083
28214
|
const providerId2 = official ? "deepseek-official" : this.providerId(profile);
|
|
@@ -28226,6 +28357,14 @@ class KimiAdapter {
|
|
|
28226
28357
|
envVarNames = [];
|
|
28227
28358
|
envNote = "Kimi Code 不从 shell 读取凭据,env.sh 对它无效。";
|
|
28228
28359
|
envNoteCode = "harness.field.kimi.envNote";
|
|
28360
|
+
official(_current) {
|
|
28361
|
+
return {
|
|
28362
|
+
kind: "account-login",
|
|
28363
|
+
available: true,
|
|
28364
|
+
titleCode: "harness.official",
|
|
28365
|
+
hintCode: "harness.officialHintKimi"
|
|
28366
|
+
};
|
|
28367
|
+
}
|
|
28229
28368
|
fields = [
|
|
28230
28369
|
{
|
|
28231
28370
|
key: "providerType",
|
|
@@ -28280,6 +28419,19 @@ class KimiAdapter {
|
|
|
28280
28419
|
envVars() {
|
|
28281
28420
|
return {};
|
|
28282
28421
|
}
|
|
28422
|
+
completionProtocol(profile) {
|
|
28423
|
+
switch (profile.extras.providerType || "kimi") {
|
|
28424
|
+
case "anthropic":
|
|
28425
|
+
return "anthropic-messages";
|
|
28426
|
+
case "openai_responses":
|
|
28427
|
+
return "openai-responses";
|
|
28428
|
+
case "kimi":
|
|
28429
|
+
case "openai_legacy":
|
|
28430
|
+
return "openai-chat";
|
|
28431
|
+
default:
|
|
28432
|
+
return;
|
|
28433
|
+
}
|
|
28434
|
+
}
|
|
28283
28435
|
validate(profile) {
|
|
28284
28436
|
if (!profile.model.trim()) {
|
|
28285
28437
|
throw new HttpError(400, "Kimi Code 需要填写模型名称,否则无法生成 models 条目", {
|
|
@@ -28403,6 +28555,7 @@ function officialModel(config2) {
|
|
|
28403
28555
|
import { join as join7 } from "node:path";
|
|
28404
28556
|
var MODELS = "models";
|
|
28405
28557
|
var SETTINGS3 = "settings";
|
|
28558
|
+
var DEFAULT_API2 = "openai-completions";
|
|
28406
28559
|
var DEFAULT_CONTEXT3 = 200000;
|
|
28407
28560
|
var DEFAULT_MAX_TOKENS2 = 8192;
|
|
28408
28561
|
|
|
@@ -28430,7 +28583,7 @@ class PiAdapter {
|
|
|
28430
28583
|
label: "协议",
|
|
28431
28584
|
labelCode: "harness.field.pi.api.label",
|
|
28432
28585
|
kind: "select",
|
|
28433
|
-
defaultValue:
|
|
28586
|
+
defaultValue: DEFAULT_API2,
|
|
28434
28587
|
options: [
|
|
28435
28588
|
{ value: "openai-completions", label: "openai-completions" },
|
|
28436
28589
|
{ value: "openai-responses", label: "openai-responses" },
|
|
@@ -28500,6 +28653,9 @@ class PiAdapter {
|
|
|
28500
28653
|
envVars() {
|
|
28501
28654
|
return {};
|
|
28502
28655
|
}
|
|
28656
|
+
completionProtocol(profile) {
|
|
28657
|
+
return apiFieldProtocol(profile.extras.api, "openai-chat");
|
|
28658
|
+
}
|
|
28503
28659
|
validate(profile) {
|
|
28504
28660
|
if (!profile.model.trim()) {
|
|
28505
28661
|
throw new HttpError(400, "Pi 需要填写模型名称,否则无法生成 models 条目", {
|
|
@@ -28530,7 +28686,7 @@ class PiAdapter {
|
|
|
28530
28686
|
}
|
|
28531
28687
|
provider.baseUrl = profile.baseUrl;
|
|
28532
28688
|
provider.apiKey = profile.apiKey;
|
|
28533
|
-
provider.api = profile.extras.api ||
|
|
28689
|
+
provider.api = profile.extras.api || DEFAULT_API2;
|
|
28534
28690
|
provider.authHeader = profile.extras.authHeader !== "false";
|
|
28535
28691
|
provider.models = [model];
|
|
28536
28692
|
const settings = parseJsonObject(current[SETTINGS3]);
|
|
@@ -29720,11 +29876,15 @@ class ProfileService {
|
|
|
29720
29876
|
this.harnesses.require(harness);
|
|
29721
29877
|
const name = input.name.trim();
|
|
29722
29878
|
const sourceName = isCreate ? name : input.sourceName?.trim() || name;
|
|
29879
|
+
const copySourceName = isCreate ? input.copySourceName?.trim() : undefined;
|
|
29723
29880
|
this.assertName(name);
|
|
29724
29881
|
this.assertName(sourceName);
|
|
29882
|
+
if (copySourceName)
|
|
29883
|
+
this.assertName(copySourceName);
|
|
29725
29884
|
const store = this.read();
|
|
29726
29885
|
store[harness] ||= {};
|
|
29727
29886
|
const prior = store[harness][sourceName];
|
|
29887
|
+
const copySource = copySourceName ? store[harness][copySourceName] : undefined;
|
|
29728
29888
|
if (isCreate && prior) {
|
|
29729
29889
|
throw new HttpError(409, "profile already exists", {
|
|
29730
29890
|
code: ERROR_CODES.profileAlreadyExists
|
|
@@ -29733,6 +29893,9 @@ class ProfileService {
|
|
|
29733
29893
|
if (!isCreate && !prior) {
|
|
29734
29894
|
throw new HttpError(404, "profile not found", { code: ERROR_CODES.profileNotFound });
|
|
29735
29895
|
}
|
|
29896
|
+
if (isCreate && copySourceName && !copySource) {
|
|
29897
|
+
throw new HttpError(404, "profile not found", { code: ERROR_CODES.profileNotFound });
|
|
29898
|
+
}
|
|
29736
29899
|
if (!isCreate && sourceName !== name && store[harness][name]) {
|
|
29737
29900
|
throw new HttpError(409, "profile already exists", {
|
|
29738
29901
|
code: ERROR_CODES.profileAlreadyExists
|
|
@@ -29743,8 +29906,9 @@ class ProfileService {
|
|
|
29743
29906
|
const providerEndpoint = input.providerEndpoint?.trim() || undefined;
|
|
29744
29907
|
const hasInlineKey = input.apiKey !== undefined && input.apiKey.trim() !== "";
|
|
29745
29908
|
const inlineKey = (input.apiKey ?? "").trim();
|
|
29746
|
-
|
|
29747
|
-
let
|
|
29909
|
+
const inherited = prior ?? copySource;
|
|
29910
|
+
let nextProviderId = inherited?.provider_id;
|
|
29911
|
+
let nextProviderEndpoint = inherited?.provider_endpoint;
|
|
29748
29912
|
let apiKey = "";
|
|
29749
29913
|
if (hasProvider && providerId2) {
|
|
29750
29914
|
const entry = this.vault.get(providerId2);
|
|
@@ -29765,24 +29929,24 @@ class ProfileService {
|
|
|
29765
29929
|
} else if (hasProvider && !providerId2) {
|
|
29766
29930
|
nextProviderId = undefined;
|
|
29767
29931
|
nextProviderEndpoint = undefined;
|
|
29768
|
-
apiKey = hasInlineKey ? inlineKey :
|
|
29932
|
+
apiKey = hasInlineKey ? inlineKey : inherited ? this.resolveKey(inherited) : "";
|
|
29769
29933
|
} else if (hasInlineKey) {
|
|
29770
29934
|
nextProviderId = undefined;
|
|
29771
29935
|
nextProviderEndpoint = undefined;
|
|
29772
29936
|
apiKey = inlineKey;
|
|
29773
|
-
} else if (
|
|
29774
|
-
apiKey =
|
|
29937
|
+
} else if (inherited) {
|
|
29938
|
+
apiKey = this.resolveKey(inherited);
|
|
29775
29939
|
}
|
|
29776
29940
|
if (isCreate && !apiKey) {
|
|
29777
29941
|
throw new HttpError(400, "apiKey is required", { code: ERROR_CODES.profileApiKeyRequired });
|
|
29778
29942
|
}
|
|
29779
|
-
const baseUrl = this.resolveBaseUrl((input.baseUrl ??
|
|
29943
|
+
const baseUrl = this.resolveBaseUrl((input.baseUrl ?? inherited?.base_url ?? "").trim(), providerId2 || nextProviderId, providerEndpoint || nextProviderEndpoint);
|
|
29780
29944
|
const next = {
|
|
29781
29945
|
base_url: baseUrl,
|
|
29782
29946
|
api_key: this.crypto.encrypt(apiKey),
|
|
29783
|
-
model: (input.model ??
|
|
29784
|
-
notes: input.notes ??
|
|
29785
|
-
extras: input.extras ??
|
|
29947
|
+
model: (input.model ?? inherited?.model ?? "").trim(),
|
|
29948
|
+
notes: input.notes ?? inherited?.notes ?? "",
|
|
29949
|
+
extras: input.extras ?? inherited?.extras ?? {},
|
|
29786
29950
|
overrides: input.overrides ?? prior?.overrides ?? {},
|
|
29787
29951
|
provider_id: nextProviderId,
|
|
29788
29952
|
provider_endpoint: nextProviderEndpoint,
|
|
@@ -30537,8 +30701,16 @@ function deepEqual(left, right) {
|
|
|
30537
30701
|
// src/services/probe.ts
|
|
30538
30702
|
var IProbeService = createDecorator("probeService");
|
|
30539
30703
|
var TIMEOUT_MS = 1e4;
|
|
30704
|
+
var COMPLETION_TIMEOUT_MS = 30000;
|
|
30540
30705
|
var MAX_BODY_BYTES = 4 * 1024 * 1024;
|
|
30541
30706
|
var MAX_MODELS = 1000;
|
|
30707
|
+
var COMPLETION_PROMPT = "hi";
|
|
30708
|
+
var COMPLETION_MAX_TOKENS = 1;
|
|
30709
|
+
var COMPLETION_PROTOCOLS = [
|
|
30710
|
+
"openai-chat",
|
|
30711
|
+
"openai-responses",
|
|
30712
|
+
"anthropic-messages"
|
|
30713
|
+
];
|
|
30542
30714
|
var _dec = [
|
|
30543
30715
|
inject()
|
|
30544
30716
|
];
|
|
@@ -30562,11 +30734,24 @@ class ProbeService {
|
|
|
30562
30734
|
if (base.protocol !== "http:" && base.protocol !== "https:") {
|
|
30563
30735
|
return failure(PROBE_CODES.badUrl, `Base URL 必须是 http/https:${base.protocol}`);
|
|
30564
30736
|
}
|
|
30565
|
-
const
|
|
30566
|
-
|
|
30737
|
+
const catalog = await this.readCatalog(base, input.apiKey);
|
|
30738
|
+
if (!input.completion) {
|
|
30739
|
+
return catalog;
|
|
30740
|
+
}
|
|
30741
|
+
const model = input.model?.trim() || catalog.models?.[0] || "";
|
|
30742
|
+
if (!model) {
|
|
30743
|
+
return {
|
|
30744
|
+
...catalog,
|
|
30745
|
+
completion: completionFailure(PROBE_CODES.missingModel, "没有可用于补全测试的模型:请填写模型名称,或先获取模型目录")
|
|
30746
|
+
};
|
|
30747
|
+
}
|
|
30748
|
+
return { ...catalog, completion: await this.complete(base, input, model) };
|
|
30749
|
+
}
|
|
30750
|
+
async readCatalog(base, apiKey) {
|
|
30751
|
+
const candidates = versioned(base) ? [joinUrl(base, "models")] : [joinUrl(base, "v1/models"), joinUrl(base, "models")];
|
|
30567
30752
|
let lastStatus;
|
|
30568
30753
|
for (let index = 0;index < candidates.length; index++) {
|
|
30569
|
-
const result = await this.request(candidates[index],
|
|
30754
|
+
const result = await this.request(candidates[index], apiKey);
|
|
30570
30755
|
if (result.status !== 404 || index === candidates.length - 1) {
|
|
30571
30756
|
return result;
|
|
30572
30757
|
}
|
|
@@ -30582,12 +30767,7 @@ class ProbeService {
|
|
|
30582
30767
|
let response;
|
|
30583
30768
|
try {
|
|
30584
30769
|
response = await fetch(url2, {
|
|
30585
|
-
headers: {
|
|
30586
|
-
Accept: "application/json",
|
|
30587
|
-
Authorization: `Bearer ${apiKey}`,
|
|
30588
|
-
"x-api-key": apiKey,
|
|
30589
|
-
"anthropic-version": "2023-06-01"
|
|
30590
|
-
},
|
|
30770
|
+
headers: authHeaders(apiKey, { Accept: "application/json" }),
|
|
30591
30771
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
30592
30772
|
redirect: "follow"
|
|
30593
30773
|
});
|
|
@@ -30625,11 +30805,104 @@ class ProbeService {
|
|
|
30625
30805
|
}
|
|
30626
30806
|
return { ok: true, ...shared, models };
|
|
30627
30807
|
}
|
|
30808
|
+
async complete(base, input, model) {
|
|
30809
|
+
const protocols = ordered(input.protocol);
|
|
30810
|
+
let last;
|
|
30811
|
+
for (let index = 0;index < protocols.length; index++) {
|
|
30812
|
+
const protocol = protocols[index];
|
|
30813
|
+
const attempt = await this.sendCompletion(base, input.apiKey, model, protocol);
|
|
30814
|
+
if (attempt.status !== 404 || index === protocols.length - 1) {
|
|
30815
|
+
return attempt;
|
|
30816
|
+
}
|
|
30817
|
+
last = attempt;
|
|
30818
|
+
}
|
|
30819
|
+
return last ?? completionFailure(PROBE_CODES.completionUnsupported, "端点不接受任何已知的补全协议");
|
|
30820
|
+
}
|
|
30821
|
+
async sendCompletion(base, apiKey, model, protocol) {
|
|
30822
|
+
const url2 = joinUrl(base, completionPath(base, protocol));
|
|
30823
|
+
const started = performance.now();
|
|
30824
|
+
let response;
|
|
30825
|
+
try {
|
|
30826
|
+
response = await fetch(url2, {
|
|
30827
|
+
method: "POST",
|
|
30828
|
+
headers: authHeaders(apiKey, {
|
|
30829
|
+
Accept: "application/json",
|
|
30830
|
+
"Content-Type": "application/json"
|
|
30831
|
+
}),
|
|
30832
|
+
body: JSON.stringify(completionBody(protocol, model)),
|
|
30833
|
+
signal: AbortSignal.timeout(COMPLETION_TIMEOUT_MS),
|
|
30834
|
+
redirect: "follow"
|
|
30835
|
+
});
|
|
30836
|
+
} catch (error51) {
|
|
30837
|
+
const latencyMs2 = Math.round(performance.now() - started);
|
|
30838
|
+
const shared2 = { model, protocol, latencyMs: latencyMs2, requestUrl: url2.toString() };
|
|
30839
|
+
if (isTimeout(error51)) {
|
|
30840
|
+
return completionFailure(PROBE_CODES.timeout, `补全请求超时(${COMPLETION_TIMEOUT_MS / 1000} 秒)`, shared2);
|
|
30841
|
+
}
|
|
30842
|
+
return completionFailure(PROBE_CODES.networkError, reason(error51), shared2);
|
|
30843
|
+
}
|
|
30844
|
+
const latencyMs = Math.round(performance.now() - started);
|
|
30845
|
+
const shared = {
|
|
30846
|
+
model,
|
|
30847
|
+
protocol,
|
|
30848
|
+
status: response.status,
|
|
30849
|
+
latencyMs,
|
|
30850
|
+
requestUrl: url2.toString()
|
|
30851
|
+
};
|
|
30852
|
+
if (response.status === 401 || response.status === 403) {
|
|
30853
|
+
return completionFailure(PROBE_CODES.unauthorized, `端点可达但拒绝了凭据(HTTP ${response.status}),请检查 API Key`, { ...shared, params: { status: response.status } });
|
|
30854
|
+
}
|
|
30855
|
+
if (!response.ok) {
|
|
30856
|
+
return completionFailure(PROBE_CODES.completionHttpError, `模型 ${model} 的补全请求返回 HTTP ${response.status}`, { ...shared, params: { status: response.status, model } });
|
|
30857
|
+
}
|
|
30858
|
+
const text = await readBody(response);
|
|
30859
|
+
if (text === null) {
|
|
30860
|
+
return completionFailure(PROBE_CODES.completionInvalid, "补全响应体过大", shared);
|
|
30861
|
+
}
|
|
30862
|
+
const produced = extractCompletionText(text);
|
|
30863
|
+
if (produced === null) {
|
|
30864
|
+
return completionFailure(PROBE_CODES.completionInvalid, "补全响应不是已知的格式,无法确认模型真的作答", shared);
|
|
30865
|
+
}
|
|
30866
|
+
return { ok: true, ...shared, produced: produced.length > 0 };
|
|
30867
|
+
}
|
|
30628
30868
|
}
|
|
30629
30869
|
ProbeService = __decorateElement(_init, 0, "ProbeService", _dec, ProbeService);
|
|
30630
30870
|
__runInitializers(_init, 1, ProbeService);
|
|
30631
30871
|
__decoratorMetadata(_init, ProbeService);
|
|
30632
30872
|
let _ProbeService = ProbeService;
|
|
30873
|
+
function authHeaders(apiKey, extra) {
|
|
30874
|
+
return {
|
|
30875
|
+
...extra,
|
|
30876
|
+
Authorization: `Bearer ${apiKey}`,
|
|
30877
|
+
"x-api-key": apiKey,
|
|
30878
|
+
"anthropic-version": "2023-06-01"
|
|
30879
|
+
};
|
|
30880
|
+
}
|
|
30881
|
+
function ordered(preferred) {
|
|
30882
|
+
if (!preferred) {
|
|
30883
|
+
return [...COMPLETION_PROTOCOLS];
|
|
30884
|
+
}
|
|
30885
|
+
return [preferred, ...COMPLETION_PROTOCOLS.filter((item) => item !== preferred)];
|
|
30886
|
+
}
|
|
30887
|
+
function completionPath(base, protocol) {
|
|
30888
|
+
const suffix = protocol === "openai-chat" ? "chat/completions" : protocol === "openai-responses" ? "responses" : "messages";
|
|
30889
|
+
return versioned(base) ? suffix : `v1/${suffix}`;
|
|
30890
|
+
}
|
|
30891
|
+
function completionBody(protocol, model) {
|
|
30892
|
+
if (protocol === "openai-responses") {
|
|
30893
|
+
return { model, input: COMPLETION_PROMPT, max_output_tokens: 16, stream: false };
|
|
30894
|
+
}
|
|
30895
|
+
return {
|
|
30896
|
+
model,
|
|
30897
|
+
messages: [{ role: "user", content: COMPLETION_PROMPT }],
|
|
30898
|
+
max_tokens: COMPLETION_MAX_TOKENS,
|
|
30899
|
+
stream: false
|
|
30900
|
+
};
|
|
30901
|
+
}
|
|
30902
|
+
function versioned(base) {
|
|
30903
|
+
const path = base.pathname.replace(/\/+$/, "");
|
|
30904
|
+
return /\/v\d+$/.test(path);
|
|
30905
|
+
}
|
|
30633
30906
|
async function readBody(response) {
|
|
30634
30907
|
const declaredLength = response.headers.get("content-length");
|
|
30635
30908
|
if (declaredLength && Number(declaredLength) > MAX_BODY_BYTES) {
|
|
@@ -30665,6 +30938,9 @@ function joinUrl(base, suffix) {
|
|
|
30665
30938
|
function failure(code, message, extra = {}) {
|
|
30666
30939
|
return { ok: false, code, message, ...extra };
|
|
30667
30940
|
}
|
|
30941
|
+
function completionFailure(code, message, extra = {}) {
|
|
30942
|
+
return { ok: false, code, message, ...extra };
|
|
30943
|
+
}
|
|
30668
30944
|
function isTimeout(error51) {
|
|
30669
30945
|
const name = error51?.name;
|
|
30670
30946
|
return name === "TimeoutError" || name === "AbortError";
|
|
@@ -30698,6 +30974,53 @@ function extractModels(body) {
|
|
|
30698
30974
|
}
|
|
30699
30975
|
return models;
|
|
30700
30976
|
}
|
|
30977
|
+
function extractCompletionText(body) {
|
|
30978
|
+
let parsed;
|
|
30979
|
+
try {
|
|
30980
|
+
parsed = JSON.parse(body);
|
|
30981
|
+
} catch {
|
|
30982
|
+
return null;
|
|
30983
|
+
}
|
|
30984
|
+
if (!isRecord3(parsed)) {
|
|
30985
|
+
return null;
|
|
30986
|
+
}
|
|
30987
|
+
if (isRecord3(parsed.error)) {
|
|
30988
|
+
return null;
|
|
30989
|
+
}
|
|
30990
|
+
if (Array.isArray(parsed.choices)) {
|
|
30991
|
+
return parsed.choices.map((choice) => {
|
|
30992
|
+
if (!isRecord3(choice))
|
|
30993
|
+
return "";
|
|
30994
|
+
const message = isRecord3(choice.message) ? choice.message : undefined;
|
|
30995
|
+
return contentText(message?.content) || (typeof choice.text === "string" ? choice.text : "") || contentText(isRecord3(choice.delta) ? choice.delta.content : undefined);
|
|
30996
|
+
}).join("").trim();
|
|
30997
|
+
}
|
|
30998
|
+
if (Array.isArray(parsed.content)) {
|
|
30999
|
+
return contentText(parsed.content).trim();
|
|
31000
|
+
}
|
|
31001
|
+
if (Array.isArray(parsed.output)) {
|
|
31002
|
+
return parsed.output.map((entry) => isRecord3(entry) ? contentText(entry.content) : "").join("").trim();
|
|
31003
|
+
}
|
|
31004
|
+
if (typeof parsed.output_text === "string") {
|
|
31005
|
+
return parsed.output_text.trim();
|
|
31006
|
+
}
|
|
31007
|
+
return null;
|
|
31008
|
+
}
|
|
31009
|
+
function contentText(content) {
|
|
31010
|
+
if (typeof content === "string") {
|
|
31011
|
+
return content;
|
|
31012
|
+
}
|
|
31013
|
+
if (!Array.isArray(content)) {
|
|
31014
|
+
return "";
|
|
31015
|
+
}
|
|
31016
|
+
return content.map((block) => {
|
|
31017
|
+
if (typeof block === "string")
|
|
31018
|
+
return block;
|
|
31019
|
+
if (!isRecord3(block))
|
|
31020
|
+
return "";
|
|
31021
|
+
return firstString(block, ["text", "output_text", "content"]);
|
|
31022
|
+
}).join("");
|
|
31023
|
+
}
|
|
30701
31024
|
function isRecord3(value) {
|
|
30702
31025
|
return typeof value === "object" && value !== null;
|
|
30703
31026
|
}
|
|
@@ -30711,6 +31034,103 @@ function firstString(record2, keys) {
|
|
|
30711
31034
|
return "";
|
|
30712
31035
|
}
|
|
30713
31036
|
|
|
31037
|
+
// src/services/probe-cache.ts
|
|
31038
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
31039
|
+
var IProbeCacheService = createDecorator("probeCacheService");
|
|
31040
|
+
var OK_TTL_MS = 6 * 60 * 60 * 1000;
|
|
31041
|
+
var FAILURE_TTL_MS = 5 * 60 * 1000;
|
|
31042
|
+
var _dec = [
|
|
31043
|
+
inject(IEnvironmentService, IFileService)
|
|
31044
|
+
];
|
|
31045
|
+
var _init = __decoratorStart(undefined);
|
|
31046
|
+
|
|
31047
|
+
class ProbeCacheService {
|
|
31048
|
+
environment;
|
|
31049
|
+
files;
|
|
31050
|
+
constructor(environment, files) {
|
|
31051
|
+
this.environment = environment;
|
|
31052
|
+
this.files = files;
|
|
31053
|
+
}
|
|
31054
|
+
get(harness, profile, key) {
|
|
31055
|
+
const entry = this.read()[harness]?.[profile];
|
|
31056
|
+
if (!entry || entry.fingerprint !== fingerprint(key)) {
|
|
31057
|
+
return;
|
|
31058
|
+
}
|
|
31059
|
+
const age = Date.now() - Date.parse(entry.at);
|
|
31060
|
+
if (!Number.isFinite(age) || age < 0) {
|
|
31061
|
+
return;
|
|
31062
|
+
}
|
|
31063
|
+
if (age > (entry.completion.ok ? OK_TTL_MS : FAILURE_TTL_MS)) {
|
|
31064
|
+
return;
|
|
31065
|
+
}
|
|
31066
|
+
return { ...entry.completion, cachedAt: entry.at };
|
|
31067
|
+
}
|
|
31068
|
+
set(harness, profile, key, value) {
|
|
31069
|
+
const store = this.read();
|
|
31070
|
+
store[harness] ||= {};
|
|
31071
|
+
const { cachedAt: _replayed, ...completion } = value;
|
|
31072
|
+
store[harness][profile] = {
|
|
31073
|
+
fingerprint: fingerprint(key),
|
|
31074
|
+
at: new Date().toISOString(),
|
|
31075
|
+
completion
|
|
31076
|
+
};
|
|
31077
|
+
this.write(store);
|
|
31078
|
+
}
|
|
31079
|
+
forget(harness, profile) {
|
|
31080
|
+
const store = this.read();
|
|
31081
|
+
if (!store[harness]?.[profile]) {
|
|
31082
|
+
return;
|
|
31083
|
+
}
|
|
31084
|
+
delete store[harness][profile];
|
|
31085
|
+
this.write(store);
|
|
31086
|
+
}
|
|
31087
|
+
read() {
|
|
31088
|
+
return this.files.readJson(this.environment.files.probeCache, {});
|
|
31089
|
+
}
|
|
31090
|
+
write(store) {
|
|
31091
|
+
try {
|
|
31092
|
+
this.files.writeJson(this.environment.files.probeCache, store);
|
|
31093
|
+
} catch {}
|
|
31094
|
+
}
|
|
31095
|
+
}
|
|
31096
|
+
ProbeCacheService = __decorateElement(_init, 0, "ProbeCacheService", _dec, ProbeCacheService);
|
|
31097
|
+
__runInitializers(_init, 1, ProbeCacheService);
|
|
31098
|
+
__decoratorMetadata(_init, ProbeCacheService);
|
|
31099
|
+
let _ProbeCacheService = ProbeCacheService;
|
|
31100
|
+
function fingerprint(key) {
|
|
31101
|
+
return createHash2("sha256").update(JSON.stringify([
|
|
31102
|
+
key.baseUrl,
|
|
31103
|
+
key.model,
|
|
31104
|
+
key.protocol ?? "",
|
|
31105
|
+
createHash2("sha256").update(key.apiKey).digest("hex")
|
|
31106
|
+
])).digest("hex");
|
|
31107
|
+
}
|
|
31108
|
+
|
|
31109
|
+
// src/services/probe-profile.ts
|
|
31110
|
+
async function probeSavedProfile(deps, harness, profile, options = {}) {
|
|
31111
|
+
const protocol = options.protocol ?? deps.adapter.completionProtocol?.(profile);
|
|
31112
|
+
const model = (options.model ?? profile.model).trim();
|
|
31113
|
+
const input = {
|
|
31114
|
+
baseUrl: profile.baseUrl,
|
|
31115
|
+
apiKey: profile.apiKey,
|
|
31116
|
+
...model ? { model } : {},
|
|
31117
|
+
...protocol ? { protocol } : {}
|
|
31118
|
+
};
|
|
31119
|
+
if (!options.completion) {
|
|
31120
|
+
return deps.probe.probe(input);
|
|
31121
|
+
}
|
|
31122
|
+
const key = model ? { baseUrl: profile.baseUrl, model, protocol, apiKey: profile.apiKey } : undefined;
|
|
31123
|
+
const cached4 = key && !options.refresh ? deps.cache.get(harness, profile.name, key) : undefined;
|
|
31124
|
+
if (cached4) {
|
|
31125
|
+
return { ...await deps.probe.probe(input), completion: cached4 };
|
|
31126
|
+
}
|
|
31127
|
+
const result = await deps.probe.probe({ ...input, completion: true });
|
|
31128
|
+
if (key && result.completion) {
|
|
31129
|
+
deps.cache.set(harness, profile.name, key, result.completion);
|
|
31130
|
+
}
|
|
31131
|
+
return result;
|
|
31132
|
+
}
|
|
31133
|
+
|
|
30714
31134
|
// src/services/doctor.ts
|
|
30715
31135
|
var IDoctorService = createDecorator("doctorService");
|
|
30716
31136
|
var BIN_NAMES = {
|
|
@@ -30720,7 +31140,7 @@ var BIN_NAMES = {
|
|
|
30720
31140
|
pi: "pi"
|
|
30721
31141
|
};
|
|
30722
31142
|
var _dec = [
|
|
30723
|
-
inject(IEnvironmentService, IFileService, IHarnessRegistry, IAdapterRegistry, IActivationService, IDriftService, IProfileService, IProbeService)
|
|
31143
|
+
inject(IEnvironmentService, IFileService, IHarnessRegistry, IAdapterRegistry, IActivationService, IDriftService, IProfileService, IProbeService, IProbeCacheService)
|
|
30724
31144
|
];
|
|
30725
31145
|
var _init = __decoratorStart(undefined);
|
|
30726
31146
|
|
|
@@ -30733,7 +31153,8 @@ class DoctorService {
|
|
|
30733
31153
|
drift;
|
|
30734
31154
|
profiles;
|
|
30735
31155
|
probe;
|
|
30736
|
-
|
|
31156
|
+
probeCache;
|
|
31157
|
+
constructor(environment, files, harnesses, adapters, activation, drift, profiles, probe, probeCache) {
|
|
30737
31158
|
this.environment = environment;
|
|
30738
31159
|
this.files = files;
|
|
30739
31160
|
this.harnesses = harnesses;
|
|
@@ -30742,17 +31163,19 @@ class DoctorService {
|
|
|
30742
31163
|
this.drift = drift;
|
|
30743
31164
|
this.profiles = profiles;
|
|
30744
31165
|
this.probe = probe;
|
|
31166
|
+
this.probeCache = probeCache;
|
|
30745
31167
|
}
|
|
30746
31168
|
async run(options = {}) {
|
|
30747
31169
|
const harnessIds = options.harness ? [this.harnesses.require(options.harness)] : this.harnesses.list().map((item) => item.id);
|
|
31170
|
+
const completion = options.completion === true;
|
|
30748
31171
|
const items = await Promise.all(harnessIds.map(async (harness) => ({
|
|
30749
31172
|
harness,
|
|
30750
|
-
checks: await this.harnessChecks(harness, options.probe === true)
|
|
31173
|
+
checks: await this.harnessChecks(harness, completion || options.probe === true, completion)
|
|
30751
31174
|
})));
|
|
30752
31175
|
const update = await checkForUpdate();
|
|
30753
31176
|
return { items, updatedAvailable: update.updateAvailable };
|
|
30754
31177
|
}
|
|
30755
|
-
async harnessChecks(harness, probe) {
|
|
31178
|
+
async harnessChecks(harness, probe, completion) {
|
|
30756
31179
|
const checks3 = [];
|
|
30757
31180
|
const bin = BIN_NAMES[harness];
|
|
30758
31181
|
if (bin === undefined) {
|
|
@@ -30818,23 +31241,29 @@ class DoctorService {
|
|
|
30818
31241
|
checks3.push(ok(`${harness}.drift`, "live 文件与激活配置一致", DOCTOR_CODES.driftInSync));
|
|
30819
31242
|
}
|
|
30820
31243
|
if (probe) {
|
|
30821
|
-
checks3.push(await this.
|
|
31244
|
+
checks3.push(...await this.probeChecks(harness, completion));
|
|
30822
31245
|
}
|
|
30823
31246
|
return checks3;
|
|
30824
31247
|
}
|
|
30825
|
-
async
|
|
31248
|
+
async probeChecks(harness, completion) {
|
|
30826
31249
|
const active = this.activation.getActive(harness);
|
|
30827
31250
|
if (!active) {
|
|
30828
|
-
return
|
|
31251
|
+
return [
|
|
31252
|
+
unknown2(`${harness}.probe`, "未激活任何配置,跳过连通性探测", DOCTOR_CODES.probeNoProfile, undefined, { probed: false })
|
|
31253
|
+
];
|
|
30829
31254
|
}
|
|
30830
31255
|
if (active.official === true) {
|
|
30831
|
-
return
|
|
31256
|
+
return [
|
|
31257
|
+
unknown2(`${harness}.probe`, `${HARNESS_LABELS[harness]} 处于官方账号登录状态,无自定义端点可探测`, DOCTOR_CODES.probeOfficialLogin, undefined, { probed: false })
|
|
31258
|
+
];
|
|
30832
31259
|
}
|
|
30833
31260
|
const decrypted = this.profiles.decrypt(harness, active.name);
|
|
30834
31261
|
if (!decrypted.baseUrl || !decrypted.apiKey) {
|
|
30835
|
-
return
|
|
31262
|
+
return [
|
|
31263
|
+
warn(`${harness}.probe`, `配置 ${active.name} 缺少 Base URL 或 API Key,无法探测`, DOCTOR_CODES.probeMissingCredential, { profile: active.name }, { probed: false, baseUrl: decrypted.baseUrl || null })
|
|
31264
|
+
];
|
|
30836
31265
|
}
|
|
30837
|
-
const result = await this.probe.
|
|
31266
|
+
const result = await probeSavedProfile({ probe: this.probe, cache: this.probeCache, adapter: this.adapters.get(harness) }, harness, decrypted, { completion });
|
|
30838
31267
|
const detail = {
|
|
30839
31268
|
probed: true,
|
|
30840
31269
|
baseUrl: result.requestUrl ?? decrypted.baseUrl,
|
|
@@ -30843,10 +31272,8 @@ class DoctorService {
|
|
|
30843
31272
|
modelCount: result.models?.length ?? null,
|
|
30844
31273
|
reason: result.code ?? null
|
|
30845
31274
|
};
|
|
30846
|
-
|
|
30847
|
-
|
|
30848
|
-
}
|
|
30849
|
-
return error51(`${harness}.probe`, `连通性探测失败:${result.message ?? "未知原因"}`, DOCTOR_CODES.probeFailed, { profile: active.name, reason: result.code ?? PROBE_CODES.networkError }, detail);
|
|
31275
|
+
const catalog = result.ok ? ok(`${harness}.probe`, `端点可达(${result.latencyMs ?? "?"}ms,${result.models?.length ?? 0} 个模型)`, DOCTOR_CODES.probeOk, { profile: active.name }, detail) : error51(`${harness}.probe`, `连通性探测失败:${result.message ?? "未知原因"}`, DOCTOR_CODES.probeFailed, { profile: active.name, reason: result.code ?? PROBE_CODES.networkError }, detail);
|
|
31276
|
+
return result.completion ? [catalog, completionCheck(harness, active.name, result.completion)] : [catalog];
|
|
30850
31277
|
}
|
|
30851
31278
|
commandExists(bin) {
|
|
30852
31279
|
try {
|
|
@@ -30903,6 +31330,20 @@ function error51(id, message, code, params, detail) {
|
|
|
30903
31330
|
function unknown2(id, message, code, params, detail) {
|
|
30904
31331
|
return makeCheck(id, message, "unknown", code, params, detail);
|
|
30905
31332
|
}
|
|
31333
|
+
function completionCheck(harness, profile, completion) {
|
|
31334
|
+
const detail = {
|
|
31335
|
+
model: completion.model ?? null,
|
|
31336
|
+
protocol: completion.protocol ?? null,
|
|
31337
|
+
status: completion.status ?? null,
|
|
31338
|
+
latencyMs: completion.latencyMs ?? null,
|
|
31339
|
+
produced: completion.produced ?? null,
|
|
31340
|
+
cachedAt: completion.cachedAt ?? null,
|
|
31341
|
+
reason: completion.code ?? null
|
|
31342
|
+
};
|
|
31343
|
+
const model = completion.model ?? "?";
|
|
31344
|
+
const cached4 = completion.cachedAt ? "(缓存结果)" : "";
|
|
31345
|
+
return completion.ok ? ok(`${harness}.completion`, `模型 ${model} 补全成功(${completion.latencyMs ?? "?"}ms)${cached4}`, DOCTOR_CODES.completionOk, { profile, model, latencyMs: completion.latencyMs ?? 0 }, detail) : error51(`${harness}.completion`, `模型 ${model} 补全失败:${completion.message ?? "未知原因"}${cached4}`, DOCTOR_CODES.completionFailed, { profile, model, reason: completion.code ?? PROBE_CODES.networkError }, detail);
|
|
31346
|
+
}
|
|
30906
31347
|
function octal(mode) {
|
|
30907
31348
|
return mode.toString(8).padStart(4, "0");
|
|
30908
31349
|
}
|
|
@@ -30913,9 +31354,10 @@ function createDoctorRoutes(services) {
|
|
|
30913
31354
|
const doctor = services.get(IDoctorService);
|
|
30914
31355
|
app.get("/", async (c) => {
|
|
30915
31356
|
const probe = c.req.query("probe") === "1";
|
|
31357
|
+
const completion = c.req.query("completion") === "1";
|
|
30916
31358
|
const harnessParam = c.req.query("harness");
|
|
30917
31359
|
const harness = harnessParam && harnessParam.length > 0 ? harnessParam : undefined;
|
|
30918
|
-
return c.json(await doctor.run({ probe, harness }));
|
|
31360
|
+
return c.json(await doctor.run({ probe, completion, harness }));
|
|
30919
31361
|
});
|
|
30920
31362
|
return app;
|
|
30921
31363
|
}
|
|
@@ -31994,21 +32436,36 @@ function createHarnessRoutes(services) {
|
|
|
31994
32436
|
const files = services.get(IFileService);
|
|
31995
32437
|
const log = services.get(ILogService);
|
|
31996
32438
|
const probe = services.get(IProbeService);
|
|
32439
|
+
const probeCache = services.get(IProbeCacheService);
|
|
31997
32440
|
function summary(id) {
|
|
31998
32441
|
const adapter = adapters.get(id);
|
|
32442
|
+
const targets = adapter.targets();
|
|
32443
|
+
const current = adapter.officialNeedsCurrent ? Object.fromEntries(targets.map((target) => [target.key, files.readOptional(target.path)])) : {};
|
|
32444
|
+
const capability = adapter.official?.(current);
|
|
32445
|
+
const profileList = profiles.list(id);
|
|
32446
|
+
const linkedProfile = capability?.matchesProfile ? profileList.find(capability.matchesProfile) : undefined;
|
|
31999
32447
|
return {
|
|
32000
32448
|
id,
|
|
32001
32449
|
label: harnesses.label(id),
|
|
32002
32450
|
mode: adapter.mode,
|
|
32003
32451
|
active: activation.getActive(id),
|
|
32004
|
-
profiles:
|
|
32452
|
+
profiles: profileList,
|
|
32005
32453
|
fields: adapter.fields,
|
|
32006
32454
|
modelRequired: adapter.modelRequired,
|
|
32007
|
-
targets
|
|
32455
|
+
targets,
|
|
32008
32456
|
envVars: adapter.envVarNames,
|
|
32009
32457
|
envNote: adapter.envNote,
|
|
32010
32458
|
envNoteCode: adapter.envNoteCode,
|
|
32011
|
-
|
|
32459
|
+
...capability ? {
|
|
32460
|
+
official: {
|
|
32461
|
+
kind: capability.kind,
|
|
32462
|
+
available: capability.available,
|
|
32463
|
+
active: activation.getActive(id)?.official === true,
|
|
32464
|
+
titleCode: capability.titleCode,
|
|
32465
|
+
hintCode: capability.hintCode,
|
|
32466
|
+
...linkedProfile ? { linkedProfileName: linkedProfile.name } : {}
|
|
32467
|
+
}
|
|
32468
|
+
} : {}
|
|
32012
32469
|
};
|
|
32013
32470
|
}
|
|
32014
32471
|
app.get("/", (c) => c.json({
|
|
@@ -32019,13 +32476,15 @@ function createHarnessRoutes(services) {
|
|
|
32019
32476
|
app.post("/:harnessId/profiles", async (c) => {
|
|
32020
32477
|
const harnessId = harnesses.require(c.req.param("harnessId"));
|
|
32021
32478
|
const body = await readJsonBody(c, createProfileRequestSchema);
|
|
32022
|
-
|
|
32479
|
+
const copiedProviderType = body.copySourceName ? profiles.get(harnessId, body.copySourceName)?.extras.providerType : undefined;
|
|
32480
|
+
if (harnessId === "dsh" && (body.extras?.providerType ?? copiedProviderType) === "official" && profiles.list("dsh").some((profile2) => profile2.extras.providerType === "official")) {
|
|
32023
32481
|
throw new HttpError(409, "DeepSeek 官方配置已存在,请直接编辑现有官方配置", {
|
|
32024
32482
|
code: ERROR_CODES.officialProfileAlreadyExists
|
|
32025
32483
|
});
|
|
32026
32484
|
}
|
|
32027
32485
|
const profile = profiles.upsert(harnessId, {
|
|
32028
32486
|
name: body.name,
|
|
32487
|
+
copySourceName: body.copySourceName,
|
|
32029
32488
|
baseUrl: body.baseUrl,
|
|
32030
32489
|
apiKey: body.apiKey,
|
|
32031
32490
|
model: body.model,
|
|
@@ -32086,6 +32545,7 @@ function createHarnessRoutes(services) {
|
|
|
32086
32545
|
const name = decodeURIComponent(c.req.param("name"));
|
|
32087
32546
|
activation.prepareDelete(harnessId, name);
|
|
32088
32547
|
profiles.remove(harnessId, name);
|
|
32548
|
+
probeCache.forget(harnessId, name);
|
|
32089
32549
|
return c.json({ ok: true });
|
|
32090
32550
|
});
|
|
32091
32551
|
app.get("/:harnessId/profiles/:name/preview", (c) => {
|
|
@@ -32100,9 +32560,11 @@ function createHarnessRoutes(services) {
|
|
|
32100
32560
|
app.post("/:harnessId/profiles/:name/probe", async (c) => {
|
|
32101
32561
|
const harnessId = harnesses.require(c.req.param("harnessId"));
|
|
32102
32562
|
const name = decodeURIComponent(c.req.param("name"));
|
|
32103
|
-
parseWith(probeStoredRequestSchema, await c.req.json().catch(() => ({})));
|
|
32563
|
+
const body = parseWith(probeStoredRequestSchema, await c.req.json().catch(() => ({})));
|
|
32104
32564
|
const decrypted = profiles.decrypt(harnessId, name);
|
|
32105
|
-
return c.json({
|
|
32565
|
+
return c.json({
|
|
32566
|
+
result: await probeSavedProfile({ probe, cache: probeCache, adapter: adapters.get(harnessId) }, harnessId, decrypted, body)
|
|
32567
|
+
});
|
|
32106
32568
|
});
|
|
32107
32569
|
app.post("/:harnessId/profiles/:name/activate", (c) => {
|
|
32108
32570
|
const harnessId = harnesses.require(c.req.param("harnessId"));
|
|
@@ -32160,7 +32622,13 @@ function createProbeRoutes(services) {
|
|
|
32160
32622
|
});
|
|
32161
32623
|
}
|
|
32162
32624
|
return c.json({
|
|
32163
|
-
result: await probe.probe({
|
|
32625
|
+
result: await probe.probe({
|
|
32626
|
+
baseUrl: body.baseUrl,
|
|
32627
|
+
apiKey,
|
|
32628
|
+
completion: body.completion,
|
|
32629
|
+
model: body.model,
|
|
32630
|
+
protocol: body.protocol
|
|
32631
|
+
})
|
|
32164
32632
|
});
|
|
32165
32633
|
});
|
|
32166
32634
|
return app;
|
|
@@ -32241,7 +32709,15 @@ function createProviderRoutes(services) {
|
|
|
32241
32709
|
}
|
|
32242
32710
|
});
|
|
32243
32711
|
}
|
|
32244
|
-
return c.json({
|
|
32712
|
+
return c.json({
|
|
32713
|
+
result: await probe.probe({
|
|
32714
|
+
baseUrl,
|
|
32715
|
+
apiKey,
|
|
32716
|
+
completion: body.completion,
|
|
32717
|
+
model: body.model,
|
|
32718
|
+
protocol: body.protocol
|
|
32719
|
+
})
|
|
32720
|
+
});
|
|
32245
32721
|
});
|
|
32246
32722
|
app.delete("/:id", (c) => {
|
|
32247
32723
|
vault.remove(decodeURIComponent(c.req.param("id")));
|
|
@@ -33028,24 +33504,22 @@ function createApp(services) {
|
|
|
33028
33504
|
guarded("/drift", createDriftRoutes(services));
|
|
33029
33505
|
app.route("/api", api2);
|
|
33030
33506
|
const publicDir = environment.publicDir;
|
|
33031
|
-
|
|
33032
|
-
|
|
33033
|
-
|
|
33034
|
-
|
|
33035
|
-
|
|
33036
|
-
|
|
33037
|
-
|
|
33038
|
-
|
|
33039
|
-
|
|
33040
|
-
|
|
33041
|
-
|
|
33042
|
-
|
|
33043
|
-
|
|
33044
|
-
|
|
33045
|
-
|
|
33046
|
-
|
|
33047
|
-
});
|
|
33048
|
-
}
|
|
33507
|
+
app.get("*", async (c, next) => {
|
|
33508
|
+
if (c.req.path.startsWith("/api") || c.req.path === "/healthz") {
|
|
33509
|
+
return next();
|
|
33510
|
+
}
|
|
33511
|
+
const assetPath = resolve3(publicDir, c.req.path.replace(/^\//, ""));
|
|
33512
|
+
if (c.req.path !== "/" && isPublicAsset(publicDir, assetPath) && existsSync5(assetPath)) {
|
|
33513
|
+
c.header("Content-Type", contentType(assetPath));
|
|
33514
|
+
return c.body(readFileSync4(assetPath));
|
|
33515
|
+
}
|
|
33516
|
+
const index = join14(publicDir, "index.html");
|
|
33517
|
+
if (existsSync5(index)) {
|
|
33518
|
+
c.header("Cache-Control", "no-store");
|
|
33519
|
+
return c.html(readFileSync4(index, "utf8"));
|
|
33520
|
+
}
|
|
33521
|
+
return c.text("frontend not built", 503);
|
|
33522
|
+
});
|
|
33049
33523
|
app.notFound((c) => {
|
|
33050
33524
|
const code = ERROR_CODES.requestFailed;
|
|
33051
33525
|
return c.json({ code, msg: localizeMessage(requestLanguage(c.req.header("Accept-Language")), code) }, 404);
|
|
@@ -33138,6 +33612,7 @@ function createServices() {
|
|
|
33138
33612
|
collection.set(IVaultService, new SyncDescriptor(VaultService));
|
|
33139
33613
|
collection.set(IProfileService, new SyncDescriptor(ProfileService));
|
|
33140
33614
|
collection.set(IProbeService, new SyncDescriptor(ProbeService));
|
|
33615
|
+
collection.set(IProbeCacheService, new SyncDescriptor(ProbeCacheService));
|
|
33141
33616
|
collection.set(IActivationService, new SyncDescriptor(ActivationService));
|
|
33142
33617
|
collection.set(ITransferService, new SyncDescriptor(TransferService));
|
|
33143
33618
|
collection.set(IGitHubSyncService, new SyncDescriptor(GitHubSyncService));
|
|
@@ -33717,6 +34192,7 @@ function cliUsage() {
|
|
|
33717
34192
|
" --json, -j machine-readable JSON output",
|
|
33718
34193
|
" --yes, -y skip confirmation for activate, official and delete",
|
|
33719
34194
|
" --probe test the active profile's endpoint (makes a real request)",
|
|
34195
|
+
" --completion also send one minimal completion; proves the model answers, costs a token",
|
|
33720
34196
|
" --harness H limit doctor to one harness",
|
|
33721
34197
|
" --strict make doctor exit 1 when any check has error status",
|
|
33722
34198
|
" --user USER run an API-backed command for this Unix user",
|
|
@@ -33815,10 +34291,10 @@ function validateCommand(command, positional, flags) {
|
|
|
33815
34291
|
delete: { flags: ["yes"], min: 2, max: 2, usage: "delete <harness> <profile> [--yes]" },
|
|
33816
34292
|
providers: { min: 0, max: 0, usage: "providers [options]" },
|
|
33817
34293
|
doctor: {
|
|
33818
|
-
flags: ["probe", "harness", "strict"],
|
|
34294
|
+
flags: ["probe", "completion", "harness", "strict"],
|
|
33819
34295
|
min: 0,
|
|
33820
34296
|
max: 0,
|
|
33821
|
-
usage: "doctor [--probe] [--harness H] [--strict]"
|
|
34297
|
+
usage: "doctor [--probe] [--completion] [--harness H] [--strict]"
|
|
33822
34298
|
},
|
|
33823
34299
|
plan: { min: 2, max: 2, usage: "plan <harness> <profile> [options]" },
|
|
33824
34300
|
activate: {
|
|
@@ -33952,6 +34428,9 @@ async function cmdDoctor(client, flags, json2) {
|
|
|
33952
34428
|
if (hasFlag(flags, "probe")) {
|
|
33953
34429
|
query.set("probe", "1");
|
|
33954
34430
|
}
|
|
34431
|
+
if (hasFlag(flags, "completion")) {
|
|
34432
|
+
query.set("completion", "1");
|
|
34433
|
+
}
|
|
33955
34434
|
const harness = flagValue(flags, "harness");
|
|
33956
34435
|
if (harness) {
|
|
33957
34436
|
query.set("harness", harness);
|