@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.
Files changed (89) 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-TAMDRZYV.js → capability-72DTW5M2.js} +9 -9
  4. package/dist/{capability-U7TDEEEG.js → capability-PJHNI4GJ.js} +9 -9
  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-WZRX4KOH.js → chunk-GT46FPXN.js} +4 -6
  10. package/dist/{chunk-5XUSIK27.js → chunk-ILIU36SU.js} +10 -7
  11. package/dist/{chunk-JHENBQ5B.js → chunk-LYVNONC4.js} +0 -35
  12. package/dist/{chunk-JUW4AJXN.js → chunk-P3FGXJTU.js} +12 -7
  13. package/dist/chunk-QGM4M3NI.js +37 -0
  14. package/dist/{chunk-753BUTNZ.js → chunk-RGKJGKT7.js} +2 -2
  15. package/dist/{chunk-UIHQJK5E.js → chunk-SAU3QFIQ.js} +3 -3
  16. package/dist/{chunk-VLWOLBGZ.js → chunk-UOUS37JQ.js} +149 -161
  17. package/dist/{chunk-AXDXJTPC.js → chunk-UW5UN47B.js} +19 -2
  18. package/dist/chunk-VPKZ7I72.js +509 -0
  19. package/dist/{chunk-QATA32VR.js → chunk-VR3LCBHW.js} +2 -2
  20. package/dist/{chunk-IBH3LDAH.js → chunk-YA6SMTXG.js} +3 -3
  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 +68 -34
  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-5MIMNIMT.js → metadata-UILXHBWF.js} +10 -9
  31. package/dist/{metadata-LERKDJN6.js → metadata-XXR34N5P.js} +10 -9
  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-FCHRTNIY.js → te-analysis-O6DCO6BS.js} +36 -13
  39. package/dist/{te-analysis-QG7UKGDA.js → te-analysis-ZMNGOVNW.js} +36 -13
  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-D6EG3NOR.js → te-engage-FGBGQ4IY.js} +9 -8
  45. package/dist/{te-engage-ZSMIJLUW.js → te-engage-RAK5PESW.js} +9 -8
  46. package/dist/{te-experiment-K5US7RMG.js → te-experiment-SO5MPDMJ.js} +9 -8
  47. package/dist/{te-experiment-WA7TFMEL.js → te-experiment-VZF7BT6G.js} +9 -8
  48. package/dist/{te-kb-OIH3T6CS.js → te-kb-APXBWBDY.js} +6 -6
  49. package/dist/{te-system-AZ3URMUO.js → te-system-YARIK4S5.js} +7 -4
  50. package/dist/te-system-Z77IKZFN.js +2213 -0
  51. package/dist/{te-team-GZPU6UWA.js → te-team-EFKWYKMK.js} +7 -7
  52. package/dist/{update-TOBFXF2V.js → update-OGPSZM5A.js} +7 -7
  53. package/package.json +13 -3
  54. package/skills/ae-agent/SKILL.md +21 -11
  55. package/skills/ae-agent/references/approval-effect.md +44 -0
  56. package/skills/ae-agent/references/approval-request.md +46 -0
  57. package/skills/ae-agent/references/approval-task.md +45 -0
  58. package/skills/ae-agent/references/approval-type.md +32 -0
  59. package/skills/ae-agent/references/command_index.md +19 -0
  60. package/skills/ae-analysis/SKILL.md +11 -7
  61. package/skills/ae-analysis/references/adhoc_run.md +2 -0
  62. package/skills/ae-analysis/references/ai_models.md +27 -0
  63. package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -2
  64. package/skills/ae-analysis/references/command_index.md +4 -1
  65. package/skills/ae-analysis/references/dashboard_get.md +8 -2
  66. package/skills/ae-analysis/references/dashboard_report_data_run.md +3 -1
  67. package/skills/ae-analysis/references/dashboard_update.md +4 -1
  68. package/skills/ae-analysis/references/project_space_business_filter_upsert.md +17 -0
  69. package/skills/ae-analysis/references/user_tag_models.md +4 -4
  70. package/skills/ae-data-integration/SKILL.md +54 -0
  71. package/skills/ae-data-integration/references/handoff.md +43 -0
  72. package/skills/ae-data-integration/references/local-analysis.md +27 -0
  73. package/skills/ae-data-integration/references/reuse.md +41 -0
  74. package/skills/ae-data-integration/references/sink-upload.md +58 -0
  75. package/skills/ae-data-integration/references/source-inspect.md +55 -0
  76. package/skills/ae-data-integration/references/sync-json-upload.md +60 -0
  77. package/skills/ae-data-integration/references/tracking-plan.md +35 -0
  78. package/skills/ae-data-integration/references/transform.md +65 -0
  79. package/skills/ae-data-integration/references/ue-mapping.md +142 -0
  80. package/skills/ae-data-integration/references/ue-routing.md +35 -0
  81. package/skills/ae-data-integration-helper/SKILL.md +1 -1
  82. package/skills/ae-dataops/SKILL.md +1 -1
  83. package/skills/ae-dataops/references/dataops-query.md +4 -4
  84. package/skills/ae-generate-tracking-plan/SKILL.md +54 -3
  85. package/skills/ae-metadata/SKILL.md +0 -1
  86. package/dist/chunk-3FY3RJ26.js +0 -293
  87. package/dist/chunk-S5NTSDBS.js +0 -198
  88. package/dist/chunk-ZQKDZXDO.js +0 -317
  89. package/dist/cli-token-4UPER74P.js +0 -21
@@ -6,17 +6,17 @@ import {
6
6
  waitForAnalysisRun,
7
7
  withAsyncArtifactLifecycle,
8
8
  withInterruptSignal
9
- } from "./chunk-UIHQJK5E.js";
9
+ } from "./chunk-YA6SMTXG.js";
10
10
  import {
11
11
  createCapabilityCommand
12
- } from "./chunk-753BUTNZ.js";
12
+ } from "./chunk-VR3LCBHW.js";
13
13
  import {
14
14
  registerCapabilityGatewayRoute,
15
15
  resolveGatewayDomain
16
16
  } from "./chunk-PTE56QPL.js";
17
17
  import {
18
18
  withOutputMetadata
19
- } from "./chunk-WZRX4KOH.js";
19
+ } from "./chunk-GT46FPXN.js";
20
20
  import {
21
21
  CapabilityGatewayError,
22
22
  buildCapabilityGatewayUrl,
@@ -27,16 +27,17 @@ import {
27
27
  requestCapabilityGatewayWithEnvelope,
28
28
  uploadInputFile,
29
29
  validateCapability
30
- } from "./chunk-5XUSIK27.js";
30
+ } from "./chunk-ILIU36SU.js";
31
+ import "./chunk-6EIJSNBD.js";
31
32
  import {
32
33
  getCliToken
33
- } from "./chunk-S5NTSDBS.js";
34
- import "./chunk-ZQKDZXDO.js";
35
- import "./chunk-3FY3RJ26.js";
34
+ } from "./chunk-4SGZG4XY.js";
35
+ import "./chunk-ZZUOD757.js";
36
36
  import {
37
37
  CliValidationError
38
- } from "./chunk-AXDXJTPC.js";
39
- import "./chunk-JHENBQ5B.js";
38
+ } from "./chunk-UW5UN47B.js";
39
+ import "./chunk-LYVNONC4.js";
40
+ import "./chunk-QGM4M3NI.js";
40
41
 
41
42
  // src/commands/te-analysis/capability-shared.ts
42
43
  var ANALYSIS_GATEWAY_CLI_SERVICES = /* @__PURE__ */ new Set(["project", "system"]);
@@ -2774,7 +2775,7 @@ var dashboardGet = createAnalysisCapabilityCommand({
2774
2775
  resource: "dashboard",
2775
2776
  command: "get",
2776
2777
  capabilityId: "analysis.dashboard.get",
2777
- description: "Get one dashboard detail, including creator, create/update time, settings, reports, notes, and share information.",
2778
+ description: "Get one dashboard detail, including location, creator, create/update time, settings, reports, notes, and share information.",
2778
2779
  flags: [
2779
2780
  projectIdFlag,
2780
2781
  { name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID." },
@@ -2793,10 +2794,10 @@ var dashboardUpdate = createAnalysisCapabilityCommand({
2793
2794
  resource: "dashboard",
2794
2795
  command: "update",
2795
2796
  capabilityId: "analysis.dashboard.update",
2796
- description: "Update dashboard settings or create/update a dashboard note. Use --operation settings or note-upsert.",
2797
+ description: "Update dashboard settings, create/update a dashboard note, or replace the dashboard-level business filter. Use --operation settings, note-upsert, or business-filter.",
2797
2798
  flags: [
2798
2799
  projectIdFlag,
2799
- { name: "operation", type: "string", required: true, desc: "Update operation: settings or note-upsert." },
2800
+ { name: "operation", type: "string", required: true, desc: "Update operation: settings, note-upsert, or business-filter." },
2800
2801
  { name: "dashboard-id", type: "number", required: false, desc: "Dashboard ID for a single-dashboard update." },
2801
2802
  { name: "dashboard-ids", type: "json", required: false, desc: "Dashboard ID array for batch settings updates." },
2802
2803
  { name: "dashboard-name", type: "string", required: false, desc: "Dashboard name for single rename." },
@@ -2807,6 +2808,7 @@ var dashboardUpdate = createAnalysisCapabilityCommand({
2807
2808
  { name: "note-title", type: "string", required: false, desc: "Dashboard note title." },
2808
2809
  { name: "description", type: "string", required: false, desc: "Dashboard note description." },
2809
2810
  { name: "ui-config", type: "string", required: false, desc: "Dashboard or note UI config string." },
2811
+ { name: "filter", type: "json", required: false, desc: 'Dashboard-level business filter in snake_case QP form. Required with --operation business-filter. Pass {"junction_kind":"and","ta_filters":[]} to clear it.' },
2810
2812
  payloadFlag
2811
2813
  ],
2812
2814
  risk: "write",
@@ -2823,6 +2825,7 @@ var dashboardUpdate = createAnalysisCapabilityCommand({
2823
2825
  note_title: optionalString(ctx, "note-title"),
2824
2826
  description: optionalString(ctx, "description"),
2825
2827
  ui_config: optionalString(ctx, "ui-config"),
2828
+ filter: optionalJson(ctx, "filter"),
2826
2829
  payload: optionalJson(ctx, "payload")
2827
2830
  })
2828
2831
  });
@@ -3973,10 +3976,30 @@ var projectSpaceGet = createAnalysisCapabilityCommand({
3973
3976
  })
3974
3977
  });
3975
3978
 
3979
+ // src/commands/te-analysis/project-space/business-filter-upsert.ts
3980
+ var projectSpaceBusinessFilterUpsert = createAnalysisCapabilityCommand({
3981
+ resource: "project-space",
3982
+ command: "business-filter-upsert",
3983
+ capabilityId: "analysis.project_space.business_filter_upsert",
3984
+ description: "Create or replace the space-level business filter inherited by dashboards in a project space.",
3985
+ flags: [
3986
+ projectIdFlag,
3987
+ { name: "space-id", type: "number", required: true, desc: "Project space ID." },
3988
+ { name: "filter", type: "json", required: true, desc: 'Space-level business filter in snake_case QP form. Pass {"junction_kind":"and","ta_filters":[]} to clear it.' }
3989
+ ],
3990
+ risk: "write",
3991
+ buildInput: (ctx) => compactInput({
3992
+ ...projectInput(ctx),
3993
+ space_id: ctx.num("space-id"),
3994
+ filter: ctx.json("filter")
3995
+ })
3996
+ });
3997
+
3976
3998
  // src/commands/te-analysis/project-space/index.ts
3977
3999
  var commands31 = [
3978
4000
  projectSpaceList,
3979
- projectSpaceGet
4001
+ projectSpaceGet,
4002
+ projectSpaceBusinessFilterUpsert
3980
4003
  ];
3981
4004
  var project_space_default = commands31;
3982
4005
 
@@ -6,17 +6,17 @@ import {
6
6
  waitForAnalysisRun,
7
7
  withAsyncArtifactLifecycle,
8
8
  withInterruptSignal
9
- } from "./chunk-IBH3LDAH.js";
9
+ } from "./chunk-SAU3QFIQ.js";
10
10
  import {
11
11
  createCapabilityCommand
12
- } from "./chunk-QATA32VR.js";
12
+ } from "./chunk-RGKJGKT7.js";
13
13
  import {
14
14
  registerCapabilityGatewayRoute,
15
15
  resolveGatewayDomain
16
16
  } from "./chunk-PTE56QPL.js";
17
17
  import {
18
18
  withOutputMetadata
19
- } from "./chunk-WZRX4KOH.js";
19
+ } from "./chunk-GT46FPXN.js";
20
20
  import {
21
21
  CapabilityGatewayError,
22
22
  buildCapabilityGatewayUrl,
@@ -27,16 +27,17 @@ import {
27
27
  requestCapabilityGatewayWithEnvelope,
28
28
  uploadInputFile,
29
29
  validateCapability
30
- } from "./chunk-JUW4AJXN.js";
30
+ } from "./chunk-P3FGXJTU.js";
31
+ import "./chunk-C4MGVGJW.js";
31
32
  import {
32
33
  getCliToken
33
- } from "./chunk-S5NTSDBS.js";
34
- import "./chunk-ZQKDZXDO.js";
35
- import "./chunk-3FY3RJ26.js";
34
+ } from "./chunk-4SGZG4XY.js";
35
+ import "./chunk-ZZUOD757.js";
36
36
  import {
37
37
  CliValidationError
38
- } from "./chunk-AXDXJTPC.js";
39
- import "./chunk-JHENBQ5B.js";
38
+ } from "./chunk-UW5UN47B.js";
39
+ import "./chunk-LYVNONC4.js";
40
+ import "./chunk-QGM4M3NI.js";
40
41
 
41
42
  // src/commands/te-analysis/capability-shared.ts
42
43
  var ANALYSIS_GATEWAY_CLI_SERVICES = /* @__PURE__ */ new Set(["project", "system"]);
@@ -2774,7 +2775,7 @@ var dashboardGet = createAnalysisCapabilityCommand({
2774
2775
  resource: "dashboard",
2775
2776
  command: "get",
2776
2777
  capabilityId: "analysis.dashboard.get",
2777
- description: "Get one dashboard detail, including creator, create/update time, settings, reports, notes, and share information.",
2778
+ description: "Get one dashboard detail, including location, creator, create/update time, settings, reports, notes, and share information.",
2778
2779
  flags: [
2779
2780
  projectIdFlag,
2780
2781
  { name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID." },
@@ -2793,10 +2794,10 @@ var dashboardUpdate = createAnalysisCapabilityCommand({
2793
2794
  resource: "dashboard",
2794
2795
  command: "update",
2795
2796
  capabilityId: "analysis.dashboard.update",
2796
- description: "Update dashboard settings or create/update a dashboard note. Use --operation settings or note-upsert.",
2797
+ description: "Update dashboard settings, create/update a dashboard note, or replace the dashboard-level business filter. Use --operation settings, note-upsert, or business-filter.",
2797
2798
  flags: [
2798
2799
  projectIdFlag,
2799
- { name: "operation", type: "string", required: true, desc: "Update operation: settings or note-upsert." },
2800
+ { name: "operation", type: "string", required: true, desc: "Update operation: settings, note-upsert, or business-filter." },
2800
2801
  { name: "dashboard-id", type: "number", required: false, desc: "Dashboard ID for a single-dashboard update." },
2801
2802
  { name: "dashboard-ids", type: "json", required: false, desc: "Dashboard ID array for batch settings updates." },
2802
2803
  { name: "dashboard-name", type: "string", required: false, desc: "Dashboard name for single rename." },
@@ -2807,6 +2808,7 @@ var dashboardUpdate = createAnalysisCapabilityCommand({
2807
2808
  { name: "note-title", type: "string", required: false, desc: "Dashboard note title." },
2808
2809
  { name: "description", type: "string", required: false, desc: "Dashboard note description." },
2809
2810
  { name: "ui-config", type: "string", required: false, desc: "Dashboard or note UI config string." },
2811
+ { name: "filter", type: "json", required: false, desc: 'Dashboard-level business filter in snake_case QP form. Required with --operation business-filter. Pass {"junction_kind":"and","ta_filters":[]} to clear it.' },
2810
2812
  payloadFlag
2811
2813
  ],
2812
2814
  risk: "write",
@@ -2823,6 +2825,7 @@ var dashboardUpdate = createAnalysisCapabilityCommand({
2823
2825
  note_title: optionalString(ctx, "note-title"),
2824
2826
  description: optionalString(ctx, "description"),
2825
2827
  ui_config: optionalString(ctx, "ui-config"),
2828
+ filter: optionalJson(ctx, "filter"),
2826
2829
  payload: optionalJson(ctx, "payload")
2827
2830
  })
2828
2831
  });
@@ -3973,10 +3976,30 @@ var projectSpaceGet = createAnalysisCapabilityCommand({
3973
3976
  })
3974
3977
  });
3975
3978
 
3979
+ // src/commands/te-analysis/project-space/business-filter-upsert.ts
3980
+ var projectSpaceBusinessFilterUpsert = createAnalysisCapabilityCommand({
3981
+ resource: "project-space",
3982
+ command: "business-filter-upsert",
3983
+ capabilityId: "analysis.project_space.business_filter_upsert",
3984
+ description: "Create or replace the space-level business filter inherited by dashboards in a project space.",
3985
+ flags: [
3986
+ projectIdFlag,
3987
+ { name: "space-id", type: "number", required: true, desc: "Project space ID." },
3988
+ { name: "filter", type: "json", required: true, desc: 'Space-level business filter in snake_case QP form. Pass {"junction_kind":"and","ta_filters":[]} to clear it.' }
3989
+ ],
3990
+ risk: "write",
3991
+ buildInput: (ctx) => compactInput({
3992
+ ...projectInput(ctx),
3993
+ space_id: ctx.num("space-id"),
3994
+ filter: ctx.json("filter")
3995
+ })
3996
+ });
3997
+
3976
3998
  // src/commands/te-analysis/project-space/index.ts
3977
3999
  var commands31 = [
3978
4000
  projectSpaceList,
3979
- projectSpaceGet
4001
+ projectSpaceGet,
4002
+ projectSpaceBusinessFilterUpsert
3980
4003
  ];
3981
4004
  var project_space_default = commands31;
3982
4005
 
@@ -1,36 +1,42 @@
1
1
  import {
2
2
  registerCapabilityGatewayRoute
3
3
  } from "./chunk-PTE56QPL.js";
4
+ import {
5
+ internalCallSourceHeaders
6
+ } from "./chunk-C4MGVGJW.js";
4
7
  import {
5
8
  clearCliToken,
6
9
  getCliToken
7
- } from "./chunk-S5NTSDBS.js";
8
- import "./chunk-ZQKDZXDO.js";
10
+ } from "./chunk-4SGZG4XY.js";
9
11
  import {
10
12
  getActiveHost,
11
13
  safeJsonParse
12
- } from "./chunk-3FY3RJ26.js";
14
+ } from "./chunk-ZZUOD757.js";
13
15
  import {
14
16
  CliValidationError,
15
17
  PermissionError
16
- } from "./chunk-AXDXJTPC.js";
18
+ } from "./chunk-UW5UN47B.js";
17
19
  import {
18
20
  logger
19
- } from "./chunk-JHENBQ5B.js";
21
+ } from "./chunk-LYVNONC4.js";
22
+ import "./chunk-QGM4M3NI.js";
20
23
 
21
24
  // src/core/mcp.ts
22
- async function permissionMessage(resp) {
25
+ async function permissionDetails(resp) {
23
26
  const text = await resp.text().catch(() => "");
24
27
  try {
25
28
  const d = safeJsonParse(text);
26
29
  const msg = d && (d.error?.message || (typeof d.error === "string" ? d.error : void 0) || d.message);
27
- if (msg && typeof msg === "string") return msg;
30
+ if (msg && typeof msg === "string") {
31
+ return {
32
+ message: msg,
33
+ code: typeof d.code === "string" ? d.code : typeof d.error?.code === "string" ? d.error.code : void 0,
34
+ hint: typeof d.hint === "string" ? d.hint : typeof d.error?.hint === "string" ? d.error.hint : void 0
35
+ };
36
+ }
28
37
  } catch {
29
38
  }
30
- return "Permission denied for this resource (HTTP 403)";
31
- }
32
- function isInvalidCliTokenMessage(message) {
33
- return /\b(cli[-_\s]?token|token)\b.*\binvalid\b/i.test(message) || /\binvalid\b.*\b(cli[-_\s]?token|token)\b/i.test(message);
39
+ return { message: "Permission denied for this resource (HTTP 403)" };
34
40
  }
35
41
  var MCP_PROTOCOL_VERSION = "2025-11-25";
36
42
  var JSONRPC_VERSION = "2.0";
@@ -85,6 +91,7 @@ async function mcpRequest(url, method, params = {}, hostOverride) {
85
91
  "Content-Type": "application/json",
86
92
  "Accept": "application/json, text/event-stream",
87
93
  "mcp-protocol-version": MCP_PROTOCOL_VERSION,
94
+ ...internalCallSourceHeaders(),
88
95
  ...buildAuthHeaders(token)
89
96
  };
90
97
  const resp = await fetch(url, {
@@ -93,15 +100,12 @@ async function mcpRequest(url, method, params = {}, hostOverride) {
93
100
  body: JSON.stringify(body)
94
101
  });
95
102
  if (!resp.ok) {
96
- let permissionMsg;
97
103
  if (resp.status === 403) {
98
- permissionMsg = await permissionMessage(resp);
99
- if (!isInvalidCliTokenMessage(permissionMsg)) {
100
- throw new PermissionError(permissionMsg);
101
- }
104
+ const permission = await permissionDetails(resp);
105
+ throw new PermissionError(permission.message, permission.code, permission.hint);
102
106
  }
103
- if (resp.status === 401 || resp.status === 403 && permissionMsg) {
104
- logger.warn(`MCP request failed (${resp.status === 403 ? permissionMsg : "HTTP 401"}) for ${hostUrl}, refreshing CLI token`);
107
+ if (resp.status === 401) {
108
+ logger.warn(`MCP request failed (HTTP 401) for ${hostUrl}, refreshing CLI token`);
105
109
  clearCliToken(hostUrl);
106
110
  const newToken = await getCliToken(hostUrl);
107
111
  logger.info(`CLI token refreshed for ${hostUrl}`);
@@ -114,7 +118,8 @@ async function mcpRequest(url, method, params = {}, hostOverride) {
114
118
  body: JSON.stringify(body)
115
119
  });
116
120
  if (retryResp.status === 403) {
117
- throw new PermissionError(await permissionMessage(retryResp));
121
+ const permission = await permissionDetails(retryResp);
122
+ throw new PermissionError(permission.message, permission.code, permission.hint);
118
123
  }
119
124
  if (!retryResp.ok) {
120
125
  throw new Error(`MCP HTTP error: ${retryResp.status} ${retryResp.statusText}`);
@@ -1,36 +1,42 @@
1
1
  import {
2
2
  registerCapabilityGatewayRoute
3
3
  } from "./chunk-PTE56QPL.js";
4
+ import {
5
+ internalCallSourceHeaders
6
+ } from "./chunk-6EIJSNBD.js";
4
7
  import {
5
8
  clearCliToken,
6
9
  getCliToken
7
- } from "./chunk-S5NTSDBS.js";
8
- import "./chunk-ZQKDZXDO.js";
10
+ } from "./chunk-4SGZG4XY.js";
9
11
  import {
10
12
  getActiveHost,
11
13
  safeJsonParse
12
- } from "./chunk-3FY3RJ26.js";
14
+ } from "./chunk-ZZUOD757.js";
13
15
  import {
14
16
  CliValidationError,
15
17
  PermissionError
16
- } from "./chunk-AXDXJTPC.js";
18
+ } from "./chunk-UW5UN47B.js";
17
19
  import {
18
20
  logger
19
- } from "./chunk-JHENBQ5B.js";
21
+ } from "./chunk-LYVNONC4.js";
22
+ import "./chunk-QGM4M3NI.js";
20
23
 
21
24
  // src/core/mcp.ts
22
- async function permissionMessage(resp) {
25
+ async function permissionDetails(resp) {
23
26
  const text = await resp.text().catch(() => "");
24
27
  try {
25
28
  const d = safeJsonParse(text);
26
29
  const msg = d && (d.error?.message || (typeof d.error === "string" ? d.error : void 0) || d.message);
27
- if (msg && typeof msg === "string") return msg;
30
+ if (msg && typeof msg === "string") {
31
+ return {
32
+ message: msg,
33
+ code: typeof d.code === "string" ? d.code : typeof d.error?.code === "string" ? d.error.code : void 0,
34
+ hint: typeof d.hint === "string" ? d.hint : typeof d.error?.hint === "string" ? d.error.hint : void 0
35
+ };
36
+ }
28
37
  } catch {
29
38
  }
30
- return "Permission denied for this resource (HTTP 403)";
31
- }
32
- function isInvalidCliTokenMessage(message) {
33
- return /\b(cli[-_\s]?token|token)\b.*\binvalid\b/i.test(message) || /\binvalid\b.*\b(cli[-_\s]?token|token)\b/i.test(message);
39
+ return { message: "Permission denied for this resource (HTTP 403)" };
34
40
  }
35
41
  var MCP_PROTOCOL_VERSION = "2025-11-25";
36
42
  var JSONRPC_VERSION = "2.0";
@@ -85,7 +91,7 @@ async function mcpRequest(url, method, params = {}, hostOverride) {
85
91
  "Content-Type": "application/json",
86
92
  "Accept": "application/json, text/event-stream",
87
93
  "mcp-protocol-version": MCP_PROTOCOL_VERSION,
88
- "X-Source": "ae-cli",
94
+ ...internalCallSourceHeaders(),
89
95
  ...buildAuthHeaders(token)
90
96
  };
91
97
  const resp = await fetch(url, {
@@ -94,15 +100,12 @@ async function mcpRequest(url, method, params = {}, hostOverride) {
94
100
  body: JSON.stringify(body)
95
101
  });
96
102
  if (!resp.ok) {
97
- let permissionMsg;
98
103
  if (resp.status === 403) {
99
- permissionMsg = await permissionMessage(resp);
100
- if (!isInvalidCliTokenMessage(permissionMsg)) {
101
- throw new PermissionError(permissionMsg);
102
- }
104
+ const permission = await permissionDetails(resp);
105
+ throw new PermissionError(permission.message, permission.code, permission.hint);
103
106
  }
104
- if (resp.status === 401 || resp.status === 403 && permissionMsg) {
105
- logger.warn(`MCP request failed (${resp.status === 403 ? permissionMsg : "HTTP 401"}) for ${hostUrl}, refreshing CLI token`);
107
+ if (resp.status === 401) {
108
+ logger.warn(`MCP request failed (HTTP 401) for ${hostUrl}, refreshing CLI token`);
106
109
  clearCliToken(hostUrl);
107
110
  const newToken = await getCliToken(hostUrl);
108
111
  logger.info(`CLI token refreshed for ${hostUrl}`);
@@ -115,7 +118,8 @@ async function mcpRequest(url, method, params = {}, hostOverride) {
115
118
  body: JSON.stringify(body)
116
119
  });
117
120
  if (retryResp.status === 403) {
118
- throw new PermissionError(await permissionMessage(retryResp));
121
+ const permission = await permissionDetails(retryResp);
122
+ throw new PermissionError(permission.message, permission.code, permission.hint);
119
123
  }
120
124
  if (!retryResp.ok) {
121
125
  throw new Error(`MCP HTTP error: ${retryResp.status} ${retryResp.statusText}`);
@@ -1,25 +1,33 @@
1
1
  import {
2
2
  printError
3
- } from "./chunk-WZRX4KOH.js";
3
+ } from "./chunk-GT46FPXN.js";
4
+ import {
5
+ internalCallSourceHeaders
6
+ } from "./chunk-6EIJSNBD.js";
4
7
  import {
5
8
  clearCliToken,
6
9
  getCliToken
7
- } from "./chunk-S5NTSDBS.js";
8
- import {
9
- resolveHost
10
- } from "./chunk-ZQKDZXDO.js";
10
+ } from "./chunk-4SGZG4XY.js";
11
11
  import {
12
+ resolveHost,
12
13
  safeJsonParse
13
- } from "./chunk-3FY3RJ26.js";
14
+ } from "./chunk-ZZUOD757.js";
14
15
  import {
15
16
  CliValidationError,
16
17
  PermissionError
17
- } from "./chunk-AXDXJTPC.js";
18
+ } from "./chunk-UW5UN47B.js";
18
19
  import {
19
20
  logger
20
- } from "./chunk-JHENBQ5B.js";
21
+ } from "./chunk-LYVNONC4.js";
22
+ import "./chunk-QGM4M3NI.js";
21
23
 
22
24
  // src/commands/te-dataops/shared.ts
25
+ import { randomBytes } from "crypto";
26
+ import { createWriteStream } from "fs";
27
+ import { mkdir, rename, unlink } from "fs/promises";
28
+ import { basename, dirname, join, resolve } from "path";
29
+ import { Readable } from "stream";
30
+ import { pipeline } from "stream/promises";
23
31
  var TOOL_API_MAP = {
24
32
  repo_list_spaces: { method: "GET", path: "/api/cli/dataops/v1/gaia/repo/spaces" },
25
33
  datatable_get_table_detail: { method: "GET", path: "/api/cli/dataops/v1/gaia/datatable/table-detail" },
@@ -110,16 +118,16 @@ function buildDataopsApiDryRun(ctx, toolName59, args = {}) {
110
118
  body: params
111
119
  };
112
120
  }
113
- async function downloadDataopsApi(ctx, path2, params, retry = true) {
121
+ async function downloadDataopsApi(ctx, path, params, targetPath, retry = true) {
114
122
  const host = resolveHost(ctx.host());
115
123
  const token = await getCliToken(host);
116
- const url = buildUrl(host, path2, compactArgs(params));
124
+ const url = buildUrl(host, path, compactArgs(params));
117
125
  const resp = await fetch(url, {
118
126
  method: "GET",
119
127
  headers: {
120
128
  "cli-token": token,
121
129
  "Accept": "*/*",
122
- "X-Source": "ae-cli"
130
+ ...internalCallSourceHeaders()
123
131
  }
124
132
  });
125
133
  if (resp.status === 403) {
@@ -128,23 +136,44 @@ async function downloadDataopsApi(ctx, path2, params, retry = true) {
128
136
  }
129
137
  if (resp.status === 401 && retry) {
130
138
  clearCliToken(host);
131
- return downloadDataopsApi(ctx, path2, params, false);
139
+ return downloadDataopsApi(ctx, path, params, targetPath, false);
132
140
  }
133
141
  if (!resp.ok) {
134
142
  const data = parseResponseBody(await resp.text(), url, resp.status, true);
135
143
  throw new Error(formatHttpError(resp.status, resp.statusText, data));
136
144
  }
137
- return Buffer.from(await resp.arrayBuffer());
138
- }
139
- async function dataopsRequest(ctx, method, path2, params = {}, body, retry = true) {
145
+ if (!resp.body) {
146
+ throw new Error("DataOps download response has no body.");
147
+ }
148
+ const outputPath = resolve(targetPath);
149
+ await mkdir(dirname(outputPath), { recursive: true });
150
+ const tempPath = join(
151
+ dirname(outputPath),
152
+ `.${basename(outputPath)}.part-${process.pid}-${randomBytes(6).toString("hex")}`
153
+ );
154
+ let tempPresent = false;
155
+ try {
156
+ tempPresent = true;
157
+ await pipeline(
158
+ Readable.fromWeb(resp.body),
159
+ createWriteStream(tempPath, { flags: "wx" })
160
+ );
161
+ await rename(tempPath, outputPath);
162
+ tempPresent = false;
163
+ return outputPath;
164
+ } finally {
165
+ if (tempPresent) await unlink(tempPath).catch(() => void 0);
166
+ }
167
+ }
168
+ async function dataopsRequest(ctx, method, path, params = {}, body, retry = true) {
140
169
  const host = resolveHost(ctx.host());
141
170
  const token = await getCliToken(host);
142
- const url = buildUrl(host, path2, params);
171
+ const url = buildUrl(host, path, params);
143
172
  const headers = {
144
173
  "cli-token": token,
145
174
  "Accept": "application/json",
146
175
  "Content-Type": "application/json",
147
- "X-Source": "ae-cli"
176
+ ...internalCallSourceHeaders()
148
177
  };
149
178
  const options = { method, headers };
150
179
  if (method !== "GET") {
@@ -160,16 +189,16 @@ async function dataopsRequest(ctx, method, path2, params = {}, body, retry = tru
160
189
  if (resp.status === 401 && retry) {
161
190
  logger.warn(`DataOps request failed (HTTP 401) for ${host}, refreshing CLI token`);
162
191
  clearCliToken(host);
163
- return dataopsRequest(ctx, method, path2, params, body, false);
192
+ return dataopsRequest(ctx, method, path, params, body, false);
164
193
  }
165
194
  if (!resp.ok) {
166
195
  throw new Error(formatHttpError(resp.status, resp.statusText, data));
167
196
  }
168
197
  return unwrapDataResponse(data);
169
198
  }
170
- function buildUrl(host, path2, params = {}) {
199
+ function buildUrl(host, path, params = {}) {
171
200
  const base = host.replace(/\/+$/, "");
172
- const normalizedPath = path2.startsWith("/") ? path2 : `/${path2}`;
201
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
173
202
  const url = new URL(`${base}${normalizedPath}`);
174
203
  for (const [key, value] of Object.entries(params)) {
175
204
  if (value !== void 0 && value !== null) {
@@ -219,8 +248,8 @@ function permissionMessage(data) {
219
248
  }
220
249
  function formatHttpError(status, statusText, data) {
221
250
  const detail = typeof data === "string" ? data : data?.message || data?.error || data?.return_message || data?.returnMessage;
222
- const path2 = data?.path ? ` path: ${data.path}` : "";
223
- return `AE API error: HTTP ${status} ${statusText}${detail ? ` - ${detail}` : ""}${path2}`;
251
+ const path = data?.path ? ` path: ${data.path}` : "";
252
+ return `AE API error: HTTP ${status} ${statusText}${detail ? ` - ${detail}` : ""}${path}`;
224
253
  }
225
254
 
226
255
  // src/commands/te-dataops/datatable/get-table-detail.ts
@@ -1845,8 +1874,6 @@ var cancelSqlQuery = {
1845
1874
  };
1846
1875
 
1847
1876
  // src/commands/te-dataops/ide/get-sql-query-status.ts
1848
- import { mkdir, writeFile } from "fs/promises";
1849
- import path from "path";
1850
1877
  var toolName51 = "ide_get_sql_query_status";
1851
1878
  var downloadPath = "/api/cli/dataops/v1/gaia/ide/sql-query-download";
1852
1879
  function optionalString5(ctx, name) {
@@ -1865,24 +1892,20 @@ function isDownloadReady(data) {
1865
1892
  }
1866
1893
  async function downloadResult(ctx, data, targetPath) {
1867
1894
  const params = data?.downloadParams ?? {};
1868
- const bytes = await downloadDataopsApi(ctx, downloadPath, {
1895
+ return downloadDataopsApi(ctx, downloadPath, {
1869
1896
  spaceCode: params.spaceCode,
1870
1897
  taskId: params.taskId
1871
- });
1872
- const absPath = path.resolve(targetPath);
1873
- await mkdir(path.dirname(absPath), { recursive: true });
1874
- await writeFile(absPath, bytes);
1875
- return absPath;
1898
+ }, targetPath);
1876
1899
  }
1877
1900
  var getSqlQueryStatus = {
1878
1901
  service: "dataops_ide",
1879
1902
  command: "+get_sql_query_status",
1880
- description: "Poll a Gaia download-center task created by +submit_sql_query. Requires spaceCode and downloadTaskId. requestId is trace-only. Returns status and download metadata; --downloadTo saves the result zip locally after SUCCESS and adds localFile.",
1903
+ description: "Poll a Gaia download-center task created by +submit_sql_query. Requires spaceCode and downloadTaskId. requestId is trace-only. Returns status and download metadata; --downloadTo streams the result zip to a local file after SUCCESS and adds localFile.",
1881
1904
  flags: [
1882
1905
  { name: "spaceCode", type: "string", required: true, desc: "Space code returned by +submit_sql_query" },
1883
1906
  { name: "downloadTaskId", type: "number", required: true, desc: "Download task ID returned by +submit_sql_query" },
1884
1907
  { name: "requestId", type: "string", required: false, desc: "Optional request ID returned by +submit_sql_query, used only for trace display" },
1885
- { name: "downloadTo", type: "string", required: false, desc: "Optional local file path. When downloadStatus=SUCCESS, save the result zip to this path; use a .zip suffix, for example ./result.zip." }
1908
+ { name: "downloadTo", type: "string", required: false, desc: "Optional local file path. After SUCCESS, stream the result zip and replace this path only when the download completes; use a .zip suffix, for example ./result.zip." }
1886
1909
  ],
1887
1910
  risk: "read",
1888
1911
  dryRun: (ctx) => buildDataopsApiDryRun(ctx, toolName51, buildArgs47(ctx)),
@@ -2144,10 +2167,10 @@ function buildArgs54(ctx) {
2144
2167
  var submitSqlQuery = {
2145
2168
  service: "dataops_ide",
2146
2169
  command: "+submit_sql_query",
2147
- description: "Submit an IDE SQL query and create a Gaia download-center task. Requires spaceCode and sql. Optional repoCode/engineType default to te_etl/TASK_ENGINE_TRINO. Returns download task metadata; result rows are never returned by MCP/CLI.",
2170
+ description: "Submit exactly one read-only IDE SQL query and create a Gaia download-center task. Optional repoCode/engineType default to te_etl/TASK_ENGINE_TRINO. Results are platform-bounded; Gaia returns downloadRowLimit when supported, and rows are never returned by MCP/CLI.",
2148
2171
  flags: [
2149
2172
  { name: "spaceCode", type: "string", required: true, desc: "Space code" },
2150
- { name: "sql", type: "string", required: true, desc: "SQL statement to execute" },
2173
+ { name: "sql", type: "string", required: true, desc: "Exactly one read-only SQL query" },
2151
2174
  { name: "repoCode", type: "string", required: false, desc: "Repository code. Defaults to te_etl." },
2152
2175
  { name: "engineType", type: "string", required: false, desc: "SQL execution engine. Defaults to TASK_ENGINE_TRINO. Optional: TASK_ENGINE_STARROCKS." }
2153
2176
  ],