@pipelex/mthds-form 0.19.0 → 0.20.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.
@@ -208,6 +208,6 @@ function inflateAllInputs(simplifiedData, inputSchemas) {
208
208
  return result;
209
209
  }
210
210
 
211
- export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode };
212
- //# sourceMappingURL=chunk-HQMXXK5X.js.map
213
- //# sourceMappingURL=chunk-HQMXXK5X.js.map
211
+ export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, isWrappedForm, pruneEmptyOptionals, resolveConceptCode };
212
+ //# sourceMappingURL=chunk-E6BIXJ6C.js.map
213
+ //# sourceMappingURL=chunk-E6BIXJ6C.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/wire-format.ts"],"names":[],"mappings":";;;;;AAmCA,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;AAGA,IAAM,kBAAA,GAAqB,UAAU,MAAM,CAAA;AAG3C,IAAM,2BAAA,GAA8B,SAAA,CAAU,UAAA,EAAY,OAAA,EAAS,MAAM,CAAA;AAEzE,SAAS,cAAc,OAAA,EAA0B;AAC/C,EAAA,OAAO,kBAAA,CAAmB,IAAI,OAAO,CAAA;AACvC;AAEA,SAAS,sBAAsB,OAAA,EAA0B;AACvD,EAAA,OAAO,2BAAA,CAA4B,IAAI,OAAO,CAAA;AAChD;AAGA,SAAS,cAAc,WAAA,EAA+D;AACpF,EAAA,IAAI,WAAA,CAAY,QAAA,CAAS,IAAI,CAAA,EAAG,OAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,WAAA,EAAa,WAAA,CAAY,KAAA,CA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A;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-HQMXXK5X.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 { hasOwnProp, ownProp } from './own-property';\nimport { collectSchemaDefs, resolveSchemaIndirection, schemaTypeOf } from './schema-utils';\n\n// ─── The wire taxonomy ──────────────────────────────────────────────────────\n//\n// Which native concepts use a SIMPLIFIED wire form is a fact about the\n// runtime's input parser, not about rendering - so this module states it for\n// itself, and it is the one native-concept knowledge left in the package now\n// that the render taxonomy is gone (the field mapper reads the wire descriptor;\n// see docs/derivation-swap.md). `native.Date` and `native.Html` are absent on\n// purpose: both travel through the structured `{ concept, content }` branch,\n// which since the derivation swap carries their REAL content models\n// (`DateContent {date, time}`, `HtmlContent {inner_html, css_class}`) rather\n// than the historical `{text}` drift.\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\n/** Concepts whose simplified wire form is a bare string (`{text} ↔ \"...\"`). */\nconst WIRE_TEXT_CONCEPTS = nativeSet('Text');\n\n/** Concepts whose simplified wire form is a bare URL string. */\nconst WIRE_DOCUMENT_LIKE_CONCEPTS = nativeSet('Document', 'Image', 'Page');\n\nfunction isTextConcept(concept: string): boolean {\n return WIRE_TEXT_CONCEPTS.has(concept);\n}\n\nfunction isDocumentLikeConcept(concept: string): boolean {\n return WIRE_DOCUMENT_LIKE_CONCEPTS.has(concept);\n}\n\n/** A concept ref like `native.Document[]` → base `native.Document`, isList true. */\nfunction isListConcept(conceptCode: string): { isList: boolean; baseConcept: string } {\n if (conceptCode.endsWith('[]')) return { isList: true, baseConcept: conceptCode.slice(0, -2) };\n return { isList: false, baseConcept: conceptCode };\n}\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"]}
1
+ {"version":3,"sources":["../src/core/wire-format.ts"],"names":[],"mappings":";;;;;AAmCA,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;AAGA,IAAM,kBAAA,GAAqB,UAAU,MAAM,CAAA;AAG3C,IAAM,2BAAA,GAA8B,SAAA,CAAU,UAAA,EAAY,OAAA,EAAS,MAAM,CAAA;AAEzE,SAAS,cAAc,OAAA,EAA0B;AAC/C,EAAA,OAAO,kBAAA,CAAmB,IAAI,OAAO,CAAA;AACvC;AAEA,SAAS,sBAAsB,OAAA,EAA0B;AACvD,EAAA,OAAO,2BAAA,CAA4B,IAAI,OAAO,CAAA;AAChD;AAGA,SAAS,cAAc,WAAA,EAA+D;AACpF,EAAA,IAAI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AAS,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-E6BIXJ6C.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 { hasOwnProp, ownProp } from './own-property';\nimport { collectSchemaDefs, resolveSchemaIndirection, schemaTypeOf } from './schema-utils';\n\n// ─── The wire taxonomy ──────────────────────────────────────────────────────\n//\n// Which native concepts use a SIMPLIFIED wire form is a fact about the\n// runtime's input parser, not about rendering - so this module states it for\n// itself, and it is the one native-concept knowledge left in the package now\n// that the render taxonomy is gone (the field mapper reads the wire descriptor;\n// see docs/derivation-swap.md). `native.Date` and `native.Html` are absent on\n// purpose: both travel through the structured `{ concept, content }` branch,\n// which since the derivation swap carries their REAL content models\n// (`DateContent {date, time}`, `HtmlContent {inner_html, css_class}`) rather\n// than the historical `{text}` drift.\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\n/** Concepts whose simplified wire form is a bare string (`{text} ↔ \"...\"`). */\nconst WIRE_TEXT_CONCEPTS = nativeSet('Text');\n\n/** Concepts whose simplified wire form is a bare URL string. */\nconst WIRE_DOCUMENT_LIKE_CONCEPTS = nativeSet('Document', 'Image', 'Page');\n\nfunction isTextConcept(concept: string): boolean {\n return WIRE_TEXT_CONCEPTS.has(concept);\n}\n\nfunction isDocumentLikeConcept(concept: string): boolean {\n return WIRE_DOCUMENT_LIKE_CONCEPTS.has(concept);\n}\n\n/** A concept ref like `native.Document[]` → base `native.Document`, isList true. */\nfunction isListConcept(conceptCode: string): { isList: boolean; baseConcept: string } {\n if (conceptCode.endsWith('[]')) return { isList: true, baseConcept: conceptCode.slice(0, -2) };\n return { isList: false, baseConcept: conceptCode };\n}\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 */\nexport function 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,41 @@
1
+ // src/core/sources.ts
2
+ function sourceFileValue(file) {
3
+ return { url: file.url, filename: file.name };
4
+ }
5
+ function heldUrl(item) {
6
+ if (!item || typeof item !== "object") return void 0;
7
+ const url = item.url;
8
+ return typeof url === "string" && url !== "" ? url : void 0;
9
+ }
10
+ function heldUrls(items) {
11
+ return new Set(items.map(heldUrl).filter((url) => url !== void 0));
12
+ }
13
+ function addChosenFiles(held, chosen) {
14
+ const items = [...held ?? []];
15
+ const urls = heldUrls(items);
16
+ let free = 0;
17
+ for (const file of chosen) {
18
+ if (urls.has(file.url)) continue;
19
+ urls.add(file.url);
20
+ while (free < items.length && heldUrl(items[free]) !== void 0) free += 1;
21
+ if (free < items.length) items[free] = sourceFileValue(file);
22
+ else items.push(sourceFileValue(file));
23
+ free += 1;
24
+ }
25
+ return items;
26
+ }
27
+ function chosenFilesAdded(held, chosen) {
28
+ const urls = heldUrls(held ?? []);
29
+ const before = urls.size;
30
+ for (const file of chosen) urls.add(file.url);
31
+ return urls.size - before;
32
+ }
33
+ function roomForChosenFiles(held, maxItemCount) {
34
+ if (maxItemCount === void 0) return void 0;
35
+ const files = (held ?? []).filter((item) => heldUrl(item) !== void 0).length;
36
+ return Math.max(0, maxItemCount - files);
37
+ }
38
+
39
+ export { addChosenFiles, chosenFilesAdded, roomForChosenFiles, sourceFileValue };
40
+ //# sourceMappingURL=chunk-EQJBM3NS.js.map
41
+ //# sourceMappingURL=chunk-EQJBM3NS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/sources.ts"],"names":[],"mappings":";AA+IO,SAAS,gBAAgB,IAAA,EAAqD;AACnF,EAAA,OAAO,EAAE,GAAA,EAAK,IAAA,CAAK,GAAA,EAAK,QAAA,EAAU,KAAK,IAAA,EAAK;AAC9C;AAGA,SAAS,QAAQ,IAAA,EAAmC;AAClD,EAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,UAAU,OAAO,MAAA;AAC9C,EAAA,MAAM,MAAO,IAAA,CAA2B,GAAA;AACxC,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,KAAK,GAAA,GAAM,MAAA;AACvD;AAGA,SAAS,SAAS,KAAA,EAAwC;AACxD,EAAA,OAAO,IAAI,GAAA,CAAI,KAAA,CAAM,GAAA,CAAI,OAAO,CAAA,CAAE,MAAA,CAAO,CAAC,GAAA,KAAuB,GAAA,KAAQ,MAAS,CAAC,CAAA;AACrF;AAUO,SAAS,cAAA,CACd,MACA,MAAA,EACW;AACX,EAAA,MAAM,KAAA,GAAQ,CAAC,GAAI,IAAA,IAAQ,EAAG,CAAA;AAC9B,EAAA,MAAM,IAAA,GAAO,SAAS,KAAK,CAAA;AAC3B,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,KAAA,MAAW,QAAQ,MAAA,EAAQ;AACzB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,GAAG,CAAA,EAAG;AACxB,IAAA,IAAA,CAAK,GAAA,CAAI,KAAK,GAAG,CAAA;AACjB,IAAA,OAAO,IAAA,GAAO,MAAM,MAAA,IAAU,OAAA,CAAQ,MAAM,IAAI,CAAC,CAAA,KAAM,MAAA,EAAW,IAAA,IAAQ,CAAA;AAC1E,IAAA,IAAI,OAAO,KAAA,CAAM,MAAA,QAAc,IAAI,CAAA,GAAI,gBAAgB,IAAI,CAAA;AAAA,SACtD,KAAA,CAAM,IAAA,CAAK,eAAA,CAAgB,IAAI,CAAC,CAAA;AACrC,IAAA,IAAA,IAAQ,CAAA;AAAA,EACV;AACA,EAAA,OAAO,KAAA;AACT;AAaO,SAAS,gBAAA,CACd,MACA,MAAA,EACQ;AACR,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,IAAA,IAAQ,EAAE,CAAA;AAChC,EAAA,MAAM,SAAS,IAAA,CAAK,IAAA;AACpB,EAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,KAAK,GAAG,CAAA;AAC5C,EAAA,OAAO,KAAK,IAAA,GAAO,MAAA;AACrB;AAEO,SAAS,kBAAA,CACd,MACA,YAAA,EACoB;AACpB,EAAA,IAAI,YAAA,KAAiB,QAAW,OAAO,MAAA;AACvC,EAAA,MAAM,KAAA,GAAA,CAAS,IAAA,IAAQ,EAAC,EAAG,MAAA,CAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAI,CAAA,KAAM,MAAS,CAAA,CAAE,MAAA;AACzE,EAAA,OAAO,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,YAAA,GAAe,KAAK,CAAA;AACzC","file":"chunk-EQJBM3NS.js","sourcesContent":["/**\n * The two optional host seams beside the upload: a **file source**, which lets\n * a file field take a file the host already stores, and an **example source**,\n * which lets a whole form take a set of values someone saved for the method.\n *\n * The kernel states the shapes and applies the answers; the host answers. It\n * knows nothing of any platform's routes, records or permissions: a host maps\n * its own list onto these shapes, and a host that gives neither seam gets the\n * form it had before. The controls that use them are `./react`'s\n * (`FilePicker`, `FillWithExample`), and docs/sources.md is the contract.\n *\n * Shapes and pure functions only, so a host's server can import the types it\n * answers with, and the rules that write an answer into a value are tested in\n * node. No React, no fetch.\n */\n\n/** Whose files a file source lists: the person's own, or the whole team's. */\nexport type FileSourceScope = 'mine' | 'everyone';\n\n/** One page of a file source's list, as the picker asks for it. */\nexport interface FileSourceQuery {\n /** What the person searched for, trimmed; empty when they searched for nothing. */\n search: string;\n /** Whose files to list. */\n scope: FileSourceScope;\n /**\n * The MIME types the field accepts, after any narrowing a host applied\n * (`narrowFileFormats`), in the field's own order. The list must hold only\n * files of these types: the picker writes what is chosen straight into the\n * field, and a field that refuses a dropped file of another type must not\n * be handed one this way.\n */\n mediaTypes: readonly string[];\n /** Where to continue: absent for the first page, else the previous page's `nextCursor`. */\n cursor?: string;\n /** Aborted when the answer is no longer wanted: a newer search, a closed picker. */\n signal: AbortSignal;\n}\n\n/** One row of a file source's list: a file the host already stores. */\nexport interface SourceFile {\n /** The row's identity in the host's list, which a choice is kept by. */\n id: string;\n /**\n * The stored file's address, written into the field as its `url`, exactly as\n * an upload's result is. Several rows may share one address.\n */\n url: string;\n /** The file's name, shown on the row and written into the field as its `filename`. */\n name: string;\n /** The file's MIME type, which names its format on the row. */\n mediaType?: string;\n /** The file's size in bytes. */\n size?: number;\n /** How the file came to be. A `test` file is marked \"Test file\" at the head of its row's second line. */\n kind?: 'uploaded' | 'generated' | 'test';\n /** When the file was stored, as an ISO 8601 timestamp; the row says it as a date. */\n createdAt?: string;\n /**\n * Where the file came from, in the host's own words (\"Uploaded by Ana\",\n * \"Made by Invoice extraction\"), shown on the row's second line as it is.\n */\n origin?: string;\n}\n\n/** One page of a file source's answer. */\nexport interface FileSourcePage {\n /** The page's files, newest first. A page may be empty and still carry a cursor. */\n files: readonly SourceFile[];\n /** Where the next page starts, or nothing when this page is the last. */\n nextCursor?: string | null;\n}\n\n/**\n * Where a file field can take a file the host already stores. When a form has\n * one, every file field offers \"Choose from your team's files\", and a list of\n * files offers it for several at once.\n */\nexport interface FileSource {\n /** Lists one page of files for a query. Rejecting shows the failure with Try again. */\n list: (query: FileSourceQuery) => Promise<FileSourcePage>;\n /** Which of Mine and Everyone the picker opens on. */\n initialScope: FileSourceScope;\n}\n\n/** One example of a method: a name and the inputs a run of it sends. */\nexport interface FormExample {\n /** The example's identity in the host's list. */\n id: string;\n /** The example's name, shown on its row. */\n name: string;\n /**\n * The inputs as a run takes them: each input `{ concept, content }`, an\n * optional input left out, an empty plural input a bare `[]`. It is the\n * shape `apiInputsFromRunValues` produces, so a host saves an example from\n * `form.inputs` and hands it back as it is.\n */\n inputs: Readonly<Record<string, unknown>>;\n}\n\n/** One page of an example source's list. */\nexport interface ExampleSourceQuery {\n /** Where to continue: absent for the first page, else the previous page's `nextCursor`. */\n cursor?: string;\n /** Aborted when the answer is no longer wanted. */\n signal: AbortSignal;\n}\n\n/** One page of an example source's answer. */\nexport interface ExampleSourcePage {\n /** The page's examples, in the order the list shows them. */\n examples: readonly FormExample[];\n /** Where the next page starts, or nothing when this page is the last. */\n nextCursor?: string | null;\n}\n\n/**\n * Where a form can take a whole set of values. When a form has one, it offers\n * \"Fill with an example\". `rename` and `delete` are capabilities: each is\n * offered on a row's menu only when given, so a host gives them only to a\n * person allowed to change examples.\n */\nexport interface ExampleSource {\n /** Lists one page of the method's examples. Rejecting shows the failure with Try again. */\n list: (query: ExampleSourceQuery) => Promise<ExampleSourcePage>;\n /**\n * Renames an example. Resolving to the example as stored replaces the row;\n * resolving to nothing keeps the row under the new name.\n */\n rename?: (example: FormExample, name: string) => Promise<FormExample | void>;\n /** Deletes an example. Asked for only after the person confirmed it. */\n delete?: (example: FormExample) => Promise<void>;\n /**\n * Whether \"Fill with an example\" is left out while the method has no\n * example. `false` by default, when the empty list says how to make one.\n * A host sets it for a person who cannot save an example, to whom an empty\n * list has nothing to offer; the form then asks for the first page as it\n * mounts, to know whether to offer the control.\n */\n hideWhenEmpty?: boolean;\n}\n\n/** What a chosen file writes into its field: the same `{ url, filename }` an upload writes. */\nexport function sourceFileValue(file: SourceFile): { url: string; filename: string } {\n return { url: file.url, filename: file.name };\n}\n\n/** The `url` a list item holds, when it is a file value holding one. */\nfunction heldUrl(item: unknown): string | undefined {\n if (!item || typeof item !== 'object') return undefined;\n const url = (item as { url?: unknown }).url;\n return typeof url === 'string' && url !== '' ? url : undefined;\n}\n\n/** The addresses a list's items hold, each once. */\nfunction heldUrls(items: readonly unknown[]): Set<string> {\n return new Set(items.map(heldUrl).filter((url): url is string => url !== undefined));\n}\n\n/**\n * A list of files with the chosen files written into it, in the order they\n * were chosen: first into the rows that hold no file yet (a row the person\n * added and left empty), then as new rows after the last. A file whose address\n * the list already holds is not written again, and neither is a second choice\n * of one address: two rows of a source may name the same stored file. Returns\n * a new array and leaves `held` as it was.\n */\nexport function addChosenFiles(\n held: readonly unknown[] | undefined,\n chosen: readonly SourceFile[],\n): unknown[] {\n const items = [...(held ?? [])];\n const urls = heldUrls(items);\n let free = 0;\n for (const file of chosen) {\n if (urls.has(file.url)) continue;\n urls.add(file.url);\n while (free < items.length && heldUrl(items[free]) !== undefined) free += 1;\n if (free < items.length) items[free] = sourceFileValue(file);\n else items.push(sourceFileValue(file));\n free += 1;\n }\n return items;\n}\n\n/**\n * How many files a list may still take from a source: its bound less the files\n * it holds, since `addChosenFiles` writes into its empty rows before adding\n * any. `undefined` when the list has no bound.\n */\n/**\n * How many files `addChosenFiles` writes for `chosen` into `held`: the choices\n * whose address the list does not hold yet, each address once. This is what a\n * choice spends of `roomForChosenFiles`, so a held file chosen again, or a\n * second row naming a chosen file, takes no room.\n */\nexport function chosenFilesAdded(\n held: readonly unknown[] | undefined,\n chosen: readonly SourceFile[],\n): number {\n const urls = heldUrls(held ?? []);\n const before = urls.size;\n for (const file of chosen) urls.add(file.url);\n return urls.size - before;\n}\n\nexport function roomForChosenFiles(\n held: readonly unknown[] | undefined,\n maxItemCount: number | undefined,\n): number | undefined {\n if (maxItemCount === undefined) return undefined;\n const files = (held ?? []).filter((item) => heldUrl(item) !== undefined).length;\n return Math.max(0, maxItemCount - files);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { buildRunFields } from './chunk-ZB4RYUKV.js';
2
- import { inflateAllInputs, deflateAllInputs } from './chunk-HQMXXK5X.js';
2
+ import { inflateAllInputs, deflateAllInputs, isWrappedForm } from './chunk-E6BIXJ6C.js';
3
3
  import { isFilled, isOptionalStructure, optionalStructureOpen } from './chunk-XO5OENNF.js';
4
4
  import { isOptionalInput, isPluralInput } from './chunk-WYH56SOZ.js';
5
5
  import { ownProp } from './chunk-V3OV2XQT.js';
@@ -137,6 +137,18 @@ function apiInputsFromRunValues(values, fields, inputSchemas) {
137
137
  }
138
138
  return out;
139
139
  }
140
+ function runValuesFromInputs(inputs, fields) {
141
+ const out = {};
142
+ for (const field of fields) {
143
+ const entry = ownProp(inputs ?? {}, field.name);
144
+ const content = isWrappedForm(entry) ? entry.content : entry;
145
+ out[field.name] = fromRjsf(field, content);
146
+ }
147
+ return out;
148
+ }
149
+ function sameRunValues(a, b, fields) {
150
+ return JSON.stringify(rjsfDataFromRunValues(a, fields)) === JSON.stringify(rjsfDataFromRunValues(b, fields));
151
+ }
140
152
  function hasWorkingMemoryRoot(value) {
141
153
  return !!value && typeof value === "object" && "working_memory" in value && !!value.working_memory && typeof value.working_memory.root === "object";
142
154
  }
@@ -197,6 +209,6 @@ function setValueAtPath(root, path, value) {
197
209
  return { ...root, [head]: setValueAtPath(child ?? {}, rest, value) };
198
210
  }
199
211
 
200
- export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues };
201
- //# sourceMappingURL=chunk-MEXWXLR7.js.map
202
- //# sourceMappingURL=chunk-MEXWXLR7.js.map
212
+ export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues };
213
+ //# sourceMappingURL=chunk-ZX52CQJ4.js.map
214
+ //# sourceMappingURL=chunk-ZX52CQJ4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/values.ts"],"names":[],"mappings":";;;;;;;AA+CA,SAAS,WAAA,CAAY,OAAiB,KAAA,EAAyB;AAC7D,EAAA,OAAO,KAAA,CAAM,eAAe,MAAA,GAAY,KAAA,GAAQ,EAAE,CAAC,KAAA,CAAM,UAAU,GAAG,KAAA,EAAM;AAC9E;AAOA,SAAS,aAAA,CAAc,OAAiB,KAAA,EAAyB;AAC/D,EAAA,MAAM,MAAM,KAAA,CAAM,UAAA;AAClB,EAAA,IAAI,GAAA,KAAQ,UAAa,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AACjF,IAAA,OAAO,KAAA;AACT,EAAA,OAAO,OAAA,CAAQ,OAAkC,GAAG,CAAA;AACtD;AAGA,IAAM,gBAAA,GAAmB,CAAA;AAsBzB,SAAS,cAAA,CAAe,KAAA,EAAgB,KAAA,GAAQ,CAAA,EAAuB;AACrE,EAAA,IAAI,KAAA,IAAS,MAAM,OAAO,MAAA;AAC1B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,KAAA;AACtC,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,OAAO,UAAU,SAAA,EAAW,OAAO,OAAO,KAAK,CAAA;AAChF,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,IAAS,kBAAkB,OAAO,MAAA;AACnE,EAAA,MAAM,QAAA,GAAW,KAAA;AACjB,EAAA,IAAI,UA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EAAI;AAAA,EAChC;AACA,EAAA,OAAO,EAAE,GAAG,IAAA,EAAM,CAAC,IAAI,GAAG,cAAA,CAAgB,KAAA,IAAkB,EAAC,EAAG,IAAA,EAAM,KAAK,CAAA,EAAE;AAC/E","file":"chunk-ZX52CQJ4.js","sourcesContent":["/**\n * Bridges the `MethodRunner`'s field values to the rest of the host.\n *\n * The method-store keeps inputs in the *simplified* format and runs send the\n * *full* RJSF form shape - both already handled by `inflate/deflateAllInputs`.\n * The only gap is that a few field controls use a friendlier value than RJSF: a\n * scalar is the bare scalar where the full shape is the content model its\n * concept declares (`{ text }`, `{ number }`, `{ yes_no }`), and a file is\n * `{ url, filename }`. `fromRjsf`/`toRjsf` translate just those, so store\n * reads/writes and run payloads stay byte-for-byte compatible with the proven\n * playground path.\n *\n * Which property a scalar wraps into is NOT decided here - it arrives on the\n * descriptor as `contentKey`, derived from the contract by `buildRunFields`.\n *\n * Pure module - no React, unit-tested.\n */\nimport type { PipeInputFormDescriptor } from 'mthds/protocol';\n\nimport type { RunField } from './descriptor';\nimport { buildRunFields } from './derive';\nimport { ownProp } from './own-property';\nimport { isFilled, isOptionalStructure, optionalStructureOpen } from './readiness';\nimport { isOptionalInput, isPluralInput } from './contracts';\nimport { deflateAllInputs, inflateAllInputs, isWrappedForm } from './wire-format';\nimport type { PipeIOContract, PipeInputContract } from './contracts';\n\ntype Dict = Record<string, unknown>;\ntype InputSchemas = Record<string, PipeInputContract>;\n\n// ─── RJSF full shape ↔ RunField value ──────────────────────────────────────\n\n/**\n * Put a scalar back inside the content model its concept declares:\n * `\"hi\"` → `{ text: \"hi\" }`, `2` → `{ number: 2 }`, `false` → `{ yes_no: false }`.\n *\n * The property name comes from the DESCRIPTOR (`contentKey`, stamped by\n * `buildRunFields` - the only reader of JSON Schema). This module holds no\n * taxonomy of its own, which is the point: the version that did held a list of\n * concepts that wrap, `native.Number` was missing from it, and every run\n * carrying a number was rejected by the gate against `NumberContent`.\n *\n * A field with no `contentKey` keeps its value plain. That is not an oversight\n * either - a child property of a structured concept, or a custom concept whose\n * schema is a bare string, IS its value, and wrapping it double-nests it\n * (`{ text: { text } }`) into a payload no schema accepts.\n */\nfunction wrapContent(field: RunField, value: unknown): unknown {\n return field.contentKey === undefined ? value : { [field.contentKey]: value };\n}\n\n/**\n * The inverse. A value that is already bare passes through untouched: persisted\n * `inputData` predates the number and yes/no wrappers, and an inputs.json\n * written by hand or by an agent says `2`, not `{number: 2}`.\n */\nfunction unwrapContent(field: RunField, value: unknown): unknown {\n const key = field.contentKey;\n if (key === undefined || !value || typeof value !== 'object' || Array.isArray(value))\n return value;\n return ownProp(value as Record<string, unknown>, key);\n}\n\n/** How deep a nested `{ text: … }` / `{ content: … }` chain we bother unwrapping. */\nconst MAX_UNWRAP_DEPTH = 8;\n\n/**\n * Pull a plain string out of whatever the store hands a text field.\n *\n * Persisted `inputData` carries historical corruptions - a double-wrapped\n * `{ text: { text } }`, a `{ concept, content }` envelope that was never\n * deflated - and the old fallback ran `String()` over them, which renders the\n * literal `\"[object Object]\"` into the textarea. That is worse than showing\n * nothing: it looks exactly like content the user typed, and one keystroke\n * later it is content the user typed. So unwrap the envelopes we know, and give\n * up with `undefined` (an empty field) rather than displaying garbage.\n *\n * Genuine primitives still stringify - a number or a boolean in a text slot is\n * a value, not a wrapper.\n *\n * The envelope names here are the HISTORICAL corruptions, not the wrapper key:\n * the declared wrapper is stripped by `unwrapContent` first, off the field's\n * `contentKey`, exactly as the number and boolean paths do. A text wrapper\n * whose property is not literally `text` would otherwise read back empty - and\n * one save later, BE empty.\n */\nfunction textFromStored(value: unknown, depth = 0): string | undefined {\n if (value == null) return undefined;\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (typeof value !== 'object' || depth >= MAX_UNWRAP_DEPTH) return undefined;\n const envelope = value as { text?: unknown; content?: unknown };\n if ('text' in envelope) return textFromStored(envelope.text, depth + 1);\n if ('content' in envelope) return textFromStored(envelope.content, depth + 1);\n return undefined;\n}\n\n/** RJSF full form value → the runner's field value. */\nfunction fromRjsf(field: RunField, value: unknown): unknown {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return textFromStored(unwrapContent(field, value));\n case 'number': {\n // The control holds `number | undefined`. A numeric STRING is tolerated\n // because that is what a hand-written inputs.json tends to carry; anything\n // else empties the field rather than feeding NaN to a number input.\n const raw = unwrapContent(field, value);\n if (typeof raw === 'number') return Number.isFinite(raw) ? raw : undefined;\n if (typeof raw === 'string' && raw.trim() !== '') {\n const parsed = Number(raw);\n return Number.isFinite(parsed) ? parsed : undefined;\n }\n return undefined;\n }\n case 'boolean': {\n // Strictly a real boolean, deliberately: pipelex declares `YesNoContent.\n // yes_no` with `strict=True` precisely to refuse \"yes\"/1/\"true\", and\n // coercing here would smuggle back in what the runtime closed off.\n const raw = unwrapContent(field, value);\n return typeof raw === 'boolean' ? raw : undefined;\n }\n case 'unknown':\n // The escape hatch is a raw-JSON textarea, so a structured value belongs\n // there as JSON - `String(value)` would have shown \"[object Object]\" and\n // thrown the actual value away.\n if (typeof value === 'string') return value;\n if (value == null) return undefined;\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return undefined;\n }\n }\n return String(value);\n case 'document':\n case 'image': {\n if (value && typeof value === 'object') {\n const o = value as { url?: unknown; filename?: unknown };\n return o.url\n ? { url: String(o.url), filename: o.filename as string | undefined }\n : undefined;\n }\n return typeof value === 'string' && value ? { url: value } : undefined;\n }\n case 'object': {\n // An optional structure the store holds no object for - absent, or the\n // `null` a stored run writes for a structure it went without - stays\n // CLOSED. Materializing a shell of `undefined` children here reopened it:\n // `optionalStructureOpen` reads any plain object as open, so a run reloaded\n // from the store showed every structure it had left out as opened and\n // blank. A required structure has no closed state, and keeps its shell.\n if (isOptionalStructure(field) && !optionalStructureOpen(value)) return undefined;\n const obj = (value && typeof value === 'object' ? value : {}) as Dict;\n const out: Dict = {};\n for (const child of field.fields) out[child.name] = fromRjsf(child, ownProp(obj, child.name));\n return out;\n }\n case 'list': {\n const arr = Array.isArray(value) ? value : [];\n return arr.map((item) => fromRjsf(field.item, item));\n }\n default:\n return value;\n }\n}\n\n/**\n * The runner's field value → RJSF full form value (what runs/store expect).\n *\n * `collapseEmpty` is what a SINGULAR slot does and a LIST ITEM must not: an\n * untouched structure in a singular slot is absent, but an item exists only\n * because the user added it, so adding IS the touch. Only the structure case\n * reads the flag.\n */\nfunction toRjsf(field: RunField, value: unknown, collapseEmpty = true): unknown {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return wrapContent(field, typeof value === 'string' ? value : '');\n case 'number':\n // An untouched number stays ABSENT rather than becoming an empty wrapper.\n // The gate then does the right thing on both counts: it prunes an absent\n // optional input, and it reports a required one as missing by name -\n // where `{number: undefined}` would read as a malformed value instead.\n return typeof value === 'number' && Number.isFinite(value)\n ? wrapContent(field, value)\n : undefined;\n case 'boolean':\n // `false` is a value, not an absence - hence the type test rather than a\n // truthiness one.\n return typeof value === 'boolean' ? wrapContent(field, value) : undefined;\n case 'unknown':\n return typeof value === 'string' ? value : '';\n case 'document':\n case 'image': {\n const url = value && typeof value === 'object' ? (value as { url?: unknown }).url : value;\n const filename =\n value && typeof value === 'object' ? (value as { filename?: unknown }).filename : undefined;\n return { url: url ? String(url) : '', ...(filename ? { filename } : {}) };\n }\n case 'object': {\n const obj = (value && typeof value === 'object' ? value : {}) as Dict;\n const out: Dict = {};\n for (const child of field.fields) out[child.name] = toRjsf(child, ownProp(obj, child.name));\n // A structure nobody put anything into stays ABSENT, exactly as an\n // untouched number does above - it does NOT become a shell of empty\n // children. Materializing that shell made an OPTIONAL structured input\n // unrunnable whenever its concept declared a required child: readiness\n // ignored the input (correctly - the method said it may be omitted), Run\n // lit up, and the gate then judged an object the kernel had invented\n // against the concept's full schema and rejected the run for a child the\n // user was never asked to fill.\n //\n // Emptiness is `isFilled`, the SAME predicate readiness and the wire\n // payload use, so the three cannot disagree about whether this input is\n // there. Which also says what the touch is NOT: opening the optional\n // disclosure is local view state the value never sees, so a section\n // opened and left blank collapses exactly like one never opened. What\n // keeps a structure is a VALUE in it - and then the whole shell survives,\n // empty children and all, so a required child left blank still fails, and\n // loudly.\n return collapseEmpty && !isFilled(out) ? undefined : out;\n }\n case 'list': {\n const arr = Array.isArray(value) ? value : [];\n // An item is NEVER absent: it is in the array because the user added it,\n // and `ListField`'s \"Add\" seeds an object item with `{}`. Letting it\n // collapse the way an untouched singular slot does put `undefined` in the\n // array, which ajv rejects as `must be object` - blocking an empty item\n // the item schema allowed, and turning a required-child complaint into a\n // type error that names nothing the user can act on.\n return arr.map((item) => toRjsf(field.item, item, false));\n }\n default:\n return value;\n }\n}\n\n// ─── Store ↔ RunField values ──────────────────────────────────────────────\n\n/** Seed the runner's form values from the method-store's simplified inputData. */\nexport function runValuesFromStore(\n inputData: Dict | undefined,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Dict {\n const full = inflateAllInputs(inputData ?? {}, inputSchemas);\n const out: Dict = {};\n for (const field of fields) out[field.name] = fromRjsf(field, ownProp(full, field.name));\n return out;\n}\n\n/**\n * The runner's form values in **schema shape** - the same shape an RJSF panel\n * holds, and therefore the shape `gate.ts` validates against the per-input\n * JSON Schemas.\n *\n * Deliberately stops short of `deflateAllInputs`: deflation is the STORE's\n * compact form, and ajv validates the full one.\n */\nexport function rjsfDataFromRunValues(values: Dict, fields: RunField[]): Dict {\n const full: Dict = {};\n for (const field of fields) full[field.name] = toRjsf(field, ownProp(values, field.name));\n return full;\n}\n\n/** Convert the runner's form values back to the store's simplified inputData. */\nexport function storeInputDataFromRunValues(\n values: Dict,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Dict {\n return deflateAllInputs(rjsfDataFromRunValues(values, fields), inputSchemas);\n}\n\n/**\n * Build the `{ concept, content }` map a run expects from the form values.\n *\n * The two ways a method says \"this may be nothing\" land differently on the wire,\n * and both matter:\n * - an **optional (`?`)** input left blank is OMITTED, so the runtime records a\n * real absence the method can branch on - sending `{ text: \"\" }` would look\n * like the caller supplied an empty string;\n * - a **plural (`[]`)** input keeps its key, because a plural slot is never\n * absent - its empty form IS the empty list, and the runtime requires the key.\n * When that list is EMPTY it is sent BARE, without the envelope: the envelope\n * is the runtime's \"explicit form\", which bypasses the top-down shaper and\n * hands the value to the bottom-up factory, and that factory types a list from\n * its first item - so an empty list there raises \"Cannot create Stuff from\n * empty list in content\". The bare form keeps the shaper, which reads the\n * DECLARED concept and builds the empty list correctly. (pipelex/#1096 makes\n * the envelope agree; the bare form runs today and stays correct after.)\n */\nexport function apiInputsFromRunValues(\n values: Dict,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const field of fields) {\n const schema = ownProp(inputSchemas, field.name);\n if (!schema) continue;\n const value = ownProp(values, field.name);\n if (isOptionalInput(schema) && !isFilled(value)) continue;\n if (isPluralInput(schema) && !isFilled(value)) {\n out[field.name] = [];\n continue;\n }\n out[field.name] = { concept: schema.concept_ref, content: toRjsf(field, value) };\n }\n return out;\n}\n\n/**\n * The form values a set of run inputs stands for: the inverse of\n * `apiInputsFromRunValues`, for inputs saved from a form (an example) and\n * handed back to one.\n *\n * Each input is read as a run sends it, `{ concept, content }`, or as its bare\n * content (the empty plural `[]`), and its content is turned back into the\n * control's own shape. Only an object naming its concept is read as that\n * envelope: a structure sent bare may well have a property called `content`. An input the inputs do not hold is left empty, and an\n * optional structure they do not hold stays closed: the inputs are the whole\n * run, so an input they left out was left out of the run too. An input no\n * field takes is ignored.\n */\nexport function runValuesFromInputs(inputs: Readonly<Dict> | undefined, fields: RunField[]): Dict {\n const out: Dict = {};\n for (const field of fields) {\n const entry = ownProp(inputs ?? {}, field.name);\n const content = isWrappedForm(entry) ? entry.content : entry;\n out[field.name] = fromRjsf(field, content);\n }\n return out;\n}\n\n/**\n * Whether two sets of form values send the same run.\n *\n * Compared in the shape a run takes, so the differences a run cannot see do\n * not count: a text typed and then erased is the blank it started as, and an\n * optional structure opened and left empty is the closed one it was. What\n * \"Fill with an example\" asks before replacing is the work a person did, and\n * a value that sends nothing is no work to lose.\n */\nexport function sameRunValues(a: Dict, b: Dict, fields: RunField[]): boolean {\n return (\n JSON.stringify(rjsfDataFromRunValues(a, fields)) ===\n JSON.stringify(rjsfDataFromRunValues(b, fields))\n );\n}\n\n// ─── Pipe output → result entries ────────────────────────────────────────────\n\n/** One named output pulled out of a run's working memory, ready to render. */\nexport interface OutputEntry {\n /** The output variable key (mono). */\n key: string;\n conceptRef?: string;\n value: unknown;\n}\n\n/**\n * The slice of a serialized pipe output this module actually reads. Structural\n * on purpose: the SDK's `DictPipeOutput` is the host's wire type, and the kernel\n * must not depend on `@pipelex/sdk` - the guard below verifies the shape at\n * runtime anyway.\n */\ninterface PipeOutputWithWorkingMemory {\n working_memory: {\n root: Record<string, unknown>;\n aliases?: Record<string, string>;\n };\n}\n\nfunction hasWorkingMemoryRoot(value: unknown): value is PipeOutputWithWorkingMemory {\n return (\n !!value &&\n typeof value === 'object' &&\n 'working_memory' in value &&\n !!(value as { working_memory?: { root?: unknown } }).working_memory &&\n typeof (value as { working_memory: { root?: unknown } }).working_memory.root === 'object'\n );\n}\n\n/** The concept code of a working-memory entry (`{concept}` may be obj/str/absent). */\nfunction entryConceptRef(data: unknown): string | undefined {\n if (!data || typeof data !== 'object') return undefined;\n const raw = (data as { concept?: unknown; concept_code?: unknown }).concept;\n if (raw && typeof raw === 'object')\n return (\n ((raw as { concept_code?: string }).concept_code ?? (raw as { code?: string }).code) ||\n undefined\n );\n if (typeof raw === 'string') return raw;\n return (data as { concept_code?: string }).concept_code || undefined;\n}\n\n/**\n * Split a run's pipe output into the main result and any intermediate outputs,\n * excluding the inputs. The main output's identity comes from the working\n * memory's `main_stuff` alias (the authoritative pointer to the output variable)\n * - so its label is the REAL stuff name, not a positional guess. Falls back to\n * the last produced stuff only when the alias is absent.\n */\nexport function outputsFromPipeOutput(\n pipeOutput: unknown,\n inputKeys: string[],\n): { main: OutputEntry; intermediates: OutputEntry[] } | null {\n if (!hasWorkingMemoryRoot(pipeOutput)) return null;\n const wm = pipeOutput.working_memory as {\n root: Record<string, unknown>;\n aliases?: Record<string, string>;\n };\n const entries = Object.entries(wm.root).filter(([key]) => !inputKeys.includes(key));\n if (entries.length === 0) return null;\n\n const toEntry = ([key, data]: [string, unknown]): OutputEntry => ({\n key,\n conceptRef: entryConceptRef(data),\n value: (data as { content?: unknown })?.content ?? data,\n });\n\n // The real main-output name: `aliases.main_stuff` → its root key.\n const mainKey = wm.aliases?.['main_stuff'];\n const mainEntry: [string, unknown] =\n mainKey && Object.prototype.hasOwnProperty.call(wm.root, mainKey)\n ? [mainKey, wm.root[mainKey]]\n : entries[entries.length - 1]!;\n const intermediates = entries.filter(([key]) => key !== mainEntry[0]).map(toEntry);\n\n return { main: toEntry(mainEntry), intermediates };\n}\n\n/**\n * Recover the inputs a run was executed with from its working memory. The run's\n * `working_memory.root` holds every named stuff - inputs AND outputs - keyed by\n * variable name; we pull the entries whose keys are declared inputs and deflate\n * their `content` (the full form shape) back into the store's simplified\n * `inputData`. Lets the runner repopulate the form for a past/shared run - the\n * inputs that produced the result. Returns `null` when no inputs are present.\n */\nexport function inputDataFromWorkingMemory(\n workingMemory: unknown,\n inputSchemas: InputSchemas,\n): Dict | null {\n const root = (workingMemory as { root?: Record<string, unknown> } | null | undefined)?.root;\n if (!root || typeof root !== 'object') return null;\n const full: Dict = {};\n let found = false;\n for (const key of Object.keys(inputSchemas)) {\n const entry = ownProp(root, key);\n if (entry && typeof entry === 'object' && 'content' in entry) {\n full[key] = (entry as { content: unknown }).content;\n found = true;\n }\n }\n if (!found) return null;\n return deflateAllInputs(full, inputSchemas);\n}\n\n/**\n * Field descriptors for a method's main pipe - the wire descriptor mapped over\n * the contract, or `[]` while either artifact has not arrived yet. The\n * descriptor comes back from `validate` beside `pipe_io_contracts` when the\n * request opts in with `views: [\"input_form\"]`; `getPipeInputForm` is the\n * lookup that matches `getPipeIOContract`.\n */\nexport function fieldsForContract(\n contract: PipeIOContract | undefined,\n descriptor: PipeInputFormDescriptor | undefined,\n): RunField[] {\n return contract?.inputs && descriptor ? buildRunFields(descriptor, contract.inputs) : [];\n}\n\n/**\n * Immutably set a value at a dotted/indexed path (`a.0.b`). Used to write an\n * uploaded file's URL back to a field anywhere in the (possibly nested) tree.\n */\nexport function setValueAtPath(root: Dict, path: string[], value: unknown): Dict {\n const head = path[0];\n if (head === undefined) return root;\n const rest = path.slice(1);\n if (rest.length === 0) return { ...root, [head]: value };\n\n const nextSeg = rest[0] as string;\n const child = root[head];\n if (/^\\d+$/.test(nextSeg)) {\n const arr = Array.isArray(child) ? child.slice() : [];\n const idx = Number(nextSeg);\n arr[idx] =\n rest.length === 1 ? value : setValueAtPath((arr[idx] as Dict) ?? {}, rest.slice(1), value);\n return { ...root, [head]: arr };\n }\n return { ...root, [head]: setValueAtPath((child as Dict) ?? {}, rest, value) };\n}\n"]}
package/dist/core/gate.js CHANGED
@@ -1,5 +1,5 @@
1
- export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-2HIYTIQ6.js';
2
- import '../chunk-HQMXXK5X.js';
1
+ export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-4DPYGNJ3.js';
2
+ import '../chunk-E6BIXJ6C.js';
3
3
  import '../chunk-Y2ND6W4W.js';
4
4
  import '../chunk-LBFZXYCY.js';
5
5
  import '../chunk-XO5OENNF.js';
@@ -12,7 +12,8 @@ export { closeOptionalStructures, openOptionalStructures, seedInputs, seedObject
12
12
  export { InputPresence, buildPipeRef, getPipeIOContract, inputMustBeFilled, isFixedCountInput, isOptionalInput, isPluralInput } from './contracts.js';
13
13
  export { RunInputsGateResult, RunInputsVerdict, apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from './gate.js';
14
14
  export { RunInputError, validateRunInputsSchema } from './gate-validator.js';
15
- export { OutputEntry, apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues } from './values.js';
15
+ export { OutputEntry, apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues } from './values.js';
16
+ export { ExampleSource, ExampleSourcePage, ExampleSourceQuery, FileSource, FileSourcePage, FileSourceQuery, FileSourceScope, FormExample, SourceFile, addChosenFiles, chosenFilesAdded, roomForChosenFiles, sourceFileValue } from './sources.js';
16
17
  export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode } from './wire-format.js';
17
18
  export { asCalendarDate, dayWithinDateTime, isAcceptableDate, isAcceptableDateTime, toDateInputValue, toStoredDateValue } from './date-format.js';
18
19
  export { Translate, ValidationMessageKey, describeValidationError, displayValue, valueAtProperty } from './validation-message.js';
@@ -1,16 +1,17 @@
1
- export { describeValidationError, displayValue, valueAtProperty } from '../chunk-RPA7DNSK.js';
2
1
  export { planFileSave, planStuffSave } from '../chunk-ICUEHNEH.js';
3
2
  export { closeOptionalStructures, openOptionalStructures, seedInputs, seedObjectValue } from '../chunk-VH5CDQDR.js';
3
+ export { addChosenFiles, chosenFilesAdded, roomForChosenFiles, sourceFileValue } from '../chunk-EQJBM3NS.js';
4
4
  export { collectStuffFiles } from '../chunk-RRTI7AIR.js';
5
- export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues } from '../chunk-MEXWXLR7.js';
5
+ export { describeValidationError, displayValue, valueAtProperty } from '../chunk-RPA7DNSK.js';
6
+ export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues } from '../chunk-ZX52CQJ4.js';
6
7
  export { narrowFileFormats } from '../chunk-CAKQ5VFT.js';
7
8
  export { NATIVE_COMPOSITE_CONCEPT_REF, NATIVE_DATE_CONCEPT_REF, NATIVE_HTML_CONCEPT_REF, TYPED_SCALAR_MARKERS, formatDateContent, hasTypedScalarMarkers, isNativeCompositeNode, isNativeDateNode, isNativeHtmlNode, isViewableUrl, readCompositeContent, readDataUrl, readDateContent, readDocumentContent, readHtmlContent, readImageContent, viewableUrl } from '../chunk-CM4KVG53.js';
8
9
  export { getPipeOutputForm } from '../chunk-JIGRWJTV.js';
9
10
  export { buildResultField, buildRunFields, getPipeInputForm } from '../chunk-ZB4RYUKV.js';
10
11
  export { conceptCategory } from '../chunk-FABY3DEY.js';
11
12
  export { DOCUMENT_FORMATS, IMAGE_FORMATS, acceptLabel, acceptMap, formatsForKind, isAcceptedFile } from '../chunk-XCO6GTEC.js';
12
- export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-2HIYTIQ6.js';
13
- export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode } from '../chunk-HQMXXK5X.js';
13
+ export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-4DPYGNJ3.js';
14
+ export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode } from '../chunk-E6BIXJ6C.js';
14
15
  import '../chunk-Y2ND6W4W.js';
15
16
  export { normalizeSchemaForRjsf, prepareSchemaForRjsf } from '../chunk-LBFZXYCY.js';
16
17
  export { anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional } from '../chunk-XO5OENNF.js';
@@ -0,0 +1,161 @@
1
+ /**
2
+ * The two optional host seams beside the upload: a **file source**, which lets
3
+ * a file field take a file the host already stores, and an **example source**,
4
+ * which lets a whole form take a set of values someone saved for the method.
5
+ *
6
+ * The kernel states the shapes and applies the answers; the host answers. It
7
+ * knows nothing of any platform's routes, records or permissions: a host maps
8
+ * its own list onto these shapes, and a host that gives neither seam gets the
9
+ * form it had before. The controls that use them are `./react`'s
10
+ * (`FilePicker`, `FillWithExample`), and docs/sources.md is the contract.
11
+ *
12
+ * Shapes and pure functions only, so a host's server can import the types it
13
+ * answers with, and the rules that write an answer into a value are tested in
14
+ * node. No React, no fetch.
15
+ */
16
+ /** Whose files a file source lists: the person's own, or the whole team's. */
17
+ type FileSourceScope = 'mine' | 'everyone';
18
+ /** One page of a file source's list, as the picker asks for it. */
19
+ interface FileSourceQuery {
20
+ /** What the person searched for, trimmed; empty when they searched for nothing. */
21
+ search: string;
22
+ /** Whose files to list. */
23
+ scope: FileSourceScope;
24
+ /**
25
+ * The MIME types the field accepts, after any narrowing a host applied
26
+ * (`narrowFileFormats`), in the field's own order. The list must hold only
27
+ * files of these types: the picker writes what is chosen straight into the
28
+ * field, and a field that refuses a dropped file of another type must not
29
+ * be handed one this way.
30
+ */
31
+ mediaTypes: readonly string[];
32
+ /** Where to continue: absent for the first page, else the previous page's `nextCursor`. */
33
+ cursor?: string;
34
+ /** Aborted when the answer is no longer wanted: a newer search, a closed picker. */
35
+ signal: AbortSignal;
36
+ }
37
+ /** One row of a file source's list: a file the host already stores. */
38
+ interface SourceFile {
39
+ /** The row's identity in the host's list, which a choice is kept by. */
40
+ id: string;
41
+ /**
42
+ * The stored file's address, written into the field as its `url`, exactly as
43
+ * an upload's result is. Several rows may share one address.
44
+ */
45
+ url: string;
46
+ /** The file's name, shown on the row and written into the field as its `filename`. */
47
+ name: string;
48
+ /** The file's MIME type, which names its format on the row. */
49
+ mediaType?: string;
50
+ /** The file's size in bytes. */
51
+ size?: number;
52
+ /** How the file came to be. A `test` file is marked "Test file" at the head of its row's second line. */
53
+ kind?: 'uploaded' | 'generated' | 'test';
54
+ /** When the file was stored, as an ISO 8601 timestamp; the row says it as a date. */
55
+ createdAt?: string;
56
+ /**
57
+ * Where the file came from, in the host's own words ("Uploaded by Ana",
58
+ * "Made by Invoice extraction"), shown on the row's second line as it is.
59
+ */
60
+ origin?: string;
61
+ }
62
+ /** One page of a file source's answer. */
63
+ interface FileSourcePage {
64
+ /** The page's files, newest first. A page may be empty and still carry a cursor. */
65
+ files: readonly SourceFile[];
66
+ /** Where the next page starts, or nothing when this page is the last. */
67
+ nextCursor?: string | null;
68
+ }
69
+ /**
70
+ * Where a file field can take a file the host already stores. When a form has
71
+ * one, every file field offers "Choose from your team's files", and a list of
72
+ * files offers it for several at once.
73
+ */
74
+ interface FileSource {
75
+ /** Lists one page of files for a query. Rejecting shows the failure with Try again. */
76
+ list: (query: FileSourceQuery) => Promise<FileSourcePage>;
77
+ /** Which of Mine and Everyone the picker opens on. */
78
+ initialScope: FileSourceScope;
79
+ }
80
+ /** One example of a method: a name and the inputs a run of it sends. */
81
+ interface FormExample {
82
+ /** The example's identity in the host's list. */
83
+ id: string;
84
+ /** The example's name, shown on its row. */
85
+ name: string;
86
+ /**
87
+ * The inputs as a run takes them: each input `{ concept, content }`, an
88
+ * optional input left out, an empty plural input a bare `[]`. It is the
89
+ * shape `apiInputsFromRunValues` produces, so a host saves an example from
90
+ * `form.inputs` and hands it back as it is.
91
+ */
92
+ inputs: Readonly<Record<string, unknown>>;
93
+ }
94
+ /** One page of an example source's list. */
95
+ interface ExampleSourceQuery {
96
+ /** Where to continue: absent for the first page, else the previous page's `nextCursor`. */
97
+ cursor?: string;
98
+ /** Aborted when the answer is no longer wanted. */
99
+ signal: AbortSignal;
100
+ }
101
+ /** One page of an example source's answer. */
102
+ interface ExampleSourcePage {
103
+ /** The page's examples, in the order the list shows them. */
104
+ examples: readonly FormExample[];
105
+ /** Where the next page starts, or nothing when this page is the last. */
106
+ nextCursor?: string | null;
107
+ }
108
+ /**
109
+ * Where a form can take a whole set of values. When a form has one, it offers
110
+ * "Fill with an example". `rename` and `delete` are capabilities: each is
111
+ * offered on a row's menu only when given, so a host gives them only to a
112
+ * person allowed to change examples.
113
+ */
114
+ interface ExampleSource {
115
+ /** Lists one page of the method's examples. Rejecting shows the failure with Try again. */
116
+ list: (query: ExampleSourceQuery) => Promise<ExampleSourcePage>;
117
+ /**
118
+ * Renames an example. Resolving to the example as stored replaces the row;
119
+ * resolving to nothing keeps the row under the new name.
120
+ */
121
+ rename?: (example: FormExample, name: string) => Promise<FormExample | void>;
122
+ /** Deletes an example. Asked for only after the person confirmed it. */
123
+ delete?: (example: FormExample) => Promise<void>;
124
+ /**
125
+ * Whether "Fill with an example" is left out while the method has no
126
+ * example. `false` by default, when the empty list says how to make one.
127
+ * A host sets it for a person who cannot save an example, to whom an empty
128
+ * list has nothing to offer; the form then asks for the first page as it
129
+ * mounts, to know whether to offer the control.
130
+ */
131
+ hideWhenEmpty?: boolean;
132
+ }
133
+ /** What a chosen file writes into its field: the same `{ url, filename }` an upload writes. */
134
+ declare function sourceFileValue(file: SourceFile): {
135
+ url: string;
136
+ filename: string;
137
+ };
138
+ /**
139
+ * A list of files with the chosen files written into it, in the order they
140
+ * were chosen: first into the rows that hold no file yet (a row the person
141
+ * added and left empty), then as new rows after the last. A file whose address
142
+ * the list already holds is not written again, and neither is a second choice
143
+ * of one address: two rows of a source may name the same stored file. Returns
144
+ * a new array and leaves `held` as it was.
145
+ */
146
+ declare function addChosenFiles(held: readonly unknown[] | undefined, chosen: readonly SourceFile[]): unknown[];
147
+ /**
148
+ * How many files a list may still take from a source: its bound less the files
149
+ * it holds, since `addChosenFiles` writes into its empty rows before adding
150
+ * any. `undefined` when the list has no bound.
151
+ */
152
+ /**
153
+ * How many files `addChosenFiles` writes for `chosen` into `held`: the choices
154
+ * whose address the list does not hold yet, each address once. This is what a
155
+ * choice spends of `roomForChosenFiles`, so a held file chosen again, or a
156
+ * second row naming a chosen file, takes no room.
157
+ */
158
+ declare function chosenFilesAdded(held: readonly unknown[] | undefined, chosen: readonly SourceFile[]): number;
159
+ declare function roomForChosenFiles(held: readonly unknown[] | undefined, maxItemCount: number | undefined): number | undefined;
160
+
161
+ export { type ExampleSource, type ExampleSourcePage, type ExampleSourceQuery, type FileSource, type FileSourcePage, type FileSourceQuery, type FileSourceScope, type FormExample, type SourceFile, addChosenFiles, chosenFilesAdded, roomForChosenFiles, sourceFileValue };
@@ -0,0 +1,3 @@
1
+ export { addChosenFiles, chosenFilesAdded, roomForChosenFiles, sourceFileValue } from '../chunk-EQJBM3NS.js';
2
+ //# sourceMappingURL=sources.js.map
3
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"sources.js"}
@@ -55,6 +55,30 @@ declare function storeInputDataFromRunValues(values: Dict, fields: RunField[], i
55
55
  * the envelope agree; the bare form runs today and stays correct after.)
56
56
  */
57
57
  declare function apiInputsFromRunValues(values: Dict, fields: RunField[], inputSchemas: InputSchemas): Record<string, unknown>;
58
+ /**
59
+ * The form values a set of run inputs stands for: the inverse of
60
+ * `apiInputsFromRunValues`, for inputs saved from a form (an example) and
61
+ * handed back to one.
62
+ *
63
+ * Each input is read as a run sends it, `{ concept, content }`, or as its bare
64
+ * content (the empty plural `[]`), and its content is turned back into the
65
+ * control's own shape. Only an object naming its concept is read as that
66
+ * envelope: a structure sent bare may well have a property called `content`. An input the inputs do not hold is left empty, and an
67
+ * optional structure they do not hold stays closed: the inputs are the whole
68
+ * run, so an input they left out was left out of the run too. An input no
69
+ * field takes is ignored.
70
+ */
71
+ declare function runValuesFromInputs(inputs: Readonly<Dict> | undefined, fields: RunField[]): Dict;
72
+ /**
73
+ * Whether two sets of form values send the same run.
74
+ *
75
+ * Compared in the shape a run takes, so the differences a run cannot see do
76
+ * not count: a text typed and then erased is the blank it started as, and an
77
+ * optional structure opened and left empty is the closed one it was. What
78
+ * "Fill with an example" asks before replacing is the work a person did, and
79
+ * a value that sends nothing is no work to lose.
80
+ */
81
+ declare function sameRunValues(a: Dict, b: Dict, fields: RunField[]): boolean;
58
82
  /** One named output pulled out of a run's working memory, ready to render. */
59
83
  interface OutputEntry {
60
84
  /** The output variable key (mono). */
@@ -96,4 +120,4 @@ declare function fieldsForContract(contract: PipeIOContract | undefined, descrip
96
120
  */
97
121
  declare function setValueAtPath(root: Dict, path: string[], value: unknown): Dict;
98
122
 
99
- export { type OutputEntry, apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues };
123
+ export { type OutputEntry, apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues };
@@ -1,7 +1,7 @@
1
- export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues } from '../chunk-MEXWXLR7.js';
1
+ export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues } from '../chunk-ZX52CQJ4.js';
2
2
  import '../chunk-ZB4RYUKV.js';
3
3
  import '../chunk-XCO6GTEC.js';
4
- import '../chunk-HQMXXK5X.js';
4
+ import '../chunk-E6BIXJ6C.js';
5
5
  import '../chunk-XO5OENNF.js';
6
6
  import '../chunk-OD3VYXUY.js';
7
7
  import '../chunk-WYH56SOZ.js';