@thinkingai/ae-cli 6.1.42 → 6.1.43

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 (114) hide show
  1. package/README.md +14 -4
  2. package/README.zh.md +14 -4
  3. package/bin/ae-cli.js +3 -0
  4. package/bin/heari/commander-LICENSE +22 -0
  5. package/bin/heari/engine.mjs +6136 -0
  6. package/bin/heari/package.json +6 -0
  7. package/bin/heari.mjs +29 -0
  8. package/cli-installation-guide.md +3 -5
  9. package/dist/{ai-monitor-E62FT3TT.js → ai-monitor-4VPHXQTL.js} +7 -6
  10. package/dist/ai-monitor.js +10 -9
  11. package/dist/{auth-SDK5OAGP.js → auth-RDSS2LUT.js} +18 -16
  12. package/dist/{automation-IMDCJUML.js → automation-VLIWG2XY.js} +5 -4
  13. package/dist/{capability-F6YWGPZZ.js → capability-CUOEIB5F.js} +5 -4
  14. package/dist/{chunk-KE5WGBXS.js → chunk-3DTMWDJX.js} +1 -1
  15. package/dist/{chunk-KAZ5FWPB.js → chunk-3FSYICDW.js} +6 -5
  16. package/dist/{chunk-ZK6KEGUR.js → chunk-3TV24AVQ.js} +10 -10
  17. package/dist/{chunk-DTODOQ6T.js → chunk-3U75VLCP.js} +1 -1
  18. package/dist/{chunk-N2QILIGH.js → chunk-4MOCV6HU.js} +1 -1
  19. package/dist/{chunk-M2OCZRVX.js → chunk-6VLHJKDD.js} +2 -2
  20. package/dist/{chunk-WG27BD67.js → chunk-7KBENPQF.js} +8 -16
  21. package/dist/{chunk-CDBW5RE6.js → chunk-BFSWGXM2.js} +3 -3
  22. package/dist/{chunk-UK7HQ4IL.js → chunk-CBNE2S44.js} +2 -2
  23. package/dist/{chunk-UWQXGF44.js → chunk-FEYZBUFQ.js} +4 -353
  24. package/dist/chunk-FKTVD63C.js +369 -0
  25. package/dist/{chunk-2H3SFJE3.js → chunk-FKVG7LOP.js} +5 -3
  26. package/dist/{chunk-GTENC5CO.js → chunk-IAZ4AMVY.js} +6 -4
  27. package/dist/{chunk-ZSKLELL7.js → chunk-LSELMDKQ.js} +2 -2
  28. package/dist/{chunk-2RORKIF6.js → chunk-NJGB4YOH.js} +2 -2
  29. package/dist/{chunk-L7MT53VM.js → chunk-PWG5IGCP.js} +1 -1
  30. package/dist/{chunk-DIYDOOBL.js → chunk-TFEGYB4X.js} +2 -2
  31. package/dist/{chunk-DZRQGI2Z.js → chunk-ZPAOEDK7.js} +5 -3
  32. package/dist/{compat-check-J5K3NO5G.js → compat-check-L3C7HCVG.js} +4 -3
  33. package/dist/{config-O3W6XLHO.js → config-LAF5MMYK.js} +6 -5
  34. package/dist/context-E4YKECC4.js +350 -0
  35. package/dist/{evaluation-OZM54MES.js → evaluation-I4IJ25CY.js} +4 -3
  36. package/dist/heari-cli-login.js +83 -0
  37. package/dist/index.js +42 -34
  38. package/dist/{memory-VPOPSU52.js → memory-Y7LPCRP4.js} +5 -4
  39. package/dist/{metadata-3GA2N27I.js → metadata-T6HYAU7E.js} +7 -6
  40. package/dist/{model-2F2354QP.js → model-2BNN72MN.js} +7 -6
  41. package/dist/{personal-semantic-preference-T2HFF2V4.js → personal-semantic-preference-WCZBOA7V.js} +42 -16
  42. package/dist/{project-semantic-WJOP2HGJ.js → project-semantic-WW5AZST3.js} +266 -17
  43. package/dist/{sync-K65X7ODO.js → sync-6PL25V42.js} +13 -12
  44. package/dist/{te-agent-QWZC36YS.js → te-agent-KXLDW4NE.js} +6 -5
  45. package/dist/{te-analysis-7E2GVKOR.js → te-analysis-KKRECQ7F.js} +311 -52
  46. package/dist/{te-community-NQNSLNON.js → te-community-6RGX7IWH.js} +8 -6
  47. package/dist/{te-dataops-PMI7UX36.js → te-dataops-RSPBC6WJ.js} +726 -220
  48. package/dist/{te-engage-EZBV5IPQ.js → te-engage-FIPP5L2Z.js} +6 -5
  49. package/dist/{te-experiment-RDB3TYBG.js → te-experiment-KQ5CBYKI.js} +86 -10
  50. package/dist/{te-kb-OWPJB243.js → te-kb-XYSDXZUG.js} +32 -11
  51. package/dist/{te-system-Z4VEB6PL.js → te-system-QSOHAP7M.js} +7 -6
  52. package/dist/{te-team-NCMN34IL.js → te-team-R6MZ4RK2.js} +6 -5
  53. package/dist/{things-UBMLTY3S.js → things-DEONFUGS.js} +6 -5
  54. package/dist/{update-LYVYF3KJ.js → update-C6G4P3C7.js} +5 -4
  55. package/dist/{web-runtime-XJWDFVP3.js → web-runtime-UGKPTBOK.js} +12 -10
  56. package/dist/{workspace-W5ZPVWJS.js → workspace-OBIIE5FN.js} +5 -4
  57. package/package.json +7 -5
  58. package/skills/ae-analysis/SKILL.md +41 -16
  59. package/skills/ae-analysis/references/adhoc_export.md +1 -1
  60. package/skills/ae-analysis/references/adhoc_run.md +8 -2
  61. package/skills/ae-analysis/references/analysis_drilldown_contract.md +1 -1
  62. package/skills/ae-analysis/references/audience_scheduling.md +30 -0
  63. package/skills/ae-analysis/references/business_semantics_workspace.md +57 -0
  64. package/skills/ae-analysis/references/command_index.md +18 -13
  65. package/skills/ae-analysis/references/context_prepare.md +49 -0
  66. package/skills/ae-analysis/references/drilldown_entities_export.md +1 -1
  67. package/skills/ae-analysis/references/drilldown_entities_run.md +1 -1
  68. package/skills/ae-analysis/references/drilldown_user_events_export.md +3 -1
  69. package/skills/ae-analysis/references/drilldown_user_events_run.md +2 -1
  70. package/skills/ae-analysis/references/governance_recommendation_export.md +1 -1
  71. package/skills/ae-analysis/references/personal_semantic_preference_add.md +5 -1
  72. package/skills/ae-analysis/references/personal_semantic_preference_get.md +4 -2
  73. package/skills/ae-analysis/references/personal_semantic_preference_list.md +7 -6
  74. package/skills/ae-analysis/references/personal_semantic_preference_submit.md +1 -1
  75. package/skills/ae-analysis/references/personal_semantic_preference_update.md +5 -1
  76. package/skills/ae-analysis/references/project_info_get.md +4 -0
  77. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +1 -1
  78. package/skills/ae-analysis/references/project_semantic_setup.md +60 -0
  79. package/skills/ae-analysis/references/report_get.md +2 -0
  80. package/skills/ae-analysis/references/report_presentation.md +55 -0
  81. package/skills/ae-analysis/references/report_update.md +4 -2
  82. package/skills/ae-analysis/references/system_openapi_token_batch_generate.md +20 -0
  83. package/skills/ae-analysis/references/system_openapi_token_get.md +14 -0
  84. package/skills/ae-analysis/references/user_cluster_create.md +3 -1
  85. package/skills/ae-analysis/references/user_cluster_models.md +2 -0
  86. package/skills/ae-analysis/references/user_cluster_update.md +5 -3
  87. package/skills/ae-analysis/references/user_tag_create.md +4 -22
  88. package/skills/ae-analysis/references/user_tag_models.md +8 -0
  89. package/skills/ae-analysis/references/user_tag_update.md +6 -14
  90. package/skills/ae-analysis/scripts/read-semantic-catalog.mjs +40 -0
  91. package/skills/ae-capability/SKILL.md +5 -1
  92. package/skills/ae-dataops/SKILL.md +9 -6
  93. package/skills/ae-dataops/references/dataops-flow-create.md +64 -47
  94. package/skills/ae-dataops/references/dataops-flow-monitor.md +4 -2
  95. package/skills/ae-dataops/references/dataops-flow-python.md +109 -0
  96. package/skills/ae-experiment/SKILL.md +9 -1
  97. package/skills/ae-experiment/references/manage_feature_fixed_value.md +73 -0
  98. package/skills/ae-experiment/references/save_feature.md +14 -1
  99. package/skills/ae-heari-research/SKILL.md +40 -0
  100. package/skills/ae-heari-research/references/design.md +35 -0
  101. package/skills/ae-heari-research/references/examples.md +46 -0
  102. package/skills/ae-heari-research/references/platform-auth.md +35 -0
  103. package/skills/ae-heari-research/references/platform-research.md +74 -0
  104. package/skills/ae-heari-research/references/platform-results.md +73 -0
  105. package/skills/ae-heari-research/references/platform.md +34 -0
  106. package/skills/ae-heari-research/references/probing-screening.md +31 -0
  107. package/skills/ae-heari-research/references/quality.md +44 -0
  108. package/skills/ae-kb/SKILL.md +10 -5
  109. package/skills/ae-kb/references/analysis-workflow.md +19 -10
  110. package/skills/ae-kb/references/query-workflow.md +34 -17
  111. package/skills/ae-kb-discovery/SKILL.md +4 -3
  112. package/skills/ae-onboarding/SKILL.md +3 -3
  113. package/dist/context-WJQGJD6F.js +0 -139
  114. package/dist/{data-integration-KMJWYAKK.js → data-integration-SCYYZLWI.js} +4 -4
@@ -1,26 +1,12 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
- getActiveHost,
4
3
  getConfigDir,
5
- getFallbackCliToken,
6
- readSandboxCliTokenEntry,
7
- safeJsonParse,
8
- safeReadJsonFile
4
+ safeJsonParse
9
5
  } from "./chunk-IGU3R2JD.js";
10
6
  import {
11
- externalCliTokenRequestOptions,
12
7
  logger,
13
- normalizeUrl,
14
- readExternalCliToken
8
+ normalizeUrl
15
9
  } from "./chunk-MTK4ZE7W.js";
16
- import {
17
- PermissionError
18
- } from "./chunk-3ZQY7SLZ.js";
19
-
20
- // src/core/internal-call-source.ts
21
- function internalCallSourceHeaders() {
22
- return {};
23
- }
24
10
 
25
11
  // src/core/secure-store.ts
26
12
  import crypto from "crypto";
@@ -547,352 +533,17 @@ var CredentialStoreUnreadableError = class extends Error {
547
533
  }
548
534
  };
549
535
 
550
- // src/core/cli-token.ts
551
- import crypto2 from "crypto";
552
- import fs2 from "fs";
553
- import path2 from "path";
554
- var CLI_TOKEN_GENERATE_PATH = "/v1/ta/cli/token/generate";
555
- var CLI_TOKEN_RENEW_PATH = "/v1/ta/cli/token/renew";
556
- var CLI_TOKEN_VALIDATE_PATH = "/v1/ta/cli/token/validate";
557
- function safeReturnCode(value) {
558
- return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
559
- }
560
- var CliTokenValidationUnavailableError = class extends Error {
561
- constructor(message) {
562
- super(message);
563
- this.name = "CliTokenValidationUnavailableError";
564
- }
565
- };
566
- function isExplicitCliTokenRejection(data, responseText) {
567
- const code = String(data?.code ?? data?.error?.code ?? "");
568
- const message = String(data?.return_message ?? data?.message ?? data?.error?.message ?? responseText);
569
- return /cli[_-]?token[_-]?(invalid|expired)/i.test(code) || /cli[-_\s]?token.*\b(invalid|expired)\b/i.test(message) || /\b(invalid|expired)\b.*cli[-_\s]?token/i.test(message);
570
- }
571
- function cliAccessDisabledDetails(data, responseText) {
572
- const code = String(data?.code ?? data?.error?.code ?? "");
573
- const message = String(data?.return_message ?? data?.message ?? data?.error?.message ?? responseText);
574
- if (code !== "CLI_ACCESS_DISABLED" && !message.includes("CLI_ACCESS_DISABLED")) return void 0;
575
- return {
576
- message: message || "CLI access is disabled for this account.",
577
- hint: data?.hint ?? data?.error?.hint
578
- };
579
- }
580
- function optionalNonEmptyString(...values) {
581
- return values.find((value) => typeof value === "string" && value.trim());
582
- }
583
- function optionalIsoDate(...values) {
584
- const value = values.find((candidate) => typeof candidate === "string" && candidate.trim() || typeof candidate === "number");
585
- if (value === void 0) return void 0;
586
- const date = new Date(value);
587
- return Number.isFinite(date.getTime()) ? date.toISOString() : void 0;
588
- }
589
- var cliTokenCache = /* @__PURE__ */ new Map();
590
- var renewedLocalDate = /* @__PURE__ */ new Map();
591
- var renewInFlight = /* @__PURE__ */ new Map();
592
- function tokenFingerprint2(cliToken) {
593
- return crypto2.createHash("sha256").update(cliToken).digest("hex").slice(0, 16);
594
- }
595
- function renewKey(hostUrl, cliToken) {
596
- return `${normalizeUrl(hostUrl)}#${tokenFingerprint2(cliToken)}`;
597
- }
598
- function renewStateFilePath() {
599
- return path2.join(getConfigDir(), "cli-token-renew.json");
600
- }
601
- function localRenewDate(now = /* @__PURE__ */ new Date()) {
602
- const y = now.getFullYear();
603
- const m = String(now.getMonth() + 1).padStart(2, "0");
604
- const d = String(now.getDate()).padStart(2, "0");
605
- return `${y}-${m}-${d}`;
606
- }
607
- function loadRenewStore() {
608
- try {
609
- const file = renewStateFilePath();
610
- if (!fs2.existsSync(file)) return {};
611
- const data = safeReadJsonFile(file);
612
- return data && typeof data === "object" && !Array.isArray(data) ? data : {};
613
- } catch {
614
- return {};
615
- }
616
- }
617
- function saveRenewStore(store) {
618
- const file = renewStateFilePath();
619
- if (Object.keys(store).length === 0) {
620
- try {
621
- fs2.rmSync(file, { force: true });
622
- } catch {
623
- }
624
- return;
625
- }
626
- const dir = getConfigDir();
627
- if (!fs2.existsSync(dir)) fs2.mkdirSync(dir, { recursive: true });
628
- fs2.writeFileSync(file, JSON.stringify(store, null, 2), { encoding: "utf8", mode: 384 });
629
- try {
630
- fs2.chmodSync(file, 384);
631
- } catch {
632
- }
633
- }
634
- function persistedRenewDate(hostUrl, cliToken) {
635
- const credential = getActiveCredential(hostUrl);
636
- if (credential?.cliToken === cliToken && credential.lastRenewedOn) return credential.lastRenewedOn;
637
- return loadRenewStore()[renewKey(hostUrl, cliToken)]?.date;
638
- }
639
- function markRenewSucceeded(hostUrl, cliToken, date) {
640
- const key = renewKey(hostUrl, cliToken);
641
- renewedLocalDate.set(key, date);
642
- markCredentialRenewed(hostUrl, cliToken, date);
643
- const store = loadRenewStore();
644
- store[key] = { date };
645
- saveRenewStore(store);
646
- }
647
- function clearCliTokenCache(hostUrl) {
648
- if (!hostUrl) {
649
- cliTokenCache.clear();
650
- renewedLocalDate.clear();
651
- renewInFlight.clear();
652
- return;
653
- }
654
- const normalizedHost = normalizeUrl(hostUrl);
655
- cliTokenCache.delete(normalizedHost);
656
- for (const key of [...renewedLocalDate.keys()]) {
657
- if (key.startsWith(`${normalizedHost}#`)) renewedLocalDate.delete(key);
658
- }
659
- for (const key of [...renewInFlight.keys()]) {
660
- if (key.startsWith(`${normalizedHost}#`)) renewInFlight.delete(key);
661
- }
662
- }
663
- async function generateCliToken(hostUrl, accessToken, signal) {
664
- if (!accessToken) throw new Error("CLI token generation requires the access token returned by auth login.");
665
- const url = `${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_GENERATE_PATH}`;
666
- const resp = await fetch(url, {
667
- method: "GET",
668
- headers: { Authorization: `bearer ${accessToken}`, ...internalCallSourceHeaders() },
669
- signal,
670
- ...signal ? { redirect: "error" } : {}
671
- });
672
- if (!resp.ok) {
673
- if (resp.status === 403) {
674
- const text = await resp.text();
675
- let body = {};
676
- try {
677
- body = text ? safeJsonParse(text) : {};
678
- } catch {
679
- }
680
- const serviceMessage = body.message ?? body.return_message;
681
- const code = body.code === "CLI_ACCESS_DISABLED" || String(serviceMessage).includes("CLI_ACCESS_DISABLED") ? "CLI_ACCESS_DISABLED" : void 0;
682
- throw new PermissionError(
683
- code === "CLI_ACCESS_DISABLED" ? "CLI access is disabled for this account." : "You do not have permission to generate a CLI token.",
684
- code
685
- );
686
- }
687
- throw new Error(`CLI token generate HTTP error: ${resp.status} ${resp.statusText}`);
688
- }
689
- const data = safeJsonParse(await resp.text());
690
- if (data.return_code !== 0) {
691
- const serviceMessage = data.return_message || data.message;
692
- if (data.code === "CLI_ACCESS_DISABLED" || String(serviceMessage).includes("CLI_ACCESS_DISABLED")) {
693
- throw new PermissionError(
694
- "CLI access is disabled for this account.",
695
- "CLI_ACCESS_DISABLED"
696
- );
697
- }
698
- const code = safeReturnCode(data.return_code);
699
- throw new Error(`CLI token generation failed${code ? ` (code: ${code})` : ""}`);
700
- }
701
- const cliToken = data.data?.userSecret ?? data.data?.user_secret;
702
- if (!cliToken) throw new Error("CLI token generate error: empty userSecret in response");
703
- return cliToken;
704
- }
705
- async function validateCliTokenOnServer(hostUrl, cliToken, signal) {
706
- const url = `${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_VALIDATE_PATH}`;
707
- let resp;
708
- try {
709
- resp = await fetch(url, {
710
- method: "GET",
711
- headers: { Accept: "application/json", "cli-token": cliToken, ...internalCallSourceHeaders() },
712
- ...externalCliTokenRequestOptions(url),
713
- ...signal ? { redirect: "error" } : {},
714
- signal
715
- });
716
- } catch (error) {
717
- signal?.throwIfAborted();
718
- throw new CliTokenValidationUnavailableError(`Unable to validate CLI token for ${hostUrl}: ${error.message}`);
719
- }
720
- const responseText = await resp.text();
721
- let body;
722
- try {
723
- body = safeJsonParse(responseText);
724
- } catch {
725
- body = void 0;
726
- }
727
- const accessDisabled = cliAccessDisabledDetails(body, responseText);
728
- if (accessDisabled) {
729
- throw new PermissionError(accessDisabled.message, "CLI_ACCESS_DISABLED", accessDisabled.hint);
730
- }
731
- if (isExplicitCliTokenRejection(body, responseText)) {
732
- throw new SecureStoreAuthError(`CLI token is invalid or expired for ${hostUrl}.`);
733
- }
734
- if (!resp.ok) {
735
- throw new CliTokenValidationUnavailableError(
736
- `CLI token validation is unavailable for ${hostUrl} (HTTP ${resp.status} ${resp.statusText})`
737
- );
738
- }
739
- if (body?.return_code !== 0) {
740
- throw new CliTokenValidationUnavailableError(`CLI token validation returned an unsupported response for ${hostUrl}`);
741
- }
742
- const data = body?.data;
743
- const openId = optionalNonEmptyString(data?.openId, data?.open_id);
744
- const loginName = optionalNonEmptyString(data?.loginName, data?.login_name);
745
- const userName = optionalNonEmptyString(data?.userName, data?.user_name);
746
- const account = openId && loginName && userName ? { openId, loginName, userName } : void 0;
747
- const cliTokenExpiresAt = optionalIsoDate(data?.expiresAt, data?.expires_at);
748
- return {
749
- ...account ? { account } : {},
750
- ...cliTokenExpiresAt ? { cliTokenExpiresAt } : {}
751
- };
752
- }
753
- async function renewCliTokenOnServer(hostUrl, cliToken, external = false, signal) {
754
- const url = new URL(`${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_RENEW_PATH}`);
755
- if (!external) url.searchParams.set("cli-token", cliToken);
756
- const resp = await fetch(url.toString(), {
757
- method: "GET",
758
- headers: { Accept: "application/json", ...external ? { "cli-token": cliToken } : {}, ...internalCallSourceHeaders() },
759
- ...externalCliTokenRequestOptions(url.toString()),
760
- signal
761
- });
762
- const text = await resp.text();
763
- let data;
764
- try {
765
- data = text ? safeJsonParse(text) : {};
766
- } catch {
767
- data = {};
768
- }
769
- if (!resp.ok) throw new Error(`CLI token renew HTTP error: ${resp.status} ${resp.statusText}`);
770
- if (data?.return_code !== void 0 && data.return_code !== 0) {
771
- throw new Error(`CLI token renew error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
772
- }
773
- }
774
- async function maybeRenewCliTokenDaily(hostUrl, cliToken, external = false, signal) {
775
- signal?.throwIfAborted();
776
- const key = renewKey(hostUrl, cliToken);
777
- const today = localRenewDate();
778
- if (renewedLocalDate.get(key) === today || !external && persistedRenewDate(hostUrl, cliToken) === today) {
779
- renewedLocalDate.set(key, today);
780
- return;
781
- }
782
- let attempt = renewInFlight.get(key);
783
- if (!attempt || attempt.controller.signal.aborted) {
784
- const current = { controller: new AbortController(), promise: Promise.resolve(), waiters: 0 };
785
- current.promise = (async () => {
786
- try {
787
- await renewCliTokenOnServer(hostUrl, cliToken, external, current.controller.signal);
788
- current.controller.signal.throwIfAborted();
789
- if (external) renewedLocalDate.set(key, today);
790
- else markRenewSucceeded(hostUrl, cliToken, today);
791
- logger.info(`cli-token: renewed for ${normalizeUrl(hostUrl)} (local day ${today})`);
792
- } catch (error) {
793
- if (!current.controller.signal.aborted) {
794
- logger.warn(`cli-token: renew failed for ${normalizeUrl(hostUrl)}${external ? "" : `: ${error?.message || error}`}; business call proceeds`);
795
- }
796
- } finally {
797
- if (renewInFlight.get(key) === current) renewInFlight.delete(key);
798
- }
799
- })();
800
- renewInFlight.set(key, current);
801
- attempt = current;
802
- }
803
- attempt.waiters++;
804
- let onAbort = () => void 0;
805
- try {
806
- const aborted = signal && new Promise((_resolve, reject) => {
807
- onAbort = () => reject(signal.reason ?? new DOMException("The operation was aborted", "AbortError"));
808
- if (signal.aborted) onAbort();
809
- else signal.addEventListener("abort", onAbort, { once: true });
810
- });
811
- await (aborted ? Promise.race([attempt.promise, aborted]) : attempt.promise);
812
- } finally {
813
- signal?.removeEventListener("abort", onAbort);
814
- if (--attempt.waiters === 0) {
815
- if (renewInFlight.get(key) === attempt) renewInFlight.delete(key);
816
- attempt.controller.abort();
817
- }
818
- }
819
- }
820
- function peekCliToken(hostOverride) {
821
- const external = readExternalCliToken(hostOverride);
822
- if (external) return external.token;
823
- if (process.env.TE_AGENT_CLI_CONFIG_DIR !== void 0) return sessionCliToken(hostOverride);
824
- const hostUrl = hostOverride || getActiveHost();
825
- if (!hostUrl) return void 0;
826
- const normalizedHost = normalizeUrl(hostUrl);
827
- let stored;
828
- try {
829
- stored = loadCliToken(normalizedHost);
830
- } catch (error) {
831
- if (error instanceof CredentialStoreUnreadableError) return void 0;
832
- throw error;
833
- }
834
- if (stored) {
835
- cliTokenCache.set(normalizedHost, stored);
836
- return stored;
837
- }
838
- return cliTokenCache.get(normalizedHost) || getFallbackCliToken(normalizedHost) || void 0;
839
- }
840
- async function getCliToken(hostOverride, signal) {
841
- signal?.throwIfAborted();
842
- const external = readExternalCliToken(hostOverride);
843
- if (external) {
844
- await maybeRenewCliTokenDaily(external.url, external.token, true, signal);
845
- signal?.throwIfAborted();
846
- return external.token;
847
- }
848
- if (process.env.TE_AGENT_CLI_CONFIG_DIR !== void 0) {
849
- const token2 = sessionCliToken(hostOverride);
850
- if (!token2) throw new SecureStoreAuthError("Current session CLI credential is unavailable or does not match the requested host.");
851
- return token2;
852
- }
853
- const resolvedHost = hostOverride || getActiveHost();
854
- if (!resolvedHost) throw new SecureStoreAuthError("No AE host configured. Run: ae-cli auth login --host <url>");
855
- const hostUrl = normalizeUrl(resolvedHost);
856
- const stored = loadCliToken(hostUrl);
857
- let token = stored || getFallbackCliToken(hostUrl) || cliTokenCache.get(hostUrl);
858
- if (!token) {
859
- throw new SecureStoreAuthError(`No stored CLI token for ${hostUrl}. Run: ae-cli auth login --host ${hostUrl}`);
860
- }
861
- cliTokenCache.set(hostUrl, token);
862
- await maybeRenewCliTokenDaily(hostUrl, token, false, signal);
863
- signal?.throwIfAborted();
864
- return token;
865
- }
866
- function sessionCliToken(hostOverride) {
867
- const entry = readSandboxCliTokenEntry();
868
- if (!entry?.token.startsWith("cli_")) return void 0;
869
- if (hostOverride && normalizeUrl(entry.url) !== normalizeUrl(hostOverride)) return void 0;
870
- return entry.token;
871
- }
872
- async function mintCliToken(hostUrl, accessToken, signal) {
873
- logger.info(`Generating CLI token for ${hostUrl}`);
874
- const cliToken = await generateCliToken(hostUrl, accessToken, signal);
875
- cliTokenCache.set(normalizeUrl(hostUrl), cliToken);
876
- return cliToken;
877
- }
878
-
879
536
  export {
880
- internalCallSourceHeaders,
881
537
  assertCredentialsReadable,
882
538
  getActiveCredential,
883
539
  listCredentials,
884
540
  saveCredential,
885
541
  updateCredentialMetadata,
542
+ markCredentialRenewed,
886
543
  activateCredential,
887
544
  removeActiveCredential,
888
545
  clearAllCredentials,
889
546
  loadCliToken,
890
547
  SecureStoreAuthError,
891
- CredentialStoreUnreadableError,
892
- CliTokenValidationUnavailableError,
893
- clearCliTokenCache,
894
- validateCliTokenOnServer,
895
- peekCliToken,
896
- getCliToken,
897
- mintCliToken
548
+ CredentialStoreUnreadableError
898
549
  };