@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,447 +1,598 @@
|
|
|
1
|
-
import {
|
|
2
|
-
canonicalJson,
|
|
3
|
-
hashArtifactValue as hashValue,
|
|
4
|
-
withHash,
|
|
5
|
-
} from "../../datarc-semantic-core/scripts/canonical.mjs";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
steps
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
"
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
"
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
!
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
"
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
"
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
)
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
return
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
1
|
+
import {
|
|
2
|
+
canonicalJson,
|
|
3
|
+
hashArtifactValue as hashValue,
|
|
4
|
+
withHash,
|
|
5
|
+
} from "../../datarc-semantic-core/scripts/canonical.mjs";
|
|
6
|
+
import {
|
|
7
|
+
assertEnvelopeHash,
|
|
8
|
+
bindSummaryAuthorityTargets,
|
|
9
|
+
canonicalPlanResourceId,
|
|
10
|
+
fail,
|
|
11
|
+
isRecord,
|
|
12
|
+
listAllPages,
|
|
13
|
+
requireArrayResponse,
|
|
14
|
+
statesEqual,
|
|
15
|
+
validateMutationCaseIds,
|
|
16
|
+
} from "../../datarc-semantic-core/scripts/shared.mjs";
|
|
17
|
+
import {
|
|
18
|
+
bridgeLanguage,
|
|
19
|
+
knowledgeKind,
|
|
20
|
+
KNOWLEDGE_SLOT,
|
|
21
|
+
promptBody,
|
|
22
|
+
promptBridgeSource,
|
|
23
|
+
promptCollectionPath,
|
|
24
|
+
revalidatePairedKnowledge,
|
|
25
|
+
semanticPrompt,
|
|
26
|
+
} from "../../datarc-semantic-knowledge/scripts/knowledge-plan.mjs";
|
|
27
|
+
|
|
28
|
+
const PLAN_VERSION = 1; // must match interventions PLAN_VERSION
|
|
29
|
+
export function buildPromptPlan(knowledgePlan, workspaceId) {
|
|
30
|
+
assertEnvelopeHash(
|
|
31
|
+
knowledgePlan,
|
|
32
|
+
"planHash",
|
|
33
|
+
`APPLY:${knowledgePlan?.planHash}`,
|
|
34
|
+
"APPLY",
|
|
35
|
+
);
|
|
36
|
+
if (
|
|
37
|
+
knowledgePlan.workspaceId !== workspaceId ||
|
|
38
|
+
!Array.isArray(knowledgePlan.promptChanges)
|
|
39
|
+
)
|
|
40
|
+
fail(
|
|
41
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
42
|
+
"Knowledge计划与工作区不匹配,请重新读取同一工作区的完整计划。",
|
|
43
|
+
);
|
|
44
|
+
const caseIds = new Set(
|
|
45
|
+
knowledgePlan.promptChanges.flatMap((change) => change.caseIds),
|
|
46
|
+
);
|
|
47
|
+
const scenesByCase = new Map();
|
|
48
|
+
for (const change of knowledgePlan.promptChanges) {
|
|
49
|
+
const scene = change.pairedKnowledge?.scene ?? change.after?.scene;
|
|
50
|
+
for (const caseId of change.caseIds) {
|
|
51
|
+
if (!scenesByCase.has(caseId)) scenesByCase.set(caseId, new Set());
|
|
52
|
+
scenesByCase.get(caseId).add(scene);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const authorities = knowledgePlan.authorities
|
|
56
|
+
.filter((authority) => caseIds.has(authority.caseId))
|
|
57
|
+
.map((authority) => ({
|
|
58
|
+
...authority,
|
|
59
|
+
kind: "prompt_bridge",
|
|
60
|
+
target: {
|
|
61
|
+
scene: [...scenesByCase.get(authority.caseId)],
|
|
62
|
+
knowledgeTarget: structuredClone(authority.target),
|
|
63
|
+
},
|
|
64
|
+
}));
|
|
65
|
+
const steps = knowledgePlan.promptChanges.map((change) => ({
|
|
66
|
+
kind: "prompt_bridge",
|
|
67
|
+
caseIds: structuredClone(change.caseIds),
|
|
68
|
+
endpoint: change.endpoint,
|
|
69
|
+
operation: change.operation,
|
|
70
|
+
before: change.before,
|
|
71
|
+
after: change.after,
|
|
72
|
+
dictionarySyncRequired: false,
|
|
73
|
+
requiresContrast: knowledgePlan.steps.some(
|
|
74
|
+
(step) =>
|
|
75
|
+
step.requiresContrast === true &&
|
|
76
|
+
step.caseIds.some((caseId) => change.caseIds.includes(caseId)),
|
|
77
|
+
),
|
|
78
|
+
pairedKnowledge: structuredClone({
|
|
79
|
+
...change.pairedKnowledge,
|
|
80
|
+
knowledgeTarget: Object.fromEntries(
|
|
81
|
+
change.caseIds.map((caseId) => {
|
|
82
|
+
const authority = knowledgePlan.authorities.find(
|
|
83
|
+
(a) => a.caseId === caseId,
|
|
84
|
+
);
|
|
85
|
+
return [
|
|
86
|
+
caseId,
|
|
87
|
+
authority ? structuredClone(authority.target) : undefined,
|
|
88
|
+
];
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
}),
|
|
92
|
+
preconditions: { dryRuns: change.dryRuns, source: change.source },
|
|
93
|
+
}));
|
|
94
|
+
const plan = {
|
|
95
|
+
version: PLAN_VERSION,
|
|
96
|
+
workspaceId,
|
|
97
|
+
dependsOn: knowledgePlan.planHash,
|
|
98
|
+
authorities,
|
|
99
|
+
steps,
|
|
100
|
+
summaries: steps.map((step) => ({
|
|
101
|
+
kind: "prompt_bridge",
|
|
102
|
+
status: "planned",
|
|
103
|
+
scene: step.after?.scene,
|
|
104
|
+
caseIds: structuredClone(step.caseIds),
|
|
105
|
+
})),
|
|
106
|
+
warnings: [],
|
|
107
|
+
impact: [],
|
|
108
|
+
};
|
|
109
|
+
bindSummaryAuthorityTargets(plan);
|
|
110
|
+
return withHash(plan, "planHash");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function revalidatePromptBridgeStep(
|
|
114
|
+
client,
|
|
115
|
+
workspaceId,
|
|
116
|
+
step,
|
|
117
|
+
authorities,
|
|
118
|
+
) {
|
|
119
|
+
const { dryRuns, source } = validatePromptBridgeStepStructure(
|
|
120
|
+
step,
|
|
121
|
+
workspaceId,
|
|
122
|
+
);
|
|
123
|
+
await revalidatePairedKnowledge(client, workspaceId, step, authorities);
|
|
124
|
+
const collection = promptCollectionPath(workspaceId);
|
|
125
|
+
if (source.kind === "default") {
|
|
126
|
+
const defaults = await client.request("GET", `${collection}default/`, {
|
|
127
|
+
query: { scene: step.after.scene },
|
|
128
|
+
});
|
|
129
|
+
if (
|
|
130
|
+
!isRecord(defaults) ||
|
|
131
|
+
canonicalJson(promptBridgeSource("default", defaults)) !==
|
|
132
|
+
canonicalJson(source) ||
|
|
133
|
+
bridgeLanguage(defaults.prompt, step.after.scene, "prompt") !==
|
|
134
|
+
step.after.prompt ||
|
|
135
|
+
bridgeLanguage(defaults.promptEn, step.after.scene, "promptEn") !==
|
|
136
|
+
step.after.promptEn
|
|
137
|
+
)
|
|
138
|
+
fail(
|
|
139
|
+
"PROMPT_SOURCE_DRIFT",
|
|
140
|
+
"default Prompt changed after the bridge was planned",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
for (const evidence of dryRuns) {
|
|
144
|
+
const response = await client.request("POST", `${collection}dry-run/`, {
|
|
145
|
+
body: {
|
|
146
|
+
scene: step.after.scene,
|
|
147
|
+
prompt: step.after[evidence.field],
|
|
148
|
+
language: evidence.language,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
if (!isRecord(response) || typeof response.prompt !== "string")
|
|
152
|
+
fail("PROMPT_DRY_RUN_FAILED", "Prompt dry-run response is invalid");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function validatePromptBridgeStepStructure(step, workspaceId) {
|
|
157
|
+
const allowed = new Set([
|
|
158
|
+
"after",
|
|
159
|
+
"before",
|
|
160
|
+
"caseIds",
|
|
161
|
+
"dictionarySyncRequired",
|
|
162
|
+
"endpoint",
|
|
163
|
+
"kind",
|
|
164
|
+
"operation",
|
|
165
|
+
"pairedKnowledge",
|
|
166
|
+
"preconditions",
|
|
167
|
+
]);
|
|
168
|
+
if (
|
|
169
|
+
Object.keys(step).some(
|
|
170
|
+
(field) => !allowed.has(field) && field !== "requiresContrast",
|
|
171
|
+
) ||
|
|
172
|
+
[...allowed].some((field) => !Object.hasOwn(step, field)) ||
|
|
173
|
+
(Object.hasOwn(step, "requiresContrast") &&
|
|
174
|
+
typeof step.requiresContrast !== "boolean") ||
|
|
175
|
+
step.kind !== "prompt_bridge" ||
|
|
176
|
+
step.dictionarySyncRequired !== false
|
|
177
|
+
)
|
|
178
|
+
fail("INVALID_PROMPT_BRIDGE_PLAN", "Prompt bridge step fields are invalid");
|
|
179
|
+
const collection = promptCollectionPath(workspaceId);
|
|
180
|
+
const after = validatePromptSnapshot(
|
|
181
|
+
step.after,
|
|
182
|
+
"after",
|
|
183
|
+
step.operation === "PATCH",
|
|
184
|
+
);
|
|
185
|
+
let before = null;
|
|
186
|
+
if (step.operation === "POST") {
|
|
187
|
+
if (
|
|
188
|
+
step.before !== null ||
|
|
189
|
+
after.id !== undefined ||
|
|
190
|
+
step.endpoint !== collection
|
|
191
|
+
)
|
|
192
|
+
fail(
|
|
193
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
194
|
+
"Prompt bridge POST must create from the collection",
|
|
195
|
+
);
|
|
196
|
+
} else if (step.operation === "PATCH") {
|
|
197
|
+
before = validatePromptSnapshot(step.before, "before", true);
|
|
198
|
+
const beforeId = canonicalPlanResourceId(
|
|
199
|
+
before.id,
|
|
200
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
201
|
+
);
|
|
202
|
+
const afterId = canonicalPlanResourceId(
|
|
203
|
+
after.id,
|
|
204
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
205
|
+
);
|
|
206
|
+
if (
|
|
207
|
+
beforeId !== afterId ||
|
|
208
|
+
before.scene !== after.scene ||
|
|
209
|
+
step.endpoint !== `${collection}${beforeId}/` ||
|
|
210
|
+
statesEqual(before, after)
|
|
211
|
+
)
|
|
212
|
+
fail(
|
|
213
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
214
|
+
"Prompt bridge PATCH identity or desired state is invalid",
|
|
215
|
+
);
|
|
216
|
+
} else
|
|
217
|
+
fail("INVALID_PROMPT_BRIDGE_PLAN", "Prompt bridge operation is invalid");
|
|
218
|
+
|
|
219
|
+
const caseIds = validateMutationCaseIds(
|
|
220
|
+
step.caseIds,
|
|
221
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
222
|
+
);
|
|
223
|
+
if (
|
|
224
|
+
!isRecord(step.pairedKnowledge) ||
|
|
225
|
+
!["caseIds", "scene"].every((field) =>
|
|
226
|
+
Object.hasOwn(step.pairedKnowledge, field),
|
|
227
|
+
) ||
|
|
228
|
+
Object.keys(step.pairedKnowledge).some(
|
|
229
|
+
(field) => !["caseIds", "scene", "knowledgeTarget"].includes(field),
|
|
230
|
+
) ||
|
|
231
|
+
step.pairedKnowledge.scene !== after.scene ||
|
|
232
|
+
canonicalJson(step.pairedKnowledge.caseIds) !== canonicalJson(caseIds)
|
|
233
|
+
)
|
|
234
|
+
fail(
|
|
235
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
236
|
+
"Prompt bridge is not bound to its Knowledge authorities",
|
|
237
|
+
);
|
|
238
|
+
const { dryRuns, source } = validatePromptBridgePreconditions(
|
|
239
|
+
step.preconditions,
|
|
240
|
+
before,
|
|
241
|
+
after,
|
|
242
|
+
);
|
|
243
|
+
return { after, before, caseIds, dryRuns, source };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function validatePromptSnapshot(value, label, requireId) {
|
|
247
|
+
if (!isRecord(value))
|
|
248
|
+
fail(
|
|
249
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
250
|
+
`Prompt bridge ${label} must be an object`,
|
|
251
|
+
);
|
|
252
|
+
const allowed = new Set([
|
|
253
|
+
...(requireId ? ["id"] : []),
|
|
254
|
+
"prompt",
|
|
255
|
+
"promptEn",
|
|
256
|
+
"scene",
|
|
257
|
+
]);
|
|
258
|
+
if (
|
|
259
|
+
Object.keys(value).some((field) => !allowed.has(field)) ||
|
|
260
|
+
[...allowed].some((field) => !Object.hasOwn(value, field)) ||
|
|
261
|
+
!Number.isSafeInteger(value.scene) ||
|
|
262
|
+
value.scene <= 0 ||
|
|
263
|
+
typeof value.prompt !== "string" ||
|
|
264
|
+
typeof value.promptEn !== "string" ||
|
|
265
|
+
(!value.prompt.trim() && !value.promptEn.trim())
|
|
266
|
+
)
|
|
267
|
+
fail(
|
|
268
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
269
|
+
`Prompt bridge ${label} snapshot is invalid`,
|
|
270
|
+
);
|
|
271
|
+
if (requireId)
|
|
272
|
+
canonicalPlanResourceId(value.id, "INVALID_PROMPT_BRIDGE_PLAN");
|
|
273
|
+
for (const field of ["prompt", "promptEn"]) {
|
|
274
|
+
const count = value[field].split(KNOWLEDGE_SLOT).length - 1;
|
|
275
|
+
if (count > 1 || (label === "after" && value[field].trim() && count !== 1))
|
|
276
|
+
fail(
|
|
277
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
278
|
+
`Prompt bridge ${label} slot count is invalid`,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
return value;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function validatePromptBridgePreconditions(
|
|
285
|
+
preconditions,
|
|
286
|
+
before,
|
|
287
|
+
after,
|
|
288
|
+
) {
|
|
289
|
+
if (
|
|
290
|
+
!isRecord(preconditions) ||
|
|
291
|
+
canonicalJson(Object.keys(preconditions).sort()) !==
|
|
292
|
+
canonicalJson(["dryRuns", "source"]) ||
|
|
293
|
+
!Array.isArray(preconditions.dryRuns) ||
|
|
294
|
+
!isRecord(preconditions.source)
|
|
295
|
+
)
|
|
296
|
+
fail(
|
|
297
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
298
|
+
"Prompt bridge preconditions are invalid",
|
|
299
|
+
);
|
|
300
|
+
const source = preconditions.source;
|
|
301
|
+
if (
|
|
302
|
+
canonicalJson(Object.keys(source).sort()) !==
|
|
303
|
+
canonicalJson(["kind", "promptEnHash", "promptHash"]) ||
|
|
304
|
+
!new Set(["default", "workspace_override"]).has(source.kind) ||
|
|
305
|
+
!/^[0-9a-f]{64}$/u.test(source.promptHash) ||
|
|
306
|
+
!/^[0-9a-f]{64}$/u.test(source.promptEnHash) ||
|
|
307
|
+
(source.kind === "default") !== (before === null) ||
|
|
308
|
+
(before !== null &&
|
|
309
|
+
canonicalJson(source) !==
|
|
310
|
+
canonicalJson(promptBridgeSource("workspace_override", before))) ||
|
|
311
|
+
(before !== null &&
|
|
312
|
+
(bridgeLanguage(before.prompt, after.scene, "prompt") !== after.prompt ||
|
|
313
|
+
bridgeLanguage(before.promptEn, after.scene, "promptEn") !==
|
|
314
|
+
after.promptEn))
|
|
315
|
+
)
|
|
316
|
+
fail(
|
|
317
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
318
|
+
"Prompt bridge source evidence is invalid",
|
|
319
|
+
);
|
|
320
|
+
const expectedFields = ["prompt", "promptEn"].filter(
|
|
321
|
+
(field) =>
|
|
322
|
+
after[field].trim() &&
|
|
323
|
+
(before === null || after[field] !== before[field]),
|
|
324
|
+
);
|
|
325
|
+
const seen = new Set();
|
|
326
|
+
for (const evidence of preconditions.dryRuns) {
|
|
327
|
+
if (
|
|
328
|
+
!isRecord(evidence) ||
|
|
329
|
+
canonicalJson(Object.keys(evidence).sort()) !==
|
|
330
|
+
canonicalJson(["field", "language", "promptHash", "status"]) ||
|
|
331
|
+
!expectedFields.includes(evidence.field) ||
|
|
332
|
+
seen.has(evidence.field) ||
|
|
333
|
+
evidence.language !== (evidence.field === "prompt" ? "zh-CN" : "en-US") ||
|
|
334
|
+
evidence.promptHash !== hashValue(after[evidence.field]) ||
|
|
335
|
+
evidence.status !== "SUCCESS"
|
|
336
|
+
)
|
|
337
|
+
fail(
|
|
338
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
339
|
+
"Prompt bridge dry-run evidence is invalid",
|
|
340
|
+
);
|
|
341
|
+
seen.add(evidence.field);
|
|
342
|
+
}
|
|
343
|
+
if (
|
|
344
|
+
seen.size !== expectedFields.length ||
|
|
345
|
+
expectedFields.some((field) => !seen.has(field))
|
|
346
|
+
)
|
|
347
|
+
fail(
|
|
348
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
349
|
+
"every changed Prompt language requires one dry-run",
|
|
350
|
+
);
|
|
351
|
+
return { dryRuns: preconditions.dryRuns, source };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function promptWriteDesired(client, step) {
|
|
355
|
+
return client.request(step.operation, step.endpoint, {
|
|
356
|
+
body: promptBody(step.after, step.operation === "POST"),
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function promptWriteBefore(client, step) {
|
|
361
|
+
return client.request("PATCH", step.endpoint, {
|
|
362
|
+
body: promptBody(step.before, false),
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async function promptReadState(client, workspaceId, step) {
|
|
367
|
+
const id = step.after?.id ?? step.before?.id;
|
|
368
|
+
if (id !== undefined)
|
|
369
|
+
return semanticPrompt(
|
|
370
|
+
await client.request("GET", `${promptCollectionPath(workspaceId)}${id}/`),
|
|
371
|
+
);
|
|
372
|
+
const rows = requireArrayResponse(
|
|
373
|
+
await client.request("GET", promptCollectionPath(workspaceId)),
|
|
374
|
+
"INVALID_PROMPT_STATE",
|
|
375
|
+
"workspace Prompt list must be an array",
|
|
376
|
+
);
|
|
377
|
+
const matches = rows.filter(
|
|
378
|
+
(item) =>
|
|
379
|
+
String(item.scene) === String(step.after?.scene ?? step.before?.scene),
|
|
380
|
+
);
|
|
381
|
+
if (matches.length > 1)
|
|
382
|
+
fail(
|
|
383
|
+
"PROMPT_IDENTITY_AMBIGUOUS",
|
|
384
|
+
"multiple workspace Prompts match one scene",
|
|
385
|
+
);
|
|
386
|
+
return matches[0] ? semanticPrompt(matches[0]) : null;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function promptReadCreatedState(client, workspaceId, step) {
|
|
390
|
+
const id = step.after?.id;
|
|
391
|
+
const rows = requireArrayResponse(
|
|
392
|
+
await client.request("GET", promptCollectionPath(workspaceId)),
|
|
393
|
+
"INVALID_PROMPT_STATE",
|
|
394
|
+
"workspace Prompt list must be an array",
|
|
395
|
+
);
|
|
396
|
+
const row = rows.find((item) => String(item.id) === String(id));
|
|
397
|
+
return row ? semanticPrompt(row) : null;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async function promptExactCreatedCandidates(client, workspaceId, step) {
|
|
401
|
+
const scene = step.after?.scene;
|
|
402
|
+
const rows = requireArrayResponse(
|
|
403
|
+
await client.request("GET", promptCollectionPath(workspaceId)),
|
|
404
|
+
"INVALID_PROMPT_STATE",
|
|
405
|
+
"workspace Prompt list must be an array",
|
|
406
|
+
);
|
|
407
|
+
return rows
|
|
408
|
+
.filter((row) => String(row.scene) === String(scene))
|
|
409
|
+
.map(semanticPrompt);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function promptRevalidate(client, workspaceId, step, ctx) {
|
|
413
|
+
return revalidatePromptBridgeStep(client, workspaceId, step, ctx.authorities);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function validatePromptAuthorityTarget(target) {
|
|
417
|
+
const allowed = new Set(["scene", "knowledgeTarget"]);
|
|
418
|
+
if (
|
|
419
|
+
Object.keys(target).some((field) => !allowed.has(field)) ||
|
|
420
|
+
!Array.isArray(target.scene) ||
|
|
421
|
+
target.scene.length === 0 ||
|
|
422
|
+
target.scene.some((scene) => !Number.isSafeInteger(scene) || scene <= 0)
|
|
423
|
+
)
|
|
424
|
+
fail("INVALID_PLAN_STRUCTURE", "Prompt authority target is invalid");
|
|
425
|
+
if (Object.hasOwn(target, "knowledgeTarget")) {
|
|
426
|
+
if (!isRecord(target.knowledgeTarget))
|
|
427
|
+
fail(
|
|
428
|
+
"INVALID_PLAN_STRUCTURE",
|
|
429
|
+
"Prompt缺少配对Knowledge权威,请重新生成计划。",
|
|
430
|
+
);
|
|
431
|
+
knowledgeKind.validateAuthorityTarget(target.knowledgeTarget);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function validatePromptPlanStep(step, plan, authorities, plannedCaseIds) {
|
|
436
|
+
const { caseIds } = validatePromptBridgeStepStructure(step, plan.workspaceId);
|
|
437
|
+
for (const caseId of caseIds) {
|
|
438
|
+
const authority = authorities.get(caseId);
|
|
439
|
+
const matched =
|
|
440
|
+
authority?.kind === "knowledge"
|
|
441
|
+
? authority.target.scenes.includes(step.after.scene)
|
|
442
|
+
: authority?.kind === "prompt_bridge"
|
|
443
|
+
? authority.target.scene.includes(step.after.scene)
|
|
444
|
+
: false;
|
|
445
|
+
if (
|
|
446
|
+
!matched ||
|
|
447
|
+
(authority.target.knowledgeTarget !== undefined &&
|
|
448
|
+
canonicalJson(authority.target.knowledgeTarget) !==
|
|
449
|
+
canonicalJson(step.pairedKnowledge.knowledgeTarget?.[caseId]))
|
|
450
|
+
)
|
|
451
|
+
fail(
|
|
452
|
+
"INVALID_PROMPT_BRIDGE_PLAN",
|
|
453
|
+
"Prompt bridge caseIds must match exact Knowledge authorities",
|
|
454
|
+
);
|
|
455
|
+
plannedCaseIds.add(caseId);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function promptSummaryMatches(summary, authorityTargets) {
|
|
460
|
+
const targets = authorityTargets.map(({ target }) => target);
|
|
461
|
+
return targets.every((target) => summary.name === target.name);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function promptVerificationAuthority(authority, planSteps, receipt) {
|
|
465
|
+
if (
|
|
466
|
+
!receipt ||
|
|
467
|
+
!Array.isArray(receipt.completedSteps) ||
|
|
468
|
+
!Array.isArray(planSteps)
|
|
469
|
+
)
|
|
470
|
+
fail(
|
|
471
|
+
"PROMPT_VERIFICATION_AUTHORITY_REQUIRED",
|
|
472
|
+
"Prompt验证需要完整计划和已完成回执,请回读原始执行工件后重试。",
|
|
473
|
+
);
|
|
474
|
+
promptKind.validateAuthorityTarget(authority.target);
|
|
475
|
+
const promptTargets = [];
|
|
476
|
+
let knowledgeTarget;
|
|
477
|
+
for (const [index, planned] of planSteps.entries()) {
|
|
478
|
+
if (
|
|
479
|
+
planned.kind !== "prompt_bridge" ||
|
|
480
|
+
!planned.caseIds?.includes(authority.caseId)
|
|
481
|
+
)
|
|
482
|
+
continue;
|
|
483
|
+
validatePromptBridgeStepStructure(planned, receipt.workspaceId);
|
|
484
|
+
const completed = receipt.completedSteps.filter(
|
|
485
|
+
(step) => step.planStepIndex === index,
|
|
486
|
+
);
|
|
487
|
+
if (completed.length !== 1)
|
|
488
|
+
fail(
|
|
489
|
+
"PROMPT_VERIFICATION_AUTHORITY_REQUIRED",
|
|
490
|
+
"Prompt回执缺少唯一完成步骤,请核对原执行工件,不要重放写入。",
|
|
491
|
+
);
|
|
492
|
+
const [step] = completed;
|
|
493
|
+
validatePromptSnapshot(step.after, "after", true);
|
|
494
|
+
const expected = { ...planned.after, id: step.after.id };
|
|
495
|
+
if (
|
|
496
|
+
step.kind !== "prompt_bridge" ||
|
|
497
|
+
step.planStepHash !== hashValue(planned) ||
|
|
498
|
+
canonicalJson(step.after) !== canonicalJson(expected) ||
|
|
499
|
+
(planned.after.id !== undefined && planned.after.id !== step.after.id) ||
|
|
500
|
+
step.endpoint !==
|
|
501
|
+
`${promptCollectionPath(receipt.workspaceId)}${step.after.id}/` ||
|
|
502
|
+
canonicalJson(step.pairedKnowledge) !==
|
|
503
|
+
canonicalJson(planned.pairedKnowledge) ||
|
|
504
|
+
canonicalJson(step.caseIds) !== canonicalJson(planned.caseIds) ||
|
|
505
|
+
!authority.target.scene.includes(step.after.scene)
|
|
506
|
+
)
|
|
507
|
+
fail(
|
|
508
|
+
"PROMPT_VERIFICATION_AUTHORITY_MISMATCH",
|
|
509
|
+
"Prompt完成状态与计划权威不匹配,请回读原计划和回执重新核对。",
|
|
510
|
+
);
|
|
511
|
+
const target = planned.pairedKnowledge.knowledgeTarget?.[authority.caseId];
|
|
512
|
+
if (!target || typeof target !== "object" || Array.isArray(target))
|
|
513
|
+
fail(
|
|
514
|
+
"PROMPT_VERIFICATION_AUTHORITY_REQUIRED",
|
|
515
|
+
"Prompt计划缺少配对Knowledge快照,请重新生成并确认计划。",
|
|
516
|
+
);
|
|
517
|
+
knowledgeKind.validateAuthorityTarget(target);
|
|
518
|
+
if (
|
|
519
|
+
(authority.target.knowledgeTarget !== undefined &&
|
|
520
|
+
canonicalJson(target) !==
|
|
521
|
+
canonicalJson(authority.target.knowledgeTarget)) ||
|
|
522
|
+
!target.active ||
|
|
523
|
+
!target.scenes.includes(step.after.scene) ||
|
|
524
|
+
(knowledgeTarget &&
|
|
525
|
+
canonicalJson(knowledgeTarget) !== canonicalJson(target))
|
|
526
|
+
)
|
|
527
|
+
fail(
|
|
528
|
+
"PROMPT_VERIFICATION_AUTHORITY_MISMATCH",
|
|
529
|
+
"Prompt场景与配对Knowledge权威不一致,请重新核对已确认的范围。",
|
|
530
|
+
);
|
|
531
|
+
knowledgeTarget = structuredClone(target);
|
|
532
|
+
promptTargets.push({
|
|
533
|
+
endpoint: step.endpoint,
|
|
534
|
+
after: structuredClone(step.after),
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
const scenes = promptTargets.map((target) => target.after.scene);
|
|
538
|
+
if (
|
|
539
|
+
scenes.length !== new Set(scenes).size ||
|
|
540
|
+
canonicalJson([...scenes].sort((a, b) => a - b)) !==
|
|
541
|
+
canonicalJson([...authority.target.scene].sort((a, b) => a - b))
|
|
542
|
+
)
|
|
543
|
+
fail(
|
|
544
|
+
"PROMPT_VERIFICATION_AUTHORITY_MISMATCH",
|
|
545
|
+
"Prompt验证未精确覆盖权威场景,请核对计划与完成回执。",
|
|
546
|
+
);
|
|
547
|
+
if (!knowledgeTarget || !promptTargets.length)
|
|
548
|
+
fail(
|
|
549
|
+
"PROMPT_VERIFICATION_AUTHORITY_REQUIRED",
|
|
550
|
+
"Prompt验证缺少完成目标,请回读完整执行回执。",
|
|
551
|
+
);
|
|
552
|
+
return { knowledgeTarget, promptTargets };
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
async function verifyPromptTargets(client, workspaceId, targets) {
|
|
556
|
+
const collection = promptCollectionPath(workspaceId);
|
|
557
|
+
const rows = await listAllPages(client, collection);
|
|
558
|
+
for (const target of targets) {
|
|
559
|
+
const matches = rows.filter(
|
|
560
|
+
(row) => String(row.scene) === String(target.after.scene),
|
|
561
|
+
);
|
|
562
|
+
if (
|
|
563
|
+
matches.length !== 1 ||
|
|
564
|
+
String(matches[0].id) !== String(target.after.id)
|
|
565
|
+
)
|
|
566
|
+
fail(
|
|
567
|
+
"PROMPT_STATE_DRIFT",
|
|
568
|
+
"待验证Prompt的身份或场景已变化,请回读最新配置重新生成方案。",
|
|
569
|
+
);
|
|
570
|
+
const current = semanticPrompt(
|
|
571
|
+
await client.request("GET", target.endpoint),
|
|
572
|
+
);
|
|
573
|
+
if (canonicalJson(current) !== canonicalJson(target.after))
|
|
574
|
+
fail(
|
|
575
|
+
"PROMPT_STATE_DRIFT",
|
|
576
|
+
"待验证Prompt模板已变化,请回读最新配置重新生成方案。",
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export const promptKind = {
|
|
582
|
+
name: "prompt_bridge",
|
|
583
|
+
verificationAuthority: promptVerificationAuthority,
|
|
584
|
+
verifyCurrent: verifyPromptTargets,
|
|
585
|
+
planable: false,
|
|
586
|
+
writeDesired: promptWriteDesired,
|
|
587
|
+
writeBefore: promptWriteBefore,
|
|
588
|
+
readState: promptReadState,
|
|
589
|
+
readCreatedState: promptReadCreatedState,
|
|
590
|
+
postApplyRead: promptRevalidate,
|
|
591
|
+
exactCreatedCandidates: promptExactCreatedCandidates,
|
|
592
|
+
collection: promptCollectionPath,
|
|
593
|
+
targetKey: (step) => `prompt:${step.after?.id ?? step.after?.scene}`,
|
|
594
|
+
validateAuthorityTarget: validatePromptAuthorityTarget,
|
|
595
|
+
validateStep: validatePromptPlanStep,
|
|
596
|
+
summaryField: ["scene"],
|
|
597
|
+
summaryMatches: promptSummaryMatches,
|
|
598
|
+
};
|