@pipelex/mthds-form 0.2.0 → 0.4.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/README.md +7 -2
- package/dist/chunk-6XD6UZSU.js +28 -0
- package/dist/chunk-6XD6UZSU.js.map +1 -0
- package/dist/chunk-7BMOPXDY.js +205 -0
- package/dist/chunk-7BMOPXDY.js.map +1 -0
- package/dist/chunk-GKV77RAS.js +46 -0
- package/dist/chunk-GKV77RAS.js.map +1 -0
- package/dist/chunk-HARYEWNG.js +31 -0
- package/dist/chunk-HARYEWNG.js.map +1 -0
- package/dist/chunk-KFZ5MZOM.js +44 -0
- package/dist/chunk-KFZ5MZOM.js.map +1 -0
- package/dist/chunk-NMT7BRLO.js +40 -0
- package/dist/chunk-NMT7BRLO.js.map +1 -0
- package/dist/chunk-O4O3QNVC.js +146 -0
- package/dist/chunk-O4O3QNVC.js.map +1 -0
- package/dist/chunk-PM55AHRO.js +52 -0
- package/dist/chunk-PM55AHRO.js.map +1 -0
- package/dist/chunk-RPA7DNSK.js +41 -0
- package/dist/chunk-RPA7DNSK.js.map +1 -0
- package/dist/chunk-V3OV2XQT.js +12 -0
- package/dist/chunk-V3OV2XQT.js.map +1 -0
- package/dist/chunk-VMLXO5JS.js +132 -0
- package/dist/chunk-VMLXO5JS.js.map +1 -0
- package/dist/chunk-VTPUDBSJ.js +61 -0
- package/dist/chunk-VTPUDBSJ.js.map +1 -0
- package/dist/chunk-WXBSM2CE.js +201 -0
- package/dist/chunk-WXBSM2CE.js.map +1 -0
- package/dist/chunk-XEPD5VJQ.js +99 -0
- package/dist/chunk-XEPD5VJQ.js.map +1 -0
- package/dist/core/contracts.d.ts +143 -0
- package/dist/core/contracts.js +4 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/date-format.d.ts +87 -0
- package/dist/core/date-format.js +3 -0
- package/dist/core/date-format.js.map +1 -0
- package/dist/core/derive.d.ts +20 -0
- package/dist/core/derive.js +7 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{descriptor-X6MwFIWu.d.ts → core/descriptor.d.ts} +42 -1
- package/dist/core/descriptor.js +3 -0
- package/dist/core/descriptor.js.map +1 -0
- package/dist/core/gate-validator.d.ts +27 -0
- package/dist/core/gate-validator.js +4 -0
- package/dist/core/gate-validator.js.map +1 -0
- package/dist/core/gate.d.ts +144 -0
- package/dist/core/gate.js +13 -0
- package/dist/core/gate.js.map +1 -0
- package/dist/core/index.d.ts +12 -615
- package/dist/core/index.js +14 -1
- package/dist/core/native-concepts.d.ts +78 -0
- package/dist/core/native-concepts.js +3 -0
- package/dist/core/native-concepts.js.map +1 -0
- package/dist/core/normalize-schema.d.ts +30 -0
- package/dist/core/normalize-schema.js +4 -0
- package/dist/core/normalize-schema.js.map +1 -0
- package/dist/core/own-property.d.ts +46 -0
- package/dist/core/own-property.js +3 -0
- package/dist/core/own-property.js.map +1 -0
- package/dist/core/readiness.d.ts +89 -0
- package/dist/core/readiness.js +4 -0
- package/dist/core/readiness.js.map +1 -0
- package/dist/core/schema-utils.d.ts +74 -0
- package/dist/core/schema-utils.js +3 -0
- package/dist/core/schema-utils.js.map +1 -0
- package/dist/core/validation-message.d.ts +39 -0
- package/dist/core/validation-message.js +4 -0
- package/dist/core/validation-message.js.map +1 -0
- package/dist/core/values.d.ts +91 -0
- package/dist/core/values.js +11 -0
- package/dist/core/values.js.map +1 -0
- package/dist/core/wire-format.d.ts +95 -0
- package/dist/core/wire-format.js +7 -0
- package/dist/core/wire-format.js.map +1 -0
- package/dist/react/index.d.ts +22 -1
- package/dist/react/index.js +128 -48
- package/dist/react/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -1
- package/dist/chunk-YWMUM7BC.js +0 -966
- package/dist/chunk-YWMUM7BC.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,9 +21,10 @@ import { FieldRenderer } from '@pipelex/mthds-form/react'; // the controls
|
|
|
21
21
|
import { buildRunFields, computeReadiness, getPipeIOContract } from '@pipelex/mthds-form';
|
|
22
22
|
import { FieldRenderer } from '@pipelex/mthds-form/react';
|
|
23
23
|
|
|
24
|
-
const contract = getPipeIOContract(method.pipe_io_contracts,
|
|
24
|
+
const contract = getPipeIOContract(method.pipe_io_contracts, method.domain, pipeCode);
|
|
25
25
|
const fields = buildRunFields(contract.inputs);
|
|
26
|
-
const {
|
|
26
|
+
const { missing } = computeReadiness(fields, values);
|
|
27
|
+
const canRun = missing.length === 0;
|
|
27
28
|
|
|
28
29
|
return fields.map((field) => (
|
|
29
30
|
<FieldRenderer
|
|
@@ -36,6 +37,10 @@ return fields.map((field) => (
|
|
|
36
37
|
));
|
|
37
38
|
```
|
|
38
39
|
|
|
40
|
+
The lookup takes its arguments in wire order — **contracts, domain, pipe code** — and both of the last two are strings, so swapping them typechecks. It resolves anyway against a map keyed by bare pipe code, and fails only against one keyed by namespaced `pipe_ref`, a long way from the call.
|
|
41
|
+
|
|
42
|
+
`computeReadiness` reports `{ total, ready, missing }` — `missing` names the inputs still to fill, so it is both the Run gate and what a form tells the user is left.
|
|
43
|
+
|
|
39
44
|
`buildRunFields` is the only function that reads JSON Schema. Everything downstream — rendering, readiness, validation messaging — reads the `RunField` descriptor it returns. That is the load-bearing rule of the package, and [docs/architecture.md](docs/architecture.md) explains what it buys.
|
|
40
45
|
|
|
41
46
|
Submitting goes through the gate: `buildRunInputsSchema` → `prepareRunInputs` → `validateRunInputs` → `apiInputsFromSchemaData`. The verdict is structured (`RunInputError[]`), and `describeValidationError` renders it for a person.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/core/descriptor.ts
|
|
2
|
+
function conceptCategory(field) {
|
|
3
|
+
switch (field.kind) {
|
|
4
|
+
case "text":
|
|
5
|
+
case "prose":
|
|
6
|
+
return "text";
|
|
7
|
+
case "date":
|
|
8
|
+
return "date";
|
|
9
|
+
case "document":
|
|
10
|
+
return "document";
|
|
11
|
+
case "image":
|
|
12
|
+
return "image";
|
|
13
|
+
case "number":
|
|
14
|
+
return "number";
|
|
15
|
+
case "boolean":
|
|
16
|
+
return "boolean";
|
|
17
|
+
case "enum":
|
|
18
|
+
return "choice";
|
|
19
|
+
case "list":
|
|
20
|
+
return "list";
|
|
21
|
+
default:
|
|
22
|
+
return "structured";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { conceptCategory };
|
|
27
|
+
//# sourceMappingURL=chunk-6XD6UZSU.js.map
|
|
28
|
+
//# sourceMappingURL=chunk-6XD6UZSU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/descriptor.ts"],"names":[],"mappings":";AAkKO,SAAS,gBAAgB,KAAA,EAAkC;AAChE,EAAA,QAAQ,MAAM,IAAA;AAAM,IAClB,KAAK,MAAA;AAAA,IACL,KAAK,OAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT,KAAK,UAAA;AACH,MAAA,OAAO,UAAA;AAAA,IACT,KAAK,OAAA;AACH,MAAA,OAAO,OAAA;AAAA,IACT,KAAK,QAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAA,OAAO,SAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT;AACE,MAAA,OAAO,YAAA;AAAA;AAEb","file":"chunk-6XD6UZSU.js","sourcesContent":["/**\n * The `RunField` descriptor - the consumer-facing currency of the form kernel.\n *\n * A method's inputs arrive from the API as a map of variable name →\n * `PipeInputContract` ({ concept_ref, json_schema }). That JSON Schema is rich\n * (Pydantic-generated) and not pleasant to render directly. `buildRunFields`\n * (in `derive.ts`) normalizes it once into a flat, recursive `RunField[]`\n * descriptor that the presentational field components consume - so the\n * components never touch raw JSON Schema, and stories can describe any input\n * shape declaratively.\n *\n * Pure module: no React, no API calls. Trivially unit-testable.\n */\n\nexport type RunFieldKind =\n | 'text' // short single-line string\n | 'prose' // long free-text (textarea)\n | 'date' // a calendar date (schema `format: date` or `date-time`)\n | 'number' // integer or float\n | 'boolean' // true/false\n | 'enum' // pick one of a fixed set\n | 'document' // a file (PDF, docx…) by upload or URL\n | 'image' // a file rendered with a preview\n | 'object' // a structured concept with nested fields\n | 'list' // an array of one element type\n | 'unknown'; // anything we can't map → raw JSON escape hatch\n\nexport interface RunFieldCommon {\n /** The variable identifier as written in the method (rendered in mono). */\n name: string;\n /** Human label; falls back to `name` when absent. */\n title?: string;\n /** The concept this input carries, e.g. `native.Document`, `demo.Invoice`. */\n conceptRef?: string;\n /** One-line helper text shown under the label. */\n description?: string;\n /** Required inputs always show; optional ones can collapse. */\n required: boolean;\n /**\n * Whether Run waits for this input - set on TOP-LEVEL fields only, straight\n * from `inputMustBeFilled` (see `mustBeFilled` in `readiness.ts` for why this\n * is not the same question as `required`). Nested fields leave it undefined;\n * they are gated through their parent's `fieldFilled`.\n */\n gating?: boolean;\n /**\n * The single property this field's value sits inside on the wire, when its\n * concept declares a scalar content model: `native.Text` is `TextContent\n * {text}`, `native.Number` is `NumberContent {number}`, `native.YesNo` is\n * `YesNoContent {yes_no}`. The control still holds the plain scalar; the\n * value bridge wraps into this property on the way out and unwraps on the way\n * back in.\n *\n * A property NAME, never a schema - the descriptor stays the only currency\n * and `buildRunFields` stays the only reader of JSON Schema. Absent whenever\n * the value is already the whole content (a structured concept, a file, a\n * child property of a structure): wrapping those would double-nest them.\n */\n contentKey?: string;\n}\n\nexport interface TextRunField extends RunFieldCommon {\n kind: 'text';\n placeholder?: string;\n}\n\nexport interface ProseRunField extends RunFieldCommon {\n kind: 'prose';\n placeholder?: string;\n}\n\nexport interface DateRunField extends RunFieldCommon {\n kind: 'date';\n /**\n * True when the backing schema is `format: date-time`: the stored value is a\n * full RFC 3339 timestamp (`2026-07-06T00:00:00Z`) so it passes the API's\n * `date-time` validation, even though the control only asks for a day. False\n * for a bare `format: date`, where the value stays `YYYY-MM-DD`.\n */\n datetime: boolean;\n}\n\nexport interface NumberRunField extends RunFieldCommon {\n kind: 'number';\n integer: boolean;\n min?: number;\n max?: number;\n}\n\nexport interface BooleanRunField extends RunFieldCommon {\n kind: 'boolean';\n}\n\nexport interface EnumRunField extends RunFieldCommon {\n kind: 'enum';\n options: string[];\n}\n\nexport interface FileRunField extends RunFieldCommon {\n kind: 'document' | 'image';\n /** Accept hint shown to the user, e.g. \"PDF, PNG, JPG\". */\n accept?: string;\n}\n\nexport interface ObjectRunField extends RunFieldCommon {\n kind: 'object';\n fields: RunField[];\n}\n\nexport interface ListRunField extends RunFieldCommon {\n kind: 'list';\n /** The element descriptor (its `name` is unused; the index labels items). */\n item: RunField;\n /**\n * The FEWEST items the slot accepts, when the schema states a lower bound.\n * Absent for a variable `Concept[]` list, which demands none.\n *\n * Read off the array schema's `minItems` rather than off the contract's\n * `item_count`, which states the same number: this exists so `fieldFilled` can\n * answer the question **ajv** answers, and `minItems` is the keyword ajv\n * reads. pipelex emits `minItems`/`maxItems` = N for a `[N]` slot and neither\n * for `[]`, so on a top-level slot the two sources agree by construction.\n *\n * A schema may still state a lower bound alone - `mapSchema` recurses, so a\n * nested array inside a structured concept reaches here with whatever its\n * model declared and no MTHDS multiplicity behind it. Gating on that bound is\n * the same rule, and it is the direction that cannot leave readiness more\n * permissive than the gate.\n */\n itemCount?: number;\n /**\n * The MOST items the slot accepts, off the schema's `maxItems`.\n *\n * A separate field because it is a separate fact, and conflating them is a\n * bug that hides: `itemCount` was read as a minimum by readiness and as a\n * maximum by the control that stops offering `Add`, which agree only while\n * a contract states both bounds equal. A list told \"at least two\" was then\n * presented as a list of exactly two.\n */\n maxItemCount?: number;\n}\n\nexport interface UnknownRunField extends RunFieldCommon {\n kind: 'unknown';\n}\n\nexport type RunField =\n | TextRunField\n | ProseRunField\n | DateRunField\n | NumberRunField\n | BooleanRunField\n | EnumRunField\n | FileRunField\n | ObjectRunField\n | ListRunField\n | UnknownRunField;\n\n/** The short, friendly category label for a concept_ref (drives the pill dot). */\nexport type ConceptCategory =\n 'text' | 'date' | 'document' | 'image' | 'number' | 'boolean' | 'choice' | 'structured' | 'list';\n\nexport function conceptCategory(field: RunField): ConceptCategory {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return 'text';\n case 'date':\n return 'date';\n case 'document':\n return 'document';\n case 'image':\n return 'image';\n case 'number':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'enum':\n return 'choice';\n case 'list':\n return 'list';\n default:\n return 'structured';\n }\n}\n"]}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { collectSchemaDefs, resolveSchemaIndirection, schemaTypeOf } from './chunk-O4O3QNVC.js';
|
|
2
|
+
import { ownProp, hasOwnProp } from './chunk-V3OV2XQT.js';
|
|
3
|
+
import { asCalendarDate } from './chunk-GKV77RAS.js';
|
|
4
|
+
import { splitListConcept, isWireTextConcept, isWireDocumentLikeConcept } from './chunk-NMT7BRLO.js';
|
|
5
|
+
|
|
6
|
+
// src/core/wire-format.ts
|
|
7
|
+
function isListConcept(conceptCode) {
|
|
8
|
+
const { base, isList } = splitListConcept(conceptCode);
|
|
9
|
+
return { isList, baseConcept: base ?? "" };
|
|
10
|
+
}
|
|
11
|
+
var isTextConcept = isWireTextConcept;
|
|
12
|
+
var isDocumentLikeConcept = isWireDocumentLikeConcept;
|
|
13
|
+
function deflateInput(value, conceptCode) {
|
|
14
|
+
const { isList, baseConcept } = isListConcept(conceptCode);
|
|
15
|
+
if (isList) {
|
|
16
|
+
const items = Array.isArray(value) ? value : [];
|
|
17
|
+
return items.map((item) => deflateListItem(item, baseConcept));
|
|
18
|
+
}
|
|
19
|
+
return deflateSingleValue(value, baseConcept);
|
|
20
|
+
}
|
|
21
|
+
function deflateListItem(value, concept) {
|
|
22
|
+
if (isTextConcept(concept)) {
|
|
23
|
+
if (value && typeof value === "object" && "text" in value) {
|
|
24
|
+
return value.text;
|
|
25
|
+
}
|
|
26
|
+
return typeof value === "string" ? value : String(value ?? "");
|
|
27
|
+
}
|
|
28
|
+
if (isDocumentLikeConcept(concept)) {
|
|
29
|
+
if (value && typeof value === "object" && "url" in value) {
|
|
30
|
+
return value.url;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === "string") return value;
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
return { concept, content: unwrapAllWrappers(value) };
|
|
36
|
+
}
|
|
37
|
+
function deflateSingleValue(value, concept) {
|
|
38
|
+
if (isTextConcept(concept)) {
|
|
39
|
+
if (value && typeof value === "object" && "text" in value) {
|
|
40
|
+
return value.text;
|
|
41
|
+
}
|
|
42
|
+
return typeof value === "string" ? value : String(value ?? "");
|
|
43
|
+
}
|
|
44
|
+
if (isDocumentLikeConcept(concept)) {
|
|
45
|
+
if (value && typeof value === "object" && "url" in value) {
|
|
46
|
+
return value.url;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === "string") return value;
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
return { concept, content: unwrapAllWrappers(value) };
|
|
52
|
+
}
|
|
53
|
+
function inflateInput(value, conceptCode) {
|
|
54
|
+
const { isList, baseConcept } = isListConcept(conceptCode);
|
|
55
|
+
if (isList) {
|
|
56
|
+
const unwrapped = isWrappedForm(value) ? value.content : value;
|
|
57
|
+
let items;
|
|
58
|
+
if (Array.isArray(unwrapped)) {
|
|
59
|
+
items = unwrapped;
|
|
60
|
+
} else if (unwrapped != null && typeof unwrapped === "object") {
|
|
61
|
+
items = [unwrapped];
|
|
62
|
+
} else {
|
|
63
|
+
items = [];
|
|
64
|
+
}
|
|
65
|
+
return items.map((item) => inflateSingleValue(item, baseConcept));
|
|
66
|
+
}
|
|
67
|
+
return inflateSingleValue(value, baseConcept);
|
|
68
|
+
}
|
|
69
|
+
var DOCUMENT_FIELDS = /* @__PURE__ */ new Set(["url", "public_url", "mime_type", "filename", "title", "snippet"]);
|
|
70
|
+
function looksLikeDocument(obj) {
|
|
71
|
+
return Object.keys(obj).some((k) => DOCUMENT_FIELDS.has(k));
|
|
72
|
+
}
|
|
73
|
+
function isWrappedForm(value) {
|
|
74
|
+
return !!value && typeof value === "object" && "concept" in value && "content" in value && typeof value.concept === "string";
|
|
75
|
+
}
|
|
76
|
+
function inflateSingleValue(value, concept) {
|
|
77
|
+
if (isWrappedForm(value) && (isTextConcept(concept) || isDocumentLikeConcept(concept))) {
|
|
78
|
+
return inflateSingleValue(value.content, concept);
|
|
79
|
+
}
|
|
80
|
+
if (isTextConcept(concept)) {
|
|
81
|
+
if (typeof value === "string") {
|
|
82
|
+
return { text: value };
|
|
83
|
+
}
|
|
84
|
+
if (value && typeof value === "object" && "text" in value) {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
return { text: "" };
|
|
88
|
+
}
|
|
89
|
+
if (isDocumentLikeConcept(concept)) {
|
|
90
|
+
if (typeof value === "string") {
|
|
91
|
+
return { url: value };
|
|
92
|
+
}
|
|
93
|
+
if (value && typeof value === "object" && "url" in value) {
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
if (value && typeof value === "object" && looksLikeDocument(value)) {
|
|
97
|
+
return { ...value, url: "" };
|
|
98
|
+
}
|
|
99
|
+
return { url: "" };
|
|
100
|
+
}
|
|
101
|
+
return unwrapAllWrappers(value);
|
|
102
|
+
}
|
|
103
|
+
function unwrapAllWrappers(value) {
|
|
104
|
+
let current = value;
|
|
105
|
+
while (isWrappedForm(current)) {
|
|
106
|
+
current = current.content;
|
|
107
|
+
}
|
|
108
|
+
if (current && typeof current === "object" && !Array.isArray(current) && "content" in current) {
|
|
109
|
+
return current.content;
|
|
110
|
+
}
|
|
111
|
+
return current;
|
|
112
|
+
}
|
|
113
|
+
function resolveConceptCode(schema) {
|
|
114
|
+
const code = schema.concept_ref;
|
|
115
|
+
if (!code) return "";
|
|
116
|
+
if (!code.endsWith("[]") && schema.json_schema?.type === "array") {
|
|
117
|
+
return code + "[]";
|
|
118
|
+
}
|
|
119
|
+
return code;
|
|
120
|
+
}
|
|
121
|
+
function deflateAllInputs(formData, inputSchemas) {
|
|
122
|
+
const result = {};
|
|
123
|
+
for (const [stuffName, schema] of Object.entries(inputSchemas)) {
|
|
124
|
+
result[stuffName] = deflateInput(ownProp(formData, stuffName), resolveConceptCode(schema));
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
function healStringWrappers(value, rawSchema, defs) {
|
|
129
|
+
if (!rawSchema || value == null) return value;
|
|
130
|
+
const allDefs = defs ?? collectSchemaDefs(rawSchema, {}, { traverseArrays: false });
|
|
131
|
+
const schema = resolveSchemaIndirection(rawSchema, allDefs);
|
|
132
|
+
const type = schemaTypeOf(schema);
|
|
133
|
+
if (type === "string" && schema.format === "date" && typeof value === "string") {
|
|
134
|
+
return asCalendarDate(value) ?? value;
|
|
135
|
+
}
|
|
136
|
+
if (type === "string") {
|
|
137
|
+
if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 1 && typeof value.text === "string") {
|
|
138
|
+
return value.text;
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
if (type === "object" && typeof value === "object" && !Array.isArray(value)) {
|
|
143
|
+
const props = schema.properties;
|
|
144
|
+
if (!props) return value;
|
|
145
|
+
const out = { ...value };
|
|
146
|
+
for (const [key, propSchema] of Object.entries(props)) {
|
|
147
|
+
if (hasOwnProp(out, key)) out[key] = healStringWrappers(out[key], propSchema, allDefs);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
if (type === "array" && Array.isArray(value)) {
|
|
152
|
+
const items = schema.items;
|
|
153
|
+
return value.map((item) => healStringWrappers(item, items, allDefs));
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function isEmptyAfterPruning(value) {
|
|
158
|
+
if (value === "" || value === null || value === void 0) return true;
|
|
159
|
+
return typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
160
|
+
}
|
|
161
|
+
function pruneEmptyOptionals(value, rawSchema, defs) {
|
|
162
|
+
if (!rawSchema || value == null) return value;
|
|
163
|
+
const allDefs = defs ?? collectSchemaDefs(rawSchema, {}, { traverseArrays: false });
|
|
164
|
+
const schema = resolveSchemaIndirection(rawSchema, allDefs);
|
|
165
|
+
const type = schemaTypeOf(schema);
|
|
166
|
+
if (type === "array" && Array.isArray(value)) {
|
|
167
|
+
const items = schema.items;
|
|
168
|
+
return value.map((item) => pruneEmptyOptionals(item, items, allDefs));
|
|
169
|
+
}
|
|
170
|
+
if (type !== "object" || typeof value !== "object" || Array.isArray(value)) return value;
|
|
171
|
+
const props = schema.properties;
|
|
172
|
+
if (!props) return value;
|
|
173
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
174
|
+
const out = {};
|
|
175
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
176
|
+
const propSchema = ownProp(props, key);
|
|
177
|
+
if (!propSchema) {
|
|
178
|
+
out[key] = raw;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const pruned = pruneEmptyOptionals(raw, propSchema, allDefs);
|
|
182
|
+
if (isEmptyAfterPruning(pruned) && !required.has(key)) continue;
|
|
183
|
+
out[key] = pruned;
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
function inflateAllInputs(simplifiedData, inputSchemas) {
|
|
188
|
+
const result = {};
|
|
189
|
+
for (const [stuffName, value] of Object.entries(simplifiedData)) {
|
|
190
|
+
const schema = ownProp(inputSchemas, stuffName);
|
|
191
|
+
if (schema) {
|
|
192
|
+
result[stuffName] = healStringWrappers(
|
|
193
|
+
inflateInput(value, resolveConceptCode(schema)),
|
|
194
|
+
schema.json_schema
|
|
195
|
+
);
|
|
196
|
+
} else {
|
|
197
|
+
result[stuffName] = value;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode };
|
|
204
|
+
//# sourceMappingURL=chunk-7BMOPXDY.js.map
|
|
205
|
+
//# sourceMappingURL=chunk-7BMOPXDY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/wire-format.ts"],"names":[],"mappings":";;;;;;AA0BA,SAAS,cAAc,WAAA,EAA+D;AACpF,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,EAAO,GAAI,iBAAiB,WAAW,CAAA;AACrD,EAAA,OAAO,EAAE,MAAA,EAAQ,WAAA,EAAa,IAAA,IAAQ,EAAA,EAAG;AAC3C;AAEA,IAAM,aAAA,GAAgB,iBAAA;AACtB,IAAM,qBAAA,GAAwB,yBAAA;AAgBvB,SAAS,YAAA,CAAa,OAAgB,WAAA,EAA8B;AACzE,EAAA,MAAM,EAAE,MAAA,EAAQ,WAAA,EAAY,GAAI,cAAc,WAAW,CAAA;AAEzD,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,QAAQ,EAAC;AAG9C,IAAA,OAAO,MAAM,GAAA,CAAI,CAAC,SAAS,eAAA,CAAgB,IAAA,EAAM,WAAW,CAAC,CAAA;AAAA,EAC/D;AAEA,EAAA,OAAO,kBAAA,CAAmB,OAAO,WAAW,CAAA;AAC9C;AAGA,SAAS,eAAA,CAAgB,OAAgB,OAAA,EAA0B;AACjE,EAAA,IAAI,aAAA,CAAc,OAAO,CAAA,EAAG;AAC1B,IAAA,IAAI,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,KAAA,EAAO;AACzD,MAAA,OAAQ,KAAA,CAA2B,IAAA;AAAA,IACrC;AACA,IAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,MAAA,CAAO,SAAS,EAAE,CAAA;AAAA,EAC/D;AAEA,EAAA,IA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AAA,EAAO,GAAG,CAAA;AACrC,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,GAAA,CAAI,GAAG,CAAA,GAAI,GAAA;AACX,MAAA;AAAA,IACF;AACA,IAAA,MAAM,MAAA,GAAS,mBAAA,CAAoB,GAAA,EAAK,UAAA,EAAY,OAAO,CAAA;AAC3D,IAAA,IAAI,oBAAoB,MAAM,CAAA,IAAK,CAAC,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA,EAAG;AACvD,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI,MAAA;AAAA,EACb;AACA,EAAA,OAAO,GAAA;AACT;AAMO,SAAS,gBAAA,CACd,gBACA,YAAA,EACyB;AACzB,EAAA,MAAM,SAAkC,EAAC;AACzC,EAAA,KAAA,MAAW,CAAC,SAAA,EAAW,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,cAAc,CAAA,EAAG;AAC/D,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,YAAA,EAAc,SAAS,CAAA;AAC9C,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,MAAA,CAAO,SAAS,CAAA,GAAI,kBAAA;AAAA,QAClB,YAAA,CAAa,KAAA,EAAO,kBAAA,CAAmB,MAAM,CAAC,CAAA;AAAA,QAC9C,MAAA,CAAO;AAAA,OACT;AAAA,IACF,CAAA,MAAO;AAEL,MAAA,MAAA,CAAO,SAAS,CAAA,GAAI,KAAA;AAAA,IACtB;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"chunk-7BMOPXDY.js","sourcesContent":["/**\n * Converts between the simplified inputs.json format and the full RJSF form format.\n *\n * The inputs.json file uses a SIMPLIFIED format for users:\n * - Text: \"my text\" (instead of { text: \"my text\" })\n * - Document: \"file.pdf\" or { url: \"...\" } (instead of { url: \"...\", ... })\n * - Image: same as Document\n * - Text[]: [\"t1\", \"t2\"]\n * - Document[]: [\"f1.pdf\"] or [{ url: \"...\" }]\n * - Custom: { concept, content } (no simplification)\n *\n * The RJSF form uses the FULL concept structure from the json_schema.\n *\n * Two directions:\n * - deflate: form (full) → inputs.json (simplified) - for writing inputs.json / API calls\n * - inflate: inputs.json (simplified) → form (full) - for populating the form from inputs.json\n */\n\nimport { asCalendarDate } from './date-format';\nimport { isWireDocumentLikeConcept, isWireTextConcept, splitListConcept } from './native-concepts';\nimport { hasOwnProp, ownProp } from './own-property';\nimport { collectSchemaDefs, resolveSchemaIndirection, schemaTypeOf } from './schema-utils';\n\n/** The wire-format view of the native-concept taxonomy (which concept codes use\n * simplified formats) lives in `native-concepts.ts` - including the record of\n * where it drifts from the field mapper's view. */\nfunction isListConcept(conceptCode: string): { isList: boolean; baseConcept: string } {\n const { base, isList } = splitListConcept(conceptCode);\n return { isList, baseConcept: base ?? '' };\n}\n\nconst isTextConcept = isWireTextConcept;\nconst isDocumentLikeConcept = isWireDocumentLikeConcept;\n\n// ─── Deflate: form (full) → inputs.json (simplified) ──────────────────────\n\n/**\n * Convert a single form value to the simplified inputs.json format.\n * Used when writing inputs.json and when calling the run API.\n *\n * Rules:\n * - Text { text: \"hello\" } → \"hello\"\n * - Document { url: \"file.pdf\", ... } → \"file.pdf\" (if only url) or { url, ... }\n * - Image: same as Document\n * - Page: same as Document\n * - List types → array of deflated items\n * - Custom → { concept, content }\n */\nexport function deflateInput(value: unknown, conceptCode: string): unknown {\n const { isList, baseConcept } = isListConcept(conceptCode);\n\n if (isList) {\n const items = Array.isArray(value) ? value : [];\n // pipelex accepts Sequence[str] for list inputs, not list of dicts.\n // Always simplify list items to their scalar form (URL string for docs, plain string for text).\n return items.map((item) => deflateListItem(item, baseConcept));\n }\n\n return deflateSingleValue(value, baseConcept);\n}\n\n/** Deflate a single item within a list - always reduces to the simplest scalar form. */\nfunction deflateListItem(value: unknown, concept: string): unknown {\n if (isTextConcept(concept)) {\n if (value && typeof value === 'object' && 'text' in value) {\n return (value as { text: string }).text;\n }\n return typeof value === 'string' ? value : String(value ?? '');\n }\n\n if (isDocumentLikeConcept(concept)) {\n // Always extract just the URL for list items - pipelex resolves metadata at runtime\n if (value && typeof value === 'object' && 'url' in value) {\n return (value as { url: string }).url;\n }\n if (typeof value === 'string') return value;\n return '';\n }\n\n // Custom structured concept → { concept, content }.\n //\n // IDEMPOTENT ON PURPOSE - see `unwrapAllWrappers`. Wrapping unconditionally\n // corrupted persisted inputs: a host panel seeds the form with the RAW\n // stored value when the input schemas aren't loaded yet (no dry run yet),\n // so the form could hold an ALREADY-wrapped value; the next change deflated\n // it again and saved `{ concept, content: { concept, content: {...} } }`.\n // Wrapping exactly once, whatever we're handed, makes that unreachable.\n return { concept, content: unwrapAllWrappers(value) };\n}\n\nfunction deflateSingleValue(value: unknown, concept: string): unknown {\n if (isTextConcept(concept)) {\n // { text: \"hello\" } → \"hello\"\n if (value && typeof value === 'object' && 'text' in value) {\n return (value as { text: string }).text;\n }\n // Already a string (passthrough)\n return typeof value === 'string' ? value : String(value ?? '');\n }\n\n if (isDocumentLikeConcept(concept)) {\n // Always extract just the URL - pipelex resolves metadata at runtime.\n // A bare dict without a 'concept' key is rejected by StuffFactory.\n if (value && typeof value === 'object' && 'url' in value) {\n return (value as { url: string }).url;\n }\n // Already a string URL (passthrough)\n if (typeof value === 'string') return value;\n return '';\n }\n\n // Custom structured concept → { concept, content }.\n //\n // IDEMPOTENT ON PURPOSE - see `unwrapAllWrappers`. Wrapping unconditionally\n // corrupted persisted inputs: a host panel seeds the form with the RAW\n // stored value when the input schemas aren't loaded yet (no dry run yet),\n // so the form could hold an ALREADY-wrapped value; the next change deflated\n // it again and saved `{ concept, content: { concept, content: {...} } }`.\n // Wrapping exactly once, whatever we're handed, makes that unreachable.\n return { concept, content: unwrapAllWrappers(value) };\n}\n\n// ─── Inflate: inputs.json (simplified) → form (full) ──────────────────────\n\n/**\n * Convert a simplified inputs.json value to the full form structure.\n * Used when populating the RJSF form from inputs.json.\n *\n * Rules:\n * - \"hello\" → { text: \"hello\" } (for Text concepts)\n * - \"file.pdf\" → { url: \"file.pdf\" } (for Document/Image/Page concepts)\n * - { url: \"...\" } → passthrough (already full)\n * - [\"t1\", \"t2\"] → inflated array of items\n * - { concept, content } → content (for custom concepts)\n */\nexport function inflateInput(value: unknown, conceptCode: string): unknown {\n const { isList, baseConcept } = isListConcept(conceptCode);\n\n if (isList) {\n // The sandbox may write the wrapped form at the LIST level:\n // { concept: \"native.Document\", content: [item, item] } - pipelex accepts it.\n // Unwrap before the array check, otherwise the wrapper itself gets treated\n // as a single list item and inflates to one empty entry.\n const unwrapped = isWrappedForm(value) ? value.content : value;\n // Handle: array (correct), single object (legacy/form default), or null/undefined\n let items: unknown[];\n if (Array.isArray(unwrapped)) {\n items = unwrapped;\n } else if (unwrapped != null && typeof unwrapped === 'object') {\n // Single object instead of array (e.g., {\"url\": \"\"} from form default) - wrap it\n items = [unwrapped];\n } else {\n items = [];\n }\n return items.map((item) => inflateSingleValue(item, baseConcept));\n }\n\n return inflateSingleValue(value, baseConcept);\n}\n\n/** Known optional fields on DocumentContent (from pipelex Pydantic model). */\nconst DOCUMENT_FIELDS = new Set(['url', 'public_url', 'mime_type', 'filename', 'title', 'snippet']);\n\n/** Returns true if the object looks like a DocumentContent (has any known doc field). */\nfunction looksLikeDocument(obj: Record<string, unknown>): boolean {\n return Object.keys(obj).some((k) => DOCUMENT_FIELDS.has(k));\n}\n\n/**\n * Detect the fully-qualified wrapper form `{ concept: \"...\", content: ... }`.\n * pipelex accepts this for any concept (native or custom), and the mthds-inputs\n * agent skill writes it by default for disambiguation. We unwrap before applying\n * concept-specific inflation so the form populates correctly.\n */\nfunction isWrappedForm(value: unknown): value is { concept: string; content: unknown } {\n return (\n !!value &&\n typeof value === 'object' &&\n 'concept' in value &&\n 'content' in value &&\n typeof (value as { concept: unknown }).concept === 'string'\n );\n}\n\nfunction inflateSingleValue(value: unknown, concept: string): unknown {\n // Unwrap { concept, content } for native concepts - the content IS the value.\n // For custom concepts we unwrap below (historical behaviour) but after concept-specific checks.\n if (isWrappedForm(value) && (isTextConcept(concept) || isDocumentLikeConcept(concept))) {\n return inflateSingleValue(value.content, concept);\n }\n\n if (isTextConcept(concept)) {\n // \"hello\" → { text: \"hello\" }\n if (typeof value === 'string') {\n return { text: value };\n }\n // Already full structure { text: \"...\" }\n if (value && typeof value === 'object' && 'text' in value) {\n return value;\n }\n return { text: '' };\n }\n\n if (isDocumentLikeConcept(concept)) {\n // \"file.pdf\" → { url: \"file.pdf\" }\n if (typeof value === 'string') {\n return { url: value };\n }\n // Already full structure { url: \"...\" }\n if (value && typeof value === 'object' && 'url' in value) {\n return value;\n }\n // Object without url key but with other document fields (e.g. from RJSF defaults)\n // Ensure the required url field is present\n if (value && typeof value === 'object' && looksLikeDocument(value as Record<string, unknown>)) {\n return { ...(value as Record<string, unknown>), url: '' };\n }\n return { url: '' };\n }\n\n // Custom structured: unwrap { concept, content } → content.\n //\n // Unwrap REPEATEDLY. `deflateSingleValue` used to wrap unconditionally, so a\n // form change made while the input schemas weren't loaded yet re-wrapped an\n // already-wrapped value and persisted `{ concept, content: { concept,\n // content: {...} } }` to DynamoDB. Unwrapping a single level left the FORM\n // holding `{ concept, content }` - properties no schema declares, so RJSF\n // matched nothing and rendered every field empty, with the real values\n // sitting one level deeper. Deflate is idempotent now, but the corrupted\n // shape survives in persisted inputData, so this heals it on read.\n return unwrapAllWrappers(value);\n}\n\n/** Strip every `{ concept, content }` layer - one, or the double wrap a\n * non-idempotent deflate persisted. */\nfunction unwrapAllWrappers(value: unknown): unknown {\n let current = value;\n while (isWrappedForm(current)) {\n current = current.content;\n }\n // A `{ content }` with no `concept` is the historical half-wrapper.\n if (current && typeof current === 'object' && !Array.isArray(current) && 'content' in current) {\n return (current as { content: unknown }).content;\n }\n return current;\n}\n\n// ─── Schema helpers ─────────────────────────────────────────────────────\n\ninterface InputSchema {\n concept_ref: string;\n json_schema?: Record<string, unknown>;\n}\n\n/**\n * The validation API returns concept_ref WITHOUT the [] suffix for list inputs.\n * The array-ness is only encoded in json_schema.type === \"array\".\n * This helper resolves the correct concept ref by checking the schema.\n */\nexport function resolveConceptCode(schema: InputSchema): string {\n const code = schema.concept_ref;\n // Defensive: a malformed/partial contract entry (missing concept) must\n // degrade, never throw and blank the whole input panel.\n if (!code) return '';\n if (!code.endsWith('[]') && (schema.json_schema as Record<string, unknown>)?.type === 'array') {\n return code + '[]';\n }\n return code;\n}\n\n// ─── Batch helpers for full inputData objects ────────────────────────────\n\n/**\n * Deflate all inputs from form format to simplified inputs.json format.\n * Used by InputConfigPanel when preparing data for the run API.\n */\nexport function deflateAllInputs(\n formData: Record<string, unknown>,\n inputSchemas: Record<string, InputSchema>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [stuffName, schema] of Object.entries(inputSchemas)) {\n result[stuffName] = deflateInput(ownProp(formData, stuffName), resolveConceptCode(schema));\n }\n return result;\n}\n\n/**\n * Heal values against their json_schema: the run-form bridge used to\n * double-wrap plain string properties as `{ text: \"...\" }` (fixed in\n * run-values.ts, but the corrupted shape survives in persisted inputData -\n * store and server copies). Wherever the schema expects a string but the\n * value is a lone `{ text: string }` wrapper, unwrap it. Walks nested\n * objects and arrays, resolving `#/$defs/...` refs against the root schema;\n * anything already valid passes through untouched.\n */\nexport function healStringWrappers(\n value: unknown,\n rawSchema: Record<string, unknown> | undefined,\n defs?: Record<string, Record<string, unknown>>,\n): unknown {\n if (!rawSchema || value == null) return value;\n\n // Resolve $ref / nullable-anyOf indirection (Pydantic emits `{$ref}` for\n // nested models and `anyOf: [T, {type:'null'}]` for optionals). The `$defs`\n // walk deliberately keeps its historical no-array-traversal mode - see\n // `CollectDefsOptions` in schema-utils.\n const allDefs = defs ?? collectSchemaDefs(rawSchema, {}, { traverseArrays: false });\n const schema = resolveSchemaIndirection(rawSchema, allDefs);\n const type = schemaTypeOf(schema);\n\n // A `format: date` field takes a calendar date ALONE. `DateContent` in pipelex\n // enforces that with a `mode=\"before\"` validator (`_reject_lax_temporal`) that\n // deliberately closes pydantic's lax coercion - a datetime string on `date`\n // would silently drop its time and offset (DT3, \"no silent midnight\"), so the\n // runner answers a 500, not a coercion.\n //\n // An agent-written or hand-written inputs.json says `\"2026-07-06T00:00:00Z\"`\n // anyway - that is how every system exports a date. So NORMALIZE it here to\n // the day it denotes rather than forwarding it to fail at the runner: the\n // padding is noise, and dropping noise is not the fidelity loss DT3 forbids.\n // A value carrying a REAL time (15:40) returns null and is left untouched -\n // it must fail, because silently discarding it is precisely the corruption\n // the rule exists to prevent.\n if (type === 'string' && schema.format === 'date' && typeof value === 'string') {\n return asCalendarDate(value) ?? value;\n }\n\n if (type === 'string') {\n if (\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.keys(value).length === 1 &&\n typeof (value as { text?: unknown }).text === 'string'\n ) {\n return (value as { text: string }).text;\n }\n return value;\n }\n if (type === 'object' && typeof value === 'object' && !Array.isArray(value)) {\n const props = schema.properties as Record<string, Record<string, unknown>> | undefined;\n if (!props) return value;\n const out = { ...(value as Record<string, unknown>) };\n for (const [key, propSchema] of Object.entries(props)) {\n if (hasOwnProp(out, key)) out[key] = healStringWrappers(out[key], propSchema, allDefs);\n }\n return out;\n }\n if (type === 'array' && Array.isArray(value)) {\n const items = schema.items as Record<string, unknown> | undefined;\n return value.map((item) => healStringWrappers(item, items, allDefs));\n }\n return value;\n}\n\n/** Nothing left worth sending, once this value has itself been pruned. */\nfunction isEmptyAfterPruning(value: unknown): boolean {\n if (value === '' || value === null || value === undefined) return true;\n // An object whose every property was itself pruned away carries nothing, and\n // that is what an untouched OPTIONAL STRUCTURED input looks like by the time\n // it reaches here - a shell of empty children, emptied out. Keeping the `{}`\n // handed it to ajv against the concept's full schema, which rejected the run\n // for a required child of an input the method said may be omitted. Dropping\n // it is the same judgement the wire payload already makes one step later\n // (`apiInputsFromSchemaData` omits it as unfilled); making the prune agree is\n // what stops the gate from failing a run it was about to omit anyway.\n //\n // An empty ARRAY is deliberately NOT empty: a plural slot is never absent in\n // MTHDS - its empty form IS the empty list - so dropping it would invent an\n // absence the method cannot express.\n return typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0;\n}\n\n/**\n * Drop optional properties the user never filled, so an untouched field cannot\n * fail validation or reach the API as an empty string.\n *\n * RJSF fills EVERY unset string property with `\"\"` on mount. That is harmless\n * for a plain string, but `prepareSchemaForRjsf` collapses pydantic's\n * `anyOf: [T, null]` by dropping the null branch, so an optional *constrained*\n * field - `DateContent.time`, declared `datetime.time | None` and rendered\n * `{ type: \"string\", format: \"time\" }` - is left demanding a well-formed time.\n * `\"\"` is not one, and the run was blocked on a field the user never opened.\n *\n * Pruning is the semantically correct repair, not a validation dodge: for\n * pipelex an absent optional field IS `None`, and `\"\"` would fail pydantic at\n * the runner just as it fails ajv here. Only properties absent from their\n * parent's `required` are dropped - an empty REQUIRED field must still fail, so\n * the user is told about it.\n *\n * What counts as empty is `isEmptyAfterPruning`, and it includes an optional\n * STRUCTURE the user never opened, on exactly the same grounds.\n */\nexport function pruneEmptyOptionals(\n value: unknown,\n rawSchema: Record<string, unknown> | undefined,\n defs?: Record<string, Record<string, unknown>>,\n): unknown {\n if (!rawSchema || value == null) return value;\n\n const allDefs = defs ?? collectSchemaDefs(rawSchema, {}, { traverseArrays: false });\n const schema = resolveSchemaIndirection(rawSchema, allDefs);\n const type = schemaTypeOf(schema);\n\n if (type === 'array' && Array.isArray(value)) {\n const items = schema.items as Record<string, unknown> | undefined;\n return value.map((item) => pruneEmptyOptionals(item, items, allDefs));\n }\n if (type !== 'object' || typeof value !== 'object' || Array.isArray(value)) return value;\n\n const props = schema.properties as Record<string, Record<string, unknown>> | undefined;\n if (!props) return value;\n const required = new Set(Array.isArray(schema.required) ? (schema.required as string[]) : []);\n const out: Record<string, unknown> = {};\n for (const [key, raw] of Object.entries(value as Record<string, unknown>)) {\n const propSchema = ownProp(props, key);\n if (!propSchema) {\n out[key] = raw;\n continue;\n }\n const pruned = pruneEmptyOptionals(raw, propSchema, allDefs);\n if (isEmptyAfterPruning(pruned) && !required.has(key)) continue;\n out[key] = pruned;\n }\n return out;\n}\n\n/**\n * Inflate all inputs from simplified inputs.json format to form format.\n * Used by onInputUpdate when receiving inputs.json changes from the sandbox.\n */\nexport function inflateAllInputs(\n simplifiedData: Record<string, unknown>,\n inputSchemas: Record<string, InputSchema>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [stuffName, value] of Object.entries(simplifiedData)) {\n const schema = ownProp(inputSchemas, stuffName);\n if (schema) {\n result[stuffName] = healStringWrappers(\n inflateInput(value, resolveConceptCode(schema)),\n schema.json_schema,\n );\n } else {\n // Unknown input - pass through unchanged\n result[stuffName] = value;\n }\n }\n return result;\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/core/date-format.ts
|
|
2
|
+
var FULL_DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
var ZERO_TIME_DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})[T ]00:00(?::00(?:\.0+)?)?(?:Z|z|[+-]\d{2}:?\d{2})?$/;
|
|
4
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|z|[+-]\d{2}:?\d{2})?$/;
|
|
5
|
+
function isRealCalendarDate(value) {
|
|
6
|
+
const match = FULL_DATE_RE.exec(value);
|
|
7
|
+
if (!match) return false;
|
|
8
|
+
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
9
|
+
if (month < 1 || month > 12) return false;
|
|
10
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
11
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
12
|
+
}
|
|
13
|
+
function asCalendarDate(value) {
|
|
14
|
+
if (isRealCalendarDate(value)) return value;
|
|
15
|
+
const zeroTime = ZERO_TIME_DATE_TIME_RE.exec(value);
|
|
16
|
+
if (zeroTime && isRealCalendarDate(zeroTime[1])) return zeroTime[1];
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function dayWithinDateTime(value) {
|
|
20
|
+
if (asCalendarDate(value) !== null) return null;
|
|
21
|
+
const match = DATE_TIME_RE.exec(value);
|
|
22
|
+
if (!match || !isRealCalendarDate(match[1])) return null;
|
|
23
|
+
return match[1];
|
|
24
|
+
}
|
|
25
|
+
function isAcceptableDate(value) {
|
|
26
|
+
return isRealCalendarDate(value);
|
|
27
|
+
}
|
|
28
|
+
function isAcceptableDateTime(value) {
|
|
29
|
+
if (isRealCalendarDate(value)) return true;
|
|
30
|
+
const match = DATE_TIME_RE.exec(value);
|
|
31
|
+
if (!match || !isRealCalendarDate(match[1])) return false;
|
|
32
|
+
const [hours, minutes, seconds] = [Number(match[2]), Number(match[3]), Number(match[4] ?? 0)];
|
|
33
|
+
return hours <= 23 && minutes <= 59 && seconds <= 59;
|
|
34
|
+
}
|
|
35
|
+
function toDateInputValue(value) {
|
|
36
|
+
if (typeof value !== "string") return "";
|
|
37
|
+
return asCalendarDate(value) ?? value.slice(0, 10);
|
|
38
|
+
}
|
|
39
|
+
function toStoredDateValue(day, datetime) {
|
|
40
|
+
if (!day) return void 0;
|
|
41
|
+
return datetime ? `${day}T00:00:00Z` : day;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { asCalendarDate, dayWithinDateTime, isAcceptableDate, isAcceptableDateTime, toDateInputValue, toStoredDateValue };
|
|
45
|
+
//# sourceMappingURL=chunk-GKV77RAS.js.map
|
|
46
|
+
//# sourceMappingURL=chunk-GKV77RAS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/date-format.ts"],"names":[],"mappings":";AAqCA,IAAM,YAAA,GAAe,2BAAA;AAOrB,IAAM,sBAAA,GACJ,0EAAA;AAGF,IAAM,YAAA,GACJ,0FAAA;AAGF,SAAS,mBAAmB,KAAA,EAAwB;AAClD,EAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,IAAA,CAAK,KAAK,CAAA;AACrC,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mBAAmB,KAAK,CAAA;AACjC;AAGO,SAAS,qBAAqB,KAAA,EAAwB;AAC3D,EAAA,IAAI,kBAAA,CAAmB,KAAK,CAAA,EAAG,OAAO,IAAA;AACtC,EAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,IAAA,CAAK,KAAK,CAAA;AACrC,EAAA,IAAI,CAAC,SAAS,CAAC,kBAAA,CAAmB,MAAM,CAAC,CAAE,GAAG,OAAO,KAAA;AACrD,EAAA,MAAM,CAAC,OAAO,OAAA,EAAS,OAAO,IAAI,CAAC,MAAA,CAAO,MAAM,CAAC,CAAC,GAAG,MAAA,CAAO,KAAA,CAAM,CAAC,CAAC,CAAA,EAAG,OAAO,KAAA,CAAM,CAAC,CAAA,IAAK,CAAC,CAAC,CAAA;AAC5F,EAAA,OAAO,KAAA,IAAS,EAAA,IAAM,OAAA,IAAW,EAAA,IAAM,OAAA,IAAW,EAAA;AACpD;AAGO,SAAS,iBAAiB,KAAA,EAAmC;AAClE,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,EAAA;AACtC,EAAA,OAAO,eAAe,KAAK,CAAA,IAAK,KAAA,CAAM,KAAA,CAAM,GAAG,EAAE,CAAA;AACnD;AAOO,SAAS,iBAAA,CAAkB,KAAa,QAAA,EAAuC;AACpF,EAAA,IAAI,CAAC,KAAK,OAAO,MAAA;AACjB,EAAA,OAAO,QAAA,GAAW,CAAA,EAAG,GAAG,CAAA,UAAA,CAAA,GAAe,GAAA;AACzC","file":"chunk-GKV77RAS.js","sourcesContent":["/**\n * Pure conversions between a stored date value and what a native `<input\n * type=\"date\">` shows, plus the leniency rules our schema validation uses.\n * Kept React-free so both the runner's `DateField` and the RJSF `DateWidget`\n * share one source of truth (and it's trivially unit-tested).\n *\n * Two schema shapes reach us, and they are NOT interchangeable:\n * - an MTHDS `type = \"date\"` structure field compiles to `format: date-time`,\n * so its value round-trips as a full RFC 3339 timestamp;\n * - `native.Date`'s own `date` field is a python `datetime.date`, i.e.\n * `format: date` - a bare `YYYY-MM-DD`.\n *\n * ## Why these rules exist\n *\n * The runtime (pydantic) is LENIENT in both directions, and our client used to\n * be stricter than the contract it was enforcing: `ajv`'s stock `format: \"date\"`\n * accepts a bare `YYYY-MM-DD` and nothing else, so a hand-written\n * `\"2026-07-06T00:00:00Z\"` in an `inputs.json` was rejected here even though\n * pydantic accepts it happily and coerces it to `date(2026, 7, 6)`. The run\n * never even reached the runner. These predicates mirror pydantic exactly\n * (measured, not assumed):\n *\n * format: date \"2026-07-06\" -> date(2026, 7, 6)\n * \"2026-07-06T00:00:00Z\" -> date(2026, 7, 6)\n * \"2026-07-06T00:00:00+02:00\" -> date(2026, 7, 6) (literal date, no UTC shift)\n * \"2026-07-06T15:40:00Z\" -> REJECTED \"should have zero time\"\n * format: date-time \"2026-07-06\" -> datetime(2026, 7, 6, 0, 0)\n * \"2026-07-06T00:00:00Z\" -> datetime(2026, 7, 6, 0, 0, tz)\n *\n * A midnight-padded timestamp is unambiguously \"just a day\", so take it. A real\n * time is data - refusing it is the point (`DateContentError`: \"no silent\n * midnight\"), because silently dropping 15:40 corrupts the value. And an\n * ambiguous `06/07/2026` is never accepted by anyone: 6 July or June 7 depends\n * on who's reading, and guessing wrong fails silently.\n */\n\n/** `YYYY-MM-DD`, no time. */\nconst FULL_DATE_RE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/**\n * A datetime whose clock reads exactly zero - optional seconds, optional\n * all-zero fraction, optional `Z`/offset. `00:00:01` and `00:00:00.001` do NOT\n * match: they carry a real time.\n */\nconst ZERO_TIME_DATE_TIME_RE =\n /^(\\d{4}-\\d{2}-\\d{2})[T ]00:00(?::00(?:\\.0+)?)?(?:Z|z|[+-]\\d{2}:?\\d{2})?$/;\n\n/** Any RFC 3339-ish datetime we can hand to the runtime as a date-time. */\nconst DATE_TIME_RE =\n /^(\\d{4}-\\d{2}-\\d{2})[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?(?:Z|z|[+-]\\d{2}:?\\d{2})?$/;\n\n/** Guards against `2026-02-30` - a well-formed string that isn't a real day. */\nfunction isRealCalendarDate(value: string): boolean {\n const match = FULL_DATE_RE.exec(value);\n if (!match) return false;\n const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];\n if (month < 1 || month > 12) return false;\n const date = new Date(Date.UTC(year, month - 1, day));\n return (\n date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day\n );\n}\n\n/**\n * The calendar day a value denotes, or `null` when it doesn't denote one.\n * Accepts a bare date or a midnight-padded timestamp; the day is taken\n * LITERALLY from the string (never shifted through a timezone), matching\n * pydantic - `2026-07-06T00:00:00+02:00` is 2026-07-06, not the 5th.\n */\nexport function asCalendarDate(value: string): string | null {\n if (isRealCalendarDate(value)) return value;\n const zeroTime = ZERO_TIME_DATE_TIME_RE.exec(value);\n if (zeroTime && isRealCalendarDate(zeroTime[1]!)) return zeroTime[1]!;\n return null;\n}\n\n/**\n * The calendar day inside a value that carries a REAL time - precisely the case\n * `asCalendarDate` refuses. `null` when the value isn't a timestamp at all, or\n * when it IS already an acceptable day (nothing to report).\n *\n * This exists to EXPLAIN, never to coerce. `2026-07-06T14:30:00+02:00` is\n * rejected for a `format: date` field, and the rejection is right (DT3, \"no\n * silent midnight\" - dropping 14:30 corrupts the value). But telling the user\n * \"pick a valid date\" while the picker shows them a perfectly good 06/07/2026\n * reads as a lie: `toDateInputValue` renders the day, the stored value carries\n * the time, and only one of those is what gets validated. Naming both the value\n * we hold and the day it would have to become is what makes the error legible.\n */\nexport function dayWithinDateTime(value: string): string | null {\n if (asCalendarDate(value) !== null) return null;\n const match = DATE_TIME_RE.exec(value);\n if (!match || !isRealCalendarDate(match[1]!)) return null;\n return match[1]!;\n}\n\n/**\n * What `format: \"date\"` accepts: a bare `YYYY-MM-DD`, and nothing else.\n *\n * DO NOT relax this to take a midnight-padded timestamp. `DateContent` in\n * pipelex carries a `mode=\"before\"` field validator (`_reject_lax_temporal`)\n * that deliberately CLOSES pydantic's lax coercion for exactly this case:\n *\n * \"A Date's `date` field takes a calendar date alone; a string carrying a\n * time (e.g. '2026-07-07T00:00:00') would drop it - put the time and offset\n * in `time` instead.\"\n *\n * That rule (DT3, \"no silent midnight\") is the concept's whole point, so a\n * lenient client here does not help anyone: it just forwards the value and the\n * runner answers with a 500 instead of the field saying so up front.\n *\n * The leniency belongs in `asCalendarDate` - normalize the pasted timestamp to\n * the day it denotes, then this passes. Accept-and-fix, not accept-and-forward.\n */\nexport function isAcceptableDate(value: string): boolean {\n return isRealCalendarDate(value);\n}\n\n/** What `format: \"date-time\"` should accept - a bare day is midnight. */\nexport function isAcceptableDateTime(value: string): boolean {\n if (isRealCalendarDate(value)) return true;\n const match = DATE_TIME_RE.exec(value);\n if (!match || !isRealCalendarDate(match[1]!)) return false;\n const [hours, minutes, seconds] = [Number(match[2]), Number(match[3]), Number(match[4] ?? 0)];\n return hours <= 23 && minutes <= 59 && seconds <= 59;\n}\n\n/** The `YYYY-MM-DD` a native date input shows, from any stored date/date-time. */\nexport function toDateInputValue(value: string | undefined): string {\n if (typeof value !== 'string') return '';\n return asCalendarDate(value) ?? value.slice(0, 10);\n}\n\n/**\n * The value to store for a picked day. A `date-time` field becomes midnight-UTC\n * (`2026-07-06T00:00:00Z`); a plain `date` field keeps the bare `YYYY-MM-DD`.\n * An empty day clears the value.\n */\nexport function toStoredDateValue(day: string, datetime: boolean): string | undefined {\n if (!day) return undefined;\n return datetime ? `${day}T00:00:00Z` : day;\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ownProp } from './chunk-V3OV2XQT.js';
|
|
2
|
+
|
|
3
|
+
// src/core/contracts.ts
|
|
4
|
+
function buildPipeRef(domain, pipeCode) {
|
|
5
|
+
return `${domain}.${pipeCode}`;
|
|
6
|
+
}
|
|
7
|
+
function getPipeIOContract(pipeIoContracts, domain, pipeCode) {
|
|
8
|
+
if (!pipeIoContracts || !pipeCode) return void 0;
|
|
9
|
+
if (domain) {
|
|
10
|
+
const byRef = ownProp(pipeIoContracts, buildPipeRef(domain, pipeCode));
|
|
11
|
+
if (byRef) return byRef;
|
|
12
|
+
}
|
|
13
|
+
return ownProp(pipeIoContracts, pipeCode);
|
|
14
|
+
}
|
|
15
|
+
function isOptionalInput(input) {
|
|
16
|
+
return input.presence === "optional";
|
|
17
|
+
}
|
|
18
|
+
function isPluralInput(input) {
|
|
19
|
+
return input.json_schema?.type === "array";
|
|
20
|
+
}
|
|
21
|
+
function isFixedCountInput(input) {
|
|
22
|
+
return input.multiplicity === "fixed";
|
|
23
|
+
}
|
|
24
|
+
function inputMustBeFilled(input) {
|
|
25
|
+
if (isOptionalInput(input)) return false;
|
|
26
|
+
return !isPluralInput(input) || isFixedCountInput(input);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { buildPipeRef, getPipeIOContract, inputMustBeFilled, isFixedCountInput, isOptionalInput, isPluralInput };
|
|
30
|
+
//# sourceMappingURL=chunk-HARYEWNG.js.map
|
|
31
|
+
//# sourceMappingURL=chunk-HARYEWNG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/contracts.ts"],"names":[],"mappings":";;;AAiFO,SAAS,YAAA,CAAa,QAAgB,QAAA,EAA0B;AACrE,EAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA;AAC9B;AAkBO,SAAS,iBAAA,CACd,eAAA,EACA,MAAA,EACA,QAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,eAAA,IAAmB,CAAC,QAAA,EAAU,OAAO,MAAA;AAC1C,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,MAAM,QAAQ,OAAA,CAAQ,eAAA,EAAiB,YAAA,CAAa,MAAA,EAAQ,QAAQ,CAAC,CAAA;AACrE,IAAA,IAAI,OAAO,OAAO,KAAA;AAAA,EACpB;AACA,EAAA,OAAO,OAAA,CAAQ,iBAAiB,QAAQ,CAAA;AAC1C;AAWO,SAAS,gBAAgB,KAAA,EAAmC;AACjE,EAAA,OAAO,MAAM,QAAA,KAAa,UAAA;AAC5B;AAcO,SAAS,cAAc,KAAA,EAAmC;AAC/D,EAAA,OAAQ,KAAA,CAAM,aAAgD,IAAA,KAAS,OAAA;AACzE;AASO,SAAS,kBAAkB,KAAA,EAAmC;AACnE,EAAA,OAAO,MAAM,YAAA,KAAiB,OAAA;AAChC;AAqBO,SAAS,kBAAkB,KAAA,EAAmC;AACnE,EAAA,IAAI,eAAA,CAAgB,KAAK,CAAA,EAAG,OAAO,KAAA;AACnC,EAAA,OAAO,CAAC,aAAA,CAAc,KAAK,CAAA,IAAK,kBAAkB,KAAK,CAAA;AACzD","file":"chunk-HARYEWNG.js","sourcesContent":["/**\n * The typed `pipe_io_contracts` mirror and its gating predicates.\n *\n * Mirrors pipelex's `PipeIOContract` (pipelex/pipeline/pipe_io_contracts.py).\n * The SDK deliberately keeps `pipe_io_contracts` opaque, so the kernel is the\n * canonical TS home for this shape until the D-track specs it.\n *\n * The map itself is keyed by namespaced pipe ref (`<domain>.<pipe_code>`),\n * NOT bare pipe code - use `getPipeIOContract` to look entries up by the bare\n * codes the UI tracks.\n */\n\nimport { ownProp } from './own-property';\n\n/**\n * The authored presence marker on an input slot, verbatim.\n *\n * - `plain` - no marker: the caller must supply the input.\n * - `optional` (`?`) - the caller may omit it and the pipe handles the absence\n * itself.\n * - `force` (`!`) - a use-site assertion that the value IS present. It must be\n * supplied, exactly like `plain`; the distinction is the authored assertion,\n * which lint and graph surfaces read and a form does not.\n */\nexport type InputPresence = 'plain' | 'optional' | 'force';\n\n/**\n * How many items a slot carries.\n *\n * - `single` - one item. `Concept[1]` is single too: no list framing.\n * - `variable` (`Concept[]`) - a list of any length, the empty list included.\n * - `fixed` (`Concept[N]`, N > 1) - a list of exactly `item_count` items.\n */\nexport type IOMultiplicity = 'single' | 'variable' | 'fixed';\n\nexport interface PipeInputContract {\n concept_ref: string;\n /** The declared presence marker - see `InputPresence`. */\n presence: InputPresence;\n /** The declared multiplicity - see `IOMultiplicity`. */\n multiplicity: IOMultiplicity;\n /**\n * The exact item count, non-null exactly when `multiplicity` is `fixed`. The\n * slot is always on the wire, `null` off the fixed arm.\n */\n item_count: number | null;\n /**\n * The input's JSON Schema. A plural slot (`variable` or `fixed`) is an array\n * wrapper around the item schema, and a `fixed` one additionally carries\n * `minItems` / `maxItems` set to `item_count` - which is what makes the gate's\n * ajv pass enforce the declared count without the kernel restating it.\n */\n json_schema: Record<string, unknown>;\n}\n\nexport interface PipeOutputContract {\n concept_ref: string;\n multiplicity: IOMultiplicity;\n /** As on the input: non-null exactly on the `fixed` arm, always on the wire. */\n item_count: number | null;\n /**\n * `true` when the output is declared optional (`?`) - the pipe may resolve it\n * as a recorded absence instead of a value.\n *\n * Deliberately still a boolean while the INPUT side carries three-valued\n * `presence`: output presence is genuinely two-valued, because `!` is\n * rejected on an output. The asymmetry is the wire's, not ours.\n */\n optional: boolean;\n}\n\nexport interface PipeIOContract {\n inputs: Record<string, PipeInputContract>;\n output: PipeOutputContract;\n}\n\n/** The `pipe_io_contracts` map: namespaced `pipe_ref` → IO contract. */\nexport type PipeIOContracts = Record<string, PipeIOContract>;\n\n/** Namespaced pipe ref (`<domain>.<pipe_code>`) - the identity convention the\n * validate artifacts key on. */\nexport function buildPipeRef(domain: string, pipeCode: string): string {\n return `${domain}.${pipeCode}`;\n}\n\n/**\n * Look up a pipe's IO contract by pipe code, tolerant of both key conventions.\n *\n * The map may be keyed by namespaced `pipe_ref` (`<domain>.<code>`, the\n * canonical convention) OR by bare pipe code - the current hosted `/validate`\n * keys `pipe_structures` by bare code, and methods persisted before the\n * pipe_ref re-keying also carry bare-code keys. Try the namespaced ref first\n * (when the caller supplies a domain), then fall back to the bare code.\n * Returns `undefined` (never crashes) when neither matches.\n *\n * Both lookups read OWN properties only. A bare index returned the inherited\n * `Object` constructor for a pipe code named `constructor` (or `toString`, …) -\n * a truthy non-contract that sailed straight through the `if (!contract)` guard\n * hosts are shown writing, so a pipe that does not exist rendered as one taking\n * no inputs instead of reaching the host's not-found path. See `ownProp`.\n */\nexport function getPipeIOContract(\n pipeIoContracts: PipeIOContracts | null | undefined,\n domain: string | null | undefined,\n pipeCode: string | null | undefined,\n): PipeIOContract | undefined {\n if (!pipeIoContracts || !pipeCode) return undefined;\n if (domain) {\n const byRef = ownProp(pipeIoContracts, buildPipeRef(domain, pipeCode));\n if (byRef) return byRef;\n }\n return ownProp(pipeIoContracts, pipeCode);\n}\n\n/**\n * True when the method declared the input omittable (`?`).\n *\n * The ONE reader of `presence` in the package: everything that asks \"may this\n * be absent?\" - the descriptor's `required`, the gate's `required` list, the\n * payload builders that omit an unfilled input - goes through here, so a\n * marker the wire adds later cannot mean one thing on one surface and another\n * elsewhere. `force` (`!`) reads as NOT optional, like `plain`.\n */\nexport function isOptionalInput(input: PipeInputContract): boolean {\n return input.presence === 'optional';\n}\n\n/**\n * True when the input carries a plural concept (`Image[]`, `Image[3]`): its\n * JSON Schema is an array wrapper.\n *\n * Deliberately a SCHEMA test rather than a read of the declared `multiplicity`,\n * even though the wire now states both. The schema is what `buildRunFields`\n * maps and therefore what the user is shown; a predicate reading the other\n * field could disagree with the rendered control, which is the exact failure\n * mode `mustBeFilled` (readiness.ts) exists to prevent. The two agree by\n * construction upstream - pipelex wraps the schema in an array exactly when it\n * reports `variable` or `fixed`.\n */\nexport function isPluralInput(input: PipeInputContract): boolean {\n return (input.json_schema as { type?: unknown } | undefined)?.type === 'array';\n}\n\n/**\n * True when the slot declares an EXACT number of items (`Concept[N]`), whose\n * count is `item_count`.\n *\n * The distinction that matters to the gate: a variable list can legitimately be\n * empty, a fixed one cannot.\n */\nexport function isFixedCountInput(input: PipeInputContract): boolean {\n return input.multiplicity === 'fixed';\n}\n\n/**\n * True when the user MUST put a value in before a run can start.\n *\n * Two declarations relieve an input of that duty, for different reasons:\n * - **optional (`?`)** - the method itself states the caller may omit it;\n * - **variable-plural (`[]`)** - the empty list is a legitimate value and the\n * language cannot declare \"at least one\", so gating on it would invent a\n * constraint the method never made.\n *\n * Everything else gates: `plain`, `force` (`!`), and a **fixed-count** list\n * (`[N]`), which is a list whose empty form the method has explicitly ruled out.\n * This is the derivation the input-form descriptor spec states for `gating`.\n *\n * Emptiness is all this predicate answers for - WHETHER a slot gates, never how\n * much it needs. A fixed-count list that holds fewer items than it declares\n * gates here and is refused by `fieldFilled`, which reads the declared count off\n * the descriptor's `itemCount`, and by the gate's ajv pass on the schema's\n * `minItems`. All three read the one number the method stated.\n */\nexport function inputMustBeFilled(input: PipeInputContract): boolean {\n if (isOptionalInput(input)) return false;\n return !isPluralInput(input) || isFixedCountInput(input);\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { flattenAnyOf, hoistDefsToRoot } from './chunk-O4O3QNVC.js';
|
|
2
|
+
|
|
3
|
+
// src/core/normalize-schema.ts
|
|
4
|
+
function normalizeSchemaForRjsf(schema) {
|
|
5
|
+
let normalized = flattenAnyOf(schema);
|
|
6
|
+
if (normalized.properties && typeof normalized.properties === "object") {
|
|
7
|
+
const props = normalized.properties;
|
|
8
|
+
const normalizedProps = {};
|
|
9
|
+
for (const [key, value] of Object.entries(props)) {
|
|
10
|
+
normalizedProps[key] = value && typeof value === "object" ? normalizeSchemaForRjsf(value) : value;
|
|
11
|
+
}
|
|
12
|
+
normalized = { ...normalized, properties: normalizedProps };
|
|
13
|
+
}
|
|
14
|
+
if (normalized.items && typeof normalized.items === "object" && !Array.isArray(normalized.items)) {
|
|
15
|
+
normalized = {
|
|
16
|
+
...normalized,
|
|
17
|
+
items: normalizeSchemaForRjsf(normalized.items)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(normalized.anyOf)) {
|
|
21
|
+
normalized = {
|
|
22
|
+
...normalized,
|
|
23
|
+
anyOf: normalized.anyOf.map(
|
|
24
|
+
(branch) => typeof branch === "object" && branch !== null ? normalizeSchemaForRjsf(branch) : branch
|
|
25
|
+
)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (normalized.$defs && typeof normalized.$defs === "object" && !Array.isArray(normalized.$defs)) {
|
|
29
|
+
const defs = normalized.$defs;
|
|
30
|
+
const normalizedDefs = {};
|
|
31
|
+
for (const [key, value] of Object.entries(defs)) {
|
|
32
|
+
normalizedDefs[key] = value && typeof value === "object" ? normalizeSchemaForRjsf(value) : value;
|
|
33
|
+
}
|
|
34
|
+
normalized = { ...normalized, $defs: normalizedDefs };
|
|
35
|
+
}
|
|
36
|
+
return normalized;
|
|
37
|
+
}
|
|
38
|
+
function prepareSchemaForRjsf(schema) {
|
|
39
|
+
return normalizeSchemaForRjsf(hoistDefsToRoot(schema));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { normalizeSchemaForRjsf, prepareSchemaForRjsf };
|
|
43
|
+
//# sourceMappingURL=chunk-KFZ5MZOM.js.map
|
|
44
|
+
//# sourceMappingURL=chunk-KFZ5MZOM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/normalize-schema.ts"],"names":[],"mappings":";;;AAsBO,SAAS,uBAAuB,MAAA,EAA0D;AAE/F,EAAA,IAAI,UAAA,GAAa,aAAa,MAAM,CAAA;AAGpC,EAAA,IAAI,UAAA,CAAW,UAAA,IAAc,OAAO,UAAA,CAAW,eAAe,QAAA,EAAU;AACtE,IAAA,MAAM,QAAQ,UAAA,CAAW,UAAA;AACzB,IAAA,MAAM,kBAA2C,EAAC;AAClD,IAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,MAAA,eAAA,CAAgB,GAAG,IACjB,KAAA,IAAS,OAAO,UAAU,QAAA,GACtB,sBAAA,CAAuB,KAAgC,CAAA,GACvD,KAAA;AAAA,IACR;AACA,IAAA,UAAA,GAAa,EAAE,GAAG,UAAA,EAAY,UAAA,EAAY,eAAA,EAAgB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C,CAAA;AACvD","file":"chunk-KFZ5MZOM.js","sourcesContent":["/**\n * Normalizes a JSON Schema for RJSF compatibility.\n *\n * Pydantic v2 generates `anyOf: [{type: \"string\"}, {type: \"null\"}]` for optional\n * fields (`str | None`). RJSF renders this as a dropdown selector asking the user\n * to pick a sub-schema, which is terrible UX. The normalizer flattens those\n * patterns on every node (see `flattenAnyOf` in `schema-utils.ts` for the exact\n * rules) and hoists nested `$defs` to the root so composed sub-schemas keep\n * their refs resolvable.\n *\n * The collapse and hoist engines live in `schema-utils.ts` - the\n * consolidated home for the kernel's JSON-Schema plumbing; this module owns the\n * recursive application over a whole schema tree.\n */\nimport { flattenAnyOf, hoistDefsToRoot } from './schema-utils';\n\nexport { hoistDefsToRoot };\n\n/**\n * Recursively normalize a JSON Schema for RJSF.\n * Walks the entire schema tree and flattens anyOf patterns on every node.\n */\nexport function normalizeSchemaForRjsf(schema: Record<string, unknown>): Record<string, unknown> {\n // Flatten anyOf at this level\n let normalized = flattenAnyOf(schema);\n\n // Recurse into properties\n if (normalized.properties && typeof normalized.properties === 'object') {\n const props = normalized.properties as Record<string, unknown>;\n const normalizedProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n normalizedProps[key] =\n value && typeof value === 'object'\n ? normalizeSchemaForRjsf(value as Record<string, unknown>)\n : value;\n }\n normalized = { ...normalized, properties: normalizedProps };\n }\n\n // Recurse into items (array schemas)\n if (\n normalized.items &&\n typeof normalized.items === 'object' &&\n !Array.isArray(normalized.items)\n ) {\n normalized = {\n ...normalized,\n items: normalizeSchemaForRjsf(normalized.items as Record<string, unknown>),\n };\n }\n\n // Recurse into anyOf branches that weren't flattened (complex unions)\n if (Array.isArray(normalized.anyOf)) {\n normalized = {\n ...normalized,\n anyOf: (normalized.anyOf as Record<string, unknown>[]).map((branch) =>\n typeof branch === 'object' && branch !== null\n ? normalizeSchemaForRjsf(branch as Record<string, unknown>)\n : branch,\n ),\n };\n }\n\n // Recurse into $defs so nested definitions (e.g. ImageSize) also get anyOf normalized\n if (\n normalized.$defs &&\n typeof normalized.$defs === 'object' &&\n !Array.isArray(normalized.$defs)\n ) {\n const defs = normalized.$defs as Record<string, unknown>;\n const normalizedDefs: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(defs)) {\n normalizedDefs[key] =\n value && typeof value === 'object'\n ? normalizeSchemaForRjsf(value as Record<string, unknown>)\n : value;\n }\n normalized = { ...normalized, $defs: normalizedDefs };\n }\n\n return normalized;\n}\n\n/**\n * Prepare a schema for RJSF: hoist all nested `$defs` to the root, then normalize\n * anyOf patterns. Call this on any schema that composes multiple sub-schemas\n * (each of which may ship its own `$defs`).\n */\nexport function prepareSchemaForRjsf(schema: Record<string, unknown>): Record<string, unknown> {\n return normalizeSchemaForRjsf(hoistDefsToRoot(schema));\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/core/native-concepts.ts
|
|
2
|
+
function nativeSet(...names) {
|
|
3
|
+
return new Set(names.flatMap((n) => [n, `native.${n}`]));
|
|
4
|
+
}
|
|
5
|
+
var TEXT_CONCEPTS = nativeSet("Text");
|
|
6
|
+
var DATE_CONCEPTS = nativeSet("Date");
|
|
7
|
+
var HTML_CONCEPTS = nativeSet("HTML");
|
|
8
|
+
var DOCUMENT_CONCEPTS = nativeSet("Document");
|
|
9
|
+
var PAGE_CONCEPTS = nativeSet("Page");
|
|
10
|
+
var IMAGE_CONCEPTS = nativeSet("Image");
|
|
11
|
+
var NUMBER_CONCEPTS = nativeSet("Number");
|
|
12
|
+
var YES_NO_CONCEPTS = nativeSet("YesNo");
|
|
13
|
+
var FIELD_TEXT_CONCEPTS = /* @__PURE__ */ new Set([
|
|
14
|
+
...TEXT_CONCEPTS,
|
|
15
|
+
...DATE_CONCEPTS
|
|
16
|
+
]);
|
|
17
|
+
var FIELD_DOCUMENT_CONCEPTS = /* @__PURE__ */ new Set([
|
|
18
|
+
...DOCUMENT_CONCEPTS,
|
|
19
|
+
...PAGE_CONCEPTS
|
|
20
|
+
]);
|
|
21
|
+
function isWireTextConcept(concept) {
|
|
22
|
+
return TEXT_CONCEPTS.has(concept);
|
|
23
|
+
}
|
|
24
|
+
function isWireDocumentLikeConcept(concept) {
|
|
25
|
+
return DOCUMENT_CONCEPTS.has(concept) || IMAGE_CONCEPTS.has(concept) || PAGE_CONCEPTS.has(concept);
|
|
26
|
+
}
|
|
27
|
+
var TEXT_WRAPPER_CONCEPTS = /* @__PURE__ */ new Set([
|
|
28
|
+
...TEXT_CONCEPTS,
|
|
29
|
+
...DATE_CONCEPTS,
|
|
30
|
+
...HTML_CONCEPTS
|
|
31
|
+
]);
|
|
32
|
+
function splitListConcept(conceptRef) {
|
|
33
|
+
if (!conceptRef) return { isList: false };
|
|
34
|
+
if (conceptRef.endsWith("[]")) return { base: conceptRef.slice(0, -2), isList: true };
|
|
35
|
+
return { base: conceptRef, isList: false };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { DATE_CONCEPTS, DOCUMENT_CONCEPTS, FIELD_DOCUMENT_CONCEPTS, FIELD_TEXT_CONCEPTS, HTML_CONCEPTS, IMAGE_CONCEPTS, NUMBER_CONCEPTS, PAGE_CONCEPTS, TEXT_CONCEPTS, TEXT_WRAPPER_CONCEPTS, YES_NO_CONCEPTS, isWireDocumentLikeConcept, isWireTextConcept, splitListConcept };
|
|
39
|
+
//# sourceMappingURL=chunk-NMT7BRLO.js.map
|
|
40
|
+
//# sourceMappingURL=chunk-NMT7BRLO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/native-concepts.ts"],"names":[],"mappings":";AAqCA,SAAS,aAAa,KAAA,EAAsC;AAC1D,EAAA,OAAO,IAAI,GAAA,CAAI,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,KAAM,CAAC,CAAA,EAAG,CAAA,OAAA,EAAU,CAAC,CAAA,CAAE,CAAC,CAAC,CAAA;AACzD;AAEO,IAAM,aAAA,GAAgB,UAAU,MAAM;AACtC,I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n * view exported explicitly, because the three copies this consolidates had\n * DRIFTED and K1 preserved each path's observable behavior exactly (see\n * `concept-taxonomy-characterization.test.ts`).\n *\n * The sets below spell the codes MTHDS actually defines (the `native` domain of\n * the language spec). That is not pedantry: a set that named a concept the\n * language does not have is what broke `native.Number`, because the render path\n * knew the concept and the value path did not.\n *\n * The drift, recorded for M1 (where the server-derived descriptor retires this\n * module entirely):\n *\n * | concept | field mapper (render) | wire format (deflate/inflate) | value bridge (content wrapper) |\n * | ------- | ------------------------- | ----------------------------- | ------------------------------ |\n * | Text | text/prose | bare string | `{text}`, from `TextContent` |\n * | Number | number | `{concept, content}` | `{number}`, from `NumberContent` |\n * | YesNo | boolean | `{concept, content}` | `{yes_no}`, from `YesNoContent` |\n * | Date | text/prose (NOT a picker) | CUSTOM `{concept, content}` | `{text}` - WRONG, see below |\n * | Html | nested object | `{concept, content}` | - |\n * | Page | document | document-like (bare URL) | - |\n *\n * A `Date` input therefore ships as `{concept: \"native.Date\", content: {text}}`\n * today - consistent end-to-end, but not `DateContent {date, time}`. Changing\n * that is a wire-visible fix and belongs to M1, not here.\n *\n * `HTML_CONCEPTS` below spells the code `HTML`; the language spells it `Html`\n * (`NativeConceptCode.HTML = \"Html\"`), so the set matches nothing a real\n * contract carries and `native.Html` falls through to the generic object\n * dispatch - a nested card over `HtmlContent {inner_html, css_class}`, which\n * round-trips correctly. Correcting the spelling would route `native.Html` into\n * the prose-plus-`{text}` drift above and BREAK inputs that work today, so the\n * spelling is left alone deliberately and goes with the Date fix at M1.\n */\n\n/** Both spellings a concept ref uses: bare (`Text`) and namespaced (`native.Text`). */\nfunction nativeSet(...names: string[]): ReadonlySet<string> {\n return new Set(names.flatMap((n) => [n, `native.${n}`]));\n}\n\nexport const TEXT_CONCEPTS = nativeSet('Text');\nexport const DATE_CONCEPTS = nativeSet('Date');\n/** Deliberately the code the language does NOT use - see the header. */\nexport const HTML_CONCEPTS = nativeSet('HTML');\nexport const DOCUMENT_CONCEPTS = nativeSet('Document');\nexport const PAGE_CONCEPTS = nativeSet('Page');\nexport const IMAGE_CONCEPTS = nativeSet('Image');\nexport const NUMBER_CONCEPTS = nativeSet('Number');\nexport const YES_NO_CONCEPTS = nativeSet('YesNo');\n\n// ─── The field mapper's view (field-model.ts) ───────────────────────────────\n\n/** Concepts the mapper renders as text/prose - `Date` deliberately included\n * (a `native.Date` input renders as prose today, not as a date picker). */\nexport const FIELD_TEXT_CONCEPTS: ReadonlySet<string> = new Set([\n ...TEXT_CONCEPTS,\n ...DATE_CONCEPTS,\n]);\n\n/** Concepts the mapper renders as a document upload - `Page` folded in. */\nexport const FIELD_DOCUMENT_CONCEPTS: ReadonlySet<string> = new Set([\n ...DOCUMENT_CONCEPTS,\n ...PAGE_CONCEPTS,\n]);\n\n// ─── The wire format's view (input-format.ts) ───────────────────────────────\n\n/** True when the simplified wire form is a bare string (`{text} ↔ \"...\"`).\n * `Date` is NOT here: it travels through the custom-concept `{concept,\n * content}` branch (the drift the header records). */\nexport function isWireTextConcept(concept: string): boolean {\n return TEXT_CONCEPTS.has(concept);\n}\n\n/** True when the simplified wire form is a bare URL string. */\nexport function isWireDocumentLikeConcept(concept: string): boolean {\n return (\n DOCUMENT_CONCEPTS.has(concept) || IMAGE_CONCEPTS.has(concept) || PAGE_CONCEPTS.has(concept)\n );\n}\n\n// ─── The value bridge's view (run-values.ts) ────────────────────────────────\n\n/**\n * The FALLBACK text wrapper, for a text concept whose contract declares no\n * single-property content model to read the wrapper name off.\n *\n * The wrapper property is normally derived from the declared schema, in\n * `derive.ts`, and travels on the descriptor as `RunField.contentKey` - so the\n * value bridge wraps by name and holds no taxonomy of its own. This set is what\n * answers when that derivation finds nothing:\n *\n * - `native.Text` with a degenerate contract (a bare `{type: 'object'}`, or a\n * bare `{type: 'string'}`) still wraps as `{text}`, as it always has;\n * - `native.Date` declares `DateContent {date, time}` - two properties, so no\n * single wrapper - and this set is what keeps it wrapping as `{text}`. That\n * is the recorded drift, preserved on purpose until M1.\n */\nexport const TEXT_WRAPPER_CONCEPTS: ReadonlySet<string> = new Set([\n ...TEXT_CONCEPTS,\n ...DATE_CONCEPTS,\n ...HTML_CONCEPTS,\n]);\n\n// ─── List refs ──────────────────────────────────────────────────────────────\n\n/** A concept ref like `native.Document[]` → base `native.Document`, isList true. */\nexport function splitListConcept(conceptRef: string | undefined): {\n base?: string;\n isList: boolean;\n} {\n if (!conceptRef) return { isList: false };\n if (conceptRef.endsWith('[]')) return { base: conceptRef.slice(0, -2), isList: true };\n return { base: conceptRef, isList: false };\n}\n"]}
|