@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,180 +1,180 @@
1
- import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
2
- export class DatarcError extends Error {
3
- constructor(message, code = "DATARC_ERROR", details) {
4
- super(message);
5
- this.name = "DatarcError";
6
- this.code = code;
7
- this.details = details;
8
- }
9
- }
10
-
11
- export function parseArgs(argv) {
12
- const result = { _: [] };
13
- for (let index = 0; index < argv.length; index += 1) {
14
- const value = argv[index];
15
- if (!value.startsWith("--")) {
16
- result._.push(value);
17
- continue;
18
- }
19
- const key = value.slice(2);
20
- const next = argv[index + 1];
21
- if (next === undefined || next.startsWith("--")) result[key] = true;
22
- else {
23
- result[key] =
24
- result[key] === undefined ? next : [].concat(result[key], next);
25
- index += 1;
26
- }
27
- }
28
- return result;
29
- }
30
-
31
- export function required(args, key) {
32
- if (args[key] === undefined || args[key] === true || args[key] === "")
33
- throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
34
- return args[key];
35
- }
36
-
37
- export function createClient(options = {}) {
38
- const { endpoint, token } = resolveCredentials(options);
39
- const fetchImpl = options.fetchImpl ?? globalThis.fetch;
40
- if (!endpoint)
41
- throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
42
- if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
43
-
44
- async function request(method, path, { query, body } = {}) {
45
- const url = new URL(`${endpoint}${path}`);
46
- for (const [key, value] of Object.entries(query ?? {}))
47
- for (const item of [].concat(value ?? []))
48
- if (item !== "") url.searchParams.append(key, item);
49
- let response;
50
- try {
51
- response = await fetchImpl(url, {
52
- method,
53
- headers: {
54
- Authorization: token,
55
- ...(body === undefined ? {} : { "Content-Type": "application/json" }),
56
- },
57
- ...(body === undefined ? {} : { body: JSON.stringify(body) }),
58
- });
59
- } catch (error) {
60
- throw new DatarcError(`网络请求失败:${error.message}`, "NETWORK_ERROR");
61
- }
62
- const text = await response.text();
63
- let payload;
64
- try {
65
- payload = text ? JSON.parse(text) : {};
66
- } catch {
67
- throw new DatarcError(
68
- `服务返回非 JSON(HTTP ${response.status})`,
69
- "INVALID_RESPONSE",
70
- );
71
- }
72
- const isEnvelope =
73
- payload !== null &&
74
- typeof payload === "object" &&
75
- !Array.isArray(payload);
76
- if (!response.ok)
77
- throw new DatarcError(
78
- (isEnvelope && payload.message) ||
79
- `请求失败(HTTP ${response.status})`,
80
- apiErrorCode(response.status),
81
- {
82
- httpStatus: response.status,
83
- status: isEnvelope ? payload.status : undefined,
84
- },
85
- );
86
- if (!isEnvelope || typeof payload.status !== "string")
87
- throw new DatarcError(
88
- `服务返回无效响应信封(HTTP ${response.status})`,
89
- "INVALID_RESPONSE",
90
- { httpStatus: response.status },
91
- );
92
- if (payload.status !== "SUCCESS")
93
- throw new DatarcError(
94
- payload.message || `请求失败(HTTP ${response.status})`,
95
- apiErrorCode(response.status),
96
- { httpStatus: response.status, status: payload.status },
97
- );
98
- if (!Object.hasOwn(payload, "data"))
99
- throw new DatarcError(
100
- `服务返回无效响应信封(HTTP ${response.status})`,
101
- "INVALID_RESPONSE",
102
- { httpStatus: response.status },
103
- );
104
- return payload.data;
105
- }
106
- return { request };
107
- }
108
-
109
- export function errorJson(error) {
110
- const trusted = [
111
- "DatarcError",
112
- "CaseModelError",
113
- "DatasetPreflightError",
114
- ].includes(error?.name);
115
- const code =
116
- trusted && typeof error?.code === "string"
117
- ? error.code
118
- : "UNEXPECTED_ERROR";
119
- const details = safeErrorDetails(error?.details);
120
- return {
121
- code,
122
- message: safeErrorMessage(error, code),
123
- ...(Object.keys(details).length ? { details } : {}),
124
- };
125
- }
126
-
127
- function apiErrorCode(status) {
128
- if (status === 401) return "AUTHENTICATION_FAILED";
129
- if (status === 403) return "PERMISSION_DENIED";
130
- if (status === 429) return "RATE_LIMITED";
131
- return "API_ERROR";
132
- }
133
-
134
- function safeErrorMessage(error, code) {
135
- if (code === "NETWORK_ERROR") return "无法连接北极九章(datarc)服务";
136
- if (code === "INVALID_RESPONSE") return "北极九章(datarc)服务返回无效响应";
137
- if (
138
- new Set([
139
- "API_ERROR",
140
- "AUTHENTICATION_FAILED",
141
- "PERMISSION_DENIED",
142
- "RATE_LIMITED",
143
- ]).has(code)
144
- )
145
- return "北极九章(datarc)服务请求失败";
146
- if (code === "UNEXPECTED_ERROR") return "操作失败";
147
- return typeof error?.message === "string" && error.message
148
- ? error.message
149
- : "操作失败";
150
- }
151
-
152
- function safeErrorDetails(details) {
153
- if (!details || typeof details !== "object" || Array.isArray(details))
154
- return {};
155
- const result = {};
156
- for (const key of [
157
- "artifact",
158
- "conflictIndex",
159
- "duplicateIndex",
160
- "firstIndex",
161
- "hash",
162
- "httpStatus",
163
- "index",
164
- "kind",
165
- "partial",
166
- "phase",
167
- "reloadRequired",
168
- "resourceId",
169
- "resourceKind",
170
- "sourceIndex",
171
- "sourceType",
172
- "status",
173
- "workspaceId",
174
- ]) {
175
- const value = details[key];
176
- if (["string", "number", "boolean"].includes(typeof value))
177
- result[key] = value;
178
- }
179
- return result;
180
- }
1
+ import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
2
+ export class DatarcError extends Error {
3
+ constructor(message, code = "DATARC_ERROR", details) {
4
+ super(message);
5
+ this.name = "DatarcError";
6
+ this.code = code;
7
+ this.details = details;
8
+ }
9
+ }
10
+
11
+ export function parseArgs(argv) {
12
+ const result = { _: [] };
13
+ for (let index = 0; index < argv.length; index += 1) {
14
+ const value = argv[index];
15
+ if (!value.startsWith("--")) {
16
+ result._.push(value);
17
+ continue;
18
+ }
19
+ const key = value.slice(2);
20
+ const next = argv[index + 1];
21
+ if (next === undefined || next.startsWith("--")) result[key] = true;
22
+ else {
23
+ result[key] =
24
+ result[key] === undefined ? next : [].concat(result[key], next);
25
+ index += 1;
26
+ }
27
+ }
28
+ return result;
29
+ }
30
+
31
+ export function required(args, key) {
32
+ if (args[key] === undefined || args[key] === true || args[key] === "")
33
+ throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
34
+ return args[key];
35
+ }
36
+
37
+ export function createClient(options = {}) {
38
+ const { endpoint, token } = resolveCredentials(options);
39
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
40
+ if (!endpoint)
41
+ throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
42
+ if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
43
+
44
+ async function request(method, path, { query, body } = {}) {
45
+ const url = new URL(`${endpoint}${path}`);
46
+ for (const [key, value] of Object.entries(query ?? {}))
47
+ for (const item of [].concat(value ?? []))
48
+ if (item !== "") url.searchParams.append(key, item);
49
+ let response;
50
+ try {
51
+ response = await fetchImpl(url, {
52
+ method,
53
+ headers: {
54
+ Authorization: token,
55
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
56
+ },
57
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
58
+ });
59
+ } catch (error) {
60
+ throw new DatarcError(`网络请求失败:${error.message}`, "NETWORK_ERROR");
61
+ }
62
+ const text = await response.text();
63
+ let payload;
64
+ try {
65
+ payload = text ? JSON.parse(text) : {};
66
+ } catch {
67
+ throw new DatarcError(
68
+ `服务返回非 JSON(HTTP ${response.status})`,
69
+ "INVALID_RESPONSE",
70
+ );
71
+ }
72
+ const isEnvelope =
73
+ payload !== null &&
74
+ typeof payload === "object" &&
75
+ !Array.isArray(payload);
76
+ if (!response.ok)
77
+ throw new DatarcError(
78
+ (isEnvelope && payload.message) ||
79
+ `请求失败(HTTP ${response.status})`,
80
+ apiErrorCode(response.status),
81
+ {
82
+ httpStatus: response.status,
83
+ status: isEnvelope ? payload.status : undefined,
84
+ },
85
+ );
86
+ if (!isEnvelope || typeof payload.status !== "string")
87
+ throw new DatarcError(
88
+ `服务返回无效响应信封(HTTP ${response.status})`,
89
+ "INVALID_RESPONSE",
90
+ { httpStatus: response.status },
91
+ );
92
+ if (payload.status !== "SUCCESS")
93
+ throw new DatarcError(
94
+ payload.message || `请求失败(HTTP ${response.status})`,
95
+ apiErrorCode(response.status),
96
+ { httpStatus: response.status, status: payload.status },
97
+ );
98
+ if (!Object.hasOwn(payload, "data"))
99
+ throw new DatarcError(
100
+ `服务返回无效响应信封(HTTP ${response.status})`,
101
+ "INVALID_RESPONSE",
102
+ { httpStatus: response.status },
103
+ );
104
+ return payload.data;
105
+ }
106
+ return { request };
107
+ }
108
+
109
+ export function errorJson(error) {
110
+ const trusted = [
111
+ "DatarcError",
112
+ "CaseModelError",
113
+ "DatasetPreflightError",
114
+ ].includes(error?.name);
115
+ const code =
116
+ trusted && typeof error?.code === "string"
117
+ ? error.code
118
+ : "UNEXPECTED_ERROR";
119
+ const details = safeErrorDetails(error?.details);
120
+ return {
121
+ code,
122
+ message: safeErrorMessage(error, code),
123
+ ...(Object.keys(details).length ? { details } : {}),
124
+ };
125
+ }
126
+
127
+ function apiErrorCode(status) {
128
+ if (status === 401) return "AUTHENTICATION_FAILED";
129
+ if (status === 403) return "PERMISSION_DENIED";
130
+ if (status === 429) return "RATE_LIMITED";
131
+ return "API_ERROR";
132
+ }
133
+
134
+ function safeErrorMessage(error, code) {
135
+ if (code === "NETWORK_ERROR") return "无法连接北极九章(datarc)服务";
136
+ if (code === "INVALID_RESPONSE") return "北极九章(datarc)服务返回无效响应";
137
+ if (
138
+ new Set([
139
+ "API_ERROR",
140
+ "AUTHENTICATION_FAILED",
141
+ "PERMISSION_DENIED",
142
+ "RATE_LIMITED",
143
+ ]).has(code)
144
+ )
145
+ return "北极九章(datarc)服务请求失败";
146
+ if (code === "UNEXPECTED_ERROR") return "操作失败";
147
+ return typeof error?.message === "string" && error.message
148
+ ? error.message
149
+ : "操作失败";
150
+ }
151
+
152
+ function safeErrorDetails(details) {
153
+ if (!details || typeof details !== "object" || Array.isArray(details))
154
+ return {};
155
+ const result = {};
156
+ for (const key of [
157
+ "artifact",
158
+ "conflictIndex",
159
+ "duplicateIndex",
160
+ "firstIndex",
161
+ "hash",
162
+ "httpStatus",
163
+ "index",
164
+ "kind",
165
+ "partial",
166
+ "phase",
167
+ "reloadRequired",
168
+ "resourceId",
169
+ "resourceKind",
170
+ "sourceIndex",
171
+ "sourceType",
172
+ "status",
173
+ "workspaceId",
174
+ ]) {
175
+ const value = details[key];
176
+ if (["string", "number", "boolean"].includes(typeof value))
177
+ result[key] = value;
178
+ }
179
+ return result;
180
+ }
@@ -1,57 +1,57 @@
1
- import { isRecord, requiredTrimmedString, uniquePairs } from "./shared.mjs";
2
-
3
- const UNSAFE_INTERPRETATION_KEYS = new Set([
4
- "cards",
5
- "data",
6
- "error",
7
- "history",
8
- "params",
9
- "prompt",
10
- "prompten",
11
- "qkey",
12
- "query",
13
- "reasoning",
14
- "result",
15
- "results",
16
- "secret",
17
- "secrets",
18
- "sql",
19
- ]);
20
-
21
- export function actionInterpretations(actions) {
22
- const pairs = [];
23
- for (const action of actions) collectSafePairs(action?.data, pairs);
24
- return uniquePairs(pairs);
25
- }
26
-
27
- function collectSafePairs(value, pairs, key = "") {
28
- if (value === null || value === undefined || unsafeKey(key)) return;
29
- if (Array.isArray(value)) {
30
- for (const item of value) collectSafePairs(item, pairs, key);
31
- return;
32
- }
33
- if (!isRecord(value)) return;
34
-
35
- const word = requiredTrimmedString(value.word);
36
- const prop = requiredTrimmedString(value.prop);
37
- if (word && prop) pairs.push({ word, prop });
38
- for (const [childKey, child] of Object.entries(value)) {
39
- if (childKey === "word" || childKey === "prop") continue;
40
- collectSafePairs(child, pairs, childKey);
41
- }
42
- }
43
-
44
- function unsafeKey(key) {
45
- const normalized = String(key)
46
- .replace(/[^a-z]/giu, "")
47
- .toLowerCase();
48
- return (
49
- UNSAFE_INTERPRETATION_KEYS.has(normalized) ||
50
- normalized.includes("secret") ||
51
- normalized.includes("password") ||
52
- normalized.includes("authorization") ||
53
- normalized.includes("apikey") ||
54
- normalized.includes("accesstoken") ||
55
- normalized.includes("refreshtoken")
56
- );
57
- }
1
+ import { isRecord, requiredTrimmedString, uniquePairs } from "./shared.mjs";
2
+
3
+ const UNSAFE_INTERPRETATION_KEYS = new Set([
4
+ "cards",
5
+ "data",
6
+ "error",
7
+ "history",
8
+ "params",
9
+ "prompt",
10
+ "prompten",
11
+ "qkey",
12
+ "query",
13
+ "reasoning",
14
+ "result",
15
+ "results",
16
+ "secret",
17
+ "secrets",
18
+ "sql",
19
+ ]);
20
+
21
+ export function actionInterpretations(actions) {
22
+ const pairs = [];
23
+ for (const action of actions) collectSafePairs(action?.data, pairs);
24
+ return uniquePairs(pairs);
25
+ }
26
+
27
+ function collectSafePairs(value, pairs, key = "") {
28
+ if (value === null || value === undefined || unsafeKey(key)) return;
29
+ if (Array.isArray(value)) {
30
+ for (const item of value) collectSafePairs(item, pairs, key);
31
+ return;
32
+ }
33
+ if (!isRecord(value)) return;
34
+
35
+ const word = requiredTrimmedString(value.word);
36
+ const prop = requiredTrimmedString(value.prop);
37
+ if (word && prop) pairs.push({ word, prop });
38
+ for (const [childKey, child] of Object.entries(value)) {
39
+ if (childKey === "word" || childKey === "prop") continue;
40
+ collectSafePairs(child, pairs, childKey);
41
+ }
42
+ }
43
+
44
+ function unsafeKey(key) {
45
+ const normalized = String(key)
46
+ .replace(/[^a-z]/giu, "")
47
+ .toLowerCase();
48
+ return (
49
+ UNSAFE_INTERPRETATION_KEYS.has(normalized) ||
50
+ normalized.includes("secret") ||
51
+ normalized.includes("password") ||
52
+ normalized.includes("authorization") ||
53
+ normalized.includes("apikey") ||
54
+ normalized.includes("accesstoken") ||
55
+ normalized.includes("refreshtoken")
56
+ );
57
+ }