@huawei-iac-tools/landingzone-workbench 0.0.0-stage → 0.0.1

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 (246) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +85 -2
  3. package/cordis.patch.yml +21 -0
  4. package/knowledge/account-qualification.md +128 -0
  5. package/knowledge/blueprints/_base/blueprint.json +481 -0
  6. package/knowledge/blueprints/_base/defaults.json +127 -0
  7. package/knowledge/blueprints/foundation-lz/blueprint.json +43 -0
  8. package/knowledge/blueprints/foundation-lz/defaults.json +47 -0
  9. package/knowledge/blueprints/full-lz/blueprint.json +11 -0
  10. package/knowledge/blueprints/full-lz/defaults.json +8 -0
  11. package/knowledge/config.json +43 -0
  12. package/knowledge/error-rules.json +14 -0
  13. package/knowledge/ic-policies.json +21 -0
  14. package/knowledge/modules/account-structure.md +101 -0
  15. package/knowledge/modules/compliance/config-rms.md +212 -0
  16. package/knowledge/modules/compliance/cts.md +179 -0
  17. package/knowledge/modules/compliance/obs-lts.md +155 -0
  18. package/knowledge/modules/ic-policies.json +21 -0
  19. package/knowledge/modules/identity-center.md +603 -0
  20. package/knowledge/modules/module-layers.md +169 -0
  21. package/knowledge/modules/network/er.md +222 -0
  22. package/knowledge/modules/network/nat-eip.md +123 -0
  23. package/knowledge/modules/network/ram-share.md +92 -0
  24. package/knowledge/modules/network/vpc-subnet.md +142 -0
  25. package/knowledge/modules/organization-security/scp.md +122 -0
  26. package/knowledge/modules/organizations.md +212 -0
  27. package/knowledge/modules/recommended-config.md +157 -0
  28. package/knowledge/modules/recommended-rules.json +175 -0
  29. package/knowledge/modules/scp-policies.json +111 -0
  30. package/knowledge/modules/security/aad.md +94 -0
  31. package/knowledge/modules/security/cfw.md +105 -0
  32. package/knowledge/modules/security/waf.md +110 -0
  33. package/knowledge/param-mappings.json +133 -0
  34. package/knowledge/prompts.md +83 -0
  35. package/knowledge/resource-types.json +1162 -0
  36. package/knowledge/scp-policies.json +111 -0
  37. package/knowledge/state-machine.md +33 -0
  38. package/lib/client.js +21 -0
  39. package/lib/index.js +28592 -0
  40. package/lib/types/account-role.d.ts +19 -0
  41. package/lib/types/account-scope.d.ts +10 -0
  42. package/lib/types/agency.d.ts +38 -0
  43. package/lib/types/client/DropdownSelect.d.ts +49 -0
  44. package/lib/types/client/LoginGate.d.ts +20 -0
  45. package/lib/types/client/PanelIcon.d.ts +11 -0
  46. package/lib/types/client/WorkbenchShell.d.ts +21 -0
  47. package/lib/types/client/account-role.d.ts +15 -0
  48. package/lib/types/client/credential-status.d.ts +15 -0
  49. package/lib/types/client/huawei-mark.d.ts +37 -0
  50. package/lib/types/client/index.d.ts +26 -0
  51. package/lib/types/client/layout-ref.d.ts +23 -0
  52. package/lib/types/client/pages/ConfigPage/AdviceCard.d.ts +26 -0
  53. package/lib/types/client/pages/ConfigPage/AuditBar.d.ts +21 -0
  54. package/lib/types/client/pages/ConfigPage/ChangeSummaryCard.d.ts +22 -0
  55. package/lib/types/client/pages/ConfigPage/ChangesCard.d.ts +27 -0
  56. package/lib/types/client/pages/ConfigPage/ComplianceDetail.d.ts +25 -0
  57. package/lib/types/client/pages/ConfigPage/ComplianceSummaryCard.d.ts +31 -0
  58. package/lib/types/client/pages/ConfigPage/FindingsCard.d.ts +21 -0
  59. package/lib/types/client/pages/ConfigPage/GlossaryDrawer.d.ts +17 -0
  60. package/lib/types/client/pages/ConfigPage/OrgComplianceDetail.d.ts +15 -0
  61. package/lib/types/client/pages/ConfigPage/Pager.d.ts +32 -0
  62. package/lib/types/client/pages/ConfigPage/ResourceDrawer.d.ts +26 -0
  63. package/lib/types/client/pages/ConfigPage/ResourcesTable.d.ts +35 -0
  64. package/lib/types/client/pages/ConfigPage/RollupPanel.d.ts +17 -0
  65. package/lib/types/client/pages/ConfigPage/RuleDetailDrawer.d.ts +23 -0
  66. package/lib/types/client/pages/ConfigPage/StatusCards.d.ts +26 -0
  67. package/lib/types/client/pages/ConfigPage/UncoveredDialog.d.ts +22 -0
  68. package/lib/types/client/pages/ConfigPage/config-api.d.ts +101 -0
  69. package/lib/types/client/pages/ConfigPage/config-store.d.ts +57 -0
  70. package/lib/types/client/pages/ConfigPage/index.d.ts +21 -0
  71. package/lib/types/client/pages/ConfigPage/paging.d.ts +46 -0
  72. package/lib/types/client/pages/ConfigPage/scope-options.d.ts +51 -0
  73. package/lib/types/client/pages/CostPage/AccountAllocation.d.ts +24 -0
  74. package/lib/types/client/pages/CostPage/AccountBars.d.ts +20 -0
  75. package/lib/types/client/pages/CostPage/AccountColumns.d.ts +24 -0
  76. package/lib/types/client/pages/CostPage/AccountDonut.d.ts +18 -0
  77. package/lib/types/client/pages/CostPage/AccountSwitcher.d.ts +25 -0
  78. package/lib/types/client/pages/CostPage/AdviceCard.d.ts +43 -0
  79. package/lib/types/client/pages/CostPage/AdviceFindings.d.ts +43 -0
  80. package/lib/types/client/pages/CostPage/BillingPanels.d.ts +23 -0
  81. package/lib/types/client/pages/CostPage/BudgetCard.d.ts +36 -0
  82. package/lib/types/client/pages/CostPage/GlossaryDrawer.d.ts +16 -0
  83. package/lib/types/client/pages/CostPage/KpiRow.d.ts +23 -0
  84. package/lib/types/client/pages/CostPage/MarkdownBlock.d.ts +16 -0
  85. package/lib/types/client/pages/CostPage/ReportView.d.ts +17 -0
  86. package/lib/types/client/pages/CostPage/ResourceColumns.d.ts +19 -0
  87. package/lib/types/client/pages/CostPage/ResourceDonut.d.ts +18 -0
  88. package/lib/types/client/pages/CostPage/ResourcesCard.d.ts +40 -0
  89. package/lib/types/client/pages/CostPage/RuleDetailDrawer.d.ts +23 -0
  90. package/lib/types/client/pages/CostPage/SavingView.d.ts +38 -0
  91. package/lib/types/client/pages/CostPage/ServiceDonut.d.ts +17 -0
  92. package/lib/types/client/pages/CostPage/TrendChart.d.ts +24 -0
  93. package/lib/types/client/pages/CostPage/budget-input.d.ts +30 -0
  94. package/lib/types/client/pages/CostPage/cost-api.d.ts +266 -0
  95. package/lib/types/client/pages/CostPage/cost-store.d.ts +25 -0
  96. package/lib/types/client/pages/CostPage/format.d.ts +37 -0
  97. package/lib/types/client/pages/CostPage/index.d.ts +34 -0
  98. package/lib/types/client/pages/CostPage/trend-fold.d.ts +32 -0
  99. package/lib/types/client/pages/CostPage/useEcharts.d.ts +70 -0
  100. package/lib/types/client/pages/OrgStructurePage/AccountStatsCard.d.ts +22 -0
  101. package/lib/types/client/pages/OrgStructurePage/CoreAccountsCard.d.ts +18 -0
  102. package/lib/types/client/pages/OrgStructurePage/CreateAccountDialog.d.ts +28 -0
  103. package/lib/types/client/pages/OrgStructurePage/ManageUsersDialog.d.ts +28 -0
  104. package/lib/types/client/pages/OrgStructurePage/MemberAccountsTable.d.ts +32 -0
  105. package/lib/types/client/pages/OrgStructurePage/MoveAccountDialog.d.ts +29 -0
  106. package/lib/types/client/pages/OrgStructurePage/OrgGlossaryDrawer.d.ts +13 -0
  107. package/lib/types/client/pages/OrgStructurePage/OrgTreeCard.d.ts +31 -0
  108. package/lib/types/client/pages/OrgStructurePage/index.d.ts +21 -0
  109. package/lib/types/client/pages/OrgStructurePage/org-api.d.ts +166 -0
  110. package/lib/types/client/pages/OverviewPage/AnchorRow.d.ts +24 -0
  111. package/lib/types/client/pages/OverviewPage/AttentionList.d.ts +29 -0
  112. package/lib/types/client/pages/OverviewPage/OverviewCharts.d.ts +79 -0
  113. package/lib/types/client/pages/OverviewPage/OverviewGlossaryDrawer.d.ts +15 -0
  114. package/lib/types/client/pages/OverviewPage/index.d.ts +22 -0
  115. package/lib/types/client/pages/OverviewPage/overview-api.d.ts +115 -0
  116. package/lib/types/client/pages/ResourcePage/AccountResourceList.d.ts +21 -0
  117. package/lib/types/client/pages/ResourcePage/components/GlossaryDrawer.d.ts +20 -0
  118. package/lib/types/client/pages/ResourcePage/components/MetricCards.d.ts +19 -0
  119. package/lib/types/client/pages/ResourcePage/components/MultiSelect.d.ts +27 -0
  120. package/lib/types/client/pages/ResourcePage/components/PanelPager.d.ts +26 -0
  121. package/lib/types/client/pages/ResourcePage/components/RankBars.d.ts +25 -0
  122. package/lib/types/client/pages/ResourcePage/components/ScopeSelect.d.ts +27 -0
  123. package/lib/types/client/pages/ResourcePage/components/SourceConfigModal.d.ts +21 -0
  124. package/lib/types/client/pages/ResourcePage/components/SyncControls.d.ts +18 -0
  125. package/lib/types/client/pages/ResourcePage/components/TrendChart.d.ts +14 -0
  126. package/lib/types/client/pages/ResourcePage/components/useColumnWidths.d.ts +12 -0
  127. package/lib/types/client/pages/ResourcePage/format.d.ts +9 -0
  128. package/lib/types/client/pages/ResourcePage/index.d.ts +20 -0
  129. package/lib/types/client/pages/ResourcePage/summary-api.d.ts +205 -0
  130. package/lib/types/client/pages/SetupPage/AskPanel.d.ts +21 -0
  131. package/lib/types/client/pages/SetupPage/ChatEmbed.d.ts +40 -0
  132. package/lib/types/client/pages/SetupPage/ChatTab.d.ts +17 -0
  133. package/lib/types/client/pages/SetupPage/FormTab.d.ts +12 -0
  134. package/lib/types/client/pages/SetupPage/FormTabV2.d.ts +14 -0
  135. package/lib/types/client/pages/SetupPage/ProgressTreeView.d.ts +15 -0
  136. package/lib/types/client/pages/SetupPage/StageFlow.d.ts +16 -0
  137. package/lib/types/client/pages/SetupPage/index.d.ts +10 -0
  138. package/lib/types/client/pages/SetupPage/progress-types.d.ts +36 -0
  139. package/lib/types/client/pages/SetupPage/session-binding.d.ts +38 -0
  140. package/lib/types/client/pages/SetupPage/session-store.d.ts +57 -0
  141. package/lib/types/client/pages/SetupPage/sessions-ref.d.ts +5 -0
  142. package/lib/types/client/pages/SetupPage/setup-replan.d.ts +13 -0
  143. package/lib/types/client/pages/SetupPage/wb-api.d.ts +192 -0
  144. package/lib/types/client/pages/list-preview.d.ts +36 -0
  145. package/lib/types/client/permission-mode.d.ts +53 -0
  146. package/lib/types/client/store.d.ts +22 -0
  147. package/lib/types/collect.d.ts +78 -0
  148. package/lib/types/config/account-scope.d.ts +61 -0
  149. package/lib/types/config/advice-findings.d.ts +31 -0
  150. package/lib/types/config/advice-prompt.d.ts +60 -0
  151. package/lib/types/config/advice.d.ts +116 -0
  152. package/lib/types/config/cts.d.ts +30 -0
  153. package/lib/types/config/evidence/rules.d.ts +31 -0
  154. package/lib/types/config/evidence/types.d.ts +103 -0
  155. package/lib/types/config/failure-note.d.ts +46 -0
  156. package/lib/types/config/fingerprint-cache.d.ts +45 -0
  157. package/lib/types/config/identity.d.ts +67 -0
  158. package/lib/types/config/query.d.ts +49 -0
  159. package/lib/types/config/rms.d.ts +412 -0
  160. package/lib/types/config/routes.d.ts +32 -0
  161. package/lib/types/config/types.d.ts +785 -0
  162. package/lib/types/config/views.d.ts +158 -0
  163. package/lib/types/cost/accounts.d.ts +29 -0
  164. package/lib/types/cost/advice-findings.d.ts +77 -0
  165. package/lib/types/cost/advice-model.d.ts +19 -0
  166. package/lib/types/cost/advice-prompt.d.ts +73 -0
  167. package/lib/types/cost/advice-subagent-types.d.ts +6 -0
  168. package/lib/types/cost/advice-subagent.d.ts +116 -0
  169. package/lib/types/cost/advice-types.d.ts +63 -0
  170. package/lib/types/cost/advice.d.ts +125 -0
  171. package/lib/types/cost/aggregate.d.ts +157 -0
  172. package/lib/types/cost/assume.d.ts +43 -0
  173. package/lib/types/cost/bss.d.ts +166 -0
  174. package/lib/types/cost/budget-overview.d.ts +38 -0
  175. package/lib/types/cost/budget.d.ts +56 -0
  176. package/lib/types/cost/cache.d.ts +58 -0
  177. package/lib/types/cost/caliber.d.ts +40 -0
  178. package/lib/types/cost/console-links.d.ts +27 -0
  179. package/lib/types/cost/credentials.d.ts +38 -0
  180. package/lib/types/cost/data-window.d.ts +38 -0
  181. package/lib/types/cost/evidence/catalog.d.ts +35 -0
  182. package/lib/types/cost/evidence/index.d.ts +70 -0
  183. package/lib/types/cost/evidence/inventory.d.ts +44 -0
  184. package/lib/types/cost/evidence/pricing.d.ts +72 -0
  185. package/lib/types/cost/evidence/projects.d.ts +18 -0
  186. package/lib/types/cost/evidence/rules.d.ts +66 -0
  187. package/lib/types/cost/evidence/state.d.ts +38 -0
  188. package/lib/types/cost/evidence/thresholds.d.ts +68 -0
  189. package/lib/types/cost/evidence/types.d.ts +288 -0
  190. package/lib/types/cost/evidence/utilization.d.ts +37 -0
  191. package/lib/types/cost/history.d.ts +36 -0
  192. package/lib/types/cost/ledger.d.ts +97 -0
  193. package/lib/types/cost/normalize.d.ts +37 -0
  194. package/lib/types/cost/period-projection.d.ts +57 -0
  195. package/lib/types/cost/plan-check.d.ts +102 -0
  196. package/lib/types/cost/plan-db.d.ts +73 -0
  197. package/lib/types/cost/plan-types.d.ts +183 -0
  198. package/lib/types/cost/plan.d.ts +63 -0
  199. package/lib/types/cost/quote.d.ts +45 -0
  200. package/lib/types/cost/report.d.ts +136 -0
  201. package/lib/types/cost/resources.d.ts +108 -0
  202. package/lib/types/cost/routes.d.ts +38 -0
  203. package/lib/types/cost/scope.d.ts +42 -0
  204. package/lib/types/cost/types.d.ts +335 -0
  205. package/lib/types/cost/unit-prices-derive.d.ts +19 -0
  206. package/lib/types/cost/unit-prices.d.ts +23 -0
  207. package/lib/types/db.d.ts +228 -0
  208. package/lib/types/host-log.d.ts +7 -0
  209. package/lib/types/http.d.ts +42 -0
  210. package/lib/types/index.d.ts +30 -0
  211. package/lib/types/inventory.d.ts +286 -0
  212. package/lib/types/obs.d.ts +16 -0
  213. package/lib/types/org/aggregate.d.ts +36 -0
  214. package/lib/types/org/churn.d.ts +10 -0
  215. package/lib/types/org/orgs.d.ts +258 -0
  216. package/lib/types/org/routes.d.ts +28 -0
  217. package/lib/types/org-types.d.ts +156 -0
  218. package/lib/types/per-service.d.ts +39 -0
  219. package/lib/types/setup/blueprint-loader.d.ts +81 -0
  220. package/lib/types/setup/caller.d.ts +105 -0
  221. package/lib/types/setup/engine.d.ts +41 -0
  222. package/lib/types/setup/form-store.d.ts +13 -0
  223. package/lib/types/setup/nodes/n1-check.d.ts +14 -0
  224. package/lib/types/setup/nodes/n10-governance.d.ts +6 -0
  225. package/lib/types/setup/nodes/n11-infra.d.ts +6 -0
  226. package/lib/types/setup/nodes/n12-reconcile.d.ts +6 -0
  227. package/lib/types/setup/nodes/n2-region.d.ts +6 -0
  228. package/lib/types/setup/nodes/n3-blueprint.d.ts +6 -0
  229. package/lib/types/setup/nodes/n4-modules.d.ts +6 -0
  230. package/lib/types/setup/nodes/n5-details.d.ts +6 -0
  231. package/lib/types/setup/nodes/n6-plan.d.ts +6 -0
  232. package/lib/types/setup/nodes/n7-verify.d.ts +6 -0
  233. package/lib/types/setup/nodes/n8-approve.d.ts +6 -0
  234. package/lib/types/setup/nodes/n9-buildmode.d.ts +6 -0
  235. package/lib/types/setup/plan-state.d.ts +10 -0
  236. package/lib/types/setup/prompt-loader.d.ts +16 -0
  237. package/lib/types/setup/routes.d.ts +22 -0
  238. package/lib/types/setup/session-notify.d.ts +30 -0
  239. package/lib/types/setup/tools.d.ts +19 -0
  240. package/lib/types/setup/types.d.ts +157 -0
  241. package/lib/types/sse-bus.d.ts +23 -0
  242. package/lib/types/tools/config-facts.d.ts +16 -0
  243. package/lib/types/tools/cost-facts.d.ts +10 -0
  244. package/lib/types/tools/register.d.ts +18 -0
  245. package/lib/types/wb-conventions.d.ts +140 -0
  246. package/package.json +77 -4
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 处置计划的 SQLite 落库层(v7 表:`cost_plan_items` / `cost_plan_resources` /
3
+ * `cost_plan_events`)。
4
+ *
5
+ * 为什么不再用 JSON 文件:计划不是"一份文档",而是**一张要查询的表** ——
6
+ * 按状态筛、按账期顺延、按分组去重、以及"谁在什么时候把它标成已执行"。
7
+ * 这三件事 JSON 一样都给不了,而且每加一类数据就要多一个文件、多一套原子写。
8
+ *
9
+ * 三条规矩:
10
+ * 1. **接口与文件版一致**(`readPlan` / `addPlanItem` / `updatePlanItem` /
11
+ * `removePlanItem`),调用方(路由、核验、报告)一行都不用改;
12
+ * 2. **写就写全量**:一次改动 = 一个事务里重建该 (账期, 账号) 的条目 + 资源
13
+ * 基线,再追加一条事件。量级是几十条,全量替换比增量补丁简单且不会漂;
14
+ * 3. **SQLite 不可用就退回文件**(Node < 22.5)。这类环境不该让整个页面挂掉。
15
+ *
16
+ * @module @huaweidevtools/landingzone-workbench/cost/plan-db
17
+ */
18
+ import { type WorkbenchDb } from '../db.ts';
19
+ import type { PlanItem, PlanStatus } from './plan-types.ts';
20
+ /** 一次改动要记的事件。 */
21
+ export interface PlanEvent {
22
+ readonly plan_id: string;
23
+ readonly action: 'add' | 'update' | 'remove' | 'import';
24
+ readonly from_status: PlanStatus | null;
25
+ readonly to_status: PlanStatus | null;
26
+ readonly note: string;
27
+ }
28
+ /**
29
+ * 试一下库能不能用。
30
+ *
31
+ * 调用方(`plan.ts`)据此决定走 SQL 还是 JSON 文件 —— 探测失败不抛错,
32
+ * 只是"这个环境没有库",页面照常。
33
+ */
34
+ export declare function planDbAvailable(): Promise<WorkbenchDb | null>;
35
+ /** 读一个口径的全部处置项。 */
36
+ export declare function readPlanDb(cycle: string, accountId: string | null): Promise<PlanItem[]>;
37
+ /**
38
+ * 把一个口径的清单**整体写成给定的样子**(事务内:先删该口径的行,再逐条写回)。
39
+ *
40
+ * @param events 这次改动要追加的事件(新加的项 / 改状态 / 移除)。
41
+ */
42
+ /**
43
+ * 按 id 找一条处置项所在的**归档口径**('' = 组织视角,否则是该账号)。
44
+ *
45
+ * 为什么要它:改状态/删除是"按 id 操作",而页面此刻可能正处在别的视角里 ——
46
+ * 组织视角看到的一条,可能属于某个账号(反过来也一样)。只按当前视角去改,
47
+ * 就会静默落空,用户看到的就是"点了没反应"。
48
+ *
49
+ * @returns 所在口径;库里没有这条(或库不可用)时 null。
50
+ */
51
+ export declare function findPlanItemScope(cycle: string, id: string): Promise<string | null>;
52
+ export declare function writePlanDb(cycle: string, accountId: string | null, items: readonly PlanItem[], events: readonly PlanEvent[]): Promise<boolean>;
53
+ /** 读某个处置项的操作日志(时间正序)。 */
54
+ export declare function readPlanEvents(planId: string): Promise<readonly {
55
+ at: string;
56
+ action: string;
57
+ from_status: string | null;
58
+ to_status: string | null;
59
+ note: string;
60
+ }[]>;
61
+ /**
62
+ * 把**上一个有内容的账期**里没做完的项顺延到本期。
63
+ *
64
+ * 为什么不做成"一次性按钮":计划是待办队列,不是月度快照。11 月标了"待批准"的事,
65
+ * 到 12 月打开页面就该还看见它 —— 否则每换一次账期都要重新加一遍,最后谁也不加。
66
+ *
67
+ * 只在**本期为空**时顺延:本期已经有内容,说明有人已经在它上面干活了,
68
+ * 这时再往里搬旧项会打乱他正在用的清单。顺延会留一条 `carry` 事件。
69
+ *
70
+ * @returns 顺延了几条。
71
+ */
72
+ export declare function carryPlanForward(cycle: string, accountId: string | null): Promise<number>;
73
+ //# sourceMappingURL=plan-db.d.ts.map
@@ -0,0 +1,183 @@
1
+ /**
2
+ * 处置项的**纯类型 + 纯函数**(浏览器与宿主共用)。
3
+ *
4
+ * 为什么单独一个文件:`plan.ts` 要 `node:crypto` / `node:fs`,客户端一旦 import
5
+ * 它的值,打包器就会把 node 内置模块拖进浏览器 bundle。与 `advice.ts` /
6
+ * `advice-types.ts` 同一套拆法(那里也是踩过同一个坑才拆的)。
7
+ *
8
+ * @module @huaweidevtools/landingzone-workbench/cost/plan-types
9
+ */
10
+ import type { ActionClass, FindingKind } from './evidence/types.ts';
11
+ /** 处置项的状态。 */
12
+ export type PlanStatus = 'planned' | 'approved' | 'done' | 'dropped';
13
+ /** 状态人话。 */
14
+ export declare const PLAN_STATUS_LABEL: Readonly<Record<PlanStatus, string>>;
15
+ /** 一笔"预期可省"是怎么来的。 */
16
+ export type ExpectedBasis =
17
+ /** 账单会归零(释放类)。 */
18
+ 'bill'
19
+ /** 按时段假设推算(定时停机)。 */
20
+ | 'assumption'
21
+ /** 按官网价价差比例 × 账单行估算(降配)。 */
22
+ | 'price_ratio'
23
+ /** 算不出来。 */
24
+ | 'unknown';
25
+ /** 加入计划那一刻,一个资源长什么样(核验"真的做了没有"的基线)。 */
26
+ export interface PlanBaselineResource {
27
+ readonly resource_id: string;
28
+ readonly resource_name: string;
29
+ /**
30
+ * 资源归属的账号。
31
+ *
32
+ * 组织视角下同一个分组会横跨多个账号(空闲节点、无标签资源都是按"类"分的),
33
+ * 只记到分组一级就说不清"这一台是谁的"。旧存档没有这两个字段。
34
+ */
35
+ readonly account_id?: string | null;
36
+ readonly account_name?: string | null;
37
+ /** 当时资源清单里的状态(`active` / `stopped`…);拿不到为 null。 */
38
+ readonly status: string | null;
39
+ /** 区域(拼控制台入口用);旧存档没有这个字段。 */
40
+ readonly region?: string | null;
41
+ /** 该资源当时的账期账单行(元);没有为 null。 */
42
+ readonly bill: number | null;
43
+ /** 该资源的价差估算(只有降配类才有)。 */
44
+ readonly saving: number | null;
45
+ }
46
+ /**
47
+ * 计划项的基线。
48
+ *
49
+ * 为什么必须有:只比账单只能证明"钱停了",证明不了"对象没了"。而"删了但盘还在
50
+ * 计费"与"还开着但账单消失了"这两种假象,只有拿**加入计划那一刻**的资源状态去
51
+ * 对比现在的清单才能分开。没有基线也不是不能核验 —— 只是分不清"没做"和
52
+ * "加入之前就已经不在了"。
53
+ */
54
+ export interface PlanBaseline {
55
+ /** 基线取自哪一刻(采集时间)。 */
56
+ readonly at: string;
57
+ readonly resources: readonly PlanBaselineResource[];
58
+ }
59
+ /** 一条处置项。 */
60
+ export interface PlanItem {
61
+ readonly id: string;
62
+ /** 产生它时的账期(**证据账期**,即上一个完整月;不随页面切换变化)。 */
63
+ readonly cycle: string;
64
+ /**
65
+ * 这条计划里的金额(`observed_bill` / 资源账单 / 可省)是按哪个成本口径算的。
66
+ *
67
+ * 缺省 / `UNKNOWN` = 口径切换前的旧条目,金额来源无法证明;页面会标注,
68
+ * 不能当成当前口径的钱。新条目写入当前口径。
69
+ */
70
+ readonly cost_type?: string;
71
+ readonly account_id: string | null;
72
+ readonly group_key: string;
73
+ readonly kind: FindingKind;
74
+ readonly action_class: ActionClass | null;
75
+ readonly title: string;
76
+ readonly resource_ids: readonly string[];
77
+ readonly resource_count: number;
78
+ /** 预期可省(元/月):只有 A 释放 / D 定时有值,其余为 null。 */
79
+ readonly expected_month: number | null;
80
+ readonly expected_basis: ExpectedBasis;
81
+ /** 该组现状月账单(参考值,**不是**可省)。 */
82
+ readonly observed_bill: number | null;
83
+ readonly owner: string | null;
84
+ /** 目标完成日 `YYYY-MM-DD`。 */
85
+ readonly due: string | null;
86
+ readonly status: PlanStatus;
87
+ readonly note: string;
88
+ /** 加入计划那一刻的资源状态(核验"对象在不在"用的基线)。旧存档没有。 */
89
+ readonly baseline?: PlanBaseline | null;
90
+ readonly created_at: string;
91
+ readonly updated_at: string;
92
+ }
93
+ /** 一个口径的处置清单。 */
94
+ export interface PlanFile {
95
+ readonly cycle: string;
96
+ readonly account_id: string | null;
97
+ readonly items: readonly PlanItem[];
98
+ readonly updated_at: string;
99
+ }
100
+ /** 计划汇总:承诺了多少、其中按什么口径。 */
101
+ export interface PlanSummary {
102
+ readonly count: number;
103
+ /** 「可省」合计(A 释放的钱,账单会归零)。 */
104
+ readonly committed_month: number;
105
+ /** 「按时段假设可省」合计(D 定时)。 */
106
+ readonly assumption_month: number;
107
+ readonly by_status: Readonly<Record<PlanStatus, number>>;
108
+ }
109
+ /** 汇总一份清单(可省额按"可省 / 假设"分开,绝不合并成一个数)。 */
110
+ export declare function summarizePlan(items: readonly PlanItem[]): PlanSummary;
111
+ /**
112
+ * 一组资源的金额(纯函数,逐资源增删时共用)。
113
+ *
114
+ * 与 `makePlanItem` / `addPlanItem` 同一套口径:释放 / 定时 / 停机看账单,
115
+ * 降配看价差,其余动作不给"可省"。抽出来是为了"移掉几个资源之后钱还剩多少"
116
+ * 只写一遍 —— 这条算错,页面就会说"剩下的资源还能省整组的钱"。
117
+ */
118
+ export declare function amountsOfResources(actionClass: ActionClass | null, resources: readonly PlanBaselineResource[]): {
119
+ readonly expected: number | null;
120
+ readonly basis: ExpectedBasis;
121
+ readonly bill: number | null;
122
+ };
123
+ /** 缺口与计划的关系("要补上缺口还差多少"的唯一算法)。 */
124
+ export interface GapCoverage {
125
+ /** 年度缺口(推算 − 预算);没预算/没推算是 null。 */
126
+ readonly gap: number | null;
127
+ readonly days_left: number;
128
+ /** 计划里"可省"合计(元/月)。 */
129
+ readonly committed_month: number;
130
+ /** 按剩余天数折算,最多能挽回多少(假设今天生效)。 */
131
+ readonly recoverable: number;
132
+ /** 缺口还剩多少;<= 0 表示覆盖得住。 */
133
+ readonly shortfall: number;
134
+ /** 要覆盖缺口,每月还得再找多少(0 = 当前计划够)。 */
135
+ readonly needed_month: number;
136
+ }
137
+ /**
138
+ * 算"计划能不能补上缺口"。
139
+ *
140
+ * 只算**可省**(`bill` / `price_ratio`),不算"按时段假设" —— 后者是"如果",
141
+ * 拿它去补一个真实的预算缺口,等于用假设兑现承诺。
142
+ *
143
+ * 折算按"计划项今天生效"算:这是上限,实际执行要审批、要窗口、要迁移,
144
+ * 所以结论里永远带上这句话。
145
+ */
146
+ export declare function gapCoverage(input: {
147
+ readonly budget: number | null;
148
+ readonly forecast: number | null;
149
+ readonly committed_month: number;
150
+ readonly now?: Date | undefined;
151
+ }): GapCoverage;
152
+ /** 一个完整月的天数(与账面口径一致的常用值)。 */
153
+ export declare const MONTH_DAYS = 30;
154
+ /**
155
+ * 把「窗口 N 天的金额」折算成**整月口径**(线性外推)。
156
+ *
157
+ * 放在这个纯类型模块里是刻意的:客户端也要用(核验卡的合计),而 `cost/ledger.ts`
158
+ * 是宿主模块(间接 import `node:crypto`)—— 客户端一旦从它引入,整个插件会加载失败:
159
+ * `require("node:crypto") missed the module table`(2026-11-16 实际踩到)。
160
+ */
161
+ export declare function monthly(amount: number, days: number): number;
162
+ /**
163
+ * 一条处置项的「预期减少」(元/月)。
164
+ *
165
+ * 宿主算好了就用宿主的值(释放/停机/有价差的降配都会算好);算不出时(降配没价差、
166
+ * 老版本加入的项)逐资源回退:saving → 估算 → 账单。
167
+ *
168
+ * 放在这里是因为它必须被**同一套规则**用于计划卡、核验卡、报告和测试 —— 分散实现
169
+ * 过一次就出现过"行内有数、合计为 0"(2026-11-16)。
170
+ */
171
+ export declare function itemExpectedOf(item: Pick<PlanItem, 'expected_month' | 'baseline'> & {
172
+ readonly observed_bill?: number | null;
173
+ }, estimateOf: ReadonlyMap<string, {
174
+ readonly value: number;
175
+ }>): number;
176
+ /**
177
+ * 分组键归一:旧存档是 `${layer}:${kind}`,新的是 `kind`。
178
+ *
179
+ * 2026-11-16 改了分组口径,历史建议全部变成"分组已经不在了" —— 所有读键的地方
180
+ * 都必须先过这里,否则看起来像数据被删了。
181
+ */
182
+ export declare function kindOfGroupKey(raw: string): string;
183
+ //# sourceMappingURL=plan-types.d.ts.map
@@ -0,0 +1,63 @@
1
+ import type { FindingsGroup } from './evidence/types.ts';
2
+ import type { PlanFile, PlanItem } from './plan-types.ts';
3
+ export type { ExpectedBasis, PlanFile, PlanItem, PlanStatus, PlanSummary } from './plan-types.ts';
4
+ export { PLAN_STATUS_LABEL, summarizePlan } from './plan-types.ts';
5
+ /** 存档目录(JSON 只在库不可用时才写它)。 */
6
+ export declare function planDir(): string;
7
+ /** 一个口径的清单路径:`plan/all-2026-11.json`。 */
8
+ export declare function planPath(cycle: string, accountId?: string | null): string;
9
+ /**
10
+ * 读一份清单。
11
+ *
12
+ * 顺序:**库 → 旧 JSON(若库是空的,顺手导入一次)→ 空**。
13
+ * 导入只做一次:写进库成功之后,文件就只是历史备份,不再被写。
14
+ */
15
+ export declare function readPlan(cycle: string, accountId?: string | null): Promise<PlanFile>;
16
+ /**
17
+ * 由一条规则分组造一条处置项。
18
+ *
19
+ * 只在这里算金额:`expected_month` 取分组金额,但**只有**语义是"可省"的两类
20
+ * (A 释放 = 账单归零,D 定时 = 时段假设可省)才填;降配/停机填 `observed_bill`
21
+ * 并明确 `expected_basis='unknown'`。
22
+ */
23
+ export declare function makePlanItem(input: {
24
+ readonly group: FindingsGroup;
25
+ readonly cycle: string;
26
+ readonly accountId: string | null;
27
+ readonly title?: string | undefined;
28
+ readonly owner?: string | null | undefined;
29
+ readonly due?: string | null | undefined;
30
+ readonly note?: string | undefined;
31
+ readonly now?: string | undefined;
32
+ /** 只收其中几个资源;缺省 = 整组。 */
33
+ readonly resourceIds?: readonly string[] | undefined;
34
+ }): PlanItem;
35
+ /** 加入一条处置项;同一个分组重复加入就合并资源,不产生两条。 */
36
+ export declare function addPlanItem(cycle: string, accountId: string | null, item: PlanItem): Promise<PlanFile>;
37
+ /** 改状态 / 负责人 / 目标日 / 备注。 */
38
+ export declare function updatePlanItem(cycle: string, accountId: string | null, id: string, patch: {
39
+ readonly status?: PlanItem['status'] | undefined;
40
+ readonly owner?: string | null | undefined;
41
+ readonly due?: string | null | undefined;
42
+ readonly note?: string | undefined;
43
+ }): Promise<PlanFile>;
44
+ /** 删掉一条。 */
45
+ export declare function removePlanItem(cycle: string, accountId: string | null, id: string): Promise<PlanFile>;
46
+ /**
47
+ * 从一条处置项里摘掉几个资源;摘空了就连条目一起删。
48
+ *
49
+ * 为什么金额必须重算:一条计划的钱是**这组资源**账单之和(或价差之和)。
50
+ * 移掉一半却还显示整组的数,等于告诉用户"剩下的还能省那么多"——
51
+ * 这跟页面其它地方"金额必须能追到具体资源"是同一条规矩。
52
+ *
53
+ * 没有逐资源基线(`baseline` 是后加的,旧条目可能没有)时拒绝逐资源移除:
54
+ * 拿不到每个资源各自的账单,就无法诚实地算出剩下的钱。这时只能整条移除。
55
+ */
56
+ export declare function removePlanResources(cycle: string, accountId: string | null, id: string, resourceIds: readonly string[]): Promise<{
57
+ ok: true;
58
+ plan: PlanFile;
59
+ } | {
60
+ ok: false;
61
+ error: string;
62
+ }>;
63
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 官网询价(买之前问价):按规格问"未来一个月要花多少"。
3
+ *
4
+ * 这条路的意义:**没有账单的资源**(新建、还没出账)不能靠账单,只能问价。
5
+ * 参数是踩过坑之后才对的(见 doc/COST-QUOTE.md):
6
+ * · 云硬盘的 `cloud_service_type` 是 `hws.service.type.ebs`(不是 ec2)
7
+ * · 线性产品(volume / bandwidth)必须带 `resource_size` + `size_measure_id`(17=GB、15=Mbps)
8
+ * · `resource_spec` 必须是目录里的真代号(`SAS` / `GPSSD` / `SSD`),不能自己拼
9
+ *
10
+ * 已实测(cn-north-4,20GB、744h/月):
11
+ * SAS ¥7.2912 · GPSSD ¥14.4336 · SSD ¥20.8320
12
+ *
13
+ * @module @huaweidevtools/landingzone-workbench/cost/quote
14
+ */
15
+ import { type BssContext } from './bss.ts';
16
+ /** 一次询价的请求行。 */
17
+ export interface QuoteLine {
18
+ readonly cloud_service_type: string;
19
+ readonly resource_type: string;
20
+ readonly resource_spec: string;
21
+ /** 线性产品的容量(GB / Mbps);非线性不传。 */
22
+ readonly resource_size?: number;
23
+ /** 容量单位:17=GB,15=Mbps。 */
24
+ readonly size_measure_id?: number;
25
+ readonly usage_factor: string;
26
+ readonly usage_value: number;
27
+ readonly usage_measure_id: number;
28
+ readonly region: string;
29
+ readonly subscription_num?: number;
30
+ }
31
+ /** 询价结果(一行)。 */
32
+ export interface QuoteResult {
33
+ readonly ok: boolean;
34
+ readonly amount?: number;
35
+ readonly message?: string;
36
+ }
37
+ /**
38
+ * 批量询价(一次调用可以带多行,接口不分页)。
39
+ *
40
+ * @returns 与输入同序的结果;失败时每行带服务端原话。
41
+ */
42
+ export declare function quoteLines(ctx: BssContext, projectId: string, lines: readonly QuoteLine[]): Promise<readonly QuoteResult[]>;
43
+ /** 云硬盘一个月的官网价(按 744 小时折算)。 */
44
+ export declare function quoteVolumeMonth(ctx: BssContext, projectId: string, region: string, volumeType: string, sizeGb: number): Promise<QuoteResult>;
45
+ //# sourceMappingURL=quote.d.ts.map
@@ -0,0 +1,136 @@
1
+ /**
2
+ * 节省报告:一份**可以被审计**的账,而不是页面截图。
3
+ *
4
+ * 结构分三段,段与段的数字口径不同,绝不合并:
5
+ * 1. 已实现 —— 同一批 resource_id 的账单在两期里少了多少(唯一能进结论的"省了");
6
+ * 2. 泄漏 —— 标了已执行、账单却还在(删了盘还在、只停机没释放、账单转到别的 id);
7
+ * 3. 机会 —— 还没做的,按 A/B/C/D 分开,明确哪些是假设。
8
+ *
9
+ * 为什么先出 `ReportModel` 再出两种渲染:Markdown 与人看的 HTML 必须来自**同一份**
10
+ * 计算,否则两份报告里的数字迟早对不上。渲染层只做排版,不做算术。
11
+ *
12
+ * @module @huaweidevtools/landingzone-workbench/cost/report
13
+ */
14
+ import type { FindingsResult } from './evidence/types.ts';
15
+ import type { LedgerRow, LedgerView } from './ledger.ts';
16
+ import type { PlanItem } from './plan-types.ts';
17
+ import { type CostType } from './types.ts';
18
+ /** 一个待核验的处置项。 */
19
+ export interface PlanVerification {
20
+ readonly item: PlanItem;
21
+ /** 账本里上期有钱、本期为 0 的资源 —— 这才是"省到了"。 */
22
+ readonly realized: readonly LedgerRow[];
23
+ /**
24
+ * 本期仍在计费的资源。
25
+ *
26
+ * 注意它**不等于泄漏**:状态还是"待批准/已批准"时,资源照常计费是当然的。
27
+ * 只有标了「已执行」却还在计费,才是泄漏。
28
+ */
29
+ readonly stillBilling: readonly LedgerRow[];
30
+ /** 标了已执行、账单仍在 —— 报告第 3 节里与"已实现"并排出现的那一类。 */
31
+ readonly leak: boolean;
32
+ /** 账本里两期都找不到的资源(从没计费过,或账期太早)。 */
33
+ readonly unverifiable: readonly string[];
34
+ }
35
+ /** 报告的一段。 */
36
+ export interface ReportSection {
37
+ readonly title: string;
38
+ readonly paragraphs?: readonly string[];
39
+ readonly bullets?: readonly string[];
40
+ readonly table?: {
41
+ readonly columns: readonly string[];
42
+ readonly rows: readonly (readonly string[])[];
43
+ };
44
+ /** 附录类段落:页面默认折叠(打印与 Markdown 仍然展开)。 */
45
+ readonly collapsible?: boolean;
46
+ }
47
+ /** 报告顶部的四颗指标 —— 先给答案,再给过程。 */
48
+ export interface ReportKpi {
49
+ /** 已实现(元,同口径天数)。 */
50
+ readonly realized_money: number;
51
+ /** 已实现涉及资源数。 */
52
+ readonly realized_count: number;
53
+ /** 已确认待执行(元/月):计划里"可省"那一部分。 */
54
+ /** 待执行 = 计划承诺(账单口径)+ 估算。 */
55
+ readonly committed_money: number;
56
+ /** 其中估算那部分(元/月)。 */
57
+ readonly committed_estimate_money: number;
58
+ readonly committed_count: number;
59
+ /** 估算补充(元/月):计划里没有账单行的资源,用官网询价/反推得到的值。 */
60
+ readonly estimated_money: number;
61
+ readonly estimated_count: number;
62
+ /** 没兑现:标了已执行但仍在计费(元,同口径天数)。 */
63
+ readonly leaking_money: number;
64
+ readonly leaking_count: number;
65
+ /** 预算缺口(元);没预算或没推算是 null。 */
66
+ readonly gap: number | null;
67
+ /** 计划能覆盖缺口的比例(0–1);没有缺口是 null。 */
68
+ readonly coverage_ratio: number | null;
69
+ readonly days_left: number;
70
+ }
71
+ /** 报告模型(渲染层的唯一输入)。 */
72
+ export interface ReportModel {
73
+ readonly title: string;
74
+ readonly subtitle: string;
75
+ readonly kpi: ReportKpi;
76
+ readonly sections: readonly ReportSection[];
77
+ }
78
+ /** 生成报告需要的全部输入。 */
79
+ export interface ReportInput {
80
+ readonly cycle: string;
81
+ readonly accountId: string | null;
82
+ readonly accountName: string | null;
83
+ /**
84
+ * 作用域说明的显式文案。
85
+ *
86
+ * 为什么要它:`accountName` 靠组织接口翻译,子账号往往查不到自己的账号名 —— 那种
87
+ * 情况下副标题会回落成"全组织",把一份只含本账号的报告说成组织级报告(2026-11-19
88
+ * 实测这个回落正好发生在成员账号上)。调用方知道自己是谁,就把话说清楚。
89
+ */
90
+ readonly scopeLabel?: string | undefined;
91
+ readonly findings: FindingsResult | null;
92
+ readonly plan: readonly PlanItem[];
93
+ readonly ledger: LedgerView | null;
94
+ /** 预算口径(年度):预算额、年末推算、已用。没有预算就传 null。 */
95
+ readonly budget: {
96
+ readonly amount: number;
97
+ readonly forecast: number | null;
98
+ readonly used: number;
99
+ } | null;
100
+ /** 上一个账期识别出的机会(来自 `cost_opportunity_snapshots`),用于趋势对照。 */
101
+ readonly previous?: {
102
+ readonly cycle: string;
103
+ readonly saving: number;
104
+ readonly schedule: number;
105
+ } | null;
106
+ readonly generatedAt?: string | undefined;
107
+ /**
108
+ * 这份报告的钱按哪个成本口径算。
109
+ *
110
+ * 由调用方(路由)传入而不是在这里读上下文:report.ts 会被客户端引(`verifyPlan`
111
+ * 是纯函数),一旦它 import 了 `caliber.ts`(node:async_hooks),client bundle 就会
112
+ * 带进一个 Node 内置模块。
113
+ */
114
+ readonly costType?: CostType;
115
+ }
116
+ /** 把账本按 resource_id 建索引(同一 id 出现在两个账号里极罕见,取先出现的)。 */
117
+ export declare function indexLedger(ledger: LedgerView | null): ReadonlyMap<string, LedgerRow>;
118
+ /**
119
+ * 核验每一条处置项。
120
+ *
121
+ * 只认真账单:`realized` 要求该资源上期有钱、本期为 0。标了「已执行」但账单没降,
122
+ * 归到 `stillBilling` + `leak`,并且**在报告里与已实现并排出现** —— 只报好消息的
123
+ * 报告没人信第二次。状态还是"待批准"的项不计泄漏(它们本来就还没动)。
124
+ */
125
+ export declare function verifyPlan(plan: readonly PlanItem[], ledger: LedgerView | null): readonly PlanVerification[];
126
+ /**
127
+ * 组装报告模型。
128
+ *
129
+ * @param input 发现 + 处置清单 + 账本 + 预算。
130
+ */
131
+ export declare function buildReportModel(input: ReportInput): ReportModel;
132
+ /** 渲染 Markdown。 */
133
+ export declare function renderMarkdown(model: ReportModel): string;
134
+ /** 渲染独立 HTML(打印即 PDF,不引第三方生成器)。 */
135
+ export declare function renderHtml(model: ReportModel): string;
136
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1,108 @@
1
+ /**
2
+ * 资源明细(子账号视角的"细"层)。
3
+ *
4
+ * 为什么子账号要看资源:主账号视角回答"哪个账号/哪个服务花了多少",那是**粗**的;
5
+ * 子账号的管理者真正能动手的对象是**具体资源**(这台 ECS、这个 ELB、这条 VPN)。
6
+ * 所以子账号页要有资源级清单,而不是把主账号那套再缩小一遍。
7
+ *
8
+ * 但资源级不是永远有数:RESOURCE_ID 维度只覆盖按资源出账的部分,而且有些账号的
9
+ * 资源维度返回空。所以这张卡还提供第二种维度 —— **企业项目**
10
+ * (`ENTERPRISE_PROJECT_ID`),它是官网"成本分析"里子账号最常用的切法,也更容易
11
+ * 对上财务/项目归属。
12
+ *
13
+ * 数据来源:ListCosts 的 `RESOURCE_ID` / `ENTERPRISE_PROJECT_ID` 维度,配合
14
+ * `ASSOCIATED_ACCOUNT` 过滤。资源维度的值是四段拼起来的:
15
+ * `服务码:资源类型码:资源ID:资源名称`,名称可能缺失。
16
+ *
17
+ * @module @huaweidevtools/landingzone-workbench/cost/resources
18
+ */
19
+ import { type BssContext } from './bss.ts';
20
+ import { type CostCapability, type TrendGranularity } from './types.ts';
21
+ /** 一行资源。 */
22
+ export interface ResourceRow {
23
+ readonly service_code: string;
24
+ readonly resource_type_code: string;
25
+ readonly resource_id: string;
26
+ readonly resource_name: string | null;
27
+ readonly amount: number;
28
+ readonly ratio: number;
29
+ }
30
+ /** 资源明细视图。 */
31
+ export interface ResourcesView {
32
+ readonly dimension: 'resource';
33
+ readonly cycle: string;
34
+ readonly account_id: string;
35
+ readonly total: number;
36
+ readonly resource_count: number;
37
+ readonly rows: readonly ResourceRow[];
38
+ /** 未列出的资源合计。 */
39
+ readonly other_amount: number;
40
+ readonly currency: string;
41
+ /** 统计窗口(跟随页面粒度),卡片右上角直接展示。 */
42
+ readonly window_label: string;
43
+ }
44
+ /** 一行企业项目。 */
45
+ export interface ProjectRow {
46
+ readonly project_id: string;
47
+ readonly project_name: string;
48
+ readonly amount: number;
49
+ readonly ratio: number;
50
+ }
51
+ /** 按企业项目的成本构成。 */
52
+ export interface ProjectsView {
53
+ readonly dimension: 'enterprise_project';
54
+ readonly cycle: string;
55
+ readonly account_id: string;
56
+ readonly total: number;
57
+ readonly project_count: number;
58
+ readonly rows: readonly ProjectRow[];
59
+ /** 未列出的项目合计。 */
60
+ readonly other_amount: number;
61
+ readonly currency: string;
62
+ /** 统计窗口(跟随页面粒度),卡片右上角直接展示。 */
63
+ readonly window_label: string;
64
+ }
65
+ /** 这张卡的两种切法(路由用 `dimension=project` 表达后者)。 */
66
+ export type CostBreakdownView = ResourcesView | ProjectsView;
67
+ /** 企业项目默认桶:`'0'` = 未指定企业项目。 */
68
+ export declare const DEFAULT_PROJECT_ID = "0";
69
+ /** 资源值分段。 */
70
+ export declare function parseResourceValue(value: string): {
71
+ serviceCode: string;
72
+ resourceTypeCode: string;
73
+ resourceId: string;
74
+ resourceName: string | null;
75
+ };
76
+ /** 把服务码转成短标签(`hws.service.type.ec2` → `EC2`)。 */
77
+ declare function serviceTag(code: string): string;
78
+ /**
79
+ * 取一个账号的成本构成(按金额降序)。
80
+ *
81
+ * 两种维度:
82
+ * · `resource` —— ListCosts 的 `RESOURCE_ID`,能落到"哪台机器在花钱";
83
+ * · `enterprise_project` —— `ENTERPRISE_PROJECT_ID`,子账号更常用的切法,
84
+ * 资源维度没数时它通常仍有数(官网成本分析里也是这么看的)。
85
+ *
86
+ * 窗口跟随页面粒度(2026-11-25 用户反馈:切到子账号后这张卡一直写"账期全月")。
87
+ * · 日 / 周 / 月:一次查询就能覆盖;
88
+ * · 年:资源维度单次最多 6 个月(接口报 `max months for resource dimension: 6`),
89
+ * 按半年切片再合并;企业项目维度一次查全年。
90
+ *
91
+ * 分页:`limit` 上限 1000 个分组(一台资源/一个项目一组),按 `total_count` 翻页。
92
+ *
93
+ * @param topN 只返回前 N 行,其余合并进 `other_amount`(两个维度都要对得上合计)。
94
+ * @param projectNames 企业项目 id → 名称(由调用方从本地 EPS 表查;缺失回落短 ID)。
95
+ * @param granularity 页面粒度;缺省按整月(兼容旧调用)。
96
+ * @param anchor 这批数据里最后有数据的那一天;日/周/年窗口用它当锚点。
97
+ */
98
+ export declare function computeResources(ctx: BssContext, cycle: string, accountId: string, topN?: number, dimension?: 'resource' | 'enterprise_project', projectNames?: ReadonlyMap<string, string>, granularity?: TrendGranularity, anchor?: string | null): Promise<{
99
+ readonly ok: true;
100
+ readonly view: CostBreakdownView;
101
+ readonly dataAsOf: string;
102
+ readonly source: 'live';
103
+ } | {
104
+ readonly ok: false;
105
+ readonly capability: CostCapability;
106
+ }>;
107
+ export { serviceTag as resourceServiceTag };
108
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1,38 @@
1
+ import { type WebServerLike } from '../http.ts';
2
+ /** 路由需要的外围依赖。 */
3
+ export interface CostRoutesDeps {
4
+ readonly webServer: WebServerLike;
5
+ /** 写操作完成后通知客户端(复用工作台自带的 SseBus)。 */
6
+ readonly broadcast: (event: {
7
+ tool: string;
8
+ phase?: string;
9
+ planDir?: string;
10
+ }) => void;
11
+ readonly logger: {
12
+ info: (message: string) => void;
13
+ warn: (message: string) => void;
14
+ };
15
+ /**
16
+ * 跑一次"成本建议"(后台一次性子代理)。返回结构化结果或错误。
17
+ *
18
+ * 放在 deps 里而不是直接 import:子代理需要 host 的 agents/subagents 服务,
19
+ * 只有 index.ts 拿得到;路由层只管拼 prompt、存档、通知。
20
+ */
21
+ readonly runAdvice?: (input: {
22
+ readonly prompt: string;
23
+ readonly outputSchema: object;
24
+ readonly label: string;
25
+ }) => Promise<{
26
+ readonly ok: boolean;
27
+ readonly structured?: unknown;
28
+ readonly text?: string;
29
+ readonly error?: string;
30
+ }>;
31
+ }
32
+ /**
33
+ * 注册全部费用路由。
34
+ * @param deps webServer + broadcast + logger。
35
+ * @returns 注销函数列表(调用方放进 ctx.effect)。
36
+ */
37
+ export declare function registerCostRoutes(deps: CostRoutesDeps): (() => void)[];
38
+ //# sourceMappingURL=routes.d.ts.map