@authinex/dsh-plugin 0.3.10 → 0.3.11
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/README.md +49 -48
- package/lib/client.js +9 -5
- package/lib/index.js +626 -99
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -90,23 +90,23 @@ function attachOptionalHosts(ctx, bridge) {
|
|
|
90
90
|
import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
91
91
|
import { homedir } from "node:os";
|
|
92
92
|
import { dirname, join } from "node:path";
|
|
93
|
-
function deviceFileAt(
|
|
93
|
+
function deviceFileAt(path3) {
|
|
94
94
|
return {
|
|
95
95
|
async read() {
|
|
96
96
|
try {
|
|
97
|
-
const
|
|
98
|
-
return
|
|
97
|
+
const text3 = await readFile(path3, "utf8");
|
|
98
|
+
return text3.trim() ? text3 : void 0;
|
|
99
99
|
} catch {
|
|
100
100
|
return void 0;
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
async write(value) {
|
|
104
|
-
await mkdir(dirname(
|
|
105
|
-
await writeFile(
|
|
106
|
-
await chmod(
|
|
104
|
+
await mkdir(dirname(path3), { recursive: true, mode: 448 });
|
|
105
|
+
await writeFile(path3, value, { mode: 384 });
|
|
106
|
+
await chmod(path3, 384);
|
|
107
107
|
},
|
|
108
108
|
async clear() {
|
|
109
|
-
await rm(
|
|
109
|
+
await rm(path3, { force: true });
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
}
|
|
@@ -129,9 +129,16 @@ var PHRASES = {
|
|
|
129
129
|
var MISS = "这次没查到。请告诉用户这次没有查到,不要用常识补云枢功能、单号或源码路径。";
|
|
130
130
|
var TIMED_OUT = "这次超时了,没有拿到结果。不要当成没查到,也不要马上用同样的参数再调一次。";
|
|
131
131
|
var SERVER_FAULT = "服务端这次出错了,不是没查到。稍后再试,不要换措辞重搜。";
|
|
132
|
+
var AUTH_INVALID = "这把密钥当前不能用了(未绑定或已失效)。请到插件配置页重新绑定,不要换措辞重搜。";
|
|
133
|
+
var BUSY_REMOTE = "服务端当前繁忙(限流),不是没查到。等一会儿再试,不要换措辞重搜。";
|
|
134
|
+
var EMPTY_RESULT = "服务端返回了空内容,这次没拿到结果。不是没查到,稍后再试或换个工具。";
|
|
132
135
|
var SERVER_PHASES = /* @__PURE__ */ new Set(["down", "http", "unreachable"]);
|
|
136
|
+
var AUTH_PHASES = /* @__PURE__ */ new Set(["invalid", "revoked"]);
|
|
137
|
+
var LOCKED_PHASES = /* @__PURE__ */ new Set(["locked"]);
|
|
133
138
|
function toolFailureText(known) {
|
|
134
139
|
if (known?.timedOut) return TIMED_OUT;
|
|
140
|
+
if (known && AUTH_PHASES.has(known.phase)) return AUTH_INVALID;
|
|
141
|
+
if (known && LOCKED_PHASES.has(known.phase)) return BUSY_REMOTE;
|
|
135
142
|
if (known && SERVER_PHASES.has(known.phase)) return SERVER_FAULT;
|
|
136
143
|
return MISS;
|
|
137
144
|
}
|
|
@@ -153,6 +160,7 @@ var MAX_PARAMS = 12;
|
|
|
153
160
|
var MAX_DESCRIPTION = 600;
|
|
154
161
|
var MAX_TIMEOUT_MS = 18e4;
|
|
155
162
|
var MAX_POLL_MS = 18e4;
|
|
163
|
+
var REGISTER_MARGIN_MS = 1e4;
|
|
156
164
|
var KINDS = /* @__PURE__ */ new Set(["read", "task", "write"]);
|
|
157
165
|
function isRecord(value) {
|
|
158
166
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -212,7 +220,9 @@ function readPoll(value) {
|
|
|
212
220
|
} catch {
|
|
213
221
|
return null;
|
|
214
222
|
}
|
|
215
|
-
|
|
223
|
+
const budget = MAX_TIMEOUT_MS - firstWaitMs - REGISTER_MARGIN_MS;
|
|
224
|
+
const bounded = Math.max(intervalMs, Math.min(waitMs, budget));
|
|
225
|
+
return { tool, idPattern, firstWaitMs, waitMs: bounded, intervalMs };
|
|
216
226
|
}
|
|
217
227
|
function registerTimeout(tool) {
|
|
218
228
|
if (tool.kind === "task" && tool.poll) {
|
|
@@ -346,9 +356,9 @@ function command(file, args) {
|
|
|
346
356
|
stdio: ["ignore", "pipe", "ignore"]
|
|
347
357
|
});
|
|
348
358
|
}
|
|
349
|
-
function readText(
|
|
359
|
+
function readText(path3) {
|
|
350
360
|
try {
|
|
351
|
-
return readFileSync(
|
|
361
|
+
return readFileSync(path3, "utf8").trim();
|
|
352
362
|
} catch {
|
|
353
363
|
return "";
|
|
354
364
|
}
|
|
@@ -377,8 +387,8 @@ function readMachineId() {
|
|
|
377
387
|
cachedMachineId = value;
|
|
378
388
|
return value;
|
|
379
389
|
}
|
|
380
|
-
function sha256(
|
|
381
|
-
return createHash("sha256").update(
|
|
390
|
+
function sha256(text3) {
|
|
391
|
+
return createHash("sha256").update(text3).digest("hex");
|
|
382
392
|
}
|
|
383
393
|
function stableFingerprint(installId, env) {
|
|
384
394
|
if (!env.machineId || env.machineId.length < 16) throw new Error("machine id unavailable");
|
|
@@ -458,11 +468,11 @@ async function postJson(fetchImpl, url, headers, body) {
|
|
|
458
468
|
|
|
459
469
|
// src/session/endpoint.ts
|
|
460
470
|
function checkEndpoint(raw) {
|
|
461
|
-
const
|
|
462
|
-
if (
|
|
471
|
+
const text3 = String(raw || "").trim();
|
|
472
|
+
if (text3 === "") return "请填写访问地址";
|
|
463
473
|
let url;
|
|
464
474
|
try {
|
|
465
|
-
url = new URL(
|
|
475
|
+
url = new URL(text3);
|
|
466
476
|
} catch {
|
|
467
477
|
return "地址不合法,需要一个完整的 http(s) 地址";
|
|
468
478
|
}
|
|
@@ -498,13 +508,13 @@ function createAccountActions(deps) {
|
|
|
498
508
|
"x-authinex-ds-version": version
|
|
499
509
|
};
|
|
500
510
|
}
|
|
501
|
-
async function postPersonal(
|
|
511
|
+
async function postPersonal(path3, body, replayed = false) {
|
|
502
512
|
const base = normalizeEndpoint(memory.endpoint);
|
|
503
513
|
if (!base || !memory.token) return { ok: false, status: 0, data: { message: PHRASES.unreachable } };
|
|
504
|
-
const res = await postJson(fetchImpl, `${base}${
|
|
514
|
+
const res = await postJson(fetchImpl, `${base}${path3}`, sessionHeaders(), body);
|
|
505
515
|
if (res.status === 401 && !replayed && await hasDeviceSecret()) {
|
|
506
516
|
const back = await signInSaved();
|
|
507
|
-
if (back) return postPersonal(
|
|
517
|
+
if (back) return postPersonal(path3, body, true);
|
|
508
518
|
}
|
|
509
519
|
return { ok: res.ok, status: res.status, data: res.data };
|
|
510
520
|
}
|
|
@@ -559,9 +569,9 @@ function createAccountActions(deps) {
|
|
|
559
569
|
async function legacyOnesOptions(issueTypes, project) {
|
|
560
570
|
const base = normalizeEndpoint(memory.endpoint);
|
|
561
571
|
if (!base || !memory.token) return { ok: false, message: PHRASES.unreachable };
|
|
562
|
-
const
|
|
572
|
+
const path3 = issueTypes ? `/api/auth/me/accounts/ones/issue-types?projectUuid=${encodeURIComponent(project.trim())}` : "/api/auth/me/accounts/ones/projects";
|
|
563
573
|
try {
|
|
564
|
-
const response = await fetchImpl(`${base}${
|
|
574
|
+
const response = await fetchImpl(`${base}${path3}`, {
|
|
565
575
|
method: issueTypes ? "GET" : "POST",
|
|
566
576
|
headers: {
|
|
567
577
|
authorization: `Bearer ${memory.token}`,
|
|
@@ -712,23 +722,25 @@ var TOOLS = {
|
|
|
712
722
|
ask_assistant: {
|
|
713
723
|
title: "问智能助手",
|
|
714
724
|
timeoutMs: 9e4,
|
|
715
|
-
description:
|
|
716
|
-
|
|
725
|
+
description: `把问题交给线上客服 Agent。后台执行,结果自动回到对话,不必调用查任务进度。
|
|
726
|
+
先试 search_kb / search_code。跨来源仍对不上再用它,并在 brief 写已知依据。不要传 deep。${DATA_NOT_INSTRUCTION}`,
|
|
717
727
|
parameters: {
|
|
718
728
|
question: { type: "string", required: true, description: "完整问句" },
|
|
719
|
-
version: { type: "string", description: "产品版本,可空" }
|
|
729
|
+
version: { type: "string", description: "产品版本,可空" },
|
|
730
|
+
brief: { type: "string", description: "已知依据、试过的检索、要补的部分。不要贴整段对话" }
|
|
720
731
|
}
|
|
721
732
|
},
|
|
722
733
|
locate_online: {
|
|
723
734
|
title: "线上源码定位",
|
|
724
735
|
timeoutMs: 7e4,
|
|
725
|
-
description:
|
|
736
|
+
description: `按版本读线上源码做只读定位。后台执行,结果自动回到对话,不必调用查任务进度。
|
|
726
737
|
结论按「根因 / 文件 / 证据 / 置信度 / 反证 / 过程」分块,引用时保留行号。
|
|
727
738
|
问「怎么配」「支持不支持」不要用它,用 search_kb 或 product_features。${DATA_NOT_INSTRUCTION}`,
|
|
728
739
|
parameters: {
|
|
729
740
|
question: { type: "string", required: true, description: "要定位的现象" },
|
|
730
741
|
version: { type: "string", description: "产品版本或分支" },
|
|
731
|
-
side: { type: "string", description: "frontend 或 backend,可空" }
|
|
742
|
+
side: { type: "string", description: "frontend 或 backend,可空" },
|
|
743
|
+
brief: { type: "string", description: "本机已查到的路径和单号。不要贴整段对话" }
|
|
732
744
|
}
|
|
733
745
|
},
|
|
734
746
|
task_status: {
|
|
@@ -864,10 +876,10 @@ function accessLine(tickets) {
|
|
|
864
876
|
var CITE_RULE = "没有真正检索过就不要写来源。工具返回没有 [S1] / [C1] 编号时,不要写「已引用」或「仅检出」。";
|
|
865
877
|
var SOURCE_HEAD = /^(?:#{1,6}\s*)?(?:已引用|仅检出)\s*$/;
|
|
866
878
|
var SOURCE_ITEM = /^(?:[-*+]\s|\d+[.)、]\s|>|\[[A-Z]\d+\])/;
|
|
867
|
-
function omitSourceSections(
|
|
879
|
+
function omitSourceSections(text3) {
|
|
868
880
|
const kept = [];
|
|
869
881
|
let skipping = false;
|
|
870
|
-
for (const line of
|
|
882
|
+
for (const line of text3.split("\n")) {
|
|
871
883
|
const trimmed = line.trim();
|
|
872
884
|
if (trimmed.startsWith("本返回带编号")) continue;
|
|
873
885
|
if (SOURCE_HEAD.test(trimmed)) {
|
|
@@ -910,24 +922,25 @@ function contextPatch(input) {
|
|
|
910
922
|
}
|
|
911
923
|
return patch;
|
|
912
924
|
}
|
|
913
|
-
var
|
|
925
|
+
var HOWTO = "用法:/ax-context 云枢 8.7 某客户 要问的问题,或 /ax-context 清空";
|
|
926
|
+
var USAGE = `没看懂。${HOWTO}`;
|
|
914
927
|
var QUESTION_MARKS = ["?", "?", "怎么", "怎样", "如何", "为啥", "为什么", "为何", "哪些", "哪个", "排查", "报错"];
|
|
915
928
|
function questionStartOf(tokens) {
|
|
916
929
|
return tokens.findIndex((token) => QUESTION_MARKS.some((mark) => token.includes(mark)));
|
|
917
930
|
}
|
|
918
931
|
function interpretCommand(raw, current) {
|
|
919
|
-
const
|
|
920
|
-
if (!
|
|
932
|
+
const text3 = raw.trim();
|
|
933
|
+
if (!text3) {
|
|
921
934
|
const line2 = formatWorkFields(current);
|
|
922
935
|
return {
|
|
923
936
|
kind: "success",
|
|
924
|
-
text: line2 ? `当前工作上下文:${line2}` : `还没有工作上下文。${
|
|
937
|
+
text: line2 ? `当前工作上下文:${line2}` : `还没有工作上下文。${HOWTO}`,
|
|
925
938
|
work: current,
|
|
926
939
|
question: ""
|
|
927
940
|
};
|
|
928
941
|
}
|
|
929
|
-
if (
|
|
930
|
-
const tokens =
|
|
942
|
+
if (text3 === "清空") return { kind: "success", text: "已清空工作上下文", work: EMPTY_WORK, question: "" };
|
|
943
|
+
const tokens = text3.split(/\s+/).filter(Boolean);
|
|
931
944
|
const kindToken = tokens[0] || "";
|
|
932
945
|
if (!Object.prototype.hasOwnProperty.call(ALIASES, kindToken) || !ALIASES[kindToken]) {
|
|
933
946
|
return { kind: "error", text: USAGE };
|
|
@@ -976,13 +989,19 @@ function createRouteHandler(deps) {
|
|
|
976
989
|
listSkills,
|
|
977
990
|
importSkill,
|
|
978
991
|
exportSkill,
|
|
979
|
-
installSkill
|
|
992
|
+
installSkill,
|
|
993
|
+
downloadUpgrade
|
|
980
994
|
} = deps;
|
|
981
|
-
async function handle(method,
|
|
995
|
+
async function handle(method, path3, body, headers, query = {}) {
|
|
996
|
+
if (method === "GET" && (path3 === "/authinex-ds/upgrade/template" || path3 === "/authinex-ds/upgrade/report")) {
|
|
997
|
+
const kind = path3.endsWith("/template") ? "template" : "report";
|
|
998
|
+
const file = await downloadUpgrade(kind, query);
|
|
999
|
+
return { status: file.status, body: { detail: file.text }, raw: file };
|
|
1000
|
+
}
|
|
982
1001
|
if (headers?.["x-authinex-ds"] !== "1") {
|
|
983
1002
|
return { status: 403, body: { detail: "forbidden" } };
|
|
984
1003
|
}
|
|
985
|
-
if (method === "GET" &&
|
|
1004
|
+
if (method === "GET" && path3 === "/authinex-ds/state") {
|
|
986
1005
|
if (!memory.token && memory.phase !== "binding") {
|
|
987
1006
|
const saved = await readSecret();
|
|
988
1007
|
if (secretReady(saved)) await restore();
|
|
@@ -990,37 +1009,37 @@ function createRouteHandler(deps) {
|
|
|
990
1009
|
await dispatch.refreshStatus();
|
|
991
1010
|
return { status: 200, body: snapshot() };
|
|
992
1011
|
}
|
|
993
|
-
if (method === "GET" &&
|
|
1012
|
+
if (method === "GET" && path3 === "/authinex-ds/context") {
|
|
994
1013
|
return { status: 200, body: dispatch.contextView() };
|
|
995
1014
|
}
|
|
996
|
-
if (method === "POST" &&
|
|
1015
|
+
if (method === "POST" && path3 === "/authinex-ds/context") {
|
|
997
1016
|
const saved = await dispatch.saveContext(body || {});
|
|
998
1017
|
return { status: saved.ok ? 200 : 400, body: { ...saved, state: snapshot() } };
|
|
999
1018
|
}
|
|
1000
|
-
if (method === "POST" &&
|
|
1019
|
+
if (method === "POST" && path3 === "/authinex-ds/bind") {
|
|
1001
1020
|
const result = await bind({ key: String(body?.key || ""), endpoint: body?.endpoint });
|
|
1002
1021
|
return { status: result.ok ? 200 : 400, body: { ...result.state, message: result.message || "" } };
|
|
1003
1022
|
}
|
|
1004
|
-
if (method === "POST" &&
|
|
1023
|
+
if (method === "POST" && path3 === "/authinex-ds/unbind") {
|
|
1005
1024
|
const result = await unbind();
|
|
1006
1025
|
return { status: 200, body: { ...result.state, message: "已解除绑定" } };
|
|
1007
1026
|
}
|
|
1008
|
-
if (
|
|
1027
|
+
if (path3 === "/authinex-ds/accounts" && method === "GET") {
|
|
1009
1028
|
return { status: 200, body: snapshot().accounts };
|
|
1010
1029
|
}
|
|
1011
|
-
if (
|
|
1030
|
+
if (path3 === "/authinex-ds/accounts" && method === "PATCH") {
|
|
1012
1031
|
const result = await saveAccount(String(body?.provider || ""), body?.form || {});
|
|
1013
1032
|
return { status: 200, body: result };
|
|
1014
1033
|
}
|
|
1015
|
-
if (
|
|
1034
|
+
if (path3 === "/authinex-ds/accounts/test" && method === "POST") {
|
|
1016
1035
|
const result = await testAccount(String(body?.provider || ""), body?.form || {});
|
|
1017
1036
|
return { status: 200, body: result };
|
|
1018
1037
|
}
|
|
1019
|
-
if (
|
|
1038
|
+
if (path3 === "/authinex-ds/accounts/enabled" && method === "POST") {
|
|
1020
1039
|
const result = await setAccountEnabled(String(body?.provider || ""), Boolean(body?.enabled));
|
|
1021
1040
|
return { status: result.ok ? 200 : 400, body: result };
|
|
1022
1041
|
}
|
|
1023
|
-
if (
|
|
1042
|
+
if (path3 === "/authinex-ds/accounts/options" && method === "POST") {
|
|
1024
1043
|
const result = await accountOptions(
|
|
1025
1044
|
String(body?.provider || ""),
|
|
1026
1045
|
String(body?.kind || ""),
|
|
@@ -1029,19 +1048,19 @@ function createRouteHandler(deps) {
|
|
|
1029
1048
|
);
|
|
1030
1049
|
return { status: 200, body: result };
|
|
1031
1050
|
}
|
|
1032
|
-
if (method === "POST" &&
|
|
1051
|
+
if (method === "POST" && path3 === "/authinex-ds/update/check") {
|
|
1033
1052
|
const result = await checkUpdate();
|
|
1034
1053
|
return { status: 200, body: { ...result.state, updateMessage: result.message || "" } };
|
|
1035
1054
|
}
|
|
1036
|
-
if (method === "POST" &&
|
|
1055
|
+
if (method === "POST" && path3 === "/authinex-ds/update/apply") {
|
|
1037
1056
|
const result = await applyUpdate();
|
|
1038
1057
|
return { status: result.ok ? 200 : 400, body: { ...result } };
|
|
1039
1058
|
}
|
|
1040
|
-
if (method === "POST" &&
|
|
1059
|
+
if (method === "POST" && path3 === "/authinex-ds/update/download") {
|
|
1041
1060
|
const result = await downloadUpdate();
|
|
1042
1061
|
return { status: result.ok ? 200 : 400, body: { ...result } };
|
|
1043
1062
|
}
|
|
1044
|
-
if (method === "POST" &&
|
|
1063
|
+
if (method === "POST" && path3 === "/authinex-ds/skills") {
|
|
1045
1064
|
const result = await listSkills({
|
|
1046
1065
|
q: String(body?.q || ""),
|
|
1047
1066
|
page: Number(body?.page || 1),
|
|
@@ -1050,7 +1069,7 @@ function createRouteHandler(deps) {
|
|
|
1050
1069
|
});
|
|
1051
1070
|
return { status: 200, body: result };
|
|
1052
1071
|
}
|
|
1053
|
-
if (method === "POST" &&
|
|
1072
|
+
if (method === "POST" && path3 === "/authinex-ds/skills/import") {
|
|
1054
1073
|
const result = await importSkill({
|
|
1055
1074
|
markdown: String(body?.markdown || ""),
|
|
1056
1075
|
name: String(body?.name || ""),
|
|
@@ -1058,11 +1077,11 @@ function createRouteHandler(deps) {
|
|
|
1058
1077
|
});
|
|
1059
1078
|
return { status: result.ok ? 200 : 400, body: result };
|
|
1060
1079
|
}
|
|
1061
|
-
if (method === "POST" &&
|
|
1080
|
+
if (method === "POST" && path3 === "/authinex-ds/skills/export") {
|
|
1062
1081
|
const result = await exportSkill(body?.id);
|
|
1063
1082
|
return { status: result.ok ? 200 : 400, body: result };
|
|
1064
1083
|
}
|
|
1065
|
-
if (method === "POST" &&
|
|
1084
|
+
if (method === "POST" && path3 === "/authinex-ds/skills/install") {
|
|
1066
1085
|
const result = await installSkill(body?.id);
|
|
1067
1086
|
return { status: result.ok ? 200 : 400, body: { ...result, state: snapshot() } };
|
|
1068
1087
|
}
|
|
@@ -1112,7 +1131,7 @@ function parseKey(raw) {
|
|
|
1112
1131
|
// src/tools/tool-run.ts
|
|
1113
1132
|
var RUNNING = /还在跑|queued|running/;
|
|
1114
1133
|
var TERMINAL = /* @__PURE__ */ new Set(["done", "failed", "timeout"]);
|
|
1115
|
-
var INDEX_WARMING = "
|
|
1134
|
+
var INDEX_WARMING = "检索超时了,多半是查询改写在排队,不是索引在预热,也不是没查到。稍后再试;手里有类名时用 find_code。";
|
|
1116
1135
|
function isTimeoutError(error) {
|
|
1117
1136
|
const name2 = "name" in error && typeof error.name === "string" ? error.name : "";
|
|
1118
1137
|
if (name2 === "TimeoutError") return true;
|
|
@@ -1210,13 +1229,13 @@ function createSessionActions(deps) {
|
|
|
1210
1229
|
function secretReady(secret) {
|
|
1211
1230
|
return Boolean(secret?.privateJwk && secret.deviceId && secret.installId && secret.endpoint);
|
|
1212
1231
|
}
|
|
1213
|
-
function secretText(
|
|
1232
|
+
function secretText(record2) {
|
|
1214
1233
|
return JSON.stringify({
|
|
1215
|
-
installId:
|
|
1216
|
-
deviceId:
|
|
1217
|
-
endpoint: normalizeEndpoint(
|
|
1218
|
-
privateJwk:
|
|
1219
|
-
publicJwk:
|
|
1234
|
+
installId: record2.installId,
|
|
1235
|
+
deviceId: record2.deviceId || "",
|
|
1236
|
+
endpoint: normalizeEndpoint(record2.endpoint),
|
|
1237
|
+
privateJwk: record2.privateJwk,
|
|
1238
|
+
publicJwk: record2.publicJwk
|
|
1220
1239
|
});
|
|
1221
1240
|
}
|
|
1222
1241
|
async function readSecret() {
|
|
@@ -1239,12 +1258,12 @@ function createSessionActions(deps) {
|
|
|
1239
1258
|
}
|
|
1240
1259
|
return fromFile;
|
|
1241
1260
|
}
|
|
1242
|
-
async function writeSecret(
|
|
1243
|
-
const
|
|
1244
|
-
await credentials.set(credentialRef2,
|
|
1261
|
+
async function writeSecret(record2) {
|
|
1262
|
+
const text3 = secretText(record2);
|
|
1263
|
+
await credentials.set(credentialRef2, text3);
|
|
1245
1264
|
if (deviceFile) {
|
|
1246
1265
|
try {
|
|
1247
|
-
await deviceFile.write(
|
|
1266
|
+
await deviceFile.write(text3);
|
|
1248
1267
|
} catch {
|
|
1249
1268
|
}
|
|
1250
1269
|
}
|
|
@@ -1286,7 +1305,7 @@ function createSessionActions(deps) {
|
|
|
1286
1305
|
}
|
|
1287
1306
|
return snapshot();
|
|
1288
1307
|
}
|
|
1289
|
-
async function request(
|
|
1308
|
+
async function request(path3, init = {}) {
|
|
1290
1309
|
const method = init.method || "POST";
|
|
1291
1310
|
const timeout = init.timeout ?? 3e4;
|
|
1292
1311
|
const session = Boolean(init.session);
|
|
@@ -1297,7 +1316,7 @@ function createSessionActions(deps) {
|
|
|
1297
1316
|
"x-authinex-ds-version": version
|
|
1298
1317
|
};
|
|
1299
1318
|
if (memory.token) headers.authorization = `Bearer ${memory.token}`;
|
|
1300
|
-
const run = () => fetchImpl(`${base}${
|
|
1319
|
+
const run = () => fetchImpl(`${base}${path3}`, {
|
|
1301
1320
|
method,
|
|
1302
1321
|
headers,
|
|
1303
1322
|
body: init.body === void 0 ? void 0 : JSON.stringify(init.body),
|
|
@@ -1347,7 +1366,7 @@ function createSessionActions(deps) {
|
|
|
1347
1366
|
const known = phaseError(failure);
|
|
1348
1367
|
if (known && !init.replayed && known.phase === "invalid" && await hasDeviceSecret()) {
|
|
1349
1368
|
const back = await signInSaved();
|
|
1350
|
-
if (back) return request(
|
|
1369
|
+
if (back) return request(path3, { ...init, replayed: true });
|
|
1351
1370
|
throw new PhaseError("session", "unreachable");
|
|
1352
1371
|
}
|
|
1353
1372
|
if (known) throw failure;
|
|
@@ -1523,8 +1542,8 @@ function createSessionActions(deps) {
|
|
|
1523
1542
|
}
|
|
1524
1543
|
}
|
|
1525
1544
|
const shown = String(memory.phase);
|
|
1526
|
-
const
|
|
1527
|
-
const message = shown === "unreachable" && memory.endpoint ? `${
|
|
1545
|
+
const text3 = phrase(shown);
|
|
1546
|
+
const message = shown === "unreachable" && memory.endpoint ? `${text3}(${memory.endpoint})` : text3;
|
|
1528
1547
|
return { ok: false, message, state: snapshot() };
|
|
1529
1548
|
}
|
|
1530
1549
|
}
|
|
@@ -1550,6 +1569,21 @@ function createSessionActions(deps) {
|
|
|
1550
1569
|
}
|
|
1551
1570
|
return { ok: true, state: snapshot() };
|
|
1552
1571
|
}
|
|
1572
|
+
async function openEvents(path3, signal) {
|
|
1573
|
+
const base = normalizeEndpoint(memory.endpoint);
|
|
1574
|
+
if (!base || !memory.token) return null;
|
|
1575
|
+
const response = await fetchImpl(`${base}${path3}`, {
|
|
1576
|
+
method: "GET",
|
|
1577
|
+
headers: {
|
|
1578
|
+
accept: "text/event-stream",
|
|
1579
|
+
authorization: `Bearer ${memory.token}`,
|
|
1580
|
+
"x-authinex-ds-version": version
|
|
1581
|
+
},
|
|
1582
|
+
signal
|
|
1583
|
+
});
|
|
1584
|
+
if (!response.ok || !response.body) return null;
|
|
1585
|
+
return response.body;
|
|
1586
|
+
}
|
|
1553
1587
|
return {
|
|
1554
1588
|
readSecret,
|
|
1555
1589
|
writeSecret,
|
|
@@ -1557,6 +1591,7 @@ function createSessionActions(deps) {
|
|
|
1557
1591
|
stopResume,
|
|
1558
1592
|
fail,
|
|
1559
1593
|
request,
|
|
1594
|
+
openEvents,
|
|
1560
1595
|
applySession,
|
|
1561
1596
|
loadAccounts,
|
|
1562
1597
|
hasDeviceSecret,
|
|
@@ -1569,6 +1604,163 @@ function createSessionActions(deps) {
|
|
|
1569
1604
|
};
|
|
1570
1605
|
}
|
|
1571
1606
|
|
|
1607
|
+
// src/session/controller-upgrade.ts
|
|
1608
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
1609
|
+
|
|
1610
|
+
// src/tools/upgrade-links.ts
|
|
1611
|
+
var SERVER_TEMPLATE_PATH = "/api/auth/ds-plugin/upgrade/evaluate/template";
|
|
1612
|
+
var SERVER_REPORT_PATH = "/api/auth/ds-plugin/upgrade/evaluate/report";
|
|
1613
|
+
var REPORT_LINK = /\/api\/auth\/ds-plugin\/upgrade\/evaluate\/report\?taskId=(eval:)?([0-9a-fA-F]{16})/g;
|
|
1614
|
+
function rewriteUpgradeLinks(text3, urls) {
|
|
1615
|
+
if (!text3) return text3;
|
|
1616
|
+
const withTemplate = text3.split(SERVER_TEMPLATE_PATH).join(`[下载模板](${urls.templateUrl()})`);
|
|
1617
|
+
return withTemplate.replace(REPORT_LINK, (_match, _prefix, id) => `[打开报告](${urls.reportUrl(`eval:${id}`)})`);
|
|
1618
|
+
}
|
|
1619
|
+
function record(value) {
|
|
1620
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1621
|
+
}
|
|
1622
|
+
function text2(value) {
|
|
1623
|
+
return typeof value === "string" ? value.trim() : "";
|
|
1624
|
+
}
|
|
1625
|
+
function num(value) {
|
|
1626
|
+
const parsed = Number(value);
|
|
1627
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
1628
|
+
}
|
|
1629
|
+
function list(value) {
|
|
1630
|
+
return Array.isArray(value) ? value : [];
|
|
1631
|
+
}
|
|
1632
|
+
function days(value) {
|
|
1633
|
+
const n = num(value);
|
|
1634
|
+
return Number.isInteger(n) ? String(n) : n.toFixed(1);
|
|
1635
|
+
}
|
|
1636
|
+
function lines(items, render) {
|
|
1637
|
+
return items.map(render).map((line) => line.trim()).filter(Boolean);
|
|
1638
|
+
}
|
|
1639
|
+
function renderReportMarkdown(payload) {
|
|
1640
|
+
const data = record(record(payload).data);
|
|
1641
|
+
const result = record(data.result);
|
|
1642
|
+
const report = record(result.report);
|
|
1643
|
+
const form = record(result.form);
|
|
1644
|
+
const taskId = text2(data.taskId) || "eval";
|
|
1645
|
+
const out = [`# 云枢升级评估报告`, ""];
|
|
1646
|
+
const versions = [text2(form.currentVersion), text2(form.targetVersion)].filter(Boolean);
|
|
1647
|
+
out.push(`- 任务:${taskId}`);
|
|
1648
|
+
if (versions.length === 2) out.push(`- 版本:${versions[0]} → ${versions[1]}`);
|
|
1649
|
+
if (text2(form.dbType)) out.push(`- 数据库:${text2(form.dbType)} ${text2(form.dbVersion)}`.trim());
|
|
1650
|
+
out.push("");
|
|
1651
|
+
const summary = text2(report.executiveSummary) || text2(report.summary);
|
|
1652
|
+
if (summary) out.push("## 结论", "", summary, "");
|
|
1653
|
+
const baseline = record(report.baselineEstimate);
|
|
1654
|
+
const ai = record(report.aiEstimate);
|
|
1655
|
+
const confidence = text2(report.confidence) || text2(baseline.confidence) || "low";
|
|
1656
|
+
out.push("## 工作量", "");
|
|
1657
|
+
out.push(`- 基线:${days(baseline.totalMin)}–${days(baseline.totalMax)} 人天(置信度 ${confidence})`);
|
|
1658
|
+
if (num(ai.totalMax) > 0) {
|
|
1659
|
+
out.push(`- AI 复核:${days(ai.totalMin)}–${days(ai.totalMax)} 人天`);
|
|
1660
|
+
} else {
|
|
1661
|
+
out.push("- AI 复核:没有通过证据复核的人天,以上基线只作数量级参考");
|
|
1662
|
+
}
|
|
1663
|
+
const modules = list(ai.modules).map(record).filter((item) => text2(item.name));
|
|
1664
|
+
if (modules.length) {
|
|
1665
|
+
out.push("", "| 模块 | 人天 | 依据 |", "| --- | ---: | --- |");
|
|
1666
|
+
for (const item of modules) {
|
|
1667
|
+
const reason = text2(item.reason).replace(/\|/g, "/").slice(0, 120);
|
|
1668
|
+
out.push(`| ${text2(item.name)} | ${days(item.minDays)}–${days(item.maxDays)} | ${reason} |`);
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
out.push("");
|
|
1672
|
+
const counts = record(report.riskCounts);
|
|
1673
|
+
const risks = list(report.risks).map(record);
|
|
1674
|
+
out.push("## 风险", "");
|
|
1675
|
+
out.push(`高 ${num(counts.high)} / 中 ${num(counts.medium)} / 低 ${num(counts.low)}`, "");
|
|
1676
|
+
for (const risk of risks) {
|
|
1677
|
+
const title = text2(risk.title);
|
|
1678
|
+
if (!title) continue;
|
|
1679
|
+
out.push(`### [${text2(risk.level) || "medium"}] ${title}`);
|
|
1680
|
+
const detail = text2(risk.detail);
|
|
1681
|
+
const impact = text2(risk.impact);
|
|
1682
|
+
const mitigation = text2(risk.mitigation);
|
|
1683
|
+
if (detail) out.push("", detail);
|
|
1684
|
+
if (impact) out.push("", `- 影响:${impact}`);
|
|
1685
|
+
if (mitigation) out.push(`- 措施:${mitigation}`);
|
|
1686
|
+
out.push("");
|
|
1687
|
+
}
|
|
1688
|
+
const drivers = lines(list(report.keyDrivers), (item) => `- ${text2(item)}`);
|
|
1689
|
+
if (drivers.length) out.push("## 影响工作量的关键事实", "", ...drivers, "");
|
|
1690
|
+
const assumptions = lines(list(report.assumptions), (item) => `- ${text2(item)}`);
|
|
1691
|
+
if (assumptions.length) out.push("## 仍需确认", "", ...assumptions, "");
|
|
1692
|
+
const actions = lines(list(report.nextActions), (item) => `- ${text2(item)}`);
|
|
1693
|
+
if (actions.length) out.push("## 下一步", "", ...actions, "");
|
|
1694
|
+
return `${out.join("\n").trimEnd()}
|
|
1695
|
+
`;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
// src/session/controller-upgrade.ts
|
|
1699
|
+
var TEMPLATE_NAME = "cloudpivot-upgrade-evaluate-material-template.md";
|
|
1700
|
+
var TASK_ID = /^eval:[0-9a-fA-F]{16}$/;
|
|
1701
|
+
function plain(status, message, filename = "upgrade-evaluate.txt") {
|
|
1702
|
+
return { status, contentType: "text/plain; charset=utf-8", filename, text: `${message}
|
|
1703
|
+
` };
|
|
1704
|
+
}
|
|
1705
|
+
function createUpgradeDownloads(deps) {
|
|
1706
|
+
const token = randomUUID2().replace(/-/g, "");
|
|
1707
|
+
const base = () => deps.origin().replace(/\/+$/, "");
|
|
1708
|
+
const templateUrl = () => `${base()}/authinex-ds/upgrade/template?t=${token}`;
|
|
1709
|
+
const reportUrl = (taskId) => `${base()}/authinex-ds/upgrade/report?t=${token}&taskId=${encodeURIComponent(taskId)}`;
|
|
1710
|
+
async function pull(path3) {
|
|
1711
|
+
const base2 = normalizeEndpoint(deps.memory.endpoint);
|
|
1712
|
+
if (!base2) return { status: 503, text: "还没绑定服务地址" };
|
|
1713
|
+
const headers = { "x-authinex-ds-version": deps.version };
|
|
1714
|
+
if (deps.memory.token) headers.authorization = `Bearer ${deps.memory.token}`;
|
|
1715
|
+
try {
|
|
1716
|
+
const response = await deps.fetchImpl(`${base2}${path3}`, { method: "GET", headers, timeout: 3e4 });
|
|
1717
|
+
return { status: response.status, text: await response.text() };
|
|
1718
|
+
} catch {
|
|
1719
|
+
return { status: 503, text: "服务不可达" };
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
async function download(kind, query) {
|
|
1723
|
+
if (query.t !== token) return plain(403, "这个下载链接已失效。回插件页重新取一次。");
|
|
1724
|
+
if (kind === "template") {
|
|
1725
|
+
const pulled = await pull(SERVER_TEMPLATE_PATH);
|
|
1726
|
+
if (pulled.status !== 200 || !pulled.text.trim()) {
|
|
1727
|
+
return plain(
|
|
1728
|
+
pulled.status === 200 ? 502 : pulled.status,
|
|
1729
|
+
pulled.status === 403 ? "当前角色不能做升级评估。" : "模板没取到,稍后再试。"
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
return {
|
|
1733
|
+
status: 200,
|
|
1734
|
+
contentType: "text/markdown; charset=utf-8",
|
|
1735
|
+
filename: TEMPLATE_NAME,
|
|
1736
|
+
text: pulled.text
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
if (kind === "report") {
|
|
1740
|
+
const taskId = query.taskId || "";
|
|
1741
|
+
if (!TASK_ID.test(taskId)) return plain(400, "任务号不对,形如 eval: 加 16 位任务号。");
|
|
1742
|
+
const pulled = await pull(`${SERVER_REPORT_PATH}?taskId=${encodeURIComponent(taskId)}`);
|
|
1743
|
+
if (pulled.status !== 200) {
|
|
1744
|
+
return plain(pulled.status === 404 ? 404 : pulled.status, "这份报告不在这台设备上,或已经过期。");
|
|
1745
|
+
}
|
|
1746
|
+
let payload = null;
|
|
1747
|
+
try {
|
|
1748
|
+
payload = JSON.parse(pulled.text);
|
|
1749
|
+
} catch {
|
|
1750
|
+
return plain(502, "报告格式不对,回对话里看摘要。");
|
|
1751
|
+
}
|
|
1752
|
+
return {
|
|
1753
|
+
status: 200,
|
|
1754
|
+
contentType: "text/markdown; charset=utf-8",
|
|
1755
|
+
filename: `${taskId.replace(":", "-")}.md`,
|
|
1756
|
+
text: renderReportMarkdown(payload)
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
return plain(404, "没有这个下载项。");
|
|
1760
|
+
}
|
|
1761
|
+
return { templateUrl, reportUrl, download };
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1572
1764
|
// src/skills/skills-fs.ts
|
|
1573
1765
|
import { mkdir as mkdir2, readdir, writeFile as writeFile2 } from "node:fs/promises";
|
|
1574
1766
|
import { homedir as homedir2 } from "node:os";
|
|
@@ -1718,9 +1910,9 @@ function createSkillActions(deps) {
|
|
|
1718
1910
|
if (!validSlug(slug)) {
|
|
1719
1911
|
return { ok: false, message: "技能目录名不合法,已放弃这次安装", path: "", slug: "" };
|
|
1720
1912
|
}
|
|
1721
|
-
const
|
|
1913
|
+
const path3 = await writeSkill2(slug, exported.markdown);
|
|
1722
1914
|
await refreshInstalled();
|
|
1723
|
-
return { ok: true, message: "已装到本机技能目录,新会话生效", path:
|
|
1915
|
+
return { ok: true, message: "已装到本机技能目录,新会话生效", path: path3, slug };
|
|
1724
1916
|
} catch {
|
|
1725
1917
|
return { ok: false, message: "写到本机技能目录失败", path: "", slug: "" };
|
|
1726
1918
|
} finally {
|
|
@@ -1894,11 +2086,11 @@ function piece(pathName, name2 = "", mime = "", data = "") {
|
|
|
1894
2086
|
return { path: pathName, name: name2, mime, data };
|
|
1895
2087
|
}
|
|
1896
2088
|
function pieceFromText(value) {
|
|
1897
|
-
const
|
|
1898
|
-
if (!
|
|
1899
|
-
if (
|
|
1900
|
-
const quoted =
|
|
1901
|
-
const candidate = (quoted ? quoted[1] :
|
|
2089
|
+
const text3 = value.trim();
|
|
2090
|
+
if (!text3) return null;
|
|
2091
|
+
if (text3.startsWith("data:")) return piece("", "", "", text3);
|
|
2092
|
+
const quoted = text3.match(/["'](\/[^"']+)["']/);
|
|
2093
|
+
const candidate = (quoted ? quoted[1] : text3.replace(/^["']|["']$/g, "")).trim();
|
|
1902
2094
|
if (!path.isAbsolute(candidate)) return null;
|
|
1903
2095
|
return piece(candidate);
|
|
1904
2096
|
}
|
|
@@ -1920,18 +2112,18 @@ function parseAttachmentInput(raw) {
|
|
|
1920
2112
|
});
|
|
1921
2113
|
}
|
|
1922
2114
|
if (typeof raw !== "string") return [];
|
|
1923
|
-
const
|
|
1924
|
-
if (!
|
|
1925
|
-
if (
|
|
2115
|
+
const text3 = raw.trim();
|
|
2116
|
+
if (!text3) return [];
|
|
2117
|
+
if (text3.startsWith("[") || text3.startsWith("{")) {
|
|
1926
2118
|
try {
|
|
1927
|
-
const parsed = JSON.parse(
|
|
2119
|
+
const parsed = JSON.parse(text3);
|
|
1928
2120
|
if (Array.isArray(parsed) || parsed && typeof parsed === "object") {
|
|
1929
2121
|
return parseAttachmentInput(Array.isArray(parsed) ? parsed : [parsed]);
|
|
1930
2122
|
}
|
|
1931
2123
|
} catch {
|
|
1932
2124
|
}
|
|
1933
2125
|
}
|
|
1934
|
-
return
|
|
2126
|
+
return text3.split(/\r?\n/).flatMap((line) => {
|
|
1935
2127
|
const parsed = pieceFromText(line);
|
|
1936
2128
|
return parsed ? [parsed] : [];
|
|
1937
2129
|
});
|
|
@@ -2099,13 +2291,94 @@ ${args.problem}`;
|
|
|
2099
2291
|
return { proceed: true };
|
|
2100
2292
|
}
|
|
2101
2293
|
|
|
2294
|
+
// src/tools/upgrade-files.ts
|
|
2295
|
+
import { readFile as readFile3, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
2296
|
+
import path2 from "node:path";
|
|
2297
|
+
var MAX_FILES2 = 20;
|
|
2298
|
+
var MAX_BYTES2 = 12 * 1024 * 1024;
|
|
2299
|
+
var MAX_TOTAL = MAX_BYTES2 * 3;
|
|
2300
|
+
var ALLOWED = [".md", ".markdown", ".txt", ".docx", ".pdf", ".xml", ".json", ".yml", ".yaml"];
|
|
2301
|
+
function suffix(name2) {
|
|
2302
|
+
const dot = name2.lastIndexOf(".");
|
|
2303
|
+
return dot > 0 ? name2.slice(dot).toLowerCase() : "";
|
|
2304
|
+
}
|
|
2305
|
+
function decodeLength2(data) {
|
|
2306
|
+
const comma = data.indexOf(",");
|
|
2307
|
+
const body = data.startsWith("data:") && comma >= 0 ? data.slice(comma + 1) : data;
|
|
2308
|
+
const compact = body.replace(/\s+/g, "");
|
|
2309
|
+
return Buffer.from(compact, "base64").length;
|
|
2310
|
+
}
|
|
2311
|
+
async function insideRoots(real, roots) {
|
|
2312
|
+
for (const root of roots) {
|
|
2313
|
+
let base = "";
|
|
2314
|
+
try {
|
|
2315
|
+
base = await realpath2(root);
|
|
2316
|
+
} catch {
|
|
2317
|
+
continue;
|
|
2318
|
+
}
|
|
2319
|
+
if (real === base || real.startsWith(base + path2.sep)) return true;
|
|
2320
|
+
}
|
|
2321
|
+
return false;
|
|
2322
|
+
}
|
|
2323
|
+
function fromData(name2, data) {
|
|
2324
|
+
const bytes = decodeLength2(data);
|
|
2325
|
+
if (bytes <= 0) throw new Error("empty");
|
|
2326
|
+
return { name: name2, data: data.replace(/^data:[^;,]+(;base64)?,/, "").replace(/\s+/g, ""), bytes };
|
|
2327
|
+
}
|
|
2328
|
+
async function fromPath(item, roots) {
|
|
2329
|
+
const real = await realpath2(item.path);
|
|
2330
|
+
const info = await stat2(real);
|
|
2331
|
+
if (!info.isFile() || info.size <= 0) throw new Error("skip");
|
|
2332
|
+
if (!await insideRoots(real, roots)) throw new Error("skip");
|
|
2333
|
+
const body = await readFile3(real);
|
|
2334
|
+
return { name: item.name || path2.basename(real), data: body.toString("base64"), bytes: body.length };
|
|
2335
|
+
}
|
|
2336
|
+
async function readUpgradeFiles(raw, roots = attachmentRoots()) {
|
|
2337
|
+
const pieces = parseAttachmentInput(raw).slice(0, MAX_FILES2 + 4);
|
|
2338
|
+
if (!pieces.length) return { payload: "", count: 0, names: [], note: "" };
|
|
2339
|
+
const files = [];
|
|
2340
|
+
const names = [];
|
|
2341
|
+
const skipped = [];
|
|
2342
|
+
let total = 0;
|
|
2343
|
+
for (const item of pieces) {
|
|
2344
|
+
const label = item.name || (item.path ? path2.basename(item.path) : "附件");
|
|
2345
|
+
if (files.length >= MAX_FILES2) {
|
|
2346
|
+
skipped.push(label);
|
|
2347
|
+
continue;
|
|
2348
|
+
}
|
|
2349
|
+
if (!ALLOWED.includes(suffix(label))) {
|
|
2350
|
+
skipped.push(label);
|
|
2351
|
+
continue;
|
|
2352
|
+
}
|
|
2353
|
+
try {
|
|
2354
|
+
const file = item.data ? fromData(label, item.data) : await fromPath(item, roots);
|
|
2355
|
+
if (file.bytes > MAX_BYTES2 || total + file.bytes > MAX_TOTAL) {
|
|
2356
|
+
skipped.push(file.name);
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
total += file.bytes;
|
|
2360
|
+
files.push({ name: file.name, data: file.data });
|
|
2361
|
+
names.push(file.name);
|
|
2362
|
+
} catch {
|
|
2363
|
+
skipped.push(label);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
const note = skipped.length ? `有 ${skipped.length} 个附件没带上(${skipped.slice(0, 3).join("、")})。评估只收 md/txt/docx/pdf/xml/json/yml,单个 12MB、合计 36MB,且必须是对话附件目录里的文件。` : "";
|
|
2367
|
+
return {
|
|
2368
|
+
payload: files.length ? JSON.stringify(files) : "",
|
|
2369
|
+
count: files.length,
|
|
2370
|
+
names,
|
|
2371
|
+
note
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2102
2375
|
// src/skills/skills-source.ts
|
|
2103
2376
|
var SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2104
2377
|
var ONLINE_SKILL_RANK = 350;
|
|
2105
2378
|
var SKILL_PROVIDER = "authinex";
|
|
2106
2379
|
function descriptionOf(item) {
|
|
2107
|
-
const
|
|
2108
|
-
return
|
|
2380
|
+
const text3 = String(item.description || item.title || "").trim().slice(0, 200);
|
|
2381
|
+
return text3;
|
|
2109
2382
|
}
|
|
2110
2383
|
function listedSkills(items) {
|
|
2111
2384
|
if (!items) return [];
|
|
@@ -2146,6 +2419,125 @@ function loadedSkill(item, invocation) {
|
|
|
2146
2419
|
};
|
|
2147
2420
|
}
|
|
2148
2421
|
|
|
2422
|
+
// src/tools/delegate-job.ts
|
|
2423
|
+
var BACKOFF_MS = [2e3, 5e3, 1e4, 1e4, 1e4];
|
|
2424
|
+
var TASK_ID2 = /\b(?:ask|dive|eval):[A-Za-z0-9_-]+/;
|
|
2425
|
+
function onlineTaskId(text3) {
|
|
2426
|
+
return TASK_ID2.exec(text3)?.[0] || "";
|
|
2427
|
+
}
|
|
2428
|
+
function delegateLabel(name2, question) {
|
|
2429
|
+
const who = name2 === "locate_online" ? "编码 Agent" : name2 === "upgrade_evaluate" ? "升级评估" : "客服 Agent";
|
|
2430
|
+
const title = question.replace(/\s+/g, " ").trim().slice(0, 40);
|
|
2431
|
+
return title ? `${who}:${title}` : who;
|
|
2432
|
+
}
|
|
2433
|
+
function clipBytes(text3, maxBytes) {
|
|
2434
|
+
if (Buffer.byteLength(text3, "utf8") <= maxBytes) return text3;
|
|
2435
|
+
let out = "";
|
|
2436
|
+
let used = 0;
|
|
2437
|
+
for (const char of text3) {
|
|
2438
|
+
const size = Buffer.byteLength(char, "utf8");
|
|
2439
|
+
if (used + size > maxBytes - 3) break;
|
|
2440
|
+
out += char;
|
|
2441
|
+
used += size;
|
|
2442
|
+
}
|
|
2443
|
+
return `${out}…`;
|
|
2444
|
+
}
|
|
2445
|
+
var ANSWER_BYTES = 2900;
|
|
2446
|
+
function renderDone(frame) {
|
|
2447
|
+
const lines2 = ["线上任务已完成。"];
|
|
2448
|
+
if (frame.answer) lines2.push(clipBytes(frame.answer, ANSWER_BYTES));
|
|
2449
|
+
const cites = frame.citations || [];
|
|
2450
|
+
if (cites.length) {
|
|
2451
|
+
lines2.push("出处:");
|
|
2452
|
+
for (const item of cites.slice(0, 12)) {
|
|
2453
|
+
const bits = [item.ref, item.docId ? `doc_id=${item.docId}` : "", item.path || ""].filter(Boolean);
|
|
2454
|
+
if (bits.length) lines2.push(`- ${bits.join(" ")}`);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
for (const gap of frame.gaps || []) lines2.push(`没查到:${gap}`);
|
|
2458
|
+
lines2.push("用 search_kb 或 search_code 复核出处。两边不一致时并列给用户,不要自行取舍。");
|
|
2459
|
+
return lines2.join("\n");
|
|
2460
|
+
}
|
|
2461
|
+
async function followTask(input) {
|
|
2462
|
+
let last = "";
|
|
2463
|
+
for (let attempt = 0; attempt <= BACKOFF_MS.length; attempt += 1) {
|
|
2464
|
+
if (input.signal.aborted) {
|
|
2465
|
+
await input.cancelTask(input.taskId).catch(() => void 0);
|
|
2466
|
+
return { status: "killed", detail: "已取消", result: `线上任务 ${input.taskId} 已取消。` };
|
|
2467
|
+
}
|
|
2468
|
+
try {
|
|
2469
|
+
const body = await input.openEvents(input.taskId, input.signal);
|
|
2470
|
+
if (!body) throw new Error("no stream");
|
|
2471
|
+
const done = await readFrames(body, (frame) => {
|
|
2472
|
+
if (frame.type === "progress") input.job.updateProgress(String(frame.progress || frame.status || "进行中"));
|
|
2473
|
+
if (frame.answer) {
|
|
2474
|
+
const answer = input.rewrite ? input.rewrite(frame.answer) : frame.answer;
|
|
2475
|
+
last = renderDone({ ...frame, answer });
|
|
2476
|
+
}
|
|
2477
|
+
});
|
|
2478
|
+
if (done) {
|
|
2479
|
+
if (last) input.job.append(last);
|
|
2480
|
+
return { status: "completed", result: last || `线上任务 ${input.taskId} 已结束。` };
|
|
2481
|
+
}
|
|
2482
|
+
} catch {
|
|
2483
|
+
if (input.signal.aborted) {
|
|
2484
|
+
await input.cancelTask(input.taskId).catch(() => void 0);
|
|
2485
|
+
return { status: "killed", detail: "已取消", result: `线上任务 ${input.taskId} 已取消。` };
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
if (attempt === BACKOFF_MS.length) break;
|
|
2489
|
+
await input.sleep(BACKOFF_MS[attempt]);
|
|
2490
|
+
}
|
|
2491
|
+
const fallback = `线上任务还在跑(${input.taskId})。用查任务进度取结果。`;
|
|
2492
|
+
return { status: "failed", detail: "事件流中断", result: last || fallback };
|
|
2493
|
+
}
|
|
2494
|
+
function startDelegate(input) {
|
|
2495
|
+
const abort = new AbortController();
|
|
2496
|
+
return input.jobs.start({
|
|
2497
|
+
kind: "authinex",
|
|
2498
|
+
label: delegateLabel(input.name, input.question),
|
|
2499
|
+
owner: input.call.agentId || void 0,
|
|
2500
|
+
toolCall: input.call.callId && input.call.rootCallId ? { callId: input.call.callId, rootCallId: input.call.rootCallId } : void 0,
|
|
2501
|
+
outputLimitBytes: 4096,
|
|
2502
|
+
run: (job) => ({
|
|
2503
|
+
cancel: () => abort.abort(),
|
|
2504
|
+
done: followTask({
|
|
2505
|
+
taskId: input.taskId,
|
|
2506
|
+
job,
|
|
2507
|
+
openEvents: input.openEvents,
|
|
2508
|
+
cancelTask: input.cancelTask,
|
|
2509
|
+
sleep: input.sleep,
|
|
2510
|
+
signal: abort.signal,
|
|
2511
|
+
rewrite: input.rewrite
|
|
2512
|
+
})
|
|
2513
|
+
})
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
async function readFrames(body, onFrame) {
|
|
2517
|
+
const decoder = new TextDecoder();
|
|
2518
|
+
let buffer = "";
|
|
2519
|
+
for await (const chunk of body) {
|
|
2520
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
2521
|
+
const parts = buffer.split("\n\n");
|
|
2522
|
+
buffer = parts.pop() || "";
|
|
2523
|
+
for (const part of parts) {
|
|
2524
|
+
for (const line of part.split("\n")) {
|
|
2525
|
+
if (!line.startsWith("data:")) continue;
|
|
2526
|
+
let frame;
|
|
2527
|
+
try {
|
|
2528
|
+
frame = JSON.parse(line.slice(5).trim());
|
|
2529
|
+
} catch {
|
|
2530
|
+
continue;
|
|
2531
|
+
}
|
|
2532
|
+
if (!frame || typeof frame !== "object") continue;
|
|
2533
|
+
onFrame(frame);
|
|
2534
|
+
if (frame.type === "done") return true;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
return false;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2149
2541
|
// src/tools/tool-dispatch.ts
|
|
2150
2542
|
var CITABLE = /* @__PURE__ */ new Set([
|
|
2151
2543
|
"search_kb",
|
|
@@ -2154,7 +2546,9 @@ var CITABLE = /* @__PURE__ */ new Set([
|
|
|
2154
2546
|
"fix_patterns",
|
|
2155
2547
|
"ask_assistant",
|
|
2156
2548
|
"locate_online",
|
|
2157
|
-
"task_status"
|
|
2549
|
+
"task_status",
|
|
2550
|
+
"upgrade_evaluate",
|
|
2551
|
+
"upgrade_evaluate_template"
|
|
2158
2552
|
]);
|
|
2159
2553
|
function textOf2(data) {
|
|
2160
2554
|
if (Array.isArray(data?.content)) {
|
|
@@ -2303,9 +2697,11 @@ ${accepted.tools.map((tool) => tool.name).join("\n")}`;
|
|
|
2303
2697
|
});
|
|
2304
2698
|
const status = data.structuredContent?.status;
|
|
2305
2699
|
const failed = Boolean(data.isError);
|
|
2306
|
-
const
|
|
2700
|
+
const shown = failed || CITABLE.has(name2) ? textOf2(data) : omitSourceSections(textOf2(data));
|
|
2701
|
+
const text3 = failed ? shown : rewriteUpgradeLinks(shown, deps.upgradeUrls);
|
|
2702
|
+
if (!failed && !text3.trim()) return { text: EMPTY_RESULT, isError: true, taskId: "", structuredStatus: "" };
|
|
2307
2703
|
return {
|
|
2308
|
-
text:
|
|
2704
|
+
text: text3,
|
|
2309
2705
|
isError: failed,
|
|
2310
2706
|
taskId: data.taskId || "",
|
|
2311
2707
|
structuredStatus: typeof status === "string" ? status : ""
|
|
@@ -2335,6 +2731,32 @@ ${accepted.tools.map((tool) => tool.name).join("\n")}`;
|
|
|
2335
2731
|
status: (taskId) => toolCall(poll.tool, { taskId }, statusTimeout)
|
|
2336
2732
|
});
|
|
2337
2733
|
}
|
|
2734
|
+
async function prepareUpgrade(args) {
|
|
2735
|
+
const outbound = { ...args };
|
|
2736
|
+
if ((textArg(args, "action") || "start") === "cancel") return { outbound };
|
|
2737
|
+
const prepared = await readUpgradeFiles(args.attachments);
|
|
2738
|
+
if (attachmentCount(args.attachments) > 0 && prepared.count === 0) {
|
|
2739
|
+
return { error: { text: prepared.note || "附件没读到,评估没有启动。", isError: true } };
|
|
2740
|
+
}
|
|
2741
|
+
if (prepared.count) outbound.attachments = prepared.payload;
|
|
2742
|
+
else delete outbound.attachments;
|
|
2743
|
+
const form = args.form;
|
|
2744
|
+
if (form && typeof form === "object") outbound.form = JSON.stringify(form);
|
|
2745
|
+
if (!outbound.attachments && !textArg(outbound, "form")) {
|
|
2746
|
+
return { error: { text: "要有填好的模板或项目特征 JSON 才能评估。先下载模板。", isError: true } };
|
|
2747
|
+
}
|
|
2748
|
+
return { outbound };
|
|
2749
|
+
}
|
|
2750
|
+
async function runUpgradeEvaluate(args, entry, timeout) {
|
|
2751
|
+
const action = textArg(args, "action") || "start";
|
|
2752
|
+
state.busy += 1;
|
|
2753
|
+
try {
|
|
2754
|
+
if (action === "cancel") return await toolCall("upgrade_evaluate", args, timeout);
|
|
2755
|
+
return entry?.kind === "task" && entry.poll ? await runTask(entry, args) : await toolCall("upgrade_evaluate", args, timeout);
|
|
2756
|
+
} finally {
|
|
2757
|
+
state.busy -= 1;
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2338
2760
|
async function locate(args) {
|
|
2339
2761
|
const first = await toolCall("locate_online", args, 15e3);
|
|
2340
2762
|
return pollTask({
|
|
@@ -2402,6 +2824,48 @@ ${prepared.note}` };
|
|
|
2402
2824
|
state.busy -= 1;
|
|
2403
2825
|
}
|
|
2404
2826
|
}
|
|
2827
|
+
function agentIdOf(agent) {
|
|
2828
|
+
if (!agent || typeof agent !== "object" || !("id" in agent)) return "";
|
|
2829
|
+
const id = agent.id;
|
|
2830
|
+
return typeof id === "string" ? id : "";
|
|
2831
|
+
}
|
|
2832
|
+
function jobsOf() {
|
|
2833
|
+
const jobs = deps.jobs;
|
|
2834
|
+
return jobs && typeof jobs.start === "function" ? jobs : void 0;
|
|
2835
|
+
}
|
|
2836
|
+
async function delegate(name2, args, ctx) {
|
|
2837
|
+
const jobs = jobsOf();
|
|
2838
|
+
if (!jobs || !deps.openEvents) return null;
|
|
2839
|
+
if (name2 === "upgrade_evaluate" && textArg(args, "action") === "cancel") return null;
|
|
2840
|
+
const first = await toolCall(name2, args, 2e4);
|
|
2841
|
+
const taskId = first.taskId || onlineTaskId(first.text);
|
|
2842
|
+
if (first.isError || !taskId) return first;
|
|
2843
|
+
const who = name2 === "locate_online" ? "编码 Agent" : name2 === "upgrade_evaluate" ? "升级评估" : "客服 Agent";
|
|
2844
|
+
let jobId = "";
|
|
2845
|
+
try {
|
|
2846
|
+
jobId = startDelegate({
|
|
2847
|
+
jobs,
|
|
2848
|
+
name: name2,
|
|
2849
|
+
question: textArg(args, "question"),
|
|
2850
|
+
taskId,
|
|
2851
|
+
call: {
|
|
2852
|
+
agentId: agentIdOf(ctx.agent),
|
|
2853
|
+
callId: ctx.callId,
|
|
2854
|
+
rootCallId: ctx.rootCallId
|
|
2855
|
+
},
|
|
2856
|
+
openEvents: (id, signal) => deps.openEvents(`/api/auth/ds-plugin/tasks/${encodeURIComponent(id)}/events`, signal),
|
|
2857
|
+
cancelTask: async (id) => {
|
|
2858
|
+
await deps.request(`/api/auth/ds-plugin/tasks/${encodeURIComponent(id)}/cancel`, { session: true, body: { name: "cancel", arguments: {} } });
|
|
2859
|
+
},
|
|
2860
|
+
sleep: deps.sleep,
|
|
2861
|
+
// 升级评估的摘要带报告地址,服务端只认设备密钥,改成本机能点的链接。
|
|
2862
|
+
rewrite: (text3) => rewriteUpgradeLinks(text3, deps.upgradeUrls)
|
|
2863
|
+
});
|
|
2864
|
+
} catch {
|
|
2865
|
+
return first;
|
|
2866
|
+
}
|
|
2867
|
+
return { text: `已交给线上${who}(任务 ${jobId},线上 ${taskId})。完成后会自动回到对话,可以先继续问别的。`, taskId, isError: false };
|
|
2868
|
+
}
|
|
2405
2869
|
async function callTool(name2, args = {}, ctx = {}) {
|
|
2406
2870
|
const entry = activeTools()?.find((tool) => tool.name === name2);
|
|
2407
2871
|
const legacy = !state.catalogJson && isToolName(name2);
|
|
@@ -2409,8 +2873,23 @@ ${prepared.note}` };
|
|
|
2409
2873
|
return { text: "当前没有这个工具。", isError: true };
|
|
2410
2874
|
}
|
|
2411
2875
|
const payload = applyContextArgs(name2, args);
|
|
2876
|
+
if (name2 === "ask_assistant" && fieldBlank(payload, "chatId")) {
|
|
2877
|
+
const id = agentIdOf(ctx.agent);
|
|
2878
|
+
if (id) payload.chatId = `ds-${id}`.slice(0, 80);
|
|
2879
|
+
}
|
|
2880
|
+
let upgradeArgs = null;
|
|
2881
|
+
if (name2 === "upgrade_evaluate") {
|
|
2882
|
+
const prepared = await prepareUpgrade(payload);
|
|
2883
|
+
if ("error" in prepared) return prepared.error;
|
|
2884
|
+
upgradeArgs = prepared.outbound;
|
|
2885
|
+
}
|
|
2886
|
+
if (name2 === "ask_assistant" || name2 === "locate_online" || name2 === "upgrade_evaluate") {
|
|
2887
|
+
const handed = await delegate(name2, upgradeArgs ?? payload, ctx);
|
|
2888
|
+
if (handed) return handed;
|
|
2889
|
+
}
|
|
2412
2890
|
if (name2 === "create_ticket") return runTicket(payload, ctx, entry?.timeoutMs || TOOLS.create_ticket.timeoutMs);
|
|
2413
2891
|
if (name2 === "submit_experience") return runExperience(payload, ctx, entry?.timeoutMs || 3e4);
|
|
2892
|
+
if (name2 === "upgrade_evaluate") return runUpgradeEvaluate(upgradeArgs ?? payload, entry, entry?.timeoutMs || 15e3);
|
|
2414
2893
|
state.busy += 1;
|
|
2415
2894
|
try {
|
|
2416
2895
|
if (!entry && name2 === "locate_online") return await locate(payload);
|
|
@@ -2564,7 +3043,7 @@ ${prepared.note}` };
|
|
|
2564
3043
|
}
|
|
2565
3044
|
|
|
2566
3045
|
// src/session/controller.ts
|
|
2567
|
-
var VERSION = true ? "0.3.
|
|
3046
|
+
var VERSION = true ? "0.3.11" : "0.1.0";
|
|
2568
3047
|
var CREDENTIAL_REF = "AUTHINEX_DS_DEVICE";
|
|
2569
3048
|
var CONTEXT_CREDENTIAL_REF = "AUTHINEX_DS_CONTEXT";
|
|
2570
3049
|
function defaultMachineFingerprint() {
|
|
@@ -2701,6 +3180,12 @@ function createController(options) {
|
|
|
2701
3180
|
getDispatch: () => dispatch,
|
|
2702
3181
|
refreshInstalled: () => refreshInstalled()
|
|
2703
3182
|
});
|
|
3183
|
+
const downloads = createUpgradeDownloads({
|
|
3184
|
+
memory,
|
|
3185
|
+
version,
|
|
3186
|
+
fetchImpl,
|
|
3187
|
+
origin: () => options.origin?.() || ""
|
|
3188
|
+
});
|
|
2704
3189
|
dispatch = createToolDispatch({
|
|
2705
3190
|
state: memory,
|
|
2706
3191
|
version,
|
|
@@ -2709,6 +3194,9 @@ function createController(options) {
|
|
|
2709
3194
|
workStore: options.workStore,
|
|
2710
3195
|
cancelled,
|
|
2711
3196
|
request: session.request,
|
|
3197
|
+
jobs: options.jobs,
|
|
3198
|
+
openEvents: session.openEvents,
|
|
3199
|
+
upgradeUrls: { templateUrl: downloads.templateUrl, reportUrl: downloads.reportUrl },
|
|
2712
3200
|
verified,
|
|
2713
3201
|
fail: session.fail,
|
|
2714
3202
|
classify(error) {
|
|
@@ -2765,6 +3253,7 @@ function createController(options) {
|
|
|
2765
3253
|
restore,
|
|
2766
3254
|
dispatch,
|
|
2767
3255
|
snapshot,
|
|
3256
|
+
downloadUpgrade: downloads.download,
|
|
2768
3257
|
bind,
|
|
2769
3258
|
unbind,
|
|
2770
3259
|
saveAccount,
|
|
@@ -2838,7 +3327,9 @@ var PATHS = [
|
|
|
2838
3327
|
"/authinex-ds/skills/import",
|
|
2839
3328
|
"/authinex-ds/skills/export",
|
|
2840
3329
|
"/authinex-ds/skills/install",
|
|
2841
|
-
"/authinex-ds/context"
|
|
3330
|
+
"/authinex-ds/context",
|
|
3331
|
+
"/authinex-ds/upgrade/template",
|
|
3332
|
+
"/authinex-ds/upgrade/report"
|
|
2842
3333
|
];
|
|
2843
3334
|
function headerMap(req) {
|
|
2844
3335
|
const headers = {};
|
|
@@ -2863,6 +3354,15 @@ function readBody(req) {
|
|
|
2863
3354
|
req.on("error", reject);
|
|
2864
3355
|
});
|
|
2865
3356
|
}
|
|
3357
|
+
function sendFile(res, status, file) {
|
|
3358
|
+
const name2 = file.filename.replace(/["\\\r\n]/g, "") || "download.md";
|
|
3359
|
+
res.writeHead(status, {
|
|
3360
|
+
"content-type": file.contentType,
|
|
3361
|
+
"content-disposition": `attachment; filename="${name2}"`,
|
|
3362
|
+
"cache-control": "no-store"
|
|
3363
|
+
});
|
|
3364
|
+
res.end(file.text);
|
|
3365
|
+
}
|
|
2866
3366
|
function send(res, status, body) {
|
|
2867
3367
|
res.writeHead(status, {
|
|
2868
3368
|
"content-type": "application/json; charset=utf-8",
|
|
@@ -2888,6 +3388,13 @@ function apply(ctx) {
|
|
|
2888
3388
|
};
|
|
2889
3389
|
const controller = createController({
|
|
2890
3390
|
clientKind: detectClientKind(),
|
|
3391
|
+
origin: () => {
|
|
3392
|
+
try {
|
|
3393
|
+
return ctx.webServer.getOrigin?.() || "";
|
|
3394
|
+
} catch {
|
|
3395
|
+
return "";
|
|
3396
|
+
}
|
|
3397
|
+
},
|
|
2891
3398
|
// 更新走 DeepSeek 自己的安装器:它会改 profile 的 package.json、重算组合并重新加载。
|
|
2892
3399
|
install: async (spec) => {
|
|
2893
3400
|
const service = manager();
|
|
@@ -2911,16 +3418,27 @@ function apply(ctx) {
|
|
|
2911
3418
|
restartRequired: result?.application === "restart-required" || result?.restartRequired === true
|
|
2912
3419
|
};
|
|
2913
3420
|
},
|
|
2914
|
-
fetch: (url, init) =>
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
3421
|
+
fetch: async (url, init) => {
|
|
3422
|
+
const response = await fetch(url, {
|
|
3423
|
+
method: init.method,
|
|
3424
|
+
headers: init.headers,
|
|
3425
|
+
body: init.body,
|
|
3426
|
+
signal: init.signal ?? AbortSignal.timeout(init.timeout || 3e4)
|
|
3427
|
+
});
|
|
3428
|
+
return {
|
|
3429
|
+
status: response.status,
|
|
3430
|
+
ok: response.ok,
|
|
3431
|
+
headers: { get: (name2) => response.headers.get(name2) },
|
|
3432
|
+
text: () => response.text(),
|
|
3433
|
+
arrayBuffer: () => response.arrayBuffer(),
|
|
3434
|
+
body: response.body
|
|
3435
|
+
};
|
|
3436
|
+
},
|
|
2920
3437
|
// 技能只落 DSH 自己的技能目录,不进用户工作区、不碰仓库。
|
|
2921
3438
|
writeSkill,
|
|
2922
3439
|
listInstalled,
|
|
2923
3440
|
deviceFile: defaultDeviceFile(),
|
|
3441
|
+
jobs: ctx.get?.("jobs"),
|
|
2924
3442
|
credentials: {
|
|
2925
3443
|
resolve: () => ctx.credentials.resolve(ref),
|
|
2926
3444
|
set: (_ref, value) => ctx.credentials.set(ref, value),
|
|
@@ -2963,7 +3481,9 @@ function apply(ctx) {
|
|
|
2963
3481
|
const result = await controller.callTool(spec.name, args, {
|
|
2964
3482
|
ask: (request) => ctx.userQuestions.ask(request),
|
|
2965
3483
|
agent: exec?.agent,
|
|
2966
|
-
signal: exec?.signal
|
|
3484
|
+
signal: exec?.signal,
|
|
3485
|
+
callId: exec?.callId,
|
|
3486
|
+
rootCallId: exec?.rootCallId
|
|
2967
3487
|
});
|
|
2968
3488
|
return publishToolResult(result);
|
|
2969
3489
|
}
|
|
@@ -2974,10 +3494,10 @@ function apply(ctx) {
|
|
|
2974
3494
|
disposed = true;
|
|
2975
3495
|
for (const dispose of disposers.splice(0)) dispose();
|
|
2976
3496
|
}, "authinex-ds: tools");
|
|
2977
|
-
for (const
|
|
3497
|
+
for (const path3 of PATHS) {
|
|
2978
3498
|
ctx.effect(() => ctx.webServer.register({
|
|
2979
3499
|
kind: "exact",
|
|
2980
|
-
path:
|
|
3500
|
+
path: path3,
|
|
2981
3501
|
handler: async (req, res) => {
|
|
2982
3502
|
const rejection = ctx.connection?.requestRejection?.(req);
|
|
2983
3503
|
if (rejection !== void 0) {
|
|
@@ -2994,9 +3514,12 @@ function apply(ctx) {
|
|
|
2994
3514
|
return;
|
|
2995
3515
|
}
|
|
2996
3516
|
}
|
|
2997
|
-
const
|
|
3517
|
+
const query = {};
|
|
3518
|
+
const rawQuery = String(req.url || "").split("?")[1] || "";
|
|
3519
|
+
for (const [key, value] of new URLSearchParams(rawQuery)) query[key] = value;
|
|
3520
|
+
const result = await controller.handle(method, path3, body, headerMap(req), query);
|
|
2998
3521
|
const payload = result.body;
|
|
2999
|
-
if (
|
|
3522
|
+
if (path3 === "/authinex-ds/bind" || path3 === "/authinex-ds/unbind" || path3 === "/authinex-ds/accounts") {
|
|
3000
3523
|
try {
|
|
3001
3524
|
registerTools();
|
|
3002
3525
|
} catch (error) {
|
|
@@ -3009,9 +3532,13 @@ function apply(ctx) {
|
|
|
3009
3532
|
console.error("authinex-ds: 工具注册失败", error);
|
|
3010
3533
|
}
|
|
3011
3534
|
}
|
|
3535
|
+
if (result.raw) {
|
|
3536
|
+
sendFile(res, result.status, result.raw);
|
|
3537
|
+
return;
|
|
3538
|
+
}
|
|
3012
3539
|
send(res, result.status, payload);
|
|
3013
3540
|
}
|
|
3014
|
-
}), `authinex-ds: ${
|
|
3541
|
+
}), `authinex-ds: ${path3}`);
|
|
3015
3542
|
}
|
|
3016
3543
|
void controller.restore().then(() => registerTools());
|
|
3017
3544
|
}
|