@thinkingai/ae-cli 6.0.41 → 6.0.44

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 (108) hide show
  1. package/dist/{auth-GBMV6TEJ.js → auth-2WTQOP77.js} +3 -3
  2. package/dist/{auth-NDSXE54J.js → auth-77BUFLGC.js} +57 -13
  3. package/dist/{capability-CETVHGXF.js → capability-ENHWPMTG.js} +12 -12
  4. package/dist/{capability-ZSQBMNOE.js → capability-WA37LSIR.js} +12 -12
  5. package/dist/{chunk-AFXA7BRK.js → chunk-4KVPKXFX.js} +5 -5
  6. package/dist/chunk-4SGZG4XY.js +311 -0
  7. package/dist/chunk-6EIJSNBD.js +8 -0
  8. package/dist/chunk-C4MGVGJW.js +13 -0
  9. package/dist/{chunk-4E3DB4MM.js → chunk-EE45RGOO.js} +7 -7
  10. package/dist/{chunk-WZRX4KOH.js → chunk-GT46FPXN.js} +4 -6
  11. package/dist/{chunk-5XUSIK27.js → chunk-ILIU36SU.js} +10 -7
  12. package/dist/{chunk-JHENBQ5B.js → chunk-LYVNONC4.js} +0 -35
  13. package/dist/{chunk-WANVG6SY.js → chunk-MGU2N3HW.js} +7 -7
  14. package/dist/{chunk-JUW4AJXN.js → chunk-P3FGXJTU.js} +12 -7
  15. package/dist/{chunk-FNZA5RZA.js → chunk-QEFCIRNJ.js} +4 -4
  16. package/dist/chunk-QGM4M3NI.js +37 -0
  17. package/dist/{chunk-J2N4PB56.js → chunk-QI524WPY.js} +4 -4
  18. package/dist/{chunk-VLWOLBGZ.js → chunk-UOUS37JQ.js} +149 -161
  19. package/dist/{chunk-AXDXJTPC.js → chunk-UW5UN47B.js} +19 -2
  20. package/dist/chunk-VPKZ7I72.js +509 -0
  21. package/dist/chunk-ZZUOD757.js +598 -0
  22. package/dist/{client-L2YDMHQ6.js → client-TKG4WBHN.js} +4 -5
  23. package/dist/{community-report-client-M2RW4MXD.js → community-report-client-FI4LNVYS.js} +3 -2
  24. package/dist/{config-OL2LWGBV.js → config-RE6CMGPK.js} +7 -7
  25. package/dist/data-integration-2MYMANJI.js +3383 -0
  26. package/dist/index.js +74 -40
  27. package/dist/local-data-upload-client-BWHSUQQK.js +167 -0
  28. package/dist/{memory-MUP7PPL7.js → memory-CHRU2F7W.js} +7 -6
  29. package/dist/{memory-U4O5PMXH.js → memory-YK33G4T7.js} +7 -6
  30. package/dist/{metadata-UKZDNLLQ.js → metadata-AXVHAAZG.js} +22 -18
  31. package/dist/{metadata-XXMJFN2M.js → metadata-GGEHHPBE.js} +22 -18
  32. package/dist/{model-JTUEO5M4.js → model-K3KLWIW6.js} +7 -3
  33. package/dist/model-NR3JHFSJ.js +139 -0
  34. package/dist/{sync-MOSFNBVR.js → sync-DAVKYVMW.js} +8 -6
  35. package/dist/sync-FCKOVWWS.js +10261 -0
  36. package/dist/{te-agent-IFKZDHZI.js → te-agent-4BKBODMF.js} +686 -71
  37. package/dist/te-agent-HLW4VTQK.js +3893 -0
  38. package/dist/{te-analysis-3QLLS35K.js → te-analysis-WX7LRVAV.js} +86 -63
  39. package/dist/{te-analysis-YSK2DBVL.js → te-analysis-YKFDBMA6.js} +86 -63
  40. package/dist/{te-community-HNKVTERD.js → te-community-6HPBWJUZ.js} +24 -19
  41. package/dist/{te-community-IWE5B7W6.js → te-community-HLC43QKH.js} +24 -20
  42. package/dist/{te-dataops-KXCEB4CS.js → te-dataops-EJP56W3K.js} +57 -34
  43. package/dist/{te-dataops-KQPYNAE3.js → te-dataops-HDRUXY4K.js} +59 -34
  44. package/dist/{te-engage-6RNGK5GH.js → te-engage-UBHPAJCO.js} +401 -15
  45. package/dist/{te-engage-IRMHTSQK.js → te-engage-WLDTS5J5.js} +401 -15
  46. package/dist/{te-kb-OIH3T6CS.js → te-kb-APXBWBDY.js} +6 -6
  47. package/dist/{te-system-AZ3URMUO.js → te-system-YARIK4S5.js} +7 -4
  48. package/dist/te-system-Z77IKZFN.js +2213 -0
  49. package/dist/{te-team-GZPU6UWA.js → te-team-EFKWYKMK.js} +7 -7
  50. package/dist/{update-TOBFXF2V.js → update-OGPSZM5A.js} +7 -7
  51. package/package.json +13 -3
  52. package/skills/ae-agent/SKILL.md +21 -11
  53. package/skills/ae-agent/references/approval-effect.md +44 -0
  54. package/skills/ae-agent/references/approval-request.md +46 -0
  55. package/skills/ae-agent/references/approval-task.md +45 -0
  56. package/skills/ae-agent/references/approval-type.md +32 -0
  57. package/skills/ae-agent/references/command_index.md +19 -0
  58. package/skills/ae-analysis/SKILL.md +11 -7
  59. package/skills/ae-analysis/references/adhoc_run.md +2 -0
  60. package/skills/ae-analysis/references/ai_models.md +31 -1
  61. package/skills/ae-analysis/references/alert_list.md +2 -3
  62. package/skills/ae-analysis/references/analysis_gateway_assets.md +8 -7
  63. package/skills/ae-analysis/references/bi_panel_list.md +2 -2
  64. package/skills/ae-analysis/references/command_index.md +18 -15
  65. package/skills/ae-analysis/references/dashboard_get.md +8 -2
  66. package/skills/ae-analysis/references/dashboard_list.md +2 -2
  67. package/skills/ae-analysis/references/dashboard_report_data_run.md +3 -1
  68. package/skills/ae-analysis/references/dashboard_update.md +4 -1
  69. package/skills/ae-analysis/references/favorite_add.md +2 -2
  70. package/skills/ae-analysis/references/favorite_remove.md +2 -2
  71. package/skills/ae-analysis/references/metric_create.md +7 -8
  72. package/skills/ae-analysis/references/project_space_business_filter_upsert.md +17 -0
  73. package/skills/ae-analysis/references/project_space_list.md +2 -2
  74. package/skills/ae-analysis/references/public_link_list.md +2 -2
  75. package/skills/ae-analysis/references/report_list.md +3 -3
  76. package/skills/ae-analysis/references/report_list_export.md +2 -2
  77. package/skills/ae-analysis/references/sql_table_list.md +3 -2
  78. package/skills/ae-analysis/references/user_cluster_update.md +4 -2
  79. package/skills/ae-analysis/references/user_tag_models.md +4 -4
  80. package/skills/ae-analysis/references/user_tag_update.md +4 -2
  81. package/skills/ae-analysis/references/virtual_property_sql_rule_update.md +3 -3
  82. package/skills/ae-data-integration/SKILL.md +54 -0
  83. package/skills/ae-data-integration/references/handoff.md +43 -0
  84. package/skills/ae-data-integration/references/local-analysis.md +27 -0
  85. package/skills/ae-data-integration/references/reuse.md +41 -0
  86. package/skills/ae-data-integration/references/sink-upload.md +58 -0
  87. package/skills/ae-data-integration/references/source-inspect.md +55 -0
  88. package/skills/ae-data-integration/references/sync-json-upload.md +60 -0
  89. package/skills/ae-data-integration/references/tracking-plan.md +35 -0
  90. package/skills/ae-data-integration/references/transform.md +65 -0
  91. package/skills/ae-data-integration/references/ue-mapping.md +142 -0
  92. package/skills/ae-data-integration/references/ue-routing.md +35 -0
  93. package/skills/ae-data-integration-helper/SKILL.md +1 -1
  94. package/skills/ae-dataops/SKILL.md +1 -1
  95. package/skills/ae-dataops/references/dataops-query.md +4 -4
  96. package/skills/ae-engage/SKILL.md +10 -2
  97. package/skills/ae-engage/references/flow-metric-user.md +2 -1
  98. package/skills/ae-engage/references/flow-node-metric-user.md +2 -1
  99. package/skills/ae-engage/references/flow-node-user.md +2 -1
  100. package/skills/ae-engage/references/task-indicator-user.md +104 -0
  101. package/skills/ae-engage/references/task-user-detail-export.md +31 -0
  102. package/skills/ae-generate-tracking-plan/SKILL.md +54 -3
  103. package/skills/ae-metadata/SKILL.md +0 -1
  104. package/skills/ae-metadata/references/metadata_property_dimension_table_bind_existing.md +1 -1
  105. package/dist/chunk-3FY3RJ26.js +0 -293
  106. package/dist/chunk-S5NTSDBS.js +0 -198
  107. package/dist/chunk-ZQKDZXDO.js +0 -317
  108. package/dist/cli-token-4UPER74P.js +0 -21
@@ -1,293 +0,0 @@
1
- import {
2
- logger
3
- } from "./chunk-JHENBQ5B.js";
4
-
5
- // src/core/json-utils.ts
6
- import fs from "fs";
7
- import { createRequire } from "module";
8
- var require2 = createRequire(import.meta.url);
9
- var JSONbig = require2("json-bigint");
10
- var jsonParser = JSONbig({ storeAsString: true });
11
- var INTEGER_TOKEN = /^-?(?:0|[1-9]\d*)$/;
12
- function normalizeParsedNumbers(lossless, native) {
13
- if (typeof lossless === "string" && typeof native === "number") {
14
- if (INTEGER_TOKEN.test(lossless) && !Number.isSafeInteger(native)) {
15
- return lossless;
16
- }
17
- return native;
18
- }
19
- if (Array.isArray(lossless) && Array.isArray(native)) {
20
- for (let index = 0; index < lossless.length; index++) {
21
- lossless[index] = normalizeParsedNumbers(lossless[index], native[index]);
22
- }
23
- return lossless;
24
- }
25
- if (lossless !== null && native !== null && typeof lossless === "object" && typeof native === "object") {
26
- for (const key of Object.keys(lossless)) {
27
- lossless[key] = normalizeParsedNumbers(lossless[key], native[key]);
28
- }
29
- }
30
- return lossless;
31
- }
32
- function safeJsonParse(text) {
33
- const lossless = jsonParser.parse(text);
34
- return normalizeParsedNumbers(lossless, JSON.parse(text));
35
- }
36
- function safeReadJsonFile(filePath) {
37
- const content = fs.readFileSync(filePath, "utf-8");
38
- return safeJsonParse(content);
39
- }
40
-
41
- // src/core/url-utils.ts
42
- function normalizeUrl(url) {
43
- if (!url) return url;
44
- if (!url.startsWith("http://") && !url.startsWith("https://")) {
45
- url = `https://${url}`;
46
- }
47
- return url.replace(/\/$/, "");
48
- }
49
-
50
- // src/core/config.ts
51
- import fs3 from "fs";
52
- import path from "path";
53
-
54
- // src/core/sandbox-runtime.ts
55
- import { homedir } from "os";
56
- import { join } from "path";
57
- import fs2 from "fs";
58
- var LINUX_SANDBOX_RUNTIME_ROOT = "/home/ta/te_agent_ta";
59
- function getDefaultSandboxRuntimeRoot() {
60
- if (process.platform === "linux") {
61
- return LINUX_SANDBOX_RUNTIME_ROOT;
62
- }
63
- return homedir();
64
- }
65
- function getSandboxRuntimeRoot() {
66
- return process.env.SANDBOX_RUNTIME_ROOT || getDefaultSandboxRuntimeRoot();
67
- }
68
- function getSandboxAeConfigDir() {
69
- return join(getSandboxRuntimeRoot(), ".ae-config");
70
- }
71
- function getSandboxCliTokenFilePath() {
72
- return join(getSandboxAeConfigDir(), "cli-token.json");
73
- }
74
- function isAeSandboxRuntime() {
75
- if (process.env.SANDBOX_RUNTIME_ROOT) {
76
- return true;
77
- }
78
- try {
79
- if (fs2.existsSync(getSandboxCliTokenFilePath())) {
80
- return true;
81
- }
82
- } catch {
83
- }
84
- return false;
85
- }
86
-
87
- // src/core/config.ts
88
- var CONFIG_DIR = path.join(process.env.HOME || "", ".ae-cli");
89
- var CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
90
- function sandboxCliTokenCandidatePaths() {
91
- const paths = [getSandboxCliTokenFilePath()];
92
- const homeFallback = path.join(process.env.HOME || "", ".ae-config", "cli-token.json");
93
- if (!paths.includes(homeFallback)) {
94
- paths.push(homeFallback);
95
- }
96
- return paths;
97
- }
98
- function readSandboxCliTokenEntry() {
99
- for (const file of sandboxCliTokenCandidatePaths()) {
100
- if (!fs3.existsSync(file)) continue;
101
- try {
102
- const data = safeReadJsonFile(file);
103
- if (data && typeof data === "object" && !Array.isArray(data)) {
104
- const url = data.url;
105
- const token = data.token ?? data["cli-token"];
106
- if (url && token) {
107
- return { url, token };
108
- }
109
- }
110
- } catch {
111
- }
112
- }
113
- return null;
114
- }
115
- function forceMigrateFromFallback() {
116
- const entry = readSandboxCliTokenEntry();
117
- if (!entry) return null;
118
- return { [entry.url]: entry.token };
119
- }
120
- function getFallbackCliToken(hostUrl) {
121
- const store = forceMigrateFromFallback();
122
- if (!store) return null;
123
- if (hostUrl && store[hostUrl]) return store[hostUrl];
124
- const entries = Object.values(store);
125
- if (entries.length === 1) return entries[0];
126
- return null;
127
- }
128
- function ensureDir() {
129
- if (!fs3.existsSync(CONFIG_DIR)) fs3.mkdirSync(CONFIG_DIR, { recursive: true });
130
- }
131
- function dedupeNormalizedHosts(config) {
132
- const hosts = {};
133
- for (const [url, entry] of Object.entries(config.hosts)) {
134
- const key = normalizeUrl(url);
135
- if (!hosts[key]) {
136
- hosts[key] = entry;
137
- }
138
- }
139
- return {
140
- activeHost: config.activeHost ? normalizeUrl(config.activeHost) : "",
141
- hosts
142
- };
143
- }
144
- function configNeedsNormalization(config) {
145
- if (config.activeHost && normalizeUrl(config.activeHost) !== config.activeHost) return true;
146
- const keys = Object.keys(config.hosts);
147
- if (keys.some((url) => normalizeUrl(url) !== url)) return true;
148
- return new Set(keys.map(normalizeUrl)).size !== keys.length;
149
- }
150
- function loadConfig() {
151
- try {
152
- if (fs3.existsSync(CONFIG_FILE)) {
153
- const raw = safeReadJsonFile(CONFIG_FILE);
154
- if (raw.defaultHost && !raw.activeHost) {
155
- const migrated = dedupeNormalizedHosts(migrateConfig(raw));
156
- saveConfig(migrated);
157
- return migrated;
158
- }
159
- const rawConfig = raw;
160
- if (configNeedsNormalization(rawConfig)) {
161
- const config = dedupeNormalizedHosts(rawConfig);
162
- saveConfig(config);
163
- return config;
164
- }
165
- return rawConfig;
166
- }
167
- } catch (err) {
168
- logger.error(`Error loading config: ${err.message}`);
169
- console.error(`Error loading config: ${err.message}`);
170
- }
171
- return { activeHost: "", hosts: {} };
172
- }
173
- function migrateConfig(old) {
174
- const hosts = {};
175
- const oldHost = old.defaultHost;
176
- if (old.hosts) {
177
- for (const [key, val] of Object.entries(old.hosts)) {
178
- const url = normalizeUrl(key.startsWith("http") ? key : `https://${key}`);
179
- hosts[url] = val;
180
- }
181
- }
182
- const activeHost = normalizeUrl(oldHost.startsWith("http") ? oldHost : `https://${oldHost}`);
183
- if (!hosts[activeHost]) {
184
- hosts[activeHost] = { label: "default" };
185
- }
186
- return { activeHost, hosts };
187
- }
188
- function saveConfig(config) {
189
- ensureDir();
190
- fs3.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
191
- logger.info(`Config saved: activeHost=${config.activeHost}, hosts=${Object.keys(config.hosts).length}`);
192
- }
193
- function getActiveHost() {
194
- const sandboxHost = readSandboxCliTokenEntry()?.url;
195
- if (sandboxHost) return sandboxHost;
196
- const config = loadConfig();
197
- return config.activeHost || "";
198
- }
199
- function setActiveHost(url) {
200
- url = normalizeUrl(url);
201
- const config = loadConfig();
202
- if (!config.hosts[url]) {
203
- throw new Error(`Host ${url} is not in the configured hosts list. Add it first.`);
204
- }
205
- config.activeHost = url;
206
- saveConfig(config);
207
- }
208
- function addHost(url, label) {
209
- url = normalizeUrl(url);
210
- label = normalizeLabel(label);
211
- const config = loadConfig();
212
- assertUniqueHostLabel(config, label, url);
213
- config.hosts[url] = { label };
214
- if (!config.activeHost) {
215
- config.activeHost = url;
216
- }
217
- saveConfig(config);
218
- }
219
- function updateHostLabel(url, label) {
220
- url = normalizeUrl(url);
221
- label = normalizeLabel(label);
222
- const config = loadConfig();
223
- if (!config.hosts[url]) {
224
- throw new Error(`Host is not configured: ${url}`);
225
- }
226
- assertUniqueHostLabel(config, label, url);
227
- config.hosts[url].label = label;
228
- saveConfig(config);
229
- }
230
- function normalizeLabel(label) {
231
- const normalized = label.trim();
232
- if (!normalized) {
233
- throw new Error("Label cannot be empty.");
234
- }
235
- return normalized;
236
- }
237
- function assertUniqueHostLabel(config, label, excludeUrl) {
238
- const duplicate = Object.entries(config.hosts).find(([url, entry]) => url !== excludeUrl && entry.label === label);
239
- if (duplicate) {
240
- throw new Error(`Label already exists: ${label}. Rename the existing label first: ${duplicate[0]}`);
241
- }
242
- }
243
- function removeHost(url) {
244
- url = normalizeUrl(url);
245
- const config = loadConfig();
246
- delete config.hosts[url];
247
- if (config.activeHost === url) {
248
- const remaining = Object.keys(config.hosts);
249
- config.activeHost = remaining.length > 0 ? remaining[0] : "";
250
- }
251
- saveConfig(config);
252
- }
253
- function listHosts() {
254
- const config = loadConfig();
255
- return Object.entries(config.hosts).map(([url, entry]) => ({
256
- url,
257
- label: entry.label,
258
- active: url === config.activeHost
259
- }));
260
- }
261
- function resolveHostSelector(env) {
262
- const raw = env.trim();
263
- const selector = raw.startsWith("http://") || raw.startsWith("https://") ? normalizeUrl(raw) : raw;
264
- const hosts = listHosts();
265
- const byUrl = hosts.find((host) => host.url === selector);
266
- if (byUrl) return { status: "found", host: byUrl };
267
- const byLabel = hosts.filter((host) => host.label === raw);
268
- if (byLabel.length === 1) return { status: "found", host: byLabel[0] };
269
- if (byLabel.length > 1) return { status: "duplicate-label", matches: byLabel };
270
- return { status: "not-found", hosts };
271
- }
272
- function getConfigDir() {
273
- return CONFIG_DIR;
274
- }
275
-
276
- export {
277
- safeJsonParse,
278
- safeReadJsonFile,
279
- normalizeUrl,
280
- getSandboxRuntimeRoot,
281
- isAeSandboxRuntime,
282
- getFallbackCliToken,
283
- loadConfig,
284
- saveConfig,
285
- getActiveHost,
286
- setActiveHost,
287
- addHost,
288
- updateHostLabel,
289
- removeHost,
290
- listHosts,
291
- resolveHostSelector,
292
- getConfigDir
293
- };
@@ -1,198 +0,0 @@
1
- import {
2
- getToken,
3
- load,
4
- loadCliToken,
5
- save
6
- } from "./chunk-ZQKDZXDO.js";
7
- import {
8
- getActiveHost,
9
- getConfigDir,
10
- getFallbackCliToken,
11
- listHosts,
12
- normalizeUrl,
13
- safeJsonParse,
14
- safeReadJsonFile
15
- } from "./chunk-3FY3RJ26.js";
16
- import {
17
- logger
18
- } from "./chunk-JHENBQ5B.js";
19
-
20
- // src/core/cli-token.ts
21
- import fs from "fs";
22
- import path from "path";
23
- var CLI_TOKEN_GENERATE_PATH = "/v1/ta/cli/token/generate";
24
- var _cliTokenCache = /* @__PURE__ */ new Map();
25
- var _renewedLocalDateByHost = /* @__PURE__ */ new Map();
26
- var _renewInFlightByHost = /* @__PURE__ */ new Map();
27
- function renewHostKey(hostUrl) {
28
- return normalizeUrl(hostUrl);
29
- }
30
- function renewStateFilePath() {
31
- return path.join(getConfigDir(), "cli-token-renew.json");
32
- }
33
- function localRenewDate(now = /* @__PURE__ */ new Date()) {
34
- const y = now.getFullYear();
35
- const m = String(now.getMonth() + 1).padStart(2, "0");
36
- const d = String(now.getDate()).padStart(2, "0");
37
- return `${y}-${m}-${d}`;
38
- }
39
- function loadRenewStore() {
40
- try {
41
- const file = renewStateFilePath();
42
- if (!fs.existsSync(file)) return {};
43
- const data = safeReadJsonFile(file);
44
- if (!data || typeof data !== "object" || Array.isArray(data)) return {};
45
- return data;
46
- } catch {
47
- return {};
48
- }
49
- }
50
- function saveRenewStore(store) {
51
- const dir = getConfigDir();
52
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
53
- const file = renewStateFilePath();
54
- if (Object.keys(store).length === 0) {
55
- try {
56
- fs.unlinkSync(file);
57
- } catch {
58
- }
59
- return;
60
- }
61
- fs.writeFileSync(file, JSON.stringify(store, null, 2), { encoding: "utf8" });
62
- try {
63
- fs.chmodSync(file, 384);
64
- } catch {
65
- }
66
- }
67
- function clearRenewState(hostUrl) {
68
- if (hostUrl) {
69
- const key = renewHostKey(hostUrl);
70
- _renewedLocalDateByHost.delete(key);
71
- _renewInFlightByHost.delete(key);
72
- if (key !== hostUrl) {
73
- _renewedLocalDateByHost.delete(hostUrl);
74
- _renewInFlightByHost.delete(hostUrl);
75
- }
76
- const store = loadRenewStore();
77
- let changed = false;
78
- for (const k of /* @__PURE__ */ new Set([key, hostUrl])) {
79
- if (store[k]) {
80
- delete store[k];
81
- changed = true;
82
- }
83
- }
84
- if (changed) {
85
- saveRenewStore(store);
86
- }
87
- return;
88
- }
89
- _renewedLocalDateByHost.clear();
90
- _renewInFlightByHost.clear();
91
- saveRenewStore({});
92
- }
93
- async function generateCliToken(hostUrl) {
94
- const accessToken = await getToken(hostUrl);
95
- const base = hostUrl.replace(/\/+$/, "");
96
- const url = `${base}${CLI_TOKEN_GENERATE_PATH}`;
97
- const resp = await fetch(url, {
98
- method: "GET",
99
- headers: {
100
- "Authorization": `bearer ${accessToken}`
101
- }
102
- });
103
- if (!resp.ok) {
104
- throw new Error(`CLI token generate HTTP error: ${resp.status} ${resp.statusText}`);
105
- }
106
- const data = safeJsonParse(await resp.text());
107
- if (data.return_code !== 0) {
108
- throw new Error(`CLI token generate error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
109
- }
110
- const cliToken = data.data?.userSecret;
111
- if (!cliToken) {
112
- throw new Error("CLI token generate error: empty userSecret in response");
113
- }
114
- return cliToken;
115
- }
116
- function persistCliTokenIfPossible(hostUrl, cliToken) {
117
- const existing = load(hostUrl);
118
- if (!existing) {
119
- logger.info(`cli-token: no secure-store session for ${hostUrl}, keeping token in-process only`);
120
- return;
121
- }
122
- save(hostUrl, { ...existing, cliToken });
123
- }
124
- function clearPersistedCliToken(hostUrl) {
125
- const existing = load(hostUrl);
126
- if (existing?.cliToken) {
127
- save(hostUrl, { ...existing, cliToken: void 0 });
128
- }
129
- }
130
- function peekCliToken(hostOverride) {
131
- const hostUrl = hostOverride || getActiveHost();
132
- if (!hostUrl) return void 0;
133
- return _cliTokenCache.get(hostUrl) || loadCliToken(hostUrl) || getFallbackCliToken(hostUrl) || void 0;
134
- }
135
- async function getCliToken(hostOverride) {
136
- const hostUrl = hostOverride || getActiveHost();
137
- let token = _cliTokenCache.get(hostUrl);
138
- if (!token) {
139
- const storedToken = loadCliToken(hostUrl);
140
- if (storedToken) {
141
- _cliTokenCache.set(hostUrl, storedToken);
142
- logger.info(`Using persisted CLI token (secure-store) for ${hostUrl}`);
143
- token = storedToken;
144
- }
145
- }
146
- if (!token) {
147
- const fallbackToken = getFallbackCliToken(hostUrl);
148
- if (fallbackToken) {
149
- _cliTokenCache.set(hostUrl, fallbackToken);
150
- logger.info(`Using sandbox-provisioned CLI token (fallback file) for ${hostUrl}`);
151
- token = fallbackToken;
152
- }
153
- }
154
- if (!token) {
155
- token = await mintCliToken(hostUrl);
156
- }
157
- return token;
158
- }
159
- async function mintCliToken(hostUrl) {
160
- logger.info(`Generating CLI token for ${hostUrl}`);
161
- const cliToken = await generateCliToken(hostUrl);
162
- _cliTokenCache.set(hostUrl, cliToken);
163
- persistCliTokenIfPossible(hostUrl, cliToken);
164
- logger.info(`CLI token generated, cached, and persisted for ${hostUrl}`);
165
- return cliToken;
166
- }
167
- function clearCliToken(hostUrl) {
168
- if (hostUrl) {
169
- _cliTokenCache.delete(hostUrl);
170
- clearPersistedCliToken(hostUrl);
171
- clearRenewState(hostUrl);
172
- return;
173
- }
174
- _cliTokenCache.clear();
175
- clearRenewState();
176
- for (const { url } of listHosts()) {
177
- clearPersistedCliToken(url);
178
- }
179
- }
180
- function setCliTokenManual(token, hostUrl) {
181
- _cliTokenCache.set(hostUrl, token);
182
- persistCliTokenIfPossible(hostUrl, token);
183
- logger.info(`CLI token set for ${hostUrl}`);
184
- }
185
- function _resetRenewMemoryForTest() {
186
- _renewedLocalDateByHost.clear();
187
- _renewInFlightByHost.clear();
188
- }
189
-
190
- export {
191
- localRenewDate,
192
- peekCliToken,
193
- getCliToken,
194
- mintCliToken,
195
- clearCliToken,
196
- setCliTokenManual,
197
- _resetRenewMemoryForTest
198
- };