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