@vaudience/aigentflow-flow-validator 0.15.3 → 0.18.0
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/PARITY.md +178 -6
- package/README.md +2 -2
- package/dist/cli.js +1579 -89
- package/dist/index.cjs +1513 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +1513 -88
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -432,7 +432,7 @@ function validateBasicStructure(flow, issues) {
|
|
|
432
432
|
|
|
433
433
|
// src/spec/aigentflow-spec.json
|
|
434
434
|
var aigentflow_spec_default = {
|
|
435
|
-
specVersion: "2.
|
|
435
|
+
specVersion: "2.819.0",
|
|
436
436
|
inputSchemaVersion: 1,
|
|
437
437
|
executorSchemes: [
|
|
438
438
|
"a2a",
|
|
@@ -463,7 +463,6 @@ var aigentflow_spec_default = {
|
|
|
463
463
|
"messenger",
|
|
464
464
|
"mock",
|
|
465
465
|
"mqtt",
|
|
466
|
-
"nexus",
|
|
467
466
|
"opencorporates",
|
|
468
467
|
"openmeteo",
|
|
469
468
|
"overpass",
|
|
@@ -754,12 +753,6 @@ var aigentflow_spec_default = {
|
|
|
754
753
|
fields: ["api_key", "base_url", "organization"],
|
|
755
754
|
extraKey: "extra",
|
|
756
755
|
scopes: {
|
|
757
|
-
aigentchat: [
|
|
758
|
-
"AIGENTFLOW_AIGENTCHAT_API_KEY",
|
|
759
|
-
"AIGENTFLOW_AIGENTCHAT_BASE_URL",
|
|
760
|
-
"AIGENTFLOW_NEXUS_API_KEY",
|
|
761
|
-
"AIGENTFLOW_NEXUS_BASE_URL"
|
|
762
|
-
],
|
|
763
756
|
anthropic: [
|
|
764
757
|
"AIGENTFLOW_ANTHROPIC_API_KEY",
|
|
765
758
|
"AIGENTFLOW_ANTHROPIC_BASE_URL"
|
|
@@ -867,12 +860,6 @@ var aigentflow_spec_default = {
|
|
|
867
860
|
"AIGENTFLOW_MQTT_PASSWORD",
|
|
868
861
|
"AIGENTFLOW_MQTT_USERNAME"
|
|
869
862
|
],
|
|
870
|
-
nexus: [
|
|
871
|
-
"AIGENTFLOW_AIGENTCHAT_API_KEY",
|
|
872
|
-
"AIGENTFLOW_AIGENTCHAT_BASE_URL",
|
|
873
|
-
"AIGENTFLOW_NEXUS_API_KEY",
|
|
874
|
-
"AIGENTFLOW_NEXUS_BASE_URL"
|
|
875
|
-
],
|
|
876
863
|
ollama: [
|
|
877
864
|
"AIGENTFLOW_OLLAMA_API_KEY",
|
|
878
865
|
"AIGENTFLOW_OLLAMA_BASE_URL"
|
|
@@ -992,9 +979,6 @@ var aigentflow_spec_default = {
|
|
|
992
979
|
]
|
|
993
980
|
},
|
|
994
981
|
familyKeySeparator: "/",
|
|
995
|
-
protocolAliases: {
|
|
996
|
-
aigentchat: "nexus"
|
|
997
|
-
},
|
|
998
982
|
families: {
|
|
999
983
|
db: {
|
|
1000
984
|
protocol: "db",
|
|
@@ -1153,40 +1137,6 @@ var aigentflow_spec_default = {
|
|
|
1153
1137
|
"AIGENTFLOW_MQTT_PASSWORD"
|
|
1154
1138
|
]
|
|
1155
1139
|
},
|
|
1156
|
-
nexus: {
|
|
1157
|
-
protocol: "nexus",
|
|
1158
|
-
configKeys: [
|
|
1159
|
-
"nexus",
|
|
1160
|
-
"aigentchat"
|
|
1161
|
-
],
|
|
1162
|
-
secretParams: [
|
|
1163
|
-
"aigentchat_api_key",
|
|
1164
|
-
"api_key"
|
|
1165
|
-
],
|
|
1166
|
-
endpointParams: [
|
|
1167
|
-
"aigentchat_base_url",
|
|
1168
|
-
"base_url"
|
|
1169
|
-
],
|
|
1170
|
-
defaultEndpoints: [],
|
|
1171
|
-
configApiKeyParam: "",
|
|
1172
|
-
configBaseUrlParam: "",
|
|
1173
|
-
implicitServerCredential: false,
|
|
1174
|
-
expandsServerEnvReferences: false,
|
|
1175
|
-
serverEnv: [
|
|
1176
|
-
"AIGENTFLOW_NEXUS_BASE_URL",
|
|
1177
|
-
"AIGENTFLOW_NEXUS_API_KEY",
|
|
1178
|
-
"AIGENTFLOW_AIGENTCHAT_API_KEY",
|
|
1179
|
-
"AIGENTFLOW_AIGENTCHAT_BASE_URL"
|
|
1180
|
-
],
|
|
1181
|
-
storedKeyShape: {
|
|
1182
|
-
ownKeyParams: [
|
|
1183
|
-
"aigentchat_api_key",
|
|
1184
|
-
"api_key"
|
|
1185
|
-
],
|
|
1186
|
-
ownCredentialsMapParam: "credentials",
|
|
1187
|
-
provider: "aigentchat"
|
|
1188
|
-
}
|
|
1189
|
-
},
|
|
1190
1140
|
opencorporates: {
|
|
1191
1141
|
protocol: "opencorporates",
|
|
1192
1142
|
configKeys: [
|
|
@@ -1307,6 +1257,97 @@ var aigentflow_spec_default = {
|
|
|
1307
1257
|
}
|
|
1308
1258
|
}
|
|
1309
1259
|
},
|
|
1260
|
+
examples: {
|
|
1261
|
+
limits: {
|
|
1262
|
+
maxPerFlow: 50,
|
|
1263
|
+
maxBlockBytes: 262144,
|
|
1264
|
+
maxInlineInputBytes: 32768,
|
|
1265
|
+
maxReferenceTextBytes: 32768,
|
|
1266
|
+
maxVariants: 10,
|
|
1267
|
+
maxTags: 8,
|
|
1268
|
+
maxMustNot: 12,
|
|
1269
|
+
maxMustNotContain: 20,
|
|
1270
|
+
maxRubricRunes: 4e3,
|
|
1271
|
+
maxGuidanceRunes: 2e3,
|
|
1272
|
+
maxNotesRunes: 2e3,
|
|
1273
|
+
titleMaxRunes: 80,
|
|
1274
|
+
maxMustNotRunes: 300,
|
|
1275
|
+
maxMustNotContainLength: 200,
|
|
1276
|
+
maxProvenanceRunes: 200,
|
|
1277
|
+
maxNoteRunes: 300,
|
|
1278
|
+
maxUrlBytes: 2048,
|
|
1279
|
+
maxPatternLength: 512,
|
|
1280
|
+
weightMax: 10,
|
|
1281
|
+
minScoreMin: 0,
|
|
1282
|
+
minScoreMax: 1
|
|
1283
|
+
},
|
|
1284
|
+
idPattern: "^[a-z][a-z0-9_]{1,47}$",
|
|
1285
|
+
tagPattern: "^[a-z][a-z0-9_-]{0,31}$",
|
|
1286
|
+
sha256Pattern: "^[0-9a-f]{64}$",
|
|
1287
|
+
mediaTypePattern: "^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$",
|
|
1288
|
+
signedUrlQueryKeyPattern: "^(x-amz-signature|signature|sig|token|access_token|key|x-goog-signature|se|sp)$",
|
|
1289
|
+
origins: [
|
|
1290
|
+
"author",
|
|
1291
|
+
"synthetic"
|
|
1292
|
+
],
|
|
1293
|
+
sideEffects: [
|
|
1294
|
+
"refuse",
|
|
1295
|
+
"allow"
|
|
1296
|
+
],
|
|
1297
|
+
statuses: [
|
|
1298
|
+
"completed",
|
|
1299
|
+
"failed",
|
|
1300
|
+
"paused_for_human"
|
|
1301
|
+
],
|
|
1302
|
+
reservedRefSchemes: [
|
|
1303
|
+
"artifact",
|
|
1304
|
+
"trove",
|
|
1305
|
+
"aiv",
|
|
1306
|
+
"s3",
|
|
1307
|
+
"gs"
|
|
1308
|
+
],
|
|
1309
|
+
secretPatterns: [
|
|
1310
|
+
{
|
|
1311
|
+
name: "an API key",
|
|
1312
|
+
expr: "\\bsk-[A-Za-z0-9_-]{20,}",
|
|
1313
|
+
flags: ""
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
name: "a platform API key",
|
|
1317
|
+
expr: "\\bcrn_[A-Za-z0-9]{16,}",
|
|
1318
|
+
flags: ""
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
name: "an AWS access key",
|
|
1322
|
+
expr: "\\bAKIA[0-9A-Z]{16}\\b",
|
|
1323
|
+
flags: ""
|
|
1324
|
+
},
|
|
1325
|
+
{
|
|
1326
|
+
name: "a private key",
|
|
1327
|
+
expr: "-----BEGIN [A-Z ]*PRIVATE KEY-----",
|
|
1328
|
+
flags: ""
|
|
1329
|
+
},
|
|
1330
|
+
{
|
|
1331
|
+
name: "a bearer token",
|
|
1332
|
+
expr: "\\bbearer\\s+[A-Za-z0-9._~+/-]{20,}",
|
|
1333
|
+
flags: "i"
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
name: "a Slack token",
|
|
1337
|
+
expr: "\\bxox[abprs]-[A-Za-z0-9-]{10,}",
|
|
1338
|
+
flags: ""
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
name: "a GitHub token",
|
|
1342
|
+
expr: "\\bgh[pousr]_[A-Za-z0-9]{30,}",
|
|
1343
|
+
flags: ""
|
|
1344
|
+
},
|
|
1345
|
+
{
|
|
1346
|
+
name: "a retired registry key",
|
|
1347
|
+
expr: "\\baivk_[A-Za-z0-9]{20,}",
|
|
1348
|
+
flags: ""
|
|
1349
|
+
}
|
|
1350
|
+
]},
|
|
1310
1351
|
knownKeys: {
|
|
1311
1352
|
root: "Flow",
|
|
1312
1353
|
types: {
|
|
@@ -1327,6 +1368,17 @@ var aigentflow_spec_default = {
|
|
|
1327
1368
|
on_children_complete: "scalar",
|
|
1328
1369
|
shared_memory: "scalar"
|
|
1329
1370
|
},
|
|
1371
|
+
Checkpoint: {
|
|
1372
|
+
exact: "map<any>",
|
|
1373
|
+
fields: "map<FieldMatcher>",
|
|
1374
|
+
min_score: "scalar",
|
|
1375
|
+
must_not: "list<scalar>",
|
|
1376
|
+
must_not_contain: "list<scalar>",
|
|
1377
|
+
optional: "scalar",
|
|
1378
|
+
reference: "ExampleReference",
|
|
1379
|
+
rubric: "scalar",
|
|
1380
|
+
status: "scalar"
|
|
1381
|
+
},
|
|
1330
1382
|
CheckpointConfig: {
|
|
1331
1383
|
enabled: "scalar",
|
|
1332
1384
|
interval_steps: "scalar",
|
|
@@ -1349,6 +1401,37 @@ var aigentflow_spec_default = {
|
|
|
1349
1401
|
retry_delay: "scalar",
|
|
1350
1402
|
retry_on: "list<scalar>"
|
|
1351
1403
|
},
|
|
1404
|
+
ExampleDefinition: {
|
|
1405
|
+
checkpoints: "map<Checkpoint>",
|
|
1406
|
+
expected: "Expectation",
|
|
1407
|
+
guidance: "scalar",
|
|
1408
|
+
hold_out: "scalar",
|
|
1409
|
+
id: "scalar",
|
|
1410
|
+
input: "map<any>",
|
|
1411
|
+
input_ref: "FileRef",
|
|
1412
|
+
min_score: "scalar",
|
|
1413
|
+
notes: "scalar",
|
|
1414
|
+
side_effects: "scalar",
|
|
1415
|
+
tags: "list<scalar>",
|
|
1416
|
+
title: "scalar",
|
|
1417
|
+
variants: "list<ExampleVariant>",
|
|
1418
|
+
weight: "scalar"
|
|
1419
|
+
},
|
|
1420
|
+
ExampleReference: {
|
|
1421
|
+
ref: "FileRef",
|
|
1422
|
+
text: "scalar"
|
|
1423
|
+
},
|
|
1424
|
+
ExampleVariant: {
|
|
1425
|
+
expected: "Expectation",
|
|
1426
|
+
guidance: "scalar",
|
|
1427
|
+
id: "scalar",
|
|
1428
|
+
input_patch: "map<any>",
|
|
1429
|
+
input_ref: "FileRef",
|
|
1430
|
+
origin: "scalar",
|
|
1431
|
+
provenance: "scalar",
|
|
1432
|
+
title: "scalar",
|
|
1433
|
+
weight: "scalar"
|
|
1434
|
+
},
|
|
1352
1435
|
ExecutorDefaultsDefinition: {
|
|
1353
1436
|
frequency_penalty: "scalar",
|
|
1354
1437
|
max_tokens: "scalar",
|
|
@@ -1371,6 +1454,16 @@ var aigentflow_spec_default = {
|
|
|
1371
1454
|
allowed_models: "list<scalar>",
|
|
1372
1455
|
allowed_providers: "list<scalar>"
|
|
1373
1456
|
},
|
|
1457
|
+
Expectation: {
|
|
1458
|
+
exact: "map<any>",
|
|
1459
|
+
fields: "map<FieldMatcher>",
|
|
1460
|
+
min_score: "scalar",
|
|
1461
|
+
must_not: "list<scalar>",
|
|
1462
|
+
must_not_contain: "list<scalar>",
|
|
1463
|
+
reference: "ExampleReference",
|
|
1464
|
+
rubric: "scalar",
|
|
1465
|
+
status: "scalar"
|
|
1466
|
+
},
|
|
1374
1467
|
FailoverBreakerConfig: {
|
|
1375
1468
|
failure_threshold: "scalar",
|
|
1376
1469
|
open_duration: "scalar",
|
|
@@ -1389,6 +1482,22 @@ var aigentflow_spec_default = {
|
|
|
1389
1482
|
type: "scalar",
|
|
1390
1483
|
validation: "scalar"
|
|
1391
1484
|
},
|
|
1485
|
+
FieldMatcher: {
|
|
1486
|
+
approx: "scalar",
|
|
1487
|
+
contains: "scalar",
|
|
1488
|
+
equals: "any",
|
|
1489
|
+
matches: "scalar",
|
|
1490
|
+
not_contains: "scalar",
|
|
1491
|
+
one_of: "list<any>",
|
|
1492
|
+
present: "scalar",
|
|
1493
|
+
tolerance: "scalar"
|
|
1494
|
+
},
|
|
1495
|
+
FileRef: {
|
|
1496
|
+
media_type: "scalar",
|
|
1497
|
+
note: "scalar",
|
|
1498
|
+
sha256: "scalar",
|
|
1499
|
+
url: "scalar"
|
|
1500
|
+
},
|
|
1392
1501
|
Flow: {
|
|
1393
1502
|
aigentflow_version: "scalar",
|
|
1394
1503
|
billing: "BillingConfig",
|
|
@@ -1402,6 +1511,7 @@ var aigentflow_spec_default = {
|
|
|
1402
1511
|
discoverable_tools: "list<scalar>",
|
|
1403
1512
|
display_name: "scalar",
|
|
1404
1513
|
error_strategy: "ErrorStrategyDefinition",
|
|
1514
|
+
examples: "list<ExampleDefinition>",
|
|
1405
1515
|
executor_config: "map<ExecutorInstanceDefinition>",
|
|
1406
1516
|
exons_uploads: "ExonsUploadsFlowConfig",
|
|
1407
1517
|
expression_functions: "list<map<scalar>>",
|
|
@@ -1479,6 +1589,7 @@ var aigentflow_spec_default = {
|
|
|
1479
1589
|
pattern: "scalar",
|
|
1480
1590
|
required: "scalar",
|
|
1481
1591
|
type: "scalar",
|
|
1592
|
+
untrusted: "scalar",
|
|
1482
1593
|
visible_when: "VisibleWhenPredicate"
|
|
1483
1594
|
},
|
|
1484
1595
|
LoopDefinition: {
|
|
@@ -1488,6 +1599,7 @@ var aigentflow_spec_default = {
|
|
|
1488
1599
|
while: "scalar"
|
|
1489
1600
|
},
|
|
1490
1601
|
LoopStepDefinition: {
|
|
1602
|
+
allow_untrusted: "list<scalar>",
|
|
1491
1603
|
condition: "scalar",
|
|
1492
1604
|
credential: "scalar",
|
|
1493
1605
|
credentials: "map<StepCredentialBinding>",
|
|
@@ -1500,7 +1612,8 @@ var aigentflow_spec_default = {
|
|
|
1500
1612
|
post_processing: "list<any>",
|
|
1501
1613
|
pre_processing: "list<any>",
|
|
1502
1614
|
query: "map<any>",
|
|
1503
|
-
response_evaluation: "scalar"
|
|
1615
|
+
response_evaluation: "scalar",
|
|
1616
|
+
trusted_output: "scalar"
|
|
1504
1617
|
},
|
|
1505
1618
|
MockBinaryAsset: {
|
|
1506
1619
|
filename: "scalar",
|
|
@@ -1588,6 +1701,7 @@ var aigentflow_spec_default = {
|
|
|
1588
1701
|
properties: "map<PropertyDefinition>",
|
|
1589
1702
|
required: "scalar",
|
|
1590
1703
|
type: "scalar",
|
|
1704
|
+
untrusted: "scalar",
|
|
1591
1705
|
validation: "scalar"
|
|
1592
1706
|
},
|
|
1593
1707
|
StepCredentialBinding: {
|
|
@@ -1595,6 +1709,7 @@ var aigentflow_spec_default = {
|
|
|
1595
1709
|
source: "scalar"
|
|
1596
1710
|
},
|
|
1597
1711
|
StepDefinition: {
|
|
1712
|
+
allow_untrusted: "list<scalar>",
|
|
1598
1713
|
condition: "scalar",
|
|
1599
1714
|
credential: "scalar",
|
|
1600
1715
|
credentials: "map<StepCredentialBinding>",
|
|
@@ -1612,7 +1727,8 @@ var aigentflow_spec_default = {
|
|
|
1612
1727
|
quality_gate: "QualityGateDefinition",
|
|
1613
1728
|
query: "map<any>",
|
|
1614
1729
|
response_evaluation: "scalar",
|
|
1615
|
-
response_expectation: "map<FieldExpectationDefinition>"
|
|
1730
|
+
response_expectation: "map<FieldExpectationDefinition>",
|
|
1731
|
+
trusted_output: "scalar"
|
|
1616
1732
|
},
|
|
1617
1733
|
ThrottleDefinition: {
|
|
1618
1734
|
batch_delay: "scalar",
|
|
@@ -1732,9 +1848,25 @@ var CREDENTIAL_ENDPOINT_PAIRING = {
|
|
|
1732
1848
|
executorConfigProviders: aigentflow_spec_default.credentialEndpointPairing.ai.executorConfigProviders
|
|
1733
1849
|
},
|
|
1734
1850
|
familyKeySeparator: aigentflow_spec_default.credentialEndpointPairing.familyKeySeparator,
|
|
1735
|
-
protocolAliases: aigentflow_spec_default.credentialEndpointPairing.protocolAliases,
|
|
1736
1851
|
families: aigentflow_spec_default.credentialEndpointPairing.families
|
|
1737
1852
|
};
|
|
1853
|
+
var EXAMPLES = {
|
|
1854
|
+
limits: aigentflow_spec_default.examples.limits,
|
|
1855
|
+
idPattern: new RegExp(aigentflow_spec_default.examples.idPattern),
|
|
1856
|
+
tagPattern: new RegExp(aigentflow_spec_default.examples.tagPattern),
|
|
1857
|
+
sha256Pattern: new RegExp(aigentflow_spec_default.examples.sha256Pattern),
|
|
1858
|
+
mediaTypePattern: new RegExp(aigentflow_spec_default.examples.mediaTypePattern),
|
|
1859
|
+
// The reference writes this pattern case-insensitively (`(?i)`); the spec
|
|
1860
|
+
// carries the bare expression, so the flag is applied here.
|
|
1861
|
+
signedUrlQueryKeyPattern: new RegExp(aigentflow_spec_default.examples.signedUrlQueryKeyPattern, "i"),
|
|
1862
|
+
origins: new Set(aigentflow_spec_default.examples.origins),
|
|
1863
|
+
sideEffects: new Set(aigentflow_spec_default.examples.sideEffects),
|
|
1864
|
+
statuses: new Set(aigentflow_spec_default.examples.statuses),
|
|
1865
|
+
reservedRefSchemes: new Set(aigentflow_spec_default.examples.reservedRefSchemes),
|
|
1866
|
+
secretPatterns: aigentflow_spec_default.examples.secretPatterns.map((p) => ({
|
|
1867
|
+
name: p.name,
|
|
1868
|
+
re: new RegExp(p.expr, p.flags)
|
|
1869
|
+
}))};
|
|
1738
1870
|
|
|
1739
1871
|
// src/validators/executors.ts
|
|
1740
1872
|
var SCHEME_SEPARATOR = "://";
|
|
@@ -3203,29 +3335,29 @@ function validateField(f, schemaPath, i, seen, issues) {
|
|
|
3203
3335
|
});
|
|
3204
3336
|
}
|
|
3205
3337
|
const stringy = INPUT_SCHEMA.stringTypes.has(type);
|
|
3206
|
-
const
|
|
3338
|
+
const mismatch2 = (constraint) => issues.error({
|
|
3207
3339
|
field: `${base}.${constraint}`,
|
|
3208
3340
|
message: `constraint '${constraint}' is not meaningful for field '${shownName}' of type '${type}'`,
|
|
3209
3341
|
code: "input_schema_constraint_type_mismatch"
|
|
3210
3342
|
});
|
|
3211
3343
|
if (!stringy) {
|
|
3212
|
-
if (f.min_length !== void 0)
|
|
3213
|
-
if (f.max_length !== void 0)
|
|
3214
|
-
if (pattern !== null && pattern !== "")
|
|
3344
|
+
if (f.min_length !== void 0) mismatch2("min_length");
|
|
3345
|
+
if (f.max_length !== void 0) mismatch2("max_length");
|
|
3346
|
+
if (pattern !== null && pattern !== "") mismatch2("pattern");
|
|
3215
3347
|
}
|
|
3216
3348
|
if (type !== TYPE_NUMBER) {
|
|
3217
|
-
if (f.min !== void 0)
|
|
3218
|
-
if (f.max !== void 0)
|
|
3349
|
+
if (f.min !== void 0) mismatch2("min");
|
|
3350
|
+
if (f.max !== void 0) mismatch2("max");
|
|
3219
3351
|
}
|
|
3220
3352
|
if (type !== TYPE_ARRAY_OF_STRINGS) {
|
|
3221
|
-
if (f.min_items !== void 0)
|
|
3222
|
-
if (f.max_items !== void 0)
|
|
3353
|
+
if (f.min_items !== void 0) mismatch2("min_items");
|
|
3354
|
+
if (f.max_items !== void 0) mismatch2("max_items");
|
|
3223
3355
|
}
|
|
3224
3356
|
if (type !== TYPE_FILE) {
|
|
3225
|
-
if (Array.isArray(f.accept) && f.accept.length > 0)
|
|
3226
|
-
if (f.max_size !== void 0)
|
|
3357
|
+
if (Array.isArray(f.accept) && f.accept.length > 0) mismatch2("accept");
|
|
3358
|
+
if (f.max_size !== void 0) mismatch2("max_size");
|
|
3227
3359
|
}
|
|
3228
|
-
if (type !== TYPE_ENUM && Array.isArray(f.enum) && f.enum.length > 0)
|
|
3360
|
+
if (type !== TYPE_ENUM && Array.isArray(f.enum) && f.enum.length > 0) mismatch2("enum");
|
|
3229
3361
|
const cap = (constraint, val) => issues.error({
|
|
3230
3362
|
field: `${base}.${constraint}`,
|
|
3231
3363
|
message: `constraint '${constraint}' (${val}) for field '${shownName}' exceeds the maximum of ${INPUT_SCHEMA.maxConstraintValue}`,
|
|
@@ -4505,7 +4637,8 @@ function parseHost(host) {
|
|
|
4505
4637
|
function parseAuthority(authority) {
|
|
4506
4638
|
const at = authority.lastIndexOf("@");
|
|
4507
4639
|
const host = parseHost(at < 0 ? authority : authority.slice(at + 1));
|
|
4508
|
-
if (host === null
|
|
4640
|
+
if (host === null) return null;
|
|
4641
|
+
if (at < 0) return { host, hasUser: false };
|
|
4509
4642
|
const userinfo = authority.slice(0, at);
|
|
4510
4643
|
if (!validUserinfo(userinfo)) return null;
|
|
4511
4644
|
const colon = userinfo.indexOf(":");
|
|
@@ -4513,7 +4646,7 @@ function parseAuthority(authority) {
|
|
|
4513
4646
|
for (const part of parts) {
|
|
4514
4647
|
if (unescapeText(part, Mode.UserPassword) === null) return null;
|
|
4515
4648
|
}
|
|
4516
|
-
return host;
|
|
4649
|
+
return { host, hasUser: true };
|
|
4517
4650
|
}
|
|
4518
4651
|
function getScheme(raw) {
|
|
4519
4652
|
for (let i = 0; i < raw.length; i++) {
|
|
@@ -4539,28 +4672,37 @@ function containsCTL(s) {
|
|
|
4539
4672
|
return false;
|
|
4540
4673
|
}
|
|
4541
4674
|
function goParseSchemeHost(rawURL) {
|
|
4675
|
+
const u = goParseURLParts(rawURL);
|
|
4676
|
+
return u === null ? null : { scheme: u.scheme, host: u.host };
|
|
4677
|
+
}
|
|
4678
|
+
function goParseURLParts(rawURL) {
|
|
4542
4679
|
const hash = rawURL.indexOf("#");
|
|
4543
4680
|
const main = hash < 0 ? rawURL : rawURL.slice(0, hash);
|
|
4544
4681
|
const frag = hash < 0 ? "" : rawURL.slice(hash + 1);
|
|
4545
4682
|
if (containsCTL(main)) return null;
|
|
4546
|
-
if (main === "*")
|
|
4683
|
+
if (main === "*") {
|
|
4684
|
+
return { scheme: "", host: "", hasUser: false, rawQuery: "", fragment: frag };
|
|
4685
|
+
}
|
|
4547
4686
|
const split = getScheme(main);
|
|
4548
4687
|
if (split === null) return null;
|
|
4549
4688
|
const scheme = split.scheme.toLowerCase();
|
|
4550
4689
|
let rest = split.rest;
|
|
4551
4690
|
const questionMarks = rest.split("?").length - 1;
|
|
4691
|
+
let rawQuery = "";
|
|
4552
4692
|
if (rest.endsWith("?") && questionMarks === 1) {
|
|
4553
4693
|
rest = rest.slice(0, -1);
|
|
4554
4694
|
} else if (questionMarks > 0) {
|
|
4695
|
+
rawQuery = rest.slice(rest.indexOf("?") + 1);
|
|
4555
4696
|
rest = rest.slice(0, rest.indexOf("?"));
|
|
4556
4697
|
}
|
|
4557
4698
|
if (!rest.startsWith("/")) {
|
|
4558
|
-
if (scheme !== "") return finish({ scheme, host: "" }, frag);
|
|
4699
|
+
if (scheme !== "") return finish({ scheme, host: "", hasUser: false, rawQuery }, frag);
|
|
4559
4700
|
const slash = rest.indexOf("/");
|
|
4560
4701
|
const segment = slash < 0 ? rest : rest.slice(0, slash);
|
|
4561
4702
|
if (segment.includes(":")) return null;
|
|
4562
4703
|
}
|
|
4563
4704
|
let host = "";
|
|
4705
|
+
let hasUser = false;
|
|
4564
4706
|
if ((scheme !== "" || !rest.startsWith("///")) && rest.startsWith("//")) {
|
|
4565
4707
|
let authority = rest.slice(2);
|
|
4566
4708
|
rest = "";
|
|
@@ -4571,14 +4713,26 @@ function goParseSchemeHost(rawURL) {
|
|
|
4571
4713
|
}
|
|
4572
4714
|
const parsed = parseAuthority(authority);
|
|
4573
4715
|
if (parsed === null) return null;
|
|
4574
|
-
host = parsed;
|
|
4716
|
+
host = parsed.host;
|
|
4717
|
+
hasUser = parsed.hasUser;
|
|
4575
4718
|
}
|
|
4576
4719
|
if (unescapeText(rest, Mode.Path) === null) return null;
|
|
4577
|
-
return finish({ scheme, host }, frag);
|
|
4720
|
+
return finish({ scheme, host, hasUser, rawQuery }, frag);
|
|
4578
4721
|
}
|
|
4579
4722
|
function finish(u, frag) {
|
|
4580
4723
|
if (frag !== "" && unescapeText(frag, Mode.Fragment) === null) return null;
|
|
4581
|
-
return u;
|
|
4724
|
+
return { ...u, fragment: frag };
|
|
4725
|
+
}
|
|
4726
|
+
function goQueryKeys(rawQuery) {
|
|
4727
|
+
const keys = [];
|
|
4728
|
+
for (const pair of rawQuery.split("&")) {
|
|
4729
|
+
if (pair === "" || pair.includes(";")) continue;
|
|
4730
|
+
const eq = pair.indexOf("=");
|
|
4731
|
+
const rawKey = eq < 0 ? pair : pair.slice(0, eq);
|
|
4732
|
+
const key = unescapeText(rawKey.replace(/\+/g, " "), Mode.Path);
|
|
4733
|
+
if (key !== null) keys.push(key);
|
|
4734
|
+
}
|
|
4735
|
+
return keys;
|
|
4582
4736
|
}
|
|
4583
4737
|
function goEndpointOrigin(raw, defaultPorts, protocolSeparator) {
|
|
4584
4738
|
const trimmed = goTrimSpace(raw);
|
|
@@ -4715,12 +4869,10 @@ function warnStoredShape(issues, field, provider) {
|
|
|
4715
4869
|
function familyOf(executor) {
|
|
4716
4870
|
const sep = executor.indexOf(CREDENTIAL_ENDPOINT_PAIRING.protocolSeparator);
|
|
4717
4871
|
if (sep <= 0) return null;
|
|
4718
|
-
|
|
4872
|
+
const protocol = executor.slice(0, sep);
|
|
4719
4873
|
const rest = executor.slice(sep + CREDENTIAL_ENDPOINT_PAIRING.protocolSeparator.length);
|
|
4720
4874
|
const slash = rest.indexOf("/");
|
|
4721
4875
|
const driver = slash < 0 ? rest : rest.slice(0, slash);
|
|
4722
|
-
const alias = own(CREDENTIAL_ENDPOINT_PAIRING.protocolAliases, protocol);
|
|
4723
|
-
if (typeof alias === "string") protocol = alias;
|
|
4724
4876
|
const candidates = driver === "" ? [protocol] : [protocol + CREDENTIAL_ENDPOINT_PAIRING.familyKeySeparator + driver, protocol];
|
|
4725
4877
|
for (const key of candidates) {
|
|
4726
4878
|
const family = own(CREDENTIAL_ENDPOINT_PAIRING.families, key);
|
|
@@ -4800,24 +4952,11 @@ function familyAuthorEndpoint(flow, family, step, issues) {
|
|
|
4800
4952
|
}
|
|
4801
4953
|
return null;
|
|
4802
4954
|
}
|
|
4803
|
-
function storedShapeHasOwnKey(family, query) {
|
|
4804
|
-
const shape = family.storedKeyShape;
|
|
4805
|
-
if (shape === void 0) return false;
|
|
4806
|
-
if (shape.ownKeyParams.some((key) => nonEmptyString(query, key) !== null)) return true;
|
|
4807
|
-
return isRecord(own(query, shape.ownCredentialsMapParam));
|
|
4808
|
-
}
|
|
4809
4955
|
function validateFamilies(flow, steps, issues) {
|
|
4810
4956
|
for (const step of steps) {
|
|
4811
4957
|
const found = familyOf(step.executor);
|
|
4812
4958
|
if (found === null || found.family.implicitServerCredential) continue;
|
|
4813
4959
|
const { key: familyKey, family } = found;
|
|
4814
|
-
if (family.storedKeyShape !== void 0) {
|
|
4815
|
-
if (storedShapeHasOwnKey(family, step.query)) continue;
|
|
4816
|
-
const key = family.endpointParams.find((k) => nonEmptyEndpoint(step.query, k) !== null);
|
|
4817
|
-
if (key !== void 0)
|
|
4818
|
-
warnStoredShape(issues, step.field(key), family.storedKeyShape.provider);
|
|
4819
|
-
continue;
|
|
4820
|
-
}
|
|
4821
4960
|
const secret = familySecret(flow, family, step, issues);
|
|
4822
4961
|
if (secret === null || secret.envName === null) continue;
|
|
4823
4962
|
const endpointField = familyAuthorEndpoint(flow, family, step, issues);
|
|
@@ -5052,6 +5191,1291 @@ function warnOrchestratorToolWithheld(flow, orch, report, issues) {
|
|
|
5052
5191
|
}
|
|
5053
5192
|
}
|
|
5054
5193
|
|
|
5194
|
+
// src/validators/examples.ts
|
|
5195
|
+
var KEY_EXAMPLES = "examples";
|
|
5196
|
+
var VISIBILITY_PUBLIC = "public";
|
|
5197
|
+
var STATUS_COMPLETED = "completed";
|
|
5198
|
+
var STATUS_FAILED = "failed";
|
|
5199
|
+
var STATUS_PAUSED_FOR_HUMAN = "paused_for_human";
|
|
5200
|
+
var ORIGIN_NONE = "";
|
|
5201
|
+
var SIDE_EFFECTS_NONE = "";
|
|
5202
|
+
var SCHEME_HTTPS = "https";
|
|
5203
|
+
var FILE_REF_KEYS = /* @__PURE__ */ new Set(["url", "sha256", "media_type", "note"]);
|
|
5204
|
+
var FILE_REF_KEY = "ref";
|
|
5205
|
+
var TYPE_SECRET = "secret";
|
|
5206
|
+
var TYPE_FILE2 = "file";
|
|
5207
|
+
var TYPE_STRING = "string";
|
|
5208
|
+
var TYPE_MULTILINE = "multiline";
|
|
5209
|
+
var TYPE_NUMBER2 = "number";
|
|
5210
|
+
var TYPE_BOOL = "bool";
|
|
5211
|
+
var TYPE_ENUM2 = "enum";
|
|
5212
|
+
var TYPE_ARRAY_OF_STRINGS2 = "array_of_strings";
|
|
5213
|
+
var TYPE_DATE = "date";
|
|
5214
|
+
var MAX_RECURSION_DEPTH = 32;
|
|
5215
|
+
var TEXTUAL_MEDIA_BASES = /* @__PURE__ */ new Set([
|
|
5216
|
+
"application/json",
|
|
5217
|
+
"application/xml",
|
|
5218
|
+
"application/yaml",
|
|
5219
|
+
"application/x-yaml",
|
|
5220
|
+
"application/markdown"
|
|
5221
|
+
]);
|
|
5222
|
+
var SUGGESTION_ID = "Pick a short stable name such as standard_invoice; it is the key results are filed under, so it never changes once saved";
|
|
5223
|
+
var SUGGESTION_CHECKPOINT = "Did you rename the step? Update the checkpoint to the new name";
|
|
5224
|
+
var SUGGESTION_SECRET_VALUE = "Remove the value; you are asked for it when you run the check";
|
|
5225
|
+
var SUGGESTION_EXPECTED = "Add at least a rubric: one or two sentences on what a good result looks like";
|
|
5226
|
+
var utf8Encoder2 = new TextEncoder();
|
|
5227
|
+
function byteLen(s) {
|
|
5228
|
+
return utf8Encoder2.encode(s).length;
|
|
5229
|
+
}
|
|
5230
|
+
function runeCount(s) {
|
|
5231
|
+
let n = 0;
|
|
5232
|
+
for (const _ of s) n++;
|
|
5233
|
+
return n;
|
|
5234
|
+
}
|
|
5235
|
+
function q(s) {
|
|
5236
|
+
let out = '"';
|
|
5237
|
+
for (const ch of s) {
|
|
5238
|
+
const c = ch.codePointAt(0);
|
|
5239
|
+
if (ch === '"') out += '\\"';
|
|
5240
|
+
else if (ch === "\\") out += "\\\\";
|
|
5241
|
+
else if (c === 7) out += "\\a";
|
|
5242
|
+
else if (c === 8) out += "\\b";
|
|
5243
|
+
else if (c === 12) out += "\\f";
|
|
5244
|
+
else if (c === 10) out += "\\n";
|
|
5245
|
+
else if (c === 13) out += "\\r";
|
|
5246
|
+
else if (c === 9) out += "\\t";
|
|
5247
|
+
else if (c === 11) out += "\\v";
|
|
5248
|
+
else if (c < 32 || c === 127) out += `\\x${c.toString(16).padStart(2, "0")}`;
|
|
5249
|
+
else if (c >= 128 && /[\p{C}\p{Z}]/u.test(ch)) {
|
|
5250
|
+
out += c > 65535 ? `\\U${c.toString(16).padStart(8, "0")}` : `\\u${c.toString(16).padStart(4, "0")}`;
|
|
5251
|
+
} else out += ch;
|
|
5252
|
+
}
|
|
5253
|
+
return `${out}"`;
|
|
5254
|
+
}
|
|
5255
|
+
function num(n) {
|
|
5256
|
+
if (Number.isNaN(n)) return "NaN";
|
|
5257
|
+
if (n === Infinity) return "+Inf";
|
|
5258
|
+
if (n === -Infinity) return "-Inf";
|
|
5259
|
+
if (n === 0) return Object.is(n, -0) ? "-0" : "0";
|
|
5260
|
+
const [mantissa = "", exponent = "0"] = n.toExponential().split("e");
|
|
5261
|
+
const exp = Number(exponent);
|
|
5262
|
+
if (exp < -4 || exp >= 6) {
|
|
5263
|
+
const sign = exp < 0 ? "-" : "+";
|
|
5264
|
+
return `${mantissa}e${sign}${String(Math.abs(exp)).padStart(2, "0")}`;
|
|
5265
|
+
}
|
|
5266
|
+
return String(n);
|
|
5267
|
+
}
|
|
5268
|
+
function has(o, key) {
|
|
5269
|
+
return Object.prototype.hasOwnProperty.call(o, key) && o[key] !== null && o[key] !== void 0;
|
|
5270
|
+
}
|
|
5271
|
+
function own2(o, key) {
|
|
5272
|
+
return Object.prototype.hasOwnProperty.call(o, key) ? o[key] : void 0;
|
|
5273
|
+
}
|
|
5274
|
+
function setOwn(o, key, value) {
|
|
5275
|
+
Object.defineProperty(o, key, {
|
|
5276
|
+
value,
|
|
5277
|
+
enumerable: true,
|
|
5278
|
+
writable: true,
|
|
5279
|
+
configurable: true
|
|
5280
|
+
});
|
|
5281
|
+
}
|
|
5282
|
+
function sortedKeys(o) {
|
|
5283
|
+
return Object.keys(o).sort();
|
|
5284
|
+
}
|
|
5285
|
+
function numberOf(v) {
|
|
5286
|
+
return typeof v === "number" ? v : void 0;
|
|
5287
|
+
}
|
|
5288
|
+
function normalize(v, depth) {
|
|
5289
|
+
if (depth > MAX_RECURSION_DEPTH) return null;
|
|
5290
|
+
if (v instanceof Date) {
|
|
5291
|
+
if (Number.isNaN(v.getTime())) return null;
|
|
5292
|
+
const iso = v.toISOString();
|
|
5293
|
+
if (/T00:00:00\.000Z$/.test(iso)) return iso.slice(0, 10);
|
|
5294
|
+
return iso.replace(/\.000Z$/, "Z");
|
|
5295
|
+
}
|
|
5296
|
+
if (Array.isArray(v)) return v.map((x) => normalize(x, depth + 1));
|
|
5297
|
+
if (isRecord(v)) {
|
|
5298
|
+
const out = {};
|
|
5299
|
+
for (const k of Object.keys(v)) setOwn(out, k, normalize(v[k], depth + 1));
|
|
5300
|
+
return out;
|
|
5301
|
+
}
|
|
5302
|
+
return v;
|
|
5303
|
+
}
|
|
5304
|
+
function deepCopy(v, depth) {
|
|
5305
|
+
if (depth > MAX_RECURSION_DEPTH) return v;
|
|
5306
|
+
if (Array.isArray(v)) return v.map((x) => deepCopy(x, depth + 1));
|
|
5307
|
+
if (isRecord(v)) {
|
|
5308
|
+
const out = {};
|
|
5309
|
+
for (const k of Object.keys(v)) setOwn(out, k, deepCopy(v[k], depth + 1));
|
|
5310
|
+
return out;
|
|
5311
|
+
}
|
|
5312
|
+
return v;
|
|
5313
|
+
}
|
|
5314
|
+
function mergePatch(target, patch, depth) {
|
|
5315
|
+
if (depth > MAX_RECURSION_DEPTH) return;
|
|
5316
|
+
for (const k of Object.keys(patch)) {
|
|
5317
|
+
const pv = patch[k];
|
|
5318
|
+
if (pv === null || pv === void 0) {
|
|
5319
|
+
delete target[k];
|
|
5320
|
+
continue;
|
|
5321
|
+
}
|
|
5322
|
+
if (isRecord(pv)) {
|
|
5323
|
+
const current = own2(target, k);
|
|
5324
|
+
const existing = isRecord(current) ? deepCopy(current, 0) : {};
|
|
5325
|
+
mergePatch(existing, pv, depth + 1);
|
|
5326
|
+
setOwn(target, k, existing);
|
|
5327
|
+
continue;
|
|
5328
|
+
}
|
|
5329
|
+
setOwn(target, k, deepCopy(pv, 0));
|
|
5330
|
+
}
|
|
5331
|
+
}
|
|
5332
|
+
function applyExamplePatch(base, patch) {
|
|
5333
|
+
const out = deepCopy(base, 0);
|
|
5334
|
+
mergePatch(out, patch, 0);
|
|
5335
|
+
return out;
|
|
5336
|
+
}
|
|
5337
|
+
function asFileRef(v) {
|
|
5338
|
+
if (!isRecord(v)) return null;
|
|
5339
|
+
const keys = Object.keys(v);
|
|
5340
|
+
if (keys.length === 0) return null;
|
|
5341
|
+
for (const k of keys) if (!FILE_REF_KEYS.has(k)) return null;
|
|
5342
|
+
const str = (k) => {
|
|
5343
|
+
const x = own2(v, k);
|
|
5344
|
+
return typeof x === "string" ? x : "";
|
|
5345
|
+
};
|
|
5346
|
+
return {
|
|
5347
|
+
url: str("url"),
|
|
5348
|
+
sha256: str("sha256"),
|
|
5349
|
+
mediaType: str("media_type"),
|
|
5350
|
+
note: str("note")
|
|
5351
|
+
};
|
|
5352
|
+
}
|
|
5353
|
+
function isTextualMediaType(mediaType) {
|
|
5354
|
+
const base = goToLower(goTrimSpace((mediaType.split(";")[0] ?? "").toString()));
|
|
5355
|
+
if (base.startsWith("text/")) return true;
|
|
5356
|
+
if (base.endsWith("+json") || base.endsWith("+xml")) return true;
|
|
5357
|
+
return TEXTUAL_MEDIA_BASES.has(base);
|
|
5358
|
+
}
|
|
5359
|
+
var Walker = class _Walker {
|
|
5360
|
+
constructor(flow, issues) {
|
|
5361
|
+
this.flow = flow;
|
|
5362
|
+
this.issues = issues;
|
|
5363
|
+
this.findings = [];
|
|
5364
|
+
}
|
|
5365
|
+
// -- emit -------------------------------------------------------------
|
|
5366
|
+
add(severity, code, field, message, suggestion) {
|
|
5367
|
+
this.findings.push({
|
|
5368
|
+
code,
|
|
5369
|
+
severity,
|
|
5370
|
+
field,
|
|
5371
|
+
message,
|
|
5372
|
+
...suggestion !== void 0 ? { suggestion } : {}
|
|
5373
|
+
});
|
|
5374
|
+
}
|
|
5375
|
+
err(code, field, message, suggestion) {
|
|
5376
|
+
this.add("error", code, field, message, suggestion);
|
|
5377
|
+
}
|
|
5378
|
+
warn(code, field, message) {
|
|
5379
|
+
this.add("warning", code, field, message);
|
|
5380
|
+
}
|
|
5381
|
+
/** A Go `string` field read by its source text; absent is "". */
|
|
5382
|
+
s(o, key, parentPath) {
|
|
5383
|
+
return this.issues.stringOf(o, key, parentPath) ?? "";
|
|
5384
|
+
}
|
|
5385
|
+
// -- the set ----------------------------------------------------------
|
|
5386
|
+
run(examples) {
|
|
5387
|
+
this.validateSet(examples);
|
|
5388
|
+
const seen = /* @__PURE__ */ new Map();
|
|
5389
|
+
examples.forEach((ex, i) => {
|
|
5390
|
+
if (isRecord(ex)) this.validateExample(i, ex, seen);
|
|
5391
|
+
});
|
|
5392
|
+
}
|
|
5393
|
+
validateSet(examples) {
|
|
5394
|
+
const n = examples.length;
|
|
5395
|
+
const L = EXAMPLES.limits;
|
|
5396
|
+
if (n > L.maxPerFlow) {
|
|
5397
|
+
this.err(
|
|
5398
|
+
"examples_too_many",
|
|
5399
|
+
KEY_EXAMPLES,
|
|
5400
|
+
`flow declares ${n} examples; the limit is ${L.maxPerFlow}`
|
|
5401
|
+
);
|
|
5402
|
+
}
|
|
5403
|
+
const size = blockBytes(examples);
|
|
5404
|
+
if (size !== null && size > L.maxBlockBytes) {
|
|
5405
|
+
this.err(
|
|
5406
|
+
"examples_block_too_large",
|
|
5407
|
+
KEY_EXAMPLES,
|
|
5408
|
+
`the examples block is ${size} bytes; the limit is ${L.maxBlockBytes}. Move large inputs or target outputs to a file reference (https URL).`
|
|
5409
|
+
);
|
|
5410
|
+
}
|
|
5411
|
+
const allHeld = examples.every((e) => isRecord(e) && own2(e, "hold_out") === true);
|
|
5412
|
+
if (allHeld) {
|
|
5413
|
+
this.warn(
|
|
5414
|
+
"examples_all_held_out",
|
|
5415
|
+
KEY_EXAMPLES,
|
|
5416
|
+
"every example is held out, so nothing is left to tune on"
|
|
5417
|
+
);
|
|
5418
|
+
}
|
|
5419
|
+
if (this.isPublic()) {
|
|
5420
|
+
this.warn(
|
|
5421
|
+
"examples_published_with_public_flow",
|
|
5422
|
+
KEY_EXAMPLES,
|
|
5423
|
+
"this flow is public, so everyone who can see it can read its examples, including their expected results. Only publish examples you are happy to show."
|
|
5424
|
+
);
|
|
5425
|
+
}
|
|
5426
|
+
}
|
|
5427
|
+
isPublic() {
|
|
5428
|
+
return this.s(this.flow, "visibility", "") === VISIBILITY_PUBLIC;
|
|
5429
|
+
}
|
|
5430
|
+
// -- one example ------------------------------------------------------
|
|
5431
|
+
validateExample(i, ex, seen) {
|
|
5432
|
+
const L = EXAMPLES.limits;
|
|
5433
|
+
const path = `examples[${i}]`;
|
|
5434
|
+
const id = this.s(ex, "id", path);
|
|
5435
|
+
const label = id === "" ? `#${i + 1}` : id;
|
|
5436
|
+
if (id === "") {
|
|
5437
|
+
this.err("example_id_missing", `${path}.id`, `example #${i + 1} has no id`, SUGGESTION_ID);
|
|
5438
|
+
} else if (!EXAMPLES.idPattern.test(id)) {
|
|
5439
|
+
this.err(
|
|
5440
|
+
"example_id_invalid",
|
|
5441
|
+
`${path}.id`,
|
|
5442
|
+
`example id ${q(id)} is not valid: use lower-case letters, digits and underscores, starting with a letter (2 to 48 characters)`,
|
|
5443
|
+
SUGGESTION_ID
|
|
5444
|
+
);
|
|
5445
|
+
} else {
|
|
5446
|
+
const first = seen.get(id);
|
|
5447
|
+
if (first !== void 0) {
|
|
5448
|
+
this.err(
|
|
5449
|
+
"example_id_duplicate",
|
|
5450
|
+
`${path}.id`,
|
|
5451
|
+
`example id ${q(id)} is used by examples #${first + 1} and #${i + 1}`
|
|
5452
|
+
);
|
|
5453
|
+
} else {
|
|
5454
|
+
seen.set(id, i);
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
const title = this.s(ex, "title", path);
|
|
5458
|
+
if (goTrimSpace(title) === "") {
|
|
5459
|
+
this.err(
|
|
5460
|
+
"example_title_missing",
|
|
5461
|
+
`${path}.title`,
|
|
5462
|
+
`example ${q(label)} has no title; the title is what a person sees in the list of examples`
|
|
5463
|
+
);
|
|
5464
|
+
} else {
|
|
5465
|
+
const n = runeCount(title);
|
|
5466
|
+
if (n > L.titleMaxRunes) {
|
|
5467
|
+
this.err(
|
|
5468
|
+
"example_title_too_long",
|
|
5469
|
+
`${path}.title`,
|
|
5470
|
+
`example ${q(label)} title is ${n} characters; the limit is ${L.titleMaxRunes}`
|
|
5471
|
+
);
|
|
5472
|
+
}
|
|
5473
|
+
}
|
|
5474
|
+
const guidance = this.s(ex, "guidance", path);
|
|
5475
|
+
if (goTrimSpace(guidance) === "") {
|
|
5476
|
+
this.warn(
|
|
5477
|
+
"example_guidance_missing",
|
|
5478
|
+
`${path}.guidance`,
|
|
5479
|
+
`example ${q(label)} has no guidance. One sentence on why this case matters helps the judge and the next author.`
|
|
5480
|
+
);
|
|
5481
|
+
} else {
|
|
5482
|
+
const n = runeCount(guidance);
|
|
5483
|
+
if (n > L.maxGuidanceRunes) {
|
|
5484
|
+
this.err(
|
|
5485
|
+
"example_guidance_too_long",
|
|
5486
|
+
`${path}.guidance`,
|
|
5487
|
+
`example ${q(label)} guidance is ${n} characters; the limit is ${L.maxGuidanceRunes}`
|
|
5488
|
+
);
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
const notesN = runeCount(this.s(ex, "notes", path));
|
|
5492
|
+
if (notesN > L.maxNotesRunes) {
|
|
5493
|
+
this.err(
|
|
5494
|
+
"example_notes_too_long",
|
|
5495
|
+
`${path}.notes`,
|
|
5496
|
+
`example ${q(label)} notes are ${notesN} characters; the limit is ${L.maxNotesRunes}`
|
|
5497
|
+
);
|
|
5498
|
+
}
|
|
5499
|
+
this.validateTags(path, label, own2(ex, "tags"));
|
|
5500
|
+
this.validateWeight(`${path}.weight`, label, numberOf(own2(ex, "weight")));
|
|
5501
|
+
const minScore = numberOf(own2(ex, "min_score"));
|
|
5502
|
+
if (minScore !== void 0 && !scoreInRange(minScore)) {
|
|
5503
|
+
this.err(
|
|
5504
|
+
"example_min_score_range",
|
|
5505
|
+
`${path}.min_score`,
|
|
5506
|
+
`example ${q(label)} has min_score ${num(minScore)}; use a number from 0 to 1 (0.7 is 7.3 out of 10)`
|
|
5507
|
+
);
|
|
5508
|
+
}
|
|
5509
|
+
const sideEffects = this.s(ex, "side_effects", path);
|
|
5510
|
+
if (sideEffects !== SIDE_EFFECTS_NONE && !EXAMPLES.sideEffects.has(sideEffects)) {
|
|
5511
|
+
this.err(
|
|
5512
|
+
"example_side_effects_invalid",
|
|
5513
|
+
`${path}.side_effects`,
|
|
5514
|
+
`example ${q(label)} has side_effects ${q(sideEffects)}; use refuse or allow`
|
|
5515
|
+
);
|
|
5516
|
+
}
|
|
5517
|
+
const holdOut = own2(ex, "hold_out") === true;
|
|
5518
|
+
if (holdOut && this.isPublic()) {
|
|
5519
|
+
this.err(
|
|
5520
|
+
"example_holdout_in_public_flow",
|
|
5521
|
+
`${path}.hold_out`,
|
|
5522
|
+
`example ${q(label)} is held out but this flow is public: a held-out example must stay private, and a public flow's definition is readable by everyone. Make the flow private or remove hold_out.`
|
|
5523
|
+
);
|
|
5524
|
+
}
|
|
5525
|
+
const hasInput = has(ex, "input");
|
|
5526
|
+
const hasInputRef = has(ex, "input_ref");
|
|
5527
|
+
if (hasInput && hasInputRef) {
|
|
5528
|
+
this.err(
|
|
5529
|
+
"example_input_conflict",
|
|
5530
|
+
path,
|
|
5531
|
+
`example ${q(label)} sets both input and input_ref; use exactly one`
|
|
5532
|
+
);
|
|
5533
|
+
} else if (!hasInput && !hasInputRef) {
|
|
5534
|
+
this.err(
|
|
5535
|
+
"example_input_missing",
|
|
5536
|
+
path,
|
|
5537
|
+
`example ${q(label)} has neither input nor input_ref; use input: {} for a flow that takes no input`
|
|
5538
|
+
);
|
|
5539
|
+
}
|
|
5540
|
+
const rawInput = own2(ex, "input");
|
|
5541
|
+
const baseInput = isRecord(rawInput) ? rawInput : null;
|
|
5542
|
+
if (baseInput !== null) {
|
|
5543
|
+
this.checkInput(`${path}.input`, label, baseInput, "example_input_invalid");
|
|
5544
|
+
}
|
|
5545
|
+
const rawInputRef = own2(ex, "input_ref");
|
|
5546
|
+
if (isRecord(rawInputRef)) {
|
|
5547
|
+
this.validateFileRef(`${path}.input_ref`, this.fileRefOf(rawInputRef, `${path}.input_ref`));
|
|
5548
|
+
}
|
|
5549
|
+
let binaryOnly = false;
|
|
5550
|
+
const expected = own2(ex, "expected");
|
|
5551
|
+
if (!has(ex, "expected")) {
|
|
5552
|
+
this.err(
|
|
5553
|
+
"example_expected_missing",
|
|
5554
|
+
`${path}.expected`,
|
|
5555
|
+
`example ${q(label)} does not say what a good result is: add a rubric, fields, exact or reference`,
|
|
5556
|
+
SUGGESTION_EXPECTED
|
|
5557
|
+
);
|
|
5558
|
+
} else if (isRecord(expected)) {
|
|
5559
|
+
this.validateExpectation(`${path}.expected`, label, expected, "final", "");
|
|
5560
|
+
binaryOnly = this.expectationIsBinaryReferenceOnly(expected, `${path}.expected`);
|
|
5561
|
+
}
|
|
5562
|
+
if (binaryOnly) {
|
|
5563
|
+
this.warn(
|
|
5564
|
+
"examples_unreadable_by_judge",
|
|
5565
|
+
`${path}.expected`,
|
|
5566
|
+
"this example can be run but not scored"
|
|
5567
|
+
);
|
|
5568
|
+
}
|
|
5569
|
+
this.validateCheckpoints(path, label, own2(ex, "checkpoints"));
|
|
5570
|
+
this.validateVariants(i, path, label, ex, hasInput, baseInput);
|
|
5571
|
+
this.scanSecretLike(i, path, ex);
|
|
5572
|
+
}
|
|
5573
|
+
validateTags(path, label, tags) {
|
|
5574
|
+
if (!Array.isArray(tags)) return;
|
|
5575
|
+
if (tags.length > EXAMPLES.limits.maxTags) {
|
|
5576
|
+
this.err(
|
|
5577
|
+
"example_tag_invalid",
|
|
5578
|
+
`${path}.tags`,
|
|
5579
|
+
`example ${q(label)} has ${tags.length} tags; the limit is ${EXAMPLES.limits.maxTags}`
|
|
5580
|
+
);
|
|
5581
|
+
}
|
|
5582
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5583
|
+
tags.forEach((item, j) => {
|
|
5584
|
+
const field = `${path}.tags[${j}]`;
|
|
5585
|
+
const tag = item === null ? "" : this.issues.stringAt(item, field) ?? null;
|
|
5586
|
+
if (tag === null) return;
|
|
5587
|
+
if (!EXAMPLES.tagPattern.test(tag)) {
|
|
5588
|
+
this.err("example_tag_invalid", field, `example ${q(label)} has an invalid tag ${q(tag)}`);
|
|
5589
|
+
} else if (seen.has(tag)) {
|
|
5590
|
+
this.err(
|
|
5591
|
+
"example_tag_invalid",
|
|
5592
|
+
field,
|
|
5593
|
+
`example ${q(label)} lists the tag ${q(tag)} more than once`
|
|
5594
|
+
);
|
|
5595
|
+
}
|
|
5596
|
+
seen.add(tag);
|
|
5597
|
+
});
|
|
5598
|
+
}
|
|
5599
|
+
validateWeight(field, label, weight) {
|
|
5600
|
+
if (weight === void 0) return;
|
|
5601
|
+
if (Number.isNaN(weight) || weight <= 0 || weight > EXAMPLES.limits.weightMax) {
|
|
5602
|
+
this.err(
|
|
5603
|
+
"example_weight_range",
|
|
5604
|
+
field,
|
|
5605
|
+
`example ${q(label)} has weight ${num(weight)}; use a number above 0 and at most 10`
|
|
5606
|
+
);
|
|
5607
|
+
}
|
|
5608
|
+
}
|
|
5609
|
+
// -- input ------------------------------------------------------------
|
|
5610
|
+
/**
|
|
5611
|
+
* Judge one inline input map (an example's `input`, or a variant's patched
|
|
5612
|
+
* input). NARROWED relative to the reference, which runs its full value
|
|
5613
|
+
* validator: here an unknown field, a missing required field, a value of the
|
|
5614
|
+
* wrong KIND and an enum value outside its list are judged; length, range,
|
|
5615
|
+
* pattern and date-format constraints are not (PARITY.md).
|
|
5616
|
+
*/
|
|
5617
|
+
checkInput(field, label, raw, code) {
|
|
5618
|
+
const input = normalize(raw, 0) ?? {};
|
|
5619
|
+
const L = EXAMPLES.limits;
|
|
5620
|
+
const size = jsonBytes(input);
|
|
5621
|
+
if (size !== null && size > L.maxInlineInputBytes) {
|
|
5622
|
+
this.err(
|
|
5623
|
+
"example_input_too_large",
|
|
5624
|
+
field,
|
|
5625
|
+
`example ${q(label)} input is ${size} bytes; the limit is ${L.maxInlineInputBytes}. Put the large part behind an https file reference.`
|
|
5626
|
+
);
|
|
5627
|
+
return;
|
|
5628
|
+
}
|
|
5629
|
+
const schema = own2(this.flow, "input_schema");
|
|
5630
|
+
const query = own2(this.flow, "query");
|
|
5631
|
+
if (isRecord(schema)) {
|
|
5632
|
+
this.checkInputAgainstSchema(field, label, input, schema, code);
|
|
5633
|
+
} else if (isRecord(query) && Object.keys(query).length > 0) {
|
|
5634
|
+
const declared = sortedKeys(query);
|
|
5635
|
+
for (const k of sortedKeys(input)) {
|
|
5636
|
+
if (!Object.prototype.hasOwnProperty.call(query, k)) {
|
|
5637
|
+
this.err(
|
|
5638
|
+
code,
|
|
5639
|
+
`${field}.${k}`,
|
|
5640
|
+
`example ${q(label)}: ${q(k)} is not a declared input of this flow (declared: ${declared.join(", ")})`
|
|
5641
|
+
);
|
|
5642
|
+
}
|
|
5643
|
+
}
|
|
5644
|
+
} else {
|
|
5645
|
+
this.warn(
|
|
5646
|
+
"example_input_unvalidated",
|
|
5647
|
+
field,
|
|
5648
|
+
`example ${q(label)} cannot be checked: the flow declares no input_schema and no query parameters.`
|
|
5649
|
+
);
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5652
|
+
checkInputAgainstSchema(field, label, input, schema, code) {
|
|
5653
|
+
const fields = this.schemaFields(schema);
|
|
5654
|
+
const byName = /* @__PURE__ */ new Map();
|
|
5655
|
+
for (const f of fields) byName.set(f.name, f);
|
|
5656
|
+
const runInput = {};
|
|
5657
|
+
for (const name of sortedKeys(input)) {
|
|
5658
|
+
const val = input[name];
|
|
5659
|
+
const f = byName.get(name);
|
|
5660
|
+
const present = val !== null && val !== void 0;
|
|
5661
|
+
if (f !== void 0 && f.type === TYPE_SECRET) {
|
|
5662
|
+
if (present) {
|
|
5663
|
+
this.err(
|
|
5664
|
+
"example_secret_value",
|
|
5665
|
+
`${field}.${name}`,
|
|
5666
|
+
`example ${q(label)} gives a value for ${q(name)}, which is a secret field. Examples are saved inside the flow and are never allowed to hold secrets; remove it. The person running the evaluation is asked for it at run time.`,
|
|
5667
|
+
SUGGESTION_SECRET_VALUE
|
|
5668
|
+
);
|
|
5669
|
+
}
|
|
5670
|
+
continue;
|
|
5671
|
+
}
|
|
5672
|
+
if (f !== void 0 && f.type === TYPE_FILE2 && present) {
|
|
5673
|
+
const ref = asFileRef(val);
|
|
5674
|
+
if (ref === null) {
|
|
5675
|
+
this.err(
|
|
5676
|
+
"example_file_input_needs_ref",
|
|
5677
|
+
`${field}.${name}`,
|
|
5678
|
+
`example ${q(label)}: field ${q(name)} is a file; give it as {url: "https://\u2026"}. A pasted upload id would stop working as soon as the session ends.`
|
|
5679
|
+
);
|
|
5680
|
+
continue;
|
|
5681
|
+
}
|
|
5682
|
+
this.validateFileRef(`${field}.${name}`, ref);
|
|
5683
|
+
setOwn(runInput, name, { [FILE_REF_KEY]: ref.url });
|
|
5684
|
+
continue;
|
|
5685
|
+
}
|
|
5686
|
+
setOwn(runInput, name, val);
|
|
5687
|
+
}
|
|
5688
|
+
for (const failure of this.judgeRun(fields, byName, runInput)) {
|
|
5689
|
+
if (failure.required) {
|
|
5690
|
+
const f = byName.get(failure.field);
|
|
5691
|
+
if (f !== void 0 && f.type === TYPE_SECRET) continue;
|
|
5692
|
+
}
|
|
5693
|
+
const at = failure.field !== "" ? `${field}.${failure.field}` : field;
|
|
5694
|
+
this.err(code, at, `example ${q(label)}: ${failure.message}`);
|
|
5695
|
+
}
|
|
5696
|
+
}
|
|
5697
|
+
schemaFields(schema) {
|
|
5698
|
+
const raw = own2(schema, "fields");
|
|
5699
|
+
if (!Array.isArray(raw)) return [];
|
|
5700
|
+
const out = [];
|
|
5701
|
+
raw.forEach((f, i) => {
|
|
5702
|
+
if (!isRecord(f)) return;
|
|
5703
|
+
const base = `input_schema.fields[${i}]`;
|
|
5704
|
+
const enumRaw = own2(f, "enum");
|
|
5705
|
+
const enumValues = [];
|
|
5706
|
+
if (Array.isArray(enumRaw)) {
|
|
5707
|
+
enumRaw.forEach((e, j) => {
|
|
5708
|
+
enumValues.push(e === null ? "" : this.issues.stringAt(e, `${base}.enum[${j}]`) ?? "");
|
|
5709
|
+
});
|
|
5710
|
+
}
|
|
5711
|
+
const vw = own2(f, "visible_when");
|
|
5712
|
+
out.push({
|
|
5713
|
+
name: this.s(f, "name", base),
|
|
5714
|
+
type: this.s(f, "type", base),
|
|
5715
|
+
required: own2(f, "required") === true,
|
|
5716
|
+
enumValues,
|
|
5717
|
+
visibleWhen: isRecord(vw) ? {
|
|
5718
|
+
field: this.s(vw, "field", `${base}.visible_when`),
|
|
5719
|
+
equals: own2(vw, "equals"),
|
|
5720
|
+
in: Array.isArray(own2(vw, "in")) ? own2(vw, "in") : []
|
|
5721
|
+
} : null
|
|
5722
|
+
});
|
|
5723
|
+
});
|
|
5724
|
+
return out;
|
|
5725
|
+
}
|
|
5726
|
+
/** The narrowed run-time judgement: required, kind, enum, unknown field. */
|
|
5727
|
+
judgeRun(fields, byName, runInput) {
|
|
5728
|
+
const failures = [];
|
|
5729
|
+
for (const f of fields) {
|
|
5730
|
+
if (!isVisible(f, runInput)) continue;
|
|
5731
|
+
const raw = own2(runInput, f.name);
|
|
5732
|
+
if (raw === void 0 || raw === null) {
|
|
5733
|
+
if (f.required) {
|
|
5734
|
+
failures.push({
|
|
5735
|
+
field: f.name,
|
|
5736
|
+
message: `input field ${q(f.name)} is required`,
|
|
5737
|
+
required: true
|
|
5738
|
+
});
|
|
5739
|
+
}
|
|
5740
|
+
continue;
|
|
5741
|
+
}
|
|
5742
|
+
failures.push(...inputValueFailures(f, raw));
|
|
5743
|
+
}
|
|
5744
|
+
for (const k of sortedKeys(runInput)) {
|
|
5745
|
+
if (!byName.has(k)) {
|
|
5746
|
+
failures.push({
|
|
5747
|
+
field: k,
|
|
5748
|
+
message: `input field ${q(k)} is not declared in input_schema`,
|
|
5749
|
+
required: false
|
|
5750
|
+
});
|
|
5751
|
+
}
|
|
5752
|
+
}
|
|
5753
|
+
return failures;
|
|
5754
|
+
}
|
|
5755
|
+
// -- file reference ---------------------------------------------------
|
|
5756
|
+
fileRefOf(rec, path) {
|
|
5757
|
+
return {
|
|
5758
|
+
url: this.s(rec, "url", path),
|
|
5759
|
+
sha256: this.s(rec, "sha256", path),
|
|
5760
|
+
mediaType: this.s(rec, "media_type", path),
|
|
5761
|
+
note: this.s(rec, "note", path)
|
|
5762
|
+
};
|
|
5763
|
+
}
|
|
5764
|
+
validateFileRef(field, ref) {
|
|
5765
|
+
const L = EXAMPLES.limits;
|
|
5766
|
+
const raw = ref.url;
|
|
5767
|
+
const invalid = "the file reference needs a url of at most 2048 characters";
|
|
5768
|
+
if (raw === "" || byteLen(raw) > L.maxUrlBytes) {
|
|
5769
|
+
this.err("example_ref_invalid", field, invalid);
|
|
5770
|
+
return;
|
|
5771
|
+
}
|
|
5772
|
+
const u = goParseURLParts(raw);
|
|
5773
|
+
if (u === null) {
|
|
5774
|
+
this.err("example_ref_invalid", field, invalid);
|
|
5775
|
+
return;
|
|
5776
|
+
}
|
|
5777
|
+
const scheme = u.scheme.toLowerCase();
|
|
5778
|
+
if (EXAMPLES.reservedRefSchemes.has(scheme)) {
|
|
5779
|
+
this.err(
|
|
5780
|
+
"example_ref_scheme_reserved",
|
|
5781
|
+
field,
|
|
5782
|
+
`${scheme}: references are not available yet. Use an https URL, or paste the text into the example.`
|
|
5783
|
+
);
|
|
5784
|
+
return;
|
|
5785
|
+
}
|
|
5786
|
+
if (scheme !== SCHEME_HTTPS) {
|
|
5787
|
+
this.err(
|
|
5788
|
+
"example_ref_scheme",
|
|
5789
|
+
field,
|
|
5790
|
+
`only https:// references are allowed (got ${q(scheme)})`
|
|
5791
|
+
);
|
|
5792
|
+
return;
|
|
5793
|
+
}
|
|
5794
|
+
if (u.hasUser || u.fragment !== "" || raw.includes("#") || u.host === "") {
|
|
5795
|
+
this.err("example_ref_invalid", field, "a reference must not carry a login or a fragment");
|
|
5796
|
+
return;
|
|
5797
|
+
}
|
|
5798
|
+
if (ref.sha256 !== "" && !EXAMPLES.sha256Pattern.test(ref.sha256)) {
|
|
5799
|
+
this.err(
|
|
5800
|
+
"example_ref_sha256_invalid",
|
|
5801
|
+
field,
|
|
5802
|
+
"sha256 must be 64 lowercase hexadecimal characters"
|
|
5803
|
+
);
|
|
5804
|
+
}
|
|
5805
|
+
if (ref.mediaType !== "" && !EXAMPLES.mediaTypePattern.test(ref.mediaType)) {
|
|
5806
|
+
this.err(
|
|
5807
|
+
"example_ref_media_type_invalid",
|
|
5808
|
+
field,
|
|
5809
|
+
`media_type ${q(ref.mediaType)} must look like type/subtype`
|
|
5810
|
+
);
|
|
5811
|
+
}
|
|
5812
|
+
const noteN = runeCount(ref.note);
|
|
5813
|
+
if (noteN > L.maxNoteRunes) {
|
|
5814
|
+
this.err(
|
|
5815
|
+
"example_ref_invalid",
|
|
5816
|
+
field,
|
|
5817
|
+
`the note is ${noteN} characters; the limit is ${L.maxNoteRunes}`
|
|
5818
|
+
);
|
|
5819
|
+
}
|
|
5820
|
+
if (ref.sha256 === "") {
|
|
5821
|
+
this.warn(
|
|
5822
|
+
"example_ref_unpinned",
|
|
5823
|
+
field,
|
|
5824
|
+
"this reference is not pinned. If the file at that address changes, your scores change with it. Add sha256 to freeze it."
|
|
5825
|
+
);
|
|
5826
|
+
}
|
|
5827
|
+
for (const key of goQueryKeys(u.rawQuery)) {
|
|
5828
|
+
if (EXAMPLES.signedUrlQueryKeyPattern.test(key)) {
|
|
5829
|
+
this.warn(
|
|
5830
|
+
"example_ref_signed_url",
|
|
5831
|
+
field,
|
|
5832
|
+
"this address looks like a signed link. Anyone who can read the flow can use it until it expires, and it will stop working. Prefer a stable public address."
|
|
5833
|
+
);
|
|
5834
|
+
break;
|
|
5835
|
+
}
|
|
5836
|
+
}
|
|
5837
|
+
}
|
|
5838
|
+
// -- expectation ------------------------------------------------------
|
|
5839
|
+
/** The names `fields` / `exact` may use, and whether such a list is declared at all. */
|
|
5840
|
+
outputNamesFor(kind, stepId) {
|
|
5841
|
+
if (kind === "final") {
|
|
5842
|
+
const out = own2(this.flow, "output");
|
|
5843
|
+
const names2 = [];
|
|
5844
|
+
if (Array.isArray(out)) {
|
|
5845
|
+
out.forEach((item, i) => {
|
|
5846
|
+
names2.push(item === null ? "" : this.issues.stringAt(item, `output[${i}]`) ?? "");
|
|
5847
|
+
});
|
|
5848
|
+
}
|
|
5849
|
+
return { names: names2, declared: names2.length > 0 };
|
|
5850
|
+
}
|
|
5851
|
+
const steps = own2(this.flow, "steps");
|
|
5852
|
+
const step = isRecord(steps) ? own2(steps, stepId) : void 0;
|
|
5853
|
+
const schema = isRecord(step) ? own2(step, "output_schema") : void 0;
|
|
5854
|
+
const fields = isRecord(schema) ? own2(schema, "fields") : void 0;
|
|
5855
|
+
if (!Array.isArray(fields) || fields.length === 0) return { names: [], declared: false };
|
|
5856
|
+
const names = [];
|
|
5857
|
+
fields.forEach((f, i) => {
|
|
5858
|
+
if (isRecord(f)) names.push(this.s(f, "name", `steps.${stepId}.output_schema.fields[${i}]`));
|
|
5859
|
+
});
|
|
5860
|
+
return { names, declared: true };
|
|
5861
|
+
}
|
|
5862
|
+
validateExpectation(path, label, e, kind, stepId) {
|
|
5863
|
+
const L = EXAMPLES.limits;
|
|
5864
|
+
const status = this.s(e, "status", path);
|
|
5865
|
+
if (status !== "" && !EXAMPLES.statuses.has(status)) {
|
|
5866
|
+
this.err(
|
|
5867
|
+
"example_status_invalid",
|
|
5868
|
+
`${path}.status`,
|
|
5869
|
+
"status must be completed, failed or paused_for_human"
|
|
5870
|
+
);
|
|
5871
|
+
}
|
|
5872
|
+
const noOutput = status === STATUS_FAILED || status === STATUS_PAUSED_FOR_HUMAN;
|
|
5873
|
+
const fieldsRec = own2(e, "fields");
|
|
5874
|
+
const exactRec = own2(e, "exact");
|
|
5875
|
+
const fieldKeys = isRecord(fieldsRec) ? sortedKeys(fieldsRec) : [];
|
|
5876
|
+
const exactKeys = isRecord(exactRec) ? sortedKeys(exactRec) : [];
|
|
5877
|
+
const hasFields = fieldKeys.length > 0;
|
|
5878
|
+
const hasExact = exactKeys.length > 0;
|
|
5879
|
+
if (hasFields && hasExact) {
|
|
5880
|
+
this.err(
|
|
5881
|
+
"example_expected_conflict",
|
|
5882
|
+
path,
|
|
5883
|
+
"use fields (some fields) or exact (the whole result), not both"
|
|
5884
|
+
);
|
|
5885
|
+
} else if (noOutput && (hasFields || hasExact)) {
|
|
5886
|
+
this.err(
|
|
5887
|
+
"example_expected_conflict",
|
|
5888
|
+
path,
|
|
5889
|
+
`a case that ends in ${status} has no output to match; remove fields and exact, or expect status completed`
|
|
5890
|
+
);
|
|
5891
|
+
}
|
|
5892
|
+
const minScore = numberOf(own2(e, "min_score"));
|
|
5893
|
+
if (minScore !== void 0 && !scoreInRange(minScore)) {
|
|
5894
|
+
this.err(
|
|
5895
|
+
"example_min_score_range",
|
|
5896
|
+
`${path}.min_score`,
|
|
5897
|
+
`min_score ${num(minScore)} is out of range; use a number from 0 to 1`
|
|
5898
|
+
);
|
|
5899
|
+
}
|
|
5900
|
+
const rubric = this.s(e, "rubric", path);
|
|
5901
|
+
if (rubric !== "") {
|
|
5902
|
+
if (goTrimSpace(rubric) === "") {
|
|
5903
|
+
this.err(
|
|
5904
|
+
"example_rubric_empty",
|
|
5905
|
+
`${path}.rubric`,
|
|
5906
|
+
"the rubric is empty; write what a good result looks like, or remove it"
|
|
5907
|
+
);
|
|
5908
|
+
} else {
|
|
5909
|
+
const n = runeCount(rubric);
|
|
5910
|
+
if (n > L.maxRubricRunes) {
|
|
5911
|
+
this.err(
|
|
5912
|
+
"example_rubric_too_long",
|
|
5913
|
+
`${path}.rubric`,
|
|
5914
|
+
`the rubric is ${n} characters; the limit is ${L.maxRubricRunes}`
|
|
5915
|
+
);
|
|
5916
|
+
}
|
|
5917
|
+
}
|
|
5918
|
+
}
|
|
5919
|
+
const reference = own2(e, "reference");
|
|
5920
|
+
if (isRecord(reference)) this.validateReference(`${path}.reference`, reference);
|
|
5921
|
+
const { names, declared } = this.outputNamesFor(kind, stepId);
|
|
5922
|
+
const checkKey = (field, key) => {
|
|
5923
|
+
if (!declared && kind === "final") {
|
|
5924
|
+
this.warn(
|
|
5925
|
+
"example_expected_field_unchecked",
|
|
5926
|
+
field,
|
|
5927
|
+
`this flow declares no output list, so ${q(key)} cannot be checked against it`
|
|
5928
|
+
);
|
|
5929
|
+
} else if (!declared) {
|
|
5930
|
+
this.warn(
|
|
5931
|
+
"example_expected_field_unchecked",
|
|
5932
|
+
field,
|
|
5933
|
+
`this step declares no output_schema, so ${q(key)} cannot be checked against it`
|
|
5934
|
+
);
|
|
5935
|
+
} else if (!names.includes(key)) {
|
|
5936
|
+
this.err(
|
|
5937
|
+
"example_expected_field_unknown",
|
|
5938
|
+
field,
|
|
5939
|
+
kind === "checkpoint" ? `${q(key)} is not a field this step declares in its output_schema (declared: ${names.join(", ")})` : `${q(key)} is not an output of this flow (outputs: ${names.join(", ")})`
|
|
5940
|
+
);
|
|
5941
|
+
}
|
|
5942
|
+
};
|
|
5943
|
+
for (const key of fieldKeys) {
|
|
5944
|
+
const fpath = `${path}.fields.${key}`;
|
|
5945
|
+
checkKey(fpath, key);
|
|
5946
|
+
const matcher = own2(fieldsRec, key);
|
|
5947
|
+
if (isRecord(matcher)) this.validateFieldMatcher(fpath, matcher);
|
|
5948
|
+
}
|
|
5949
|
+
for (const key of exactKeys) checkKey(`${path}.exact.${key}`, key);
|
|
5950
|
+
const mustNot = this.stringList(own2(e, "must_not"), `${path}.must_not`);
|
|
5951
|
+
const mustNotContain = this.stringList(own2(e, "must_not_contain"), `${path}.must_not_contain`);
|
|
5952
|
+
const mustNotMsg = `must_not takes up to ${L.maxMustNot} statements of at most ${L.maxMustNotRunes} characters each, none empty`;
|
|
5953
|
+
if (mustNot.length > L.maxMustNot) {
|
|
5954
|
+
this.err("example_must_not_invalid", `${path}.must_not`, mustNotMsg);
|
|
5955
|
+
}
|
|
5956
|
+
mustNot.forEach((item, j) => {
|
|
5957
|
+
if (goTrimSpace(item) === "" || runeCount(item) > L.maxMustNotRunes) {
|
|
5958
|
+
this.err("example_must_not_invalid", `${path}.must_not[${j}]`, mustNotMsg);
|
|
5959
|
+
}
|
|
5960
|
+
});
|
|
5961
|
+
const mncMsg = `must_not_contain takes up to ${L.maxMustNotContain} literals of 1 to ${L.maxMustNotContainLength} characters each`;
|
|
5962
|
+
if (mustNotContain.length > L.maxMustNotContain) {
|
|
5963
|
+
this.err("example_must_not_contain_invalid", `${path}.must_not_contain`, mncMsg);
|
|
5964
|
+
}
|
|
5965
|
+
mustNotContain.forEach((item, j) => {
|
|
5966
|
+
const n = runeCount(item);
|
|
5967
|
+
if (n === 0 || n > L.maxMustNotContainLength) {
|
|
5968
|
+
this.err("example_must_not_contain_invalid", `${path}.must_not_contain[${j}]`, mncMsg);
|
|
5969
|
+
}
|
|
5970
|
+
});
|
|
5971
|
+
for (const key of fieldKeys) {
|
|
5972
|
+
const matcher = own2(fieldsRec, key);
|
|
5973
|
+
if (!isRecord(matcher)) continue;
|
|
5974
|
+
const eq = own2(matcher, "equals");
|
|
5975
|
+
if (typeof eq !== "string" || eq === "") continue;
|
|
5976
|
+
for (const banned of mustNotContain) {
|
|
5977
|
+
if (banned !== "" && equalFold(banned, eq)) {
|
|
5978
|
+
this.warn(
|
|
5979
|
+
"example_expectation_contradiction",
|
|
5980
|
+
`${path}.fields.${key}`,
|
|
5981
|
+
`${q(banned)} is required by ${q(key)} and forbidden by must_not_contain`
|
|
5982
|
+
);
|
|
5983
|
+
}
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5986
|
+
if (kind === "checkpoint" && status !== "") {
|
|
5987
|
+
this.err(
|
|
5988
|
+
"example_checkpoint_status",
|
|
5989
|
+
`${path}.status`,
|
|
5990
|
+
`example ${q(label)}: a checkpoint cannot set status; status describes how the whole run ends`
|
|
5991
|
+
);
|
|
5992
|
+
}
|
|
5993
|
+
if (rubric === "" && !has(e, "reference") && !hasFields && !hasExact && mustNot.length === 0 && mustNotContain.length === 0 && (status === "" || status === STATUS_COMPLETED)) {
|
|
5994
|
+
this.err(
|
|
5995
|
+
"example_expected_empty",
|
|
5996
|
+
path,
|
|
5997
|
+
"this expectation checks nothing; add a rubric, fields, exact, reference, must_not or must_not_contain",
|
|
5998
|
+
SUGGESTION_EXPECTED
|
|
5999
|
+
);
|
|
6000
|
+
}
|
|
6001
|
+
}
|
|
6002
|
+
/** A Go `[]string` read: scalars by their text, null as "", anything else dropped. */
|
|
6003
|
+
stringList(v, path) {
|
|
6004
|
+
if (!Array.isArray(v)) return [];
|
|
6005
|
+
const out = [];
|
|
6006
|
+
v.forEach((item, j) => {
|
|
6007
|
+
if (item === null) out.push("");
|
|
6008
|
+
else {
|
|
6009
|
+
const t = this.issues.stringAt(item, `${path}[${j}]`);
|
|
6010
|
+
if (t !== null) out.push(t);
|
|
6011
|
+
}
|
|
6012
|
+
});
|
|
6013
|
+
return out;
|
|
6014
|
+
}
|
|
6015
|
+
validateReference(path, r) {
|
|
6016
|
+
const text = this.s(r, "text", path);
|
|
6017
|
+
const hasText = text !== "";
|
|
6018
|
+
const hasRef = has(r, "ref");
|
|
6019
|
+
if (hasText === hasRef) {
|
|
6020
|
+
this.err("example_reference_invalid", path, "a reference needs exactly one of text or ref");
|
|
6021
|
+
return;
|
|
6022
|
+
}
|
|
6023
|
+
if (hasText) {
|
|
6024
|
+
const n = byteLen(text);
|
|
6025
|
+
if (n > EXAMPLES.limits.maxReferenceTextBytes) {
|
|
6026
|
+
this.err(
|
|
6027
|
+
"example_reference_invalid",
|
|
6028
|
+
path,
|
|
6029
|
+
`the reference text is ${n} bytes; the limit is ${EXAMPLES.limits.maxReferenceTextBytes}. Put it behind an https file reference.`
|
|
6030
|
+
);
|
|
6031
|
+
}
|
|
6032
|
+
return;
|
|
6033
|
+
}
|
|
6034
|
+
const refRec = own2(r, "ref");
|
|
6035
|
+
if (!isRecord(refRec)) return;
|
|
6036
|
+
const ref = this.fileRefOf(refRec, `${path}.ref`);
|
|
6037
|
+
this.validateFileRef(`${path}.ref`, ref);
|
|
6038
|
+
if (ref.mediaType !== "" && !isTextualMediaType(ref.mediaType)) {
|
|
6039
|
+
this.warn(
|
|
6040
|
+
"example_reference_binary",
|
|
6041
|
+
path,
|
|
6042
|
+
"this reference is not text, so it cannot be compared in this version; the example will be skipped, not failed."
|
|
6043
|
+
);
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
expectationIsBinaryReferenceOnly(e, path) {
|
|
6047
|
+
const reference = own2(e, "reference");
|
|
6048
|
+
const refRec = isRecord(reference) ? own2(reference, "ref") : void 0;
|
|
6049
|
+
if (!isRecord(refRec)) return false;
|
|
6050
|
+
const mediaType = this.s(refRec, "media_type", `${path}.reference.ref`);
|
|
6051
|
+
if (mediaType === "" || isTextualMediaType(mediaType)) return false;
|
|
6052
|
+
const status = this.s(e, "status", path);
|
|
6053
|
+
const fields = own2(e, "fields");
|
|
6054
|
+
const exact = own2(e, "exact");
|
|
6055
|
+
return this.s(e, "rubric", path) === "" && !(isRecord(fields) && Object.keys(fields).length > 0) && !(isRecord(exact) && Object.keys(exact).length > 0) && this.stringList(own2(e, "must_not"), `${path}.must_not`).length === 0 && this.stringList(own2(e, "must_not_contain"), `${path}.must_not_contain`).length === 0 && (status === "" || status === STATUS_COMPLETED);
|
|
6056
|
+
}
|
|
6057
|
+
validateFieldMatcher(path, m) {
|
|
6058
|
+
const L = EXAMPLES.limits;
|
|
6059
|
+
const matches = this.s(m, "matches", path);
|
|
6060
|
+
const oneOf = own2(m, "one_of");
|
|
6061
|
+
const approx = numberOf(own2(m, "approx"));
|
|
6062
|
+
const tolerance = numberOf(own2(m, "tolerance"));
|
|
6063
|
+
let operators = 0;
|
|
6064
|
+
if (has(m, "equals")) operators++;
|
|
6065
|
+
if (this.s(m, "contains", path) !== "") operators++;
|
|
6066
|
+
if (this.s(m, "not_contains", path) !== "") operators++;
|
|
6067
|
+
if (matches !== "") operators++;
|
|
6068
|
+
if (Array.isArray(oneOf) && oneOf.length > 0) operators++;
|
|
6069
|
+
if (approx !== void 0) operators++;
|
|
6070
|
+
if (typeof own2(m, "present") === "boolean") operators++;
|
|
6071
|
+
if (operators !== 1) {
|
|
6072
|
+
this.err(
|
|
6073
|
+
"example_field_matcher_invalid",
|
|
6074
|
+
path,
|
|
6075
|
+
"write exactly one of equals, contains, not_contains, matches, one_of, approx, present"
|
|
6076
|
+
);
|
|
6077
|
+
return;
|
|
6078
|
+
}
|
|
6079
|
+
if (matches !== "" && byteLen(matches) > L.maxPatternLength) {
|
|
6080
|
+
this.err(
|
|
6081
|
+
"example_field_matcher_invalid",
|
|
6082
|
+
path,
|
|
6083
|
+
`the pattern in matches must be a valid regular expression of at most ${L.maxPatternLength} characters`
|
|
6084
|
+
);
|
|
6085
|
+
}
|
|
6086
|
+
if (approx !== void 0 !== (tolerance !== void 0) || tolerance !== void 0 && (Number.isNaN(tolerance) || tolerance < 0)) {
|
|
6087
|
+
this.err(
|
|
6088
|
+
"example_field_matcher_invalid",
|
|
6089
|
+
path,
|
|
6090
|
+
"approx needs a tolerance (a number, zero or more) beside it, and tolerance is only for approx"
|
|
6091
|
+
);
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
// -- checkpoints ------------------------------------------------------
|
|
6095
|
+
validateCheckpoints(path, label, cps) {
|
|
6096
|
+
if (!isRecord(cps) || Object.keys(cps).length === 0) return;
|
|
6097
|
+
const stepsRaw = own2(this.flow, "steps");
|
|
6098
|
+
const steps = isRecord(stepsRaw) ? stepsRaw : {};
|
|
6099
|
+
const stepIds = sortedKeys(steps);
|
|
6100
|
+
for (const id of sortedKeys(cps)) {
|
|
6101
|
+
const cpath = `${path}.checkpoints.${id}`;
|
|
6102
|
+
const step = own2(steps, id);
|
|
6103
|
+
if (!isRecord(step)) {
|
|
6104
|
+
this.err(
|
|
6105
|
+
"example_checkpoint_step_unknown",
|
|
6106
|
+
cpath,
|
|
6107
|
+
`example ${q(label)}: checkpoint ${q(id)} is not a step of this flow (steps: ${stepIds.join(", ")})`,
|
|
6108
|
+
SUGGESTION_CHECKPOINT
|
|
6109
|
+
);
|
|
6110
|
+
continue;
|
|
6111
|
+
}
|
|
6112
|
+
const next = own2(step, "next");
|
|
6113
|
+
if (has(step, "for_each") || has(step, "loop") || isRecord(next) && has(next, "parallel")) {
|
|
6114
|
+
this.err(
|
|
6115
|
+
"example_checkpoint_step_composite",
|
|
6116
|
+
cpath,
|
|
6117
|
+
`example ${q(label)}: step ${q(id)} repeats or branches, so there is no single result to check; put the checkpoint on a plain step or check the final output`
|
|
6118
|
+
);
|
|
6119
|
+
continue;
|
|
6120
|
+
}
|
|
6121
|
+
const cp = own2(cps, id);
|
|
6122
|
+
if (cp === null || cp === void 0) {
|
|
6123
|
+
this.validateExpectation(cpath, label, {}, "checkpoint", id);
|
|
6124
|
+
} else if (isRecord(cp)) {
|
|
6125
|
+
this.validateExpectation(cpath, label, cp, "checkpoint", id);
|
|
6126
|
+
}
|
|
6127
|
+
}
|
|
6128
|
+
}
|
|
6129
|
+
// -- variants ---------------------------------------------------------
|
|
6130
|
+
validateVariants(i, path, label, ex, hasInput, baseInput) {
|
|
6131
|
+
const L = EXAMPLES.limits;
|
|
6132
|
+
const variants = own2(ex, "variants");
|
|
6133
|
+
if (!Array.isArray(variants) || variants.length === 0) return;
|
|
6134
|
+
if (variants.length > L.maxVariants) {
|
|
6135
|
+
this.err(
|
|
6136
|
+
"example_variants_too_many",
|
|
6137
|
+
`${path}.variants`,
|
|
6138
|
+
`example ${q(label)} has ${variants.length} variants; the limit is ${L.maxVariants}`
|
|
6139
|
+
);
|
|
6140
|
+
}
|
|
6141
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6142
|
+
variants.forEach((v, j) => {
|
|
6143
|
+
if (!isRecord(v)) return;
|
|
6144
|
+
const vpath = `examples[${i}].variants[${j}]`;
|
|
6145
|
+
const vid = this.s(v, "id", vpath);
|
|
6146
|
+
const vlabel = vid === "" ? `#${j + 1}` : vid;
|
|
6147
|
+
const both = `${label}/${vlabel}`;
|
|
6148
|
+
if (!EXAMPLES.idPattern.test(vid)) {
|
|
6149
|
+
this.err(
|
|
6150
|
+
"example_variant_id_invalid",
|
|
6151
|
+
`${vpath}.id`,
|
|
6152
|
+
`variant id ${q(vid)} of example ${q(label)} is not valid: use lower-case letters, digits and underscores, starting with a letter (2 to 48 characters)`,
|
|
6153
|
+
SUGGESTION_ID
|
|
6154
|
+
);
|
|
6155
|
+
} else if (seen.has(vid)) {
|
|
6156
|
+
this.err(
|
|
6157
|
+
"example_variant_id_duplicate",
|
|
6158
|
+
`${vpath}.id`,
|
|
6159
|
+
`variant id ${q(vid)} is used twice in example ${q(label)}`
|
|
6160
|
+
);
|
|
6161
|
+
}
|
|
6162
|
+
seen.add(vid);
|
|
6163
|
+
const origin = this.s(v, "origin", vpath);
|
|
6164
|
+
if (origin === ORIGIN_NONE || !EXAMPLES.origins.has(origin)) {
|
|
6165
|
+
this.err(
|
|
6166
|
+
"example_variant_origin_invalid",
|
|
6167
|
+
`${vpath}.origin`,
|
|
6168
|
+
`variant ${q(vlabel)} of example ${q(label)} has origin ${q(origin)}; use author (a person wrote or approved it) or synthetic (generated)`
|
|
6169
|
+
);
|
|
6170
|
+
}
|
|
6171
|
+
const vtitleN = runeCount(this.s(v, "title", vpath));
|
|
6172
|
+
if (vtitleN > L.titleMaxRunes) {
|
|
6173
|
+
this.err(
|
|
6174
|
+
"example_title_too_long",
|
|
6175
|
+
`${vpath}.title`,
|
|
6176
|
+
`example ${q(both)} title is ${vtitleN} characters; the limit is ${L.titleMaxRunes}`
|
|
6177
|
+
);
|
|
6178
|
+
}
|
|
6179
|
+
const vguidanceN = runeCount(this.s(v, "guidance", vpath));
|
|
6180
|
+
if (vguidanceN > L.maxGuidanceRunes) {
|
|
6181
|
+
this.err(
|
|
6182
|
+
"example_guidance_too_long",
|
|
6183
|
+
`${vpath}.guidance`,
|
|
6184
|
+
`example ${q(both)} guidance is ${vguidanceN} characters; the limit is ${L.maxGuidanceRunes}`
|
|
6185
|
+
);
|
|
6186
|
+
}
|
|
6187
|
+
const provN = runeCount(this.s(v, "provenance", vpath));
|
|
6188
|
+
if (provN > L.maxProvenanceRunes) {
|
|
6189
|
+
this.err(
|
|
6190
|
+
"example_notes_too_long",
|
|
6191
|
+
`${vpath}.provenance`,
|
|
6192
|
+
`example ${q(both)} notes are ${provN} characters; the limit is ${L.maxProvenanceRunes}`
|
|
6193
|
+
);
|
|
6194
|
+
}
|
|
6195
|
+
this.validateWeight(`${vpath}.weight`, both, numberOf(own2(v, "weight")));
|
|
6196
|
+
const patch = own2(v, "input_patch");
|
|
6197
|
+
const patchRec = isRecord(patch) ? patch : null;
|
|
6198
|
+
const hasPatch = patchRec !== null && Object.keys(patchRec).length > 0;
|
|
6199
|
+
const hasRef = has(v, "input_ref");
|
|
6200
|
+
if (hasPatch && hasRef) {
|
|
6201
|
+
this.err(
|
|
6202
|
+
"example_variant_input_conflict",
|
|
6203
|
+
vpath,
|
|
6204
|
+
`variant ${q(vlabel)} of example ${q(label)} sets both input_patch and input_ref; use one`
|
|
6205
|
+
);
|
|
6206
|
+
} else if (!hasPatch && !hasRef && !has(v, "expected")) {
|
|
6207
|
+
this.err(
|
|
6208
|
+
"example_variant_empty",
|
|
6209
|
+
vpath,
|
|
6210
|
+
`variant ${q(vlabel)} of example ${q(label)} changes neither the input nor the expectation`
|
|
6211
|
+
);
|
|
6212
|
+
}
|
|
6213
|
+
const refRec = own2(v, "input_ref");
|
|
6214
|
+
if (isRecord(refRec)) {
|
|
6215
|
+
this.validateFileRef(`${vpath}.input_ref`, this.fileRefOf(refRec, `${vpath}.input_ref`));
|
|
6216
|
+
}
|
|
6217
|
+
if (hasPatch && patchRec !== null) {
|
|
6218
|
+
if (!hasInput) {
|
|
6219
|
+
this.warn(
|
|
6220
|
+
"example_variant_unchecked",
|
|
6221
|
+
`${vpath}.input_patch`,
|
|
6222
|
+
`variant ${q(vlabel)} of example ${q(label)} cannot be checked: its parent takes its input from input_ref.`
|
|
6223
|
+
);
|
|
6224
|
+
} else if (baseInput !== null) {
|
|
6225
|
+
this.checkVariantPatch(vpath, label, vlabel, baseInput, patchRec);
|
|
6226
|
+
}
|
|
6227
|
+
}
|
|
6228
|
+
const expected = own2(v, "expected");
|
|
6229
|
+
if (isRecord(expected)) {
|
|
6230
|
+
this.validateExpectation(`${vpath}.expected`, both, expected, "final", "");
|
|
6231
|
+
}
|
|
6232
|
+
});
|
|
6233
|
+
}
|
|
6234
|
+
/**
|
|
6235
|
+
* Judge the PATCHED input like a live run, and report a secret the patch
|
|
6236
|
+
* itself supplies. A null patch value deleting a secret is fine.
|
|
6237
|
+
*/
|
|
6238
|
+
checkVariantPatch(vpath, label, vlabel, base, patch) {
|
|
6239
|
+
const schema = own2(this.flow, "input_schema");
|
|
6240
|
+
if (isRecord(schema)) {
|
|
6241
|
+
for (const f of this.schemaFields(schema)) {
|
|
6242
|
+
if (f.type !== TYPE_SECRET) continue;
|
|
6243
|
+
const val = own2(patch, f.name);
|
|
6244
|
+
if (val !== void 0 && val !== null) {
|
|
6245
|
+
this.err(
|
|
6246
|
+
"example_secret_value",
|
|
6247
|
+
`${vpath}.input_patch.${f.name}`,
|
|
6248
|
+
`example ${q(`${label}/${vlabel}`)} gives a value for ${q(f.name)}, which is a secret field. Examples are saved inside the flow and are never allowed to hold secrets; remove it. The person running the evaluation is asked for it at run time.`,
|
|
6249
|
+
SUGGESTION_SECRET_VALUE
|
|
6250
|
+
);
|
|
6251
|
+
}
|
|
6252
|
+
}
|
|
6253
|
+
}
|
|
6254
|
+
const patched = applyExamplePatch(base, patch);
|
|
6255
|
+
const scratch = new _Walker(this.flow, this.issues);
|
|
6256
|
+
scratch.checkInput(
|
|
6257
|
+
`${vpath}.input_patch`,
|
|
6258
|
+
`${label}/${vlabel}`,
|
|
6259
|
+
patched,
|
|
6260
|
+
"example_variant_input_invalid"
|
|
6261
|
+
);
|
|
6262
|
+
for (const f of scratch.findings) {
|
|
6263
|
+
if (f.code === "example_secret_value") continue;
|
|
6264
|
+
this.findings.push(f);
|
|
6265
|
+
}
|
|
6266
|
+
}
|
|
6267
|
+
// -- credential-shaped literals ----------------------------------------
|
|
6268
|
+
scanSecretLike(i, path, ex) {
|
|
6269
|
+
const emit = (field, s) => {
|
|
6270
|
+
const name = secretMatch(s);
|
|
6271
|
+
if (name !== "") {
|
|
6272
|
+
this.err(
|
|
6273
|
+
"example_secret_like_value",
|
|
6274
|
+
field,
|
|
6275
|
+
`${field} looks like a credential (${name}). Examples are saved in the flow definition and must never contain keys or tokens. Replace it with a made-up value.`,
|
|
6276
|
+
SUGGESTION_SECRET_VALUE
|
|
6277
|
+
);
|
|
6278
|
+
}
|
|
6279
|
+
};
|
|
6280
|
+
emit(`${path}.title`, this.s(ex, "title", path));
|
|
6281
|
+
emit(`${path}.guidance`, this.s(ex, "guidance", path));
|
|
6282
|
+
emit(`${path}.notes`, this.s(ex, "notes", path));
|
|
6283
|
+
const input = own2(ex, "input");
|
|
6284
|
+
if (isRecord(input)) scanLeaves(`${path}.input`, input, 0, emit);
|
|
6285
|
+
const expected = own2(ex, "expected");
|
|
6286
|
+
if (isRecord(expected)) this.scanExpectationLeaves(`${path}.expected`, expected, emit);
|
|
6287
|
+
const cps = own2(ex, "checkpoints");
|
|
6288
|
+
if (isRecord(cps)) {
|
|
6289
|
+
for (const id of sortedKeys(cps)) {
|
|
6290
|
+
const cp = own2(cps, id);
|
|
6291
|
+
if (isRecord(cp)) this.scanExpectationLeaves(`${path}.checkpoints.${id}`, cp, emit);
|
|
6292
|
+
}
|
|
6293
|
+
}
|
|
6294
|
+
const variants = own2(ex, "variants");
|
|
6295
|
+
if (Array.isArray(variants)) {
|
|
6296
|
+
variants.forEach((v, j) => {
|
|
6297
|
+
if (!isRecord(v)) return;
|
|
6298
|
+
const vpath = `examples[${i}].variants[${j}]`;
|
|
6299
|
+
emit(`${vpath}.title`, this.s(v, "title", vpath));
|
|
6300
|
+
emit(`${vpath}.guidance`, this.s(v, "guidance", vpath));
|
|
6301
|
+
emit(`${vpath}.provenance`, this.s(v, "provenance", vpath));
|
|
6302
|
+
scanLeaves(`${vpath}.input_patch`, own2(v, "input_patch"), 0, emit);
|
|
6303
|
+
const vexp = own2(v, "expected");
|
|
6304
|
+
if (isRecord(vexp)) this.scanExpectationLeaves(`${vpath}.expected`, vexp, emit);
|
|
6305
|
+
});
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
6308
|
+
scanExpectationLeaves(path, e, emit) {
|
|
6309
|
+
emit(`${path}.rubric`, this.s(e, "rubric", path));
|
|
6310
|
+
const reference = own2(e, "reference");
|
|
6311
|
+
if (isRecord(reference)) {
|
|
6312
|
+
emit(`${path}.reference.text`, this.s(reference, "text", `${path}.reference`));
|
|
6313
|
+
}
|
|
6314
|
+
this.stringList(own2(e, "must_not"), `${path}.must_not`).forEach(
|
|
6315
|
+
(s, j) => emit(`${path}.must_not[${j}]`, s)
|
|
6316
|
+
);
|
|
6317
|
+
this.stringList(own2(e, "must_not_contain"), `${path}.must_not_contain`).forEach(
|
|
6318
|
+
(s, j) => emit(`${path}.must_not_contain[${j}]`, s)
|
|
6319
|
+
);
|
|
6320
|
+
const fields = own2(e, "fields");
|
|
6321
|
+
if (isRecord(fields)) {
|
|
6322
|
+
for (const key of sortedKeys(fields)) {
|
|
6323
|
+
const m = own2(fields, key);
|
|
6324
|
+
if (!isRecord(m)) continue;
|
|
6325
|
+
const fpath = `${path}.fields.${key}`;
|
|
6326
|
+
scanLeaves(`${fpath}.equals`, own2(m, "equals"), 0, emit);
|
|
6327
|
+
emit(`${fpath}.contains`, this.s(m, "contains", fpath));
|
|
6328
|
+
emit(`${fpath}.not_contains`, this.s(m, "not_contains", fpath));
|
|
6329
|
+
const oneOf = own2(m, "one_of");
|
|
6330
|
+
if (Array.isArray(oneOf)) {
|
|
6331
|
+
oneOf.forEach(
|
|
6332
|
+
(one, j) => scanLeaves(`${fpath}.one_of[${j}]`, one, 0, emit)
|
|
6333
|
+
);
|
|
6334
|
+
}
|
|
6335
|
+
}
|
|
6336
|
+
}
|
|
6337
|
+
scanLeaves(`${path}.exact`, own2(e, "exact"), 0, emit);
|
|
6338
|
+
}
|
|
6339
|
+
};
|
|
6340
|
+
function scoreInRange(v) {
|
|
6341
|
+
return !Number.isNaN(v) && v >= EXAMPLES.limits.minScoreMin && v <= EXAMPLES.limits.minScoreMax;
|
|
6342
|
+
}
|
|
6343
|
+
function equalFold(a, b) {
|
|
6344
|
+
const ca = [...a];
|
|
6345
|
+
const cb = [...b];
|
|
6346
|
+
if (ca.length !== cb.length) return false;
|
|
6347
|
+
return ca.every((c, i) => {
|
|
6348
|
+
const d = cb[i];
|
|
6349
|
+
return c === d || c.toLowerCase() === d.toLowerCase() || c.toUpperCase() === d.toUpperCase();
|
|
6350
|
+
});
|
|
6351
|
+
}
|
|
6352
|
+
function secretMatch(s) {
|
|
6353
|
+
for (const p of EXAMPLES.secretPatterns) {
|
|
6354
|
+
if (p.re.test(s)) return p.name;
|
|
6355
|
+
}
|
|
6356
|
+
return "";
|
|
6357
|
+
}
|
|
6358
|
+
function scanLeaves(path, v, depth, emit) {
|
|
6359
|
+
if (depth > MAX_RECURSION_DEPTH) return;
|
|
6360
|
+
if (isRecord(v)) {
|
|
6361
|
+
for (const k of sortedKeys(v)) scanLeaves(`${path}.${k}`, v[k], depth + 1, emit);
|
|
6362
|
+
return;
|
|
6363
|
+
}
|
|
6364
|
+
if (typeof v === "string") emit(path, v);
|
|
6365
|
+
else if (Array.isArray(v)) {
|
|
6366
|
+
v.forEach((item, i) => scanLeaves(`${path}[${i}]`, item, depth + 1, emit));
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
function jsonBytes(v) {
|
|
6370
|
+
try {
|
|
6371
|
+
const text = JSON.stringify(v);
|
|
6372
|
+
return text === void 0 ? null : byteLen(text);
|
|
6373
|
+
} catch {
|
|
6374
|
+
return null;
|
|
6375
|
+
}
|
|
6376
|
+
}
|
|
6377
|
+
function blockBytes(examples) {
|
|
6378
|
+
try {
|
|
6379
|
+
const text = JSON.stringify(normalize(examples, 0), function(_k, v) {
|
|
6380
|
+
if (Array.isArray(this)) return v;
|
|
6381
|
+
if (v === null || v === "" || v === false) return void 0;
|
|
6382
|
+
if (Array.isArray(v) && v.length === 0) return void 0;
|
|
6383
|
+
return v;
|
|
6384
|
+
});
|
|
6385
|
+
return text === void 0 ? null : byteLen(text);
|
|
6386
|
+
} catch {
|
|
6387
|
+
return null;
|
|
6388
|
+
}
|
|
6389
|
+
}
|
|
6390
|
+
function isVisible(f, input) {
|
|
6391
|
+
const vw = f.visibleWhen;
|
|
6392
|
+
if (vw === null) return true;
|
|
6393
|
+
if (!Object.prototype.hasOwnProperty.call(input, vw.field)) return false;
|
|
6394
|
+
const dep = input[vw.field];
|
|
6395
|
+
if (vw.equals !== void 0 && vw.equals !== null) return valuesEqual(dep, vw.equals);
|
|
6396
|
+
return vw.in.some((candidate) => valuesEqual(dep, candidate));
|
|
6397
|
+
}
|
|
6398
|
+
function valuesEqual(a, b) {
|
|
6399
|
+
const aNil = a === null || a === void 0;
|
|
6400
|
+
const bNil = b === null || b === void 0;
|
|
6401
|
+
if (aNil || bNil) return aNil && bNil;
|
|
6402
|
+
if (typeof a === "number") return typeof b === "number" && a === b;
|
|
6403
|
+
if (typeof a === "boolean") return typeof b === "boolean" && a === b;
|
|
6404
|
+
if (typeof a === "string") return typeof b === "string" && a === b;
|
|
6405
|
+
return false;
|
|
6406
|
+
}
|
|
6407
|
+
function mismatch(f, expected) {
|
|
6408
|
+
return {
|
|
6409
|
+
field: f.name,
|
|
6410
|
+
message: `input field ${q(f.name)} is not a valid ${expected}`,
|
|
6411
|
+
required: false
|
|
6412
|
+
};
|
|
6413
|
+
}
|
|
6414
|
+
function inputValueFailures(f, raw) {
|
|
6415
|
+
switch (f.type) {
|
|
6416
|
+
case TYPE_STRING:
|
|
6417
|
+
case TYPE_MULTILINE:
|
|
6418
|
+
case TYPE_SECRET:
|
|
6419
|
+
return typeof raw === "string" ? [] : [mismatch(f, TYPE_STRING)];
|
|
6420
|
+
case TYPE_NUMBER2:
|
|
6421
|
+
return typeof raw === "number" ? [] : [mismatch(f, TYPE_NUMBER2)];
|
|
6422
|
+
case TYPE_BOOL:
|
|
6423
|
+
return typeof raw === "boolean" ? [] : [mismatch(f, TYPE_BOOL)];
|
|
6424
|
+
case TYPE_ENUM2:
|
|
6425
|
+
if (typeof raw !== "string") return [mismatch(f, TYPE_ENUM2)];
|
|
6426
|
+
if (f.enumValues.includes(raw)) return [];
|
|
6427
|
+
return [
|
|
6428
|
+
{
|
|
6429
|
+
field: f.name,
|
|
6430
|
+
message: `input field ${q(f.name)} value ${q(raw)} is not one of [${f.enumValues.join(",")}]`,
|
|
6431
|
+
required: false
|
|
6432
|
+
}
|
|
6433
|
+
];
|
|
6434
|
+
case TYPE_ARRAY_OF_STRINGS2: {
|
|
6435
|
+
if (!Array.isArray(raw)) return [mismatch(f, TYPE_ARRAY_OF_STRINGS2)];
|
|
6436
|
+
const out = [];
|
|
6437
|
+
raw.forEach((item, i) => {
|
|
6438
|
+
if (typeof item !== "string") {
|
|
6439
|
+
out.push({
|
|
6440
|
+
field: f.name,
|
|
6441
|
+
message: `input field ${q(f.name)} index ${i} is not a string`,
|
|
6442
|
+
required: false
|
|
6443
|
+
});
|
|
6444
|
+
}
|
|
6445
|
+
});
|
|
6446
|
+
return out;
|
|
6447
|
+
}
|
|
6448
|
+
case TYPE_DATE:
|
|
6449
|
+
return typeof raw === "string" ? [] : [mismatch(f, TYPE_DATE)];
|
|
6450
|
+
case TYPE_FILE2: {
|
|
6451
|
+
if (typeof raw === "string") return raw === "" ? [mismatch(f, TYPE_FILE2)] : [];
|
|
6452
|
+
if (isRecord(raw)) {
|
|
6453
|
+
const ref = own2(raw, FILE_REF_KEY);
|
|
6454
|
+
return typeof ref === "string" && ref !== "" ? [] : [mismatch(f, TYPE_FILE2)];
|
|
6455
|
+
}
|
|
6456
|
+
return [mismatch(f, TYPE_FILE2)];
|
|
6457
|
+
}
|
|
6458
|
+
default:
|
|
6459
|
+
return [];
|
|
6460
|
+
}
|
|
6461
|
+
}
|
|
6462
|
+
function validateExamples(flow, issues) {
|
|
6463
|
+
const examples = flow[KEY_EXAMPLES];
|
|
6464
|
+
if (!Array.isArray(examples) || examples.length === 0) return;
|
|
6465
|
+
const walker = new Walker(flow, issues);
|
|
6466
|
+
walker.run(examples);
|
|
6467
|
+
for (const f of walker.findings) {
|
|
6468
|
+
const issue = {
|
|
6469
|
+
field: f.field,
|
|
6470
|
+
message: f.message,
|
|
6471
|
+
code: f.code,
|
|
6472
|
+
...f.suggestion !== void 0 ? { suggestion: f.suggestion } : {}
|
|
6473
|
+
};
|
|
6474
|
+
if (f.severity === "error") issues.error(issue);
|
|
6475
|
+
else issues.warn(issue);
|
|
6476
|
+
}
|
|
6477
|
+
}
|
|
6478
|
+
|
|
5055
6479
|
// src/index.ts
|
|
5056
6480
|
function countStepsWithErrors(errors) {
|
|
5057
6481
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -5107,6 +6531,7 @@ function validateParsed(flow, opts, sources) {
|
|
|
5107
6531
|
validateExecutorConfigEnvScopes(f, issues);
|
|
5108
6532
|
validateServerOwnedQueryKeys(f, issues);
|
|
5109
6533
|
validateCredentialEndpointPairing(f, issues);
|
|
6534
|
+
validateExamples(f, issues);
|
|
5110
6535
|
validateOrchestratorExons(f, issues);
|
|
5111
6536
|
validateUnknownKeys(f, issues);
|
|
5112
6537
|
const templateStats = validateTemplates(f, issues, opts);
|