apps 0.0.1-beta.30 → 0.0.1-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-AE4FWJQU.js → chunk-3FJYVAE4.js} +7 -7
  3. package/js/{chunk-KQCMHI3K.js → chunk-4OKYLVU4.js} +3 -3
  4. package/js/{chunk-BRGF7VFN.js → chunk-5DLG2FVN.js} +2 -2
  5. package/js/{chunk-XBQTJP76.js → chunk-5JVNM3CQ.js} +2 -2
  6. package/js/{chunk-6VWYEQ4X.js → chunk-5XJR4XGW.js} +3 -3
  7. package/js/{chunk-BTJMXW4I.js → chunk-6KG4DZD7.js} +1 -1
  8. package/js/{chunk-65SZ23BK.js → chunk-6ZJ2H6P4.js} +2 -2
  9. package/js/{chunk-P46HIAX6.js → chunk-AUFVX4KM.js} +2 -2
  10. package/js/{chunk-VUVBMNKC.js → chunk-AYM2FUI5.js} +2 -2
  11. package/js/{chunk-ZZOCEUTB.js → chunk-BGALSHLT.js} +4 -4
  12. package/js/{chunk-XGN5IFOZ.js → chunk-CJY5X26R.js} +1 -1
  13. package/js/{chunk-6JBTHTI5.js → chunk-DASNNAP4.js} +1 -1
  14. package/js/{chunk-WGBI5MVX.js → chunk-ETLILMHY.js} +3 -3
  15. package/js/{chunk-NXTXZ635.js → chunk-EXGKN554.js} +166 -11
  16. package/js/{chunk-PWF2DRJ3.js → chunk-FBBXFFFJ.js} +1 -1
  17. package/js/{chunk-OI5CKSBU.js → chunk-FULRJSWU.js} +8 -8
  18. package/js/{chunk-IMCEF6KE.js → chunk-GG566OOE.js} +9 -9
  19. package/js/{chunk-5ZHHO4OM.js → chunk-GZ4UHXRT.js} +3 -3
  20. package/js/{chunk-MYCVMDWI.js → chunk-HW3DPBZR.js} +1 -1
  21. package/js/{chunk-BBTELEAN.js → chunk-MFHUR5SB.js} +2 -2
  22. package/js/{chunk-BSRU52RU.js → chunk-N72RKJ5E.js} +5 -5
  23. package/js/{chunk-YML53Z7H.js → chunk-NPGRURDG.js} +350 -15
  24. package/js/{chunk-4N26L465.js → chunk-OX233L7N.js} +2 -2
  25. package/js/{chunk-2D2PKLGQ.js → chunk-QYM4STZW.js} +2 -2
  26. package/js/{chunk-PUC24GZP.js → chunk-RULZPNGP.js} +12 -12
  27. package/js/{chunk-M2KEEOIQ.js → chunk-UMCMZFXW.js} +1 -1
  28. package/js/{chunk-6NK26ONC.js → chunk-W7F23NQ2.js} +102 -19
  29. package/js/{chunk-3SPRHIEE.js → chunk-WG5DFZFT.js} +2 -2
  30. package/js/{chunk-WQ5MVBTP.js → chunk-ZOY7PDMI.js} +1 -1
  31. package/js/client.js +11 -11
  32. package/js/contracts.js +9 -9
  33. package/js/effect.js +20 -20
  34. package/js/graphql.js +22 -22
  35. package/js/host.js +20 -20
  36. package/js/index.js +14 -14
  37. package/js/mcp/effect.js +22 -22
  38. package/js/mcp/stdio.js +22 -22
  39. package/js/mcp.js +24 -24
  40. package/js/openapi.js +17 -17
  41. package/js/react.js +3 -3
  42. package/js/skills/effect.js +5 -5
  43. package/js/skills.js +12 -12
  44. package/js/storage/facet.js +4 -4
  45. package/js/ui/auth/contracts.js +2 -2
  46. package/js/ui/auth.js +5 -5
  47. package/js/ui/contracts.js +5 -5
  48. package/js/ui/serving.js +9 -9
  49. package/package.json +1 -1
  50. package/runtime.json +1 -1
  51. package/types/apps/src/contracts/openapi-compile.d.ts +1 -0
  52. package/types/apps/src/implementation/input-problems.d.ts +4 -1
  53. package/types/apps/src/implementation/openapi-document.d.ts +11 -11
  54. package/types/apps/src/implementation/schema.d.ts +28 -0
@@ -2,7 +2,7 @@ import {
2
2
  DatabaseFieldReserved,
3
3
  DatabaseLimitExceeded,
4
4
  DatabaseSchema
5
- } from "./chunk-M2KEEOIQ.js";
5
+ } from "./chunk-UMCMZFXW.js";
6
6
  import {
7
7
  CacheCommand,
8
8
  CacheReply,
@@ -13,18 +13,18 @@ import {
13
13
  FailureSource,
14
14
  ProviderError,
15
15
  UpstreamError
16
- } from "./chunk-BRGF7VFN.js";
16
+ } from "./chunk-5DLG2FVN.js";
17
17
  import {
18
18
  AppSkillName,
19
19
  AppSkills,
20
20
  SkillLoadFailed
21
- } from "./chunk-MYCVMDWI.js";
21
+ } from "./chunk-HW3DPBZR.js";
22
22
  import {
23
23
  AccountId,
24
24
  HttpUrl,
25
25
  JsonObject as JsonObject2,
26
26
  JsonValue
27
- } from "./chunk-PWF2DRJ3.js";
27
+ } from "./chunk-FBBXFFFJ.js";
28
28
  import {
29
29
  Any,
30
30
  ArraySchema,
@@ -78,7 +78,7 @@ import {
78
78
  transformOptional,
79
79
  withConstructorDefault,
80
80
  withDefault
81
- } from "./chunk-NXTXZ635.js";
81
+ } from "./chunk-EXGKN554.js";
82
82
 
83
83
  // src/contracts/router.ts
84
84
  var reservedRouterKeys = /* @__PURE__ */ new Set([
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  JsonObject,
3
3
  ValidationError
4
- } from "./chunk-PWF2DRJ3.js";
4
+ } from "./chunk-FBBXFFFJ.js";
5
5
  import {
6
6
  Cause_exports,
7
7
  Effect_exports,
@@ -10,7 +10,7 @@ import {
10
10
  SchemaIssue_exports,
11
11
  SchemaParser_exports,
12
12
  Schema_exports
13
- } from "./chunk-NXTXZ635.js";
13
+ } from "./chunk-EXGKN554.js";
14
14
 
15
15
  // ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
16
16
  function deepCompareStrict(a, b) {
@@ -345,7 +345,7 @@ function validate(instance, schema, draft = "2019-09", lookup = dereference(sche
345
345
  if ($recursiveAnchor === true && recursiveAnchor === null) {
346
346
  recursiveAnchor = schema;
347
347
  }
348
- if ($recursiveRef === "#") {
348
+ if ($recursiveRef !== void 0) {
349
349
  const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
350
350
  const keywordLocation = `${schemaLocation}/$recursiveRef`;
351
351
  const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
@@ -1293,18 +1293,334 @@ var containerKeywords = /* @__PURE__ */ new Set([
1293
1293
  "else",
1294
1294
  "dependentSchemas"
1295
1295
  ]);
1296
- var jsonSchemaProblems = (errors) => {
1297
- const problems = errors.flatMap(({ keyword, instanceLocation, error }) => {
1298
- if (containerKeywords.has(keyword)) return [];
1299
- const path = instanceLocation.replace(/^#\/?/, "").split("/").filter((segment) => segment !== "").map((segment) => decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~")).map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
1300
- const required = keyword === "required" ? /required property "([^"]*)"/.exec(error) : null;
1301
- const expected = keyword === "type" ? /Expected "([^.]*)"\.?$/.exec(error) : null;
1302
- const issue = required !== null ? { path: [...path, required[1] ?? ""], issue: "Missing key" } : {
1303
- path,
1304
- issue: expected !== null ? `Expected ${(expected[1] ?? "").replace(/"/g, "")}` : keyword === "const" || keyword === "enum" ? "Expected one of the allowed values" : `Failed the "${keyword}" constraint`
1296
+ var echoableKey = (key) => /^[A-Za-z_$][\w$-]{0,63}$/.test(key);
1297
+ var schemaKey = (name) => echoableKey(name) ? name : JSON.stringify(name.slice(0, 64));
1298
+ var maxShapeKeys = 24;
1299
+ var objectShape = (keys, open, limit = maxShapeKeys) => {
1300
+ const listed = keys.slice(0, limit).map(({ name, optional }) => `${schemaKey(name)}${optional ? "?" : ""}`);
1301
+ const parts = [
1302
+ ...listed,
1303
+ ...keys.length > limit ? [`${keys.length - limit} more`] : [],
1304
+ ...open ? ["..."] : []
1305
+ ];
1306
+ return parts.length === 0 ? "object {} with no keys" : `object {${parts.join(", ")}}`;
1307
+ };
1308
+ var maxListedValues = 10;
1309
+ var maxValuesText = 200;
1310
+ var valueText = (value) => typeof value === "bigint" ? `${value}n` : JSON.stringify(value);
1311
+ var allowedValues = (values) => {
1312
+ const texts = [...new Set(values.map(valueText))];
1313
+ const listed = [];
1314
+ for (const text of texts) {
1315
+ if (listed.length === maxListedValues || [...listed, text].join(", ").length > maxValuesText)
1316
+ break;
1317
+ listed.push(text);
1318
+ }
1319
+ const [only] = listed;
1320
+ if (texts.length === 0) return "no value, since the schema allows none";
1321
+ if (only === void 0)
1322
+ return texts.length === 1 ? "a fixed value too long to list" : `one of ${texts.length} values too long to list`;
1323
+ if (texts.length === 1) return only;
1324
+ const rest = texts.length - listed.length;
1325
+ return `one of ${listed.join(", ")}${rest > 0 ? ` and ${rest} more` : ""}`;
1326
+ };
1327
+ var maxAlternativeKeys = 8;
1328
+ var maxAlternativesText = 360;
1329
+ var unionShape = (alternatives, selector) => {
1330
+ const listed = [];
1331
+ for (const alternative of alternatives) {
1332
+ if (listed.length > 0 && [...listed, alternative].join(" or ").length > maxAlternativesText)
1333
+ break;
1334
+ listed.push(alternative);
1335
+ }
1336
+ const rest = alternatives.length - listed.length;
1337
+ return `${[...listed, ...rest > 0 ? [`${rest} more`] : []].join(" or ")}${selector === void 0 ? "" : `, told apart by ${schemaKey(selector)}`}`;
1338
+ };
1339
+ var isJsonRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1340
+ var pointerSegments = (pointer) => pointer === "#" || pointer === "" ? [] : pointer.replace(/^#?\//, "").split("/").map((segment) => decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~"));
1341
+ var resolved = (lookup, uri2) => typeof uri2 === "string" && Object.hasOwn(lookup, uri2) ? lookup[uri2] : void 0;
1342
+ var referenced = (lookup, node) => isJsonRecord(node) ? resolved(lookup, Reflect.get(node, "__absolute_ref__") ?? node.$ref) : void 0;
1343
+ var memberKeywords = /* @__PURE__ */ new Set([...schemaMaps, ...schemaArrays, "dependencies"]);
1344
+ var combinators = /* @__PURE__ */ new Set(["allOf", "anyOf", "oneOf"]);
1345
+ var schemaAt = (document, lookup, segments) => {
1346
+ const anchoredAt = (node2, anchor2) => anchor2 === null && isJsonRecord(node2) && node2.$recursiveAnchor === true ? node2 : anchor2;
1347
+ const pending = [...segments];
1348
+ let node = document;
1349
+ let anchor = anchoredAt(document, null);
1350
+ for (let keyword = pending.shift(); keyword !== void 0; keyword = pending.shift()) {
1351
+ if (!isJsonRecord(node)) return void 0;
1352
+ if (keyword === "$recursiveRef") {
1353
+ const target = anchor === null ? resolved(lookup, Reflect.get(node, "__absolute_recursive_ref__")) : anchor;
1354
+ if (anchor !== null) node = anchor;
1355
+ anchor = target;
1356
+ continue;
1357
+ }
1358
+ if (keyword === "$ref") node = referenced(lookup, node);
1359
+ else {
1360
+ const value = Object.hasOwn(node, keyword) ? node[keyword] : void 0;
1361
+ if (memberKeywords.has(keyword) || keyword === "items" && Array.isArray(value)) {
1362
+ const member = pending.shift();
1363
+ if (member === void 0) return value;
1364
+ if (combinators.has(keyword) && node.$recursiveAnchor !== true) anchor = null;
1365
+ node = Array.isArray(value) ? /^\d+$/.test(member) ? value[Number(member)] : void 0 : isJsonRecord(value) && Object.hasOwn(value, member) ? value[member] : void 0;
1366
+ } else node = value;
1367
+ }
1368
+ anchor = anchoredAt(node, anchor);
1369
+ }
1370
+ return node;
1371
+ };
1372
+ var jsonObjectShape = (node) => {
1373
+ if (!isJsonRecord(node)) return "object";
1374
+ const properties = isJsonRecord(node.properties) ? Object.keys(node.properties) : [];
1375
+ const required = new Set(Array.isArray(node.required) ? node.required : []);
1376
+ const open = node.additionalProperties !== false || isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0;
1377
+ return properties.length === 0 && open ? "object" : objectShape(
1378
+ properties.map((name) => ({ name, optional: !required.has(name) })),
1379
+ open
1380
+ );
1381
+ };
1382
+ var locationKey = (segments) => JSON.stringify(segments);
1383
+ var emptyOutline = {
1384
+ types: void 0,
1385
+ properties: /* @__PURE__ */ new Map(),
1386
+ required: /* @__PURE__ */ new Set(),
1387
+ closed: false,
1388
+ values: void 0
1389
+ };
1390
+ var commonValues = (a, b) => a === void 0 ? b : b === void 0 ? a : a.filter((value) => b.some((other) => deepCompareStrict(value, other)));
1391
+ var strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
1392
+ var commonTypes = (a, b) => new Set(
1393
+ [...a].flatMap(
1394
+ (type) => b.has(type) ? [type] : type === "number" && b.has("integer") || type === "integer" && b.has("number") ? ["integer"] : []
1395
+ )
1396
+ );
1397
+ var mergeOutlines = (a, b) => ({
1398
+ types: a.types === void 0 ? b.types : b.types === void 0 ? a.types : commonTypes(a.types, b.types),
1399
+ properties: new Map([...a.properties, ...b.properties]),
1400
+ required: /* @__PURE__ */ new Set([...a.required, ...b.required]),
1401
+ closed: a.closed || b.closed,
1402
+ values: commonValues(a.values, b.values)
1403
+ });
1404
+ var outlineOf = (node, inspection, seen = /* @__PURE__ */ new Set()) => {
1405
+ if (!isJsonRecord(node) || seen.has(node)) return emptyOutline;
1406
+ const within = /* @__PURE__ */ new Set([...seen, node]);
1407
+ const own = {
1408
+ types: typeof node.type === "string" ? /* @__PURE__ */ new Set([node.type]) : Array.isArray(node.type) ? new Set(strings(node.type)) : void 0,
1409
+ properties: new Map(isJsonRecord(node.properties) ? Object.entries(node.properties) : []),
1410
+ required: new Set(strings(node.required)),
1411
+ closed: (node.additionalProperties === false || node.unevaluatedProperties === false) && !(isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0),
1412
+ values: commonValues(
1413
+ Object.hasOwn(node, "const") ? [node.const] : void 0,
1414
+ Array.isArray(node.enum) ? node.enum : void 0
1415
+ )
1416
+ };
1417
+ return [inspection.referenced(node), ...Array.isArray(node.allOf) ? node.allOf : []].reduce(
1418
+ (outline, member) => mergeOutlines(outline, outlineOf(member, inspection, within)),
1419
+ own
1420
+ );
1421
+ };
1422
+ var describeOutline = (outline) => {
1423
+ if (outline.values !== void 0) return allowedValues(outline.values);
1424
+ const names = [
1425
+ ...outline.properties.keys(),
1426
+ ...[...outline.required].filter((name) => !outline.properties.has(name))
1427
+ ];
1428
+ const shape = names.length === 0 && !outline.closed ? "object" : objectShape(
1429
+ names.map((name) => ({ name, optional: !outline.required.has(name) })),
1430
+ !outline.closed,
1431
+ maxAlternativeKeys
1432
+ );
1433
+ if (outline.types === void 0)
1434
+ return names.length > 0 || outline.closed ? shape : "a value with other constraints";
1435
+ return [...outline.types].map((type) => type === "object" ? shape : type).join(" or ");
1436
+ };
1437
+ var overlap = (outline, value, inspection, depth = 0) => !isJsonRecord(value) || depth > 16 ? 0 : Object.entries(value).reduce((total, [key, item]) => {
1438
+ const property = outline.properties.get(key);
1439
+ return property === void 0 ? total : total + 1 + overlap(outlineOf(property, inspection), item, inspection, depth + 1);
1440
+ }, 0);
1441
+ var jsonType = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value === "object" ? "object" : typeof value;
1442
+ var accepted = (outline, value) => {
1443
+ const type = jsonType(value);
1444
+ if (outline.values !== void 0)
1445
+ return outline.values.some((allowed) => jsonType(allowed) === type);
1446
+ if (outline.types === void 0) return true;
1447
+ return outline.types.has(type) || type === "number" && outline.types.has("integer") && Number.isInteger(value);
1448
+ };
1449
+ var valueAt = (input, location2) => location2.reduce(
1450
+ (value, segment) => Array.isArray(value) ? value[Number(segment)] : isJsonRecord(value) && Object.hasOwn(value, segment) ? value[segment] : void 0,
1451
+ input
1452
+ );
1453
+ var discriminatorOf = (holder) => isJsonRecord(holder) && isJsonRecord(holder.discriminator) ? holder.discriminator : void 0;
1454
+ var definitionName = (reference) => {
1455
+ if (typeof reference !== "string" || !reference.startsWith("#/")) return void 0;
1456
+ const segments = pointerSegments(reference);
1457
+ const container = segments.at(-2);
1458
+ return container === "$defs" || container === "definitions" || container === "schemas" && segments.at(-3) === "components" ? segments.at(-1) : void 0;
1459
+ };
1460
+ var discriminatedName = (holder, value) => {
1461
+ const discriminator = discriminatorOf(holder);
1462
+ if (discriminator === void 0 || typeof value !== "string") return void 0;
1463
+ const { mapping } = discriminator;
1464
+ const target = isJsonRecord(mapping) && Object.hasOwn(mapping, value) ? mapping[value] : value;
1465
+ if (typeof target !== "string") return void 0;
1466
+ return /^[\w.-]+$/.test(target) ? target : definitionName(target);
1467
+ };
1468
+ var selectorOf = (holder, alternatives, inspection) => {
1469
+ const declared = discriminatorOf(holder)?.propertyName;
1470
+ if (typeof declared === "string") return declared;
1471
+ const [first] = alternatives;
1472
+ if (first === void 0 || alternatives.length < 2) return void 0;
1473
+ return [...first.properties.keys()].find(
1474
+ (key) => alternatives.every(
1475
+ (alternative) => alternative.properties.has(key) && outlineOf(alternative.properties.get(key), inspection).values !== void 0
1476
+ )
1477
+ );
1478
+ };
1479
+ var alternativeErrors = (errors, head, schemas) => {
1480
+ const prefix = `${errors[head]?.keywordLocation}/`;
1481
+ const alternatives = /* @__PURE__ */ new Map();
1482
+ const settle = (current2, next) => {
1483
+ const collected = alternatives.get(current2);
1484
+ const rejected = Array.isArray(schemas) ? schemas.slice(current2 + 1, next).filter((schema) => schema === false).length : 0;
1485
+ if (collected !== void 0) collected.splice(collected.length - rejected, rejected);
1486
+ };
1487
+ let index = head + 1;
1488
+ let current = -1;
1489
+ for (; index < errors.length; index++) {
1490
+ const error = errors[index];
1491
+ if (error === void 0) break;
1492
+ if (error.keywordLocation.startsWith(prefix)) {
1493
+ const alternative = Number(error.keywordLocation.slice(prefix.length).split("/")[0]);
1494
+ if (alternative !== current) settle(current, alternative);
1495
+ current = alternative;
1496
+ } else if (error.keyword !== "false") break;
1497
+ if (current >= 0) alternatives.set(current, [...alternatives.get(current) ?? [], error]);
1498
+ }
1499
+ settle(current, Array.isArray(schemas) ? schemas.length : current);
1500
+ return { alternatives, end: index };
1501
+ };
1502
+ var pathOf = (location2) => location2.map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
1503
+ var unionProblems = (union, schemas, errorsByAlternative, inspection) => {
1504
+ const location2 = pointerSegments(union.instanceLocation);
1505
+ const path = pathOf(location2);
1506
+ if (!Array.isArray(schemas))
1507
+ return [
1508
+ { path, issue: `Failed the "${union.keyword}" constraint` },
1509
+ ...[...errorsByAlternative.values()].flatMap((errors) => problemsOf(errors, inspection))
1510
+ ];
1511
+ const alternatives = schemas.flatMap(
1512
+ (schema, index) => schema === false ? [] : [
1513
+ {
1514
+ schema,
1515
+ matched: !errorsByAlternative.has(index),
1516
+ problems: () => problemsOf(errorsByAlternative.get(index) ?? [], inspection)
1517
+ }
1518
+ ]
1519
+ );
1520
+ const [only] = alternatives;
1521
+ if (only === void 0) return [{ path, issue: "No value is allowed here" }];
1522
+ if (alternatives.length === 1) return only.problems();
1523
+ const holder = inspection.schemaAt(pointerSegments(union.keywordLocation).slice(0, -1));
1524
+ const shared = outlineOf(holder, inspection);
1525
+ const own = alternatives.map(({ schema }) => outlineOf(schema, inspection));
1526
+ const outlines = own.map((outline) => mergeOutlines(shared, outline));
1527
+ const fixed = outlines.flatMap(({ values }) => values === void 0 ? [] : [values]);
1528
+ if (fixed.length === outlines.length)
1529
+ return [{ path, issue: `Expected ${allowedValues(fixed.flat())}` }];
1530
+ const selector = selectorOf(holder, own, inspection);
1531
+ const expected = `Expected ${unionShape(outlines.map(describeOutline), selector)}`;
1532
+ const matched = alternatives.filter((alternative) => alternative.matched).length;
1533
+ if (union.keyword === "oneOf" && matched > 1)
1534
+ return [{ path, issue: `${expected}. Exactly one may match, but ${matched} do` }];
1535
+ const value = valueAt(inspection.input, location2);
1536
+ const selectorValue = selector !== void 0 && isJsonRecord(value) && Object.hasOwn(value, selector) ? { value: value[selector] } : void 0;
1537
+ const named = discriminatedName(holder, selectorValue?.value);
1538
+ const ranked = alternatives.map(({ schema, problems }, index) => {
1539
+ const outline = outlines[index] ?? emptyOutline;
1540
+ const property = own[index]?.properties.get(selector ?? "");
1541
+ return {
1542
+ index,
1543
+ problems: problems(),
1544
+ selected: selectorValue !== void 0 && (named !== void 0 && isJsonRecord(schema) && definitionName(schema.$ref) === named || property !== void 0 && outlineOf(property, inspection).values !== void 0 && inspection.accepts(property, selectorValue.value)),
1545
+ typed: accepted(outline, value),
1546
+ overlap: overlap(outline, value, inspection)
1305
1547
  };
1306
- return [issue];
1307
1548
  });
1549
+ const closest = ranked.reduce(
1550
+ (best, candidate) => ([
1551
+ Number(candidate.selected) - Number(best.selected),
1552
+ Number(candidate.typed) - Number(best.typed),
1553
+ candidate.overlap - best.overlap,
1554
+ best.problems.length - candidate.problems.length
1555
+ ].find((difference) => difference !== 0) ?? 0) > 0 ? candidate : best
1556
+ );
1557
+ return closest.selected || closest.typed ? [
1558
+ {
1559
+ path,
1560
+ issue: `${expected}. Closest is alternative ${closest.index + 1}, whose problems follow`
1561
+ },
1562
+ ...closest.problems
1563
+ ] : [{ path, issue: expected }];
1564
+ };
1565
+ var problemsOf = (errors, inspection) => {
1566
+ const closed = /* @__PURE__ */ new Map();
1567
+ const problems = [];
1568
+ for (let index = 0; index < errors.length; index++) {
1569
+ const error = errors[index];
1570
+ if (error === void 0) break;
1571
+ const { keyword, instanceLocation, keywordLocation } = error;
1572
+ if (keyword === "anyOf" || keyword === "oneOf") {
1573
+ const schemas = inspection.schemaAt(pointerSegments(keywordLocation));
1574
+ const { alternatives, end } = alternativeErrors(errors, index, schemas);
1575
+ problems.push(...unionProblems(error, schemas, alternatives, inspection));
1576
+ index = end - 1;
1577
+ continue;
1578
+ }
1579
+ const location2 = pointerSegments(instanceLocation);
1580
+ const path = pathOf(location2);
1581
+ const problem = (issue, at = path) => problems.push({ path: at, issue });
1582
+ const node = () => inspection.schemaAt(pointerSegments(keywordLocation).slice(0, -1));
1583
+ if (keyword === "additionalProperties" || keyword === "unevaluatedProperties") {
1584
+ closed.set(locationKey(location2), node());
1585
+ continue;
1586
+ }
1587
+ if (containerKeywords.has(keyword)) continue;
1588
+ if (keyword === "false") {
1589
+ const key = location2.at(-1);
1590
+ const parent = locationKey(location2.slice(0, -1));
1591
+ if (key === void 0 || !closed.has(parent)) problem("No value is allowed here");
1592
+ else
1593
+ problem(
1594
+ `Unexpected key${echoableKey(key) ? ` "${key}"` : ""}. Expected ${jsonObjectShape(closed.get(parent))}`,
1595
+ path.slice(0, -1)
1596
+ );
1597
+ continue;
1598
+ }
1599
+ const required = keyword === "required" ? /required property "([^"]*)"/.exec(error.error) : null;
1600
+ if (required !== null) {
1601
+ problem("Missing key", [...path, required[1] ?? ""]);
1602
+ continue;
1603
+ }
1604
+ const expected = keyword === "type" ? /Expected "([^.]*)"\.?$/.exec(error.error) : null;
1605
+ if (expected !== null) {
1606
+ const types = (expected[1] ?? "").split('", "').map((type) => type === "object" ? jsonObjectShape(node()) : type);
1607
+ problem(`Expected ${types.join(" or ")}`);
1608
+ continue;
1609
+ }
1610
+ if (keyword === "const" || keyword === "enum") {
1611
+ const schema = node();
1612
+ const values = !isJsonRecord(schema) ? void 0 : keyword === "const" ? Object.hasOwn(schema, "const") ? [schema.const] : void 0 : Array.isArray(schema.enum) ? schema.enum : void 0;
1613
+ problem(
1614
+ values === void 0 ? "Expected one of the allowed values" : `Expected ${allowedValues(values)}`
1615
+ );
1616
+ continue;
1617
+ }
1618
+ problem(`Failed the "${keyword}" constraint`);
1619
+ }
1620
+ return problems;
1621
+ };
1622
+ var jsonSchemaProblems = (errors, inspection) => {
1623
+ const problems = problemsOf(errors, inspection);
1308
1624
  return problems.length === 0 ? false : problems;
1309
1625
  };
1310
1626
  var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
@@ -1331,8 +1647,22 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
1331
1647
  throw new ValidationError();
1332
1648
  }
1333
1649
  }
1650
+ const inspection = (input) => ({
1651
+ schemaAt: (segments) => schemaAt(normalized, lookup, segments),
1652
+ referenced: (node) => referenced(lookup, node),
1653
+ accepts: (node, value) => {
1654
+ if (typeof node !== "boolean" && !isJsonRecord(node)) return false;
1655
+ try {
1656
+ return validate(value, node, draft, lookup).valid;
1657
+ } catch {
1658
+ return false;
1659
+ }
1660
+ },
1661
+ input
1662
+ });
1334
1663
  return {
1335
- validate: (input) => validate(input, normalized, draft, lookup)
1664
+ validate: (input) => validate(input, normalized, draft, lookup),
1665
+ inspection
1336
1666
  };
1337
1667
  },
1338
1668
  catch: () => new ValidationError()
@@ -1342,7 +1672,7 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
1342
1672
  (value) => {
1343
1673
  try {
1344
1674
  const result = validator.validate(value);
1345
- return result.valid || jsonSchemaProblems(result.errors);
1675
+ return result.valid || jsonSchemaProblems(result.errors, validator.inspection(value));
1346
1676
  } catch {
1347
1677
  return false;
1348
1678
  }
@@ -1440,6 +1770,11 @@ export {
1440
1770
  once,
1441
1771
  withLazyJsonSchemaDocument,
1442
1772
  nestJsonSchema,
1773
+ echoableKey,
1774
+ objectShape,
1775
+ allowedValues,
1776
+ maxAlternativeKeys,
1777
+ unionShape,
1443
1778
  compileJsonSchemaDecoder,
1444
1779
  lazyJsonSchemaDecoder,
1445
1780
  preparedJsonSchemaDecoder,
@@ -5,11 +5,11 @@ import {
5
5
  SkillDefinitionInvalid,
6
6
  SkillFile,
7
7
  SkillFilePath
8
- } from "./chunk-MYCVMDWI.js";
8
+ } from "./chunk-HW3DPBZR.js";
9
9
  import {
10
10
  Effect_exports,
11
11
  Schema_exports
12
- } from "./chunk-NXTXZ635.js";
12
+ } from "./chunk-EXGKN554.js";
13
13
 
14
14
  // src/implementation/skill-files.ts
15
15
  var skillFromFiles = (input, source = {}) => Effect_exports.gen(function* () {
@@ -19,7 +19,7 @@ import {
19
19
  text,
20
20
  uint8Array,
21
21
  urlParams
22
- } from "./chunk-XGN5IFOZ.js";
22
+ } from "./chunk-CJY5X26R.js";
23
23
  import {
24
24
  Cause,
25
25
  Defect,
@@ -114,7 +114,7 @@ import {
114
114
  transformEffect,
115
115
  transformPull,
116
116
  void_2 as void_
117
- } from "./chunk-NXTXZ635.js";
117
+ } from "./chunk-EXGKN554.js";
118
118
  import {
119
119
  __export
120
120
  } from "./chunk-CZ7CSFO4.js";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  skillFromFiles
3
- } from "./chunk-4N26L465.js";
3
+ } from "./chunk-OX233L7N.js";
4
4
  import {
5
5
  joinPath,
6
6
  mergeMeta
7
- } from "./chunk-6VWYEQ4X.js";
7
+ } from "./chunk-5XJR4XGW.js";
8
8
  import {
9
9
  isShortenedUpstream,
10
10
  parseProviderError,
11
11
  providerError
12
- } from "./chunk-KQCMHI3K.js";
12
+ } from "./chunk-4OKYLVU4.js";
13
13
  import {
14
14
  ApiErrorResponse,
15
15
  FetchOptionUnsupported,
@@ -26,10 +26,10 @@ import {
26
26
  networkRefusalHeader,
27
27
  networkRefusalStatus,
28
28
  supportedFetchOptions
29
- } from "./chunk-BSRU52RU.js";
29
+ } from "./chunk-N72RKJ5E.js";
30
30
  import {
31
31
  AppDatabaseError
32
- } from "./chunk-M2KEEOIQ.js";
32
+ } from "./chunk-UMCMZFXW.js";
33
33
  import {
34
34
  CacheError,
35
35
  FailureCode,
@@ -38,26 +38,26 @@ import {
38
38
  maxFailureFields,
39
39
  maxFailureMessageLength,
40
40
  maxUpstreamMessageLength
41
- } from "./chunk-BRGF7VFN.js";
41
+ } from "./chunk-5DLG2FVN.js";
42
42
  import {
43
43
  SkillLoadFailed,
44
44
  skillFormatLimits
45
- } from "./chunk-MYCVMDWI.js";
45
+ } from "./chunk-HW3DPBZR.js";
46
46
  import {
47
47
  invocationFetch
48
- } from "./chunk-WGBI5MVX.js";
48
+ } from "./chunk-ETLILMHY.js";
49
49
  import {
50
50
  jsonSchemaDocument
51
- } from "./chunk-YML53Z7H.js";
51
+ } from "./chunk-NPGRURDG.js";
52
52
  import {
53
53
  AppStorageError,
54
54
  AppStorageUnavailable
55
- } from "./chunk-BTJMXW4I.js";
55
+ } from "./chunk-6KG4DZD7.js";
56
56
  import {
57
57
  AccountId,
58
58
  HttpUrl,
59
59
  JsonObject
60
- } from "./chunk-PWF2DRJ3.js";
60
+ } from "./chunk-FBBXFFFJ.js";
61
61
  import {
62
62
  Cause_exports,
63
63
  Effect_exports,
@@ -67,7 +67,7 @@ import {
67
67
  Redacted_exports,
68
68
  Result_exports,
69
69
  Schema_exports
70
- } from "./chunk-NXTXZ635.js";
70
+ } from "./chunk-EXGKN554.js";
71
71
 
72
72
  // src/contracts/openapi.ts
73
73
  var OpenapiErrorResponse = Schema_exports.Struct({
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-NXTXZ635.js";
3
+ } from "./chunk-EXGKN554.js";
4
4
 
5
5
  // ../app-data/src/contracts/database.ts
6
6
  var DataName = Schema_exports.String.check(