@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,90 +1,90 @@
1
- ---
2
- name: datarc-report-add-card
3
- description: 将北极九章(datarc)已有查询结果中的一张数据卡保存到可编辑报告,或新建报告后加入并返回链接。用于“把刚才第二张图放进新周报”等明确保存现有结果的请求。
4
- ---
5
-
6
- # Datarc 报告加卡
7
-
8
- 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
-
10
- 把数据搜索或 DataSeek 刚刚产出的数据卡片加入报告。Agent 负责确认用户指的是哪张卡片、组织报告选择与命名交互;`scripts/report-card.mjs` 负责合并推荐、组装请求、添加前后回读验证和构造报告链接。所有命令输出 `{"ok":true,...}` 或 `{"ok":false,"error":{code,message,details}}`,令牌只从环境变量读取,不得出现在参数、日志或回复中。
11
-
12
- ## 前置条件
13
-
14
- 1. 按 [datarc-oauth](../datarc-oauth/SKILL.md) 配置并确认 `DATARC_ENDPOINT` 与 `DATARC_TOKEN`。
15
- 2. Node.js 18+。
16
- 3. 待加入的卡片来自 `datarc-data-search` 或 `datarc-dataseek-search` 的查询结果;本技能不查询数据。
17
- 4. `--project-id` 使用上一步搜索的同一个工作区 id(整数);缺失时先用 datarc-workspace-context 按名称选择,不向用户索要 ID,不得猜测。
18
- 5. 在本技能目录执行 `node scripts/report-card.mjs <命令>`。
19
-
20
- ## 标准流程
21
-
22
- ### 1. 保存待加入的卡片
23
-
24
- 普通问数直接使用选中子问题的 `resultFile` 作为 `--card-file`;DataSeek 会话搜索或旧版普通问数,把上一步搜索命令的完整 stdout JSON 写入临时文件(如 `report-card-input.json`)传给 `--card-file`(支持 `-` 从标准输入读取)。必须保存包含 `answer`(及其 `tokens`)的层级;单独的卡片对象无法还原问题,脚本会报 `CARD_TOKENS_MISSING`。
25
-
26
- 先用本地 `select` 检查待写入对象,尤其在新建报告前完成选卡:
27
-
28
- ```bash
29
- node scripts/report-card.mjs select --card-file report-card-input.json [--result-index <结果序号>] [--card-index <卡片序号>]
30
- ```
31
-
32
- 只有一张候选直接使用;名称或“第二张图”等指代能唯一定位时,按结果内的卡片位置传对应序号(从 0 开始)。多张仍符合时,展示候选问题和标题等用户选择。将选定的两个序号原样传给后续 `add`。
33
-
34
- ### 2. 推荐报告
35
-
36
- ```bash
37
- node scripts/report-card.mjs list --project-id <工作区id> [--q 名称关键词] [--limit 10]
38
- ```
39
-
40
- 脚本合并"最近使用"(30 天内访问,优先)与"可编辑的全部报告"(按更新时间兜底),只保留当前用户可编辑的报告并标注 `recent`。
41
-
42
- 向用户列出前 3 个推荐(最近使用优先)加一个「新建报告」选项。用户要的报告不在选项里时,先用 `--q` 按名称关键词再查;选择新建时用自由文本收集报告名称(1–255 个字符),可顺带询问一句话介绍。
43
-
44
- ### 3a. 加入已有报告
45
-
46
- ```bash
47
- node scripts/report-card.mjs add --project-id <工作区id> --pinboard-uid <报告uid> --card-file report-card-input.json --result-index <已选结果序号> --card-index <已选卡片序号>
48
- ```
49
-
50
- 脚本自动执行:添加前读取报告 → 一次 add-to-pinboards → 添加后回读,并要求恰好新增一张卡片 pin 且签名(tokens、卡片类型、模型、标题)匹配;否则报 `CARD_VERIFY_FAILED`,不会重试添加。序号越界报 `CARD_INDEX_OUT_OF_RANGE`,`details.candidates` 列出全部候选及标题,据此修正参数后重跑读取步骤。
51
-
52
- ### 3b. 新建报告并加入
53
-
54
- ```bash
55
- node scripts/report-card.mjs create --project-id <工作区id> --name "<报告名称>" [--desc "<一句话介绍>"]
56
- node scripts/report-card.mjs add --project-id <工作区id> --pinboard-uid <新报告uid> --card-file report-card-input.json --result-index <已选结果序号> --card-index <已选卡片序号>
57
- ```
58
-
59
- 新报告已创建但加卡未确认时,返回已创建的报告链接,说明卡片状态并先回读核对。
60
-
61
- ### 4. 返回结果
62
-
63
- 成功输出报告 uid、名称、卡片 pin id 与报告链接 `${DATARC_ENDPOINT}/#/pinboard/<报告uid>?projectId=<工作区id>`。向用户报告"已加入《报告名》"、报告链接和卡片标题;新建报告时明确说明已新建。
64
-
65
- ## 错误处理
66
-
67
- - 认证、权限、工作区与服务错误按 [datarc-oauth](../datarc-oauth/SKILL.md) 的错误表处理。
68
- - 本技能特有错误码:
69
-
70
- | code | 含义与处置 |
71
- | ------------------------- | -------------------------------------------------- |
72
- | `CARD_SELECTION_REQUIRED` | 多张卡片符合条件;按候选问题和标题选定后再写入 |
73
- | `CARD_TOKENS_MISSING` | 输入缺少 answer.tokens;改为保存完整搜索结果 JSON |
74
- | `NO_CARDS` | 输入中没有卡片;先执行数据搜索 |
75
- | `CARD_INDEX_OUT_OF_RANGE` | 序号越界;按 details.candidates 修正后重跑 |
76
- | `CARD_VERIFY_FAILED` | 回读未确认恰好新增一张卡;停止并向用户说明,不重试 |
77
- | `INVALID_NAME` | 报告名称必须是 1–255 个字符 |
78
-
79
- - HTTP 403 常见原因是无报告编辑权限或报告数量达到上限;停止写操作并向用户说明,不得改加入其他报告或重试。
80
-
81
- ## 能力边界
82
-
83
- - 可以:把两个搜索技能返回的单张数据卡加入当前用户可编辑的报告;新建私有报告并加入;回读验证;返回报告链接。
84
- - 不可以:查询或生成数据(先用 datarc-data-search 或 datarc-dataseek-search);加入富文本、标题或章节,也不生成多章节分析报告(使用 datarc-analysis-report);移动、排版、删除已有卡片或修改报告布局与分享设置;一次把同一张卡加入多个报告(接口支持,本技能暂未开放)。
85
-
86
- ## 结果呈现
87
-
88
- - 先给结论(已加入《报告名》),再给报告链接和卡片标题;新建报告时明确说明已新建。
89
- - 凭据始终保密。正常回复只展示报告链接和卡片标题;排查选卡时可展示候选问题、标题和序号。
90
- - 验证加入时的报告回读会记为一次访问,该报告因此会排在下次"最近使用"推荐前列;需要时向用户说明即可。
1
+ ---
2
+ name: datarc-report-add-card
3
+ description: 将北极九章(datarc)已有查询结果中的一张数据卡保存到可编辑报告,或新建报告后加入并返回链接。用于“把刚才第二张图放进新周报”等明确保存现有结果的请求。
4
+ ---
5
+
6
+ # Datarc 报告加卡
7
+
8
+ 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
+
10
+ 把数据搜索或 DataSeek 刚刚产出的数据卡片加入报告。Agent 负责确认用户指的是哪张卡片、组织报告选择与命名交互;`scripts/report-card.mjs` 负责合并推荐、组装请求、添加前后回读验证和构造报告链接。所有命令输出 `{"ok":true,...}` 或 `{"ok":false,"error":{code,message,details}}`,令牌只从环境变量读取,不得出现在参数、日志或回复中。
11
+
12
+ ## 前置条件
13
+
14
+ 1. 按 [datarc-oauth](../datarc-oauth/SKILL.md) 配置并确认 `DATARC_ENDPOINT` 与 `DATARC_TOKEN`。
15
+ 2. Node.js 18+。
16
+ 3. 待加入的卡片来自 `datarc-data-search` 或 `datarc-dataseek-search` 的查询结果;本技能不查询数据。
17
+ 4. `--project-id` 使用上一步搜索的同一个工作区 id(整数);缺失时先用 datarc-workspace-context 按名称选择,不向用户索要 ID,不得猜测。
18
+ 5. 在本技能目录执行 `node scripts/report-card.mjs <命令>`。
19
+
20
+ ## 标准流程
21
+
22
+ ### 1. 保存待加入的卡片
23
+
24
+ 普通问数直接使用选中子问题的 `resultFile` 作为 `--card-file`;DataSeek 会话搜索或旧版普通问数,把上一步搜索命令的完整 stdout JSON 写入临时文件(如 `report-card-input.json`)传给 `--card-file`(支持 `-` 从标准输入读取)。必须保存包含 `answer`(及其 `tokens`)的层级;单独的卡片对象无法还原问题,脚本会报 `CARD_TOKENS_MISSING`。
25
+
26
+ 先用本地 `select` 检查待写入对象,尤其在新建报告前完成选卡:
27
+
28
+ ```bash
29
+ node scripts/report-card.mjs select --card-file report-card-input.json [--result-index <结果序号>] [--card-index <卡片序号>]
30
+ ```
31
+
32
+ 只有一张候选直接使用;名称或“第二张图”等指代能唯一定位时,按结果内的卡片位置传对应序号(从 0 开始)。多张仍符合时,展示候选问题和标题等用户选择。将选定的两个序号原样传给后续 `add`。
33
+
34
+ ### 2. 推荐报告
35
+
36
+ ```bash
37
+ node scripts/report-card.mjs list --project-id <工作区id> [--q 名称关键词] [--limit 10]
38
+ ```
39
+
40
+ 脚本合并"最近使用"(30 天内访问,优先)与"可编辑的全部报告"(按更新时间兜底),只保留当前用户可编辑的报告并标注 `recent`。
41
+
42
+ 向用户列出前 3 个推荐(最近使用优先)加一个「新建报告」选项。用户要的报告不在选项里时,先用 `--q` 按名称关键词再查;选择新建时用自由文本收集报告名称(1–255 个字符),可顺带询问一句话介绍。
43
+
44
+ ### 3a. 加入已有报告
45
+
46
+ ```bash
47
+ node scripts/report-card.mjs add --project-id <工作区id> --pinboard-uid <报告uid> --card-file report-card-input.json --result-index <已选结果序号> --card-index <已选卡片序号>
48
+ ```
49
+
50
+ 脚本自动执行:添加前读取报告 → 一次 add-to-pinboards → 添加后回读,并要求恰好新增一张卡片 pin 且签名(tokens、卡片类型、模型、标题)匹配;否则报 `CARD_VERIFY_FAILED`,不会重试添加。序号越界报 `CARD_INDEX_OUT_OF_RANGE`,`details.candidates` 列出全部候选及标题,据此修正参数后重跑读取步骤。
51
+
52
+ ### 3b. 新建报告并加入
53
+
54
+ ```bash
55
+ node scripts/report-card.mjs create --project-id <工作区id> --name "<报告名称>" [--desc "<一句话介绍>"]
56
+ node scripts/report-card.mjs add --project-id <工作区id> --pinboard-uid <新报告uid> --card-file report-card-input.json --result-index <已选结果序号> --card-index <已选卡片序号>
57
+ ```
58
+
59
+ 新报告已创建但加卡未确认时,返回已创建的报告链接,说明卡片状态并先回读核对。
60
+
61
+ ### 4. 返回结果
62
+
63
+ 成功输出报告 uid、名称、卡片 pin id 与报告链接 `${DATARC_ENDPOINT}/#/pinboard/<报告uid>?projectId=<工作区id>`。向用户报告"已加入《报告名》"、报告链接和卡片标题;新建报告时明确说明已新建。
64
+
65
+ ## 错误处理
66
+
67
+ - 认证、权限、工作区与服务错误按 [datarc-oauth](../datarc-oauth/SKILL.md) 的错误表处理。
68
+ - 本技能特有错误码:
69
+
70
+ | code | 含义与处置 |
71
+ | ------------------------- | -------------------------------------------------- |
72
+ | `CARD_SELECTION_REQUIRED` | 多张卡片符合条件;按候选问题和标题选定后再写入 |
73
+ | `CARD_TOKENS_MISSING` | 输入缺少 answer.tokens;改为保存完整搜索结果 JSON |
74
+ | `NO_CARDS` | 输入中没有卡片;先执行数据搜索 |
75
+ | `CARD_INDEX_OUT_OF_RANGE` | 序号越界;按 details.candidates 修正后重跑 |
76
+ | `CARD_VERIFY_FAILED` | 回读未确认恰好新增一张卡;停止并向用户说明,不重试 |
77
+ | `INVALID_NAME` | 报告名称必须是 1–255 个字符 |
78
+
79
+ - HTTP 403 常见原因是无报告编辑权限或报告数量达到上限;停止写操作并向用户说明,不得改加入其他报告或重试。
80
+
81
+ ## 能力边界
82
+
83
+ - 可以:把两个搜索技能返回的单张数据卡加入当前用户可编辑的报告;新建私有报告并加入;回读验证;返回报告链接。
84
+ - 不可以:查询或生成数据(先用 datarc-data-search 或 datarc-dataseek-search);加入富文本、标题或章节,也不生成多章节分析报告(使用 datarc-analysis-report);移动、排版、删除已有卡片或修改报告布局与分享设置;一次把同一张卡加入多个报告(接口支持,本技能暂未开放)。
85
+
86
+ ## 结果呈现
87
+
88
+ - 先给结论(已加入《报告名》),再给报告链接和卡片标题;新建报告时明确说明已新建。
89
+ - 凭据始终保密。正常回复只展示报告链接和卡片标题;排查选卡时可展示候选问题、标题和序号。
90
+ - 验证加入时的报告回读会记为一次访问,该报告因此会排在下次"最近使用"推荐前列;需要时向用户说明即可。
@@ -1,4 +1,4 @@
1
- interface:
2
- display_name: "Datarc 报告加卡"
3
- short_description: "推荐最近使用的报告,把数据搜索或 DataSeek 的结果卡片加入报告,或新建报告后加入"
4
- default_prompt: "使用 $datarc-report-add-card 把刚才查询到的数据卡片加入报告;先推荐我最近使用的报告,也可以新建报告。"
1
+ interface:
2
+ display_name: "Datarc 报告加卡"
3
+ short_description: "推荐最近使用的报告,把数据搜索或 DataSeek 的结果卡片加入报告,或新建报告后加入"
4
+ default_prompt: "使用 $datarc-report-add-card 把刚才查询到的数据卡片加入报告;先推荐我最近使用的报告,也可以新建报告。"
@@ -0,0 +1,464 @@
1
+ import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
2
+ import { createWriteStream } from "node:fs";
3
+ import { mkdir, readFile, rename, rm, stat } from "node:fs/promises";
4
+ import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
5
+ import { Readable } from "node:stream";
6
+ import { pipeline } from "node:stream/promises";
7
+
8
+ export class DatarcError extends Error {
9
+ constructor(message, code = "DATARC_ERROR", details) {
10
+ super(message);
11
+ this.name = "DatarcError";
12
+ this.code = code;
13
+ this.details = details;
14
+ }
15
+ }
16
+
17
+ export function parseArgs(argv) {
18
+ const result = { _: [] };
19
+ for (let i = 0; i < argv.length; i += 1) {
20
+ if (!argv[i].startsWith("--")) {
21
+ result._.push(argv[i]);
22
+ continue;
23
+ }
24
+ const key = argv[i].slice(2);
25
+ const next = argv[i + 1];
26
+ if (next === undefined || next.startsWith("--")) result[key] = true;
27
+ else {
28
+ result[key] =
29
+ result[key] === undefined ? next : [].concat(result[key], next);
30
+ i += 1;
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+
36
+ export function required(args, key) {
37
+ if (args[key] === undefined || args[key] === true || args[key] === "")
38
+ throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
39
+ return args[key];
40
+ }
41
+
42
+ export async function readJson(path) {
43
+ const text = path === "-" ? await stdin() : await readFile(path, "utf8");
44
+ try {
45
+ return JSON.parse(text);
46
+ } catch {
47
+ throw new DatarcError("输入不是有效 JSON", "INVALID_JSON");
48
+ }
49
+ }
50
+
51
+ export function createClient(options = {}) {
52
+ const { endpoint, token } = resolveCredentials(options);
53
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
54
+ const sleep =
55
+ options.sleep ??
56
+ ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
57
+ if (!endpoint)
58
+ throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
59
+ if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
60
+
61
+ async function request(method, path, { query, body } = {}) {
62
+ const url = new URL(`${endpoint}${path}`);
63
+ for (const [key, value] of Object.entries(query ?? {}))
64
+ for (const item of [].concat(value ?? []))
65
+ if (item !== "") url.searchParams.append(key, item);
66
+ let response;
67
+ try {
68
+ response = await fetchImpl(url, {
69
+ method,
70
+ headers: {
71
+ Authorization: token,
72
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
73
+ },
74
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
75
+ });
76
+ } catch (error) {
77
+ throw new DatarcError(`网络请求失败:${error.message}`, "NETWORK_ERROR");
78
+ }
79
+ const text = await response.text();
80
+ let payload;
81
+ try {
82
+ payload = text ? JSON.parse(text) : {};
83
+ } catch {
84
+ throw new DatarcError(
85
+ `服务返回非 JSON(HTTP ${response.status})`,
86
+ "INVALID_RESPONSE",
87
+ );
88
+ }
89
+ if (!response.ok || (payload.status && payload.status !== "SUCCESS"))
90
+ throw new DatarcError(
91
+ payload.message || `请求失败(HTTP ${response.status})`,
92
+ apiErrorCode(response.status, payload),
93
+ {
94
+ httpStatus: response.status,
95
+ status: payload.status,
96
+ errorCode: payload.code ?? payload.errcode,
97
+ },
98
+ );
99
+ return payload.data;
100
+ }
101
+
102
+ async function poll(workspaceId, uid, taskType, options = {}) {
103
+ const started = Date.now();
104
+ const maxWaitMs = Number(options.maxWaitMs ?? 600000);
105
+ const intervalMs = Number(options.intervalMs ?? 2000);
106
+ const pending = taskType === 4 ? [0, 1, 4, 5] : [0, 1];
107
+ while (Date.now() - started <= maxWaitMs) {
108
+ const task = await request(
109
+ "GET",
110
+ `/api/v2/account-projects/${workspaceId}/async-tasks/${uid}/`,
111
+ );
112
+ if (Number(task.status) === 2) {
113
+ const result = task.result;
114
+ if (
115
+ [8, 11].includes(Number(taskType)) &&
116
+ (!result ||
117
+ typeof result !== "object" ||
118
+ result.status !== "SUCCESS" ||
119
+ !Object.hasOwn(result, "data"))
120
+ )
121
+ throw new DatarcError(
122
+ "异步任务成功状态缺少有效结果",
123
+ "INVALID_TASK_RESULT",
124
+ { status: task.status, result: safeTaskResult(result) },
125
+ );
126
+ return result;
127
+ }
128
+ if (!pending.includes(Number(task.status)))
129
+ throw new DatarcError("异步任务失败、取消或过期", "TASK_FAILED", {
130
+ status: task.status,
131
+ result: safeTaskResult(task.result),
132
+ });
133
+ await sleep(intervalMs);
134
+ }
135
+ throw new DatarcError("异步任务轮询超时", "TASK_TIMEOUT");
136
+ }
137
+
138
+ async function download(url, destination) {
139
+ const targetUrl = new URL(url);
140
+ const headers =
141
+ targetUrl.origin === new URL(endpoint).origin
142
+ ? { Authorization: token }
143
+ : {};
144
+ let response;
145
+ try {
146
+ response = await fetchImpl(targetUrl, { headers, redirect: "follow" });
147
+ } catch (error) {
148
+ throw new DatarcError(`下载失败:${error.message}`, "NETWORK_ERROR");
149
+ }
150
+ if (!response.ok || !response.body)
151
+ throw new DatarcError(
152
+ `下载失败(HTTP ${response.status})`,
153
+ apiErrorCode(response.status, {}),
154
+ );
155
+ await mkdir(dirname(destination), { recursive: true });
156
+ const temporary = `${destination}.part`;
157
+ let overwritten = false;
158
+ try {
159
+ await stat(destination);
160
+ overwritten = true;
161
+ } catch (error) {
162
+ if (error.code !== "ENOENT") throw error;
163
+ }
164
+ try {
165
+ await pipeline(
166
+ Readable.fromWeb(response.body),
167
+ createWriteStream(temporary),
168
+ );
169
+ await rm(destination, { force: true });
170
+ await rename(temporary, destination);
171
+ return { size: (await stat(destination)).size, overwritten };
172
+ } catch (error) {
173
+ await rm(temporary, { force: true });
174
+ throw new DatarcError(
175
+ `保存下载文件失败:${error.message}`,
176
+ "DOWNLOAD_FAILED",
177
+ );
178
+ }
179
+ }
180
+ return { request, poll, sleep, download };
181
+ }
182
+
183
+ export function primaryCards(cards = []) {
184
+ if (!Array.isArray(cards)) return [];
185
+ const direct = cards.find(
186
+ (card) => Number(card?.resultType ?? card?.result_type ?? 0) === 0,
187
+ );
188
+ return direct ? [direct] : [];
189
+ }
190
+
191
+ export function seriesOf(cards = []) {
192
+ return cards.flatMap((card, cardIndex) =>
193
+ (card.data ?? []).map((series, seriesIndex) => ({
194
+ cardIndex,
195
+ seriesIndex,
196
+ title: card.title ?? `卡片 ${cardIndex + 1}`,
197
+ cardType: card.card_type,
198
+ columns: series.columns ?? [],
199
+ query: series.data,
200
+ })),
201
+ );
202
+ }
203
+
204
+ export function collectCards(value) {
205
+ const cards = [];
206
+ const seen = new Set();
207
+ function visit(current) {
208
+ if (!current || typeof current !== "object" || seen.has(current)) return;
209
+ seen.add(current);
210
+ if (Array.isArray(current.cards))
211
+ cards.push(...primaryCards(current.cards));
212
+ for (const [key, child] of Object.entries(current)) {
213
+ if (key !== "cards") visit(child);
214
+ }
215
+ }
216
+ visit(value);
217
+ if (!cards.length && Array.isArray(value)) return value;
218
+ return cards;
219
+ }
220
+
221
+ export async function preview(client, workspaceId, cards, options = {}) {
222
+ const output = [];
223
+ const seriesList = seriesOf(cards);
224
+ for (const series of seriesList) {
225
+ try {
226
+ if (!series.query?.qKey)
227
+ throw new DatarcError("卡片缺少 qKey", "MISSING_QKEY");
228
+ const queryWorkspaceId = series.query.project ?? workspaceId;
229
+ const task = await client.request(
230
+ "POST",
231
+ `/api/v2/account-projects/${queryWorkspaceId}/async-tasks/`,
232
+ {
233
+ body: {
234
+ taskType: 8,
235
+ params: {
236
+ qKey: series.query.qKey,
237
+ params: queryPageParams(series.query.params, options),
238
+ },
239
+ },
240
+ },
241
+ );
242
+ output.push({
243
+ ...series,
244
+ data: unwrapTaskResult(
245
+ await client.poll(queryWorkspaceId, task.uid, 8, options),
246
+ ),
247
+ });
248
+ } catch (error) {
249
+ rethrowGlobalError(error);
250
+ output.push({ ...series, error: errorJson(error) });
251
+ }
252
+ }
253
+ return output;
254
+ }
255
+
256
+ export function unwrapTaskResult(value) {
257
+ if (
258
+ value &&
259
+ typeof value === "object" &&
260
+ value.status === "SUCCESS" &&
261
+ Object.hasOwn(value, "data")
262
+ )
263
+ return value.data;
264
+ return value;
265
+ }
266
+
267
+ export async function exportAll(client, workspaceId, cards, options = {}) {
268
+ const extension = String(options.extension ?? ".csv").replace(/^(?!\.)/, ".");
269
+ if (![".csv", ".xlsx"].includes(extension))
270
+ throw new DatarcError("导出格式仅支持 csv 或 xlsx", "INVALID_ARGUMENT");
271
+ const output = [];
272
+ const seriesList = seriesOf(cards);
273
+ for (const series of seriesList) {
274
+ if ([1, 12].includes(Number(series.cardType))) {
275
+ output.push({
276
+ ...series,
277
+ extension,
278
+ status: "skipped",
279
+ reasonCode: "NUMBER_CARD_NOT_EXPORTABLE",
280
+ message: "数字卡不支持导出 CSV 或 Excel",
281
+ });
282
+ continue;
283
+ }
284
+ try {
285
+ if (!series.query?.qKey)
286
+ throw new DatarcError("卡片缺少 qKey", "MISSING_QKEY");
287
+ const title = fileTitle(
288
+ options.title ?? series.title,
289
+ seriesList.length > 1 ? series.seriesIndex + 1 : undefined,
290
+ );
291
+ const task = await client.request(
292
+ "POST",
293
+ `/api/v2/account-projects/${workspaceId}/async-tasks/`,
294
+ {
295
+ body: {
296
+ taskType: 4,
297
+ params: {
298
+ title,
299
+ extension,
300
+ data: [{ data: series.query, columns: series.columns }],
301
+ },
302
+ },
303
+ },
304
+ );
305
+ const exported = {
306
+ ...series,
307
+ exportTitle: title,
308
+ extension,
309
+ data: await client.poll(workspaceId, task.uid, 4, options),
310
+ };
311
+ if (options.download) {
312
+ const url = exported.data?.url;
313
+ if (!url)
314
+ throw new DatarcError("导出结果缺少下载地址", "MISSING_DOWNLOAD_URL");
315
+ const directory = outputDirectory(options.outputDir, options.taskId);
316
+ const filePath = resolve(
317
+ directory.absolutePath,
318
+ `${title}${extension}`,
319
+ );
320
+ const saved = await client.download(url, filePath);
321
+ exported.file = {
322
+ relativePath: relative(process.cwd(), filePath),
323
+ absolutePath: filePath,
324
+ size: saved.size,
325
+ overwritten: Boolean(saved.overwritten),
326
+ };
327
+ exported.directory = directory;
328
+ }
329
+ output.push(exported);
330
+ } catch (error) {
331
+ rethrowGlobalError(error);
332
+ output.push({ ...series, extension, error: errorJson(error) });
333
+ }
334
+ }
335
+ return output;
336
+ }
337
+
338
+ export function outputDirectory(value = ".datarc-downloads", taskId) {
339
+ if (typeof value !== "string" || !value)
340
+ throw new DatarcError(
341
+ "--output-dir 必须是非空相对路径",
342
+ "INVALID_ARGUMENT",
343
+ );
344
+ if (isAbsolute(value))
345
+ throw new DatarcError(
346
+ "--output-dir 必须是当前工作目录下的相对路径",
347
+ "INVALID_ARGUMENT",
348
+ );
349
+ if (
350
+ typeof taskId !== "string" ||
351
+ !/^[A-Za-z0-9._-]{1,80}$/.test(taskId) ||
352
+ [".", ".."].includes(taskId)
353
+ )
354
+ throw new DatarcError(
355
+ "下载时必须提供仅含字母、数字、点、下划线或连字符的 --task-id",
356
+ "INVALID_ARGUMENT",
357
+ );
358
+ const cwd = resolve(process.cwd());
359
+ const absolutePath = resolve(cwd, value, taskId);
360
+ const fromCwd = relative(cwd, absolutePath);
361
+ if (fromCwd.startsWith("..") || isAbsolute(fromCwd))
362
+ throw new DatarcError(
363
+ "--output-dir 不得超出当前工作目录",
364
+ "INVALID_ARGUMENT",
365
+ );
366
+ return { taskId, relativePath: fromCwd || ".", absolutePath };
367
+ }
368
+
369
+ export function assertAccess(data) {
370
+ if (data?.canAccessData === false)
371
+ throw new DatarcError("当前用户没有数据访问权限", "DATA_ACCESS_DENIED");
372
+ if (data?.noPermissionTokens?.length)
373
+ throw new DatarcError("查询包含无权访问的字段", "FIELD_ACCESS_DENIED", {
374
+ tokens: data.noPermissionTokens.map(({ word, prop }) => ({ word, prop })),
375
+ });
376
+ return data;
377
+ }
378
+
379
+ export function isGlobalError(error) {
380
+ return [
381
+ "MISSING_ENDPOINT",
382
+ "MISSING_TOKEN",
383
+ "NETWORK_ERROR",
384
+ "INVALID_RESPONSE",
385
+ "AUTHENTICATION_FAILED",
386
+ "PERMISSION_DENIED",
387
+ "RATE_LIMITED",
388
+ "DATA_ACCESS_DENIED",
389
+ "FIELD_ACCESS_DENIED",
390
+ ].includes(error?.code);
391
+ }
392
+
393
+ export function rethrowGlobalError(error) {
394
+ if (isGlobalError(error)) throw error;
395
+ }
396
+
397
+ export function errorJson(error) {
398
+ return {
399
+ code: error?.code ?? "UNEXPECTED_ERROR",
400
+ message: error?.message ?? String(error),
401
+ ...(error?.details === undefined ? {} : { details: error.details }),
402
+ };
403
+ }
404
+ export async function runCli(main) {
405
+ try {
406
+ process.stdout.write(
407
+ `${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`,
408
+ );
409
+ } catch (error) {
410
+ process.stdout.write(
411
+ `${JSON.stringify({ ok: false, error: errorJson(error) }, null, 2)}\n`,
412
+ );
413
+ process.exitCode = 1;
414
+ }
415
+ }
416
+
417
+ function apiErrorCode(httpStatus, payload) {
418
+ const businessCodes = [payload.status, payload.code, payload.errcode]
419
+ .filter((value) => value !== undefined && value !== null)
420
+ .map(String);
421
+ if (httpStatus === 401) return "AUTHENTICATION_FAILED";
422
+ if (httpStatus === 403) return "PERMISSION_DENIED";
423
+ if (httpStatus === 429 || businessCodes.includes("0110001"))
424
+ return "RATE_LIMITED";
425
+ return "API_ERROR";
426
+ }
427
+
428
+ function queryPageParams(value, options) {
429
+ const params =
430
+ value && typeof value === "object" && !Array.isArray(value)
431
+ ? { ...value }
432
+ : {};
433
+ if (options.offset !== undefined) params.offset = Number(options.offset);
434
+ else if (params.offset === undefined) params.offset = 0;
435
+ if (options.limit !== undefined) params.limit = Number(options.limit);
436
+ else if (params.limit === undefined) params.limit = 100;
437
+ return params;
438
+ }
439
+
440
+ function safeTaskResult(value) {
441
+ if (value === null || value === undefined) return value;
442
+ if (typeof value === "string") return { message: "异步任务执行失败" };
443
+ if (typeof value !== "object" || Array.isArray(value)) return undefined;
444
+ return {
445
+ ...(value.status === undefined ? {} : { status: value.status }),
446
+ ...(value.message === undefined ? {} : { message: "异步任务执行失败" }),
447
+ };
448
+ }
449
+
450
+ function fileTitle(value, seriesNumber) {
451
+ const safeTitle = basename(String(value ?? "data"))
452
+ .replace(/[\\/:*?"<>|]/g, "_")
453
+ .trim()
454
+ .replace(/[. ]+$/g, "")
455
+ .slice(0, 100);
456
+ const base = safeTitle || "data";
457
+ return seriesNumber === undefined ? base : `${base}-${seriesNumber}`;
458
+ }
459
+
460
+ async function stdin() {
461
+ const chunks = [];
462
+ for await (const chunk of process.stdin) chunks.push(chunk);
463
+ return Buffer.concat(chunks).toString("utf8");
464
+ }