@thinkingai/ae-cli 6.1.32 → 6.1.34

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 (119) hide show
  1. package/README.md +8 -5
  2. package/README.zh.md +10 -9
  3. package/bin/runtime-capabilities.json +1 -1
  4. package/cli-installation-guide.md +14 -4
  5. package/dist/{ai-monitor-MKMHSSNI.js → ai-monitor-TVRFVZBH.js} +11 -9
  6. package/dist/ai-monitor.js +18 -16
  7. package/dist/{auth-CZHHPZOQ.js → auth-JAXLMPBB.js} +33 -316
  8. package/dist/{automation-FLCPFMN4.js → automation-OQ647CSW.js} +7 -7
  9. package/dist/{capability-64KVJFIA.js → capability-2Z4ZXTPD.js} +19 -16
  10. package/dist/chunk-2H3SFJE3.js +344 -0
  11. package/dist/{chunk-TMQGS4TO.js → chunk-3PZNM5KN.js} +3 -3
  12. package/dist/chunk-3ZQY7SLZ.js +147 -0
  13. package/dist/chunk-6E6HCTP2.js +60 -0
  14. package/dist/{local-data-upload-client-KCMG6J62.js → chunk-6IUTXRAD.js} +32 -4
  15. package/dist/{chunk-5M5LBRR3.js → chunk-CYZV5AXW.js} +18 -9
  16. package/dist/{chunk-3ULDJJTZ.js → chunk-DE5XHQQ6.js} +2 -2
  17. package/dist/{chunk-FCAA7I2D.js → chunk-E5CJI7L3.js} +26 -10
  18. package/dist/{chunk-QVRIDN42.js → chunk-EQMGH32F.js} +2 -2
  19. package/dist/{chunk-DWBYNGSR.js → chunk-FNACCKQR.js} +372 -194
  20. package/dist/{chunk-OAWPT7VP.js → chunk-GD5JSAGV.js} +2 -2
  21. package/dist/{chunk-CF6JTT2U.js → chunk-GYODT7C4.js} +1 -1
  22. package/dist/chunk-HBI7IQH3.js +1207 -0
  23. package/dist/{chunk-4PSTYEG5.js → chunk-IGU3R2JD.js} +9 -5
  24. package/dist/{chunk-IDDWEZ7F.js → chunk-IWMDPHMI.js} +3 -3
  25. package/dist/{chunk-P7QDCWJ6.js → chunk-L7MT53VM.js} +8 -2
  26. package/dist/{chunk-F2VFZUGG.js → chunk-LXRALNNA.js} +2 -2
  27. package/dist/{chunk-6M7ZEDT2.js → chunk-M2OCZRVX.js} +14 -8
  28. package/dist/{chunk-Z3Q2AEIN.js → chunk-MTK4ZE7W.js} +17 -145
  29. package/dist/{chunk-T7WF4HYW.js → chunk-NK5PS5X7.js} +3 -3
  30. package/dist/{chunk-JEUXDY3B.js → chunk-NPH5J65M.js} +1 -1
  31. package/dist/chunk-PUSFEC6B.js +29 -0
  32. package/dist/{chunk-BNBCMCYN.js → chunk-Q764EZND.js} +78 -72
  33. package/dist/chunk-QOJXLXDJ.js +55 -0
  34. package/dist/{chunk-HVMCPKOZ.js → chunk-QPUPWGZ3.js} +1 -1
  35. package/dist/{chunk-72NJKS7O.js → chunk-RLPMXKDQ.js} +8921 -10119
  36. package/dist/{chunk-NLEXY2TM.js → chunk-S74XV3A6.js} +7 -5
  37. package/dist/{chunk-KTJXD27G.js → chunk-SHB7A2JE.js} +3 -3
  38. package/dist/{chunk-HTZ2MLYA.js → chunk-UWQXGF44.js} +25 -11
  39. package/dist/{data-integration-QE37EQ3A.js → chunk-V6UKLIM6.js} +160 -2258
  40. package/dist/{chunk-4XKTRCRK.js → chunk-VPLRZSMY.js} +22 -13
  41. package/dist/{chunk-2F64AZYH.js → chunk-Z6WSCIHM.js} +2 -2
  42. package/dist/{community-report-client-TJVCLZ3K.js → community-report-client-5VNT6HCV.js} +4 -2
  43. package/dist/{compat-check-ZJNCMNQV.js → compat-check-E7AQ7UCG.js} +6 -4
  44. package/dist/{config-FSH2NMNZ.js → config-PGSUWIK5.js} +16 -11
  45. package/dist/{context-YAQG6YQC.js → context-Y2A6QIS3.js} +9 -6
  46. package/dist/conversion-4FR3RA45.js +16 -0
  47. package/dist/data-integration-EIF5QHYF.js +2138 -0
  48. package/dist/{evaluation-2JSF4V47.js → evaluation-OZM54MES.js} +6 -5
  49. package/dist/index.js +79 -52
  50. package/dist/local-data-upload-client-2U3LFD7Z.js +16 -0
  51. package/dist/{memory-VEZZVAAP.js → memory-6QMZS4HF.js} +7 -7
  52. package/dist/{metadata-3IWHX3V4.js → metadata-7MZ3CJ2N.js} +11 -9
  53. package/dist/{model-T7H7Q6BG.js → model-LEYRQKOS.js} +8 -8
  54. package/dist/{personal-semantic-preference-YITU23SA.js → personal-semantic-preference-SWOUNDWJ.js} +46 -14
  55. package/dist/{project-semantic-MHEXJF3C.js → project-semantic-M2DDPAMD.js} +10 -8
  56. package/dist/{sync-AQHVCSPI.js → sync-PWC63JCO.js} +17 -16
  57. package/dist/{te-agent-RXI7WOH4.js → te-agent-S7UH657Z.js} +304 -16
  58. package/dist/{te-analysis-CZY74HVF.js → te-analysis-BK6PE333.js} +295 -223
  59. package/dist/{te-community-DKCYUBCM.js → te-community-OLNTKGCW.js} +17 -13
  60. package/dist/{te-dataops-QEH6VE56.js → te-dataops-XUWRIF5R.js} +18 -14
  61. package/dist/{te-engage-WK7WKDKF.js → te-engage-I3I4FJOM.js} +10 -8
  62. package/dist/{te-experiment-LH3RPIOE.js → te-experiment-XSDUL4KH.js} +216 -28
  63. package/dist/{te-kb-UPORIOVN.js → te-kb-QFH3YLFQ.js} +74 -21
  64. package/dist/{te-system-AL4B4XZL.js → te-system-DB5Z3LLF.js} +7 -7
  65. package/dist/{te-team-LLVTO2G4.js → te-team-UADF2HBO.js} +10 -8
  66. package/dist/{things-XLMLBYQR.js → things-G2QFXDK7.js} +10 -8
  67. package/dist/{update-7J5UQHSK.js → update-6I366ICW.js} +10 -9
  68. package/dist/web-runtime-3XFREWRF.js +2367 -0
  69. package/dist/{workspace-FF2HXJGR.js → workspace-RZESYB6T.js} +7 -7
  70. package/package.json +9 -5
  71. package/skills/ae-agent/SKILL.md +19 -5
  72. package/skills/ae-agent/references/a2a.md +103 -0
  73. package/skills/ae-agent/references/command_index.md +11 -0
  74. package/skills/ae-analysis/SKILL.md +35 -23
  75. package/skills/ae-analysis/references/analysis_data_retrieval.md +1 -1
  76. package/skills/ae-analysis/references/asset_authentication_export.md +1 -1
  77. package/skills/ae-analysis/references/asset_authentication_update.md +6 -2
  78. package/skills/ae-analysis/references/bad_case_review.md +4 -4
  79. package/skills/ae-analysis/references/command_index.md +7 -7
  80. package/skills/ae-analysis/references/governance_recommendation_export.md +2 -2
  81. package/skills/ae-analysis/references/personal_semantic_preference_add.md +9 -1
  82. package/skills/ae-analysis/references/personal_semantic_preference_delete.md +2 -0
  83. package/skills/ae-analysis/references/personal_semantic_preference_get.md +2 -0
  84. package/skills/ae-analysis/references/personal_semantic_preference_list.md +10 -2
  85. package/skills/ae-analysis/references/personal_semantic_preference_update.md +8 -0
  86. package/skills/ae-analysis/references/project_owner_update.md +5 -1
  87. package/skills/ae-analysis/references/scenario_evaluation.md +17 -1
  88. package/skills/ae-analysis/references/scenario_list.md +5 -6
  89. package/skills/ae-capability/SKILL.md +8 -4
  90. package/skills/ae-data-integration/references/ue-mapping.md +2 -0
  91. package/skills/ae-experiment/SKILL.md +45 -16
  92. package/skills/ae-experiment/references/experiment_approval.md +87 -29
  93. package/skills/ae-experiment/references/manage_experiment.md +7 -3
  94. package/skills/ae-experiment/references/manage_traffic_domains.md +131 -0
  95. package/skills/ae-experiment/references/query_experiment_detail.md +8 -0
  96. package/skills/ae-experiment/references/query_experiment_list.md +6 -0
  97. package/skills/ae-experiment/references/save_experiment.md +39 -13
  98. package/skills/ae-experiment/references/save_metric.md +29 -2
  99. package/skills/ae-experiment/references/save_submit_experiment.md +11 -7
  100. package/skills/ae-experiment/references/save_submit_external_experiment.md +16 -14
  101. package/skills/ae-experiment/references/save_traffic_layer.md +17 -1
  102. package/skills/ae-kb/SKILL.md +4 -2
  103. package/skills/ae-kb/references/publication.md +45 -0
  104. package/skills/ae-onboarding/SKILL.md +64 -0
  105. package/skills/ae-onboarding/references/business-sdk.md +8 -0
  106. package/skills/ae-onboarding/references/demo-operations.md +79 -0
  107. package/skills/ae-onboarding/references/import.md +19 -0
  108. package/skills/ae-onboarding/references/onboarding_experiment_launch.md +12 -0
  109. package/skills/ae-onboarding/references/onboarding_experiment_plan.md +14 -0
  110. package/skills/ae-onboarding/references/onboarding_growth.md +36 -0
  111. package/skills/ae-onboarding/references/onboarding_run.md +11 -0
  112. package/skills/ae-onboarding/references/onboarding_status.md +5 -0
  113. package/skills/ae-onboarding/scripts/experiment-preset.json +252 -0
  114. package/skills/ae-onboarding/scripts/experiment-requests.mjs +120 -0
  115. package/skills/ae-onboarding/scripts/generate.mjs +170 -0
  116. package/skills/ae-onboarding/scripts/resolve-experiment-preset.mjs +26 -0
  117. package/skills/ae-onboarding/scripts/web-journey.mjs +39 -0
  118. package/dist/chunk-6ZIQV5GW.js +0 -26
  119. package/dist/chunk-Y74WTIKJ.js +0 -10
@@ -1,22 +1,22 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  resolveWorkspaceTarget
4
- } from "./chunk-KTJXD27G.js";
4
+ } from "./chunk-SHB7A2JE.js";
5
5
  import {
6
6
  currentAgentSpaceId
7
7
  } from "./chunk-RK6GLDGI.js";
8
- import "./chunk-F2VFZUGG.js";
8
+ import "./chunk-LXRALNNA.js";
9
9
  import {
10
10
  TeAgentApiError,
11
11
  deleteFromMainApp,
12
12
  getFromMainApp,
13
13
  patchToMainApp,
14
14
  postToMainApp
15
- } from "./chunk-5M5LBRR3.js";
16
- import "./chunk-Y74WTIKJ.js";
17
- import "./chunk-HTZ2MLYA.js";
18
- import "./chunk-4PSTYEG5.js";
19
- import "./chunk-Z3Q2AEIN.js";
15
+ } from "./chunk-CYZV5AXW.js";
16
+ import "./chunk-UWQXGF44.js";
17
+ import "./chunk-IGU3R2JD.js";
18
+ import "./chunk-MTK4ZE7W.js";
19
+ import "./chunk-3ZQY7SLZ.js";
20
20
 
21
21
  // src/commands/automation/index.ts
22
22
  import { randomUUID } from "crypto";
@@ -1,23 +1,23 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import {
3
- resolveHost
4
- } from "./chunk-2F64AZYH.js";
5
- import {
6
- confirmHighRiskWrite,
7
- normalizeRiskLevel,
8
- requiresConfirmation
9
- } from "./chunk-CF6JTT2U.js";
10
2
  import {
11
3
  findGatewayDomain,
12
4
  listCapabilityDiscoveryPrefixes,
13
5
  listRegisteredCapabilityDomains,
14
6
  resolveGatewayDomain
15
7
  } from "./chunk-AWW2T2WL.js";
8
+ import {
9
+ confirmHighRiskWrite,
10
+ normalizeRiskLevel,
11
+ requiresConfirmation
12
+ } from "./chunk-GYODT7C4.js";
13
+ import {
14
+ resolveHost
15
+ } from "./chunk-Z6WSCIHM.js";
16
16
  import {
17
17
  printError,
18
18
  printOutput,
19
19
  withOutputMetadata
20
- } from "./chunk-3ULDJJTZ.js";
20
+ } from "./chunk-DE5XHQQ6.js";
21
21
  import {
22
22
  CapabilityGatewayError,
23
23
  dryRunCapabilityWithEnvelope,
@@ -26,26 +26,29 @@ import {
26
26
  inspectCapabilityWithEnvelope,
27
27
  listCapabilitiesWithEnvelope,
28
28
  validateCapabilityWithEnvelope
29
- } from "./chunk-4XKTRCRK.js";
30
- import "./chunk-Y74WTIKJ.js";
29
+ } from "./chunk-VPLRZSMY.js";
30
+ import "./chunk-6E6HCTP2.js";
31
31
  import {
32
32
  assertBusinessEnabled,
33
33
  businessForCapability,
34
34
  readBusinessConfigForExecution,
35
35
  readCurrentBusinessConfig
36
- } from "./chunk-DWBYNGSR.js";
36
+ } from "./chunk-FNACCKQR.js";
37
+ import "./chunk-PUSFEC6B.js";
37
38
  import {
38
39
  CredentialStoreUnreadableError,
39
40
  SecureStoreAuthError
40
- } from "./chunk-HTZ2MLYA.js";
41
+ } from "./chunk-UWQXGF44.js";
41
42
  import {
42
43
  parseJsonRequest
43
- } from "./chunk-4PSTYEG5.js";
44
+ } from "./chunk-IGU3R2JD.js";
45
+ import {
46
+ ExternalCliTokenError
47
+ } from "./chunk-MTK4ZE7W.js";
44
48
  import {
45
49
  CliValidationError,
46
- ExternalCliTokenError,
47
50
  PermissionError
48
- } from "./chunk-Z3Q2AEIN.js";
51
+ } from "./chunk-3ZQY7SLZ.js";
49
52
 
50
53
  // src/commands/capability/helpers.ts
51
54
  import { readFileSync } from "fs";
@@ -0,0 +1,344 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ internalCallSourceHeaders
4
+ } from "./chunk-UWQXGF44.js";
5
+ import {
6
+ logger
7
+ } from "./chunk-MTK4ZE7W.js";
8
+ import {
9
+ PermissionError
10
+ } from "./chunk-3ZQY7SLZ.js";
11
+
12
+ // src/core/device-auth.ts
13
+ import { execFileSync } from "child_process";
14
+
15
+ // src/core/abort-signal.ts
16
+ function boundedRequestSignal(parent, milliseconds) {
17
+ const controller = new AbortController();
18
+ const abort = () => controller.abort();
19
+ const timer = setTimeout(abort, milliseconds);
20
+ timer.unref();
21
+ parent?.addEventListener("abort", abort, { once: true });
22
+ controller.signal.addEventListener("abort", () => {
23
+ clearTimeout(timer);
24
+ parent?.removeEventListener("abort", abort);
25
+ }, { once: true });
26
+ if (parent?.aborted) abort();
27
+ return controller.signal;
28
+ }
29
+
30
+ // src/core/device-auth.ts
31
+ function deviceApiPath(protocol, action) {
32
+ return protocol === "uba" ? `/v1/ta/cli/auth/device/${action}` : `/api/auth/device/${action}`;
33
+ }
34
+ function ubaAuthorizationDenial(code) {
35
+ if (code === "CLI_ACCESS_DISABLED") return {
36
+ code,
37
+ message: "CLI access is disabled for this account.",
38
+ hint: "Contact your administrator."
39
+ };
40
+ if (code === "ACCOUNT_UNAVAILABLE") return {
41
+ code,
42
+ message: "This account is unavailable.",
43
+ hint: "Contact your administrator or sign in with an active account."
44
+ };
45
+ if (code === "ORIGIN_DENIED") return {
46
+ code,
47
+ message: "Authorization must be approved from the trusted platform page.",
48
+ hint: "Open the verification URL on the configured AE host and sign in there."
49
+ };
50
+ return {
51
+ code: "AUTHORIZATION_DENIED",
52
+ message: "Device authorization was denied.",
53
+ hint: "Check your account status with your administrator before requesting authorization again."
54
+ };
55
+ }
56
+ var DeviceFlowUnsupportedError = class extends Error {
57
+ constructor(httpStatus) {
58
+ super("This AE server does not support device code login (it may be an older server version).");
59
+ this.httpStatus = httpStatus;
60
+ this.name = "DeviceFlowUnsupportedError";
61
+ }
62
+ httpStatus;
63
+ };
64
+ function looksLikeMissingEndpoint(status, contentType, body) {
65
+ if (status === 404) return true;
66
+ if (contentType && contentType.toLowerCase().includes("text/html")) return true;
67
+ const head = body.trimStart().toLowerCase();
68
+ return head.startsWith("<!doctype html") || head.startsWith("<html");
69
+ }
70
+ function openBrowser(url, _execFile) {
71
+ let parsedUrl;
72
+ try {
73
+ parsedUrl = new URL(url);
74
+ } catch {
75
+ logger.warn(`openBrowser: invalid URL, not opening`);
76
+ return false;
77
+ }
78
+ if (!["http:", "https:"].includes(parsedUrl.protocol)) {
79
+ logger.warn(`openBrowser: unsafe protocol "${parsedUrl.protocol}", not opening`);
80
+ return false;
81
+ }
82
+ const safeLogUrl = `${parsedUrl.origin}${parsedUrl.pathname}`;
83
+ const exec = _execFile ?? execFileSync;
84
+ try {
85
+ if (process.platform === "darwin") {
86
+ exec("open", [url], { timeout: 5e3 });
87
+ return true;
88
+ }
89
+ if (process.platform === "win32") {
90
+ exec("cmd", ["/c", "start", "", url], { timeout: 5e3 });
91
+ return true;
92
+ }
93
+ exec("xdg-open", [url], { timeout: 5e3 });
94
+ return true;
95
+ } catch (e) {
96
+ logger.warn(`openBrowser: failed to open ${safeLogUrl}`);
97
+ return false;
98
+ }
99
+ }
100
+ async function authorizeDevice(host, protocol = "legacy", signal) {
101
+ const base = host.replace(/\/+$/, "");
102
+ const url = `${base}${deviceApiPath(protocol, "authorize")}`;
103
+ let resp;
104
+ try {
105
+ resp = await fetch(url, {
106
+ method: "POST",
107
+ headers: {
108
+ "Content-Type": "application/json",
109
+ ...internalCallSourceHeaders(),
110
+ ...protocol === "uba" ? { "X-CLI-Verification-Origin": new URL(host).origin } : {}
111
+ },
112
+ redirect: "error",
113
+ signal: boundedRequestSignal(signal, 1e4)
114
+ });
115
+ } catch (e) {
116
+ signal?.throwIfAborted();
117
+ throw new Error("Device authorize request failed. Check the AE host and network, then retry.");
118
+ }
119
+ const contentType = resp.headers.get("content-type");
120
+ const text = await resp.text().catch(() => "");
121
+ signal?.throwIfAborted();
122
+ if (looksLikeMissingEndpoint(resp.status, contentType, text)) {
123
+ throw new DeviceFlowUnsupportedError(resp.status);
124
+ }
125
+ if (!resp.ok) {
126
+ if (resp.status === 403) {
127
+ if (protocol === "uba") {
128
+ let code;
129
+ try {
130
+ code = JSON.parse(text)?.code;
131
+ } catch {
132
+ }
133
+ const denial = ubaAuthorizationDenial(code);
134
+ throw new PermissionError(denial.message, denial.code, denial.hint);
135
+ }
136
+ throw new PermissionError("CLI authorization is not allowed.", "CLI_ACCESS_DISABLED", "Contact your administrator.");
137
+ }
138
+ throw new Error(`Device authorize returned HTTP ${resp.status}`);
139
+ }
140
+ let body;
141
+ try {
142
+ body = JSON.parse(text);
143
+ } catch {
144
+ throw new Error("Device authorize returned invalid JSON");
145
+ }
146
+ if (typeof body.device_code !== "string" || !body.device_code || typeof body.user_code !== "string" || !body.user_code) {
147
+ throw new Error("Device authorize response missing required fields");
148
+ }
149
+ if (protocol === "uba" && (!Number.isInteger(body.expires_in) || body.expires_in < 1 || body.expires_in > 300 || !Number.isInteger(body.interval) || body.interval < 1 || body.interval > body.expires_in)) {
150
+ throw new Error("UBA authorization returned invalid polling limits. Check the server deployment.");
151
+ }
152
+ return body;
153
+ }
154
+ async function pollDeviceToken(host, deviceCode, protocol = "legacy", signal) {
155
+ const base = host.replace(/\/+$/, "");
156
+ const url = `${base}${deviceApiPath(protocol, "token")}`;
157
+ let resp;
158
+ try {
159
+ resp = await fetch(url, {
160
+ method: "POST",
161
+ headers: { "Content-Type": "application/json", ...internalCallSourceHeaders() },
162
+ body: JSON.stringify({ device_code: deviceCode }),
163
+ redirect: "error",
164
+ signal: boundedRequestSignal(signal, 1e4)
165
+ });
166
+ } catch (e) {
167
+ signal?.throwIfAborted();
168
+ return { status: "error", message: "Network error while polling authorization." };
169
+ }
170
+ if (resp.status === 200) {
171
+ let body;
172
+ try {
173
+ body = await resp.json();
174
+ } catch {
175
+ return { status: "error", message: "Token response is not valid JSON" };
176
+ }
177
+ if (typeof body.access_token !== "string" || !body.access_token) {
178
+ return { status: "error", message: "Token response missing access_token" };
179
+ }
180
+ return { status: "approved", tokens: body };
181
+ }
182
+ if (resp.status === 400) {
183
+ let errorBody;
184
+ try {
185
+ errorBody = await resp.json();
186
+ } catch {
187
+ errorBody = {};
188
+ }
189
+ const err = errorBody.error;
190
+ if (err === "authorization_pending") return { status: "pending" };
191
+ if (err === "slow_down") return { status: "slow_down" };
192
+ if (err === "expired_token") return { status: "expired" };
193
+ if (err === "access_denied") return {
194
+ status: "denied",
195
+ code: "AUTHORIZATION_DENIED",
196
+ message: "Device authorization was denied.",
197
+ hint: "Run ae-cli auth login again only when you want to request authorization."
198
+ };
199
+ return { status: "error", message: "Token endpoint returned an unrecognized authorization error." };
200
+ }
201
+ if (resp.status === 403) {
202
+ let errorBody = {};
203
+ try {
204
+ errorBody = await resp.json();
205
+ } catch {
206
+ }
207
+ if (protocol === "uba") return { status: "denied", ...ubaAuthorizationDenial(errorBody.code) };
208
+ return {
209
+ status: "denied",
210
+ code: errorBody.code ?? "CLI_ACCESS_DISABLED",
211
+ message: errorBody.message ?? errorBody.error ?? "CLI access is disabled for this account.",
212
+ hint: errorBody.hint
213
+ };
214
+ }
215
+ const contentType = resp.headers.get("content-type");
216
+ const text = await resp.text().catch(() => "");
217
+ signal?.throwIfAborted();
218
+ if (looksLikeMissingEndpoint(resp.status, contentType, text)) {
219
+ return { status: "unsupported" };
220
+ }
221
+ return { status: "error", message: `Unexpected HTTP ${resp.status} from token endpoint` };
222
+ }
223
+ function buildVerificationUrl(host, userCode, protocol = "legacy") {
224
+ if (protocol === "uba") {
225
+ return `${host.replace(/\/+$/, "")}/#/cli/device-activate?user_code=${encodeURIComponent(userCode)}`;
226
+ }
227
+ return `${host.replace(/\/+$/, "")}/device-activate?user_code=${encodeURIComponent(userCode)}`;
228
+ }
229
+ async function pollDeviceFlow(host, deviceCode, options = {}, onStatus) {
230
+ const emit = (msg) => {
231
+ if (onStatus) onStatus(msg);
232
+ };
233
+ let intervalMs = options.intervalMs ?? 5e3;
234
+ const expiresIn = options.expiresIn ?? 300;
235
+ const deadline = Date.now() + expiresIn * 1e3;
236
+ let pollCount = 0;
237
+ while (Date.now() < deadline) {
238
+ await sleep(intervalMs);
239
+ pollCount++;
240
+ const result = await pollDeviceToken(host, deviceCode, options.protocol);
241
+ if (result.status === "approved") {
242
+ emit(`Authorization successful! (polled ${pollCount} time(s))`);
243
+ return result.tokens;
244
+ }
245
+ if (result.status === "pending") {
246
+ if (pollCount % 5 === 0) {
247
+ const remaining = Math.max(0, Math.round((deadline - Date.now()) / 1e3));
248
+ emit(`Waiting for authorization... (expires in ${remaining}s)`);
249
+ }
250
+ logger.info(`device-auth: poll #${pollCount} pending`);
251
+ continue;
252
+ }
253
+ if (result.status === "slow_down") {
254
+ intervalMs += 5e3;
255
+ logger.info(`device-auth: slow_down received, new interval=${intervalMs}ms`);
256
+ continue;
257
+ }
258
+ if (result.status === "expired") {
259
+ throw new Error(
260
+ `Device code has expired. Please run ae-cli auth login again to restart the authorization flow.`
261
+ );
262
+ }
263
+ if (result.status === "denied") {
264
+ throw new PermissionError(result.message, result.code, result.hint);
265
+ }
266
+ if (result.status === "unsupported") {
267
+ throw new DeviceFlowUnsupportedError();
268
+ }
269
+ if (result.status === "error") {
270
+ logger.warn(`device-auth: poll error: ${result.message}`);
271
+ emit(`Poll error: ${result.message}`);
272
+ if (result.message.includes("HTTP 401") || result.message.includes("HTTP 403")) {
273
+ throw new Error(`Authorization denied (${result.message}). Please check your configuration or run ae-cli auth login again.`);
274
+ }
275
+ continue;
276
+ }
277
+ }
278
+ throw new Error(
279
+ `Authorization timed out (not completed within ${expiresIn}s). Please run ae-cli auth login again.`
280
+ );
281
+ }
282
+ async function runDeviceFlow(host, options = {}, onStatus) {
283
+ const emit = (msg) => {
284
+ if (onStatus) onStatus(msg);
285
+ };
286
+ emit("Requesting authorization code from server...");
287
+ const auth = options.authorization ?? await authorizeDevice(host, options.protocol);
288
+ const userCode = auth.user_code;
289
+ const verifyUrl = buildVerificationUrl(host, userCode, options.protocol);
290
+ const expiresIn = auth.expires_in ?? 300;
291
+ emit("");
292
+ emit(`Verification code: ${userCode}`);
293
+ emit(`Open the following link in your browser to complete authorization:`);
294
+ emit(` ${verifyUrl}`);
295
+ emit("");
296
+ if (!options.noBrowser) {
297
+ const opened = openBrowser(verifyUrl);
298
+ if (opened) {
299
+ emit("(Attempted to open the link in your browser)");
300
+ } else {
301
+ emit("(Could not open browser automatically; please copy the link above manually)");
302
+ }
303
+ emit("");
304
+ }
305
+ return pollDeviceFlow(host, auth.device_code, { intervalMs: (auth.interval ?? 5) * 1e3, expiresIn, protocol: options.protocol }, onStatus);
306
+ }
307
+ function sleep(ms) {
308
+ return new Promise((resolve) => setTimeout(resolve, ms));
309
+ }
310
+
311
+ // src/core/login-device-flow.ts
312
+ function resolveLegacyLoginBase(host) {
313
+ const base = host.replace(/\/+$/, "");
314
+ const basePath = process.env.TE_CLAUDE_BASE_PATH || "/agent";
315
+ return base.endsWith(basePath) ? base : base + basePath;
316
+ }
317
+ function resolveDeviceSessionRoute(host, deviceCode) {
318
+ return deviceCode.startsWith("uba_") ? { baseUrl: host, protocol: "uba" } : { baseUrl: resolveLegacyLoginBase(host), protocol: "legacy" };
319
+ }
320
+ async function authorizeLoginDevice(host, signal) {
321
+ try {
322
+ const authorization = await authorizeDevice(host, "uba", signal);
323
+ if (!/^uba_[A-Za-z0-9_-]+$/.test(authorization.device_code)) {
324
+ throw new Error("UBA authorization returned an unsupported device-code format. Check the server deployment.");
325
+ }
326
+ return { baseUrl: host, protocol: "uba", authorization };
327
+ } catch (error) {
328
+ if (!(error instanceof DeviceFlowUnsupportedError) || error.httpStatus !== 404) throw error;
329
+ const baseUrl = resolveLegacyLoginBase(host);
330
+ return { baseUrl, protocol: "legacy", authorization: await authorizeDevice(baseUrl, "legacy", signal) };
331
+ }
332
+ }
333
+
334
+ export {
335
+ DeviceFlowUnsupportedError,
336
+ openBrowser,
337
+ pollDeviceToken,
338
+ buildVerificationUrl,
339
+ pollDeviceFlow,
340
+ runDeviceFlow,
341
+ resolveLegacyLoginBase,
342
+ resolveDeviceSessionRoute,
343
+ authorizeLoginDevice
344
+ };
@@ -4,15 +4,15 @@ import {
4
4
  } from "./chunk-AWW2T2WL.js";
5
5
  import {
6
6
  withOutputMetadata
7
- } from "./chunk-3ULDJJTZ.js";
7
+ } from "./chunk-DE5XHQQ6.js";
8
8
  import {
9
9
  dryRunCapabilityWithEnvelope,
10
10
  executeCapabilityWithEnvelope,
11
11
  validateCapabilityWithEnvelope
12
- } from "./chunk-4XKTRCRK.js";
12
+ } from "./chunk-VPLRZSMY.js";
13
13
  import {
14
14
  CliValidationError
15
- } from "./chunk-Z3Q2AEIN.js";
15
+ } from "./chunk-3ZQY7SLZ.js";
16
16
 
17
17
  // src/core/capability-command.ts
18
18
  import { randomBytes } from "crypto";
@@ -0,0 +1,147 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __esm = (fn, res, err) => function __init() {
15
+ if (err) throw err[0];
16
+ try {
17
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
18
+ } catch (e) {
19
+ throw err = [e], e;
20
+ }
21
+ };
22
+ var __commonJS = (cb, mod) => function __require2() {
23
+ try {
24
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
25
+ } catch (e) {
26
+ throw mod = 0, e;
27
+ }
28
+ };
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, { get: all[name], enumerable: true });
32
+ };
33
+ var __copyProps = (to, from, except, desc) => {
34
+ if (from && typeof from === "object" || typeof from === "function") {
35
+ for (let key of __getOwnPropNames(from))
36
+ if (!__hasOwnProp.call(to, key) && key !== except)
37
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
38
+ }
39
+ return to;
40
+ };
41
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
42
+ // If the importer is in node compatibility mode or this is not an ESM
43
+ // file that has been converted to a CommonJS file using a Babel-
44
+ // compatible transform (i.e. "__esModule" has not been set), then set
45
+ // "default" to the CommonJS "module.exports" for node compatibility.
46
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
47
+ mod
48
+ ));
49
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
+
51
+ // src/core/errors.ts
52
+ var PermissionError = class extends Error {
53
+ constructor(message, code, hint, details, meta) {
54
+ super(message);
55
+ this.code = code;
56
+ this.hint = hint;
57
+ this.details = details;
58
+ this.meta = meta;
59
+ this.name = "PermissionError";
60
+ }
61
+ code;
62
+ hint;
63
+ details;
64
+ meta;
65
+ };
66
+ function isApiErrorType(value) {
67
+ return value === "auth" || value === "permission" || value === "validation" || value === "not_found" || value === "api";
68
+ }
69
+ var CliValidationError = class extends Error {
70
+ code;
71
+ hint;
72
+ location;
73
+ constructor(message, options = {}) {
74
+ super(message);
75
+ this.name = "CliValidationError";
76
+ this.code = options.code;
77
+ this.hint = options.hint;
78
+ if (options.location) {
79
+ const location = {};
80
+ if (typeof options.location.segment === "number" && Number.isFinite(options.location.segment)) {
81
+ location.segment = options.location.segment;
82
+ }
83
+ if (typeof options.location.record === "number" && Number.isFinite(options.location.record)) {
84
+ location.record = options.location.record;
85
+ }
86
+ if (typeof options.location.field === "string" && options.location.field.length > 0) {
87
+ location.field = options.location.field;
88
+ }
89
+ if (Object.keys(location).length > 0) this.location = location;
90
+ }
91
+ }
92
+ };
93
+ var CliApiError = class extends Error {
94
+ code;
95
+ hint;
96
+ meta;
97
+ constructor(message, options = {}) {
98
+ super(message);
99
+ this.name = "CliApiError";
100
+ this.code = options.code;
101
+ this.hint = options.hint;
102
+ this.meta = options.meta;
103
+ }
104
+ };
105
+ var CommunityReportError = class extends Error {
106
+ code;
107
+ httpStatus;
108
+ hint;
109
+ meta;
110
+ constructor(message, options = {}) {
111
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
112
+ this.name = "CommunityReportError";
113
+ this.code = options.code;
114
+ this.httpStatus = options.httpStatus;
115
+ this.hint = options.hint;
116
+ this.meta = options.meta;
117
+ }
118
+ };
119
+ var LocalDataUploadError = class extends Error {
120
+ code;
121
+ httpStatus;
122
+ hint;
123
+ meta;
124
+ constructor(message, options = {}) {
125
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
126
+ this.name = "LocalDataUploadError";
127
+ this.code = options.code;
128
+ this.httpStatus = options.httpStatus;
129
+ this.hint = options.hint;
130
+ this.meta = options.meta;
131
+ }
132
+ };
133
+
134
+ export {
135
+ __require,
136
+ __esm,
137
+ __commonJS,
138
+ __export,
139
+ __toESM,
140
+ __toCommonJS,
141
+ PermissionError,
142
+ isApiErrorType,
143
+ CliValidationError,
144
+ CliApiError,
145
+ CommunityReportError,
146
+ LocalDataUploadError
147
+ };
@@ -0,0 +1,60 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ getLocalCliPackageInfo
4
+ } from "./chunk-PUSFEC6B.js";
5
+ import {
6
+ getAeSandboxDetectionReason
7
+ } from "./chunk-IGU3R2JD.js";
8
+ import {
9
+ logger
10
+ } from "./chunk-MTK4ZE7W.js";
11
+
12
+ // src/core/source-logged-fetch.ts
13
+ import { randomUUID } from "crypto";
14
+ var CLI_REQUEST_ID_HEADER = "X-TA-CLI-Request-Id";
15
+ var localPackage = getLocalCliPackageInfo();
16
+ var MAX_LOG_VALUE_LENGTH = 256;
17
+ function bounded(value) {
18
+ return value.length > MAX_LOG_VALUE_LENGTH ? `${value.slice(0, MAX_LOG_VALUE_LENGTH)}...[truncated]` : value;
19
+ }
20
+ function sourceLoggedFetch(url, init) {
21
+ const requestId = randomUUID();
22
+ let headers;
23
+ if (init.headers instanceof Headers) {
24
+ headers = new Headers(init.headers);
25
+ headers.set(CLI_REQUEST_ID_HEADER, requestId);
26
+ } else if (Array.isArray(init.headers)) {
27
+ headers = [
28
+ ...init.headers.filter(([name]) => name.toLowerCase() !== CLI_REQUEST_ID_HEADER.toLowerCase()),
29
+ [CLI_REQUEST_ID_HEADER, requestId]
30
+ ];
31
+ } else {
32
+ headers = Object.fromEntries(Object.entries(init.headers ?? {}).filter(([name]) => name.toLowerCase() !== CLI_REQUEST_ID_HEADER.toLowerCase()));
33
+ headers[CLI_REQUEST_ID_HEADER] = requestId;
34
+ }
35
+ const request = { ...init, headers };
36
+ try {
37
+ const target = new URL(url);
38
+ const actualHeaders = new Headers(headers);
39
+ const source = actualHeaders.get("X-Source");
40
+ const sandboxDetection = getAeSandboxDetectionReason();
41
+ logger.info(`CLI_SOURCE_SEND ${JSON.stringify({
42
+ request_id: requestId,
43
+ method: init.method ?? "GET",
44
+ host: bounded(target.host),
45
+ path: bounded(target.pathname),
46
+ source: source === null ? null : bounded(source),
47
+ source_state: source === null ? "missing" : source === "" ? "empty" : source.includes(",") ? "multiple" : "present",
48
+ cli_package: localPackage.name,
49
+ cli_version: localPackage.version,
50
+ sandbox_detected: sandboxDetection !== "not_detected",
51
+ sandbox_detection: sandboxDetection
52
+ })}`);
53
+ } catch {
54
+ }
55
+ return fetch(url, request);
56
+ }
57
+
58
+ export {
59
+ sourceLoggedFetch
60
+ };