@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,211 +1,211 @@
1
- import { mkdtemp, writeFile } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { credentialBinding, resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
5
- import { DatarcError, readJson } from "./datarc-client.mjs";
6
-
7
- function credentialScope(options) {
8
- const { endpoint, token } = resolveCredentials(options);
9
- return credentialBinding(endpoint, token);
10
- }
11
-
12
- export async function readSearchResult(
13
- file,
14
- workspaceId,
15
- options,
16
- kind = "result",
17
- ) {
18
- if (options?.resultStorage === "artifact")
19
- throw new DatarcError("远程问数请通过 input_artifact 传入原搜索任务的结果工件。", "INVALID_ARGUMENT");
20
- let saved;
21
- try {
22
- saved = await readJson(file);
23
- } catch (error) {
24
- if (error.code !== "ENOENT") throw error;
25
- throw new DatarcError(
26
- "上轮结果文件已不可用,请使用对话中已有的预览,或重新查询缺少的数据",
27
- "RESULT_UNAVAILABLE",
28
- );
29
- }
30
- return validateSearchResult(saved, workspaceId, options, kind);
31
- }
32
-
33
- function validateSearchResult(saved, workspaceId, options, kind = "result") {
34
- if (
35
- saved?.kind !== kind ||
36
- !saved.scope ||
37
- saved.scope !== credentialScope(options) ||
38
- (workspaceId !== undefined && String(workspaceId) !== saved.workspaceId)
39
- ) {
40
- throw new DatarcError(
41
- "结果与当前服务、登录身份或工作区不匹配,请使用当前会话的查询结果",
42
- "RESULT_SCOPE_MISMATCH",
43
- );
44
- }
45
- // Older snapshots stored a requested offset as if it had been confirmed.
46
- if (kind === "result" && saved.summary?.previews?.some((series) => "offset" in series)) {
47
- saved.summary.previews = saved.summary.previews.map(({ offset, ...series }) => ({
48
- ...series,
49
- ...columnMetadata(saved.answer?.cards?.[series.cardIndex]?.data?.[series.seriesIndex]?.columns),
50
- ...(offset === undefined ? {} : unknownPage),
51
- }));
52
- }
53
- return saved;
54
- }
55
-
56
- export async function saveInspection(workspaceId, question, tokens, options) {
57
- const dir = await mkdtemp(join(tmpdir(), "datarc-inspect-"));
58
- const file = join(dir, "inspection.json");
59
- await writeFile(
60
- file,
61
- JSON.stringify({
62
- kind: "inspection",
63
- workspaceId: String(workspaceId),
64
- scope: credentialScope(options),
65
- question,
66
- tokens,
67
- }),
68
- { mode: 0o600, flag: "wx" },
69
- );
70
- return file;
71
- }
72
-
73
- // Resolve a saved CLI envelope, a single result file, or a legacy inline card.
74
- export async function resolveResultInput(input, workspaceId, options) {
75
- const payload = input?.ok === true ? input.data : input;
76
- if (options?.resultStorage === "artifact" && Array.isArray(payload?.results) &&
77
- payload.results.some((item) => !item?.answer && Array.isArray(item?.previews))) {
78
- throw new DatarcError("业务摘要不含卡片,请用 input_artifact 传入原搜索任务的结果工件。", "INVALID_ARGUMENT");
79
- }
80
- if (payload?.kind === "result")
81
- return validateSearchResult(payload, workspaceId, options);
82
- if (
83
- payload?.results?.length &&
84
- payload.results.every((result) => result.resultFile || result.status === "calculation_required")
85
- ) {
86
- const results = await Promise.all(payload.results.map((result) =>
87
- result.resultFile ? readSearchResult(result.resultFile, workspaceId, options) : result
88
- ));
89
- return { results };
90
- }
91
- return input;
92
- }
93
-
94
- // Attribution may include executable units. Keep business data rows intact.
95
- export function businessMetadata(value) {
96
- if (Array.isArray(value)) return value.map(businessMetadata);
97
- if (!value || typeof value !== "object") return value;
98
- return Object.fromEntries(
99
- Object.entries(value)
100
- .filter(([key]) => !["prop", "qKey", "units", "sql"].includes(key))
101
- .map(([key, item]) => [key, businessMetadata(item)]),
102
- );
103
- }
104
-
105
- function columnMetadata(columns = []) {
106
- const details = columns.map((column) => ({
107
- ...(column?._f ? { format: column._f } : {}),
108
- ...(column?._cc ? { currencyCode: column._cc } : {}),
109
- }));
110
- return details.some((detail) => Object.keys(detail).length)
111
- ? { columnMetadata: details }
112
- : {};
113
- }
114
-
115
- const unknownPage = {
116
- coverage: "unknown",
117
- message: "服务端未确认实际分页范围,请按明确的对象或时间范围重新查询后再合并。",
118
- };
119
-
120
- export function businessSeries(entries, options = {}) {
121
- return entries.map(({ columns, query, data, ...entry }) => {
122
- const names = (columns ?? []).map((column) =>
123
- typeof column === "string"
124
- ? column
125
- : column?._n && column._n !== column._nes
126
- ? column._n
127
- : null,
128
- );
129
- const series = { ...entry, columns: names, ...columnMetadata(columns), data };
130
- if (entry.extension || entry.error) return series;
131
- if (options.page || options.offset !== undefined || options.limit !== undefined ||
132
- query?.params?.offset !== undefined || query?.params?.limit !== undefined)
133
- return { ...series, ...unknownPage };
134
- // A first preview describes the original question, including any ranking in it.
135
- const truncated = data !== null && typeof data === "object" &&
136
- (!Array.isArray(data) || data.length >= 100);
137
- return { ...series, coverage: truncated ? "preview" : "complete" };
138
- });
139
- }
140
-
141
- export async function presentSearch(raw, workspaceId, modelUids, options) {
142
- const results = [];
143
- const scope = options.resultStorage === "artifact" ? undefined : credentialScope(options);
144
- let dir;
145
- for (const [
146
- index,
147
- { answer, previews, exports, ...result },
148
- ] of raw.results.entries()) {
149
- if (result.status === "calculation_required") {
150
- results.push(result);
151
- continue;
152
- }
153
- const measureAliases = answer.cards.flatMap((card) =>
154
- (card.explanations ?? []).flatMap((scope) =>
155
- (scope.measures ?? [])
156
- .flat()
157
- .filter(
158
- (token) =>
159
- Array.isArray(token.names) &&
160
- token.word !== token.prop &&
161
- token.names.some(
162
- (name) => name !== token.word && name !== token.prop,
163
- ),
164
- )
165
- .map((token) => ({
166
- model: scope.model,
167
- measure: token.word,
168
- names: token.names.filter(
169
- (name) => name !== token.word && name !== token.prop,
170
- ),
171
- })),
172
- ),
173
- );
174
- const summary = {
175
- ...result,
176
- ...(measureAliases.length ? { measureAliases } : {}),
177
- insights: businessMetadata(result.insights),
178
- previews: businessSeries(previews, options),
179
- ...(exports ? { exports: businessSeries(exports) } : {}),
180
- };
181
- const cardSource = { tokens: answer.tokens, cards: answer.cards };
182
- if (options.resultStorage === "artifact") {
183
- results.push({ ...summary, answer: cardSource });
184
- continue;
185
- }
186
- dir ??= await mkdtemp(join(tmpdir(), "datarc-search-"));
187
- const resultFile = join(dir, `result-${index + 1}.json`);
188
- const actualModels = answer.cards.flatMap((card) =>
189
- card.activeTuids?.length
190
- ? card.activeTuids
191
- : (card.explanations ?? [])
192
- .map((item) => item.modelUid)
193
- .filter(Boolean),
194
- );
195
- const saved = {
196
- kind: "result",
197
- workspaceId: String(workspaceId),
198
- scope,
199
- modelUids: modelUids.length ? modelUids : [...new Set(actualModels)],
200
- question: result.question,
201
- answer: cardSource,
202
- summary,
203
- };
204
- await writeFile(resultFile, JSON.stringify(saved), {
205
- mode: 0o600,
206
- flag: "wx",
207
- });
208
- results.push({ ...summary, resultFile });
209
- }
210
- return { ...raw, results };
211
- }
1
+ import { mkdtemp, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { credentialBinding, resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
5
+ import { DatarcError, readJson } from "./datarc-client.mjs";
6
+
7
+ function credentialScope(options) {
8
+ const { endpoint, token } = resolveCredentials(options);
9
+ return credentialBinding(endpoint, token);
10
+ }
11
+
12
+ export async function readSearchResult(
13
+ file,
14
+ workspaceId,
15
+ options,
16
+ kind = "result",
17
+ ) {
18
+ if (options?.resultStorage === "artifact")
19
+ throw new DatarcError("远程问数请通过 input_artifact 传入原搜索任务的结果工件。", "INVALID_ARGUMENT");
20
+ let saved;
21
+ try {
22
+ saved = await readJson(file);
23
+ } catch (error) {
24
+ if (error.code !== "ENOENT") throw error;
25
+ throw new DatarcError(
26
+ "上轮结果文件已不可用,请使用对话中已有的预览,或重新查询缺少的数据",
27
+ "RESULT_UNAVAILABLE",
28
+ );
29
+ }
30
+ return validateSearchResult(saved, workspaceId, options, kind);
31
+ }
32
+
33
+ function validateSearchResult(saved, workspaceId, options, kind = "result") {
34
+ if (
35
+ saved?.kind !== kind ||
36
+ !saved.scope ||
37
+ saved.scope !== credentialScope(options) ||
38
+ (workspaceId !== undefined && String(workspaceId) !== saved.workspaceId)
39
+ ) {
40
+ throw new DatarcError(
41
+ "结果与当前服务、登录身份或工作区不匹配,请使用当前会话的查询结果",
42
+ "RESULT_SCOPE_MISMATCH",
43
+ );
44
+ }
45
+ // Older snapshots stored a requested offset as if it had been confirmed.
46
+ if (kind === "result" && saved.summary?.previews?.some((series) => "offset" in series)) {
47
+ saved.summary.previews = saved.summary.previews.map(({ offset, ...series }) => ({
48
+ ...series,
49
+ ...columnMetadata(saved.answer?.cards?.[series.cardIndex]?.data?.[series.seriesIndex]?.columns),
50
+ ...(offset === undefined ? {} : unknownPage),
51
+ }));
52
+ }
53
+ return saved;
54
+ }
55
+
56
+ export async function saveInspection(workspaceId, question, tokens, options) {
57
+ const dir = await mkdtemp(join(tmpdir(), "datarc-inspect-"));
58
+ const file = join(dir, "inspection.json");
59
+ await writeFile(
60
+ file,
61
+ JSON.stringify({
62
+ kind: "inspection",
63
+ workspaceId: String(workspaceId),
64
+ scope: credentialScope(options),
65
+ question,
66
+ tokens,
67
+ }),
68
+ { mode: 0o600, flag: "wx" },
69
+ );
70
+ return file;
71
+ }
72
+
73
+ // Resolve a saved CLI envelope, a single result file, or a legacy inline card.
74
+ export async function resolveResultInput(input, workspaceId, options) {
75
+ const payload = input?.ok === true ? input.data : input;
76
+ if (options?.resultStorage === "artifact" && Array.isArray(payload?.results) &&
77
+ payload.results.some((item) => !item?.answer && Array.isArray(item?.previews))) {
78
+ throw new DatarcError("业务摘要不含卡片,请用 input_artifact 传入原搜索任务的结果工件。", "INVALID_ARGUMENT");
79
+ }
80
+ if (payload?.kind === "result")
81
+ return validateSearchResult(payload, workspaceId, options);
82
+ if (
83
+ payload?.results?.length &&
84
+ payload.results.every((result) => result.resultFile || result.status === "calculation_required")
85
+ ) {
86
+ const results = await Promise.all(payload.results.map((result) =>
87
+ result.resultFile ? readSearchResult(result.resultFile, workspaceId, options) : result
88
+ ));
89
+ return { results };
90
+ }
91
+ return input;
92
+ }
93
+
94
+ // Attribution may include executable units. Keep business data rows intact.
95
+ export function businessMetadata(value) {
96
+ if (Array.isArray(value)) return value.map(businessMetadata);
97
+ if (!value || typeof value !== "object") return value;
98
+ return Object.fromEntries(
99
+ Object.entries(value)
100
+ .filter(([key]) => !["prop", "qKey", "units", "sql"].includes(key))
101
+ .map(([key, item]) => [key, businessMetadata(item)]),
102
+ );
103
+ }
104
+
105
+ function columnMetadata(columns = []) {
106
+ const details = columns.map((column) => ({
107
+ ...(column?._f ? { format: column._f } : {}),
108
+ ...(column?._cc ? { currencyCode: column._cc } : {}),
109
+ }));
110
+ return details.some((detail) => Object.keys(detail).length)
111
+ ? { columnMetadata: details }
112
+ : {};
113
+ }
114
+
115
+ const unknownPage = {
116
+ coverage: "unknown",
117
+ message: "服务端未确认实际分页范围,请按明确的对象或时间范围重新查询后再合并。",
118
+ };
119
+
120
+ export function businessSeries(entries, options = {}) {
121
+ return entries.map(({ columns, query, data, ...entry }) => {
122
+ const names = (columns ?? []).map((column) =>
123
+ typeof column === "string"
124
+ ? column
125
+ : column?._n && column._n !== column._nes
126
+ ? column._n
127
+ : null,
128
+ );
129
+ const series = { ...entry, columns: names, ...columnMetadata(columns), data };
130
+ if (entry.extension || entry.error) return series;
131
+ if (options.page || options.offset !== undefined || options.limit !== undefined ||
132
+ query?.params?.offset !== undefined || query?.params?.limit !== undefined)
133
+ return { ...series, ...unknownPage };
134
+ // A first preview describes the original question, including any ranking in it.
135
+ const truncated = data !== null && typeof data === "object" &&
136
+ (!Array.isArray(data) || data.length >= 100);
137
+ return { ...series, coverage: truncated ? "preview" : "complete" };
138
+ });
139
+ }
140
+
141
+ export async function presentSearch(raw, workspaceId, modelUids, options) {
142
+ const results = [];
143
+ const scope = options.resultStorage === "artifact" ? undefined : credentialScope(options);
144
+ let dir;
145
+ for (const [
146
+ index,
147
+ { answer, previews, exports, ...result },
148
+ ] of raw.results.entries()) {
149
+ if (result.status === "calculation_required") {
150
+ results.push(result);
151
+ continue;
152
+ }
153
+ const measureAliases = answer.cards.flatMap((card) =>
154
+ (card.explanations ?? []).flatMap((scope) =>
155
+ (scope.measures ?? [])
156
+ .flat()
157
+ .filter(
158
+ (token) =>
159
+ Array.isArray(token.names) &&
160
+ token.word !== token.prop &&
161
+ token.names.some(
162
+ (name) => name !== token.word && name !== token.prop,
163
+ ),
164
+ )
165
+ .map((token) => ({
166
+ model: scope.model,
167
+ measure: token.word,
168
+ names: token.names.filter(
169
+ (name) => name !== token.word && name !== token.prop,
170
+ ),
171
+ })),
172
+ ),
173
+ );
174
+ const summary = {
175
+ ...result,
176
+ ...(measureAliases.length ? { measureAliases } : {}),
177
+ insights: businessMetadata(result.insights),
178
+ previews: businessSeries(previews, options),
179
+ ...(exports ? { exports: businessSeries(exports) } : {}),
180
+ };
181
+ const cardSource = { tokens: answer.tokens, cards: answer.cards };
182
+ if (options.resultStorage === "artifact") {
183
+ results.push({ ...summary, answer: cardSource });
184
+ continue;
185
+ }
186
+ dir ??= await mkdtemp(join(tmpdir(), "datarc-search-"));
187
+ const resultFile = join(dir, `result-${index + 1}.json`);
188
+ const actualModels = answer.cards.flatMap((card) =>
189
+ card.activeTuids?.length
190
+ ? card.activeTuids
191
+ : (card.explanations ?? [])
192
+ .map((item) => item.modelUid)
193
+ .filter(Boolean),
194
+ );
195
+ const saved = {
196
+ kind: "result",
197
+ workspaceId: String(workspaceId),
198
+ scope,
199
+ modelUids: modelUids.length ? modelUids : [...new Set(actualModels)],
200
+ question: result.question,
201
+ answer: cardSource,
202
+ summary,
203
+ };
204
+ await writeFile(resultFile, JSON.stringify(saved), {
205
+ mode: 0o600,
206
+ flag: "wx",
207
+ });
208
+ results.push({ ...summary, resultFile });
209
+ }
210
+ return { ...raw, results };
211
+ }
@@ -1,59 +1,59 @@
1
- ---
2
- name: datarc-dataseek-batch-evaluation
3
- description: 批量回归评估北极九章(datarc)DataSeek 对 CSV 问题的理解步骤、最终问题 Token 及其 Word;调用真实 DataSeek、保留原始列、自动跳过完全一致项,并由大模型判断非完全一致结果是否逻辑等价。用于批量测试、回归验收和定位理解流程偏差,不用于生成测试集或修改语义配置。
4
- ---
5
-
6
- # DataSeek 批量回归评估
7
-
8
- 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
-
10
- 使用 `scripts/dataseek-batch-evaluation.mjs` 采集和整理测试结果;Agent 负责对非完全一致项作语义等价判断。
11
-
12
- ## 前置条件
13
-
14
- - 按 `datarc-oauth` 配置 `DATARC_ENDPOINT` 与 `DATARC_TOKEN`,令牌由共享客户端从环境变量或 datarc 工作区凭据文件解析。
15
- - 调用方提供工作区 ID 和 UTF-8 CSV。CSV 包含原始问题、期望理解 JSON、期望最终问题 Token,以及紧随 Token 的期望 Token Word 列;列名可通过参数指定。兼容旧 CSV:未指定 Word 列时从期望 Token 的 `word` 自动派生。
16
- - 每行使用独立的新 DataSeek 会话,避免上下文污染。当前版本只支持直接单 query;遇到 `parallel` 或 `chained` 会明确记为不支持的执行错误,不会误报为缺少 Token。评估只读取理解结果,不执行数据卡片查询,也不修改工作区。
17
- - 工作区由消息接口 URL 与当前成员权限绑定,不在请求体中传递额外工作区字段。消息完成仅以 `current.result` 非空或 `current.error` 为准,不等待卡片取数。
18
-
19
- ## 工作流
20
-
21
- 先查看参数契约:
22
-
23
- ```bash
24
- node scripts/dataseek-batch-evaluation.mjs --help
25
- ```
26
-
27
- 1. 运行 `collect`。脚本逐行调用 DataSeek,原子保存 checkpoint,并生成仅含待模型复核案例的 JSONL。默认串行,只有服务容量明确允许时才提高 `--concurrency`。
28
- 2. 分批读取 review JSONL。逐案比较期望与实际的理解结果、最终 Token 和 Token Word;Word 与原始问题表达相同语义时可判等价,不要求逐字一致。判定规则见 [references/equivalence.md](references/equivalence.md)。
29
- 3. 将判定逐行写成 decisions JSONL,原样带回 review 中的 `caseKey`,再运行 `finalize`。不得修改 checkpoint 或原始 CSV。缺失或不匹配的 `caseKey` 不会应用到当前案例。
30
- 4. 检查输出汇总和结果 CSV。结果 CSV 保留全部原始列,并追加实际结果、是否正确、差异阶段、差异简述和独立报错信息。查询或采集失败写入报错信息;逻辑不等价写入差异简述,两者不混用。
31
-
32
- 采集字段必须来自以下固定位置:
33
-
34
- - 实际理解 JSON:`message.history` 中名称为“理解问题”或 `Understand the problem` 的步骤所返回的结构化 JSON。
35
- - 实际最终问题 Token:最终 `answer` 动作的 `data.tokens`。
36
- - 实际 Token Word:按 Token 顺序抽取每个 `word`,用单个空格连接。
37
- - 同义词证据:先读取期望与实际 Token 自带的 `synonyms` 和 `aliases`;名称不同时,脚本按需调用成员接口 `POST /api/v2/account-projects/{workspaceId}/tokens/`(`siriType=2`)并缓存返回的 `synonyms`、`aliases` 和 `originalName`。同一 `prop` 且名称集合有交集时可认定 Token 关键词等价;不同 `prop` 不得仅因字面相近而自动放行。元数据接口不可用时保留给模型复核,不得为了比较而改写输出中的实际 JSON 或 Token。
38
- - `answer.data.questions` 是候选问题列表,不得写入实际 Token 列;`message.current.result` 是动作数组,不得写入实际理解 JSON 列。
39
-
40
- 典型命令:
41
-
42
- ```bash
43
- node scripts/dataseek-batch-evaluation.mjs collect --workspace-id 1 --input cases.csv --output-dir .datarc-evaluations/run-001 --question-column 原始问题 --expected-understanding-column 理解JSON --expected-tokens-column 问题Token --expected-token-words-column 问题TokenWord
44
- node scripts/dataseek-batch-evaluation.mjs finalize --manifest .datarc-evaluations/run-001/manifest.json --decisions .datarc-evaluations/run-001/decisions.jsonl --output result.csv
45
- ```
46
-
47
- `finalize` 会同时写入结果 CSV 和 `<结果 CSV>.summary.json`。两个输出路径都会在写入前检查,不得覆盖输入 CSV、manifest、checkpoint、review 或 decisions。
48
-
49
- 大批量时每次只读取 review JSONL 的一个批次,写完对应 decisions 后再处理下一批。决策格式和续跑规则见 [references/artifacts.md](references/artifacts.md)。
50
-
51
- ## 判定边界
52
-
53
- - 指标、维度、维度值、时间范围、筛选、聚合、排序、Top N、对比方式、并列/链式依赖中的任一业务语义变化,均不是等价。
54
- - 仅字段顺序、无意义措辞、JSON 对象键顺序、可互换的结构包装或同义但约束相同的表达可以等价。理解 JSON 中的字段名或维度值使用同义表达时,应结合 Token 的相同 `prop` 及 `synonyms`/`aliases` 判断;证据不足时保持待复核。
55
- - 证据不足时判为 `review`,不要猜测 `pass`。
56
- - DataSeek 调用失败判为 `error`;与语义不一致的 `fail` 分开统计。
57
- - 不输出内部 Prompt、SQL、密钥或无关业务数据。产物可能包含业务问题和 Token,不得提交到版本库。
58
-
59
- 未来需要定位全流程差异时,优先扩展采集 artifact 中的阶段列表和逐阶段判定;不要改变已有 CSV 输出列的含义。
1
+ ---
2
+ name: datarc-dataseek-batch-evaluation
3
+ description: 批量回归评估北极九章(datarc)DataSeek 对 CSV 问题的理解步骤、最终问题 Token 及其 Word;调用真实 DataSeek、保留原始列、自动跳过完全一致项,并由大模型判断非完全一致结果是否逻辑等价。用于批量测试、回归验收和定位理解流程偏差,不用于生成测试集或修改语义配置。
4
+ ---
5
+
6
+ # DataSeek 批量回归评估
7
+
8
+ 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
+
10
+ 使用 `scripts/dataseek-batch-evaluation.mjs` 采集和整理测试结果;Agent 负责对非完全一致项作语义等价判断。
11
+
12
+ ## 前置条件
13
+
14
+ - 按 `datarc-oauth` 配置 `DATARC_ENDPOINT` 与 `DATARC_TOKEN`,令牌由共享客户端从环境变量或 datarc 工作区凭据文件解析。
15
+ - 调用方提供工作区 ID 和 UTF-8 CSV。CSV 包含原始问题、期望理解 JSON、期望最终问题 Token,以及紧随 Token 的期望 Token Word 列;列名可通过参数指定。兼容旧 CSV:未指定 Word 列时从期望 Token 的 `word` 自动派生。
16
+ - 每行使用独立的新 DataSeek 会话,避免上下文污染。当前版本只支持直接单 query;遇到 `parallel` 或 `chained` 会明确记为不支持的执行错误,不会误报为缺少 Token。评估只读取理解结果,不执行数据卡片查询,也不修改工作区。
17
+ - 工作区由消息接口 URL 与当前成员权限绑定,不在请求体中传递额外工作区字段。消息完成仅以 `current.result` 非空或 `current.error` 为准,不等待卡片取数。
18
+
19
+ ## 工作流
20
+
21
+ 先查看参数契约:
22
+
23
+ ```bash
24
+ node scripts/dataseek-batch-evaluation.mjs --help
25
+ ```
26
+
27
+ 1. 运行 `collect`。脚本逐行调用 DataSeek,原子保存 checkpoint,并生成仅含待模型复核案例的 JSONL。默认串行,只有服务容量明确允许时才提高 `--concurrency`。
28
+ 2. 分批读取 review JSONL。逐案比较期望与实际的理解结果、最终 Token 和 Token Word;Word 与原始问题表达相同语义时可判等价,不要求逐字一致。判定规则见 [references/equivalence.md](references/equivalence.md)。
29
+ 3. 将判定逐行写成 decisions JSONL,原样带回 review 中的 `caseKey`,再运行 `finalize`。不得修改 checkpoint 或原始 CSV。缺失或不匹配的 `caseKey` 不会应用到当前案例。
30
+ 4. 检查输出汇总和结果 CSV。结果 CSV 保留全部原始列,并追加实际结果、是否正确、差异阶段、差异简述和独立报错信息。查询或采集失败写入报错信息;逻辑不等价写入差异简述,两者不混用。
31
+
32
+ 采集字段必须来自以下固定位置:
33
+
34
+ - 实际理解 JSON:`message.history` 中名称为“理解问题”或 `Understand the problem` 的步骤所返回的结构化 JSON。
35
+ - 实际最终问题 Token:最终 `answer` 动作的 `data.tokens`。
36
+ - 实际 Token Word:按 Token 顺序抽取每个 `word`,用单个空格连接。
37
+ - 同义词证据:先读取期望与实际 Token 自带的 `synonyms` 和 `aliases`;名称不同时,脚本按需调用成员接口 `POST /api/v2/account-projects/{workspaceId}/tokens/`(`siriType=2`)并缓存返回的 `synonyms`、`aliases` 和 `originalName`。同一 `prop` 且名称集合有交集时可认定 Token 关键词等价;不同 `prop` 不得仅因字面相近而自动放行。元数据接口不可用时保留给模型复核,不得为了比较而改写输出中的实际 JSON 或 Token。
38
+ - `answer.data.questions` 是候选问题列表,不得写入实际 Token 列;`message.current.result` 是动作数组,不得写入实际理解 JSON 列。
39
+
40
+ 典型命令:
41
+
42
+ ```bash
43
+ node scripts/dataseek-batch-evaluation.mjs collect --workspace-id 1 --input cases.csv --output-dir .datarc-evaluations/run-001 --question-column 原始问题 --expected-understanding-column 理解JSON --expected-tokens-column 问题Token --expected-token-words-column 问题TokenWord
44
+ node scripts/dataseek-batch-evaluation.mjs finalize --manifest .datarc-evaluations/run-001/manifest.json --decisions .datarc-evaluations/run-001/decisions.jsonl --output result.csv
45
+ ```
46
+
47
+ `finalize` 会同时写入结果 CSV 和 `<结果 CSV>.summary.json`。两个输出路径都会在写入前检查,不得覆盖输入 CSV、manifest、checkpoint、review 或 decisions。
48
+
49
+ 大批量时每次只读取 review JSONL 的一个批次,写完对应 decisions 后再处理下一批。决策格式和续跑规则见 [references/artifacts.md](references/artifacts.md)。
50
+
51
+ ## 判定边界
52
+
53
+ - 指标、维度、维度值、时间范围、筛选、聚合、排序、Top N、对比方式、并列/链式依赖中的任一业务语义变化,均不是等价。
54
+ - 仅字段顺序、无意义措辞、JSON 对象键顺序、可互换的结构包装或同义但约束相同的表达可以等价。理解 JSON 中的字段名或维度值使用同义表达时,应结合 Token 的相同 `prop` 及 `synonyms`/`aliases` 判断;证据不足时保持待复核。
55
+ - 证据不足时判为 `review`,不要猜测 `pass`。
56
+ - DataSeek 调用失败判为 `error`;与语义不一致的 `fail` 分开统计。
57
+ - 不输出内部 Prompt、SQL、密钥或无关业务数据。产物可能包含业务问题和 Token,不得提交到版本库。
58
+
59
+ 未来需要定位全流程差异时,优先扩展采集 artifact 中的阶段列表和逐阶段判定;不要改变已有 CSV 输出列的含义。
@@ -1,36 +1,36 @@
1
- # 产物与续跑契约
2
-
3
- `collect` 在输出目录生成:
4
-
5
- - `manifest.json`:输入、列映射、工作区、行数及其他产物路径。
6
- - `checkpoint.jsonl`:每次采集完成追加一行;同一 `rowNumber` 最后一条有效记录生效。默认续跑会跳过已用当前比较规则完成的成功记录,并重新处理旧版或同义词元数据获取不完整的成功记录;`--retry-errors` 只重试采集失败行。
7
- - `review.jsonl`:只包含不能由结构完全一致自动通过的案例。每行是一个案例,适合按行号范围分批交给模型。
8
-
9
- 模型创建 `decisions.jsonl`,每行格式:
10
-
11
- ```json
12
- { "rowNumber": 2, "caseKey": "review 中对应的 caseKey", "verdict": "fail", "mismatchStage": "tokens", "summary": "实际缺少去年时间范围" }
13
- ```
14
-
15
- 约束:
16
-
17
- - `rowNumber` 必须来自 review artifact,且每行最多一条最终判定;重复时最后一条生效。
18
- - `caseKey` 必须原样复制自同一条 review 记录。输入行变化后旧判定不得复用;缺失或不匹配时结果保持“待复核”。
19
- - `verdict` 只能是 `pass`、`fail`、`review`。
20
- - `mismatchStage` 只能是 `understanding`、`tokens`、`both`、`unknown`。
21
- - `summary` 使用单行简述,不写推理过程;`pass` 可写“逻辑等价”,但 `finalize` 不会将通过原因写入 `测试_差异简述`。
22
-
23
- `finalize` 生成结果 CSV 和同名 `.summary.json`。输出追加列固定为:
24
-
25
- 如果原始 CSV 在采集后发生变化,`finalize` 会停止并要求重新采集;输出路径也不得覆盖输入或任何中间产物。
26
-
27
- - `测试_实际理解JSON`
28
- - `测试_实际问题Token`
29
- - `测试_实际问题TokenWord`
30
- - `测试_执行状态`
31
- - `测试_是否正确`
32
- - `测试_差异阶段`
33
- - `测试_差异简述`
34
- - `测试_报错信息`
35
-
36
- 完全结构一致,或理解 JSON 与 Token Word 的名称差异均能由相同位置、同 `prop` Token 的 `synonyms`/`aliases` 证明等价时,案例自动记为正确。Token 相同不能绕过独立的 Token Word 检查。采集失败记为执行错误并将原因写入 `测试_报错信息`;模型判为不等价或待复核时将说明写入 `测试_差异简述`;自动或模型判定通过时该列留空。
1
+ # 产物与续跑契约
2
+
3
+ `collect` 在输出目录生成:
4
+
5
+ - `manifest.json`:输入、列映射、工作区、行数及其他产物路径。
6
+ - `checkpoint.jsonl`:每次采集完成追加一行;同一 `rowNumber` 最后一条有效记录生效。默认续跑会跳过已用当前比较规则完成的成功记录,并重新处理旧版或同义词元数据获取不完整的成功记录;`--retry-errors` 只重试采集失败行。
7
+ - `review.jsonl`:只包含不能由结构完全一致自动通过的案例。每行是一个案例,适合按行号范围分批交给模型。
8
+
9
+ 模型创建 `decisions.jsonl`,每行格式:
10
+
11
+ ```json
12
+ { "rowNumber": 2, "caseKey": "review 中对应的 caseKey", "verdict": "fail", "mismatchStage": "tokens", "summary": "实际缺少去年时间范围" }
13
+ ```
14
+
15
+ 约束:
16
+
17
+ - `rowNumber` 必须来自 review artifact,且每行最多一条最终判定;重复时最后一条生效。
18
+ - `caseKey` 必须原样复制自同一条 review 记录。输入行变化后旧判定不得复用;缺失或不匹配时结果保持“待复核”。
19
+ - `verdict` 只能是 `pass`、`fail`、`review`。
20
+ - `mismatchStage` 只能是 `understanding`、`tokens`、`both`、`unknown`。
21
+ - `summary` 使用单行简述,不写推理过程;`pass` 可写“逻辑等价”,但 `finalize` 不会将通过原因写入 `测试_差异简述`。
22
+
23
+ `finalize` 生成结果 CSV 和同名 `.summary.json`。输出追加列固定为:
24
+
25
+ 如果原始 CSV 在采集后发生变化,`finalize` 会停止并要求重新采集;输出路径也不得覆盖输入或任何中间产物。
26
+
27
+ - `测试_实际理解JSON`
28
+ - `测试_实际问题Token`
29
+ - `测试_实际问题TokenWord`
30
+ - `测试_执行状态`
31
+ - `测试_是否正确`
32
+ - `测试_差异阶段`
33
+ - `测试_差异简述`
34
+ - `测试_报错信息`
35
+
36
+ 完全结构一致,或理解 JSON 与 Token Word 的名称差异均能由相同位置、同 `prop` Token 的 `synonyms`/`aliases` 证明等价时,案例自动记为正确。Token 相同不能绕过独立的 Token Word 检查。采集失败记为执行错误并将原因写入 `测试_报错信息`;模型判为不等价或待复核时将说明写入 `测试_差异简述`;自动或模型判定通过时该列留空。