@seaveyon/harness-switch 0.29.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
|
@@ -7139,7 +7139,9 @@ var DOCTOR_CODES = {
|
|
|
7139
7139
|
probeOfficialLogin: "doctor.check.probeOfficialLogin",
|
|
7140
7140
|
probeMissingCredential: "doctor.check.probeMissingCredential",
|
|
7141
7141
|
probeOk: "doctor.check.probeOk",
|
|
7142
|
-
probeFailed: "doctor.check.probeFailed"
|
|
7142
|
+
probeFailed: "doctor.check.probeFailed",
|
|
7143
|
+
completionOk: "doctor.check.completionOk",
|
|
7144
|
+
completionFailed: "doctor.check.completionFailed"
|
|
7143
7145
|
};
|
|
7144
7146
|
var SCAN_NOTE_CODES = {
|
|
7145
7147
|
unsupported: "scan.note.unsupported",
|
|
@@ -7155,7 +7157,11 @@ var PROBE_CODES = {
|
|
|
7155
7157
|
networkError: "probe.networkError",
|
|
7156
7158
|
unauthorized: "probe.unauthorized",
|
|
7157
7159
|
httpError: "probe.httpError",
|
|
7158
|
-
invalidResponse: "probe.invalidResponse"
|
|
7160
|
+
invalidResponse: "probe.invalidResponse",
|
|
7161
|
+
missingModel: "probe.missingModel",
|
|
7162
|
+
completionUnsupported: "probe.completionUnsupported",
|
|
7163
|
+
completionHttpError: "probe.completionHttpError",
|
|
7164
|
+
completionInvalid: "probe.completionInvalid"
|
|
7159
7165
|
};
|
|
7160
7166
|
var USER_BLOCK_CODES = {
|
|
7161
7167
|
homeUnsearchable: "user.block.homeUnsearchable",
|
|
@@ -7676,7 +7682,9 @@ var en_default = {
|
|
|
7676
7682
|
probeOfficialLogin: "{{harness}} is on its built-in account login; no custom endpoint to probe",
|
|
7677
7683
|
probeMissingCredential: "Profile {{profile}} has no base URL or API key; cannot probe",
|
|
7678
7684
|
probeOk: "Endpoint of profile {{profile}} is reachable",
|
|
7679
|
-
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"
|
|
7680
7688
|
}
|
|
7681
7689
|
},
|
|
7682
7690
|
notice: {
|
|
@@ -7846,7 +7854,11 @@ var en_default = {
|
|
|
7846
7854
|
networkError: "Could not reach the endpoint (DNS, refused connection or TLS failure)",
|
|
7847
7855
|
unauthorized: "Endpoint reachable but rejected the credential (HTTP {{status}}); check the API key",
|
|
7848
7856
|
httpError: "Endpoint returned HTTP {{status}}",
|
|
7849
|
-
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"
|
|
7850
7862
|
}
|
|
7851
7863
|
},
|
|
7852
7864
|
warning: {
|
|
@@ -8084,9 +8096,14 @@ var en_default = {
|
|
|
8084
8096
|
},
|
|
8085
8097
|
probe: {
|
|
8086
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).",
|
|
8087
8101
|
probing: "Testing…",
|
|
8088
8102
|
ok: "Reachable · {{latencyMs}}ms · {{count}} models",
|
|
8089
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}}",
|
|
8090
8107
|
catalogHint: "Fetched {{count}} models; click the model field to pick one from the list.",
|
|
8091
8108
|
missingBaseUrl: "Add an endpoint URL before testing."
|
|
8092
8109
|
}
|
|
@@ -8591,7 +8608,9 @@ var zh_CN_default = {
|
|
|
8591
8608
|
probeOfficialLogin: "{{harness}} 处于官方账号登录状态,无自定义端点可探测",
|
|
8592
8609
|
probeMissingCredential: "配置 {{profile}} 缺少 Base URL 或 API Key,无法探测",
|
|
8593
8610
|
probeOk: "配置 {{profile}} 的端点可达",
|
|
8594
|
-
probeFailed: "配置 {{profile}} 的连通性探测失败"
|
|
8611
|
+
probeFailed: "配置 {{profile}} 的连通性探测失败",
|
|
8612
|
+
completionOk: "模型 {{model}} 补全成功({{latencyMs}}ms)",
|
|
8613
|
+
completionFailed: "模型 {{model}} 补全失败:端点可达,但这个模型无法作答"
|
|
8595
8614
|
}
|
|
8596
8615
|
},
|
|
8597
8616
|
notice: {
|
|
@@ -8761,7 +8780,11 @@ var zh_CN_default = {
|
|
|
8761
8780
|
networkError: "无法连接到端点(DNS、拒绝连接或 TLS 失败)",
|
|
8762
8781
|
unauthorized: "端点可达但拒绝了凭据(HTTP {{status}}),请检查 API Key",
|
|
8763
8782
|
httpError: "端点返回 HTTP {{status}}",
|
|
8764
|
-
invalidResponse: "响应不是已知的模型目录格式"
|
|
8783
|
+
invalidResponse: "响应不是已知的模型目录格式",
|
|
8784
|
+
missingModel: "没有可用于补全测试的模型:请填写模型名称,或先获取模型目录",
|
|
8785
|
+
completionUnsupported: "端点不接受任何已知的补全协议",
|
|
8786
|
+
completionHttpError: "模型 {{model}} 的补全请求返回 HTTP {{status}}:目录里有这个模型,但它无法作答",
|
|
8787
|
+
completionInvalid: "补全响应不是已知的格式,无法确认模型真的作答"
|
|
8765
8788
|
}
|
|
8766
8789
|
},
|
|
8767
8790
|
warning: {
|
|
@@ -8999,9 +9022,14 @@ var zh_CN_default = {
|
|
|
8999
9022
|
},
|
|
9000
9023
|
probe: {
|
|
9001
9024
|
action: "测试连接",
|
|
9025
|
+
completionAction: "测试补全",
|
|
9026
|
+
completionHint: "真实发送一条最小请求,验证模型确实能作答(会消耗一两个 token)。",
|
|
9002
9027
|
probing: "正在测试…",
|
|
9003
9028
|
ok: "连接正常 · {{latencyMs}}ms · {{count}} 个模型",
|
|
9004
9029
|
okNoCatalog: "连接正常 · {{latencyMs}}ms · 端点未提供模型目录",
|
|
9030
|
+
completionOk: "模型 {{model}} 可作答 · {{latencyMs}}ms",
|
|
9031
|
+
completionCached: "模型 {{model}} 可作答 · 缓存于 {{at}}",
|
|
9032
|
+
completionFailedCached: "缓存于 {{at}}",
|
|
9005
9033
|
catalogHint: "已获取 {{count}} 个模型,点击“模型”输入框可从列表选择。",
|
|
9006
9034
|
missingBaseUrl: "请先填写至少一个 endpoint URL 再测试。"
|
|
9007
9035
|
}
|
|
@@ -23302,6 +23330,11 @@ var harnessIdSchema = exports_external.enum(HARNESS_IDS);
|
|
|
23302
23330
|
var extrasSchema = exports_external.record(mapKey, optionalText(MAX_EXTRA_VALUE));
|
|
23303
23331
|
var overridesSchema = exports_external.record(mapKey, optionalText(MAX_OVERRIDE));
|
|
23304
23332
|
var conflictPolicySchema = exports_external.enum(["skip", "overwrite"]);
|
|
23333
|
+
var completionProtocolSchema = exports_external.enum([
|
|
23334
|
+
"openai-chat",
|
|
23335
|
+
"openai-responses",
|
|
23336
|
+
"anthropic-messages"
|
|
23337
|
+
]);
|
|
23305
23338
|
var loginRequestSchema = exports_external.object({
|
|
23306
23339
|
password: exports_external.string().trim().min(1, "password 不能为空").max(MAX_KEY)
|
|
23307
23340
|
});
|
|
@@ -23382,10 +23415,17 @@ var scanImportRequestSchema = exports_external.object({
|
|
|
23382
23415
|
var probeRequestSchema = exports_external.object({
|
|
23383
23416
|
baseUrl: exports_external.string().trim().min(1, "baseUrl 不能为空").max(MAX_URL),
|
|
23384
23417
|
apiKey: optionalText(MAX_KEY).optional(),
|
|
23385
|
-
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()
|
|
23386
23422
|
});
|
|
23387
23423
|
var probeStoredRequestSchema = exports_external.object({
|
|
23388
|
-
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()
|
|
23389
23429
|
});
|
|
23390
23430
|
var gitHubDeviceCodeRequestSchema = exports_external.object({
|
|
23391
23431
|
clientId: optionalText(100).optional()
|
|
@@ -25439,7 +25479,8 @@ class EnvironmentService {
|
|
|
25439
25479
|
env: join2(dataDir, "env.sh"),
|
|
25440
25480
|
sessions: join2(dataDir, "sessions.json"),
|
|
25441
25481
|
vault: join2(dataDir, "vault.json"),
|
|
25442
|
-
github: join2(dataDir, "github.json")
|
|
25482
|
+
github: join2(dataDir, "github.json"),
|
|
25483
|
+
probeCache: join2(dataDir, "probe-cache.json")
|
|
25443
25484
|
};
|
|
25444
25485
|
}
|
|
25445
25486
|
get backupsDir() {
|
|
@@ -27581,6 +27622,9 @@ API_TIMEOUT_MS=3000000`,
|
|
|
27581
27622
|
}
|
|
27582
27623
|
return vars;
|
|
27583
27624
|
}
|
|
27625
|
+
completionProtocol() {
|
|
27626
|
+
return "anthropic-messages";
|
|
27627
|
+
}
|
|
27584
27628
|
render(profile, current) {
|
|
27585
27629
|
const settings = parseJsonObject(current[SETTINGS]);
|
|
27586
27630
|
const env = ensureObject(settings, "env");
|
|
@@ -27819,6 +27863,9 @@ class CodexAdapter {
|
|
|
27819
27863
|
}
|
|
27820
27864
|
return { [this.envKeyName(profile)]: profile.apiKey };
|
|
27821
27865
|
}
|
|
27866
|
+
completionProtocol() {
|
|
27867
|
+
return "openai-responses";
|
|
27868
|
+
}
|
|
27822
27869
|
render(profile, current) {
|
|
27823
27870
|
const providerId2 = this.providerId(profile);
|
|
27824
27871
|
const config2 = parseTomlObject(current[CONFIG]);
|
|
@@ -27924,8 +27971,22 @@ class CodexAdapter {
|
|
|
27924
27971
|
|
|
27925
27972
|
// src/services/adapters/dsh.ts
|
|
27926
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
|
|
27927
27987
|
var SETTINGS2 = "settings";
|
|
27928
27988
|
var CREDENTIALS = "credentials";
|
|
27989
|
+
var DEFAULT_API = "openai-responses";
|
|
27929
27990
|
var DEFAULT_CONTEXT = 262144;
|
|
27930
27991
|
var DEFAULT_MAX_TOKENS = 32768;
|
|
27931
27992
|
|
|
@@ -27984,7 +28045,7 @@ class DshAdapter {
|
|
|
27984
28045
|
label: "API 协议",
|
|
27985
28046
|
labelCode: "harness.field.dsh.api.label",
|
|
27986
28047
|
kind: "select",
|
|
27987
|
-
defaultValue:
|
|
28048
|
+
defaultValue: DEFAULT_API,
|
|
27988
28049
|
options: [
|
|
27989
28050
|
{ value: "openai-responses", label: "openai-responses" },
|
|
27990
28051
|
{ value: "openai-completions", label: "openai-completions" },
|
|
@@ -28052,6 +28113,9 @@ class DshAdapter {
|
|
|
28052
28113
|
envVars() {
|
|
28053
28114
|
return {};
|
|
28054
28115
|
}
|
|
28116
|
+
completionProtocol(profile) {
|
|
28117
|
+
return this.isOfficial(profile) ? "openai-chat" : apiFieldProtocol(profile.extras.api, "openai-responses");
|
|
28118
|
+
}
|
|
28055
28119
|
validate(profile) {
|
|
28056
28120
|
if (!profile.model.trim()) {
|
|
28057
28121
|
throw new HttpError(400, "DeepSeek Harness 需要填写模型名称", {
|
|
@@ -28082,7 +28146,7 @@ class DshAdapter {
|
|
|
28082
28146
|
settings.setIn(["llm-pi-ai", "providers", providerId2], {
|
|
28083
28147
|
displayName: profile.name,
|
|
28084
28148
|
apiKeyEnv: credentialRef,
|
|
28085
|
-
api: profile.extras.api ||
|
|
28149
|
+
api: profile.extras.api || DEFAULT_API,
|
|
28086
28150
|
baseURL: profile.baseUrl,
|
|
28087
28151
|
models
|
|
28088
28152
|
});
|
|
@@ -28355,6 +28419,19 @@ class KimiAdapter {
|
|
|
28355
28419
|
envVars() {
|
|
28356
28420
|
return {};
|
|
28357
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
|
+
}
|
|
28358
28435
|
validate(profile) {
|
|
28359
28436
|
if (!profile.model.trim()) {
|
|
28360
28437
|
throw new HttpError(400, "Kimi Code 需要填写模型名称,否则无法生成 models 条目", {
|
|
@@ -28478,6 +28555,7 @@ function officialModel(config2) {
|
|
|
28478
28555
|
import { join as join7 } from "node:path";
|
|
28479
28556
|
var MODELS = "models";
|
|
28480
28557
|
var SETTINGS3 = "settings";
|
|
28558
|
+
var DEFAULT_API2 = "openai-completions";
|
|
28481
28559
|
var DEFAULT_CONTEXT3 = 200000;
|
|
28482
28560
|
var DEFAULT_MAX_TOKENS2 = 8192;
|
|
28483
28561
|
|
|
@@ -28505,7 +28583,7 @@ class PiAdapter {
|
|
|
28505
28583
|
label: "协议",
|
|
28506
28584
|
labelCode: "harness.field.pi.api.label",
|
|
28507
28585
|
kind: "select",
|
|
28508
|
-
defaultValue:
|
|
28586
|
+
defaultValue: DEFAULT_API2,
|
|
28509
28587
|
options: [
|
|
28510
28588
|
{ value: "openai-completions", label: "openai-completions" },
|
|
28511
28589
|
{ value: "openai-responses", label: "openai-responses" },
|
|
@@ -28575,6 +28653,9 @@ class PiAdapter {
|
|
|
28575
28653
|
envVars() {
|
|
28576
28654
|
return {};
|
|
28577
28655
|
}
|
|
28656
|
+
completionProtocol(profile) {
|
|
28657
|
+
return apiFieldProtocol(profile.extras.api, "openai-chat");
|
|
28658
|
+
}
|
|
28578
28659
|
validate(profile) {
|
|
28579
28660
|
if (!profile.model.trim()) {
|
|
28580
28661
|
throw new HttpError(400, "Pi 需要填写模型名称,否则无法生成 models 条目", {
|
|
@@ -28605,7 +28686,7 @@ class PiAdapter {
|
|
|
28605
28686
|
}
|
|
28606
28687
|
provider.baseUrl = profile.baseUrl;
|
|
28607
28688
|
provider.apiKey = profile.apiKey;
|
|
28608
|
-
provider.api = profile.extras.api ||
|
|
28689
|
+
provider.api = profile.extras.api || DEFAULT_API2;
|
|
28609
28690
|
provider.authHeader = profile.extras.authHeader !== "false";
|
|
28610
28691
|
provider.models = [model];
|
|
28611
28692
|
const settings = parseJsonObject(current[SETTINGS3]);
|
|
@@ -30620,8 +30701,16 @@ function deepEqual(left, right) {
|
|
|
30620
30701
|
// src/services/probe.ts
|
|
30621
30702
|
var IProbeService = createDecorator("probeService");
|
|
30622
30703
|
var TIMEOUT_MS = 1e4;
|
|
30704
|
+
var COMPLETION_TIMEOUT_MS = 30000;
|
|
30623
30705
|
var MAX_BODY_BYTES = 4 * 1024 * 1024;
|
|
30624
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
|
+
];
|
|
30625
30714
|
var _dec = [
|
|
30626
30715
|
inject()
|
|
30627
30716
|
];
|
|
@@ -30645,11 +30734,24 @@ class ProbeService {
|
|
|
30645
30734
|
if (base.protocol !== "http:" && base.protocol !== "https:") {
|
|
30646
30735
|
return failure(PROBE_CODES.badUrl, `Base URL 必须是 http/https:${base.protocol}`);
|
|
30647
30736
|
}
|
|
30648
|
-
const
|
|
30649
|
-
|
|
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")];
|
|
30650
30752
|
let lastStatus;
|
|
30651
30753
|
for (let index = 0;index < candidates.length; index++) {
|
|
30652
|
-
const result = await this.request(candidates[index],
|
|
30754
|
+
const result = await this.request(candidates[index], apiKey);
|
|
30653
30755
|
if (result.status !== 404 || index === candidates.length - 1) {
|
|
30654
30756
|
return result;
|
|
30655
30757
|
}
|
|
@@ -30665,12 +30767,7 @@ class ProbeService {
|
|
|
30665
30767
|
let response;
|
|
30666
30768
|
try {
|
|
30667
30769
|
response = await fetch(url2, {
|
|
30668
|
-
headers: {
|
|
30669
|
-
Accept: "application/json",
|
|
30670
|
-
Authorization: `Bearer ${apiKey}`,
|
|
30671
|
-
"x-api-key": apiKey,
|
|
30672
|
-
"anthropic-version": "2023-06-01"
|
|
30673
|
-
},
|
|
30770
|
+
headers: authHeaders(apiKey, { Accept: "application/json" }),
|
|
30674
30771
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
30675
30772
|
redirect: "follow"
|
|
30676
30773
|
});
|
|
@@ -30708,11 +30805,104 @@ class ProbeService {
|
|
|
30708
30805
|
}
|
|
30709
30806
|
return { ok: true, ...shared, models };
|
|
30710
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
|
+
}
|
|
30711
30868
|
}
|
|
30712
30869
|
ProbeService = __decorateElement(_init, 0, "ProbeService", _dec, ProbeService);
|
|
30713
30870
|
__runInitializers(_init, 1, ProbeService);
|
|
30714
30871
|
__decoratorMetadata(_init, ProbeService);
|
|
30715
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
|
+
}
|
|
30716
30906
|
async function readBody(response) {
|
|
30717
30907
|
const declaredLength = response.headers.get("content-length");
|
|
30718
30908
|
if (declaredLength && Number(declaredLength) > MAX_BODY_BYTES) {
|
|
@@ -30748,6 +30938,9 @@ function joinUrl(base, suffix) {
|
|
|
30748
30938
|
function failure(code, message, extra = {}) {
|
|
30749
30939
|
return { ok: false, code, message, ...extra };
|
|
30750
30940
|
}
|
|
30941
|
+
function completionFailure(code, message, extra = {}) {
|
|
30942
|
+
return { ok: false, code, message, ...extra };
|
|
30943
|
+
}
|
|
30751
30944
|
function isTimeout(error51) {
|
|
30752
30945
|
const name = error51?.name;
|
|
30753
30946
|
return name === "TimeoutError" || name === "AbortError";
|
|
@@ -30781,6 +30974,53 @@ function extractModels(body) {
|
|
|
30781
30974
|
}
|
|
30782
30975
|
return models;
|
|
30783
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
|
+
}
|
|
30784
31024
|
function isRecord3(value) {
|
|
30785
31025
|
return typeof value === "object" && value !== null;
|
|
30786
31026
|
}
|
|
@@ -30794,6 +31034,103 @@ function firstString(record2, keys) {
|
|
|
30794
31034
|
return "";
|
|
30795
31035
|
}
|
|
30796
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
|
+
|
|
30797
31134
|
// src/services/doctor.ts
|
|
30798
31135
|
var IDoctorService = createDecorator("doctorService");
|
|
30799
31136
|
var BIN_NAMES = {
|
|
@@ -30803,7 +31140,7 @@ var BIN_NAMES = {
|
|
|
30803
31140
|
pi: "pi"
|
|
30804
31141
|
};
|
|
30805
31142
|
var _dec = [
|
|
30806
|
-
inject(IEnvironmentService, IFileService, IHarnessRegistry, IAdapterRegistry, IActivationService, IDriftService, IProfileService, IProbeService)
|
|
31143
|
+
inject(IEnvironmentService, IFileService, IHarnessRegistry, IAdapterRegistry, IActivationService, IDriftService, IProfileService, IProbeService, IProbeCacheService)
|
|
30807
31144
|
];
|
|
30808
31145
|
var _init = __decoratorStart(undefined);
|
|
30809
31146
|
|
|
@@ -30816,7 +31153,8 @@ class DoctorService {
|
|
|
30816
31153
|
drift;
|
|
30817
31154
|
profiles;
|
|
30818
31155
|
probe;
|
|
30819
|
-
|
|
31156
|
+
probeCache;
|
|
31157
|
+
constructor(environment, files, harnesses, adapters, activation, drift, profiles, probe, probeCache) {
|
|
30820
31158
|
this.environment = environment;
|
|
30821
31159
|
this.files = files;
|
|
30822
31160
|
this.harnesses = harnesses;
|
|
@@ -30825,17 +31163,19 @@ class DoctorService {
|
|
|
30825
31163
|
this.drift = drift;
|
|
30826
31164
|
this.profiles = profiles;
|
|
30827
31165
|
this.probe = probe;
|
|
31166
|
+
this.probeCache = probeCache;
|
|
30828
31167
|
}
|
|
30829
31168
|
async run(options = {}) {
|
|
30830
31169
|
const harnessIds = options.harness ? [this.harnesses.require(options.harness)] : this.harnesses.list().map((item) => item.id);
|
|
31170
|
+
const completion = options.completion === true;
|
|
30831
31171
|
const items = await Promise.all(harnessIds.map(async (harness) => ({
|
|
30832
31172
|
harness,
|
|
30833
|
-
checks: await this.harnessChecks(harness, options.probe === true)
|
|
31173
|
+
checks: await this.harnessChecks(harness, completion || options.probe === true, completion)
|
|
30834
31174
|
})));
|
|
30835
31175
|
const update = await checkForUpdate();
|
|
30836
31176
|
return { items, updatedAvailable: update.updateAvailable };
|
|
30837
31177
|
}
|
|
30838
|
-
async harnessChecks(harness, probe) {
|
|
31178
|
+
async harnessChecks(harness, probe, completion) {
|
|
30839
31179
|
const checks3 = [];
|
|
30840
31180
|
const bin = BIN_NAMES[harness];
|
|
30841
31181
|
if (bin === undefined) {
|
|
@@ -30901,23 +31241,29 @@ class DoctorService {
|
|
|
30901
31241
|
checks3.push(ok(`${harness}.drift`, "live 文件与激活配置一致", DOCTOR_CODES.driftInSync));
|
|
30902
31242
|
}
|
|
30903
31243
|
if (probe) {
|
|
30904
|
-
checks3.push(await this.
|
|
31244
|
+
checks3.push(...await this.probeChecks(harness, completion));
|
|
30905
31245
|
}
|
|
30906
31246
|
return checks3;
|
|
30907
31247
|
}
|
|
30908
|
-
async
|
|
31248
|
+
async probeChecks(harness, completion) {
|
|
30909
31249
|
const active = this.activation.getActive(harness);
|
|
30910
31250
|
if (!active) {
|
|
30911
|
-
return
|
|
31251
|
+
return [
|
|
31252
|
+
unknown2(`${harness}.probe`, "未激活任何配置,跳过连通性探测", DOCTOR_CODES.probeNoProfile, undefined, { probed: false })
|
|
31253
|
+
];
|
|
30912
31254
|
}
|
|
30913
31255
|
if (active.official === true) {
|
|
30914
|
-
return
|
|
31256
|
+
return [
|
|
31257
|
+
unknown2(`${harness}.probe`, `${HARNESS_LABELS[harness]} 处于官方账号登录状态,无自定义端点可探测`, DOCTOR_CODES.probeOfficialLogin, undefined, { probed: false })
|
|
31258
|
+
];
|
|
30915
31259
|
}
|
|
30916
31260
|
const decrypted = this.profiles.decrypt(harness, active.name);
|
|
30917
31261
|
if (!decrypted.baseUrl || !decrypted.apiKey) {
|
|
30918
|
-
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
|
+
];
|
|
30919
31265
|
}
|
|
30920
|
-
const result = await this.probe.
|
|
31266
|
+
const result = await probeSavedProfile({ probe: this.probe, cache: this.probeCache, adapter: this.adapters.get(harness) }, harness, decrypted, { completion });
|
|
30921
31267
|
const detail = {
|
|
30922
31268
|
probed: true,
|
|
30923
31269
|
baseUrl: result.requestUrl ?? decrypted.baseUrl,
|
|
@@ -30926,10 +31272,8 @@ class DoctorService {
|
|
|
30926
31272
|
modelCount: result.models?.length ?? null,
|
|
30927
31273
|
reason: result.code ?? null
|
|
30928
31274
|
};
|
|
30929
|
-
|
|
30930
|
-
|
|
30931
|
-
}
|
|
30932
|
-
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];
|
|
30933
31277
|
}
|
|
30934
31278
|
commandExists(bin) {
|
|
30935
31279
|
try {
|
|
@@ -30986,6 +31330,20 @@ function error51(id, message, code, params, detail) {
|
|
|
30986
31330
|
function unknown2(id, message, code, params, detail) {
|
|
30987
31331
|
return makeCheck(id, message, "unknown", code, params, detail);
|
|
30988
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
|
+
}
|
|
30989
31347
|
function octal(mode) {
|
|
30990
31348
|
return mode.toString(8).padStart(4, "0");
|
|
30991
31349
|
}
|
|
@@ -30996,9 +31354,10 @@ function createDoctorRoutes(services) {
|
|
|
30996
31354
|
const doctor = services.get(IDoctorService);
|
|
30997
31355
|
app.get("/", async (c) => {
|
|
30998
31356
|
const probe = c.req.query("probe") === "1";
|
|
31357
|
+
const completion = c.req.query("completion") === "1";
|
|
30999
31358
|
const harnessParam = c.req.query("harness");
|
|
31000
31359
|
const harness = harnessParam && harnessParam.length > 0 ? harnessParam : undefined;
|
|
31001
|
-
return c.json(await doctor.run({ probe, harness }));
|
|
31360
|
+
return c.json(await doctor.run({ probe, completion, harness }));
|
|
31002
31361
|
});
|
|
31003
31362
|
return app;
|
|
31004
31363
|
}
|
|
@@ -32077,6 +32436,7 @@ function createHarnessRoutes(services) {
|
|
|
32077
32436
|
const files = services.get(IFileService);
|
|
32078
32437
|
const log = services.get(ILogService);
|
|
32079
32438
|
const probe = services.get(IProbeService);
|
|
32439
|
+
const probeCache = services.get(IProbeCacheService);
|
|
32080
32440
|
function summary(id) {
|
|
32081
32441
|
const adapter = adapters.get(id);
|
|
32082
32442
|
const targets = adapter.targets();
|
|
@@ -32185,6 +32545,7 @@ function createHarnessRoutes(services) {
|
|
|
32185
32545
|
const name = decodeURIComponent(c.req.param("name"));
|
|
32186
32546
|
activation.prepareDelete(harnessId, name);
|
|
32187
32547
|
profiles.remove(harnessId, name);
|
|
32548
|
+
probeCache.forget(harnessId, name);
|
|
32188
32549
|
return c.json({ ok: true });
|
|
32189
32550
|
});
|
|
32190
32551
|
app.get("/:harnessId/profiles/:name/preview", (c) => {
|
|
@@ -32199,9 +32560,11 @@ function createHarnessRoutes(services) {
|
|
|
32199
32560
|
app.post("/:harnessId/profiles/:name/probe", async (c) => {
|
|
32200
32561
|
const harnessId = harnesses.require(c.req.param("harnessId"));
|
|
32201
32562
|
const name = decodeURIComponent(c.req.param("name"));
|
|
32202
|
-
parseWith(probeStoredRequestSchema, await c.req.json().catch(() => ({})));
|
|
32563
|
+
const body = parseWith(probeStoredRequestSchema, await c.req.json().catch(() => ({})));
|
|
32203
32564
|
const decrypted = profiles.decrypt(harnessId, name);
|
|
32204
|
-
return c.json({
|
|
32565
|
+
return c.json({
|
|
32566
|
+
result: await probeSavedProfile({ probe, cache: probeCache, adapter: adapters.get(harnessId) }, harnessId, decrypted, body)
|
|
32567
|
+
});
|
|
32205
32568
|
});
|
|
32206
32569
|
app.post("/:harnessId/profiles/:name/activate", (c) => {
|
|
32207
32570
|
const harnessId = harnesses.require(c.req.param("harnessId"));
|
|
@@ -32259,7 +32622,13 @@ function createProbeRoutes(services) {
|
|
|
32259
32622
|
});
|
|
32260
32623
|
}
|
|
32261
32624
|
return c.json({
|
|
32262
|
-
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
|
+
})
|
|
32263
32632
|
});
|
|
32264
32633
|
});
|
|
32265
32634
|
return app;
|
|
@@ -32340,7 +32709,15 @@ function createProviderRoutes(services) {
|
|
|
32340
32709
|
}
|
|
32341
32710
|
});
|
|
32342
32711
|
}
|
|
32343
|
-
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
|
+
});
|
|
32344
32721
|
});
|
|
32345
32722
|
app.delete("/:id", (c) => {
|
|
32346
32723
|
vault.remove(decodeURIComponent(c.req.param("id")));
|
|
@@ -33235,6 +33612,7 @@ function createServices() {
|
|
|
33235
33612
|
collection.set(IVaultService, new SyncDescriptor(VaultService));
|
|
33236
33613
|
collection.set(IProfileService, new SyncDescriptor(ProfileService));
|
|
33237
33614
|
collection.set(IProbeService, new SyncDescriptor(ProbeService));
|
|
33615
|
+
collection.set(IProbeCacheService, new SyncDescriptor(ProbeCacheService));
|
|
33238
33616
|
collection.set(IActivationService, new SyncDescriptor(ActivationService));
|
|
33239
33617
|
collection.set(ITransferService, new SyncDescriptor(TransferService));
|
|
33240
33618
|
collection.set(IGitHubSyncService, new SyncDescriptor(GitHubSyncService));
|
|
@@ -33814,6 +34192,7 @@ function cliUsage() {
|
|
|
33814
34192
|
" --json, -j machine-readable JSON output",
|
|
33815
34193
|
" --yes, -y skip confirmation for activate, official and delete",
|
|
33816
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",
|
|
33817
34196
|
" --harness H limit doctor to one harness",
|
|
33818
34197
|
" --strict make doctor exit 1 when any check has error status",
|
|
33819
34198
|
" --user USER run an API-backed command for this Unix user",
|
|
@@ -33912,10 +34291,10 @@ function validateCommand(command, positional, flags) {
|
|
|
33912
34291
|
delete: { flags: ["yes"], min: 2, max: 2, usage: "delete <harness> <profile> [--yes]" },
|
|
33913
34292
|
providers: { min: 0, max: 0, usage: "providers [options]" },
|
|
33914
34293
|
doctor: {
|
|
33915
|
-
flags: ["probe", "harness", "strict"],
|
|
34294
|
+
flags: ["probe", "completion", "harness", "strict"],
|
|
33916
34295
|
min: 0,
|
|
33917
34296
|
max: 0,
|
|
33918
|
-
usage: "doctor [--probe] [--harness H] [--strict]"
|
|
34297
|
+
usage: "doctor [--probe] [--completion] [--harness H] [--strict]"
|
|
33919
34298
|
},
|
|
33920
34299
|
plan: { min: 2, max: 2, usage: "plan <harness> <profile> [options]" },
|
|
33921
34300
|
activate: {
|
|
@@ -34049,6 +34428,9 @@ async function cmdDoctor(client, flags, json2) {
|
|
|
34049
34428
|
if (hasFlag(flags, "probe")) {
|
|
34050
34429
|
query.set("probe", "1");
|
|
34051
34430
|
}
|
|
34431
|
+
if (hasFlag(flags, "completion")) {
|
|
34432
|
+
query.set("completion", "1");
|
|
34433
|
+
}
|
|
34052
34434
|
const harness = flagValue(flags, "harness");
|
|
34053
34435
|
if (harness) {
|
|
34054
34436
|
query.set("harness", harness);
|