weaver-work-cli 0.1.53 → 0.1.56

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.
Files changed (183) hide show
  1. package/dist/chunks/{archive-ZQ4A4TV6.js → archive-4SQAVTIB.js} +3 -2
  2. package/dist/chunks/{archive-oa-57R2FYHV.js → archive-oa-W2UEJ67L.js} +137 -8
  3. package/dist/chunks/{asset-ZOJVBWZH.js → asset-EGZEABBI.js} +3 -2
  4. package/dist/chunks/{asset-idle-XGB5IPGT.js → asset-idle-EBUZBB6M.js} +3 -2
  5. package/dist/chunks/{attachment-content-W3TSJC3Y.js → attachment-content-QGM5MLQE.js} +4 -3
  6. package/dist/chunks/{blog-QSHLZSFW.js → blog-2YKMWOWI.js} +3 -2
  7. package/dist/chunks/{caizhilian-KCQYFH72.js → caizhilian-QJ4FLSQJ.js} +5 -4
  8. package/dist/chunks/{calendar-DLGMRJQA.js → calendar-H4QTJCUY.js} +3 -2
  9. package/dist/chunks/{chunk-XPQN4E5O.js → chunk-44KJ7WFA.js} +300 -55
  10. package/dist/chunks/{chunk-CZNZKOHR.js → chunk-4GG72JAT.js} +2 -2
  11. package/dist/chunks/{chunk-YIKSL36S.js → chunk-5N222HK6.js} +2 -2
  12. package/dist/chunks/{chunk-6GCXWKG6.js → chunk-6DVL5IN5.js} +4 -1
  13. package/dist/chunks/{chunk-WTLQGS6D.js → chunk-6MS3RLPO.js} +5 -334
  14. package/dist/chunks/{chunk-Z4G7LLDD.js → chunk-7EBV7Q3R.js} +124 -27
  15. package/dist/chunks/{chunk-76PRVYH4.js → chunk-AHJZIMCX.js} +1 -1
  16. package/dist/chunks/{chunk-TGAGQV4I.js → chunk-CQ4OVCKG.js} +2 -2
  17. package/dist/chunks/{chunk-2BQESR2U.js → chunk-DVR2EDUU.js} +99 -34
  18. package/dist/chunks/{chunk-QQXMHM3J.js → chunk-FDAJC7R4.js} +4 -4
  19. package/dist/chunks/{chunk-GR76ZDDX.js → chunk-FMNCSYIG.js} +2 -2
  20. package/dist/chunks/{chunk-IF33CG4V.js → chunk-L2LMBFG5.js} +1 -1
  21. package/dist/chunks/{chunk-DLY5GUXX.js → chunk-PH7N4UFT.js} +1 -1
  22. package/dist/chunks/{chunk-U6R6FZHD.js → chunk-SFM3M2L3.js} +286 -93
  23. package/dist/chunks/chunk-SHYQUBY3.js +48 -0
  24. package/dist/chunks/{chunk-HFXK54M4.js → chunk-TGM7BWEH.js} +2 -2
  25. package/dist/chunks/{chunk-2J3XY4ED.js → chunk-TJUAGZU7.js} +11 -11
  26. package/dist/chunks/{chunk-PE334WL3.js → chunk-UI66EMOR.js} +4 -4
  27. package/dist/chunks/{chunk-762M5XJS.js → chunk-VMCCRWFO.js} +2 -2
  28. package/dist/chunks/{chunk-U7ROML5E.js → chunk-WHJIUKJW.js} +681 -48
  29. package/dist/chunks/{chunk-PGO4ILMQ.js → chunk-WMB3SMXI.js} +1 -1
  30. package/dist/chunks/chunk-WMRNO6IU.js +337 -0
  31. package/dist/chunks/{chunk-6NXT4ICB.js → chunk-WVH5ESDA.js} +1 -1
  32. package/dist/chunks/{chunk-DEHJ7PMA.js → chunk-XU3FL3AW.js} +4 -4
  33. package/dist/chunks/{chunk-Z6UUBY37.js → chunk-Z4IPY5GV.js} +2 -2
  34. package/dist/chunks/{conflict-57WDJWL7.js → conflict-VAFFPUY3.js} +2 -2
  35. package/dist/chunks/{contract-LJRAXVZU.js → contract-LLRKMLQQ.js} +2655 -1319
  36. package/dist/chunks/{cowork-3ACICHDQ.js → cowork-2RDFBZWB.js} +3 -2
  37. package/dist/chunks/{create-flow-3FMMZBCA.js → create-flow-TVYE3IOH.js} +6 -6
  38. package/dist/chunks/{data-WK5CQXNF.js → data-WVICO3DT.js} +57 -11
  39. package/dist/chunks/{ebuilder-form-CBYI6CQ6.js → ebuilder-form-TWSXS5NA.js} +7 -6
  40. package/dist/chunks/{ehr-XI4BIVR2.js → ehr-52GBKNJR.js} +3 -2
  41. package/dist/chunks/{env-JYZE3BZB.js → env-BVVFIN4P.js} +2 -2
  42. package/dist/chunks/{esb-4BQHNP5C.js → esb-HJSXCEOM.js} +5 -4
  43. package/dist/chunks/{factory-66SCIKW3.js → factory-RCQ36LLE.js} +1 -1
  44. package/dist/chunks/{fna-ECOYBQYL.js → fna-OBACRT3J.js} +72 -3
  45. package/dist/chunks/{group-chat-MNRYMLNG.js → group-chat-YFZDUUY3.js} +3 -3
  46. package/dist/chunks/{host-TUOIOEMC.js → host-2BKMPWDH.js} +4 -3
  47. package/dist/chunks/{host-3TNBMDTR.js → host-KJT3G5D2.js} +4 -3
  48. package/dist/chunks/{host-7OWWPLM4.js → host-KOWUMNAY.js} +4 -3
  49. package/dist/chunks/{host-M4XP5URR.js → host-MFXRA2MY.js} +4 -3
  50. package/dist/chunks/{host-7NTIBSPK.js → host-TTSGY5NZ.js} +4 -3
  51. package/dist/chunks/{host-G3VU7SDW.js → host-W4JCNRFS.js} +4 -3
  52. package/dist/chunks/{hrm-YGIR3HGF.js → hrm-AK3WGBMN.js} +4 -3
  53. package/dist/chunks/{im-TN2JYVGJ.js → im-JZSBPO4Z.js} +4 -3
  54. package/dist/chunks/{invoice-V7ZTITUO.js → invoice-V6KD4TZE.js} +4 -3
  55. package/dist/chunks/{jiuchuanhui-ASFZBMPU.js → jiuchuanhui-K4EQU6GK.js} +3 -2
  56. package/dist/chunks/{lazy-dispatch-XSAHDK6Z.js → lazy-dispatch-JHGFCKJN.js} +5 -4
  57. package/dist/chunks/{mail-M3HJF5ER.js → mail-IKVCQCVZ.js} +3 -2
  58. package/dist/chunks/{meeting-IIY4UAJL.js → meeting-JOHV4RH3.js} +14 -12
  59. package/dist/chunks/minute-doc-JLS4KMFZ.js +156 -0
  60. package/dist/chunks/{okr-EVX7FB5G.js → okr-KV43FPPX.js} +3 -2
  61. package/dist/chunks/{operations-J7PUIVWZ.js → operations-ZPWBMYKE.js} +5 -4
  62. package/dist/chunks/{plan-2QJQEPBO.js → plan-WOYR4WEG.js} +3 -2
  63. package/dist/chunks/{project-XELELW2T.js → project-CQJKBUIL.js} +3 -2
  64. package/dist/chunks/{reception-QGPNTGHG.js → reception-MPBU3JXC.js} +3 -2
  65. package/dist/chunks/{recruit-stage-XCMVEQA2.js → recruit-stage-USTTRHOX.js} +3 -2
  66. package/dist/chunks/{registry-CJOVECZD.js → registry-GURQG4ZV.js} +3 -2
  67. package/dist/chunks/{registry-METZ2LWE.js → registry-LITYOH2W.js} +12 -10
  68. package/dist/chunks/{registry-QJCZ2GVG.js → registry-SS5J2FZQ.js} +5 -4
  69. package/dist/chunks/{room-recommend-YFY7HTOF.js → room-recommend-62MECG4J.js} +4 -4
  70. package/dist/chunks/{schedule-6I63TERA.js → schedule-6QRXIBGU.js} +4 -4
  71. package/dist/chunks/{smart-extract-FOUYNIG3.js → smart-extract-APX2PNIN.js} +3 -2
  72. package/dist/chunks/{workflow-YHXFIU63.js → workflow-WMPW3WSB.js} +5 -4
  73. package/dist/index.js +33 -32
  74. package/dist/internal/e10/auth/agent-host-key.js +68 -0
  75. package/dist/internal/e10/auth/agent-hosts.js +250 -0
  76. package/dist/internal/e10/auth/commands.js +99 -30
  77. package/dist/internal/e10/auth/paths.js +9 -0
  78. package/dist/internal/e10/auth/session.js +17 -0
  79. package/dist/internal/e10/auth/xiaoe.js +37 -3
  80. package/dist/shortcuts/archive-oa/operations/contract-modules.js +106 -0
  81. package/dist/shortcuts/archive-oa/operations/contract.js +38 -4
  82. package/dist/shortcuts/archive-oa/operations/registry.js +2 -1
  83. package/dist/shortcuts/contract/index.js +6 -7
  84. package/dist/shortcuts/contract/manifest.js +101 -24
  85. package/dist/shortcuts/contract/ooxml/docx-table.js +75 -3
  86. package/dist/shortcuts/contract/ooxml/xlsx.js +49 -13
  87. package/dist/shortcuts/contract/operations/card-action.js +113 -12
  88. package/dist/shortcuts/contract/operations/card-ebdf-list.js +29 -7
  89. package/dist/shortcuts/contract/operations/card-plan.js +75 -9
  90. package/dist/shortcuts/contract/operations/card-risk-report.js +2 -2
  91. package/dist/shortcuts/contract/operations/card.js +1 -1
  92. package/dist/shortcuts/contract/operations/clause-library.js +88 -16
  93. package/dist/shortcuts/contract/operations/compare-screen.js +378 -0
  94. package/dist/shortcuts/contract/operations/compare.js +1 -1
  95. package/dist/shortcuts/contract/operations/credit-page.js +1 -1
  96. package/dist/shortcuts/contract/operations/docx-slots.js +1000 -0
  97. package/dist/shortcuts/contract/operations/flow.js +2 -2
  98. package/dist/shortcuts/contract/operations/quote-to-contract.js +495 -0
  99. package/dist/shortcuts/contract/operations/quote.js +2 -229
  100. package/dist/shortcuts/contract/operations/recommend.js +1 -1
  101. package/dist/shortcuts/contract/operations/registry.js +6 -2
  102. package/dist/shortcuts/contract/operations/review.js +230 -4
  103. package/dist/shortcuts/contract/operations/save-recognize.js +122 -3
  104. package/dist/shortcuts/contract/operations/template.js +11 -10
  105. package/dist/shortcuts/data/operations/ds.js +5 -5
  106. package/dist/shortcuts/data/operations/shared.js +76 -4
  107. package/dist/shortcuts/fna/manifest.js +7 -2
  108. package/dist/shortcuts/fna/operations/budget.js +68 -0
  109. package/dist/shortcuts/meeting/minute-doc.js +153 -0
  110. package/dist/shortcuts/meeting/operations/compose-outcome.js +176 -0
  111. package/dist/shortcuts/meeting/operations/eb/catalog.js +1 -1
  112. package/dist/shortcuts/meeting/operations/eb/create-flow.js +47 -0
  113. package/dist/shortcuts/meeting/operations/eb/decision-task-batch.js +144 -0
  114. package/dist/shortcuts/meeting/operations/eb/decision.js +92 -4
  115. package/dist/shortcuts/meeting/operations/eb/index.js +133 -4
  116. package/dist/shortcuts/meeting/operations/eb/meeting-link.js +90 -0
  117. package/dist/shortcuts/meeting/operations/from-group-chat.js +46 -0
  118. package/dist/shortcuts/meeting/operations/minute-content.js +61 -0
  119. package/dist/shortcuts/meeting/operations/registry.js +14 -1
  120. package/dist/shortcuts/meeting/operations/self-check.js +49 -0
  121. package/dist/shortcuts/workflow/endpoints.js +2 -0
  122. package/dist/shortcuts/workflow/operations/read.js +114 -8
  123. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +72 -46
  124. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +41 -0
  125. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +46 -11
  126. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +18 -1
  127. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroupAdd.js +51 -0
  128. package/docs/e10-auth.md +78 -0
  129. package/docs/fna.md +8 -3
  130. package/package.json +4 -2
  131. package/scripts/pack-offline.mjs +228 -0
  132. package/scripts/package-skill.mjs +14 -5
  133. package/skill-template/business-info.json +3 -0
  134. package/skill-template/domains/qiyecheng.md +4 -3
  135. package/skills/weaver-e10-archive-oa/SKILL.md +6 -1
  136. package/skills/weaver-e10-archive-oa/references/contract-search.md +91 -4
  137. package/skills/weaver-e10-jinchengda/SKILL.md +100 -81
  138. package/skills/weaver-e10-jinchengda/references/contract-action-card-template.html +11 -6
  139. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -4
  140. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +38 -12
  141. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +1 -1
  142. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  143. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +20 -6
  144. package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +8 -3
  145. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +56 -13
  146. package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +7 -0
  147. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  148. package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +11 -5
  149. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +1 -1
  150. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +1 -1
  151. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +38 -7
  152. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +13 -25
  153. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +9 -8
  154. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +8 -6
  155. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +10 -7
  156. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +2 -2
  157. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +3 -1
  158. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +26 -18
  159. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +4 -4
  160. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +18 -13
  161. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +5 -3
  162. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +105 -49
  163. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
  164. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +3 -6
  165. package/skills/weaver-e10-meeting/SKILL.md +48 -9
  166. package/skills/weaver-e10-qiyecheng/SKILL.md +16 -7
  167. package/skills/weaver-e10-qiyecheng/references/budget.md +77 -3
  168. package/skills/weaver-e10-qiyecheng/references/catalog.md +6 -4
  169. package/skills/weaver-e10-qiyecheng/references/getEnabledTemplate-api.md +255 -0
  170. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +70 -25
  171. package/skills/weaver-e10-workflow/SKILL.md +54 -40
  172. package/skills/weaver-e10-workflow/references/todo-dialogue.md +134 -0
  173. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +102 -80
  174. package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +23 -13
  175. package/skills/weaver-e10-workflow/references/workflow-query.md +68 -46
  176. package/skills/weaver-e10-workflow/references/workflow-view.md +21 -13
  177. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +317 -332
  178. package/dist/shortcuts/contract/ooxml/docx.js +0 -295
  179. package/dist/shortcuts/contract/operations/docx-fillfromquote.js +0 -532
  180. package/skills/weaver-e10-jinchengda/references/contract-risk-report-template.html +0 -178
  181. package/skills/weaver-e10-jinchengda/references/source-manifest.json +0 -1270
  182. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +0 -998
  183. package/skills/weaver-e10-workflow/tools/todo-serve.cjs +0 -327
@@ -1,13 +1,16 @@
1
1
  import { createRequire as __esbuildCreateRequire } from 'node:module';
2
2
  const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ packagePath
5
+ } from "./chunk-SHYQUBY3.js";
3
6
  import {
4
7
  CliError
5
8
  } from "./chunk-UG5G54VL.js";
6
9
 
7
10
  // src/internal/e10/auth/session.ts
8
11
  import { constants, createDecipheriv as createDecipheriv2, createHash, publicEncrypt } from "node:crypto";
9
- import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync, unlinkSync } from "node:fs";
10
- import { dirname, resolve as resolve3 } from "node:path";
12
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, readdirSync, unlinkSync as unlinkSync2 } from "node:fs";
13
+ import { dirname as dirname2, resolve as resolve4 } from "node:path";
11
14
 
12
15
  // src/core/connector.ts
13
16
  var CONNECTOR_PROFILE = "eteams";
@@ -140,6 +143,9 @@ function getE10ProfilesRoot() {
140
143
  function getE10ActiveProfilePath() {
141
144
  return resolve(getE10AuthRoot(), "profile");
142
145
  }
146
+ function getE10AgentsPath() {
147
+ return resolve(getE10AuthRoot(), "agents.json");
148
+ }
143
149
 
144
150
  // src/internal/e10/auth/crypto.ts
145
151
  var ALGORITHM = "aes-256-gcm";
@@ -257,6 +263,210 @@ function parseAuthFile(raw) {
257
263
  }
258
264
  }
259
265
 
266
+ // src/internal/e10/auth/agent-hosts.ts
267
+ import { chmodSync, closeSync, existsSync as existsSync2, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync2, renameSync, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
268
+ import { dirname, resolve as resolve3 } from "node:path";
269
+
270
+ // src/internal/e10/auth/agent-host-key.ts
271
+ function hasEnvPrefix(env, prefix) {
272
+ return Object.keys(env).some((key) => key === prefix || key.startsWith(`${prefix}_`));
273
+ }
274
+ var AGENT_HOST_PREFIXES = [
275
+ { key: "xiaoe", prefixes: ["XIAOE", "WEAVER_XIAOE"] },
276
+ { key: "workbuddy", prefixes: ["WORKBUDDY"] },
277
+ { key: "codex", prefixes: ["CODEX"] },
278
+ { key: "doubao", prefixes: ["DOUBAO_OFFICE", "DOUBAO"] },
279
+ { key: "qwen", prefixes: ["QWENWORK", "QWEN"] }
280
+ ];
281
+ var DEFAULT_AGENT_HOST_KEY = "default";
282
+ function normalizeAgentHostKey(value) {
283
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/gu, "");
284
+ }
285
+ function normalizeExplicitAgentHostKey(value) {
286
+ const normalized = normalizeAgentHostKey(value);
287
+ if (!normalized) return "";
288
+ for (const { key, prefixes } of AGENT_HOST_PREFIXES) {
289
+ if (normalized === normalizeAgentHostKey(key)) return key;
290
+ if (prefixes.some((prefix) => normalized.startsWith(normalizeAgentHostKey(prefix)))) return key;
291
+ }
292
+ return normalized;
293
+ }
294
+ function resolveAgentHostKey(env = process.env, explicitAgentType = "") {
295
+ const explicit = normalizeExplicitAgentHostKey(explicitAgentType);
296
+ if (explicit) return explicit;
297
+ for (const { key, prefixes } of AGENT_HOST_PREFIXES) {
298
+ if (prefixes.some((prefix) => hasEnvPrefix(env, prefix))) return key;
299
+ }
300
+ return DEFAULT_AGENT_HOST_KEY;
301
+ }
302
+
303
+ // src/internal/e10/auth/agent-hosts.ts
304
+ var AGENTS_FILE_VERSION = 1;
305
+ var AGENTS_LOCK_TIMEOUT_MS = 600;
306
+ var AGENTS_LOCK_RETRY_MS = 15;
307
+ function asRecord2(value) {
308
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
309
+ }
310
+ function readText(value) {
311
+ return typeof value === "string" ? value.trim() : "";
312
+ }
313
+ function normalizeOrigin(value) {
314
+ const trimmed = value.trim();
315
+ if (!trimmed) return "";
316
+ try {
317
+ const url = new URL(trimmed);
318
+ return `${url.protocol}//${url.host}`.toLowerCase();
319
+ } catch {
320
+ return trimmed.toLowerCase().replace(/\/+$/u, "");
321
+ }
322
+ }
323
+ function readAgentHosts() {
324
+ const filePath = getE10AgentsPath();
325
+ if (!existsSync2(filePath)) return null;
326
+ try {
327
+ const parsed = asRecord2(JSON.parse(readFileSync2(filePath, "utf-8")));
328
+ const version = typeof parsed.version === "number" ? parsed.version : AGENTS_FILE_VERSION;
329
+ if (!Number.isInteger(version) || version > AGENTS_FILE_VERSION) return null;
330
+ const hosts = {};
331
+ for (const [key, raw] of Object.entries(asRecord2(parsed.hosts))) {
332
+ const entry = asRecord2(raw);
333
+ const profile = readText(entry.profile);
334
+ if (!profile) continue;
335
+ hosts[key] = {
336
+ profile,
337
+ ...readText(entry.baseUrl) ? { baseUrl: readText(entry.baseUrl) } : {},
338
+ ...readText(entry.tenantKey) ? { tenantKey: readText(entry.tenantKey) } : {},
339
+ ...readText(entry.agentType) ? { agentType: readText(entry.agentType) } : {},
340
+ updatedAt: readText(entry.updatedAt)
341
+ };
342
+ }
343
+ return { version, hosts };
344
+ } catch {
345
+ return null;
346
+ }
347
+ }
348
+ function readProfileConfigAt(profile) {
349
+ const configPath = resolve3(getE10ProfilesRoot(), profile, "config.json");
350
+ if (!existsSync2(configPath)) return {};
351
+ try {
352
+ return JSON.parse(readFileSync2(configPath, "utf-8"));
353
+ } catch {
354
+ return {};
355
+ }
356
+ }
357
+ function lookupAgentHost(env = process.env, explicitAgentType = "") {
358
+ const hostKey = resolveAgentHostKey(env, explicitAgentType);
359
+ const file = readAgentHosts();
360
+ const record = file?.hosts[hostKey];
361
+ if (!record) return null;
362
+ const profileDir = resolve3(getE10ProfilesRoot(), record.profile);
363
+ const authFile = resolve3(profileDir, "auth");
364
+ const base = { hostKey, record, profile: record.profile, authFile };
365
+ if (!existsSync2(profileDir)) return { ...base, status: "profile-missing" };
366
+ if (!existsSync2(authFile)) return { ...base, status: "auth-missing" };
367
+ const recordBaseUrl = normalizeOrigin(record.baseUrl || "");
368
+ const configBaseUrl = normalizeOrigin(readProfileConfigAt(record.profile).baseUrl || "");
369
+ if (recordBaseUrl && configBaseUrl && recordBaseUrl !== configBaseUrl) {
370
+ return { ...base, status: "domain-mismatch" };
371
+ }
372
+ return { ...base, status: "ok" };
373
+ }
374
+ function resolveLoginProfileName(input) {
375
+ const hinted = (input.profileHint || "").trim();
376
+ if (hinted) return hinted;
377
+ const derived = (input.derivedName || "").trim() || "default";
378
+ const hostKey = (input.hostKey || "").trim() || resolveAgentHostKey(input.env || process.env);
379
+ const origin = normalizeOrigin(input.baseUrl);
380
+ const hosts = readAgentHosts()?.hosts || {};
381
+ const claimedByOthers = Object.entries(hosts).filter(([key, record]) => key !== hostKey && record.profile === derived);
382
+ if (!claimedByOthers.length) return derived;
383
+ const sharesDomain = claimedByOthers.some(([, record]) => normalizeOrigin(record.baseUrl || "") === origin);
384
+ if (sharesDomain) return derived;
385
+ return `${derived}-${hostKey}`;
386
+ }
387
+ function sleepSync2(ms) {
388
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
389
+ }
390
+ function withAgentsLock(task) {
391
+ const lockPath = `${getE10AgentsPath()}.lock`;
392
+ let fd = null;
393
+ try {
394
+ mkdirSync2(dirname(lockPath), { recursive: true });
395
+ const deadline = Date.now() + AGENTS_LOCK_TIMEOUT_MS;
396
+ while (fd === null) {
397
+ try {
398
+ fd = openSync(lockPath, "wx", 384);
399
+ } catch (error) {
400
+ if (error.code !== "EEXIST") return task();
401
+ if (Date.now() >= deadline) {
402
+ try {
403
+ unlinkSync(lockPath);
404
+ fd = openSync(lockPath, "wx", 384);
405
+ } catch {
406
+ return task();
407
+ }
408
+ break;
409
+ }
410
+ sleepSync2(AGENTS_LOCK_RETRY_MS);
411
+ }
412
+ }
413
+ } catch {
414
+ return task();
415
+ }
416
+ try {
417
+ return task();
418
+ } finally {
419
+ if (fd !== null) {
420
+ try {
421
+ closeSync(fd);
422
+ } catch {
423
+ }
424
+ try {
425
+ unlinkSync(lockPath);
426
+ } catch {
427
+ }
428
+ }
429
+ }
430
+ }
431
+ function writeAgentHosts(file) {
432
+ const filePath = getE10AgentsPath();
433
+ mkdirSync2(dirname(filePath), { recursive: true });
434
+ const payload = JSON.stringify(file, null, 2) + "\n";
435
+ const tempPath = `${filePath}.${process.pid}.tmp`;
436
+ writeFileSync2(tempPath, payload, { mode: 384 });
437
+ renameSync(tempPath, filePath);
438
+ chmodSync(filePath, 384);
439
+ }
440
+ function upsertAgentHost(input) {
441
+ if (isConnectorMode()) return null;
442
+ const profile = input.profile?.trim();
443
+ if (!profile) return null;
444
+ const env = input.env || process.env;
445
+ const hostKey = input.hostKey?.trim() || resolveAgentHostKey(env);
446
+ const record = {
447
+ profile,
448
+ ...input.baseUrl ? { baseUrl: input.baseUrl } : {},
449
+ ...input.tenantKey ? { tenantKey: input.tenantKey } : {},
450
+ ...input.agentType ? { agentType: input.agentType } : {},
451
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
452
+ };
453
+ try {
454
+ return withAgentsLock(() => {
455
+ for (let attempt = 0; attempt < 2; attempt += 1) {
456
+ const hosts = {
457
+ ...readAgentHosts()?.hosts || {},
458
+ [hostKey]: record
459
+ };
460
+ writeAgentHosts({ version: AGENTS_FILE_VERSION, hosts });
461
+ if (readAgentHosts()?.hosts[hostKey]?.profile === profile) break;
462
+ }
463
+ return record;
464
+ });
465
+ } catch {
466
+ return null;
467
+ }
468
+ }
469
+
260
470
  // src/internal/e10/auth/session.ts
261
471
  var E10_TEAMS_CHECK_TIMEOUT_MS = 15e3;
262
472
  var RSA_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
@@ -298,8 +508,8 @@ async function fetchPublicKey(baseUrl, passportUrl) {
298
508
  function getActiveProfile() {
299
509
  const activeProfileFile = getE10ActiveProfilePath();
300
510
  try {
301
- if (existsSync2(activeProfileFile)) {
302
- const name = readFileSync2(activeProfileFile, "utf-8").trim();
511
+ if (existsSync3(activeProfileFile)) {
512
+ const name = readFileSync3(activeProfileFile, "utf-8").trim();
303
513
  if (name) return name;
304
514
  }
305
515
  } catch {
@@ -311,26 +521,26 @@ function setActiveProfile(name) {
311
521
  switchActiveProfile(name);
312
522
  }
313
523
  function switchActiveProfile(name) {
314
- mkdirSync2(getE10ProfilesRoot(), { recursive: true });
315
- mkdirSync2(resolve3(getE10ProfilesRoot(), name), { recursive: true });
524
+ mkdirSync3(getE10ProfilesRoot(), { recursive: true });
525
+ mkdirSync3(resolve4(getE10ProfilesRoot(), name), { recursive: true });
316
526
  writeWithRetry(getE10ActiveProfilePath(), name, "utf-8");
317
527
  }
318
528
  function listProfiles() {
319
529
  try {
320
- if (!existsSync2(getE10ProfilesRoot())) return [];
530
+ if (!existsSync3(getE10ProfilesRoot())) return [];
321
531
  return readdirSync(getE10ProfilesRoot(), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
322
532
  } catch {
323
533
  return [];
324
534
  }
325
535
  }
326
536
  function getProfileDir(name) {
327
- return resolve3(getE10ProfilesRoot(), name);
537
+ return resolve4(getE10ProfilesRoot(), name);
328
538
  }
329
539
  function getProfileAuthPath(name) {
330
- return resolve3(getProfileDir(name), "auth");
540
+ return resolve4(getProfileDir(name), "auth");
331
541
  }
332
542
  function getProfileConfigPath(name) {
333
- return resolve3(getProfileDir(name), "config.json");
543
+ return resolve4(getProfileDir(name), "config.json");
334
544
  }
335
545
  var MULTI_LABEL_PUBLIC_SUFFIXES = /* @__PURE__ */ new Set([
336
546
  "com.cn",
@@ -391,9 +601,9 @@ function profileNameFromUrl(baseUrl) {
391
601
  }
392
602
  function readProfileConfig(profile = getActiveProfile()) {
393
603
  const configPath = getProfileConfigPath(profile);
394
- if (existsSync2(configPath)) {
604
+ if (existsSync3(configPath)) {
395
605
  try {
396
- return JSON.parse(readFileSync2(configPath, "utf-8"));
606
+ return JSON.parse(readFileSync3(configPath, "utf-8"));
397
607
  } catch {
398
608
  return {};
399
609
  }
@@ -402,43 +612,49 @@ function readProfileConfig(profile = getActiveProfile()) {
402
612
  }
403
613
  function saveProfileConfig(baseUrl, passportUrl, profile = getActiveProfile(), tenantKey) {
404
614
  const configPath = getProfileConfigPath(profile);
405
- mkdirSync2(dirname(configPath), { recursive: true });
615
+ mkdirSync3(dirname2(configPath), { recursive: true });
406
616
  writeWithRetry(configPath, JSON.stringify({ baseUrl, passportUrl, tenantKey }, null, 2) + "\n", { mode: 384 });
407
617
  }
408
618
  function saveAuthFile(data, profile = getActiveProfile()) {
409
619
  const authPath = getProfileAuthPath(profile);
410
- mkdirSync2(dirname(authPath), { recursive: true });
620
+ mkdirSync3(dirname2(authPath), { recursive: true });
411
621
  writeWithRetry(authPath, JSON.stringify(encryptAuthData(JSON.stringify(data))), { mode: 384 });
412
622
  return authPath;
413
623
  }
414
624
  function clearProfileAuthFile(profile = getActiveProfile()) {
415
625
  const authFile = getProfileAuthPath(profile);
416
- if (!existsSync2(authFile)) return { profile, authFile, cleared: false };
417
- unlinkSync(authFile);
626
+ if (!existsSync3(authFile)) return { profile, authFile, cleared: false };
627
+ unlinkSync2(authFile);
418
628
  return { profile, authFile, cleared: true };
419
629
  }
630
+ function resolveActiveProfileForHost(env = process.env) {
631
+ const host = lookupAgentHost(env);
632
+ return host ? host.profile : getActiveProfile();
633
+ }
420
634
  function findAuthFile(startDir = process.cwd(), options = {}) {
421
635
  if (options.auth) return options.auth;
422
636
  if (options.profile) {
423
637
  const profileAuth = getProfileAuthPath(options.profile);
424
- if (existsSync2(profileAuth)) return profileAuth;
638
+ if (existsSync3(profileAuth)) return profileAuth;
425
639
  }
426
640
  const envAuth = process.env.E10_AUTH_PATH;
427
- if (envAuth && existsSync2(envAuth)) return envAuth;
641
+ if (envAuth && existsSync3(envAuth)) return envAuth;
642
+ const host = lookupAgentHost();
643
+ if (host) return host.status === "ok" ? host.authFile : null;
428
644
  const activeProfileAuth = getProfileAuthPath(getActiveProfile());
429
- if (existsSync2(activeProfileAuth)) return activeProfileAuth;
645
+ if (existsSync3(activeProfileAuth)) return activeProfileAuth;
430
646
  return null;
431
647
  }
432
- function asRecord2(value) {
648
+ function asRecord3(value) {
433
649
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
434
650
  }
435
651
  function readTeamsCheckUserInfo(resp, data) {
436
- const root = asRecord2(data);
437
- const nested = asRecord2(root.data);
438
- const currentUser = asRecord2(root.currentUser || nested.currentUser);
439
- const currentTenant = asRecord2(root.currentTenant || nested.currentTenant);
440
- const department = asRecord2(currentUser.department);
441
- const position = asRecord2(currentUser.position);
652
+ const root = asRecord3(data);
653
+ const nested = asRecord3(root.data);
654
+ const currentUser = asRecord3(root.currentUser || nested.currentUser);
655
+ const currentTenant = asRecord3(root.currentTenant || nested.currentTenant);
656
+ const department = asRecord3(currentUser.department);
657
+ const position = asRecord3(currentUser.position);
442
658
  const userId = resp.headers.get("employeeId") || currentUser.employeeId || currentUser.id || nested.employeeId || root.employeeId || "";
443
659
  const tenantKey = currentUser.tenantKey || currentTenant.tenantKey || nested.tenantKey || nested.tenantkey || root.tenantKey || root.tenantkey || "";
444
660
  return {
@@ -627,7 +843,7 @@ var E10AuthSession = class _E10AuthSession {
627
843
  }
628
844
  static fromFile(filePath, baseUrlFallback, passportUrlFallback) {
629
845
  try {
630
- const raw = readFileSync2(filePath, "utf-8");
846
+ const raw = readFileSync3(filePath, "utf-8");
631
847
  const data = parseAuthFile(raw);
632
848
  if (!data || !data.cookies?.ETEAMSID || !data.baseUrl) return null;
633
849
  return new _E10AuthSession(data, filePath, baseUrlFallback, passportUrlFallback);
@@ -816,47 +1032,6 @@ var E10_XIAOE_HOST_CREDENTIAL_MISSING_MESSAGE = "E10 \u767B\u5F55\u6001\u4E0D\u5
816
1032
  var E10_XIAOE_NETWORK_UNAVAILABLE_MESSAGE = "\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5 E10\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
817
1033
  var E10_SESSION_EXPIRED_MESSAGE = `E10 \u767B\u5F55\u6001\u5DF2\u5931\u6548\uFF0C\u672C\u6B21\u64CD\u4F5C\u5DF2\u505C\u6B62\u3002${E10_REAUTH_GUIDANCE}`;
818
1034
 
819
- // src/core/package-paths.ts
820
- import { existsSync as existsSync3, realpathSync } from "node:fs";
821
- import { dirname as dirname2, join, resolve as resolve4 } from "node:path";
822
- import { fileURLToPath, pathToFileURL } from "node:url";
823
- var cachedRoot;
824
- function entryDirectory(entry) {
825
- const absoluteEntry = resolve4(entry);
826
- try {
827
- return dirname2(realpathSync(absoluteEntry));
828
- } catch {
829
- return dirname2(absoluteEntry);
830
- }
831
- }
832
- function packageRootDir() {
833
- if (cachedRoot) return cachedRoot;
834
- const seeds = [];
835
- const entry = process.argv[1];
836
- if (entry) seeds.push(entryDirectory(entry));
837
- seeds.push(dirname2(fileURLToPath(import.meta.url)));
838
- for (const seed of seeds) {
839
- let dir = seed;
840
- for (let depth = 0; depth < 10; depth += 1) {
841
- if (existsSync3(join(dir, "package.json"))) {
842
- cachedRoot = dir;
843
- return dir;
844
- }
845
- const parent = dirname2(dir);
846
- if (parent === dir) break;
847
- dir = parent;
848
- }
849
- }
850
- cachedRoot = process.cwd();
851
- return cachedRoot;
852
- }
853
- function packagePath(...segments) {
854
- return join(packageRootDir(), ...segments);
855
- }
856
- function packageFileUrl(...segments) {
857
- return pathToFileURL(packagePath(...segments));
858
- }
859
-
860
1035
  // src/core/runtime-agent.ts
861
1036
  var XIAOE_RUNTIME_AGENT_ALIASES = /* @__PURE__ */ new Set([
862
1037
  "xiaoe",
@@ -879,9 +1054,10 @@ function isXiaoERuntime(options) {
879
1054
 
880
1055
  // src/internal/e10/auth/xiaoe.ts
881
1056
  import { execFile } from "node:child_process";
882
- import { accessSync, constants as fsConstants, existsSync as existsSync4, readFileSync as readFileSync3, readdirSync as readdirSync2, statSync } from "node:fs";
1057
+ import { accessSync, constants as fsConstants, existsSync as existsSync4, readFileSync as readFileSync4, readdirSync as readdirSync2, statSync } from "node:fs";
883
1058
  import { homedir as homedir2 } from "node:os";
884
- import { join as join2 } from "node:path";
1059
+ import { join } from "node:path";
1060
+ var DEFAULT_E10_LOGIN_BASE_URL = "https://weapp.eteams.cn";
885
1061
  var DEFAULT_E10_BASE_URL = "https://www.e-cology.com.cn";
886
1062
  var XIAOE_AGENT_TYPE = "XiaoE";
887
1063
  var XIAOE_UNIFIED_LOGIN_MAP_ENV_KEYS = [
@@ -1245,6 +1421,12 @@ function resolveXiaoEConfiguredBaseUrl(env) {
1245
1421
  if (firstCredential?.baseUrl) return normalizeUrl(firstCredential.baseUrl);
1246
1422
  return "";
1247
1423
  }
1424
+ function isXiaoEHostedEnvironment(env = process.env) {
1425
+ return resolveXiaoEClientType(env) !== void 0 || hasXiaoEPlatformCredential(env) || hasXiaoEEnv(env);
1426
+ }
1427
+ function resolveDefaultE10BaseUrl(env = process.env) {
1428
+ return isXiaoEHostedEnvironment(env) ? DEFAULT_E10_BASE_URL : DEFAULT_E10_LOGIN_BASE_URL;
1429
+ }
1248
1430
  function uniqueStrings(values) {
1249
1431
  const seen = /* @__PURE__ */ new Set();
1250
1432
  const result = [];
@@ -1262,15 +1444,15 @@ function xiaoETokenScriptCandidatePaths(env = process.env) {
1262
1444
  const localAppData = envString(env, "LOCALAPPDATA");
1263
1445
  const userProfile = envString(env, "USERPROFILE");
1264
1446
  return uniqueStrings([
1265
- localAppData ? join2(localAppData, "xiaoeUserData", "tokens.py") : "",
1266
- userProfile ? join2(userProfile, "AppData", "Local", "xiaoeUserData", "tokens.py") : ""
1447
+ localAppData ? join(localAppData, "xiaoeUserData", "tokens.py") : "",
1448
+ userProfile ? join(userProfile, "AppData", "Local", "xiaoeUserData", "tokens.py") : ""
1267
1449
  ]);
1268
1450
  }
1269
1451
  const envHome = envString(env, "HOME");
1270
1452
  const nodeHome = envHome ? "" : homedir2();
1271
1453
  return uniqueStrings([
1272
- envHome ? join2(envHome, "Library", "Application Support", "xiaoeUserData", "tokens.py") : "",
1273
- nodeHome ? join2(nodeHome, "Library", "Application Support", "xiaoeUserData", "tokens.py") : ""
1454
+ envHome ? join(envHome, "Library", "Application Support", "xiaoeUserData", "tokens.py") : "",
1455
+ nodeHome ? join(nodeHome, "Library", "Application Support", "xiaoeUserData", "tokens.py") : ""
1274
1456
  ]);
1275
1457
  }
1276
1458
  function xiaoETokenScriptPath(env = process.env) {
@@ -1299,7 +1481,7 @@ function isExecutableFile(path) {
1299
1481
  function listXiaoEPythonRuntimeDirectories(resourcesRoot) {
1300
1482
  if (!resourcesRoot || !existsSync4(resourcesRoot)) return [];
1301
1483
  try {
1302
- return readdirSync2(resourcesRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory() && /^Python3(?:[-_.]\d[\d.]*)?$/iu.test(entry.name)).map((entry) => join2(resourcesRoot, entry.name)).sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
1484
+ return readdirSync2(resourcesRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory() && /^Python3(?:[-_.]\d[\d.]*)?$/iu.test(entry.name)).map((entry) => join(resourcesRoot, entry.name)).sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
1303
1485
  } catch {
1304
1486
  return [];
1305
1487
  }
@@ -1308,7 +1490,7 @@ function listExecutablePythonFiles(directory, platform) {
1308
1490
  if (!directory || !existsSync4(directory)) return [];
1309
1491
  try {
1310
1492
  const pattern = platform === "win32" ? /^python(?:3(?:\.\d+)*)?\.exe$/iu : /^python3(?:\.\d+)*$/u;
1311
- return readdirSync2(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && pattern.test(entry.name)).map((entry) => join2(directory, entry.name)).filter(isExecutableFile).sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
1493
+ return readdirSync2(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && pattern.test(entry.name)).map((entry) => join(directory, entry.name)).filter(isExecutableFile).sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
1312
1494
  } catch {
1313
1495
  return [];
1314
1496
  }
@@ -1319,7 +1501,7 @@ function xiaoEClientPythonCandidates(env = process.env, platform = process.platf
1319
1501
  const envHome = envString(env, "HOME");
1320
1502
  const nodeHome = homedir2();
1321
1503
  for (const home of uniqueStrings([envHome, nodeHome])) {
1322
- appRoots.push(join2(home, "Applications", "\u667A\u80FD\u5C0Fe.app"));
1504
+ appRoots.push(join(home, "Applications", "\u667A\u80FD\u5C0Fe.app"));
1323
1505
  }
1324
1506
  appRoots.push("/Applications/\u667A\u80FD\u5C0Fe.app");
1325
1507
  } else if (platform === "win32") {
@@ -1332,19 +1514,19 @@ function xiaoEClientPythonCandidates(env = process.env, platform = process.platf
1332
1514
  const appNames = ["\u667A\u80FD\u5C0Fe", "XiaoE", "XiaoEClient", "XiaoEAI"];
1333
1515
  if (localAppData) {
1334
1516
  for (const appName of appNames) {
1335
- appRoots.push(join2(localAppData, "Programs", appName), join2(localAppData, appName));
1517
+ appRoots.push(join(localAppData, "Programs", appName), join(localAppData, appName));
1336
1518
  }
1337
1519
  }
1338
1520
  for (const programFilesRoot of programFiles) {
1339
- for (const appName of appNames) appRoots.push(join2(programFilesRoot, appName));
1521
+ for (const appName of appNames) appRoots.push(join(programFilesRoot, appName));
1340
1522
  }
1341
1523
  }
1342
1524
  const candidates = [];
1343
1525
  for (const appRoot of uniqueStrings(appRoots)) {
1344
- const resourcesRoots = platform === "darwin" ? [join2(appRoot, "Contents", "Resources")] : [join2(appRoot, "Resources"), appRoot];
1526
+ const resourcesRoots = platform === "darwin" ? [join(appRoot, "Contents", "Resources")] : [join(appRoot, "Resources"), appRoot];
1345
1527
  for (const resourcesRoot of resourcesRoots) {
1346
1528
  for (const runtimeRoot of listXiaoEPythonRuntimeDirectories(resourcesRoot)) {
1347
- const executableDirectories = platform === "win32" ? [runtimeRoot, join2(runtimeRoot, "bin")] : [join2(runtimeRoot, "bin")];
1529
+ const executableDirectories = platform === "win32" ? [runtimeRoot, join(runtimeRoot, "bin")] : [join(runtimeRoot, "bin")];
1348
1530
  for (const executableDirectory of executableDirectories) {
1349
1531
  candidates.push(...listExecutablePythonFiles(executableDirectory, platform));
1350
1532
  }
@@ -1555,10 +1737,10 @@ async function resolveXiaoEBundledEnvScriptCredential(baseUrl, env = process.env
1555
1737
  function xiaoEClientRobotsRoot(env = process.env) {
1556
1738
  if (process.platform === "win32") {
1557
1739
  const localAppData = envString(env, "LOCALAPPDATA");
1558
- return localAppData ? join2(localAppData, "XiaoE", "Robots") : "";
1740
+ return localAppData ? join(localAppData, "XiaoE", "Robots") : "";
1559
1741
  }
1560
1742
  const home = envString(env, "HOME") || homedir2();
1561
- return home ? join2(home, "Library", "Application Support", "XiaoE", "Robots") : "";
1743
+ return home ? join(home, "Library", "Application Support", "XiaoE", "Robots") : "";
1562
1744
  }
1563
1745
  function isFile(path) {
1564
1746
  if (!path || !existsSync4(path)) return false;
@@ -1588,15 +1770,15 @@ function listXiaoEClientSettingsFiles(root) {
1588
1770
  if (!isDirectory(directory)) return;
1589
1771
  try {
1590
1772
  for (const entry of readdirSync2(directory, { withFileTypes: true })) {
1591
- if (entry.isDirectory()) addCandidate(join2(directory, entry.name, "user_settings.json"));
1773
+ if (entry.isDirectory()) addCandidate(join(directory, entry.name, "user_settings.json"));
1592
1774
  }
1593
1775
  } catch {
1594
1776
  }
1595
1777
  };
1596
- addCandidate(join2(root, "user_settings.json"));
1778
+ addCandidate(join(root, "user_settings.json"));
1597
1779
  addChildSettings(root);
1598
- const robotsRoot = join2(root, "Robots");
1599
- addCandidate(join2(robotsRoot, "user_settings.json"));
1780
+ const robotsRoot = join(root, "Robots");
1781
+ addCandidate(join(robotsRoot, "user_settings.json"));
1600
1782
  addChildSettings(robotsRoot);
1601
1783
  return uniqueStrings(candidates);
1602
1784
  }
@@ -1640,7 +1822,7 @@ function hasXiaoEPlatformCredential(env = process.env) {
1640
1822
  function readXiaoEClientCredential(env = process.env) {
1641
1823
  for (const settingsFile of xiaoEClientSettingsCandidateFiles(env)) {
1642
1824
  try {
1643
- const parsed = JSON.parse(readFileSync3(settingsFile, "utf8"));
1825
+ const parsed = JSON.parse(readFileSync4(settingsFile, "utf8"));
1644
1826
  const authToken = readString(parsed, "session_id", "sessionId");
1645
1827
  const erpaUrl = normalizeUrl(readString(parsed, "erpa", "erpa_url", "erpaUrl"));
1646
1828
  if (authToken && erpaUrl) return { authToken, erpaUrl, source: XIAOE_CLIENT_SETTINGS_SOURCE };
@@ -1810,7 +1992,7 @@ function resolveXiaoEPreferredBaseUrl(options) {
1810
1992
  if (configured) return configured;
1811
1993
  const profileBaseUrl = normalizeUrl(options.profileBaseUrl || "");
1812
1994
  if (profileBaseUrl) return profileBaseUrl;
1813
- return DEFAULT_E10_BASE_URL;
1995
+ return resolveDefaultE10BaseUrl(env);
1814
1996
  }
1815
1997
  function createXiaoEUnifiedLoginUnavailableError(baseUrl = "") {
1816
1998
  const target = normalizeUrl(baseUrl);
@@ -1882,7 +2064,12 @@ async function saveXiaoEUnifiedLogin(input) {
1882
2064
  });
1883
2065
  }
1884
2066
  const tenantKey = userInfo.tenantKey || input.tenantKeyFallback || "";
1885
- const profile = input.profileHint || profileNameFromUrl(baseUrl);
2067
+ const profile = resolveLoginProfileName({
2068
+ derivedName: profileNameFromUrl(baseUrl),
2069
+ baseUrl,
2070
+ hostKey: input.hostKey,
2071
+ profileHint: input.profileHint
2072
+ });
1886
2073
  setActiveProfile(profile);
1887
2074
  const cookies = { ETEAMSID: input.eteamsId };
1888
2075
  if (input.rawCookie) cookies.raw = input.rawCookie;
@@ -1909,6 +2096,7 @@ async function saveXiaoEUnifiedLogin(input) {
1909
2096
  };
1910
2097
  const authFile = saveAuthFile(authData, profile);
1911
2098
  saveProfileConfig(baseUrl, baseUrl, profile, tenantKey);
2099
+ upsertAgentHost({ profile, baseUrl, tenantKey, agentType: XIAOE_AGENT_TYPE, hostKey: input.hostKey });
1912
2100
  const session = new E10AuthSession(authData, authFile);
1913
2101
  return {
1914
2102
  session,
@@ -2047,7 +2235,8 @@ async function tryXiaoEUnifiedLogin(options = {}) {
2047
2235
  expiryTimes: credential.expiryTimes,
2048
2236
  tenantKeyFallback: options.tenantKeyFallback,
2049
2237
  profileHint: options.profileHint,
2050
- credentialSource: describeXiaoECredentialSource(credential.source)
2238
+ credentialSource: describeXiaoECredentialSource(credential.source),
2239
+ hostKey: options.hostKey
2051
2240
  });
2052
2241
  noteXiaoEStep(diagnostics, "e10_session:ok");
2053
2242
  if (diagnostics) {
@@ -2090,12 +2279,14 @@ function startFetchTiming() {
2090
2279
  }
2091
2280
 
2092
2281
  export {
2093
- packagePath,
2094
- packageFileUrl,
2095
2282
  normalizeGlobalOptions,
2096
2283
  writeWithRetry,
2097
2284
  readErrorCauseCode,
2098
2285
  getE10AuthRoot,
2286
+ resolveAgentHostKey,
2287
+ lookupAgentHost,
2288
+ resolveLoginProfileName,
2289
+ upsertAgentHost,
2099
2290
  getActiveProfile,
2100
2291
  setActiveProfile,
2101
2292
  switchActiveProfile,
@@ -2107,6 +2298,7 @@ export {
2107
2298
  saveProfileConfig,
2108
2299
  saveAuthFile,
2109
2300
  clearProfileAuthFile,
2301
+ resolveActiveProfileForHost,
2110
2302
  findAuthFile,
2111
2303
  readTeamsCheckUserInfo,
2112
2304
  buildE10CookieHeader,
@@ -2124,6 +2316,7 @@ export {
2124
2316
  summarizeXiaoEFailureKind,
2125
2317
  lastXiaoEFailure,
2126
2318
  hasXiaoEEnv,
2319
+ resolveDefaultE10BaseUrl,
2127
2320
  inspectXiaoEUnifiedLoginSources,
2128
2321
  resolveXiaoEPreferredBaseUrl,
2129
2322
  createXiaoEUnifiedLoginUnavailableError,
@@ -0,0 +1,48 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+
4
+ // src/core/package-paths.ts
5
+ import { existsSync, realpathSync } from "node:fs";
6
+ import { dirname, join, resolve } from "node:path";
7
+ import { fileURLToPath, pathToFileURL } from "node:url";
8
+ var cachedRoot;
9
+ function entryDirectory(entry) {
10
+ const absoluteEntry = resolve(entry);
11
+ try {
12
+ return dirname(realpathSync(absoluteEntry));
13
+ } catch {
14
+ return dirname(absoluteEntry);
15
+ }
16
+ }
17
+ function packageRootDir() {
18
+ if (cachedRoot) return cachedRoot;
19
+ const seeds = [];
20
+ const entry = process.argv[1];
21
+ if (entry) seeds.push(entryDirectory(entry));
22
+ seeds.push(dirname(fileURLToPath(import.meta.url)));
23
+ for (const seed of seeds) {
24
+ let dir = seed;
25
+ for (let depth = 0; depth < 10; depth += 1) {
26
+ if (existsSync(join(dir, "package.json"))) {
27
+ cachedRoot = dir;
28
+ return dir;
29
+ }
30
+ const parent = dirname(dir);
31
+ if (parent === dir) break;
32
+ dir = parent;
33
+ }
34
+ }
35
+ cachedRoot = process.cwd();
36
+ return cachedRoot;
37
+ }
38
+ function packagePath(...segments) {
39
+ return join(packageRootDir(), ...segments);
40
+ }
41
+ function packageFileUrl(...segments) {
42
+ return pathToFileURL(packagePath(...segments));
43
+ }
44
+
45
+ export {
46
+ packagePath,
47
+ packageFileUrl
48
+ };
@@ -9,11 +9,11 @@ import {
9
9
  createE10RequestRuntime,
10
10
  isE10AuthenticationRequired,
11
11
  requireE10Session
12
- } from "./chunk-6NXT4ICB.js";
12
+ } from "./chunk-WVH5ESDA.js";
13
13
  import {
14
14
  E10_SESSION_EXPIRED_MESSAGE,
15
15
  getActiveProfile
16
- } from "./chunk-U6R6FZHD.js";
16
+ } from "./chunk-SFM3M2L3.js";
17
17
 
18
18
  // src/shortcuts/workflow/host.ts
19
19
  var DEFAULT_TIMEOUT_MS = 3e4;