@thinkingai/ae-cli 1.0.3 → 1.0.18

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 (198) hide show
  1. package/README.md +42 -72
  2. package/README.zh.md +202 -0
  3. package/dist/auth-2UTBG5U3.js +144 -0
  4. package/dist/{auth-BQC5DBE7.js → auth-ECD46NBA.js} +6 -4
  5. package/dist/{chunk-3CDLNXTD.js → chunk-4KQ7H7DY.js} +15 -3
  6. package/dist/{chunk-53FNNCZW.js → chunk-7QBNU44L.js} +101 -3
  7. package/dist/{chunk-ZYXIGPG7.js → chunk-LAAS6ITR.js} +3 -3
  8. package/dist/{chunk-EBFUVWIZ.js → chunk-MR57UIKC.js} +42 -0
  9. package/dist/{client-5QSQBBDB.js → client-O56G2SNJ.js} +3 -3
  10. package/dist/{config-Q7J3Z7Z2.js → config-BU5FHGGE.js} +23 -8
  11. package/dist/index.js +15 -15
  12. package/dist/{raw-G3GKHAPZ.js → raw-A3VN2B6I.js} +4 -4
  13. package/dist/{te-analysis-CHFTDN55.js → te-analysis-UGKESPBE.js} +62 -24
  14. package/dist/{te-audience-M6LQY6M7.js → te-audience-THZNVHYB.js} +61 -21
  15. package/dist/{te-common-BLQ7DVGC.js → te-common-QZOUME3S.js} +6 -33
  16. package/dist/{community-FVDAWGS4.js → te-community-AZVW3NFX.js} +59 -59
  17. package/dist/{te-dataops-V4OTKY35.js → te-dataops-OE5PX2K6.js} +3 -28
  18. package/dist/{te-engage-DXE4R5EW.js → te-engage-RYGEQTYK.js} +4 -22
  19. package/dist/{te-meta-FMM7KCVI.js → te-meta-MGO5BCMG.js} +88 -18
  20. package/package.json +3 -3
  21. package/skills/ae-analysis/SKILL.md +287 -0
  22. package/skills/{te-meta/references/batch-create-metadata.md → ae-analysis/references/batch_create_metadata.md} +3 -3
  23. package/skills/{te-meta/references/batch-edit-metadata.md → ae-analysis/references/batch_edit_metadata.md} +2 -2
  24. package/skills/{te-analysis/references/build-entity-details-sql.md → ae-analysis/references/build_entity_details_sql.md} +9 -9
  25. package/skills/{te-analysis/references/build-event-details-sql.md → ae-analysis/references/build_event_details_sql.md} +9 -9
  26. package/skills/{te-analysis/references/create-alert.md → ae-analysis/references/create_alert.md} +4 -4
  27. package/skills/{te-audience/references/create-cluster.md → ae-analysis/references/create_cluster.md} +23 -19
  28. package/skills/{te-analysis/references/create-dashboard.md → ae-analysis/references/create_dashboard.md} +4 -4
  29. package/skills/{te-meta/references/create-metric.md → ae-analysis/references/create_metric.md} +10 -10
  30. package/skills/{te-analysis/references/create-or-update-dashboard-note.md → ae-analysis/references/create_or_update_dashboard_note.md} +3 -3
  31. package/skills/{te-meta/references/create-project-mark-time.md → ae-analysis/references/create_project_mark_time.md} +3 -3
  32. package/skills/{te-analysis/references/create-public-access-link.md → ae-analysis/references/create_public_access_link.md} +3 -3
  33. package/skills/{te-analysis/references/create-report.md → ae-analysis/references/create_report.md} +9 -9
  34. package/skills/{te-analysis/references/create-result-cluster.md → ae-analysis/references/create_result_cluster.md} +6 -6
  35. package/skills/{te-audience/references/create-tag.md → ae-analysis/references/create_tag.md} +16 -15
  36. package/skills/{te-meta/references/create-virtual-event.md → ae-analysis/references/create_virtual_event.md} +9 -9
  37. package/skills/{te-meta/references/create-virtual-property.md → ae-analysis/references/create_virtual_property.md} +7 -7
  38. package/skills/{te-meta/references/delete-project-mark-times.md → ae-analysis/references/delete_project_mark_times.md} +2 -2
  39. package/skills/{te-meta/references/delete-track-items.md → ae-analysis/references/delete_track_items.md} +2 -2
  40. package/skills/{te-analysis/references/drilldown-user-events.md → ae-analysis/references/drilldown_user_events.md} +8 -8
  41. package/skills/{te-analysis/references/drilldown-users.md → ae-analysis/references/drilldown_users.md} +10 -7
  42. package/skills/ae-analysis/references/generate_track_program.md +51 -0
  43. package/skills/ae-analysis/references/generate_track_sdk_sample.md +43 -0
  44. package/skills/{te-analysis/references/get-alert.md → ae-analysis/references/get_alert.md} +2 -2
  45. package/skills/{te-analysis/references/get-alert-definition-schema.md → ae-analysis/references/get_alert_definition_schema.md} +1 -1
  46. package/skills/ae-analysis/references/get_analysis_query_schema.md +61 -0
  47. package/skills/ae-analysis/references/get_cluster_definition_schema.md +53 -0
  48. package/skills/ae-analysis/references/get_clusters_by_name.md +69 -0
  49. package/skills/{te-analysis/references/get-filter-schema.md → ae-analysis/references/get_filter_schema.md} +1 -1
  50. package/skills/{te-analysis/references/get-groupby-schema.md → ae-analysis/references/get_groupby_schema.md} +1 -1
  51. package/skills/{te-meta/references/get-metric.md → ae-analysis/references/get_metric.md} +2 -2
  52. package/skills/{te-meta/references/get-project-config.md → ae-analysis/references/get_project_config.md} +2 -2
  53. package/skills/{te-analysis/references/get-report-definition.md → ae-analysis/references/get_report_definition.md} +2 -2
  54. package/skills/{te-common/references/get-resource-url.md → ae-analysis/references/get_resource_url.md} +4 -4
  55. package/skills/{te-analysis/references/get-table-columns.md → ae-analysis/references/get_table_columns.md} +2 -2
  56. package/skills/ae-analysis/references/get_tag_definition_schema.md +49 -0
  57. package/skills/ae-analysis/references/get_tags_by_name.md +69 -0
  58. package/skills/{te-meta/references/get-track-program.md → ae-analysis/references/get_track_program.md} +2 -2
  59. package/skills/{te-analysis/references/list-alerts.md → ae-analysis/references/list_alerts.md} +10 -3
  60. package/skills/{te-audience/references/list-cluster-members.md → ae-analysis/references/list_cluster_members.md} +11 -4
  61. package/skills/{te-audience/references/list-clusters.md → ae-analysis/references/list_clusters.md} +14 -4
  62. package/skills/{te-analysis/references/list-dashboards.md → ae-analysis/references/list_dashboards.md} +12 -4
  63. package/skills/{te-meta/references/list-entities.md → ae-analysis/references/list_entities.md} +10 -3
  64. package/skills/{te-meta/references/list-events.md → ae-analysis/references/list_events.md} +12 -5
  65. package/skills/ae-analysis/references/list_metrics.md +45 -0
  66. package/skills/ae-analysis/references/list_project_mark_times.md +42 -0
  67. package/skills/{te-meta/references/list-project-users.md → ae-analysis/references/list_project_users.md} +2 -2
  68. package/skills/{te-common/references/list-projects.md → ae-analysis/references/list_projects.md} +6 -4
  69. package/skills/{te-meta/references/list-properties.md → ae-analysis/references/list_properties.md} +9 -4
  70. package/skills/ae-analysis/references/list_public_access_links.md +41 -0
  71. package/skills/{te-analysis/references/list-reports.md → ae-analysis/references/list_reports.md} +12 -4
  72. package/skills/{te-audience/references/list-tag-members.md → ae-analysis/references/list_tag_members.md} +11 -4
  73. package/skills/{te-audience/references/list-tags.md → ae-analysis/references/list_tags.md} +14 -4
  74. package/skills/{te-analysis/references/load-filters.md → ae-analysis/references/load_filters.md} +3 -3
  75. package/skills/{te-analysis/references/query-adhoc.md → ae-analysis/references/query_adhoc.md} +24 -9
  76. package/skills/{te-analysis/references/query-dashboard-detail.md → ae-analysis/references/query_dashboard_detail.md} +2 -2
  77. package/skills/{te-analysis/references/query-dashboard-report-data.md → ae-analysis/references/query_dashboard_report_data.md} +9 -9
  78. package/skills/{te-analysis/references/query-entity-details.md → ae-analysis/references/query_entity_details.md} +10 -10
  79. package/skills/{te-analysis/references/query-event-details.md → ae-analysis/references/query_event_details.md} +12 -12
  80. package/skills/{te-analysis/references/query-report-data.md → ae-analysis/references/query_report_data.md} +11 -11
  81. package/skills/{te-audience/references/refresh-cluster.md → ae-analysis/references/refresh_cluster.md} +2 -2
  82. package/skills/{te-audience/references/refresh-tag.md → ae-analysis/references/refresh_tag.md} +2 -2
  83. package/skills/{te-meta/references/save-track-items.md → ae-analysis/references/save_track_items.md} +2 -2
  84. package/skills/{te-analysis/references/update-alert.md → ae-analysis/references/update_alert.md} +4 -4
  85. package/skills/{te-audience/references/update-cluster.md → ae-analysis/references/update_cluster.md} +15 -13
  86. package/skills/{te-analysis/references/update-dashboard.md → ae-analysis/references/update_dashboard.md} +3 -3
  87. package/skills/{te-meta/references/update-metric.md → ae-analysis/references/update_metric.md} +9 -9
  88. package/skills/{te-meta/references/update-project-mark-time.md → ae-analysis/references/update_project_mark_time.md} +3 -3
  89. package/skills/{te-analysis/references/update-public-access-link.md → ae-analysis/references/update_public_access_link.md} +3 -3
  90. package/skills/{te-audience/references/update-tag.md → ae-analysis/references/update_tag.md} +15 -14
  91. package/skills/ae-community/SKILL.md +305 -0
  92. package/skills/{te-community → ae-community}/references/community-activity-analysis.md +6 -7
  93. package/skills/{te-community → ae-community}/references/community-analyzing-official-content.md +3 -4
  94. package/skills/{te-community → ae-community}/references/community-analyzing-theme-comment.md +5 -6
  95. package/skills/{te-community → ae-community}/references/community-character-analysis.md +5 -6
  96. package/skills/{te-community → ae-community}/references/community-daily-report.md +7 -8
  97. package/skills/{te-community → ae-community}/references/community-hottopic-insight.md +4 -5
  98. package/skills/{te-community → ae-community}/references/community-weekly-report.md +7 -8
  99. package/skills/{te-community → ae-community}/references/get_channel_info.md +4 -5
  100. package/skills/{te-community → ae-community}/references/get_comment_tag_analysis.md +3 -4
  101. package/skills/{te-community → ae-community}/references/get_comments_summary.md +4 -5
  102. package/skills/{te-community → ae-community}/references/get_corpus_tags.md +3 -4
  103. package/skills/{te-community → ae-community}/references/get_daily_summary.md +3 -4
  104. package/skills/{te-community → ae-community}/references/get_hot_topics.md +3 -4
  105. package/skills/{te-community → ae-community}/references/get_livestream_analysis.md +3 -4
  106. package/skills/{te-community → ae-community}/references/get_livestream_detail.md +4 -5
  107. package/skills/{te-community → ae-community}/references/get_livestream_list.md +3 -4
  108. package/skills/{te-community → ae-community}/references/get_livestream_overview.md +3 -4
  109. package/skills/{te-community → ae-community}/references/get_livestream_room_metrics.md +3 -4
  110. package/skills/{te-community → ae-community}/references/get_livestream_rooms.md +3 -4
  111. package/skills/{te-community → ae-community}/references/get_overview_metrics.md +3 -4
  112. package/skills/{te-community → ae-community}/references/get_post_detail.md +4 -5
  113. package/skills/{te-community → ae-community}/references/get_risk_content.md +5 -6
  114. package/skills/{te-community → ae-community}/references/get_sentiment_overview.md +4 -5
  115. package/skills/{te-community → ae-community}/references/get_tag_trends.md +3 -4
  116. package/skills/{te-community → ae-community}/references/get_topic_detail.md +3 -4
  117. package/skills/{te-community → ae-community}/references/search_posts.md +5 -6
  118. package/skills/{te-dataops → ae-dataops}/SKILL.md +73 -10
  119. package/skills/{te-dataops → ae-dataops}/references/dataops-flow-create.md +1 -1
  120. package/skills/{te-dataops → ae-dataops}/references/dataops-flow-monitor.md +1 -1
  121. package/skills/{te-dataops → ae-dataops}/references/dataops-integration.md +1 -1
  122. package/skills/{te-dataops → ae-dataops}/references/dataops-query.md +1 -1
  123. package/skills/{te-dataops → ae-dataops}/references/dataops-table.md +1 -1
  124. package/skills/{te-engage → ae-engage}/SKILL.md +106 -6
  125. package/skills/{te-engage → ae-engage}/references/add-approver.md +2 -2
  126. package/skills/{te-engage → ae-engage}/references/add-channel.md +2 -2
  127. package/skills/{te-engage → ae-engage}/references/approver-list.md +2 -2
  128. package/skills/{te-engage → ae-engage}/references/cancel-query-by-request-id.md +2 -2
  129. package/skills/{te-engage → ae-engage}/references/channel-detail.md +2 -2
  130. package/skills/{te-engage → ae-engage}/references/channel-list.md +2 -2
  131. package/skills/{te-engage → ae-engage}/references/config-channel-detail.md +2 -2
  132. package/skills/{te-engage → ae-engage}/references/config-channel-list.md +2 -2
  133. package/skills/{te-engage → ae-engage}/references/config-item-analysis-report.md +2 -2
  134. package/skills/{te-engage → ae-engage}/references/config-item-detail.md +2 -2
  135. package/skills/{te-engage → ae-engage}/references/config-item-list.md +2 -2
  136. package/skills/{te-engage → ae-engage}/references/config-item-strategy-comparison.md +2 -2
  137. package/skills/{te-engage → ae-engage}/references/config-item-trigger-report.md +2 -2
  138. package/skills/{te-engage → ae-engage}/references/copy-config-template.md +2 -2
  139. package/skills/{te-engage → ae-engage}/references/delete-channel.md +2 -2
  140. package/skills/{te-engage → ae-engage}/references/delete-config-channel.md +2 -2
  141. package/skills/{te-engage → ae-engage}/references/delete-config-item.md +2 -2
  142. package/skills/{te-engage → ae-engage}/references/delete-flow.md +2 -2
  143. package/skills/{te-engage → ae-engage}/references/flow-ab-split-node-report.md +2 -2
  144. package/skills/{te-engage → ae-engage}/references/flow-detail.md +2 -2
  145. package/skills/{te-engage → ae-engage}/references/flow-list.md +2 -2
  146. package/skills/{te-engage → ae-engage}/references/flow-node-config-schema.md +2 -2
  147. package/skills/{te-engage → ae-engage}/references/flow-node-detail-report.md +2 -2
  148. package/skills/{te-engage → ae-engage}/references/flow-node-overview-report.md +2 -2
  149. package/skills/{te-engage → ae-engage}/references/flow-process-report.md +2 -2
  150. package/skills/{te-engage → ae-engage}/references/manage-flow.md +2 -2
  151. package/skills/{te-engage → ae-engage}/references/manage-strategy.md +2 -2
  152. package/skills/{te-engage → ae-engage}/references/manage-task.md +2 -2
  153. package/skills/{te-engage → ae-engage}/references/modify-flow-base-info.md +2 -2
  154. package/skills/{te-engage → ae-engage}/references/save-flow.md +3 -3
  155. package/skills/{te-engage → ae-engage}/references/strategy-detail.md +2 -2
  156. package/skills/{te-engage → ae-engage}/references/strategy-list.md +2 -2
  157. package/skills/{te-engage → ae-engage}/references/task-data-detail.md +3 -10
  158. package/skills/{te-engage → ae-engage}/references/task-data-overview.md +3 -9
  159. package/skills/{te-engage → ae-engage}/references/task-detail.md +2 -2
  160. package/skills/{te-engage → ae-engage}/references/task-experiment-report.md +3 -9
  161. package/skills/{te-engage → ae-engage}/references/task-list.md +2 -2
  162. package/skills/{te-engage → ae-engage}/references/task-metric-detail.md +3 -9
  163. package/skills/{te-engage → ae-engage}/references/task-stats.md +2 -2
  164. package/skills/{te-engage → ae-engage}/references/update-channel-status.md +2 -2
  165. package/skills/{te-engage → ae-engage}/references/update-config-channel-status.md +2 -2
  166. package/skills/{te-engage → ae-engage}/references/validate-flow-node-config.md +2 -2
  167. package/skills/{te-engage → ae-engage}/references/whitelist-list.md +2 -2
  168. package/dist/auth-DXKYLMO7.js +0 -81
  169. package/dist/auth-JXELJNDS.js +0 -19
  170. package/dist/auth-L3G3A74I.js +0 -67
  171. package/dist/chunk-3GM5LJZR.js +0 -145
  172. package/dist/chunk-JD5DXMKL.js +0 -172
  173. package/dist/chunk-OVQOK35G.js +0 -108
  174. package/dist/chunk-RJNLN3KQ.js +0 -217
  175. package/dist/client-T4VODLA6.js +0 -16
  176. package/dist/community-GMALVSRF.js +0 -684
  177. package/dist/config-V7AXKDMB.js +0 -242
  178. package/dist/raw-ZNVURYMR.js +0 -59
  179. package/dist/te-analysis-7NN3SY3I.js +0 -871
  180. package/dist/te-audience-P43BWMHM.js +0 -350
  181. package/dist/te-common-H3IPTI2I.js +0 -144
  182. package/dist/te-dataops-WCGDBJLF.js +0 -1853
  183. package/dist/te-engage-UTRVNTGU.js +0 -1470
  184. package/dist/te-meta-HGYNXVGF.js +0 -479
  185. package/skills/te-analysis/SKILL.md +0 -107
  186. package/skills/te-analysis/references/get-analysis-query-schema.md +0 -36
  187. package/skills/te-analysis/references/list-public-access-links.md +0 -31
  188. package/skills/te-audience/SKILL.md +0 -63
  189. package/skills/te-audience/references/get-cluster-definition-schema.md +0 -37
  190. package/skills/te-audience/references/get-clusters-by-name.md +0 -32
  191. package/skills/te-audience/references/get-tag-definition-schema.md +0 -32
  192. package/skills/te-audience/references/get-tags-by-name.md +0 -32
  193. package/skills/te-common/SKILL.md +0 -135
  194. package/skills/te-community/SKILL.md +0 -125
  195. package/skills/te-meta/SKILL.md +0 -71
  196. package/skills/te-meta/references/list-metrics.md +0 -33
  197. package/skills/te-meta/references/list-project-mark-times.md +0 -33
  198. package/skills/te-shared/SKILL.md +0 -115
@@ -1,67 +0,0 @@
1
- import {
2
- printError,
3
- printOutput
4
- } from "./chunk-KM57HI5B.js";
5
- import {
6
- clearToken,
7
- getAuthStatus,
8
- getToken,
9
- resolveHost,
10
- setTokenManual
11
- } from "./chunk-RJNLN3KQ.js";
12
- import "./chunk-OVQOK35G.js";
13
-
14
- // src/commands/auth.ts
15
- function registerAuth(program) {
16
- const auth = program.command("auth").description("Authentication management");
17
- auth.command("login").description("Login to TE (auto-extract token from Chrome on macOS)").action(async () => {
18
- const host = resolveHost(program.opts().host);
19
- if (!host) {
20
- printError("config", "No TE host configured.", "Run: ae-cli config set-host");
21
- process.exit(1);
22
- }
23
- try {
24
- const token = await getToken(host);
25
- process.stderr.write(`[ae-cli] Authenticated to ${host}
26
- `);
27
- printOutput({ authenticated: true, host, token: token.slice(0, 8) + "..." }, program.opts().format || "json");
28
- } catch (err) {
29
- printError("auth", err.message);
30
- process.exit(1);
31
- }
32
- });
33
- auth.command("set-token <token>").description("Manually set authentication token for active host").action((token) => {
34
- const host = resolveHost(program.opts().host);
35
- if (!host) {
36
- printError("config", "No TE host configured.", "Run: ae-cli config set-host");
37
- process.exit(1);
38
- }
39
- setTokenManual(token, host);
40
- process.stderr.write(`[ae-cli] Token saved for ${host}
41
- `);
42
- printOutput({ saved: true, host }, program.opts().format || "json");
43
- });
44
- auth.command("status").description("Show current authentication status").action(() => {
45
- const host = resolveHost(program.opts().host);
46
- if (!host) {
47
- printOutput({ authenticated: false, host: "(none)", hint: "Run: ae-cli config set-host" }, program.opts().format || "json");
48
- return;
49
- }
50
- const status = getAuthStatus(host);
51
- printOutput(status, program.opts().format || "json");
52
- });
53
- auth.command("logout").description("Clear stored token for active host").action(() => {
54
- const host = resolveHost(program.opts().host);
55
- if (!host) {
56
- printError("config", "No TE host configured.", "Run: ae-cli config set-host");
57
- process.exit(1);
58
- }
59
- clearToken(host);
60
- process.stderr.write(`[ae-cli] Token cleared for ${host}
61
- `);
62
- printOutput({ cleared: true, host }, program.opts().format || "json");
63
- });
64
- }
65
- export {
66
- registerAuth
67
- };
@@ -1,145 +0,0 @@
1
- import {
2
- clearToken,
3
- getToken,
4
- resolveHost
5
- } from "./chunk-RJNLN3KQ.js";
6
-
7
- // src/core/client.ts
8
- import WebSocket from "ws";
9
- import { randomBytes } from "crypto";
10
- function genRequestId(prefix) {
11
- const rand = randomBytes(4).toString("base64url").slice(0, 8);
12
- return `${prefix}@@${rand}`;
13
- }
14
- function buildUrl(baseUrl, modulePath, params = {}) {
15
- const base = baseUrl.replace(/\/$/, "");
16
- const p = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
17
- const url = new URL(`${base}${p}`);
18
- for (const [k, v] of Object.entries(params)) {
19
- if (v !== void 0 && v !== null) url.searchParams.set(k, String(v));
20
- }
21
- return url.toString();
22
- }
23
- function buildWsUrl(baseUrl, token) {
24
- const base = baseUrl.replace(/\/$/, "");
25
- const wsBase = base.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://");
26
- return `${wsBase}/v1/ta-websocket/query/${token}`;
27
- }
28
- async function request(method, modulePath, params = {}, body = null, retry = true, hostUrl) {
29
- const resolvedHost = resolveHost(hostUrl);
30
- const token = await getToken(resolvedHost);
31
- const url = buildUrl(resolvedHost, modulePath, params);
32
- const headers = {
33
- "Authorization": `bearer ${token}`,
34
- "Content-Type": "application/json"
35
- };
36
- const options = { method, headers };
37
- if (body && method !== "GET") options.body = JSON.stringify(body);
38
- const resp = await fetch(url, options);
39
- if ((resp.status === 401 || resp.status === 403) && retry) {
40
- clearToken(resolvedHost);
41
- return request(method, modulePath, params, body, false, resolvedHost);
42
- }
43
- const data = await resp.json();
44
- if (data.return_code === -1001 && retry) {
45
- clearToken(resolvedHost);
46
- return request(method, modulePath, params, body, false, resolvedHost);
47
- }
48
- if (data.return_code !== 0 && data.return_code !== void 0) {
49
- throw new Error(`TE API error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
50
- }
51
- return data.data !== void 0 ? data.data : data;
52
- }
53
- async function httpGet(modulePath, params = {}, hostUrl) {
54
- return request("GET", modulePath, params, null, true, hostUrl);
55
- }
56
- async function httpPost(modulePath, params = {}, body, hostUrl) {
57
- return request("POST", modulePath, params, body ?? {}, true, hostUrl);
58
- }
59
- async function wsQueryOnce(projectId, requestId, qp, eventModel, options = {}, token, hostUrl, timeoutMs = 3e4) {
60
- const wsUrl = buildWsUrl(hostUrl, token);
61
- return new Promise((resolve, reject) => {
62
- const ws = new WebSocket(wsUrl);
63
- const timer = setTimeout(() => {
64
- ws.close();
65
- reject(new Error(`WebSocket query timed out after ${timeoutMs}ms`));
66
- }, timeoutMs);
67
- ws.on("open", () => {
68
- const payload = {
69
- requestId,
70
- projectId,
71
- eventModel,
72
- qp: typeof qp === "string" ? qp : JSON.stringify(qp),
73
- searchSource: options.searchSource || "reportQuery",
74
- querySource: options.querySource || "single_report",
75
- contentTranslate: options.contentTranslate !== false,
76
- ...options.extra || {}
77
- };
78
- ws.send(JSON.stringify(["data", payload, { channel: "ta" }]));
79
- });
80
- ws.on("message", (raw) => {
81
- try {
82
- const msg = JSON.parse(raw.toString());
83
- if (Array.isArray(msg) && msg.length >= 2) {
84
- const data = msg[1];
85
- if (data.requestId === requestId && data.progress === 100) {
86
- clearTimeout(timer);
87
- ws.close();
88
- resolve(data);
89
- }
90
- }
91
- } catch {
92
- }
93
- });
94
- ws.on("error", (err) => {
95
- clearTimeout(timer);
96
- reject(err);
97
- });
98
- ws.on("close", () => {
99
- clearTimeout(timer);
100
- });
101
- });
102
- }
103
- async function wsQuery(projectId, requestId, qp, eventModel, options = {}, hostUrl) {
104
- const resolvedHost = resolveHost(hostUrl);
105
- const token = await getToken(resolvedHost);
106
- try {
107
- return await wsQueryOnce(projectId, requestId, qp, eventModel, options, token, resolvedHost);
108
- } catch (err) {
109
- const msg = err.message || "";
110
- if (msg.includes("401") || msg.includes("403") || msg.includes("auth")) {
111
- clearToken(resolvedHost);
112
- const newToken = await getToken(resolvedHost);
113
- return wsQueryOnce(projectId, requestId, qp, eventModel, options, newToken, resolvedHost);
114
- }
115
- throw err;
116
- }
117
- }
118
- async function querySql(projectId, sql, hostUrl) {
119
- const requestId = genRequestId("sqlIde");
120
- const qp = {
121
- events: { sql },
122
- eventView: { sqlViewParams: [] }
123
- };
124
- return wsQuery(projectId, requestId, qp, 10, {
125
- searchSource: "sqlIde",
126
- querySource: "sqlIde"
127
- }, hostUrl);
128
- }
129
- async function queryReportData(projectId, reportId, qp, eventModel, options = {}, hostUrl) {
130
- const dashboardId = options.dashboardId || 0;
131
- const requestId = genRequestId(`${projectId}_${dashboardId}_${reportId}`);
132
- return wsQuery(projectId, requestId, qp, eventModel, {
133
- searchSource: options.searchSource || "model_search",
134
- querySource: options.querySource || "module",
135
- ...options
136
- }, hostUrl);
137
- }
138
-
139
- export {
140
- httpGet,
141
- httpPost,
142
- wsQuery,
143
- querySql,
144
- queryReportData
145
- };
@@ -1,172 +0,0 @@
1
- import {
2
- getToken
3
- } from "./chunk-RJNLN3KQ.js";
4
- import {
5
- getActiveHost,
6
- getConfigDir
7
- } from "./chunk-OVQOK35G.js";
8
-
9
- // src/core/mcp.ts
10
- import fs from "fs";
11
- import path from "path";
12
- var MCP_PROTOCOL_VERSION = "2025-11-25";
13
- var JSONRPC_VERSION = "2.0";
14
- var serviceMappingMap = /* @__PURE__ */ new Map();
15
- registerMcpMapping("te_analysis", {
16
- componentName: "analysis",
17
- mappingPath: "analysis"
18
- });
19
- registerMcpMapping("te_analysis_extend", {
20
- componentName: "analysis",
21
- mappingPath: "analysis-extend"
22
- });
23
- function registerMcpMapping(serviceName, mapping) {
24
- serviceMappingMap.set(serviceName, mapping);
25
- }
26
- function registerMcpMappings(mappings) {
27
- for (const [serviceName, mapping] of Object.entries(mappings)) {
28
- serviceMappingMap.set(serviceName, mapping);
29
- }
30
- }
31
- function getMcpMapping(serviceName) {
32
- const mapping = serviceMappingMap.get(serviceName);
33
- if (!mapping) {
34
- throw new Error(`MCP mapping not found for service: '${serviceName}'. Please register it using registerMcpMapping() first.`);
35
- }
36
- return mapping;
37
- }
38
- function buildMcpUrl(host, serviceName) {
39
- const mapping = getMcpMapping(serviceName);
40
- const base = host.replace(/\/+$/, "");
41
- return `${base}/mcp/${mapping.componentName}/http/${mapping.mappingPath}`;
42
- }
43
- function resolveMcpUrl(mcpUrlOverride, host, serviceName) {
44
- if (mcpUrlOverride) {
45
- return mcpUrlOverride;
46
- }
47
- return buildMcpUrl(host, serviceName);
48
- }
49
- var requestIdCounter = 1;
50
- function genRequestId() {
51
- return requestIdCounter++;
52
- }
53
- var MCP_TOKEN_FILE = path.join(getConfigDir(), "mcp-tokens.json");
54
- var MCP_TOKEN_GENERATE_PATH = "/v1/ta/mcp/token/generate";
55
- function loadMcpTokenStore() {
56
- try {
57
- if (fs.existsSync(MCP_TOKEN_FILE)) {
58
- return JSON.parse(fs.readFileSync(MCP_TOKEN_FILE, "utf-8"));
59
- }
60
- } catch {
61
- }
62
- return {};
63
- }
64
- function saveMcpTokenStore(store) {
65
- const dir = getConfigDir();
66
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
67
- fs.writeFileSync(MCP_TOKEN_FILE, JSON.stringify(store, null, 2));
68
- }
69
- async function generateMcpToken(hostUrl) {
70
- const teToken = await getToken(hostUrl);
71
- const base = hostUrl.replace(/\/+$/, "");
72
- const url = `${base}${MCP_TOKEN_GENERATE_PATH}`;
73
- const resp = await fetch(url, {
74
- method: "GET",
75
- headers: {
76
- "Authorization": `bearer ${teToken}`
77
- }
78
- });
79
- if (!resp.ok) {
80
- throw new Error(`MCP token generate HTTP error: ${resp.status} ${resp.statusText}`);
81
- }
82
- const data = await resp.json();
83
- if (data.return_code !== 0) {
84
- throw new Error(`MCP token generate error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
85
- }
86
- const mcpToken = data.data?.userSecret;
87
- if (!mcpToken) {
88
- throw new Error("MCP token generate error: empty userSecret in response");
89
- }
90
- return mcpToken;
91
- }
92
- async function getMcpToken(hostOverride) {
93
- const hostUrl = hostOverride || getActiveHost();
94
- const store = loadMcpTokenStore();
95
- if (store[hostUrl]) {
96
- return store[hostUrl];
97
- }
98
- const mcpToken = await generateMcpToken(hostUrl);
99
- const updatedStore = { ...store, [hostUrl]: mcpToken };
100
- saveMcpTokenStore(updatedStore);
101
- return mcpToken;
102
- }
103
- async function mcpRequest(url, method, params = {}, hostOverride) {
104
- const token = await getMcpToken(hostOverride);
105
- const requestId = genRequestId();
106
- const paramsWithMeta = {
107
- ...params,
108
- _meta: { progressToken: requestId }
109
- };
110
- const body = {
111
- jsonrpc: JSONRPC_VERSION,
112
- id: requestId,
113
- method,
114
- params: paramsWithMeta
115
- };
116
- const headers = {
117
- "Content-Type": "application/json",
118
- "Accept": "application/json, text/event-stream",
119
- "mcp-protocol-version": MCP_PROTOCOL_VERSION,
120
- "mcp-token": token
121
- };
122
- const resp = await fetch(url, {
123
- method: "POST",
124
- headers,
125
- body: JSON.stringify(body)
126
- });
127
- if (!resp.ok) {
128
- throw new Error(`MCP HTTP error: ${resp.status} ${resp.statusText}`);
129
- }
130
- const data = await resp.json();
131
- if (data.error) {
132
- throw new Error(`MCP error: ${data.error.message || JSON.stringify(data.error)}`);
133
- }
134
- return data.result;
135
- }
136
- async function callMcpTool(url, toolName, args = {}, hostOverride) {
137
- const params = {
138
- name: toolName,
139
- arguments: args
140
- };
141
- const result = await mcpRequest(url, "tools/call", params, hostOverride);
142
- return {
143
- content: result.content.map((item) => {
144
- if (item.type === "text") {
145
- return { type: "text", text: item.text };
146
- } else if (item.type === "image") {
147
- return { type: "image", data: item.data, mimeType: item.mimeType };
148
- } else {
149
- return { type: "resource", ...item };
150
- }
151
- }),
152
- isError: result.isError
153
- };
154
- }
155
- function parseMcpResult(result) {
156
- if (result.content.length > 0 && result.content[0].type === "text") {
157
- const text = result.content[0].text || "";
158
- try {
159
- return JSON.parse(text);
160
- } catch {
161
- return text;
162
- }
163
- }
164
- return result;
165
- }
166
-
167
- export {
168
- registerMcpMappings,
169
- resolveMcpUrl,
170
- callMcpTool,
171
- parseMcpResult
172
- };
@@ -1,108 +0,0 @@
1
- // src/core/config.ts
2
- import fs from "fs";
3
- import path from "path";
4
- var CONFIG_DIR = path.join(process.env.HOME || "", ".ae-cli");
5
- var CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
6
- function ensureDir() {
7
- if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR, { recursive: true });
8
- }
9
- function loadConfig() {
10
- try {
11
- if (fs.existsSync(CONFIG_FILE)) {
12
- const raw = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
13
- if (raw.defaultHost && !raw.activeHost) {
14
- const migrated = migrateConfig(raw);
15
- saveConfig(migrated);
16
- return migrated;
17
- }
18
- return raw;
19
- }
20
- } catch {
21
- }
22
- return { activeHost: "", hosts: {} };
23
- }
24
- function migrateConfig(old) {
25
- const hosts = {};
26
- const oldHost = old.defaultHost;
27
- if (old.hosts) {
28
- for (const [key, val] of Object.entries(old.hosts)) {
29
- const url = key.startsWith("http") ? key : `https://${key}`;
30
- hosts[url] = val;
31
- }
32
- }
33
- const activeHost = oldHost.startsWith("http") ? oldHost : `https://${oldHost}`;
34
- if (!hosts[activeHost]) {
35
- hosts[activeHost] = { label: "default" };
36
- }
37
- return { activeHost, hosts };
38
- }
39
- function saveConfig(config) {
40
- ensureDir();
41
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
42
- }
43
- function getActiveHost() {
44
- const config = loadConfig();
45
- return config.activeHost;
46
- }
47
- function setActiveHost(url) {
48
- const config = loadConfig();
49
- if (!config.hosts[url]) {
50
- throw new Error(`Host ${url} is not in the configured hosts list. Add it first.`);
51
- }
52
- config.activeHost = url;
53
- saveConfig(config);
54
- }
55
- function addHost(url, label) {
56
- const config = loadConfig();
57
- config.hosts[url] = { label };
58
- if (!config.activeHost) {
59
- config.activeHost = url;
60
- }
61
- saveConfig(config);
62
- }
63
- function updateHostLabel(url, label) {
64
- const config = loadConfig();
65
- if (config.hosts[url]) {
66
- config.hosts[url].label = label;
67
- saveConfig(config);
68
- }
69
- }
70
- function removeHost(url) {
71
- const config = loadConfig();
72
- delete config.hosts[url];
73
- if (config.activeHost === url) {
74
- const remaining = Object.keys(config.hosts);
75
- config.activeHost = remaining.length > 0 ? remaining[0] : "";
76
- }
77
- saveConfig(config);
78
- }
79
- function listHosts() {
80
- const config = loadConfig();
81
- return Object.entries(config.hosts).map(([url, entry]) => ({
82
- url,
83
- label: entry.label,
84
- active: url === config.activeHost
85
- }));
86
- }
87
- function getConfigDir() {
88
- return CONFIG_DIR;
89
- }
90
- function extractHostname(fullUrl) {
91
- try {
92
- const u = new URL(fullUrl);
93
- return u.host;
94
- } catch {
95
- return fullUrl;
96
- }
97
- }
98
-
99
- export {
100
- getActiveHost,
101
- setActiveHost,
102
- addHost,
103
- updateHostLabel,
104
- removeHost,
105
- listHosts,
106
- getConfigDir,
107
- extractHostname
108
- };
@@ -1,217 +0,0 @@
1
- import {
2
- extractHostname,
3
- getActiveHost,
4
- getConfigDir
5
- } from "./chunk-OVQOK35G.js";
6
-
7
- // src/core/auth.ts
8
- import fs from "fs";
9
- import path from "path";
10
- import { execFileSync } from "child_process";
11
- var TOKENS_FILE = path.join(getConfigDir(), "tokens.json");
12
- var LEGACY_DIR = path.join(process.env.HOME || "", ".te-mcp");
13
- var TOKEN_TTL_MS = 20 * 60 * 60 * 1e3;
14
- var OSASCRIPT_POLL_INTERVAL_MS = 2e3;
15
- var OSASCRIPT_POLL_TIMEOUT_MS = 6e4;
16
- function ensureDir() {
17
- const dir = getConfigDir();
18
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
19
- }
20
- function resolveHost(hostOverride) {
21
- if (hostOverride) return hostOverride;
22
- return getActiveHost();
23
- }
24
- function loadAllTokens() {
25
- try {
26
- const legacyTokens = path.join(LEGACY_DIR, "tokens.json");
27
- if (fs.existsSync(legacyTokens) && !fs.existsSync(TOKENS_FILE)) {
28
- const data = JSON.parse(fs.readFileSync(legacyTokens, "utf-8"));
29
- const migrated = {};
30
- for (const [key, val] of Object.entries(data)) {
31
- const url = key.startsWith("http") ? key : `https://${key}`;
32
- migrated[url] = val;
33
- }
34
- ensureDir();
35
- fs.writeFileSync(TOKENS_FILE, JSON.stringify(migrated, null, 2));
36
- return migrated;
37
- }
38
- if (fs.existsSync(TOKENS_FILE)) {
39
- const data = JSON.parse(fs.readFileSync(TOKENS_FILE, "utf-8"));
40
- let needsMigration = false;
41
- const migrated = {};
42
- for (const [key, val] of Object.entries(data)) {
43
- if (!key.startsWith("http")) {
44
- migrated[`https://${key}`] = val;
45
- needsMigration = true;
46
- } else {
47
- migrated[key] = val;
48
- }
49
- }
50
- if (needsMigration) {
51
- fs.writeFileSync(TOKENS_FILE, JSON.stringify(migrated, null, 2));
52
- return migrated;
53
- }
54
- return data;
55
- }
56
- } catch {
57
- }
58
- return {};
59
- }
60
- function saveAllTokens(tokens) {
61
- ensureDir();
62
- fs.writeFileSync(TOKENS_FILE, JSON.stringify(tokens, null, 2));
63
- }
64
- function loadToken(hostUrl) {
65
- const tokens = loadAllTokens();
66
- const entry = tokens[hostUrl];
67
- if (!entry || !entry.token) return null;
68
- if (entry.updatedAt) {
69
- const age = Date.now() - new Date(entry.updatedAt).getTime();
70
- if (age > TOKEN_TTL_MS) {
71
- clearToken(hostUrl);
72
- return null;
73
- }
74
- }
75
- return { host: hostUrl, token: entry.token, updatedAt: entry.updatedAt };
76
- }
77
- function saveToken(token, hostUrl) {
78
- const tokens = loadAllTokens();
79
- tokens[hostUrl] = { token, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
80
- saveAllTokens(tokens);
81
- }
82
- function clearToken(hostUrl) {
83
- const tokens = loadAllTokens();
84
- delete tokens[hostUrl];
85
- saveAllTokens(tokens);
86
- }
87
- function setTokenManual(token, hostUrl) {
88
- saveToken(token, hostUrl);
89
- }
90
- function getAuthStatus(hostUrl) {
91
- if (process.env.TE_TOKEN) {
92
- return { authenticated: true, host: hostUrl, source: "env:TE_TOKEN" };
93
- }
94
- const cached = loadToken(hostUrl);
95
- if (cached) {
96
- const ageMs = Date.now() - new Date(cached.updatedAt).getTime();
97
- const hours = Math.round(ageMs / 36e5);
98
- return { authenticated: true, host: hostUrl, tokenAge: `${hours}h ago`, source: "cache" };
99
- }
100
- return { authenticated: false, host: hostUrl };
101
- }
102
- function extractTokenViaOsascript(hostUrl) {
103
- if (process.platform !== "darwin") return { token: null, error: "not_mac" };
104
- const hostname = extractHostname(hostUrl);
105
- const lines = [
106
- 'tell application "Google Chrome"',
107
- " repeat with w in windows",
108
- " repeat with t in tabs of w",
109
- ` if URL of t contains "${hostname}" then`,
110
- ` return execute t javascript "localStorage.getItem('ACCESS_TOKEN')"`,
111
- " end if",
112
- " end repeat",
113
- " end repeat",
114
- ' return "NO_TAB_FOUND"',
115
- "end tell"
116
- ];
117
- try {
118
- const args = lines.flatMap((line) => ["-e", line]);
119
- const result = execFileSync("osascript", args, { encoding: "utf8", timeout: 5e3 }).trim();
120
- if (result === "NO_TAB_FOUND") return { token: null, error: "no_tab" };
121
- if (!result || result === "missing value") return { token: null, error: "no_token" };
122
- return { token: result.replace(/^["']|["']$/g, ""), error: null };
123
- } catch (e) {
124
- const msg = e.message || "";
125
- if (msg.includes("not allowed") || msg.includes("assistive access") || msg.includes("(-1743)")) {
126
- return { token: null, error: "no_js_permission" };
127
- }
128
- return { token: null, error: "no_tab" };
129
- }
130
- }
131
- async function requestTokenViaOsascript(hostUrl) {
132
- process.stderr.write(`[ae-cli] No TE tab found in Chrome. Opening ${hostUrl} ...
133
- `);
134
- process.stderr.write(`[ae-cli] Please login, then your token will be captured automatically.
135
- `);
136
- try {
137
- const openScript = [
138
- 'tell application "Google Chrome"',
139
- " activate",
140
- " if (count of windows) > 0 then",
141
- ` make new tab at end of tabs of window 1 with properties {URL:"${hostUrl}"}`,
142
- " else",
143
- ` open location "${hostUrl}"`,
144
- " end if",
145
- "end tell"
146
- ];
147
- execFileSync("osascript", openScript.flatMap((line) => ["-e", line]), { timeout: 5e3 });
148
- } catch {
149
- process.stderr.write(`[ae-cli] Could not open browser. Please open ${hostUrl} in Chrome manually.
150
- `);
151
- }
152
- const deadline = Date.now() + OSASCRIPT_POLL_TIMEOUT_MS;
153
- while (Date.now() < deadline) {
154
- await new Promise((r) => setTimeout(r, OSASCRIPT_POLL_INTERVAL_MS));
155
- const { token, error } = extractTokenViaOsascript(hostUrl);
156
- if (token) {
157
- process.stderr.write(`[ae-cli] Token captured from Chrome for ${hostUrl}.
158
- `);
159
- return token;
160
- }
161
- if (error === "no_js_permission") return null;
162
- }
163
- process.stderr.write(`[ae-cli] Polling timed out after ${OSASCRIPT_POLL_TIMEOUT_MS / 1e3}s.
164
- `);
165
- return null;
166
- }
167
- async function getToken(hostUrl) {
168
- if (!hostUrl) {
169
- throw new Error(
170
- `No TE host configured.
171
- Run: ae-cli config set-host`
172
- );
173
- }
174
- if (process.env.TE_TOKEN) {
175
- return process.env.TE_TOKEN;
176
- }
177
- const cached = loadToken(hostUrl);
178
- if (cached && cached.token) return cached.token;
179
- const { token: osascriptToken, error } = extractTokenViaOsascript(hostUrl);
180
- if (error === "no_js_permission") {
181
- throw new Error(
182
- `Chrome JavaScript from Apple Events is not enabled.
183
- Enable it: Chrome menu \u2192 View \u2192 Developer \u2192 Allow JavaScript from Apple Events`
184
- );
185
- }
186
- if (error === "not_mac") {
187
- throw new Error(
188
- `Auto token extraction is only available on macOS + Chrome.
189
- Use: ae-cli auth set-token <token>`
190
- );
191
- }
192
- if (osascriptToken) {
193
- saveToken(osascriptToken, hostUrl);
194
- return osascriptToken;
195
- }
196
- const polledToken = await requestTokenViaOsascript(hostUrl);
197
- if (polledToken) {
198
- saveToken(polledToken, hostUrl);
199
- return polledToken;
200
- }
201
- throw new Error(
202
- `Cannot obtain token for ${hostUrl}.
203
- Options:
204
- 1. ae-cli auth login (macOS + Chrome)
205
- 2. ae-cli auth set-token <token>`
206
- );
207
- }
208
-
209
- export {
210
- resolveHost,
211
- loadToken,
212
- saveToken,
213
- clearToken,
214
- setTokenManual,
215
- getAuthStatus,
216
- getToken
217
- };