@pipelex/mthds-form 0.18.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.
Files changed (34) hide show
  1. package/README.md +3 -0
  2. package/dist/{chunk-KLCV736G.js → chunk-4DPYGNJ3.js} +3 -3
  3. package/dist/{chunk-KLCV736G.js.map → chunk-4DPYGNJ3.js.map} +1 -1
  4. package/dist/{chunk-YY3JI6VI.js → chunk-CSLDIWB6.js} +1455 -112
  5. package/dist/chunk-CSLDIWB6.js.map +1 -0
  6. package/dist/{chunk-HQMXXK5X.js → chunk-E6BIXJ6C.js} +3 -3
  7. package/dist/{chunk-HQMXXK5X.js.map → chunk-E6BIXJ6C.js.map} +1 -1
  8. package/dist/chunk-EQJBM3NS.js +41 -0
  9. package/dist/chunk-EQJBM3NS.js.map +1 -0
  10. package/dist/{chunk-HVWE3TTC.js → chunk-ZB4RYUKV.js} +3 -3
  11. package/dist/{chunk-HVWE3TTC.js.map → chunk-ZB4RYUKV.js.map} +1 -1
  12. package/dist/{chunk-PQ3ZX5MJ.js → chunk-ZX52CQJ4.js} +17 -5
  13. package/dist/chunk-ZX52CQJ4.js.map +1 -0
  14. package/dist/core/derive.js +2 -2
  15. package/dist/core/gate.js +2 -2
  16. package/dist/core/index.d.ts +2 -1
  17. package/dist/core/index.js +13 -12
  18. package/dist/core/sources.d.ts +161 -0
  19. package/dist/core/sources.js +3 -0
  20. package/dist/core/sources.js.map +1 -0
  21. package/dist/core/values.d.ts +25 -1
  22. package/dist/core/values.js +4 -4
  23. package/dist/core/wire-format.d.ts +11 -1
  24. package/dist/core/wire-format.js +1 -1
  25. package/dist/{field-renderer-C5Onx6qB.d.ts → field-renderer-B3g16qZT.d.ts} +9 -0
  26. package/dist/generative/index.d.ts +2 -1
  27. package/dist/generative/index.js +8 -7
  28. package/dist/generative/index.js.map +1 -1
  29. package/dist/react/index.d.ts +248 -6
  30. package/dist/react/index.js +8 -7
  31. package/dist/styles.css +1 -1
  32. package/package.json +5 -2
  33. package/dist/chunk-PQ3ZX5MJ.js.map +0 -1
  34. package/dist/chunk-YY3JI6VI.js.map +0 -1
@@ -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,11 +1,11 @@
1
- export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues } from '../chunk-PQ3ZX5MJ.js';
1
+ export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromInputs, runValuesFromStore, sameRunValues, setValueAtPath, storeInputDataFromRunValues } from '../chunk-ZX52CQJ4.js';
2
+ import '../chunk-ZB4RYUKV.js';
3
+ import '../chunk-XCO6GTEC.js';
4
+ import '../chunk-E6BIXJ6C.js';
2
5
  import '../chunk-XO5OENNF.js';
3
- import '../chunk-HQMXXK5X.js';
4
- import '../chunk-HVWE3TTC.js';
5
6
  import '../chunk-OD3VYXUY.js';
6
7
  import '../chunk-WYH56SOZ.js';
7
8
  import '../chunk-V3OV2XQT.js';
8
- import '../chunk-XCO6GTEC.js';
9
9
  import '../chunk-GKV77RAS.js';
10
10
  //# sourceMappingURL=values.js.map
11
11
  //# sourceMappingURL=values.js.map
@@ -40,6 +40,16 @@ declare function deflateInput(value: unknown, conceptCode: string): unknown;
40
40
  * - { concept, content } → content (for custom concepts)
41
41
  */
42
42
  declare function inflateInput(value: unknown, conceptCode: string): unknown;
43
+ /**
44
+ * Detect the fully-qualified wrapper form `{ concept: "...", content: ... }`.
45
+ * pipelex accepts this for any concept (native or custom), and the mthds-inputs
46
+ * agent skill writes it by default for disambiguation. We unwrap before applying
47
+ * concept-specific inflation so the form populates correctly.
48
+ */
49
+ declare function isWrappedForm(value: unknown): value is {
50
+ concept: string;
51
+ content: unknown;
52
+ };
43
53
  interface InputSchema {
44
54
  concept_ref: string;
45
55
  json_schema?: Record<string, unknown>;
@@ -92,4 +102,4 @@ declare function pruneEmptyOptionals(value: unknown, rawSchema: Record<string, u
92
102
  */
93
103
  declare function inflateAllInputs(simplifiedData: Record<string, unknown>, inputSchemas: Record<string, InputSchema>): Record<string, unknown>;
94
104
 
95
- export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode };
105
+ export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, isWrappedForm, pruneEmptyOptionals, resolveConceptCode };
@@ -1,4 +1,4 @@
1
- export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode } from '../chunk-HQMXXK5X.js';
1
+ export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, isWrappedForm, pruneEmptyOptionals, resolveConceptCode } from '../chunk-E6BIXJ6C.js';
2
2
  import '../chunk-OD3VYXUY.js';
3
3
  import '../chunk-V3OV2XQT.js';
4
4
  import '../chunk-GKV77RAS.js';
@@ -1,5 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { RunField } from './core/descriptor.js';
3
+ import { FileSource } from './core/sources.js';
3
4
 
4
5
  /**
5
6
  * Ambient state that any field in the tree may need, threaded unchanged through
@@ -45,6 +46,14 @@ interface FieldEnv {
45
46
  /** Resolve a `pipelex-storage://` URI to a browser-viewable URL (for previews
46
47
  * of already-stored files). */
47
48
  resolveUrl?: (uri: string) => Promise<string | null>;
49
+ /**
50
+ * Where a file field can take a file the host already stores. Its presence
51
+ * is the capability, as `onDropFile`'s is: every empty file field then
52
+ * offers "Choose from your team's files", and a list of files offers it for
53
+ * several at once. The choice is written as `{ url, filename }`, exactly as
54
+ * an upload's result is. See docs/sources.md.
55
+ */
56
+ fileSource?: FileSource;
48
57
  }
49
58
  interface FieldRendererProps {
50
59
  field: RunField;
@@ -9,11 +9,12 @@ import { Components, Renderer } from '@json-render/react';
9
9
  import { B as BrandManifest } from '../manifest-DUeAWeqa.js';
10
10
  export { b as brandManifestSchema } from '../manifest-DUeAWeqa.js';
11
11
  import * as zod_v4_core from 'zod/v4/core';
12
- import { F as FieldEnv } from '../field-renderer-C5Onx6qB.js';
12
+ import { F as FieldEnv } from '../field-renderer-B3g16qZT.js';
13
13
  export { seedInputs } from '../core/seed.js';
14
14
  import '../core/contracts.js';
15
15
  import 'mthds/protocol';
16
16
  import '../core/file-formats.js';
17
+ import '../core/sources.js';
17
18
 
18
19
  /**
19
20
  * Whether a spec is one this catalog can render - the check every source
@@ -1,19 +1,20 @@
1
1
  "use client";
2
- import { cn, fieldControlClass, ResultRoot, ResultField, FieldRenderer, ToggleGroup, ToggleGroupItem, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../chunk-YY3JI6VI.js';
2
+ import { cn, fieldControlClass, ResultRoot, ResultField, FieldRenderer, ToggleGroup, ToggleGroupItem, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../chunk-CSLDIWB6.js';
3
3
  import '../chunk-ICUEHNEH.js';
4
4
  export { seedInputs } from '../chunk-VH5CDQDR.js';
5
+ import '../chunk-EQJBM3NS.js';
5
6
  import '../chunk-RRTI7AIR.js';
6
- import '../chunk-PQ3ZX5MJ.js';
7
- import '../chunk-XO5OENNF.js';
8
- import '../chunk-HQMXXK5X.js';
7
+ import '../chunk-ZX52CQJ4.js';
9
8
  import { isNativeValueNode, readDateContent, formatDateContent, isNativeHtmlNode, isNativeDateNode, isNativeCompositeNode } from '../chunk-CM4KVG53.js';
10
9
  export { brandManifestSchema } from '../chunk-QFX332LE.js';
11
- import '../chunk-HVWE3TTC.js';
10
+ import '../chunk-ZB4RYUKV.js';
11
+ import '../chunk-FABY3DEY.js';
12
+ import '../chunk-XCO6GTEC.js';
13
+ import '../chunk-E6BIXJ6C.js';
14
+ import '../chunk-XO5OENNF.js';
12
15
  import '../chunk-OD3VYXUY.js';
13
16
  import '../chunk-WYH56SOZ.js';
14
17
  import { hasOwnProp } from '../chunk-V3OV2XQT.js';
15
- import '../chunk-FABY3DEY.js';
16
- import '../chunk-XCO6GTEC.js';
17
18
  import '../chunk-GKV77RAS.js';
18
19
  import { defineSchema, defineCatalog, validateSpec, compileSpecStream } from '@json-render/core';
19
20
  import { z } from 'zod';