@thinkingai/ae-cli 6.1.14 → 6.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{auth-GBMV6TEJ.js → auth-2WTQOP77.js} +3 -3
- package/dist/{auth-NDSXE54J.js → auth-77BUFLGC.js} +57 -13
- package/dist/{capability-TAMDRZYV.js → capability-72DTW5M2.js} +9 -9
- package/dist/{capability-U7TDEEEG.js → capability-PJHNI4GJ.js} +9 -9
- package/dist/{chunk-AFXA7BRK.js → chunk-4KVPKXFX.js} +5 -5
- package/dist/chunk-4SGZG4XY.js +311 -0
- package/dist/chunk-6EIJSNBD.js +8 -0
- package/dist/chunk-C4MGVGJW.js +13 -0
- package/dist/{chunk-WZRX4KOH.js → chunk-GT46FPXN.js} +4 -6
- package/dist/{chunk-5XUSIK27.js → chunk-ILIU36SU.js} +10 -7
- package/dist/{chunk-JHENBQ5B.js → chunk-LYVNONC4.js} +0 -35
- package/dist/{chunk-JUW4AJXN.js → chunk-P3FGXJTU.js} +12 -7
- package/dist/chunk-QGM4M3NI.js +37 -0
- package/dist/{chunk-753BUTNZ.js → chunk-RGKJGKT7.js} +2 -2
- package/dist/{chunk-UIHQJK5E.js → chunk-SAU3QFIQ.js} +3 -3
- package/dist/{chunk-VLWOLBGZ.js → chunk-UOUS37JQ.js} +149 -161
- package/dist/{chunk-AXDXJTPC.js → chunk-UW5UN47B.js} +19 -2
- package/dist/chunk-VPKZ7I72.js +509 -0
- package/dist/{chunk-QATA32VR.js → chunk-VR3LCBHW.js} +2 -2
- package/dist/{chunk-IBH3LDAH.js → chunk-YA6SMTXG.js} +3 -3
- package/dist/chunk-ZZUOD757.js +598 -0
- package/dist/{client-L2YDMHQ6.js → client-TKG4WBHN.js} +4 -5
- package/dist/{community-report-client-M2RW4MXD.js → community-report-client-FI4LNVYS.js} +3 -2
- package/dist/{config-OL2LWGBV.js → config-RE6CMGPK.js} +7 -7
- package/dist/data-integration-2MYMANJI.js +3383 -0
- package/dist/index.js +68 -34
- package/dist/local-data-upload-client-BWHSUQQK.js +167 -0
- package/dist/{memory-MUP7PPL7.js → memory-CHRU2F7W.js} +7 -6
- package/dist/{memory-U4O5PMXH.js → memory-YK33G4T7.js} +7 -6
- package/dist/{metadata-5MIMNIMT.js → metadata-UILXHBWF.js} +10 -9
- package/dist/{metadata-LERKDJN6.js → metadata-XXR34N5P.js} +10 -9
- package/dist/{model-JTUEO5M4.js → model-K3KLWIW6.js} +7 -3
- package/dist/model-NR3JHFSJ.js +139 -0
- package/dist/{sync-MOSFNBVR.js → sync-DAVKYVMW.js} +8 -6
- package/dist/sync-FCKOVWWS.js +10261 -0
- package/dist/{te-agent-IFKZDHZI.js → te-agent-4BKBODMF.js} +686 -71
- package/dist/te-agent-HLW4VTQK.js +3893 -0
- package/dist/{te-analysis-FCHRTNIY.js → te-analysis-O6DCO6BS.js} +36 -13
- package/dist/{te-analysis-QG7UKGDA.js → te-analysis-ZMNGOVNW.js} +36 -13
- package/dist/{te-community-HNKVTERD.js → te-community-6HPBWJUZ.js} +24 -19
- package/dist/{te-community-IWE5B7W6.js → te-community-HLC43QKH.js} +24 -20
- package/dist/{te-dataops-KXCEB4CS.js → te-dataops-EJP56W3K.js} +57 -34
- package/dist/{te-dataops-KQPYNAE3.js → te-dataops-HDRUXY4K.js} +59 -34
- package/dist/{te-engage-D6EG3NOR.js → te-engage-FGBGQ4IY.js} +9 -8
- package/dist/{te-engage-ZSMIJLUW.js → te-engage-RAK5PESW.js} +9 -8
- package/dist/{te-experiment-K5US7RMG.js → te-experiment-SO5MPDMJ.js} +9 -8
- package/dist/{te-experiment-WA7TFMEL.js → te-experiment-VZF7BT6G.js} +9 -8
- package/dist/{te-kb-OIH3T6CS.js → te-kb-APXBWBDY.js} +6 -6
- package/dist/{te-system-AZ3URMUO.js → te-system-YARIK4S5.js} +7 -4
- package/dist/te-system-Z77IKZFN.js +2213 -0
- package/dist/{te-team-GZPU6UWA.js → te-team-EFKWYKMK.js} +7 -7
- package/dist/{update-TOBFXF2V.js → update-OGPSZM5A.js} +7 -7
- package/package.json +13 -3
- package/skills/ae-agent/SKILL.md +21 -11
- package/skills/ae-agent/references/approval-effect.md +44 -0
- package/skills/ae-agent/references/approval-request.md +46 -0
- package/skills/ae-agent/references/approval-task.md +45 -0
- package/skills/ae-agent/references/approval-type.md +32 -0
- package/skills/ae-agent/references/command_index.md +19 -0
- package/skills/ae-analysis/SKILL.md +11 -7
- package/skills/ae-analysis/references/adhoc_run.md +2 -0
- package/skills/ae-analysis/references/ai_models.md +27 -0
- package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -2
- package/skills/ae-analysis/references/command_index.md +4 -1
- package/skills/ae-analysis/references/dashboard_get.md +8 -2
- package/skills/ae-analysis/references/dashboard_report_data_run.md +3 -1
- package/skills/ae-analysis/references/dashboard_update.md +4 -1
- package/skills/ae-analysis/references/project_space_business_filter_upsert.md +17 -0
- package/skills/ae-analysis/references/user_tag_models.md +4 -4
- package/skills/ae-data-integration/SKILL.md +54 -0
- package/skills/ae-data-integration/references/handoff.md +43 -0
- package/skills/ae-data-integration/references/local-analysis.md +27 -0
- package/skills/ae-data-integration/references/reuse.md +41 -0
- package/skills/ae-data-integration/references/sink-upload.md +58 -0
- package/skills/ae-data-integration/references/source-inspect.md +55 -0
- package/skills/ae-data-integration/references/sync-json-upload.md +60 -0
- package/skills/ae-data-integration/references/tracking-plan.md +35 -0
- package/skills/ae-data-integration/references/transform.md +65 -0
- package/skills/ae-data-integration/references/ue-mapping.md +142 -0
- package/skills/ae-data-integration/references/ue-routing.md +35 -0
- package/skills/ae-data-integration-helper/SKILL.md +1 -1
- package/skills/ae-dataops/SKILL.md +1 -1
- package/skills/ae-dataops/references/dataops-query.md +4 -4
- package/skills/ae-generate-tracking-plan/SKILL.md +54 -3
- package/skills/ae-metadata/SKILL.md +0 -1
- package/dist/chunk-3FY3RJ26.js +0 -293
- package/dist/chunk-S5NTSDBS.js +0 -198
- package/dist/chunk-ZQKDZXDO.js +0 -317
- package/dist/cli-token-4UPER74P.js +0 -21
package/dist/chunk-S5NTSDBS.js
DELETED
|
@@ -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
|
-
};
|
package/dist/chunk-ZQKDZXDO.js
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getActiveHost,
|
|
3
|
-
getConfigDir,
|
|
4
|
-
normalizeUrl,
|
|
5
|
-
safeJsonParse
|
|
6
|
-
} from "./chunk-3FY3RJ26.js";
|
|
7
|
-
import {
|
|
8
|
-
logger
|
|
9
|
-
} from "./chunk-JHENBQ5B.js";
|
|
10
|
-
|
|
11
|
-
// src/core/secure-store.ts
|
|
12
|
-
import crypto from "crypto";
|
|
13
|
-
import fs from "fs";
|
|
14
|
-
import os from "os";
|
|
15
|
-
import path from "path";
|
|
16
|
-
import { execFileSync } from "child_process";
|
|
17
|
-
var STORE_DIR_SUFFIX = "secure-tokens";
|
|
18
|
-
var SCRYPT_SALT = Buffer.from("ae-cli-secure-store-v1");
|
|
19
|
-
var SCRYPT_N = 16384;
|
|
20
|
-
var SCRYPT_R = 8;
|
|
21
|
-
var SCRYPT_P = 1;
|
|
22
|
-
var KEY_LEN = 32;
|
|
23
|
-
var NONCE_LEN = 12;
|
|
24
|
-
var REFRESH_TOKEN_PATH = "/v1/oauth/refreshForToken";
|
|
25
|
-
function getMachineId() {
|
|
26
|
-
if (process.platform === "darwin") {
|
|
27
|
-
try {
|
|
28
|
-
const out = execFileSync(
|
|
29
|
-
"ioreg",
|
|
30
|
-
["-rd1", "-c", "IOPlatformExpertDevice"],
|
|
31
|
-
{ encoding: "utf8", timeout: 3e3 }
|
|
32
|
-
);
|
|
33
|
-
const m = out.match(/IOPlatformUUID.*?=.*?"([0-9A-F-]{36})"/i);
|
|
34
|
-
if (m?.[1]) return `darwin:${m[1]}`;
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (process.platform === "linux") {
|
|
39
|
-
for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
|
|
40
|
-
try {
|
|
41
|
-
const id = fs.readFileSync(p, "utf8").trim();
|
|
42
|
-
if (id) return `linux:${id}`;
|
|
43
|
-
} catch {
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (process.platform === "win32") {
|
|
48
|
-
try {
|
|
49
|
-
const out = execFileSync(
|
|
50
|
-
"reg",
|
|
51
|
-
["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"],
|
|
52
|
-
{ encoding: "utf8", timeout: 3e3 }
|
|
53
|
-
);
|
|
54
|
-
const m = out.match(/MachineGuid\s+REG_SZ\s+([0-9a-f-]+)/i);
|
|
55
|
-
if (m?.[1]) return `win32:${m[1]}`;
|
|
56
|
-
} catch {
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const fallback = `${os.homedir()}|${os.hostname()}|${os.platform()}`;
|
|
60
|
-
logger.warn("secure-store: using fallback machine-id (HOME+hostname+platform)");
|
|
61
|
-
return `fallback:${fallback}`;
|
|
62
|
-
}
|
|
63
|
-
var _cachedMachineId;
|
|
64
|
-
function getCachedMachineId() {
|
|
65
|
-
if (!_cachedMachineId) _cachedMachineId = getMachineId();
|
|
66
|
-
return _cachedMachineId;
|
|
67
|
-
}
|
|
68
|
-
function deriveKey(machineId) {
|
|
69
|
-
return crypto.scryptSync(machineId, SCRYPT_SALT, KEY_LEN, {
|
|
70
|
-
N: SCRYPT_N,
|
|
71
|
-
r: SCRYPT_R,
|
|
72
|
-
p: SCRYPT_P
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
var _cachedKey;
|
|
76
|
-
function getKey() {
|
|
77
|
-
if (!_cachedKey) _cachedKey = deriveKey(getCachedMachineId());
|
|
78
|
-
return _cachedKey;
|
|
79
|
-
}
|
|
80
|
-
function encrypt(plaintext) {
|
|
81
|
-
const key = getKey();
|
|
82
|
-
const nonce = crypto.randomBytes(NONCE_LEN);
|
|
83
|
-
const cipher = crypto.createCipheriv("aes-256-gcm", key, nonce);
|
|
84
|
-
const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
85
|
-
const tag = cipher.getAuthTag();
|
|
86
|
-
return {
|
|
87
|
-
nonce: nonce.toString("hex"),
|
|
88
|
-
tag: tag.toString("hex"),
|
|
89
|
-
data: encrypted.toString("hex")
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function decrypt(blob) {
|
|
93
|
-
const key = getKey();
|
|
94
|
-
const nonce = Buffer.from(blob.nonce, "hex");
|
|
95
|
-
const tag = Buffer.from(blob.tag, "hex");
|
|
96
|
-
const data = Buffer.from(blob.data, "hex");
|
|
97
|
-
const decipher = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
98
|
-
decipher.setAuthTag(tag);
|
|
99
|
-
const decrypted = Buffer.concat([decipher.update(data), decipher.final()]);
|
|
100
|
-
return decrypted.toString("utf8");
|
|
101
|
-
}
|
|
102
|
-
function storeDir() {
|
|
103
|
-
return path.join(getConfigDir(), STORE_DIR_SUFFIX);
|
|
104
|
-
}
|
|
105
|
-
function tokenFilePath(host) {
|
|
106
|
-
const safe = host.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
107
|
-
return path.join(storeDir(), `${safe}.enc.json`);
|
|
108
|
-
}
|
|
109
|
-
function ensureStoreDir() {
|
|
110
|
-
const dir = storeDir();
|
|
111
|
-
if (!fs.existsSync(dir)) {
|
|
112
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
113
|
-
try {
|
|
114
|
-
fs.chmodSync(dir, 448);
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function save(host, payload) {
|
|
120
|
-
ensureStoreDir();
|
|
121
|
-
const plaintext = JSON.stringify(payload);
|
|
122
|
-
const blob = encrypt(plaintext);
|
|
123
|
-
const filePath = tokenFilePath(host);
|
|
124
|
-
fs.writeFileSync(filePath, JSON.stringify(blob, null, 2), { encoding: "utf8" });
|
|
125
|
-
try {
|
|
126
|
-
fs.chmodSync(filePath, 384);
|
|
127
|
-
} catch {
|
|
128
|
-
}
|
|
129
|
-
logger.info(`secure-store: token saved for ${host}`);
|
|
130
|
-
}
|
|
131
|
-
function load(host) {
|
|
132
|
-
const filePath = tokenFilePath(host);
|
|
133
|
-
if (!fs.existsSync(filePath)) return null;
|
|
134
|
-
try {
|
|
135
|
-
const raw = fs.readFileSync(filePath, "utf8");
|
|
136
|
-
const blob = safeJsonParse(raw);
|
|
137
|
-
if (!blob?.nonce || !blob?.tag || !blob?.data) {
|
|
138
|
-
logger.warn(`secure-store: malformed blob for ${host}`);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const plaintext = decrypt(blob);
|
|
142
|
-
return JSON.parse(plaintext);
|
|
143
|
-
} catch (e) {
|
|
144
|
-
logger.error(`secure-store: decrypt failed for ${host}: ${e.message}`);
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
function clear(host) {
|
|
149
|
-
const filePath = tokenFilePath(host);
|
|
150
|
-
if (fs.existsSync(filePath)) {
|
|
151
|
-
fs.rmSync(filePath);
|
|
152
|
-
logger.info(`secure-store: token cleared for ${host}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async function getValidAccessToken(host) {
|
|
156
|
-
const payload = load(host);
|
|
157
|
-
if (!payload) {
|
|
158
|
-
throw new SecureStoreAuthError(
|
|
159
|
-
`No stored token for ${host}. Please run: ae-cli auth login`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
const expiresAt = new Date(payload.accessExpiresAt).getTime();
|
|
163
|
-
const now = Date.now();
|
|
164
|
-
const needsRefresh = expiresAt - now < 6e4;
|
|
165
|
-
if (!needsRefresh) {
|
|
166
|
-
return payload.accessToken;
|
|
167
|
-
}
|
|
168
|
-
if (payload.refreshToken) {
|
|
169
|
-
logger.info(`secure-store: access token past local expiry for ${host}, refreshing\u2026`);
|
|
170
|
-
const refreshed = await doRefresh(host, payload.refreshToken);
|
|
171
|
-
save(host, { ...refreshed, cliToken: payload.cliToken });
|
|
172
|
-
logger.info(`secure-store: token refreshed for ${host}`);
|
|
173
|
-
return refreshed.accessToken;
|
|
174
|
-
}
|
|
175
|
-
logger.info(`secure-store: ${host} past static local expiry, no refresh token \u2014 returning stored token, server validates (lazy)`);
|
|
176
|
-
return payload.accessToken;
|
|
177
|
-
}
|
|
178
|
-
function loadCliToken(host) {
|
|
179
|
-
return load(host)?.cliToken ?? null;
|
|
180
|
-
}
|
|
181
|
-
async function doRefresh(host, refreshToken) {
|
|
182
|
-
const base = host.replace(/\/+$/, "");
|
|
183
|
-
const url = `${base}${REFRESH_TOKEN_PATH}`;
|
|
184
|
-
let resp;
|
|
185
|
-
try {
|
|
186
|
-
resp = await fetch(url, {
|
|
187
|
-
method: "POST",
|
|
188
|
-
headers: { "Content-Type": "application/json" },
|
|
189
|
-
body: JSON.stringify({ refreshToken })
|
|
190
|
-
});
|
|
191
|
-
} catch (e) {
|
|
192
|
-
throw new SecureStoreAuthError(
|
|
193
|
-
`Token refresh network error for ${host}: ${e.message}. Please run: ae-cli auth login`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
if (!resp.ok) {
|
|
197
|
-
throw new SecureStoreAuthError(
|
|
198
|
-
`Token refresh failed (HTTP ${resp.status}) for ${host}. Please run: ae-cli auth login`
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
let body;
|
|
202
|
-
try {
|
|
203
|
-
body = safeJsonParse(await resp.text());
|
|
204
|
-
} catch {
|
|
205
|
-
throw new SecureStoreAuthError(
|
|
206
|
-
`Token refresh returned invalid JSON for ${host}. Please run: ae-cli auth login`
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (body.return_code !== 0) {
|
|
210
|
-
throw new SecureStoreAuthError(
|
|
211
|
-
`Token refresh error (${body.return_code}: ${body.return_message ?? "unknown"}) for ${host}. Please run: ae-cli auth login`
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
const d = body.data;
|
|
215
|
-
const newAccess = d?.accessToken ?? d?.access_token ?? "";
|
|
216
|
-
const newRefresh = d?.refreshToken ?? d?.refresh_token ?? refreshToken;
|
|
217
|
-
const expiresIn = d?.expiresIn ?? d?.expires_in ?? 72e3;
|
|
218
|
-
if (!newAccess) {
|
|
219
|
-
throw new SecureStoreAuthError(
|
|
220
|
-
`Token refresh returned empty accessToken for ${host}. Please run: ae-cli auth login`
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
accessToken: newAccess,
|
|
225
|
-
refreshToken: newRefresh,
|
|
226
|
-
accessExpiresAt: new Date(Date.now() + expiresIn * 1e3).toISOString()
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
var SecureStoreAuthError = class extends Error {
|
|
230
|
-
constructor(message) {
|
|
231
|
-
super(message);
|
|
232
|
-
this.name = "SecureStoreAuthError";
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// src/core/host-guidance.ts
|
|
237
|
-
var AE_TRIAL_URL = "https://thinkingai.cn/request-demo";
|
|
238
|
-
var AE_HOST_SETUP_COMMAND = "ae-cli config set-host <url>";
|
|
239
|
-
function missingAeHostHint(additionalAction) {
|
|
240
|
-
const actions = [
|
|
241
|
-
`If your organization already uses AgenticEngine, ask your administrator for its AE URL, then run: ${AE_HOST_SETUP_COMMAND}.`,
|
|
242
|
-
`If you do not have an AgenticEngine environment, request a trial: ${AE_TRIAL_URL}`
|
|
243
|
-
];
|
|
244
|
-
if (additionalAction) actions.push(additionalAction);
|
|
245
|
-
return actions.join(" ");
|
|
246
|
-
}
|
|
247
|
-
function missingAeHostGuidance() {
|
|
248
|
-
return {
|
|
249
|
-
configure_host: AE_HOST_SETUP_COMMAND,
|
|
250
|
-
existing_customer: "Ask your AgenticEngine administrator for the AE environment URL.",
|
|
251
|
-
request_trial_url: AE_TRIAL_URL
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// src/core/auth.ts
|
|
256
|
-
function resolveHost(hostOverride) {
|
|
257
|
-
if (hostOverride) return normalizeUrl(hostOverride);
|
|
258
|
-
return getActiveHost();
|
|
259
|
-
}
|
|
260
|
-
async function validateToken(token, hostUrl) {
|
|
261
|
-
const url = `${hostUrl}/v1/oauth/checkToken`;
|
|
262
|
-
try {
|
|
263
|
-
const resp = await fetch(url, {
|
|
264
|
-
method: "POST",
|
|
265
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
266
|
-
body: new URLSearchParams({ accessToken: token }).toString()
|
|
267
|
-
});
|
|
268
|
-
const respJson = safeJsonParse(await resp.text());
|
|
269
|
-
return respJson?.return_code === 0;
|
|
270
|
-
} catch {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
function invalidateAccessTokenForRetry(hostUrl) {
|
|
275
|
-
const payload = load(hostUrl);
|
|
276
|
-
if (!payload) return;
|
|
277
|
-
save(hostUrl, { ...payload, accessExpiresAt: (/* @__PURE__ */ new Date(0)).toISOString() });
|
|
278
|
-
logger.info(`auth: marked access token stale for retry on ${hostUrl}`);
|
|
279
|
-
}
|
|
280
|
-
async function getToken(hostUrl) {
|
|
281
|
-
if (!hostUrl) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
`No AE host configured.
|
|
284
|
-
` + missingAeHostHint()
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
try {
|
|
288
|
-
const secureToken = await getValidAccessToken(hostUrl);
|
|
289
|
-
logger.info(`Using secure-store token for ${hostUrl}`);
|
|
290
|
-
return secureToken;
|
|
291
|
-
} catch (e) {
|
|
292
|
-
if (e instanceof SecureStoreAuthError) {
|
|
293
|
-
logger.info(`secure-store: ${e.message}`);
|
|
294
|
-
} else {
|
|
295
|
-
logger.warn(`secure-store unexpected error: ${e.message}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
throw new Error(
|
|
299
|
-
`Cannot obtain token for ${hostUrl}.
|
|
300
|
-
Run: ae-cli auth login (device code flow, cross-platform)`
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export {
|
|
305
|
-
save,
|
|
306
|
-
load,
|
|
307
|
-
clear,
|
|
308
|
-
loadCliToken,
|
|
309
|
-
SecureStoreAuthError,
|
|
310
|
-
AE_TRIAL_URL,
|
|
311
|
-
missingAeHostHint,
|
|
312
|
-
missingAeHostGuidance,
|
|
313
|
-
resolveHost,
|
|
314
|
-
validateToken,
|
|
315
|
-
invalidateAccessTokenForRetry,
|
|
316
|
-
getToken
|
|
317
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
_resetRenewMemoryForTest,
|
|
3
|
-
clearCliToken,
|
|
4
|
-
getCliToken,
|
|
5
|
-
localRenewDate,
|
|
6
|
-
mintCliToken,
|
|
7
|
-
peekCliToken,
|
|
8
|
-
setCliTokenManual
|
|
9
|
-
} from "./chunk-S5NTSDBS.js";
|
|
10
|
-
import "./chunk-ZQKDZXDO.js";
|
|
11
|
-
import "./chunk-3FY3RJ26.js";
|
|
12
|
-
import "./chunk-JHENBQ5B.js";
|
|
13
|
-
export {
|
|
14
|
-
_resetRenewMemoryForTest,
|
|
15
|
-
clearCliToken,
|
|
16
|
-
getCliToken,
|
|
17
|
-
localRenewDate,
|
|
18
|
-
mintCliToken,
|
|
19
|
-
peekCliToken,
|
|
20
|
-
setCliTokenManual
|
|
21
|
-
};
|