@thinkingai/ae-cli 6.1.27 → 6.1.29

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 (177) hide show
  1. package/README.md +52 -6
  2. package/README.zh.md +52 -6
  3. package/bin/ae-cli.js +5 -0
  4. package/bin/runtime-capabilities.json +5 -0
  5. package/cli-installation-guide.md +24 -3
  6. package/dist/{auth-WA7YGGRT.js → auth-OBQ5KVQM.js} +175 -45
  7. package/dist/{automation-VAAQBM7Y.js → automation-NAR5DDGL.js} +94 -38
  8. package/dist/{capability-GAAYJ3IQ.js → capability-LFSVNI5B.js} +57 -28
  9. package/dist/chunk-2UW3Y463.js +2289 -0
  10. package/dist/{chunk-VZZNLV3I.js → chunk-3SDHJOCR.js} +68 -18
  11. package/dist/chunk-6HAUVWOQ.js +132 -0
  12. package/dist/{chunk-5XJYLEVC.js → chunk-72NJKS7O.js} +4 -4
  13. package/dist/{chunk-Q5US7JC5.js → chunk-7JAVT5TK.js} +3 -3
  14. package/dist/{chunk-7KU2WNQE.js → chunk-CVCTFLSO.js} +37 -15
  15. package/dist/{chunk-GHXZK54S.js → chunk-H3K5UGYC.js} +41 -13
  16. package/dist/{chunk-OP44TT4H.js → chunk-IN7KKL6K.js} +4 -2
  17. package/dist/{chunk-S6M42KND.js → chunk-JEUXDY3B.js} +1 -1
  18. package/dist/{chunk-ZL7SGNIA.js → chunk-JNVVJ273.js} +58 -46
  19. package/dist/chunk-N6XBLRB7.js +105 -0
  20. package/dist/{chunk-AP7YP2NX.js → chunk-OAWPT7VP.js} +2 -2
  21. package/dist/{chunk-AQJPNWZF.js → chunk-PWXDWMCW.js} +7 -7
  22. package/dist/{chunk-CT7QDJS6.js → chunk-QVRIDN42.js} +2 -2
  23. package/dist/chunk-QZLRHGVH.js +222 -0
  24. package/dist/{chunk-RPBOAQQQ.js → chunk-QZUVLFNR.js} +1 -1
  25. package/dist/{chunk-3YVEAZUN.js → chunk-RJHGDWSC.js} +32 -21
  26. package/dist/{chunk-MWIA43UJ.js → chunk-VCZE3IWO.js} +10 -8
  27. package/dist/chunk-YVG6QD3V.js +233 -0
  28. package/dist/{chunk-WNGFSIOB.js → chunk-Z3Q2AEIN.js} +237 -86
  29. package/dist/{community-report-client-PEERQCX2.js → community-report-client-TJVCLZ3K.js} +1 -1
  30. package/dist/compat-check-CII6B74E.js +32 -0
  31. package/dist/{config-JOD5DOPE.js → config-YZ6O2UQ2.js} +40 -7
  32. package/dist/{context-NGVFPCBK.js → context-F6FCGTF3.js} +4 -4
  33. package/dist/{data-integration-BCLQFTGU.js → data-integration-6UAZO4GG.js} +207 -24
  34. package/dist/evaluation-4LO2O4AF.js +3714 -0
  35. package/dist/index.js +352 -81
  36. package/dist/{local-data-upload-client-TWMHFLUA.js → local-data-upload-client-KCMG6J62.js} +1 -1
  37. package/dist/{memory-CQKH2JAV.js → memory-HHPX3NF2.js} +6 -6
  38. package/dist/{metadata-NR3PHR23.js → metadata-TIFY24LW.js} +17 -9
  39. package/dist/{model-VX5M2CJ6.js → model-7UHGWYVR.js} +4 -4
  40. package/dist/{personal-semantic-preference-2RAI36P3.js → personal-semantic-preference-WKJEGPTM.js} +7 -6
  41. package/dist/{project-semantic-3BUGP3ZM.js → project-semantic-EIQVZNHW.js} +11 -10
  42. package/dist/{sync-RZIAV37C.js → sync-RV3OPCTI.js} +8 -7
  43. package/dist/{te-agent-AORRE2FM.js → te-agent-5ENVZJUH.js} +757 -94
  44. package/dist/{te-analysis-GP7DSQ7Q.js → te-analysis-USIK6ZZG.js} +584 -100
  45. package/dist/{te-community-42M7ICDO.js → te-community-WE2UU4XV.js} +722 -228
  46. package/dist/{te-dataops-BNKNZ4F2.js → te-dataops-XNMO7MBF.js} +9 -6
  47. package/dist/{te-engage-2CO6LRCX.js → te-engage-6C3HCFQR.js} +13 -12
  48. package/dist/{te-experiment-652CLXMU.js → te-experiment-LVTRI3QK.js} +55 -21
  49. package/dist/{te-kb-ULATOTQ3.js → te-kb-TUPGMVBY.js} +409 -85
  50. package/dist/{te-system-UGHVKBVV.js → te-system-YM657FKO.js} +6 -6
  51. package/dist/{te-team-YA6SNOJ3.js → te-team-G4VEJJNL.js} +64 -41
  52. package/dist/{things-DTCOQIQB.js → things-22KQWC23.js} +7 -7
  53. package/dist/{update-ESNYKUVR.js → update-XX4ILU7X.js} +11 -7
  54. package/dist/{workspace-JEOHKFPX.js → workspace-LYDAP647.js} +6 -6
  55. package/package.json +26 -11
  56. package/skills/ae-agent/SKILL.md +22 -3
  57. package/skills/ae-agent/references/command_index.md +8 -0
  58. package/skills/ae-agent/references/resource-package.md +57 -0
  59. package/skills/ae-analysis/SKILL.md +23 -10
  60. package/skills/ae-analysis/references/adhoc_export.md +1 -1
  61. package/skills/ae-analysis/references/agent_review_preflight.md +55 -10
  62. package/skills/ae-analysis/references/agent_review_priorities_comparisons.md +5 -3
  63. package/skills/ae-analysis/references/agent_review_submit_to_page.md +60 -24
  64. package/skills/ae-analysis/references/ai_models/event.md +58 -2
  65. package/skills/ae-analysis/references/ai_models/rank_list.md +1 -0
  66. package/skills/ae-analysis/references/ai_models/retention.md +2 -0
  67. package/skills/ae-analysis/references/ai_models/revenue.md +2 -0
  68. package/skills/ae-analysis/references/analysis_data_export.md +11 -1
  69. package/skills/ae-analysis/references/asset_batch_info_export.md +2 -2
  70. package/skills/ae-analysis/references/asset_batch_sql_export.md +2 -2
  71. package/skills/ae-analysis/references/asset_export.md +1 -1
  72. package/skills/ae-analysis/references/bi_panel_page_data_export.md +1 -1
  73. package/skills/ae-analysis/references/check_export.md +1 -1
  74. package/skills/ae-analysis/references/command_index.md +39 -26
  75. package/skills/ae-analysis/references/dashboard_report_data_export.md +2 -0
  76. package/skills/ae-analysis/references/dashboard_report_get.md +6 -2
  77. package/skills/ae-analysis/references/dashboard_report_update.md +24 -5
  78. package/skills/ae-analysis/references/feedback_submit.md +1 -1
  79. package/skills/ae-analysis/references/governance_recommendation_export.md +40 -18
  80. package/skills/ae-analysis/references/governance_recommendation_run_update.md +13 -0
  81. package/skills/ae-analysis/references/live_data_export.md +1 -1
  82. package/skills/ae-analysis/references/metric_create.md +29 -0
  83. package/skills/ae-analysis/references/metric_get.md +2 -0
  84. package/skills/ae-analysis/references/metric_update.md +2 -0
  85. package/skills/ae-analysis/references/operation_record_export.md +1 -1
  86. package/skills/ae-analysis/references/plan_change_log_export.md +1 -1
  87. package/skills/ae-analysis/references/plan_export.md +1 -1
  88. package/skills/ae-analysis/references/project_info_get.md +4 -0
  89. package/skills/ae-analysis/references/project_member_group_add_members.md +35 -0
  90. package/skills/ae-analysis/references/project_member_group_create.md +25 -0
  91. package/skills/ae-analysis/references/project_member_group_delete.md +34 -0
  92. package/skills/ae-analysis/references/project_member_group_list.md +29 -0
  93. package/skills/ae-analysis/references/project_member_group_members.md +28 -0
  94. package/skills/ae-analysis/references/project_member_group_remove_members.md +35 -0
  95. package/skills/ae-analysis/references/project_member_group_rename.md +26 -0
  96. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +9 -1
  97. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +6 -1
  98. package/skills/ae-analysis/references/report_data_export.md +1 -1
  99. package/skills/ae-analysis/references/scenario_append.md +31 -0
  100. package/skills/ae-analysis/references/scenario_begin.md +11 -0
  101. package/skills/ae-analysis/references/scenario_collect.md +43 -0
  102. package/skills/ae-analysis/references/scenario_evaluation.md +18 -0
  103. package/skills/ae-analysis/references/scenario_get.md +15 -0
  104. package/skills/ae-analysis/references/scenario_list.md +64 -0
  105. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +73 -4
  106. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +14 -1
  107. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +5 -1
  108. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/execution-contract.mjs +173 -0
  109. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/generate-build-ir.mjs +109 -64
  110. package/skills/ae-automation/SKILL.md +2 -2
  111. package/skills/ae-automation/references/cli.md +18 -1
  112. package/skills/ae-capability/SKILL.md +7 -3
  113. package/skills/ae-community/SKILL.md +77 -27
  114. package/skills/ae-community/references/community-analyzing-theme-comment.md +10 -8
  115. package/skills/ae-community/references/community-data-quality.md +68 -0
  116. package/skills/ae-community/references/community-query-evidence.md +85 -0
  117. package/skills/ae-community/references/community-scenario-capabilities.md +137 -0
  118. package/skills/ae-community/references/community-weekly-report.md +6 -3
  119. package/skills/ae-community/references/get_channel_info.md +7 -4
  120. package/skills/ae-community/references/get_comment_tag_analysis.md +3 -3
  121. package/skills/ae-community/references/get_comments_summary.md +4 -4
  122. package/skills/ae-community/references/get_corpus_tags.md +3 -3
  123. package/skills/ae-community/references/get_daily_summary.md +3 -3
  124. package/skills/ae-community/references/get_hot_topics.md +3 -3
  125. package/skills/ae-community/references/get_livestream_analysis.md +3 -3
  126. package/skills/ae-community/references/get_livestream_detail.md +4 -4
  127. package/skills/ae-community/references/get_livestream_list.md +3 -3
  128. package/skills/ae-community/references/get_livestream_overview.md +3 -3
  129. package/skills/ae-community/references/get_livestream_room_metrics.md +3 -3
  130. package/skills/ae-community/references/get_livestream_rooms.md +3 -3
  131. package/skills/ae-community/references/get_overview_metrics.md +3 -3
  132. package/skills/ae-community/references/get_post_detail.md +4 -4
  133. package/skills/ae-community/references/get_risk_content.md +5 -5
  134. package/skills/ae-community/references/get_sentiment_overview.md +4 -4
  135. package/skills/ae-community/references/get_tag_trends.md +3 -3
  136. package/skills/ae-community/references/get_topic_detail.md +3 -3
  137. package/skills/ae-community/references/list_sources.md +28 -0
  138. package/skills/ae-community/references/list_spaces.md +39 -0
  139. package/skills/ae-community/references/search_posts.md +21 -7
  140. package/skills/ae-data-integration/SKILL.md +6 -4
  141. package/skills/ae-data-integration/references/error-handling.md +1 -0
  142. package/skills/ae-data-integration/references/handoff.md +1 -1
  143. package/skills/ae-data-integration/references/sink-upload.md +11 -0
  144. package/skills/ae-data-integration/references/source-inspect.md +2 -1
  145. package/skills/ae-data-integration/references/transform.md +1 -1
  146. package/skills/ae-data-integration/references/ue-mapping.md +1 -1
  147. package/skills/ae-evaluation/SKILL.md +83 -0
  148. package/skills/ae-evaluation/references/access-and-members.md +55 -0
  149. package/skills/ae-evaluation/references/connections.md +78 -0
  150. package/skills/ae-evaluation/references/datasets.md +57 -0
  151. package/skills/ae-evaluation/references/evaluators.md +81 -0
  152. package/skills/ae-evaluation/references/files.md +33 -0
  153. package/skills/ae-evaluation/references/integrations.md +39 -0
  154. package/skills/ae-evaluation/references/runs.md +160 -0
  155. package/skills/ae-evaluation/references/schedules.md +31 -0
  156. package/skills/ae-experiment/SKILL.md +7 -1
  157. package/skills/ae-experiment/references/manage_experiment.md +18 -1
  158. package/skills/ae-experiment/references/query_experiment_detail.md +7 -0
  159. package/skills/ae-experiment/references/save_experiment.md +76 -2
  160. package/skills/ae-experiment/references/save_submit_experiment.md +7 -0
  161. package/skills/ae-kb/SKILL.md +33 -7
  162. package/skills/ae-kb/references/publication.md +81 -0
  163. package/skills/ae-kb/references/query-workflow.md +14 -1
  164. package/skills/ae-metadata/SKILL.md +3 -2
  165. package/skills/ae-metadata/references/metadata_data_table_download.md +7 -1
  166. package/skills/ae-metadata/references/metadata_data_table_get.md +37 -0
  167. package/skills/ae-system/SKILL.md +1 -1
  168. package/skills/ae-team/SKILL.md +2 -2
  169. package/skills/ae-team/references/run-start.md +1 -0
  170. package/skills/ae-team/references/run-watch.md +7 -5
  171. package/skills/ae-things/SKILL.md +53 -51
  172. package/skills/ae-things/references/cli.md +56 -54
  173. package/skills/ae-things-progress/SKILL.md +20 -20
  174. package/skills/ae-things-review/SKILL.md +19 -19
  175. package/skills/ae-workspace/SKILL.md +1 -1
  176. package/dist/chunk-6VNIR4AP.js +0 -1422
  177. package/dist/chunk-CI24BDR2.js +0 -43
@@ -4,15 +4,17 @@ import {
4
4
  } from "./chunk-Y74WTIKJ.js";
5
5
  import {
6
6
  getCliToken
7
- } from "./chunk-GHXZK54S.js";
7
+ } from "./chunk-H3K5UGYC.js";
8
8
  import {
9
9
  getActiveHost,
10
10
  getSandboxRuntimeRoot
11
- } from "./chunk-ZL7SGNIA.js";
11
+ } from "./chunk-JNVVJ273.js";
12
12
  import {
13
13
  PermissionError,
14
- isApiErrorType
15
- } from "./chunk-WNGFSIOB.js";
14
+ externalCliTokenRequestOptions,
15
+ isApiErrorType,
16
+ readExternalCliToken
17
+ } from "./chunk-Z3Q2AEIN.js";
16
18
 
17
19
  // src/core/te-agent-credentials.ts
18
20
  import { readFileSync } from "fs";
@@ -153,7 +155,7 @@ async function fetchWithTimeout(url, init, timeoutMs = DEFAULT_TIMEOUT_MS) {
153
155
  const controller = new AbortController();
154
156
  const timer = setTimeout(() => controller.abort(), timeoutMs);
155
157
  try {
156
- return await fetch(url, { ...init, signal: controller.signal });
158
+ return await fetch(url, { ...init, signal: controller.signal, ...externalCliTokenRequestOptions(url) });
157
159
  } catch (err) {
158
160
  if (err?.name === "AbortError") {
159
161
  throw new TeAgentApiError(
@@ -197,7 +199,8 @@ function teClaudeBaseFromActiveHost(hostOverride) {
197
199
  if (!h) return void 0;
198
200
  return resolveTeClaudeBaseUrl(h);
199
201
  }
200
- async function signRequest(method, path2, hostOverride, includeJsonContentType = true) {
202
+ async function signRequest(method, path2, hostOverride, includeJsonContentType = true, authMode = "auto") {
203
+ const external = readExternalCliToken(hostOverride);
201
204
  const configuredHost = hostOverride || getActiveHost();
202
205
  const sandboxOnly = !hostOverride && (/* @__PURE__ */ new Set([
203
206
  "/api/sandbox/models",
@@ -207,8 +210,8 @@ async function signRequest(method, path2, hostOverride, includeJsonContentType =
207
210
  "/api/sandbox/sync/pull",
208
211
  "/api/sandbox/sync/pull/candidates"
209
212
  ])).has(path2.split("?")[0]);
210
- const sandboxCred = configuredHost && !sandboxOnly ? null : tryLoadTeAgentSandboxCredentials();
211
- if (!hostOverride && sandboxCred && sandboxCred.sandboxId && sandboxCred.sandboxSecretKey) {
213
+ const sandboxCred = external || configuredHost && !sandboxOnly ? null : tryLoadTeAgentSandboxCredentials();
214
+ if (authMode === "auto" && !hostOverride && sandboxCred && sandboxCred.sandboxId && sandboxCred.sandboxSecretKey) {
212
215
  const headers = {
213
216
  "X-Sandbox-Id": sandboxCred.sandboxId,
214
217
  "X-Sandbox-Secret-Key": sandboxCred.sandboxSecretKey
@@ -222,7 +225,7 @@ async function signRequest(method, path2, hostOverride, includeJsonContentType =
222
225
  authKind: "sandbox"
223
226
  };
224
227
  }
225
- const baseUrl = hostOverride ? teClaudeBaseFromActiveHost(hostOverride) : sandboxCred?.url || teClaudeBaseFromActiveHost();
228
+ const baseUrl = hostOverride || external ? teClaudeBaseFromActiveHost(hostOverride || external?.url) : sandboxCred?.url || teClaudeBaseFromActiveHost();
226
229
  if (!baseUrl) {
227
230
  throw new TeAgentCredentialsError(
228
231
  "Cannot determine the te-claude service URL",
@@ -248,13 +251,14 @@ async function fetchSigned(options) {
248
251
  options.method,
249
252
  options.path,
250
253
  options.hostOverride,
251
- options.includeJsonContentType
254
+ options.includeJsonContentType,
255
+ options.authMode
252
256
  );
253
257
  return fetchWithTimeout(
254
258
  signed.url,
255
259
  {
256
260
  method: options.method,
257
- headers: signed.headers,
261
+ headers: { ...Object.fromEntries(new Headers(options.headers).entries()), ...signed.headers },
258
262
  body: options.body
259
263
  },
260
264
  options.timeoutMs
@@ -263,7 +267,7 @@ async function fetchSigned(options) {
263
267
  function errorDetails(parsed, defaultErrorPrefix, status) {
264
268
  const nested = parsed && typeof parsed === "object" && parsed.error && typeof parsed.error === "object" ? parsed.error : parsed;
265
269
  const message = typeof parsed?.error === "string" ? parsed.error : typeof nested?.message === "string" ? nested.message : typeof parsed?.message === "string" ? parsed.message : typeof parsed?.return_message === "string" ? parsed.return_message : `${defaultErrorPrefix} ${status}`;
266
- const code = typeof nested?.code === "string" ? nested.code : typeof parsed?.code === "string" ? parsed.code : void 0;
270
+ const code = typeof nested?.code === "string" ? nested.code : typeof parsed?.code === "string" ? parsed.code : typeof parsed?.errorCode === "string" ? parsed.errorCode : void 0;
267
271
  const hint = typeof nested?.hint === "string" ? nested.hint : typeof parsed?.hint === "string" ? parsed.hint : void 0;
268
272
  const declaredType = isApiErrorType(nested?.type) ? nested.type : void 0;
269
273
  const type = status === 401 ? "auth" : status === 403 ? "permission" : declaredType ?? ([400, 413, 422].includes(status) ? "validation" : status === 404 ? "not_found" : "api");
@@ -303,21 +307,23 @@ async function parseResponse(response, defaultErrorPrefix) {
303
307
  }
304
308
  return parsed;
305
309
  }
306
- async function postToMainApp(path2, body, hostOverride) {
310
+ async function postToMainApp(path2, body, hostOverride, authMode = "auto") {
307
311
  const rawBody = JSON.stringify(body);
308
312
  const response = await fetchSigned({
309
313
  method: "POST",
310
314
  path: path2,
311
315
  body: rawBody,
312
- hostOverride
316
+ hostOverride,
317
+ authMode
313
318
  });
314
319
  return parseResponse(response, "Main app returned");
315
320
  }
316
- async function getFromMainApp(path2, hostOverride) {
321
+ async function getFromMainApp(path2, hostOverride, authMode = "auto") {
317
322
  const response = await fetchSigned({
318
323
  method: "GET",
319
324
  path: path2,
320
- hostOverride
325
+ hostOverride,
326
+ authMode
321
327
  });
322
328
  return parseResponse(response, "Main app returned");
323
329
  }
@@ -347,21 +353,23 @@ async function postSandboxSyncPull(args) {
347
353
  mode: "merge"
348
354
  });
349
355
  }
350
- async function deleteFromMainApp(path2, hostOverride) {
356
+ async function deleteFromMainApp(path2, hostOverride, authMode = "auto") {
351
357
  const response = await fetchSigned({
352
358
  method: "DELETE",
353
359
  path: path2,
354
- hostOverride
360
+ hostOverride,
361
+ authMode
355
362
  });
356
363
  return parseResponse(response, "Main app returned");
357
364
  }
358
- async function patchToMainApp(path2, body, hostOverride) {
365
+ async function patchToMainApp(path2, body, hostOverride, authMode = "auto") {
359
366
  const rawBody = JSON.stringify(body);
360
367
  const response = await fetchSigned({
361
368
  method: "PATCH",
362
369
  path: path2,
363
370
  body: rawBody,
364
- hostOverride
371
+ hostOverride,
372
+ authMode
365
373
  });
366
374
  return parseResponse(response, "Main app returned");
367
375
  }
@@ -447,7 +455,8 @@ async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
447
455
  return await fetch(requestToSend.url, {
448
456
  method: "GET",
449
457
  headers: requestToSend.headers,
450
- signal: controller.signal
458
+ signal: controller.signal,
459
+ ...externalCliTokenRequestOptions(requestToSend.url)
451
460
  });
452
461
  } catch (error) {
453
462
  if (error?.name === "AbortError") {
@@ -519,7 +528,9 @@ export {
519
528
  getClaudeConfigDir,
520
529
  resolveTeClaudeBaseUrl,
521
530
  TeAgentApiError,
531
+ fetchSigned,
522
532
  createTeAgentApiError,
533
+ parseResponse,
523
534
  postToMainApp,
524
535
  getFromMainApp,
525
536
  getSandboxModels,
@@ -1,18 +1,21 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import {
3
- dryRunCapability,
4
- executeCapabilityWithEnvelope,
5
- validateCapability
6
- } from "./chunk-VZZNLV3I.js";
7
2
  import {
8
3
  resolveGatewayDomain
9
4
  } from "./chunk-KPQY44JQ.js";
10
5
  import {
11
6
  withOutputMetadata
12
- } from "./chunk-6VNIR4AP.js";
7
+ } from "./chunk-QZLRHGVH.js";
8
+ import {
9
+ dryRunCapability,
10
+ executeCapabilityWithEnvelope,
11
+ validateCapability
12
+ } from "./chunk-3SDHJOCR.js";
13
13
  import {
14
14
  CliValidationError
15
- } from "./chunk-WNGFSIOB.js";
15
+ } from "./chunk-Z3Q2AEIN.js";
16
+
17
+ // src/core/capability-command.ts
18
+ import { randomBytes } from "crypto";
16
19
 
17
20
  // src/core/definition-intent.ts
18
21
  import { createHash } from "crypto";
@@ -83,7 +86,6 @@ function isRecord(value) {
83
86
  }
84
87
 
85
88
  // src/core/capability-command.ts
86
- import { randomBytes } from "crypto";
87
89
  function createCapabilityCommand(config) {
88
90
  return {
89
91
  service: config.cliService,
@@ -0,0 +1,233 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ CliValidationError,
4
+ logger
5
+ } from "./chunk-Z3Q2AEIN.js";
6
+
7
+ // src/core/eval-endpoint.ts
8
+ function resolveEvaluationHost(host) {
9
+ let endpoint;
10
+ try {
11
+ endpoint = new URL(host);
12
+ if (endpoint.username || endpoint.password || endpoint.search || endpoint.hash || /[?#\s]/.test(host)) throw new Error();
13
+ } catch {
14
+ throw new CliValidationError("Evaluation AE Host must be an absolute HTTP(S) URL without credentials, query, or fragment.", {
15
+ code: "EVAL_ENDPOINT_INVALID"
16
+ });
17
+ }
18
+ const hostname = endpoint.hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
19
+ const mappedIpv4 = /^::ffff:([0-9a-f]+):[0-9a-f]+$/.exec(hostname);
20
+ if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "::1" || hostname === "::" || hostname === "0.0.0.0" || hostname.startsWith("127.") || mappedIpv4 && parseInt(mappedIpv4[1], 16) >> 8 === 127 || hostname === "::ffff:0:0") {
21
+ throw new CliValidationError("Loopback evaluation endpoints are unsupported.", {
22
+ code: "EVAL_ENDPOINT_LOOPBACK_UNSUPPORTED",
23
+ hint: "Select an online AE Host with --host."
24
+ });
25
+ }
26
+ if (endpoint.protocol !== "http:" && endpoint.protocol !== "https:") {
27
+ throw new CliValidationError("Evaluation AE Host must use HTTP or HTTPS.", {
28
+ code: "EVAL_ENDPOINT_INVALID"
29
+ });
30
+ }
31
+ return endpoint.toString().replace(/\/+$/, "").replace(/\/agent$/, "");
32
+ }
33
+
34
+ // src/core/eval-client.ts
35
+ import { open, unlink } from "fs/promises";
36
+ import { resolve } from "path";
37
+ var DEFAULT_TIMEOUT_MS = 3e4;
38
+ var EvalApiError = class extends Error {
39
+ code;
40
+ httpStatus;
41
+ hint;
42
+ details;
43
+ constructor(message, options) {
44
+ const redact = evaluationErrorRedactor([
45
+ ...options.sensitiveValues ?? [],
46
+ process.env.AE_EVAL_ACCESS_TOKEN ?? ""
47
+ ]);
48
+ super(redact(message));
49
+ this.name = "EvalApiError";
50
+ this.code = options.code;
51
+ this.httpStatus = options.httpStatus;
52
+ this.hint = options.hint === void 0 ? void 0 : redact(options.hint);
53
+ this.details = options.details === void 0 ? void 0 : redact(options.details);
54
+ }
55
+ };
56
+ function evaluationErrorRedactor(secrets) {
57
+ const forms = [...new Set(secrets.filter(Boolean).flatMap((secret) => [
58
+ secret,
59
+ JSON.stringify(secret).slice(1, -1),
60
+ encodeURIComponent(secret)
61
+ ]))].sort((a, b) => b.length - a.length);
62
+ const redact = (value) => {
63
+ if (typeof value === "string") {
64
+ for (const secret of forms) value = value.split(secret).join("[REDACTED]");
65
+ return value;
66
+ }
67
+ if (Array.isArray(value)) return value.map(redact);
68
+ if (value && typeof value === "object") {
69
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [redact(key), redact(item)]));
70
+ }
71
+ return value;
72
+ };
73
+ return redact;
74
+ }
75
+ async function evalRequest(options) {
76
+ const url = buildEvalUrl(options.baseUrl, options.path, options.params);
77
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
78
+ const fetchImpl = options.fetchImpl ?? fetch;
79
+ const controller = new AbortController();
80
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
81
+ const headers = {
82
+ ...options.headers,
83
+ Accept: options.responseType === "bytes" ? "application/octet-stream, application/json" : "application/json"
84
+ };
85
+ const isMultipart = options.body instanceof FormData;
86
+ if (options.body !== void 0 && !isMultipart) {
87
+ headers["Content-Type"] = "application/json";
88
+ }
89
+ if (options.idempotencyKey) {
90
+ headers["Idempotency-Key"] = options.idempotencyKey;
91
+ }
92
+ let response;
93
+ let responseText = "";
94
+ let bytes;
95
+ try {
96
+ response = await fetchImpl(url, {
97
+ method: options.method,
98
+ headers,
99
+ body: options.body === void 0 ? void 0 : options.body instanceof FormData ? options.body : JSON.stringify(options.body),
100
+ redirect: "error",
101
+ signal: controller.signal
102
+ });
103
+ if (response.ok && options.responseType === "bytes") {
104
+ bytes = new Uint8Array(await response.arrayBuffer());
105
+ } else {
106
+ responseText = await response.text();
107
+ }
108
+ } catch (error) {
109
+ const timedOut = controller.signal.aborted || error instanceof Error && error.name === "AbortError";
110
+ logEvalRequest(options.method, url, response?.status ?? "unavailable");
111
+ if (timedOut) {
112
+ throw new EvalApiError(`Evaluation API request timed out after ${timeoutMs} ms.`, {
113
+ code: "EVAL_API_TIMEOUT",
114
+ httpStatus: 0,
115
+ hint: "Verify the evaluation platform is reachable at the configured endpoint."
116
+ });
117
+ }
118
+ throw new EvalApiError("Evaluation API request failed before a response was received.", {
119
+ code: "EVAL_API_NETWORK_ERROR",
120
+ httpStatus: 0,
121
+ hint: "Verify the --endpoint URL and network path."
122
+ });
123
+ } finally {
124
+ clearTimeout(timeout);
125
+ }
126
+ logEvalRequest(options.method, url, response.status);
127
+ if (bytes !== void 0) return bytes;
128
+ const responseBody = parseEvalResponseBody(responseText, response.status);
129
+ if (!response.ok) {
130
+ const sensitiveValues = Object.values(options.headers).flatMap((value) => [value, value.replace(/^Bearer\s+/i, "")]);
131
+ if (isRecord(options.body)) {
132
+ for (const key of ["secret", "data_token", "report_source"]) {
133
+ if (typeof options.body[key] === "string") sensitiveValues.push(options.body[key]);
134
+ }
135
+ }
136
+ throw evalErrorFromBody(responseBody, response.status, sensitiveValues);
137
+ }
138
+ return responseBody;
139
+ }
140
+ async function evalDownloadFile(options, outputPath) {
141
+ const path = resolve(outputPath);
142
+ let file;
143
+ try {
144
+ file = await open(path, "wx", 384);
145
+ } catch (error) {
146
+ if (error.code === "EEXIST") {
147
+ throw new CliValidationError("Output file already exists; choose a new --output path.", {
148
+ code: "EVAL_OUTPUT_EXISTS"
149
+ });
150
+ }
151
+ throw error;
152
+ }
153
+ let completed = false;
154
+ try {
155
+ const bytes = await evalRequest({ ...options, responseType: "bytes" });
156
+ await file.writeFile(bytes);
157
+ completed = true;
158
+ return { path, byte_size: bytes.byteLength };
159
+ } finally {
160
+ await file.close();
161
+ if (!completed) await unlink(path);
162
+ }
163
+ }
164
+ function buildEvalUrl(baseUrl, path, params) {
165
+ const base = resolveEvaluationHost(baseUrl);
166
+ const url = new URL(`${base}${path}`);
167
+ if (params) {
168
+ for (const [key, value] of Object.entries(params)) {
169
+ if (value === void 0 || value === null || value === "") continue;
170
+ url.searchParams.set(key, String(value));
171
+ }
172
+ }
173
+ return url.toString();
174
+ }
175
+ function parseEvalResponseBody(text, httpStatus) {
176
+ if (!text.trim()) {
177
+ if (httpStatus === 204) return void 0;
178
+ throw new EvalApiError("Evaluation API returned an empty response body.", {
179
+ code: "EVAL_API_INVALID_RESPONSE",
180
+ httpStatus
181
+ });
182
+ }
183
+ try {
184
+ return JSON.parse(text);
185
+ } catch {
186
+ throw new EvalApiError("Evaluation API returned a non-JSON response body.", {
187
+ code: "EVAL_API_INVALID_RESPONSE",
188
+ httpStatus
189
+ });
190
+ }
191
+ }
192
+ function evalErrorFromBody(body, httpStatus, sensitiveValues) {
193
+ const error = body?.error;
194
+ if (isRecord(error) && typeof error.message === "string" && error.message.trim()) {
195
+ return new EvalApiError(error.message.trim(), {
196
+ code: typeof error.code === "string" && /^[A-Z][A-Z0-9_]{0,127}$/.test(error.code) ? error.code : `EVAL_API_HTTP_${httpStatus}`,
197
+ httpStatus,
198
+ hint: typeof error.details === "string" ? error.details : void 0,
199
+ details: isRecord(error.details) ? error.details : void 0,
200
+ sensitiveValues
201
+ });
202
+ }
203
+ return new EvalApiError(`Evaluation API returned HTTP ${httpStatus}.`, {
204
+ code: `EVAL_API_HTTP_${httpStatus}`,
205
+ httpStatus,
206
+ hint: httpStatus >= 500 ? "The server response was suppressed. Check the evaluation platform logs; the CLI did not retry." : void 0
207
+ });
208
+ }
209
+ function isRecord(value) {
210
+ return value !== null && typeof value === "object" && !Array.isArray(value);
211
+ }
212
+ function logEvalRequest(method, url, status) {
213
+ logger.info(`EVAL ${method} ${redactEvalLogUrl(url)} status=${status}`);
214
+ }
215
+ function redactEvalLogUrl(url) {
216
+ try {
217
+ const parsed = new URL(url);
218
+ parsed.username = "";
219
+ parsed.password = "";
220
+ parsed.search = "";
221
+ parsed.hash = "";
222
+ return parsed.toString();
223
+ } catch {
224
+ return "[invalid evaluation URL]";
225
+ }
226
+ }
227
+
228
+ export {
229
+ resolveEvaluationHost,
230
+ EvalApiError,
231
+ evalRequest,
232
+ evalDownloadFile
233
+ };