@arcticdata/dsh-datarc-assistant 26.39.0 → 26.39.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 (149) hide show
  1. package/README.md +45 -10
  2. package/api-operations.js +404 -0
  3. package/client.js +452 -87
  4. package/cordis.patch.yml +4 -4
  5. package/entry/SKILL.md +34 -0
  6. package/icon.png +0 -0
  7. package/index.js +35 -47
  8. package/locale/en.json +6 -6
  9. package/locale/zh.json +6 -6
  10. package/native-api.mjs +326 -0
  11. package/native-contracts.js +195 -0
  12. package/native-execution.js +184 -0
  13. package/native-runner.mjs +107 -0
  14. package/native-state.js +67 -0
  15. package/native-tools.js +241 -0
  16. package/operations.js +1260 -0
  17. package/package.json +65 -51
  18. package/{skills → runtime}/datarc-access-permissions/SKILL.md +30 -30
  19. package/{skills → runtime}/datarc-access-permissions/references/api.md +31 -31
  20. package/{skills → runtime}/datarc-access-permissions/references/write-order.md +16 -16
  21. package/{skills → runtime}/datarc-analysis-report/SKILL.md +125 -125
  22. package/{skills → runtime}/datarc-analysis-report/agents/openai.yaml +6 -6
  23. package/{skills → runtime}/datarc-analysis-report/references/analyst-frameworks.md +215 -215
  24. package/{skills → runtime}/datarc-analysis-report/references/api-contracts.md +478 -478
  25. package/{skills → runtime}/datarc-analysis-report/references/direct-card-fallback-design.md +66 -66
  26. package/{skills → runtime}/datarc-analysis-report/references/human-in-the-loop.md +142 -142
  27. package/{skills → runtime}/datarc-analysis-report/references/loop-personalization-policy.md +138 -138
  28. package/{skills → runtime}/datarc-analysis-report/references/manifest-example.json +779 -779
  29. package/{skills → runtime}/datarc-analysis-report/references/narrative-schema.md +160 -160
  30. package/{skills → runtime}/datarc-analysis-report/references/question-syntax.md +151 -151
  31. package/{skills → runtime}/datarc-analysis-report/scripts/run_analysis_report.py +2225 -2225
  32. package/{skills → runtime}/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -1914
  33. package/{skills → runtime}/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -5295
  34. package/{skills → runtime}/datarc-data-search/SKILL.md +243 -243
  35. package/{skills → runtime}/datarc-data-search/scripts/calculate.py +116 -116
  36. package/{skills → runtime}/datarc-data-search/scripts/data-search.mjs +628 -628
  37. package/{skills/datarc-dataseek-search → runtime/datarc-data-search}/scripts/datarc-client.mjs +464 -464
  38. package/{skills → runtime}/datarc-data-search/scripts/search-result.mjs +211 -211
  39. package/{skills → runtime}/datarc-dataseek-batch-evaluation/SKILL.md +59 -59
  40. package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -36
  41. package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -30
  42. package/{skills/datarc-data-search → runtime/datarc-dataseek-batch-evaluation}/scripts/datarc-client.mjs +464 -464
  43. package/{skills → runtime}/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -1020
  44. package/{skills → runtime}/datarc-dataseek-search/SKILL.md +96 -96
  45. package/{skills/datarc-dataseek-batch-evaluation → runtime/datarc-dataseek-search}/scripts/datarc-client.mjs +464 -464
  46. package/{skills → runtime}/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -257
  47. package/{skills → runtime}/datarc-dataseek-semantic-debugging/SKILL.md +44 -44
  48. package/{skills → runtime}/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -4
  49. package/{skills → runtime}/datarc-dataseek-semantic-debugging/evals/evals.json +165 -165
  50. package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/dataset.md +77 -77
  51. package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -93
  52. package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/interventions.md +64 -64
  53. package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -47
  54. package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/rollback.md +11 -11
  55. package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -95
  56. package/{skills → runtime}/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -29
  57. package/{skills → runtime}/datarc-dataseek-testset-generation/SKILL.md +47 -47
  58. package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -464
  59. package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -526
  60. package/{skills → runtime}/datarc-datasource/SKILL.md +97 -97
  61. package/{skills → runtime}/datarc-oauth/SKILL.md +50 -50
  62. package/{skills → runtime}/datarc-oauth/scripts/auth.mjs +192 -192
  63. package/{skills → runtime}/datarc-oauth/scripts/credentials.mjs +237 -237
  64. package/{skills → runtime}/datarc-report-add-card/SKILL.md +90 -90
  65. package/{skills → runtime}/datarc-report-add-card/agents/openai.yaml +4 -4
  66. package/runtime/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
  67. package/{skills → runtime}/datarc-report-add-card/scripts/report-card.mjs +439 -439
  68. package/{skills → runtime}/datarc-semantic-alias/SKILL.md +20 -20
  69. package/{skills → runtime}/datarc-semantic-alias/scripts/alias-plan.mjs +422 -422
  70. package/{skills → runtime}/datarc-semantic-alias/scripts/alias.mjs +11 -11
  71. package/{skills → runtime}/datarc-semantic-calibration/SKILL.md +20 -20
  72. package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -683
  73. package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration.mjs +11 -11
  74. package/{skills → runtime}/datarc-semantic-core/SKILL.md +12 -12
  75. package/{skills → runtime}/datarc-semantic-core/scripts/artifact-journal.mjs +853 -830
  76. package/{skills → runtime}/datarc-semantic-core/scripts/canonical.mjs +48 -48
  77. package/{skills → runtime}/datarc-semantic-core/scripts/case-model.mjs +608 -608
  78. package/{skills → runtime}/datarc-semantic-core/scripts/cli.mjs +180 -180
  79. package/{skills → runtime}/datarc-semantic-core/scripts/datarc-client.mjs +180 -180
  80. package/{skills → runtime}/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -57
  81. package/{skills → runtime}/datarc-semantic-core/scripts/interventions.mjs +693 -693
  82. package/{skills → runtime}/datarc-semantic-core/scripts/live-resolution.mjs +305 -305
  83. package/{skills → runtime}/datarc-semantic-core/scripts/model-scope.mjs +49 -49
  84. package/{skills → runtime}/datarc-semantic-core/scripts/reproduction.mjs +330 -330
  85. package/{skills → runtime}/datarc-semantic-core/scripts/semantic-cli.mjs +799 -740
  86. package/{skills → runtime}/datarc-semantic-core/scripts/shared.mjs +312 -312
  87. package/{skills → runtime}/datarc-semantic-core/scripts/verification.mjs +1111 -1014
  88. package/{skills → runtime}/datarc-semantic-dataset/SKILL.md +20 -20
  89. package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -749
  90. package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -813
  91. package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset.mjs +11 -11
  92. package/{skills → runtime}/datarc-semantic-knowledge/SKILL.md +38 -38
  93. package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -61
  94. package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-generation.json +16 -16
  95. package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -347
  96. package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -848
  97. package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -31
  98. package/{skills → runtime}/datarc-semantic-prompt/SKILL.md +20 -20
  99. package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt-plan.mjs +598 -447
  100. package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt.mjs +15 -15
  101. package/{skills → runtime}/datarc-semantic-synonym/SKILL.md +20 -20
  102. package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -688
  103. package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym.mjs +11 -11
  104. package/{skills → runtime}/datarc-viz-analysis-report/SKILL.md +108 -108
  105. package/{skills → runtime}/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -8
  106. package/{skills → runtime}/datarc-viz-analysis-report/assets/echarts.min.js +45 -45
  107. package/{skills → runtime}/datarc-viz-analysis-report/references/api-contracts.md +163 -163
  108. package/{skills → runtime}/datarc-viz-analysis-report/references/derivation-log.md +157 -157
  109. package/{skills → runtime}/datarc-viz-analysis-report/references/evidence-framework.md +76 -76
  110. package/{skills → runtime}/datarc-viz-analysis-report/references/html-template.md +92 -92
  111. package/{skills → runtime}/datarc-viz-analysis-report/references/provenance-format.md +56 -56
  112. package/{skills → runtime}/datarc-viz-analysis-report/references/question-syntax.md +151 -151
  113. package/{skills → runtime}/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -1708
  114. package/{skills → runtime}/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -964
  115. package/{skills → runtime}/datarc-workspace-configuration/SKILL.md +59 -59
  116. package/{skills → runtime}/datarc-workspace-configuration/references/artifacts.md +75 -75
  117. package/{skills → runtime}/datarc-workspace-configuration/references/verification.md +20 -20
  118. package/{skills → runtime}/datarc-workspace-configuration/scripts/configuration.mjs +722 -662
  119. package/{skills → runtime}/datarc-workspace-context/SKILL.md +43 -43
  120. package/{skills → runtime}/datarc-workspace-context/agents/openai.yaml +4 -4
  121. package/{skills → runtime}/datarc-workspace-context/scripts/datarc-client.mjs +31 -31
  122. package/{skills → runtime}/datarc-workspace-context/scripts/query-display.mjs +114 -114
  123. package/{skills → runtime}/datarc-workspace-context/scripts/workspace-context.mjs +58 -58
  124. package/{skills → runtime}/datarc-workspace-custom-tables/SKILL.md +89 -89
  125. package/{skills → runtime}/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -165
  126. package/{skills → runtime}/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -601
  127. package/{skills → runtime}/datarc-workspace-keywords/SKILL.md +197 -197
  128. package/{skills → runtime}/datarc-workspace-keywords/agents/openai.yaml +4 -4
  129. package/{skills → runtime}/datarc-workspace-keywords/references/api-fields.md +79 -79
  130. package/{skills → runtime}/datarc-workspace-keywords/references/derived-measures.md +177 -177
  131. package/{skills → runtime}/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -145
  132. package/{skills → runtime}/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -2421
  133. package/{skills → runtime}/datarc-workspace-membership/SKILL.md +29 -29
  134. package/{skills → runtime}/datarc-workspace-membership/references/api.md +19 -19
  135. package/{skills → runtime}/datarc-workspace-modeling/SKILL.md +209 -209
  136. package/{skills → runtime}/datarc-workspace-modeling/agents/openai.yaml +4 -4
  137. package/{skills → runtime}/datarc-workspace-modeling/references/join-preview.md +38 -38
  138. package/{skills → runtime}/datarc-workspace-modeling/references/model-plan.md +300 -300
  139. package/{skills → runtime}/datarc-workspace-modeling/references/model-tags.md +95 -95
  140. package/{skills → runtime}/datarc-workspace-modeling/references/modeling-contract.json +29 -29
  141. package/{skills → runtime}/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -2423
  142. package/{skills → runtime}/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -137
  143. package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -238
  144. package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -1261
  145. package/skills-provider.js +51 -0
  146. package/workflow-index.json +434 -0
  147. package/icon.svg +0 -4
  148. package/skills/datarc-report-add-card/scripts/datarc-client.mjs +0 -464
  149. package/skills-index.json +0 -194
@@ -1,89 +1,89 @@
1
- ---
2
- name: datarc-workspace-custom-tables
3
- description: 在北极九章(datarc)工作区创建和维护 SQL 自定义表,支持试跑 SQL、查看字段与样例、修改 SQL、改名及模型引用影响检查。用于准备可复用的查询来源;不创建数据库物理表,不写入业务数据。
4
- ---
5
-
6
- # Datarc 自定义表配置
7
-
8
- 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
-
10
- 用 `scripts/workspace-custom-tables.mjs` 调用平台已有接口。输入 SQL 为明文,脚本负责编码、试跑、保存和回读验证。需要 Node.js 18+。
11
-
12
- ## 前置与范围
13
-
14
- - 按 `datarc-oauth` 配置 `DATARC_ENDPOINT`、`DATARC_TOKEN`;令牌仅来自运行环境,不写入输入文件或命令参数。
15
- - 使用明确的整数工作区 ID。尚未明确时按上述名称选择流程定位,由技能内部解析 ID。要求工作区管理员或负责人权限,数据源须支持自定义表。
16
- - 本技能管理平台内的 SQL 自定义表;模型字段绑定与关联继续使用 `datarc-workspace-modeling`。不提供删除、配置备份、自动回滚、数据库物理建表或业务数据写入。
17
- - 明确来源表、字段、筛选、聚合及去重口径。业务规则不明时先询问;SQL 和多表关联等复杂变更先向用户展示简短方案与影响,确认后执行。样例数据不能证明关联键全局唯一。
18
-
19
- ## 查看与定位
20
-
21
- ```bash
22
- node scripts/workspace-custom-tables.mjs --help
23
- node scripts/workspace-custom-tables.mjs list --workspace-id 12 --query 销售 --offset 0 --limit 50
24
- node scripts/workspace-custom-tables.mjs get --workspace-id 12 --table-uid <uid>
25
- node scripts/workspace-custom-tables.mjs columns --workspace-id 12 --table-uid <uid>
26
- node scripts/workspace-custom-tables.mjs preview --workspace-id 12 --table-uid <uid>
27
- node scripts/workspace-custom-tables.mjs column-preview --workspace-id 12 --table-uid <uid> --column customer_id
28
- ```
29
-
30
- `list` 是分页模糊搜索,多个结果时让用户选择,不取首个。`get` 返回已解码的 `editable.sql`、引用影响和 `fingerprint`;引用包含尚未 ready 或已禁用模型及草稿,不能只看平台表列表中的有效模型摘要。`columns` 单独读取只标记 `verified:false`,不能用旧字段证明新 SQL 生效。
31
-
32
- ## 创建
33
-
34
- 输入文件示例:
35
-
36
- ```json
37
- {
38
- "tableName": "销售汇总",
39
- "sql": "SELECT customer_id, SUM(amount) AS amount FROM sales GROUP BY customer_id"
40
- }
41
- ```
42
-
43
- 示例仅说明格式,真实表名和业务口径必须先确认。输入文件只允许 `tableName`、`sql`;不要从服务响应复制额外字段。
44
-
45
- ```bash
46
- node scripts/workspace-custom-tables.mjs create --workspace-id 12 --input table.json --dry-run
47
- node scripts/workspace-custom-tables.mjs create --workspace-id 12 --input table.json
48
- ```
49
-
50
- `--dry-run` 只读取现状、检查名称并生成计划,不保存或试跑 SQL。实际创建自动先执行与网页相同的 SQL 试跑任务,失败则不保存。可单独用 `validate --input query.json` 试跑 `{ "sql": "..." }`;试跑会执行只读查询并产生查询任务,不改变自定义表配置。
51
-
52
- ## 修改 SQL 与改名
53
-
54
- 更新文件只允许 `{ "sql": "..." }`,改名文件只允许 `{ "tableName": "..." }`。两者为独立操作,不把部分成功描述为全部完成。
55
-
56
- ```bash
57
- node scripts/workspace-custom-tables.mjs update --workspace-id 12 --table-uid <uid> --input query.json --dry-run
58
- node scripts/workspace-custom-tables.mjs update --workspace-id 12 --table-uid <uid> --input query.json --if-match <fingerprint>
59
- node scripts/workspace-custom-tables.mjs rename --workspace-id 12 --table-uid <uid> --input name.json --dry-run
60
- node scripts/workspace-custom-tables.mjs rename --workspace-id 12 --table-uid <uid> --input name.json --if-match <fingerprint>
61
- ```
62
-
63
- 使用本次 dry-run 返回的指纹;目标或引用变化后重新读取并核对方案。存在引用时,先展示受影响模型、维度表和草稿;用户明确接受影响后追加 `--allow-referenced`。检查字段删除、改名和类型变化是否破坏现有绑定,不能因为有该参数就忽略业务影响。
64
-
65
- 改名只验证名称保存,不宣称 SQL 或模型已通过验证。修改 SQL 会重新试跑,再次检查目标和引用,保存后等待字段名称、顺序及类型与试跑一致,并执行表数据预览。
66
-
67
- ## 验证与交给建模
68
-
69
- ```bash
70
- node scripts/workspace-custom-tables.mjs verify --workspace-id 12 --table-uid <uid>
71
- ```
72
-
73
- 只有 `verified:true` 才把返回的 `modelSource.tableUid` 交给建模技能。模型事实来源使用 `tableUid`,不同时提供 `table` 或 `sql`;新维度表使用 `definition.tableUid`。字段绑定、关联、模型 ready 和业务搜索验收仍由建模与数据搜索技能完成。
74
-
75
- 验证意味着当前 SQL 试跑、字段结构与样例查询可用,不意味着整个模型已同步、业务口径正确或历史后台任务全部结束。旧服务没有字段解析版本号,脚本不提供并发写入锁;避免多人同时编辑同一表,发现漂移即停止。
76
-
77
- 默认整个命令等待最多 5 分钟,`--max-wait-ms` 可调整至最多 30 分钟;`--poll-interval-ms` 默认 2 秒。接口单次最多等 70 秒且受总预算限制。试跑等待异常时尝试取消该查询任务,取消请求不代表数据库立即停止。
78
-
79
- ## 结果与失败处理
80
-
81
- - 输出结构化 JSON;错误返回非零退出码。给用户只展示表名、变更、验证结论、影响及下一步,SQL/样例按实际需要提供,不整段转贴原始响应。
82
- - `saved:true` 但验证失败:配置已经写入,保留表 UID,排查后运行 `verify`;不重复创建,不自动回滚。
83
- - `writeOutcome:unknown`:请求结果不确定,先通过 list/get 核对现状,禁止直接重发写请求。
84
- - 权限不足、数据源不支持、试跑失败、字段未就绪、预览异常和并发变化分别说明;不伪装成功。
85
- - 用户中断进程时已提交操作可能仍在运行,下一次先回读目标,不把进程退出等同于撤销。
86
-
87
- ## 配置方案与验收报告
88
-
89
- 复杂或跨资源配置先使用 [配置方案与验收](../datarc-workspace-configuration/SKILL.md) 生成方案文档,用户确认该版本后执行;配置回读及就绪后按方案真实查询并生成验收报告。保留本技能的专门确认和验证门槛。简单明确修改无需额外长方案;缺少相关技能时说明依赖,不把未执行的验证写成通过。
1
+ ---
2
+ name: datarc-workspace-custom-tables
3
+ description: 在北极九章(datarc)工作区创建和维护 SQL 自定义表,支持试跑 SQL、查看字段与样例、修改 SQL、改名及模型引用影响检查。用于准备可复用的查询来源;不创建数据库物理表,不写入业务数据。
4
+ ---
5
+
6
+ # Datarc 自定义表配置
7
+
8
+ 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
+
10
+ 用 `scripts/workspace-custom-tables.mjs` 调用平台已有接口。输入 SQL 为明文,脚本负责编码、试跑、保存和回读验证。需要 Node.js 18+。
11
+
12
+ ## 前置与范围
13
+
14
+ - 按 `datarc-oauth` 配置 `DATARC_ENDPOINT`、`DATARC_TOKEN`;令牌仅来自运行环境,不写入输入文件或命令参数。
15
+ - 使用明确的整数工作区 ID。尚未明确时按上述名称选择流程定位,由技能内部解析 ID。要求工作区管理员或负责人权限,数据源须支持自定义表。
16
+ - 本技能管理平台内的 SQL 自定义表;模型字段绑定与关联继续使用 `datarc-workspace-modeling`。不提供删除、配置备份、自动回滚、数据库物理建表或业务数据写入。
17
+ - 明确来源表、字段、筛选、聚合及去重口径。业务规则不明时先询问;SQL 和多表关联等复杂变更先向用户展示简短方案与影响,确认后执行。样例数据不能证明关联键全局唯一。
18
+
19
+ ## 查看与定位
20
+
21
+ ```bash
22
+ node scripts/workspace-custom-tables.mjs --help
23
+ node scripts/workspace-custom-tables.mjs list --workspace-id 12 --query 销售 --offset 0 --limit 50
24
+ node scripts/workspace-custom-tables.mjs get --workspace-id 12 --table-uid <uid>
25
+ node scripts/workspace-custom-tables.mjs columns --workspace-id 12 --table-uid <uid>
26
+ node scripts/workspace-custom-tables.mjs preview --workspace-id 12 --table-uid <uid>
27
+ node scripts/workspace-custom-tables.mjs column-preview --workspace-id 12 --table-uid <uid> --column customer_id
28
+ ```
29
+
30
+ `list` 是分页模糊搜索,多个结果时让用户选择,不取首个。`get` 返回已解码的 `editable.sql`、引用影响和 `fingerprint`;引用包含尚未 ready 或已禁用模型及草稿,不能只看平台表列表中的有效模型摘要。`columns` 单独读取只标记 `verified:false`,不能用旧字段证明新 SQL 生效。
31
+
32
+ ## 创建
33
+
34
+ 输入文件示例:
35
+
36
+ ```json
37
+ {
38
+ "tableName": "销售汇总",
39
+ "sql": "SELECT customer_id, SUM(amount) AS amount FROM sales GROUP BY customer_id"
40
+ }
41
+ ```
42
+
43
+ 示例仅说明格式,真实表名和业务口径必须先确认。输入文件只允许 `tableName`、`sql`;不要从服务响应复制额外字段。
44
+
45
+ ```bash
46
+ node scripts/workspace-custom-tables.mjs create --workspace-id 12 --input table.json --dry-run
47
+ node scripts/workspace-custom-tables.mjs create --workspace-id 12 --input table.json
48
+ ```
49
+
50
+ `--dry-run` 只读取现状、检查名称并生成计划,不保存或试跑 SQL。实际创建自动先执行与网页相同的 SQL 试跑任务,失败则不保存。可单独用 `validate --input query.json` 试跑 `{ "sql": "..." }`;试跑会执行只读查询并产生查询任务,不改变自定义表配置。
51
+
52
+ ## 修改 SQL 与改名
53
+
54
+ 更新文件只允许 `{ "sql": "..." }`,改名文件只允许 `{ "tableName": "..." }`。两者为独立操作,不把部分成功描述为全部完成。
55
+
56
+ ```bash
57
+ node scripts/workspace-custom-tables.mjs update --workspace-id 12 --table-uid <uid> --input query.json --dry-run
58
+ node scripts/workspace-custom-tables.mjs update --workspace-id 12 --table-uid <uid> --input query.json --if-match <fingerprint>
59
+ node scripts/workspace-custom-tables.mjs rename --workspace-id 12 --table-uid <uid> --input name.json --dry-run
60
+ node scripts/workspace-custom-tables.mjs rename --workspace-id 12 --table-uid <uid> --input name.json --if-match <fingerprint>
61
+ ```
62
+
63
+ 使用本次 dry-run 返回的指纹;目标或引用变化后重新读取并核对方案。存在引用时,先展示受影响模型、维度表和草稿;用户明确接受影响后追加 `--allow-referenced`。检查字段删除、改名和类型变化是否破坏现有绑定,不能因为有该参数就忽略业务影响。
64
+
65
+ 改名只验证名称保存,不宣称 SQL 或模型已通过验证。修改 SQL 会重新试跑,再次检查目标和引用,保存后等待字段名称、顺序及类型与试跑一致,并执行表数据预览。
66
+
67
+ ## 验证与交给建模
68
+
69
+ ```bash
70
+ node scripts/workspace-custom-tables.mjs verify --workspace-id 12 --table-uid <uid>
71
+ ```
72
+
73
+ 只有 `verified:true` 才把返回的 `modelSource.tableUid` 交给建模技能。模型事实来源使用 `tableUid`,不同时提供 `table` 或 `sql`;新维度表使用 `definition.tableUid`。字段绑定、关联、模型 ready 和业务搜索验收仍由建模与数据搜索技能完成。
74
+
75
+ 验证意味着当前 SQL 试跑、字段结构与样例查询可用,不意味着整个模型已同步、业务口径正确或历史后台任务全部结束。旧服务没有字段解析版本号,脚本不提供并发写入锁;避免多人同时编辑同一表,发现漂移即停止。
76
+
77
+ 默认整个命令等待最多 5 分钟,`--max-wait-ms` 可调整至最多 30 分钟;`--poll-interval-ms` 默认 2 秒。接口单次最多等 70 秒且受总预算限制。试跑等待异常时尝试取消该查询任务,取消请求不代表数据库立即停止。
78
+
79
+ ## 结果与失败处理
80
+
81
+ - 输出结构化 JSON;错误返回非零退出码。给用户只展示表名、变更、验证结论、影响及下一步,SQL/样例按实际需要提供,不整段转贴原始响应。
82
+ - `saved:true` 但验证失败:配置已经写入,保留表 UID,排查后运行 `verify`;不重复创建,不自动回滚。
83
+ - `writeOutcome:unknown`:请求结果不确定,先通过 list/get 核对现状,禁止直接重发写请求。
84
+ - 权限不足、数据源不支持、试跑失败、字段未就绪、预览异常和并发变化分别说明;不伪装成功。
85
+ - 用户中断进程时已提交操作可能仍在运行,下一次先回读目标,不把进程退出等同于撤销。
86
+
87
+ ## 配置方案与验收报告
88
+
89
+ 复杂或跨资源配置先使用 [配置方案与验收](../datarc-workspace-configuration/SKILL.md) 生成方案文档,用户确认该版本后执行;配置回读及就绪后按方案真实查询并生成验收报告。保留本技能的专门确认和验证门槛。简单明确修改无需额外长方案;缺少相关技能时说明依赖,不把未执行的验证写成通过。
@@ -1,165 +1,165 @@
1
- import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
2
- import { readFile } from "node:fs/promises";
3
-
4
- export class DatarcError extends Error {
5
- constructor(message, code = "DATARC_ERROR", details) {
6
- super(message);
7
- this.name = "DatarcError";
8
- this.code = code;
9
- this.details = details;
10
- }
11
- }
12
-
13
- export function parseArgs(argv) {
14
- const result = { _: [] };
15
- for (let index = 0; index < argv.length; index += 1) {
16
- const value = argv[index];
17
- if (!value.startsWith("--")) {
18
- result._.push(value);
19
- continue;
20
- }
21
- const key = value.slice(2);
22
- const next = argv[index + 1];
23
- if (next === undefined || next.startsWith("--")) result[key] = true;
24
- else {
25
- result[key] =
26
- result[key] === undefined ? next : [].concat(result[key], next);
27
- index += 1;
28
- }
29
- }
30
- return result;
31
- }
32
-
33
- export function required(args, key) {
34
- if (args[key] === undefined || args[key] === true || args[key] === "")
35
- throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
36
- return args[key];
37
- }
38
-
39
- export async function readJson(path) {
40
- const text = path === "-" ? await readStdin() : await readFile(path, "utf8");
41
- try {
42
- return JSON.parse(text);
43
- } catch {
44
- throw new DatarcError("输入不是有效 JSON", "INVALID_JSON");
45
- }
46
- }
47
-
48
- export function createClient(options = {}) {
49
- const { endpoint, token } = resolveCredentials(options);
50
- const fetchImpl = options.fetchImpl ?? globalThis.fetch;
51
- if (!endpoint)
52
- throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
53
- if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
54
-
55
- function redact(value) {
56
- return String(value)
57
- .replaceAll(token, "***")
58
- .replace(
59
- /(password|passwd|pwd|token|authorization)\s*[:=]\s*[^\s,;]+/gi,
60
- "$1=***",
61
- )
62
- .replace(/:\/\/[^\s/@]+:[^\s/@]+@/g, "://***@")
63
- .slice(0, 1500);
64
- }
65
-
66
- async function request(
67
- method,
68
- path,
69
- { query, body, timeoutMs = 70000 } = {},
70
- ) {
71
- const url = new URL(`${endpoint}${path}`);
72
- for (const [key, value] of Object.entries(query ?? {}))
73
- for (const item of [].concat(value ?? []))
74
- if (item !== "") url.searchParams.append(key, item);
75
- let response;
76
- let text;
77
- try {
78
- response = await fetchImpl(url, {
79
- method,
80
- redirect: "error",
81
- signal: AbortSignal.timeout(Math.max(1, Math.floor(timeoutMs))),
82
- headers: {
83
- Authorization: token,
84
- ...(body === undefined ? {} : { "Content-Type": "application/json" }),
85
- },
86
- ...(body === undefined ? {} : { body: JSON.stringify(body) }),
87
- });
88
- text = await response.text();
89
- } catch (error) {
90
- throw new DatarcError(
91
- `网络请求失败或超时:${redact(error.message)}`,
92
- "NETWORK_ERROR",
93
- );
94
- }
95
- let payload;
96
- try {
97
- payload = text ? JSON.parse(text) : {};
98
- } catch {
99
- throw new DatarcError(
100
- `服务返回非 JSON(HTTP ${response.status})`,
101
- "INVALID_RESPONSE",
102
- );
103
- }
104
- if (!response.ok || (payload.status && payload.status !== "SUCCESS"))
105
- throw new DatarcError(
106
- redact(payload.message || `请求失败(HTTP ${response.status})`),
107
- apiErrorCode(response.status),
108
- {
109
- httpStatus: response.status,
110
- status: payload.status,
111
- },
112
- );
113
- return payload.data;
114
- }
115
- return { request, redact };
116
- }
117
-
118
- export function encryptSql(value) {
119
- const first = Buffer.from(String(value), "utf8").toString("base64url");
120
- const second = Buffer.from([...first].reverse().join(""), "utf8").toString(
121
- "base64url",
122
- );
123
- return [...second].reverse().join("");
124
- }
125
-
126
- export function decryptSql(value) {
127
- const second = [...String(value)].reverse().join("");
128
- const firstReversed = Buffer.from(second, "base64url").toString("utf8");
129
- const first = [...firstReversed].reverse().join("");
130
- return Buffer.from(first, "base64url").toString("utf8");
131
- }
132
-
133
- export function errorJson(error) {
134
- return {
135
- code: error?.code ?? "UNEXPECTED_ERROR",
136
- message: error?.message ?? String(error),
137
- ...(error?.details === undefined ? {} : { details: error.details }),
138
- };
139
- }
140
-
141
- export async function runCli(main) {
142
- try {
143
- process.stdout.write(
144
- `${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`,
145
- );
146
- } catch (error) {
147
- process.stdout.write(
148
- `${JSON.stringify({ ok: false, error: errorJson(error) }, null, 2)}\n`,
149
- );
150
- process.exitCode = 1;
151
- }
152
- }
153
-
154
- function apiErrorCode(status) {
155
- if (status === 401) return "AUTHENTICATION_FAILED";
156
- if (status === 403) return "PERMISSION_DENIED";
157
- if (status === 429) return "RATE_LIMITED";
158
- return "API_ERROR";
159
- }
160
-
161
- async function readStdin() {
162
- const chunks = [];
163
- for await (const chunk of process.stdin) chunks.push(chunk);
164
- return Buffer.concat(chunks).toString("utf8");
165
- }
1
+ import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ export class DatarcError extends Error {
5
+ constructor(message, code = "DATARC_ERROR", details) {
6
+ super(message);
7
+ this.name = "DatarcError";
8
+ this.code = code;
9
+ this.details = details;
10
+ }
11
+ }
12
+
13
+ export function parseArgs(argv) {
14
+ const result = { _: [] };
15
+ for (let index = 0; index < argv.length; index += 1) {
16
+ const value = argv[index];
17
+ if (!value.startsWith("--")) {
18
+ result._.push(value);
19
+ continue;
20
+ }
21
+ const key = value.slice(2);
22
+ const next = argv[index + 1];
23
+ if (next === undefined || next.startsWith("--")) result[key] = true;
24
+ else {
25
+ result[key] =
26
+ result[key] === undefined ? next : [].concat(result[key], next);
27
+ index += 1;
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+
33
+ export function required(args, key) {
34
+ if (args[key] === undefined || args[key] === true || args[key] === "")
35
+ throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
36
+ return args[key];
37
+ }
38
+
39
+ export async function readJson(path) {
40
+ const text = path === "-" ? await readStdin() : await readFile(path, "utf8");
41
+ try {
42
+ return JSON.parse(text);
43
+ } catch {
44
+ throw new DatarcError("输入不是有效 JSON", "INVALID_JSON");
45
+ }
46
+ }
47
+
48
+ export function createClient(options = {}) {
49
+ const { endpoint, token } = resolveCredentials(options);
50
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
51
+ if (!endpoint)
52
+ throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
53
+ if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
54
+
55
+ function redact(value) {
56
+ return String(value)
57
+ .replaceAll(token, "***")
58
+ .replace(
59
+ /(password|passwd|pwd|token|authorization)\s*[:=]\s*[^\s,;]+/gi,
60
+ "$1=***",
61
+ )
62
+ .replace(/:\/\/[^\s/@]+:[^\s/@]+@/g, "://***@")
63
+ .slice(0, 1500);
64
+ }
65
+
66
+ async function request(
67
+ method,
68
+ path,
69
+ { query, body, timeoutMs = 70000 } = {},
70
+ ) {
71
+ const url = new URL(`${endpoint}${path}`);
72
+ for (const [key, value] of Object.entries(query ?? {}))
73
+ for (const item of [].concat(value ?? []))
74
+ if (item !== "") url.searchParams.append(key, item);
75
+ let response;
76
+ let text;
77
+ try {
78
+ response = await fetchImpl(url, {
79
+ method,
80
+ redirect: "error",
81
+ signal: AbortSignal.timeout(Math.max(1, Math.floor(timeoutMs))),
82
+ headers: {
83
+ Authorization: token,
84
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
85
+ },
86
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
87
+ });
88
+ text = await response.text();
89
+ } catch (error) {
90
+ throw new DatarcError(
91
+ `网络请求失败或超时:${redact(error.message)}`,
92
+ "NETWORK_ERROR",
93
+ );
94
+ }
95
+ let payload;
96
+ try {
97
+ payload = text ? JSON.parse(text) : {};
98
+ } catch {
99
+ throw new DatarcError(
100
+ `服务返回非 JSON(HTTP ${response.status})`,
101
+ "INVALID_RESPONSE",
102
+ );
103
+ }
104
+ if (!response.ok || (payload.status && payload.status !== "SUCCESS"))
105
+ throw new DatarcError(
106
+ redact(payload.message || `请求失败(HTTP ${response.status})`),
107
+ apiErrorCode(response.status),
108
+ {
109
+ httpStatus: response.status,
110
+ status: payload.status,
111
+ },
112
+ );
113
+ return payload.data;
114
+ }
115
+ return { request, redact };
116
+ }
117
+
118
+ export function encryptSql(value) {
119
+ const first = Buffer.from(String(value), "utf8").toString("base64url");
120
+ const second = Buffer.from([...first].reverse().join(""), "utf8").toString(
121
+ "base64url",
122
+ );
123
+ return [...second].reverse().join("");
124
+ }
125
+
126
+ export function decryptSql(value) {
127
+ const second = [...String(value)].reverse().join("");
128
+ const firstReversed = Buffer.from(second, "base64url").toString("utf8");
129
+ const first = [...firstReversed].reverse().join("");
130
+ return Buffer.from(first, "base64url").toString("utf8");
131
+ }
132
+
133
+ export function errorJson(error) {
134
+ return {
135
+ code: error?.code ?? "UNEXPECTED_ERROR",
136
+ message: error?.message ?? String(error),
137
+ ...(error?.details === undefined ? {} : { details: error.details }),
138
+ };
139
+ }
140
+
141
+ export async function runCli(main) {
142
+ try {
143
+ process.stdout.write(
144
+ `${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`,
145
+ );
146
+ } catch (error) {
147
+ process.stdout.write(
148
+ `${JSON.stringify({ ok: false, error: errorJson(error) }, null, 2)}\n`,
149
+ );
150
+ process.exitCode = 1;
151
+ }
152
+ }
153
+
154
+ function apiErrorCode(status) {
155
+ if (status === 401) return "AUTHENTICATION_FAILED";
156
+ if (status === 403) return "PERMISSION_DENIED";
157
+ if (status === 429) return "RATE_LIMITED";
158
+ return "API_ERROR";
159
+ }
160
+
161
+ async function readStdin() {
162
+ const chunks = [];
163
+ for await (const chunk of process.stdin) chunks.push(chunk);
164
+ return Buffer.concat(chunks).toString("utf8");
165
+ }