@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.
- package/README.md +45 -10
- package/api-operations.js +404 -0
- package/client.js +452 -87
- package/cordis.patch.yml +4 -4
- package/entry/SKILL.md +34 -0
- package/icon.png +0 -0
- package/index.js +35 -47
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/native-api.mjs +326 -0
- package/native-contracts.js +195 -0
- package/native-execution.js +184 -0
- package/native-runner.mjs +107 -0
- package/native-state.js +67 -0
- package/native-tools.js +241 -0
- package/operations.js +1260 -0
- package/package.json +65 -51
- package/{skills → runtime}/datarc-access-permissions/SKILL.md +30 -30
- package/{skills → runtime}/datarc-access-permissions/references/api.md +31 -31
- package/{skills → runtime}/datarc-access-permissions/references/write-order.md +16 -16
- package/{skills → runtime}/datarc-analysis-report/SKILL.md +125 -125
- package/{skills → runtime}/datarc-analysis-report/agents/openai.yaml +6 -6
- package/{skills → runtime}/datarc-analysis-report/references/analyst-frameworks.md +215 -215
- package/{skills → runtime}/datarc-analysis-report/references/api-contracts.md +478 -478
- package/{skills → runtime}/datarc-analysis-report/references/direct-card-fallback-design.md +66 -66
- package/{skills → runtime}/datarc-analysis-report/references/human-in-the-loop.md +142 -142
- package/{skills → runtime}/datarc-analysis-report/references/loop-personalization-policy.md +138 -138
- package/{skills → runtime}/datarc-analysis-report/references/manifest-example.json +779 -779
- package/{skills → runtime}/datarc-analysis-report/references/narrative-schema.md +160 -160
- package/{skills → runtime}/datarc-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-analysis-report/scripts/run_analysis_report.py +2225 -2225
- package/{skills → runtime}/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -1914
- package/{skills → runtime}/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -5295
- package/{skills → runtime}/datarc-data-search/SKILL.md +243 -243
- package/{skills → runtime}/datarc-data-search/scripts/calculate.py +116 -116
- package/{skills → runtime}/datarc-data-search/scripts/data-search.mjs +628 -628
- package/{skills/datarc-dataseek-search → runtime/datarc-data-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-data-search/scripts/search-result.mjs +211 -211
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/SKILL.md +59 -59
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -36
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -30
- package/{skills/datarc-data-search → runtime/datarc-dataseek-batch-evaluation}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -1020
- package/{skills → runtime}/datarc-dataseek-search/SKILL.md +96 -96
- package/{skills/datarc-dataseek-batch-evaluation → runtime/datarc-dataseek-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -257
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/SKILL.md +44 -44
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/evals/evals.json +165 -165
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/dataset.md +77 -77
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -93
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/interventions.md +64 -64
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -47
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/rollback.md +11 -11
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -95
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -29
- package/{skills → runtime}/datarc-dataseek-testset-generation/SKILL.md +47 -47
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -526
- package/{skills → runtime}/datarc-datasource/SKILL.md +97 -97
- package/{skills → runtime}/datarc-oauth/SKILL.md +50 -50
- package/{skills → runtime}/datarc-oauth/scripts/auth.mjs +192 -192
- package/{skills → runtime}/datarc-oauth/scripts/credentials.mjs +237 -237
- package/{skills → runtime}/datarc-report-add-card/SKILL.md +90 -90
- package/{skills → runtime}/datarc-report-add-card/agents/openai.yaml +4 -4
- package/runtime/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
- package/{skills → runtime}/datarc-report-add-card/scripts/report-card.mjs +439 -439
- package/{skills → runtime}/datarc-semantic-alias/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias-plan.mjs +422 -422
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-calibration/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -683
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-core/SKILL.md +12 -12
- package/{skills → runtime}/datarc-semantic-core/scripts/artifact-journal.mjs +853 -830
- package/{skills → runtime}/datarc-semantic-core/scripts/canonical.mjs +48 -48
- package/{skills → runtime}/datarc-semantic-core/scripts/case-model.mjs +608 -608
- package/{skills → runtime}/datarc-semantic-core/scripts/cli.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/datarc-client.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -57
- package/{skills → runtime}/datarc-semantic-core/scripts/interventions.mjs +693 -693
- package/{skills → runtime}/datarc-semantic-core/scripts/live-resolution.mjs +305 -305
- package/{skills → runtime}/datarc-semantic-core/scripts/model-scope.mjs +49 -49
- package/{skills → runtime}/datarc-semantic-core/scripts/reproduction.mjs +330 -330
- package/{skills → runtime}/datarc-semantic-core/scripts/semantic-cli.mjs +799 -740
- package/{skills → runtime}/datarc-semantic-core/scripts/shared.mjs +312 -312
- package/{skills → runtime}/datarc-semantic-core/scripts/verification.mjs +1111 -1014
- package/{skills → runtime}/datarc-semantic-dataset/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -749
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -813
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-knowledge/SKILL.md +38 -38
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -61
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-generation.json +16 -16
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -347
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -848
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -31
- package/{skills → runtime}/datarc-semantic-prompt/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt-plan.mjs +598 -447
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt.mjs +15 -15
- package/{skills → runtime}/datarc-semantic-synonym/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -688
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym.mjs +11 -11
- package/{skills → runtime}/datarc-viz-analysis-report/SKILL.md +108 -108
- package/{skills → runtime}/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -8
- package/{skills → runtime}/datarc-viz-analysis-report/assets/echarts.min.js +45 -45
- package/{skills → runtime}/datarc-viz-analysis-report/references/api-contracts.md +163 -163
- package/{skills → runtime}/datarc-viz-analysis-report/references/derivation-log.md +157 -157
- package/{skills → runtime}/datarc-viz-analysis-report/references/evidence-framework.md +76 -76
- package/{skills → runtime}/datarc-viz-analysis-report/references/html-template.md +92 -92
- package/{skills → runtime}/datarc-viz-analysis-report/references/provenance-format.md +56 -56
- package/{skills → runtime}/datarc-viz-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -1708
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -964
- package/{skills → runtime}/datarc-workspace-configuration/SKILL.md +59 -59
- package/{skills → runtime}/datarc-workspace-configuration/references/artifacts.md +75 -75
- package/{skills → runtime}/datarc-workspace-configuration/references/verification.md +20 -20
- package/{skills → runtime}/datarc-workspace-configuration/scripts/configuration.mjs +722 -662
- package/{skills → runtime}/datarc-workspace-context/SKILL.md +43 -43
- package/{skills → runtime}/datarc-workspace-context/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-context/scripts/datarc-client.mjs +31 -31
- package/{skills → runtime}/datarc-workspace-context/scripts/query-display.mjs +114 -114
- package/{skills → runtime}/datarc-workspace-context/scripts/workspace-context.mjs +58 -58
- package/{skills → runtime}/datarc-workspace-custom-tables/SKILL.md +89 -89
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -165
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -601
- package/{skills → runtime}/datarc-workspace-keywords/SKILL.md +197 -197
- package/{skills → runtime}/datarc-workspace-keywords/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-keywords/references/api-fields.md +79 -79
- package/{skills → runtime}/datarc-workspace-keywords/references/derived-measures.md +177 -177
- package/{skills → runtime}/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -145
- package/{skills → runtime}/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -2421
- package/{skills → runtime}/datarc-workspace-membership/SKILL.md +29 -29
- package/{skills → runtime}/datarc-workspace-membership/references/api.md +19 -19
- package/{skills → runtime}/datarc-workspace-modeling/SKILL.md +209 -209
- package/{skills → runtime}/datarc-workspace-modeling/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-modeling/references/join-preview.md +38 -38
- package/{skills → runtime}/datarc-workspace-modeling/references/model-plan.md +300 -300
- package/{skills → runtime}/datarc-workspace-modeling/references/model-tags.md +95 -95
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-contract.json +29 -29
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -2423
- package/{skills → runtime}/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -137
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -238
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -1261
- package/skills-provider.js +51 -0
- package/workflow-index.json +434 -0
- package/icon.svg +0 -4
- package/skills/datarc-report-add-card/scripts/datarc-client.mjs +0 -464
- package/skills-index.json +0 -194
|
@@ -1,305 +1,305 @@
|
|
|
1
|
-
import { resolveTarget, validateCaseSet } from "./case-model.mjs";
|
|
2
|
-
import { hashArtifactValue } from "./canonical.mjs";
|
|
3
|
-
import {
|
|
4
|
-
canonicalPositiveInteger,
|
|
5
|
-
fail,
|
|
6
|
-
isRecord,
|
|
7
|
-
isServerChineseCharacter,
|
|
8
|
-
requireClient,
|
|
9
|
-
safeOpaqueIdentifier,
|
|
10
|
-
} from "./shared.mjs";
|
|
11
|
-
|
|
12
|
-
const INPUT_KEYS = new Set(["workspaceId", "cases", "selections"]);
|
|
13
|
-
const KIND_ALIASES = new Map([
|
|
14
|
-
["dimension", "dimension"],
|
|
15
|
-
["dimensions", "dimension"],
|
|
16
|
-
["measure", "measure"],
|
|
17
|
-
["measures", "measure"],
|
|
18
|
-
["time_series", "time_series"],
|
|
19
|
-
["timeseries", "time_series"],
|
|
20
|
-
["timeSeries", "time_series"],
|
|
21
|
-
["dataset", "dataset"],
|
|
22
|
-
["datasets", "dataset"],
|
|
23
|
-
["knowledge", "knowledge"],
|
|
24
|
-
["model", "model"],
|
|
25
|
-
["models", "model"],
|
|
26
|
-
]);
|
|
27
|
-
const ALL_KINDS = [
|
|
28
|
-
"dimension",
|
|
29
|
-
"measure",
|
|
30
|
-
"time_series",
|
|
31
|
-
"dataset",
|
|
32
|
-
"knowledge",
|
|
33
|
-
"model",
|
|
34
|
-
];
|
|
35
|
-
const NAME_LIMITS = new Map([
|
|
36
|
-
["dimension", 255],
|
|
37
|
-
["measure", 255],
|
|
38
|
-
["time_series", 255],
|
|
39
|
-
["dataset", 120],
|
|
40
|
-
["knowledge", 256],
|
|
41
|
-
["model", 255],
|
|
42
|
-
]);
|
|
43
|
-
const RESERVED_SPACE = "\u1f6e";
|
|
44
|
-
|
|
45
|
-
export function normalizeLiveResolutionInput(input) {
|
|
46
|
-
if (!isRecord(input))
|
|
47
|
-
fail(
|
|
48
|
-
"INVALID_LIVE_RESOLUTION_INPUT",
|
|
49
|
-
"live resolution input must be an object",
|
|
50
|
-
);
|
|
51
|
-
if (Object.keys(input).some((key) => !INPUT_KEYS.has(key)))
|
|
52
|
-
fail(
|
|
53
|
-
"INVALID_LIVE_RESOLUTION_INPUT",
|
|
54
|
-
"live resolution input contains unsupported fields",
|
|
55
|
-
);
|
|
56
|
-
if (!Number.isSafeInteger(input.workspaceId) || input.workspaceId <= 0)
|
|
57
|
-
fail(
|
|
58
|
-
"INVALID_LIVE_RESOLUTION_INPUT",
|
|
59
|
-
"workspaceId must be a positive integer",
|
|
60
|
-
);
|
|
61
|
-
if (input.selections !== undefined && !Array.isArray(input.selections))
|
|
62
|
-
fail("INVALID_LIVE_RESOLUTION_INPUT", "selections must be an array");
|
|
63
|
-
|
|
64
|
-
prevalidateCaseKinds(input.cases);
|
|
65
|
-
const cases = validateCaseSet(input.cases).map((semanticCase, index) => {
|
|
66
|
-
const sourceIndex =
|
|
67
|
-
Number.isSafeInteger(semanticCase.sourceIndex) &&
|
|
68
|
-
semanticCase.sourceIndex >= 0
|
|
69
|
-
? semanticCase.sourceIndex
|
|
70
|
-
: index;
|
|
71
|
-
const suppliedCaseId = semanticCase.caseId;
|
|
72
|
-
if (
|
|
73
|
-
suppliedCaseId !== undefined &&
|
|
74
|
-
(typeof suppliedCaseId !== "string" || !suppliedCaseId.trim())
|
|
75
|
-
)
|
|
76
|
-
fail("INVALID_LIVE_RESOLUTION_INPUT", "caseId must be a nonempty string");
|
|
77
|
-
return {
|
|
78
|
-
...semanticCase,
|
|
79
|
-
sourceIndex,
|
|
80
|
-
caseId:
|
|
81
|
-
suppliedCaseId === undefined
|
|
82
|
-
? `${semanticCase.sourceType}:${sourceIndex}`
|
|
83
|
-
: suppliedCaseId.trim(),
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
const caseIds = new Set();
|
|
87
|
-
for (const semanticCase of cases) {
|
|
88
|
-
if (caseIds.has(semanticCase.caseId))
|
|
89
|
-
fail("INVALID_LIVE_RESOLUTION_INPUT", "caseId must be unique");
|
|
90
|
-
caseIds.add(semanticCase.caseId);
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
workspaceId: input.workspaceId,
|
|
94
|
-
cases,
|
|
95
|
-
...(input.selections === undefined
|
|
96
|
-
? {}
|
|
97
|
-
: { selections: structuredClone(input.selections) }),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function prevalidateCaseKinds(cases) {
|
|
102
|
-
if (!Array.isArray(cases)) return;
|
|
103
|
-
for (const semanticCase of cases) {
|
|
104
|
-
const kind = semanticCase?.targetHint?.kind;
|
|
105
|
-
if (kind !== undefined && kind !== null && String(kind).trim())
|
|
106
|
-
normalizeKind(kind);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function liveResolutionJournalRequest(input) {
|
|
111
|
-
const normalized = normalizeLiveResolutionInput(input);
|
|
112
|
-
return {
|
|
113
|
-
workspaceId: normalized.workspaceId,
|
|
114
|
-
caseCount: normalized.cases.length,
|
|
115
|
-
cases: normalized.cases.map((semanticCase) => ({
|
|
116
|
-
caseId: semanticCase.caseId,
|
|
117
|
-
sourceType: semanticCase.sourceType,
|
|
118
|
-
kind: semanticCase.targetHint.kind
|
|
119
|
-
? normalizeKind(semanticCase.targetHint.kind)
|
|
120
|
-
: null,
|
|
121
|
-
targetHintHash: hashArtifactValue(semanticCase.targetHint),
|
|
122
|
-
})),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function resolveLiveCases(client, input) {
|
|
127
|
-
const normalized = normalizeLiveResolutionInput(input);
|
|
128
|
-
requireClient(client);
|
|
129
|
-
const kinds = requiredKinds(normalized.cases);
|
|
130
|
-
const catalog = [];
|
|
131
|
-
for (const kind of kinds)
|
|
132
|
-
catalog.push(
|
|
133
|
-
...(await loadCompactCatalogKind(client, normalized.workspaceId, kind)),
|
|
134
|
-
);
|
|
135
|
-
assertUniqueIdentities(catalog);
|
|
136
|
-
return {
|
|
137
|
-
workspaceId: normalized.workspaceId,
|
|
138
|
-
resolutions: normalized.cases.map((semanticCase, index) => ({
|
|
139
|
-
sourceIndex: semanticCase.sourceIndex,
|
|
140
|
-
caseId: semanticCase.caseId,
|
|
141
|
-
resolution: resolveTarget(
|
|
142
|
-
semanticCase.targetHint,
|
|
143
|
-
catalog,
|
|
144
|
-
normalized.selections?.[index] ?? {},
|
|
145
|
-
),
|
|
146
|
-
})),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function requiredKinds(cases) {
|
|
151
|
-
if (cases.some(({ targetHint }) => targetHint.kind === undefined))
|
|
152
|
-
return ALL_KINDS;
|
|
153
|
-
return ALL_KINDS.filter((kind) =>
|
|
154
|
-
cases.some(({ targetHint }) => normalizeKind(targetHint.kind) === kind),
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async function loadCompactCatalogKind(client, workspaceId, kind) {
|
|
159
|
-
const prefix = `/api/v2/admin-projects/${workspaceId}`;
|
|
160
|
-
if (kind === "dimension")
|
|
161
|
-
return (await directList(client, `${prefix}/dimensions/`)).map((resource) =>
|
|
162
|
-
compactField(resource, kind, "d"),
|
|
163
|
-
);
|
|
164
|
-
if (kind === "measure")
|
|
165
|
-
return (await directList(client, `${prefix}/measures/`)).map((resource) =>
|
|
166
|
-
compactField(resource, kind, "m"),
|
|
167
|
-
);
|
|
168
|
-
if (kind === "time_series")
|
|
169
|
-
return (await directList(client, `${prefix}/time-series/`)).map(
|
|
170
|
-
(resource) => compactField(resource, kind, "t"),
|
|
171
|
-
);
|
|
172
|
-
if (kind === "dataset")
|
|
173
|
-
return completePagedList(
|
|
174
|
-
client,
|
|
175
|
-
`/api/v3/admin-projects/${workspaceId}/datasets/`,
|
|
176
|
-
(resource) => compactNamed(resource, kind, "ds"),
|
|
177
|
-
);
|
|
178
|
-
if (kind === "knowledge")
|
|
179
|
-
return completePagedList(
|
|
180
|
-
client,
|
|
181
|
-
`/api/v3/admin-projects/${workspaceId}/corpus/`,
|
|
182
|
-
(resource) => compactNamed(resource, kind),
|
|
183
|
-
);
|
|
184
|
-
if (kind === "model")
|
|
185
|
-
return (await directList(client, `${prefix}/models/`)).map(compactModel);
|
|
186
|
-
fail("INVALID_LIVE_CATALOG", "live catalog kind is not supported");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
async function directList(client, path) {
|
|
190
|
-
const response = await client.request("GET", path);
|
|
191
|
-
if (!Array.isArray(response))
|
|
192
|
-
fail("INVALID_LIVE_CATALOG", "live catalog response must be an array");
|
|
193
|
-
return response;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async function completePagedList(client, path, compact) {
|
|
197
|
-
const total = await client.request("GET", path, { query: { count: 1 } });
|
|
198
|
-
if (!Number.isSafeInteger(total) || total < 0)
|
|
199
|
-
fail("INCOMPLETE_LIVE_CATALOG", "live catalog count is invalid");
|
|
200
|
-
const compactRows = [];
|
|
201
|
-
const limit = 100;
|
|
202
|
-
let offset = 0;
|
|
203
|
-
while (offset < total) {
|
|
204
|
-
const expected = Math.min(limit, total - offset);
|
|
205
|
-
const page = await client.request("GET", path, {
|
|
206
|
-
query: { offset, limit },
|
|
207
|
-
});
|
|
208
|
-
if (!Array.isArray(page) || page.length !== expected)
|
|
209
|
-
fail("INCOMPLETE_LIVE_CATALOG", "live catalog pagination is incomplete");
|
|
210
|
-
compactRows.push(...page.map(compact));
|
|
211
|
-
offset += page.length;
|
|
212
|
-
}
|
|
213
|
-
return compactRows;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function compactField(resource, kind, prefix) {
|
|
217
|
-
if (!isRecord(resource))
|
|
218
|
-
fail("INVALID_LIVE_CATALOG", "live catalog resource is invalid");
|
|
219
|
-
const id = canonicalPositiveInteger(resource.id);
|
|
220
|
-
const names = compactNames(resource.names, kind);
|
|
221
|
-
if (id === null || !names)
|
|
222
|
-
fail("INVALID_LIVE_CATALOG", "live catalog resource identity is invalid");
|
|
223
|
-
return { kind, id, names, prop: `${prefix}${id}` };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function compactNamed(resource, kind, propPrefix) {
|
|
227
|
-
if (!isRecord(resource))
|
|
228
|
-
fail("INVALID_LIVE_CATALOG", "live catalog resource is invalid");
|
|
229
|
-
const id = canonicalPositiveInteger(resource.id);
|
|
230
|
-
const name = safeName(resource.name, kind);
|
|
231
|
-
if (id === null || !name)
|
|
232
|
-
fail("INVALID_LIVE_CATALOG", "live catalog resource identity is invalid");
|
|
233
|
-
return {
|
|
234
|
-
kind,
|
|
235
|
-
id,
|
|
236
|
-
names: [name],
|
|
237
|
-
...(propPrefix === undefined ? {} : { prop: `${propPrefix}${id}` }),
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function compactModel(resource) {
|
|
242
|
-
if (!isRecord(resource))
|
|
243
|
-
fail("INVALID_LIVE_CATALOG", "live catalog resource is invalid");
|
|
244
|
-
const id = safeOpaqueIdentifier(resource.uid);
|
|
245
|
-
const name = safeName(resource.name, "model");
|
|
246
|
-
if (!id || !name)
|
|
247
|
-
fail("INVALID_LIVE_CATALOG", "live catalog resource identity is invalid");
|
|
248
|
-
return { kind: "model", id, names: [name] };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function assertUniqueIdentities(catalog) {
|
|
252
|
-
const identities = new Set();
|
|
253
|
-
const props = new Set();
|
|
254
|
-
for (const resource of catalog) {
|
|
255
|
-
const identity = `${resource.kind}:${String(resource.id)}`;
|
|
256
|
-
if (
|
|
257
|
-
identities.has(identity) ||
|
|
258
|
-
(resource.prop !== undefined && props.has(resource.prop))
|
|
259
|
-
)
|
|
260
|
-
fail("DUPLICATE_LIVE_IDENTITY", "live catalog identity is duplicated");
|
|
261
|
-
identities.add(identity);
|
|
262
|
-
if (resource.prop !== undefined) props.add(resource.prop);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function compactNames(value, kind) {
|
|
267
|
-
if (!Array.isArray(value) || value.length === 0) return null;
|
|
268
|
-
const names = value.map((name) => safeName(name, kind));
|
|
269
|
-
return names.every(Boolean) ? names : null;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function safeName(value, kind) {
|
|
273
|
-
if (typeof value !== "string") return null;
|
|
274
|
-
const name = value.trim();
|
|
275
|
-
const limit = NAME_LIMITS.get(kind);
|
|
276
|
-
if (
|
|
277
|
-
!name ||
|
|
278
|
-
!limit ||
|
|
279
|
-
[...name].length > limit ||
|
|
280
|
-
/[\u0000-\u001f\u007f]/u.test(name)
|
|
281
|
-
)
|
|
282
|
-
return null;
|
|
283
|
-
return kind !== "dataset" || validDatasetName(name) ? name : null;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function validDatasetName(name) {
|
|
287
|
-
if (/^\p{Decimal_Number}+$/u.test(name.normalize("NFKC")))
|
|
288
|
-
return [...name].length >= 6;
|
|
289
|
-
let hasLetterOrChinese = false;
|
|
290
|
-
for (const character of name) {
|
|
291
|
-
const asciiLetter = /^[A-Za-z]$/u.test(character);
|
|
292
|
-
const allowedAscii = /^[A-Za-z0-9/\\_.+\- ]$/u.test(character);
|
|
293
|
-
const chinese = isServerChineseCharacter(character);
|
|
294
|
-
if (!allowedAscii && character !== RESERVED_SPACE && !chinese) return false;
|
|
295
|
-
if (asciiLetter || chinese) hasLetterOrChinese = true;
|
|
296
|
-
}
|
|
297
|
-
return hasLetterOrChinese;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function normalizeKind(value) {
|
|
301
|
-
const normalized = KIND_ALIASES.get(String(value).trim());
|
|
302
|
-
if (!normalized)
|
|
303
|
-
fail("INVALID_LIVE_RESOLUTION_INPUT", "resource kind is not supported");
|
|
304
|
-
return normalized;
|
|
305
|
-
}
|
|
1
|
+
import { resolveTarget, validateCaseSet } from "./case-model.mjs";
|
|
2
|
+
import { hashArtifactValue } from "./canonical.mjs";
|
|
3
|
+
import {
|
|
4
|
+
canonicalPositiveInteger,
|
|
5
|
+
fail,
|
|
6
|
+
isRecord,
|
|
7
|
+
isServerChineseCharacter,
|
|
8
|
+
requireClient,
|
|
9
|
+
safeOpaqueIdentifier,
|
|
10
|
+
} from "./shared.mjs";
|
|
11
|
+
|
|
12
|
+
const INPUT_KEYS = new Set(["workspaceId", "cases", "selections"]);
|
|
13
|
+
const KIND_ALIASES = new Map([
|
|
14
|
+
["dimension", "dimension"],
|
|
15
|
+
["dimensions", "dimension"],
|
|
16
|
+
["measure", "measure"],
|
|
17
|
+
["measures", "measure"],
|
|
18
|
+
["time_series", "time_series"],
|
|
19
|
+
["timeseries", "time_series"],
|
|
20
|
+
["timeSeries", "time_series"],
|
|
21
|
+
["dataset", "dataset"],
|
|
22
|
+
["datasets", "dataset"],
|
|
23
|
+
["knowledge", "knowledge"],
|
|
24
|
+
["model", "model"],
|
|
25
|
+
["models", "model"],
|
|
26
|
+
]);
|
|
27
|
+
const ALL_KINDS = [
|
|
28
|
+
"dimension",
|
|
29
|
+
"measure",
|
|
30
|
+
"time_series",
|
|
31
|
+
"dataset",
|
|
32
|
+
"knowledge",
|
|
33
|
+
"model",
|
|
34
|
+
];
|
|
35
|
+
const NAME_LIMITS = new Map([
|
|
36
|
+
["dimension", 255],
|
|
37
|
+
["measure", 255],
|
|
38
|
+
["time_series", 255],
|
|
39
|
+
["dataset", 120],
|
|
40
|
+
["knowledge", 256],
|
|
41
|
+
["model", 255],
|
|
42
|
+
]);
|
|
43
|
+
const RESERVED_SPACE = "\u1f6e";
|
|
44
|
+
|
|
45
|
+
export function normalizeLiveResolutionInput(input) {
|
|
46
|
+
if (!isRecord(input))
|
|
47
|
+
fail(
|
|
48
|
+
"INVALID_LIVE_RESOLUTION_INPUT",
|
|
49
|
+
"live resolution input must be an object",
|
|
50
|
+
);
|
|
51
|
+
if (Object.keys(input).some((key) => !INPUT_KEYS.has(key)))
|
|
52
|
+
fail(
|
|
53
|
+
"INVALID_LIVE_RESOLUTION_INPUT",
|
|
54
|
+
"live resolution input contains unsupported fields",
|
|
55
|
+
);
|
|
56
|
+
if (!Number.isSafeInteger(input.workspaceId) || input.workspaceId <= 0)
|
|
57
|
+
fail(
|
|
58
|
+
"INVALID_LIVE_RESOLUTION_INPUT",
|
|
59
|
+
"workspaceId must be a positive integer",
|
|
60
|
+
);
|
|
61
|
+
if (input.selections !== undefined && !Array.isArray(input.selections))
|
|
62
|
+
fail("INVALID_LIVE_RESOLUTION_INPUT", "selections must be an array");
|
|
63
|
+
|
|
64
|
+
prevalidateCaseKinds(input.cases);
|
|
65
|
+
const cases = validateCaseSet(input.cases).map((semanticCase, index) => {
|
|
66
|
+
const sourceIndex =
|
|
67
|
+
Number.isSafeInteger(semanticCase.sourceIndex) &&
|
|
68
|
+
semanticCase.sourceIndex >= 0
|
|
69
|
+
? semanticCase.sourceIndex
|
|
70
|
+
: index;
|
|
71
|
+
const suppliedCaseId = semanticCase.caseId;
|
|
72
|
+
if (
|
|
73
|
+
suppliedCaseId !== undefined &&
|
|
74
|
+
(typeof suppliedCaseId !== "string" || !suppliedCaseId.trim())
|
|
75
|
+
)
|
|
76
|
+
fail("INVALID_LIVE_RESOLUTION_INPUT", "caseId must be a nonempty string");
|
|
77
|
+
return {
|
|
78
|
+
...semanticCase,
|
|
79
|
+
sourceIndex,
|
|
80
|
+
caseId:
|
|
81
|
+
suppliedCaseId === undefined
|
|
82
|
+
? `${semanticCase.sourceType}:${sourceIndex}`
|
|
83
|
+
: suppliedCaseId.trim(),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const caseIds = new Set();
|
|
87
|
+
for (const semanticCase of cases) {
|
|
88
|
+
if (caseIds.has(semanticCase.caseId))
|
|
89
|
+
fail("INVALID_LIVE_RESOLUTION_INPUT", "caseId must be unique");
|
|
90
|
+
caseIds.add(semanticCase.caseId);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
workspaceId: input.workspaceId,
|
|
94
|
+
cases,
|
|
95
|
+
...(input.selections === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: { selections: structuredClone(input.selections) }),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function prevalidateCaseKinds(cases) {
|
|
102
|
+
if (!Array.isArray(cases)) return;
|
|
103
|
+
for (const semanticCase of cases) {
|
|
104
|
+
const kind = semanticCase?.targetHint?.kind;
|
|
105
|
+
if (kind !== undefined && kind !== null && String(kind).trim())
|
|
106
|
+
normalizeKind(kind);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function liveResolutionJournalRequest(input) {
|
|
111
|
+
const normalized = normalizeLiveResolutionInput(input);
|
|
112
|
+
return {
|
|
113
|
+
workspaceId: normalized.workspaceId,
|
|
114
|
+
caseCount: normalized.cases.length,
|
|
115
|
+
cases: normalized.cases.map((semanticCase) => ({
|
|
116
|
+
caseId: semanticCase.caseId,
|
|
117
|
+
sourceType: semanticCase.sourceType,
|
|
118
|
+
kind: semanticCase.targetHint.kind
|
|
119
|
+
? normalizeKind(semanticCase.targetHint.kind)
|
|
120
|
+
: null,
|
|
121
|
+
targetHintHash: hashArtifactValue(semanticCase.targetHint),
|
|
122
|
+
})),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function resolveLiveCases(client, input) {
|
|
127
|
+
const normalized = normalizeLiveResolutionInput(input);
|
|
128
|
+
requireClient(client);
|
|
129
|
+
const kinds = requiredKinds(normalized.cases);
|
|
130
|
+
const catalog = [];
|
|
131
|
+
for (const kind of kinds)
|
|
132
|
+
catalog.push(
|
|
133
|
+
...(await loadCompactCatalogKind(client, normalized.workspaceId, kind)),
|
|
134
|
+
);
|
|
135
|
+
assertUniqueIdentities(catalog);
|
|
136
|
+
return {
|
|
137
|
+
workspaceId: normalized.workspaceId,
|
|
138
|
+
resolutions: normalized.cases.map((semanticCase, index) => ({
|
|
139
|
+
sourceIndex: semanticCase.sourceIndex,
|
|
140
|
+
caseId: semanticCase.caseId,
|
|
141
|
+
resolution: resolveTarget(
|
|
142
|
+
semanticCase.targetHint,
|
|
143
|
+
catalog,
|
|
144
|
+
normalized.selections?.[index] ?? {},
|
|
145
|
+
),
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function requiredKinds(cases) {
|
|
151
|
+
if (cases.some(({ targetHint }) => targetHint.kind === undefined))
|
|
152
|
+
return ALL_KINDS;
|
|
153
|
+
return ALL_KINDS.filter((kind) =>
|
|
154
|
+
cases.some(({ targetHint }) => normalizeKind(targetHint.kind) === kind),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function loadCompactCatalogKind(client, workspaceId, kind) {
|
|
159
|
+
const prefix = `/api/v2/admin-projects/${workspaceId}`;
|
|
160
|
+
if (kind === "dimension")
|
|
161
|
+
return (await directList(client, `${prefix}/dimensions/`)).map((resource) =>
|
|
162
|
+
compactField(resource, kind, "d"),
|
|
163
|
+
);
|
|
164
|
+
if (kind === "measure")
|
|
165
|
+
return (await directList(client, `${prefix}/measures/`)).map((resource) =>
|
|
166
|
+
compactField(resource, kind, "m"),
|
|
167
|
+
);
|
|
168
|
+
if (kind === "time_series")
|
|
169
|
+
return (await directList(client, `${prefix}/time-series/`)).map(
|
|
170
|
+
(resource) => compactField(resource, kind, "t"),
|
|
171
|
+
);
|
|
172
|
+
if (kind === "dataset")
|
|
173
|
+
return completePagedList(
|
|
174
|
+
client,
|
|
175
|
+
`/api/v3/admin-projects/${workspaceId}/datasets/`,
|
|
176
|
+
(resource) => compactNamed(resource, kind, "ds"),
|
|
177
|
+
);
|
|
178
|
+
if (kind === "knowledge")
|
|
179
|
+
return completePagedList(
|
|
180
|
+
client,
|
|
181
|
+
`/api/v3/admin-projects/${workspaceId}/corpus/`,
|
|
182
|
+
(resource) => compactNamed(resource, kind),
|
|
183
|
+
);
|
|
184
|
+
if (kind === "model")
|
|
185
|
+
return (await directList(client, `${prefix}/models/`)).map(compactModel);
|
|
186
|
+
fail("INVALID_LIVE_CATALOG", "live catalog kind is not supported");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function directList(client, path) {
|
|
190
|
+
const response = await client.request("GET", path);
|
|
191
|
+
if (!Array.isArray(response))
|
|
192
|
+
fail("INVALID_LIVE_CATALOG", "live catalog response must be an array");
|
|
193
|
+
return response;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function completePagedList(client, path, compact) {
|
|
197
|
+
const total = await client.request("GET", path, { query: { count: 1 } });
|
|
198
|
+
if (!Number.isSafeInteger(total) || total < 0)
|
|
199
|
+
fail("INCOMPLETE_LIVE_CATALOG", "live catalog count is invalid");
|
|
200
|
+
const compactRows = [];
|
|
201
|
+
const limit = 100;
|
|
202
|
+
let offset = 0;
|
|
203
|
+
while (offset < total) {
|
|
204
|
+
const expected = Math.min(limit, total - offset);
|
|
205
|
+
const page = await client.request("GET", path, {
|
|
206
|
+
query: { offset, limit },
|
|
207
|
+
});
|
|
208
|
+
if (!Array.isArray(page) || page.length !== expected)
|
|
209
|
+
fail("INCOMPLETE_LIVE_CATALOG", "live catalog pagination is incomplete");
|
|
210
|
+
compactRows.push(...page.map(compact));
|
|
211
|
+
offset += page.length;
|
|
212
|
+
}
|
|
213
|
+
return compactRows;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function compactField(resource, kind, prefix) {
|
|
217
|
+
if (!isRecord(resource))
|
|
218
|
+
fail("INVALID_LIVE_CATALOG", "live catalog resource is invalid");
|
|
219
|
+
const id = canonicalPositiveInteger(resource.id);
|
|
220
|
+
const names = compactNames(resource.names, kind);
|
|
221
|
+
if (id === null || !names)
|
|
222
|
+
fail("INVALID_LIVE_CATALOG", "live catalog resource identity is invalid");
|
|
223
|
+
return { kind, id, names, prop: `${prefix}${id}` };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function compactNamed(resource, kind, propPrefix) {
|
|
227
|
+
if (!isRecord(resource))
|
|
228
|
+
fail("INVALID_LIVE_CATALOG", "live catalog resource is invalid");
|
|
229
|
+
const id = canonicalPositiveInteger(resource.id);
|
|
230
|
+
const name = safeName(resource.name, kind);
|
|
231
|
+
if (id === null || !name)
|
|
232
|
+
fail("INVALID_LIVE_CATALOG", "live catalog resource identity is invalid");
|
|
233
|
+
return {
|
|
234
|
+
kind,
|
|
235
|
+
id,
|
|
236
|
+
names: [name],
|
|
237
|
+
...(propPrefix === undefined ? {} : { prop: `${propPrefix}${id}` }),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function compactModel(resource) {
|
|
242
|
+
if (!isRecord(resource))
|
|
243
|
+
fail("INVALID_LIVE_CATALOG", "live catalog resource is invalid");
|
|
244
|
+
const id = safeOpaqueIdentifier(resource.uid);
|
|
245
|
+
const name = safeName(resource.name, "model");
|
|
246
|
+
if (!id || !name)
|
|
247
|
+
fail("INVALID_LIVE_CATALOG", "live catalog resource identity is invalid");
|
|
248
|
+
return { kind: "model", id, names: [name] };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function assertUniqueIdentities(catalog) {
|
|
252
|
+
const identities = new Set();
|
|
253
|
+
const props = new Set();
|
|
254
|
+
for (const resource of catalog) {
|
|
255
|
+
const identity = `${resource.kind}:${String(resource.id)}`;
|
|
256
|
+
if (
|
|
257
|
+
identities.has(identity) ||
|
|
258
|
+
(resource.prop !== undefined && props.has(resource.prop))
|
|
259
|
+
)
|
|
260
|
+
fail("DUPLICATE_LIVE_IDENTITY", "live catalog identity is duplicated");
|
|
261
|
+
identities.add(identity);
|
|
262
|
+
if (resource.prop !== undefined) props.add(resource.prop);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function compactNames(value, kind) {
|
|
267
|
+
if (!Array.isArray(value) || value.length === 0) return null;
|
|
268
|
+
const names = value.map((name) => safeName(name, kind));
|
|
269
|
+
return names.every(Boolean) ? names : null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function safeName(value, kind) {
|
|
273
|
+
if (typeof value !== "string") return null;
|
|
274
|
+
const name = value.trim();
|
|
275
|
+
const limit = NAME_LIMITS.get(kind);
|
|
276
|
+
if (
|
|
277
|
+
!name ||
|
|
278
|
+
!limit ||
|
|
279
|
+
[...name].length > limit ||
|
|
280
|
+
/[\u0000-\u001f\u007f]/u.test(name)
|
|
281
|
+
)
|
|
282
|
+
return null;
|
|
283
|
+
return kind !== "dataset" || validDatasetName(name) ? name : null;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function validDatasetName(name) {
|
|
287
|
+
if (/^\p{Decimal_Number}+$/u.test(name.normalize("NFKC")))
|
|
288
|
+
return [...name].length >= 6;
|
|
289
|
+
let hasLetterOrChinese = false;
|
|
290
|
+
for (const character of name) {
|
|
291
|
+
const asciiLetter = /^[A-Za-z]$/u.test(character);
|
|
292
|
+
const allowedAscii = /^[A-Za-z0-9/\\_.+\- ]$/u.test(character);
|
|
293
|
+
const chinese = isServerChineseCharacter(character);
|
|
294
|
+
if (!allowedAscii && character !== RESERVED_SPACE && !chinese) return false;
|
|
295
|
+
if (asciiLetter || chinese) hasLetterOrChinese = true;
|
|
296
|
+
}
|
|
297
|
+
return hasLetterOrChinese;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function normalizeKind(value) {
|
|
301
|
+
const normalized = KIND_ALIASES.get(String(value).trim());
|
|
302
|
+
if (!normalized)
|
|
303
|
+
fail("INVALID_LIVE_RESOLUTION_INPUT", "resource kind is not supported");
|
|
304
|
+
return normalized;
|
|
305
|
+
}
|