@authinex/dsh-plugin 0.3.7 → 0.3.9

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/lib/index.js CHANGED
@@ -79,13 +79,41 @@ function attachOptionalHosts(ctx, bridge) {
79
79
  const service = commands;
80
80
  keep(ctx, "authinex-ds: command", () => service.register({
81
81
  name: "ax-context",
82
- description: "设置当前工作上下文(产品线、版本、客户)",
83
- input: { hint: "云枢 8.7 某客户,或「清空」" },
82
+ description: "设置当前工作上下文(产品线、版本、客户),句尾可以直接带要问的问题",
83
+ input: { hint: "云枢 8.7 某客户 要问的问题,或「清空」" },
84
84
  handler: (invocation) => bridge.runContextCommand(invocation.rawInput)
85
85
  }));
86
86
  }
87
87
  }
88
88
 
89
+ // src/device-file.ts
90
+ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
91
+ import { homedir } from "node:os";
92
+ import { dirname, join } from "node:path";
93
+ function deviceFileAt(path2) {
94
+ return {
95
+ async read() {
96
+ try {
97
+ const text2 = await readFile(path2, "utf8");
98
+ return text2.trim() ? text2 : void 0;
99
+ } catch {
100
+ return void 0;
101
+ }
102
+ },
103
+ async write(value) {
104
+ await mkdir(dirname(path2), { recursive: true, mode: 448 });
105
+ await writeFile(path2, value, { mode: 384 });
106
+ await chmod(path2, 384);
107
+ },
108
+ async clear() {
109
+ await rm(path2, { force: true });
110
+ }
111
+ };
112
+ }
113
+ function defaultDeviceFile() {
114
+ return deviceFileAt(join(homedir(), ".dsh", "authinex-ds-device.json"));
115
+ }
116
+
89
117
  // src/phrases.ts
90
118
  var PHRASES = {
91
119
  unbound: "填写访问地址和密钥完成绑定",
@@ -308,9 +336,9 @@ function command(file, args) {
308
336
  stdio: ["ignore", "pipe", "ignore"]
309
337
  });
310
338
  }
311
- function readText(path) {
339
+ function readText(path2) {
312
340
  try {
313
- return readFileSync(path, "utf8").trim();
341
+ return readFileSync(path2, "utf8").trim();
314
342
  } catch {
315
343
  return "";
316
344
  }
@@ -346,6 +374,10 @@ function stableFingerprint(installId, env) {
346
374
  if (!env.machineId || env.machineId.length < 16) throw new Error("machine id unavailable");
347
375
  return sha256([env.platform, env.arch, env.machineId, installId].join("\n"));
348
376
  }
377
+ function machineFingerprint(env) {
378
+ if (!env.machineId || env.machineId.length < 16) throw new Error("machine id unavailable");
379
+ return sha256([env.platform, env.arch, env.machineId].join("\n"));
380
+ }
349
381
  function legacyFingerprint(installId, env) {
350
382
  return sha256([env.platform, env.arch, env.hostname, installId].join("\n"));
351
383
  }
@@ -359,11 +391,64 @@ function currentFingerprints(installId) {
359
391
  }
360
392
 
361
393
  // src/controller.ts
362
- import { mkdtemp, writeFile as writeFile2 } from "node:fs/promises";
394
+ import { mkdtemp, writeFile as writeFile3 } from "node:fs/promises";
363
395
  import { tmpdir } from "node:os";
364
- import { join as join2 } from "node:path";
396
+ import { join as join3 } from "node:path";
365
397
  import { arch as arch2, hostname as hostname2, platform as platform2 } from "node:os";
366
398
 
399
+ // src/account-wire.ts
400
+ var SETTING_KEYS = [
401
+ "defaultProjectUuid",
402
+ "defaultProjectName",
403
+ "defaultIssueTypeId",
404
+ "defaultIssueTypeName",
405
+ "planIssueTypeId",
406
+ "planIssueTypeName",
407
+ "engineCode",
408
+ "schemaCode",
409
+ "authMode",
410
+ "isTenant"
411
+ ];
412
+ function accountPatch(form) {
413
+ const settings = {};
414
+ for (const key of SETTING_KEYS) {
415
+ if (!Object.prototype.hasOwnProperty.call(form, key)) continue;
416
+ const value = form[key];
417
+ if (typeof value !== "string") continue;
418
+ settings[key] = value.trim();
419
+ }
420
+ const body = { settings };
421
+ for (const key of ["baseUrl", "username", "teamUuid"]) {
422
+ if (typeof form[key] === "string") body[key] = form[key].trim();
423
+ }
424
+ if (typeof form.token === "string" && form.token.trim()) body.token = form.token.trim();
425
+ return body;
426
+ }
427
+ function textOf(data, fallback) {
428
+ const message = typeof data.message === "string" ? data.message.trim() : "";
429
+ if (message) return message;
430
+ const detail = typeof data.detail === "string" ? data.detail.trim() : "";
431
+ if (detail) return detail;
432
+ return fallback;
433
+ }
434
+ async function postJson(fetchImpl, url, headers, body) {
435
+ const response = await fetchImpl(url, {
436
+ method: "POST",
437
+ headers,
438
+ body: JSON.stringify(body),
439
+ timeout: 3e4
440
+ });
441
+ const raw = await response.text();
442
+ let data = {};
443
+ try {
444
+ const parsed = raw ? JSON.parse(raw) : {};
445
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) data = parsed;
446
+ } catch {
447
+ data = {};
448
+ }
449
+ return { ok: response.ok, status: response.status, data };
450
+ }
451
+
367
452
  // src/endpoint.ts
368
453
  function checkEndpoint(raw) {
369
454
  const text2 = String(raw || "").trim();
@@ -431,23 +516,23 @@ function parseKey(raw) {
431
516
  }
432
517
 
433
518
  // src/skills-fs.ts
434
- import { mkdir, readdir, writeFile } from "node:fs/promises";
435
- import { homedir } from "node:os";
436
- import { join } from "node:path";
519
+ import { mkdir as mkdir2, readdir, writeFile as writeFile2 } from "node:fs/promises";
520
+ import { homedir as homedir2 } from "node:os";
521
+ import { join as join2 } from "node:path";
437
522
  var SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
438
523
  function skillsRoot(home) {
439
- const root = String(home || "").trim() || String(process.env.DSH_HOME || "").trim() || join(homedir(), ".dsh");
440
- return join(root, "skills");
524
+ const root = String(home || "").trim() || String(process.env.DSH_HOME || "").trim() || join2(homedir2(), ".dsh");
525
+ return join2(root, "skills");
441
526
  }
442
527
  function validSlug(slug) {
443
528
  return SLUG.test(slug);
444
529
  }
445
530
  async function writeSkill(slug, markdown, home) {
446
531
  if (!validSlug(slug)) throw new Error("非法技能目录名");
447
- const dir = join(skillsRoot(home), slug);
448
- await mkdir(dir, { recursive: true });
449
- const file = join(dir, "SKILL.md");
450
- await writeFile(file, markdown, "utf8");
532
+ const dir = join2(skillsRoot(home), slug);
533
+ await mkdir2(dir, { recursive: true });
534
+ const file = join2(dir, "SKILL.md");
535
+ await writeFile2(file, markdown, "utf8");
451
536
  return file;
452
537
  }
453
538
  async function listInstalled(home) {
@@ -459,22 +544,183 @@ async function listInstalled(home) {
459
544
  }
460
545
  }
461
546
 
547
+ // src/ticket-files.ts
548
+ import { readFile as readFile2, realpath, stat } from "node:fs/promises";
549
+ import { homedir as homedir3 } from "node:os";
550
+ import path from "node:path";
551
+ var MAX_FILES = 6;
552
+ var MAX_BYTES = 4 * 1024 * 1024;
553
+ var MIME = {
554
+ ".png": "image/png",
555
+ ".jpg": "image/jpeg",
556
+ ".jpeg": "image/jpeg",
557
+ ".gif": "image/gif",
558
+ ".webp": "image/webp",
559
+ ".bmp": "image/bmp",
560
+ ".txt": "text/plain",
561
+ ".log": "text/plain",
562
+ ".json": "application/json",
563
+ ".har": "application/json",
564
+ ".pdf": "application/pdf",
565
+ ".zip": "application/zip"
566
+ };
567
+ function attachmentRoots(env = process.env, home = homedir3()) {
568
+ const base = env.DSH_HOME || path.join(home, ".dsh");
569
+ return [path.join(base, "attachments"), path.join(base, "cache", "attachments")];
570
+ }
571
+ function piece(pathName, name2 = "", mime = "", data = "") {
572
+ if (!pathName && !data) return null;
573
+ return { path: pathName, name: name2, mime, data };
574
+ }
575
+ function pieceFromText(value) {
576
+ const text2 = value.trim();
577
+ if (!text2) return null;
578
+ if (text2.startsWith("data:")) return piece("", "", "", text2);
579
+ const quoted = text2.match(/["'](\/[^"']+)["']/);
580
+ const candidate = (quoted ? quoted[1] : text2.replace(/^["']|["']$/g, "")).trim();
581
+ if (!path.isAbsolute(candidate)) return null;
582
+ return piece(candidate);
583
+ }
584
+ function pieceFromRow(value) {
585
+ if (typeof value === "string") return pieceFromText(value);
586
+ if (!value || typeof value !== "object") return null;
587
+ const row = value;
588
+ const data = typeof row.data === "string" ? row.data : "";
589
+ const filePath = typeof row.path === "string" ? row.path : typeof row.file === "string" ? row.file : "";
590
+ const name2 = typeof row.name === "string" ? row.name.trim() : "";
591
+ const mime = typeof row.mime === "string" ? row.mime.trim() : "";
592
+ return piece(filePath.trim(), name2, mime, data);
593
+ }
594
+ function parseAttachmentInput(raw) {
595
+ if (Array.isArray(raw)) {
596
+ return raw.flatMap((item) => {
597
+ const parsed = pieceFromRow(item);
598
+ return parsed ? [parsed] : [];
599
+ });
600
+ }
601
+ if (typeof raw !== "string") return [];
602
+ const text2 = raw.trim();
603
+ if (!text2) return [];
604
+ if (text2.startsWith("[") || text2.startsWith("{")) {
605
+ try {
606
+ const parsed = JSON.parse(text2);
607
+ if (Array.isArray(parsed) || parsed && typeof parsed === "object") {
608
+ return parseAttachmentInput(Array.isArray(parsed) ? parsed : [parsed]);
609
+ }
610
+ } catch {
611
+ }
612
+ }
613
+ return text2.split(/\r?\n/).flatMap((line) => {
614
+ const parsed = pieceFromText(line);
615
+ return parsed ? [parsed] : [];
616
+ });
617
+ }
618
+ function attachmentCount(raw) {
619
+ return parseAttachmentInput(raw).length;
620
+ }
621
+ function labelOf(piece2) {
622
+ if (piece2.name) return piece2.name;
623
+ if (piece2.path) return path.basename(piece2.path);
624
+ return "附件";
625
+ }
626
+ function mimeOfData(data) {
627
+ if (!data.startsWith("data:")) return "application/octet-stream";
628
+ const comma = data.indexOf(",");
629
+ const head = (comma >= 0 ? data.slice(5, comma) : data.slice(5)).split(";")[0].trim();
630
+ return head || "application/octet-stream";
631
+ }
632
+ function decodeLength(data) {
633
+ const comma = data.indexOf(",");
634
+ const body = data.startsWith("data:") && comma >= 0 ? data.slice(comma + 1) : data;
635
+ const compact = body.replace(/\s+/g, "");
636
+ return Buffer.from(compact, "base64").length;
637
+ }
638
+ async function allowed(real, roots) {
639
+ for (const root of roots) {
640
+ let base = "";
641
+ try {
642
+ base = await realpath(root);
643
+ } catch {
644
+ continue;
645
+ }
646
+ if (real === base || real.startsWith(base + path.sep)) return true;
647
+ }
648
+ return false;
649
+ }
650
+ async function fileFromPath(item, roots) {
651
+ const real = await realpath(item.path);
652
+ const info = await stat(real);
653
+ if (!info.isFile() || info.size <= 0 || info.size > MAX_BYTES) throw new Error("skip");
654
+ if (!await allowed(real, roots)) throw new Error("skip");
655
+ const body = await readFile2(real);
656
+ const ext = path.extname(real).toLowerCase();
657
+ return {
658
+ name: item.name || path.basename(real),
659
+ mime: item.mime || MIME[ext] || "application/octet-stream",
660
+ data: body.toString("base64"),
661
+ bytes: body.length
662
+ };
663
+ }
664
+ function fileFromData(item) {
665
+ const bytes = decodeLength(item.data);
666
+ if (bytes <= 0 || bytes > MAX_BYTES) throw new Error("skip");
667
+ return {
668
+ name: item.name || "image.png",
669
+ mime: item.mime || mimeOfData(item.data),
670
+ data: item.data,
671
+ bytes
672
+ };
673
+ }
674
+ async function readTicketFiles(raw, roots = attachmentRoots()) {
675
+ const pieces = parseAttachmentInput(raw).slice(0, MAX_FILES + 4);
676
+ if (!pieces.length) return { files: [], note: "" };
677
+ const files = [];
678
+ const skipped = [];
679
+ let total = 0;
680
+ for (const item of pieces) {
681
+ const name2 = labelOf(item);
682
+ if (files.length >= MAX_FILES) {
683
+ skipped.push(name2);
684
+ continue;
685
+ }
686
+ try {
687
+ const file = item.data ? fileFromData(item) : await fileFromPath(item, roots);
688
+ if (total + file.bytes > MAX_BYTES * MAX_FILES) {
689
+ skipped.push(file.name);
690
+ continue;
691
+ }
692
+ total += file.bytes;
693
+ files.push({ name: file.name, mime: file.mime, data: file.data });
694
+ } catch {
695
+ skipped.push(name2);
696
+ }
697
+ }
698
+ const note = skipped.length ? `有 ${skipped.length} 个附件没带上(${skipped.slice(0, 3).join("、")})。只接受对话附件目录里的文件。` : "";
699
+ return { files, note };
700
+ }
701
+
462
702
  // src/confirm-write.ts
463
703
  var EXPERIENCE_CANCELLED = "用户取消了提交经验,不要用同一草稿再提一次。";
464
704
  function oneLine(value, limit) {
465
705
  return value.replace(/\s+/g, " ").slice(0, limit);
466
706
  }
467
- async function confirmCreateTicket(args, ask, askContext, login, cancelled) {
707
+ async function confirmCreateTicket(args, ask, askContext, cancelled) {
708
+ const version = (args.version || "").trim();
709
+ const files = attachmentCount(args.attachments);
710
+ const marker = typeof args.attachments === "string" ? args.attachments : "";
468
711
  const draft = `${args.system}
469
712
  ${args.title}
470
- ${args.description}`;
713
+ ${args.description}
714
+ ${version}
715
+ ${marker.slice(0, 500)}`;
471
716
  if (cancelled.has(draft)) return { proceed: false, result: { text: CANCELLED, isError: false } };
472
717
  const target = ["ones", "h3yun", "pmo"].includes(args.system) ? args.system.toUpperCase() : args.system;
473
718
  const detail = [
474
719
  `系统 ${target}`,
720
+ version ? `发现版本 ${oneLine(version, 60)}` : "",
721
+ files ? `附件 ${files} 个` : "",
475
722
  `标题 ${args.title}`,
476
- `描述 ${oneLine(args.description, 100)}`,
477
- login ? `登录名 ${login}` : ""
723
+ `描述 ${oneLine(args.description, 100)}`
478
724
  ].filter(Boolean).join(" · ");
479
725
  let selected = "";
480
726
  try {
@@ -662,10 +908,12 @@ var TOOLS = {
662
908
  title: "查询工单",
663
909
  timeoutMs: 3e4,
664
910
  description: `按单号查 ONES、氚云或 PMO。没有可用账号的那一家不要编造单号。
911
+ 13 位氚云流水号查氚云原单;要查 ONES 上同步过去的缺陷,system 填 ones,或把流水号放进 h3yunSeqNo。不要把它当成 ONES 编号。
665
912
  已知单号才用它;按条件筛用 search_tickets。${DATA_NOT_INSTRUCTION}`,
666
913
  parameters: {
667
- number: { type: "string", description: "工单号" },
914
+ number: { type: "string", description: "工单号。13 位氚云流水号配 system=ones 时查 ONES 同步缺陷。" },
668
915
  system: { type: "string", description: "ones、h3yun 或 pmo" },
916
+ h3yunSeqNo: { type: "string", description: "氚云工单流水号。只查 ONES 上这个字段,不查氚云原单。" },
669
917
  keyword: { type: "string", description: "没有单号时按标题筛" }
670
918
  }
671
919
  },
@@ -736,14 +984,22 @@ var TOOLS = {
736
984
  },
737
985
  create_ticket: {
738
986
  title: "创建工单",
739
- timeoutMs: 6e4,
740
- description: `起草 ONES、氚云或 PMO 工单。必须先让用户在确认卡上点创建,取消后不要用同一草稿再提。${DATA_NOT_INSTRUCTION}`,
987
+ // 建单本身要跑一串 ONES 往返(登录、字段字典、add3);带附件还要再申请上传、
988
+ // 传完回写 <figure>,60 秒装不下,超时会让单子看起来"没建成",人就会重提。
989
+ timeoutMs: 18e4,
990
+ description: `起草 ONES、氚云或 PMO 工单。提交用的是已经保存的个人账号,不要向用户要邮箱、密码或 Token。用户说了版本就把原话放进 version,ONES 写入「发现版本-云枢」,没说就留空。用户附了图片或文件时,把对话里给出的只读路径放进 attachments,一行一个。必须先让用户在确认卡上点创建,取消后不要用同一草稿再提。${DATA_NOT_INSTRUCTION}`,
741
991
  parameters: {
742
992
  system: { type: "string", required: true, description: "ones、h3yun 或 pmo" },
743
993
  title: { type: "string", required: true, description: "标题" },
744
994
  description: { type: "string", required: true, description: "描述" },
745
- version: { type: "string", description: "产品版本" },
746
- customer: { type: "string", description: "客户" }
995
+ version: { type: "string", description: "ONES「发现版本-云枢」。用户说了才填,按原话,如 AI-Platform-v2.1。没说留空。" },
996
+ attachments: { type: "string", description: "对话里图片或文件的只读路径,一行一个。没有就留空,不要编路径。" },
997
+ customer: { type: "string", description: "客户。PMO 要客户全称。" },
998
+ ticketType: { type: "string", description: "氚云工单类型:需求、缺陷或咨询。没说留空。" },
999
+ serviceType: { type: "string", description: "PMO 服务单类型。没说留空,系统按问题单。" },
1000
+ product: { type: "string", description: "PMO 产品类型,如云枢。没说留空。" },
1001
+ issueType: { type: "string", description: "PMO 问题类型:产品问题、技术问题或其他问题。没说留空。" },
1002
+ priority: { type: "string", description: "优先级。PMO 用高、中、底。没说留空。" }
747
1003
  }
748
1004
  }
749
1005
  };
@@ -782,7 +1038,7 @@ var ALIASES = {
782
1038
  print: "print",
783
1039
  打印: "print"
784
1040
  };
785
- function labelOf(kind) {
1041
+ function labelOf2(kind) {
786
1042
  const found = PRODUCT_KINDS.find((item) => item.id === kind);
787
1043
  return found ? found.label : kind;
788
1044
  }
@@ -820,12 +1076,19 @@ function workIsEmpty(work) {
820
1076
  }
821
1077
  function formatWork(work) {
822
1078
  const parts = [];
823
- if (work.productKind) parts.push(`产品线 ${labelOf(work.productKind)}`);
1079
+ if (work.productKind) parts.push(`产品线 ${labelOf2(work.productKind)}`);
824
1080
  if (work.version) parts.push(`版本 ${work.version}`);
825
1081
  if (work.customer) parts.push(`客户 ${work.customer}`);
826
1082
  if (!parts.length) return "";
827
1083
  return `工作上下文:${parts.join(",")}`;
828
1084
  }
1085
+ function formatWorkFields(work) {
1086
+ const parts = [];
1087
+ if (work.productKind) parts.push(`产品线 ${labelOf2(work.productKind)}`);
1088
+ if (work.version) parts.push(`版本 ${work.version}`);
1089
+ if (work.customer) parts.push(`客户 ${work.customer}`);
1090
+ return parts.join(" / ");
1091
+ }
829
1092
  var SYSTEMS = [
830
1093
  { id: "ones", label: "ONES" },
831
1094
  { id: "h3yun", label: "氚云" },
@@ -890,28 +1153,45 @@ function contextPatch(input) {
890
1153
  }
891
1154
  return patch;
892
1155
  }
893
- var USAGE = "没看懂。用法:/ax-context 云枢 8.7 某客户,或 /ax-context 清空";
1156
+ var USAGE = "没看懂。用法:/ax-context 云枢 8.7 某客户 要问的问题,或 /ax-context 清空";
1157
+ var QUESTION_MARKS = ["?", "?", "怎么", "怎样", "如何", "为啥", "为什么", "为何", "哪些", "哪个", "排查", "报错"];
1158
+ function questionStartOf(tokens) {
1159
+ return tokens.findIndex((token) => QUESTION_MARKS.some((mark) => token.includes(mark)));
1160
+ }
894
1161
  function interpretCommand(raw, current) {
895
1162
  const text2 = raw.trim();
896
1163
  if (!text2) {
897
- const line = formatWork(current);
1164
+ const line2 = formatWorkFields(current);
898
1165
  return {
899
1166
  kind: "success",
900
- text: line ? `当前${line}` : "还没有工作上下文。用法:/ax-context 云枢 8.7 某客户,或 /ax-context 清空",
901
- work: current
1167
+ text: line2 ? `当前工作上下文:${line2}` : `还没有工作上下文。${USAGE}`,
1168
+ work: current,
1169
+ question: ""
902
1170
  };
903
1171
  }
904
- if (text2 === "清空") return { kind: "success", text: "已清空工作上下文", work: EMPTY_WORK };
1172
+ if (text2 === "清空") return { kind: "success", text: "已清空工作上下文", work: EMPTY_WORK, question: "" };
905
1173
  const tokens = text2.split(/\s+/).filter(Boolean);
906
1174
  const kindToken = tokens[0] || "";
907
1175
  if (!Object.prototype.hasOwnProperty.call(ALIASES, kindToken) || !ALIASES[kindToken]) {
908
1176
  return { kind: "error", text: USAGE };
909
1177
  }
910
1178
  const version = tokens[1] || "";
911
- const customer = tokens.slice(2).join(" ");
1179
+ const rest = tokens.slice(2);
1180
+ const questionAt = questionStartOf(rest);
1181
+ const customerTokens = questionAt < 0 ? rest : rest.slice(0, questionAt);
1182
+ const questionTokens = questionAt < 0 ? [] : rest.slice(questionAt);
1183
+ const customer = customerTokens.join(" ");
1184
+ const question = questionTokens.join(" ");
912
1185
  const parsed = normalizeWork({ productKind: kindToken, version, customer });
913
1186
  if (!parsed.ok) return { kind: "error", text: parsed.message };
914
- return { kind: "success", text: `已设置${formatWork(parsed.value)}`, work: parsed.value };
1187
+ const line = formatWorkFields(parsed.value);
1188
+ let note = "";
1189
+ if (question) {
1190
+ note = `问题「${question}」这次没有发出去:/ax-context 只设置上下文,把问题直接发出来,就会带着上面的上下文回答。`;
1191
+ }
1192
+ const text22 = note ? `已设置:${line}
1193
+ ${note}` : `已设置:${line}`;
1194
+ return { kind: "success", text: text22, work: parsed.value, question };
915
1195
  }
916
1196
 
917
1197
  // src/tool-dispatch.ts
@@ -924,7 +1204,7 @@ var CITABLE = /* @__PURE__ */ new Set([
924
1204
  "locate_online",
925
1205
  "task_status"
926
1206
  ]);
927
- function textOf(data) {
1207
+ function textOf2(data) {
928
1208
  if (Array.isArray(data?.content)) {
929
1209
  return data.content.map((item) => item?.text || "").join("\n");
930
1210
  }
@@ -1071,7 +1351,7 @@ ${accepted.tools.map((tool) => tool.name).join("\n")}`;
1071
1351
  });
1072
1352
  const status = data.structuredContent?.status;
1073
1353
  const failed = Boolean(data.isError);
1074
- const text2 = failed || CITABLE.has(name2) ? textOf(data) : omitSourceSections(textOf(data));
1354
+ const text2 = failed || CITABLE.has(name2) ? textOf2(data) : omitSourceSections(textOf2(data));
1075
1355
  return {
1076
1356
  text: text2,
1077
1357
  isError: failed,
@@ -1121,16 +1401,31 @@ ${accepted.tools.map((tool) => tool.name).join("\n")}`;
1121
1401
  }
1122
1402
  async function runTicket(args, ctx, timeout) {
1123
1403
  const decision = await confirmCreateTicket(
1124
- { system: textArg(args, "system"), title: textArg(args, "title"), description: textArg(args, "description") },
1404
+ {
1405
+ system: textArg(args, "system"),
1406
+ title: textArg(args, "title"),
1407
+ description: textArg(args, "description"),
1408
+ version: textArg(args, "version"),
1409
+ attachments: args.attachments
1410
+ },
1125
1411
  ctx.ask,
1126
1412
  askContextOf(ctx),
1127
- state.accounts?.[textArg(args, "system")]?.username || "",
1128
1413
  deps.cancelled
1129
1414
  );
1130
1415
  if (!decision.proceed) return decision.result;
1416
+ const prepared = await readTicketFiles(args.attachments);
1417
+ if (attachmentCount(args.attachments) > 0 && prepared.files.length === 0) {
1418
+ return { text: prepared.note || "附件没读到,工单没有提交。", isError: true };
1419
+ }
1420
+ const outbound = { ...args };
1421
+ if (prepared.files.length) outbound.attachments = prepared.files;
1422
+ else delete outbound.attachments;
1131
1423
  state.busy += 1;
1132
1424
  try {
1133
- return await toolCall("create_ticket", args, timeout);
1425
+ const result = await toolCall("create_ticket", outbound, timeout);
1426
+ if (prepared.note && !result.isError) return { ...result, text: `${result.text}
1427
+ ${prepared.note}` };
1428
+ return result;
1134
1429
  } catch {
1135
1430
  return { text: "结果不清楚。请到「我的工单」核对,不要自动再提交一张。", isError: true };
1136
1431
  } finally {
@@ -1161,7 +1456,7 @@ ${accepted.tools.map((tool) => tool.name).join("\n")}`;
1161
1456
  return { text: "当前没有这个工具。", isError: true };
1162
1457
  }
1163
1458
  const payload = applyContextArgs(name2, args);
1164
- if (name2 === "create_ticket") return runTicket(payload, ctx, entry?.timeoutMs || 6e4);
1459
+ if (name2 === "create_ticket") return runTicket(payload, ctx, entry?.timeoutMs || TOOLS.create_ticket.timeoutMs);
1165
1460
  if (name2 === "submit_experience") return runExperience(payload, ctx, entry?.timeoutMs || 3e4);
1166
1461
  state.busy += 1;
1167
1462
  try {
@@ -1316,12 +1611,12 @@ ${accepted.tools.map((tool) => tool.name).join("\n")}`;
1316
1611
 
1317
1612
  // src/view.ts
1318
1613
  var PACKAGE_NAME = "@authinex/dsh-plugin";
1319
- var ROW_ID = "authinex-ds-plugin";
1614
+ var ROW_ID = "authinex-host";
1320
1615
  var ROW_KEY = `${PACKAGE_NAME}#${ROW_ID}`;
1321
1616
  var SKILL_PAGE_SIZE = 8;
1322
1617
 
1323
1618
  // src/controller.ts
1324
- var VERSION = true ? "0.3.7" : "0.1.0";
1619
+ var VERSION = true ? "0.3.9" : "0.1.0";
1325
1620
  var CREDENTIAL_REF = "AUTHINEX_DS_DEVICE";
1326
1621
  var CONTEXT_CREDENTIAL_REF = "AUTHINEX_DS_CONTEXT";
1327
1622
  var NPM_LATEST_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
@@ -1347,6 +1642,9 @@ var PhaseError = class extends Error {
1347
1642
  function phaseError(error) {
1348
1643
  return error instanceof PhaseError ? error : null;
1349
1644
  }
1645
+ function defaultMachineFingerprint() {
1646
+ return machineFingerprint({ platform: platform2(), arch: arch2(), machineId: readMachineId() });
1647
+ }
1350
1648
  function defaultFingerprint(installId) {
1351
1649
  return currentFingerprints(installId).current;
1352
1650
  }
@@ -1387,15 +1685,30 @@ function createController(options) {
1387
1685
  const clientKind = options.clientKind || detectClientKind();
1388
1686
  const fingerprintOf = options.fingerprint || defaultFingerprint;
1389
1687
  const legacyFingerprintOf = options.legacyFingerprint || defaultLegacyFingerprint;
1688
+ const machineFingerprintOf = options.machineFingerprint || (options.fingerprint ? (() => "") : defaultMachineFingerprint);
1689
+ const deviceFile = options.deviceFile;
1390
1690
  function devicePrints(installId) {
1391
1691
  try {
1392
- return { current: fingerprintOf(installId), legacy: legacyFingerprintOf(installId) };
1692
+ return {
1693
+ current: fingerprintOf(installId),
1694
+ legacy: legacyFingerprintOf(installId),
1695
+ machine: machineFingerprintOf()
1696
+ };
1393
1697
  } catch {
1394
1698
  const error = new PhaseError("machine", "invalid");
1395
1699
  error.detail = "读不到这台机器的硬件标识,无法绑定";
1396
1700
  throw error;
1397
1701
  }
1398
1702
  }
1703
+ function fingerprintFields(installId) {
1704
+ const prints = devicePrints(installId);
1705
+ const fields = {
1706
+ fingerprint: prints.current,
1707
+ legacyFingerprint: prints.legacy
1708
+ };
1709
+ if (prints.machine) fields.machineFingerprint = prints.machine;
1710
+ return fields;
1711
+ }
1399
1712
  const createKey = options.createKey || defaultKeyPair;
1400
1713
  const signPayload = options.sign || defaultSign;
1401
1714
  const installer = options.install;
@@ -1467,9 +1780,8 @@ function createController(options) {
1467
1780
  toolTitles: dispatch.toolTitles()
1468
1781
  };
1469
1782
  }
1470
- async function readSecret() {
1471
- const resolved = await credentials.resolve(CREDENTIAL_REF);
1472
- const value = typeof resolved === "string" ? resolved : resolved?.value;
1783
+ function parseStored(raw) {
1784
+ const value = typeof raw === "string" ? raw : raw && typeof raw === "object" && "value" in raw ? String(raw.value || "") : "";
1473
1785
  if (!value) return null;
1474
1786
  try {
1475
1787
  const data = JSON.parse(value);
@@ -1485,15 +1797,47 @@ function createController(options) {
1485
1797
  return null;
1486
1798
  }
1487
1799
  }
1488
- async function writeSecret(record) {
1489
- const secret = {
1800
+ function secretReady(secret) {
1801
+ return Boolean(secret?.privateJwk && secret.deviceId && secret.installId && secret.endpoint);
1802
+ }
1803
+ function secretText(record) {
1804
+ return JSON.stringify({
1490
1805
  installId: record.installId,
1491
1806
  deviceId: record.deviceId || "",
1492
1807
  endpoint: normalizeEndpoint(record.endpoint),
1493
1808
  privateJwk: record.privateJwk,
1494
1809
  publicJwk: record.publicJwk
1495
- };
1496
- await credentials.set(CREDENTIAL_REF, JSON.stringify(secret));
1810
+ });
1811
+ }
1812
+ async function readSecret() {
1813
+ const fromHost = parseStored(await credentials.resolve(CREDENTIAL_REF));
1814
+ if (secretReady(fromHost)) {
1815
+ if (deviceFile) {
1816
+ try {
1817
+ await deviceFile.write(secretText(fromHost));
1818
+ } catch {
1819
+ }
1820
+ }
1821
+ return fromHost;
1822
+ }
1823
+ if (!deviceFile) return fromHost;
1824
+ const fromFile = parseStored(await deviceFile.read());
1825
+ if (!secretReady(fromFile)) return fromHost;
1826
+ try {
1827
+ await credentials.set(CREDENTIAL_REF, secretText(fromFile));
1828
+ } catch {
1829
+ }
1830
+ return fromFile;
1831
+ }
1832
+ async function writeSecret(record) {
1833
+ const text2 = secretText(record);
1834
+ await credentials.set(CREDENTIAL_REF, text2);
1835
+ if (deviceFile) {
1836
+ try {
1837
+ await deviceFile.write(text2);
1838
+ } catch {
1839
+ }
1840
+ }
1497
1841
  }
1498
1842
  function clearSession() {
1499
1843
  memory.token = "";
@@ -1532,7 +1876,7 @@ function createController(options) {
1532
1876
  }
1533
1877
  return snapshot();
1534
1878
  }
1535
- async function request(path, init = {}) {
1879
+ async function request(path2, init = {}) {
1536
1880
  const method = init.method || "POST";
1537
1881
  const timeout = init.timeout ?? 3e4;
1538
1882
  const session = Boolean(init.session);
@@ -1543,7 +1887,7 @@ function createController(options) {
1543
1887
  "x-authinex-ds-version": version
1544
1888
  };
1545
1889
  if (memory.token) headers.authorization = `Bearer ${memory.token}`;
1546
- const run = () => fetchImpl(`${base}${path}`, {
1890
+ const run = () => fetchImpl(`${base}${path2}`, {
1547
1891
  method,
1548
1892
  headers,
1549
1893
  body: init.body === void 0 ? void 0 : JSON.stringify(init.body),
@@ -1585,7 +1929,7 @@ function createController(options) {
1585
1929
  const known = phaseError(error);
1586
1930
  if (known && !init.replayed && known.phase === "invalid" && await hasDeviceSecret()) {
1587
1931
  const back = await signInSaved();
1588
- if (back) return request(path, { ...init, replayed: true });
1932
+ if (back) return request(path2, { ...init, replayed: true });
1589
1933
  throw new PhaseError("session", "unreachable");
1590
1934
  }
1591
1935
  if (known) throw error;
@@ -1743,9 +2087,9 @@ function createController(options) {
1743
2087
  if (!validSlug(slug)) {
1744
2088
  return { ok: false, message: "技能目录名不合法,已放弃这次安装", path: "", slug: "" };
1745
2089
  }
1746
- const path = await writeSkill2(slug, exported.markdown);
2090
+ const path2 = await writeSkill2(slug, exported.markdown);
1747
2091
  await refreshInstalled();
1748
- return { ok: true, message: "已装到本机技能目录,新会话生效", path, slug };
2092
+ return { ok: true, message: "已装到本机技能目录,新会话生效", path: path2, slug };
1749
2093
  } catch {
1750
2094
  return { ok: false, message: "写到本机技能目录失败", path: "", slug: "" };
1751
2095
  } finally {
@@ -1772,8 +2116,7 @@ function createController(options) {
1772
2116
  const data = await request("/api/auth/ds-plugin/session", {
1773
2117
  body: {
1774
2118
  deviceId: secret.deviceId,
1775
- fingerprint: devicePrints(secret.installId).current,
1776
- legacyFingerprint: devicePrints(secret.installId).legacy,
2119
+ ...fingerprintFields(secret.installId),
1777
2120
  nonce: challenge.nonce,
1778
2121
  signature,
1779
2122
  appVersion: version
@@ -1805,7 +2148,8 @@ function createController(options) {
1805
2148
  signingIn = false;
1806
2149
  }
1807
2150
  }
1808
- async function restore() {
2151
+ let boot = null;
2152
+ async function loadBinding() {
1809
2153
  await dispatch.loadWork();
1810
2154
  const secret = await readSecret();
1811
2155
  if (!secret?.privateJwk || !secret.deviceId || !secret.installId || !secret.endpoint) {
@@ -1817,6 +2161,13 @@ function createController(options) {
1817
2161
  await signInSaved();
1818
2162
  return snapshot();
1819
2163
  }
2164
+ async function restore() {
2165
+ if (boot) return boot;
2166
+ boot = loadBinding().finally(() => {
2167
+ boot = null;
2168
+ });
2169
+ return boot;
2170
+ }
1820
2171
  async function bind(input) {
1821
2172
  if (bindFlight) return bindFlight;
1822
2173
  bindFlight = doBind(input).finally(() => {
@@ -1848,8 +2199,7 @@ function createController(options) {
1848
2199
  keyProtection: "software",
1849
2200
  clientKind,
1850
2201
  installId,
1851
- fingerprint: devicePrints(installId).current,
1852
- legacyFingerprint: devicePrints(installId).legacy,
2202
+ ...fingerprintFields(installId),
1853
2203
  deviceName: hostname2(),
1854
2204
  os: platform2(),
1855
2205
  appVersion: version
@@ -1874,8 +2224,15 @@ function createController(options) {
1874
2224
  const phase = known?.phase || "unreachable";
1875
2225
  fail(phase, known?.detail || "");
1876
2226
  memory.retryAfter = retryAfter;
1877
- const text2 = phrase(phase);
1878
- const message = phase === "unreachable" && memory.endpoint ? `${text2}(${memory.endpoint})` : text2;
2227
+ if (secretReady(existing) && existing.endpoint === endpoint) {
2228
+ const back = await signInSaved();
2229
+ if (back) {
2230
+ return { ok: true, message: "原来的绑定还在,继续用这台机器上的登录", state: snapshot() };
2231
+ }
2232
+ }
2233
+ const shown = String(memory.phase);
2234
+ const text2 = phrase(shown);
2235
+ const message = shown === "unreachable" && memory.endpoint ? `${text2}(${memory.endpoint})` : text2;
1879
2236
  return { ok: false, message, state: snapshot() };
1880
2237
  }
1881
2238
  }
@@ -1893,48 +2250,50 @@ function createController(options) {
1893
2250
  memory.endpoint = "";
1894
2251
  memory.phase = "unbound";
1895
2252
  await credentials.unset(CREDENTIAL_REF);
2253
+ if (deviceFile) {
2254
+ try {
2255
+ await deviceFile.clear();
2256
+ } catch {
2257
+ }
2258
+ }
1896
2259
  return { ok: true, state: snapshot() };
1897
2260
  }
1898
- function accountBody(form) {
1899
- const patch = { ...form };
1900
- if (!patch.token) delete patch.token;
1901
- const settings = {};
1902
- for (const key of ["defaultProjectUuid", "defaultIssueTypeId", "engineCode", "schemaCode", "authMode", "isTenant"]) {
1903
- if (patch[key] !== void 0) settings[key] = patch[key];
1904
- }
2261
+ function sessionHeaders() {
1905
2262
  return {
1906
- baseUrl: patch.baseUrl,
1907
- username: patch.username,
1908
- teamUuid: patch.teamUuid,
1909
- projectId: patch.projectId,
1910
- token: patch.token,
1911
- enabled: patch.enabled !== false,
1912
- settings
2263
+ authorization: `Bearer ${memory.token}`,
2264
+ "content-type": "application/json",
2265
+ "x-authinex-ds-version": version
1913
2266
  };
1914
2267
  }
2268
+ async function postPersonal(path2, body, replayed = false) {
2269
+ const base = normalizeEndpoint(memory.endpoint);
2270
+ if (!base || !memory.token) return { ok: false, status: 0, data: { message: PHRASES.unreachable } };
2271
+ const res = await postJson(fetchImpl, `${base}${path2}`, sessionHeaders(), body);
2272
+ if (res.status === 401 && !replayed && await hasDeviceSecret()) {
2273
+ const back = await signInSaved();
2274
+ if (back) return postPersonal(path2, body, true);
2275
+ }
2276
+ return { ok: res.ok, status: res.status, data: res.data };
2277
+ }
1915
2278
  async function testAccount(provider, form) {
1916
2279
  if (memory.busy) return { ok: false, message: BUSY };
1917
2280
  try {
1918
- const tested = await request(`/api/auth/me/accounts/test/${provider}`, {
1919
- body: accountBody(form),
1920
- session: true,
1921
- timeout: 3e4
1922
- });
1923
- return { ok: Boolean(tested.ok), message: String(tested.message || "") };
2281
+ const res = await postPersonal(
2282
+ `/api/auth/me/accounts/test/${encodeURIComponent(provider)}`,
2283
+ accountPatch(form)
2284
+ );
2285
+ const ok = res.ok && Boolean(res.data.ok);
2286
+ return { ok, message: textOf(res.data, ok ? "连接正常" : "连接失败") };
1924
2287
  } catch {
1925
- return { ok: false, message: MISS };
2288
+ return { ok: false, message: "没有连上,稍后再试" };
1926
2289
  }
1927
2290
  }
1928
2291
  async function saveAccount(provider, form) {
1929
2292
  if (memory.busy) return { ok: false, message: BUSY };
1930
- const body = accountBody(form);
2293
+ const body = accountPatch(form);
2294
+ const tested = await testAccount(provider, form);
2295
+ if (!tested.ok) return { ok: false, message: tested.message || "连接测试没通过,没有保存" };
1931
2296
  try {
1932
- const tested = await request(`/api/auth/me/accounts/test/${provider}`, {
1933
- body,
1934
- session: true,
1935
- timeout: 3e4
1936
- });
1937
- if (!tested.ok) return { ok: false, message: tested.message || "连接测试没通过,没有保存" };
1938
2297
  await request("/api/auth/me/accounts", {
1939
2298
  method: "PUT",
1940
2299
  body: { [provider]: body },
@@ -1943,7 +2302,7 @@ function createController(options) {
1943
2302
  await loadAccounts();
1944
2303
  return { ok: true, message: "已保存", state: snapshot() };
1945
2304
  } catch {
1946
- return { ok: false, message: MISS };
2305
+ return { ok: false, message: "连接通过了,但没有写进个人设置" };
1947
2306
  }
1948
2307
  }
1949
2308
  async function setAccountEnabled(provider, enabled) {
@@ -1960,6 +2319,65 @@ function createController(options) {
1960
2319
  return { ok: false, message: MISS, state: snapshot() };
1961
2320
  }
1962
2321
  }
2322
+ function optionRows(rows) {
2323
+ if (!Array.isArray(rows)) return [];
2324
+ return rows.map((row) => ({ uuid: String(row.uuid || ""), name: String(row.name || row.uuid || "") })).filter((row) => row.uuid);
2325
+ }
2326
+ async function legacyOnesOptions(issueTypes, project) {
2327
+ const base = normalizeEndpoint(memory.endpoint);
2328
+ if (!base || !memory.token) return { ok: false, message: PHRASES.unreachable };
2329
+ const path2 = issueTypes ? `/api/auth/me/accounts/ones/issue-types?projectUuid=${encodeURIComponent(project.trim())}` : "/api/auth/me/accounts/ones/projects";
2330
+ try {
2331
+ const response = await fetchImpl(`${base}${path2}`, {
2332
+ method: issueTypes ? "GET" : "POST",
2333
+ headers: {
2334
+ authorization: `Bearer ${memory.token}`,
2335
+ "x-authinex-ds-version": version
2336
+ },
2337
+ timeout: 3e4
2338
+ });
2339
+ const raw = await response.text();
2340
+ let data = {};
2341
+ try {
2342
+ const parsed = raw ? JSON.parse(raw) : {};
2343
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) data = parsed;
2344
+ } catch {
2345
+ data = {};
2346
+ }
2347
+ if (!response.ok) return { ok: false, message: textOf(data, "拉取失败") };
2348
+ if (issueTypes) {
2349
+ const rows2 = optionRows(data.issueTypes ?? data.issue_types);
2350
+ return { ok: true, message: rows2.length ? "" : "这个项目下没有工单类型", issueTypes: rows2 };
2351
+ }
2352
+ const rows = optionRows(data.projects);
2353
+ return { ok: true, message: rows.length ? "" : "这个账号下没有可选项目", projects: rows };
2354
+ } catch {
2355
+ return { ok: false, message: "没有拉到,稍后再试" };
2356
+ }
2357
+ }
2358
+ async function accountOptions(provider, kind, project, form = {}) {
2359
+ if (provider !== "ones") return { ok: false, message: "这一家没有可拉取的下拉数据" };
2360
+ const base = normalizeEndpoint(memory.endpoint);
2361
+ if (!base || !memory.token) return { ok: false, message: PHRASES.unreachable };
2362
+ const issueTypes = kind === "issueTypes";
2363
+ try {
2364
+ const res = await postPersonal("/api/auth/me/accounts/ones/form-options", {
2365
+ ...accountPatch(form),
2366
+ kind: issueTypes ? "issueTypes" : "projects",
2367
+ projectUuid: project.trim()
2368
+ });
2369
+ if (res.status === 404) return legacyOnesOptions(issueTypes, project);
2370
+ if (!res.ok) return { ok: false, message: textOf(res.data, "拉取失败") };
2371
+ if (issueTypes) {
2372
+ const rows2 = optionRows(res.data.issueTypes ?? res.data.issue_types);
2373
+ return { ok: true, message: rows2.length ? "" : textOf(res.data, "这个项目下没有工单类型"), issueTypes: rows2 };
2374
+ }
2375
+ const rows = optionRows(res.data.projects);
2376
+ return { ok: true, message: rows.length ? "" : textOf(res.data, "这个账号下没有可选项目"), projects: rows };
2377
+ } catch {
2378
+ return { ok: false, message: "没有拉到,稍后再试" };
2379
+ }
2380
+ }
1963
2381
  async function fetchManifest() {
1964
2382
  const base = normalizeEndpoint(memory.endpoint);
1965
2383
  if (!base || !memory.token) return null;
@@ -2076,65 +2494,78 @@ function createController(options) {
2076
2494
  if (found.sha && sha !== found.sha) {
2077
2495
  return { ok: false, message: "校验值不一致,已放弃这次更新" };
2078
2496
  }
2079
- const dir = await mkdtemp(join2(tmpdir(), "authinex-ds-update-"));
2080
- const file = join2(dir, found.artifact);
2081
- await writeFile2(file, buffer);
2497
+ const dir = await mkdtemp(join3(tmpdir(), "authinex-ds-update-"));
2498
+ const file = join3(dir, found.artifact);
2499
+ await writeFile3(file, buffer);
2082
2500
  return { ok: true, message: `已下载 ${found.version}`, path: file, version: found.version, sha };
2083
2501
  } catch {
2084
2502
  return { ok: false, message: "下载更新包失败" };
2085
2503
  }
2086
2504
  }
2087
- async function handle(method, path, body, headers) {
2505
+ async function handle(method, path2, body, headers) {
2088
2506
  if (headers?.["x-authinex-ds"] !== "1") {
2089
2507
  return { status: 403, body: { detail: "forbidden" } };
2090
2508
  }
2091
- if (method === "GET" && path === "/authinex-ds/state") {
2509
+ if (method === "GET" && path2 === "/authinex-ds/state") {
2510
+ if (!memory.token && memory.phase !== "binding") {
2511
+ const saved = await readSecret();
2512
+ if (secretReady(saved)) await restore();
2513
+ }
2092
2514
  await dispatch.refreshStatus();
2093
2515
  return { status: 200, body: snapshot() };
2094
2516
  }
2095
- if (method === "GET" && path === "/authinex-ds/context") {
2517
+ if (method === "GET" && path2 === "/authinex-ds/context") {
2096
2518
  return { status: 200, body: dispatch.contextView() };
2097
2519
  }
2098
- if (method === "POST" && path === "/authinex-ds/context") {
2520
+ if (method === "POST" && path2 === "/authinex-ds/context") {
2099
2521
  const saved = await dispatch.saveContext(body || {});
2100
2522
  return { status: saved.ok ? 200 : 400, body: { ...saved, state: snapshot() } };
2101
2523
  }
2102
- if (method === "POST" && path === "/authinex-ds/bind") {
2524
+ if (method === "POST" && path2 === "/authinex-ds/bind") {
2103
2525
  const result = await bind({ key: String(body?.key || ""), endpoint: body?.endpoint });
2104
2526
  return { status: result.ok ? 200 : 400, body: { ...result.state, message: result.message || "" } };
2105
2527
  }
2106
- if (method === "POST" && path === "/authinex-ds/unbind") {
2528
+ if (method === "POST" && path2 === "/authinex-ds/unbind") {
2107
2529
  const result = await unbind();
2108
2530
  return { status: 200, body: { ...result.state, message: "已解除绑定" } };
2109
2531
  }
2110
- if (path === "/authinex-ds/accounts" && method === "GET") {
2532
+ if (path2 === "/authinex-ds/accounts" && method === "GET") {
2111
2533
  return { status: 200, body: snapshot().accounts };
2112
2534
  }
2113
- if (path === "/authinex-ds/accounts" && method === "PATCH") {
2535
+ if (path2 === "/authinex-ds/accounts" && method === "PATCH") {
2114
2536
  const result = await saveAccount(String(body?.provider || ""), body?.form || {});
2115
- return { status: result.ok ? 200 : 400, body: result };
2537
+ return { status: 200, body: result };
2116
2538
  }
2117
- if (path === "/authinex-ds/accounts/test" && method === "POST") {
2539
+ if (path2 === "/authinex-ds/accounts/test" && method === "POST") {
2118
2540
  const result = await testAccount(String(body?.provider || ""), body?.form || {});
2119
- return { status: result.ok ? 200 : 400, body: result };
2541
+ return { status: 200, body: result };
2120
2542
  }
2121
- if (path === "/authinex-ds/accounts/enabled" && method === "POST") {
2543
+ if (path2 === "/authinex-ds/accounts/enabled" && method === "POST") {
2122
2544
  const result = await setAccountEnabled(String(body?.provider || ""), Boolean(body?.enabled));
2123
2545
  return { status: result.ok ? 200 : 400, body: result };
2124
2546
  }
2125
- if (method === "POST" && path === "/authinex-ds/update/check") {
2547
+ if (path2 === "/authinex-ds/accounts/options" && method === "POST") {
2548
+ const result = await accountOptions(
2549
+ String(body?.provider || ""),
2550
+ String(body?.kind || ""),
2551
+ String(body?.project || ""),
2552
+ body?.form || {}
2553
+ );
2554
+ return { status: 200, body: result };
2555
+ }
2556
+ if (method === "POST" && path2 === "/authinex-ds/update/check") {
2126
2557
  const result = await checkUpdate();
2127
2558
  return { status: 200, body: { ...result.state, updateMessage: result.message || "" } };
2128
2559
  }
2129
- if (method === "POST" && path === "/authinex-ds/update/apply") {
2560
+ if (method === "POST" && path2 === "/authinex-ds/update/apply") {
2130
2561
  const result = await applyUpdate();
2131
2562
  return { status: result.ok ? 200 : 400, body: { ...result } };
2132
2563
  }
2133
- if (method === "POST" && path === "/authinex-ds/update/download") {
2564
+ if (method === "POST" && path2 === "/authinex-ds/update/download") {
2134
2565
  const result = await downloadUpdate();
2135
2566
  return { status: result.ok ? 200 : 400, body: { ...result } };
2136
2567
  }
2137
- if (method === "POST" && path === "/authinex-ds/skills") {
2568
+ if (method === "POST" && path2 === "/authinex-ds/skills") {
2138
2569
  const result = await listSkills({
2139
2570
  q: String(body?.q || ""),
2140
2571
  page: Number(body?.page || 1),
@@ -2143,7 +2574,7 @@ function createController(options) {
2143
2574
  });
2144
2575
  return { status: 200, body: result };
2145
2576
  }
2146
- if (method === "POST" && path === "/authinex-ds/skills/import") {
2577
+ if (method === "POST" && path2 === "/authinex-ds/skills/import") {
2147
2578
  const result = await importSkill({
2148
2579
  markdown: String(body?.markdown || ""),
2149
2580
  name: String(body?.name || ""),
@@ -2151,11 +2582,11 @@ function createController(options) {
2151
2582
  });
2152
2583
  return { status: result.ok ? 200 : 400, body: result };
2153
2584
  }
2154
- if (method === "POST" && path === "/authinex-ds/skills/export") {
2585
+ if (method === "POST" && path2 === "/authinex-ds/skills/export") {
2155
2586
  const result = await exportSkill(body?.id);
2156
2587
  return { status: result.ok ? 200 : 400, body: result };
2157
2588
  }
2158
- if (method === "POST" && path === "/authinex-ds/skills/install") {
2589
+ if (method === "POST" && path2 === "/authinex-ds/skills/install") {
2159
2590
  const result = await installSkill(body?.id);
2160
2591
  return { status: result.ok ? 200 : 400, body: { ...result, state: snapshot() } };
2161
2592
  }
@@ -2191,6 +2622,7 @@ function createController(options) {
2191
2622
  saveAccount,
2192
2623
  setAccountEnabled,
2193
2624
  testAccount,
2625
+ accountOptions,
2194
2626
  checkUpdate,
2195
2627
  listSkills,
2196
2628
  importSkill,
@@ -2211,6 +2643,7 @@ var PATHS = [
2211
2643
  "/authinex-ds/accounts",
2212
2644
  "/authinex-ds/accounts/test",
2213
2645
  "/authinex-ds/accounts/enabled",
2646
+ "/authinex-ds/accounts/options",
2214
2647
  "/authinex-ds/update/check",
2215
2648
  "/authinex-ds/update/apply",
2216
2649
  "/authinex-ds/update/download",
@@ -2300,6 +2733,7 @@ function apply(ctx) {
2300
2733
  // 技能只落 DSH 自己的技能目录,不进用户工作区、不碰仓库。
2301
2734
  writeSkill,
2302
2735
  listInstalled,
2736
+ deviceFile: defaultDeviceFile(),
2303
2737
  credentials: {
2304
2738
  resolve: () => ctx.credentials.resolve(ref),
2305
2739
  set: (_ref, value) => ctx.credentials.set(ref, value),
@@ -2353,10 +2787,10 @@ function apply(ctx) {
2353
2787
  disposed = true;
2354
2788
  for (const dispose of disposers.splice(0)) dispose();
2355
2789
  }, "authinex-ds: tools");
2356
- for (const path of PATHS) {
2790
+ for (const path2 of PATHS) {
2357
2791
  ctx.effect(() => ctx.webServer.register({
2358
2792
  kind: "exact",
2359
- path,
2793
+ path: path2,
2360
2794
  handler: async (req, res) => {
2361
2795
  const rejection = ctx.connection?.requestRejection?.(req);
2362
2796
  if (rejection !== void 0) {
@@ -2373,9 +2807,9 @@ function apply(ctx) {
2373
2807
  return;
2374
2808
  }
2375
2809
  }
2376
- const result = await controller.handle(method, path, body, headerMap(req));
2810
+ const result = await controller.handle(method, path2, body, headerMap(req));
2377
2811
  const payload = result.body;
2378
- if (path === "/authinex-ds/bind" || path === "/authinex-ds/unbind" || path === "/authinex-ds/accounts") {
2812
+ if (path2 === "/authinex-ds/bind" || path2 === "/authinex-ds/unbind" || path2 === "/authinex-ds/accounts") {
2379
2813
  try {
2380
2814
  registerTools();
2381
2815
  } catch (error) {
@@ -2390,7 +2824,7 @@ function apply(ctx) {
2390
2824
  }
2391
2825
  send(res, result.status, payload);
2392
2826
  }
2393
- }), `authinex-ds: ${path}`);
2827
+ }), `authinex-ds: ${path2}`);
2394
2828
  }
2395
2829
  void controller.restore().then(() => registerTools());
2396
2830
  }