@ashley-shrok/viewmodel-shell 3.11.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/agent-skill.md CHANGED
@@ -139,6 +139,8 @@ If a response carries `nextPollIn: N`, schedule a POST `{ "name": "poll", "state
139
139
 
140
140
  File uploads use the multipart form above. One form entry per file input, keyed by the input's `name` attribute (from the corresponding node's `name` field in the tree). The file's binary content is the entry's value. JSON-body dispatch cannot carry files; use multipart.
141
141
 
142
+ **A file rides only the action(s) its input declares.** Each file `FieldNode` carries an `uploadOn` array of action names. Send a file's binary entry **only** when the action you are dispatching (`_action.name`) is listed in that file input's `uploadOn`; if you dispatch any other action, do **not** include the file. A file input with no `uploadOn` (absent or empty) rides **nothing** — its binary is never sent. This mirrors the browser, where the same declaration decides which click sends the file: an agent should not attach a file to an action a human's click could not have sent it with. (There is no positional/implicit rule — the file's own `uploadOn` is the whole contract.)
143
+
142
144
  ## Versioning
143
145
 
144
146
  This manual applies to protocol token `viewmodel-shell/1.0` — the value of the `protocol` field on the discoverability meta tag. The protocol token tracks the wire shape, NOT the package version: a 1.5.x or 1.6.x package release may still carry protocol `viewmodel-shell/1.0` because the wire has not undergone a breaking change. A future major-version bump (`viewmodel-shell/2.0`) signals a breaking change and invalidates this manual; expect a new skill at the same `/.well-known/vms-skill.md` URL.
package/dist/browser.js CHANGED
@@ -601,11 +601,26 @@ export class BrowserAdapter {
601
601
  const form = document.createElement("form");
602
602
  form.className = `vms-form${n.layout && n.layout !== "stack" ? ` vms-form--${n.layout}` : ""}`;
603
603
  form.noValidate = true;
604
- this.kids(n.children, form, on);
604
+ // File collection is by DECLARED intent, not button position: a file input
605
+ // rides an action iff that action's name is listed in the input's `uploadOn`
606
+ // (carried here via the data-vms-upload-on attribute set in field()). EVERY
607
+ // trigger inside the form — submit, buttons[], a ButtonNode or
608
+ // FieldNode.action nested in children — routes through this one path, so
609
+ // where a trigger sits is irrelevant; the file's own uploadOn decides. An
610
+ // input with no uploadOn rides nothing (there is no positional fallback).
605
611
  const dispatchWithFiles = (action) => {
606
612
  const files = {};
607
613
  form.querySelectorAll("input[type=file]").forEach(inp => {
608
- if (inp.name && inp.files?.[0])
614
+ if (!inp.name || !inp.files?.[0])
615
+ return;
616
+ let uploadOn = [];
617
+ try {
618
+ uploadOn = JSON.parse(inp.dataset.vmsUploadOn ?? "[]");
619
+ }
620
+ catch {
621
+ uploadOn = [];
622
+ }
623
+ if (uploadOn.includes(action.name))
609
624
  files[inp.name] = inp.files[0];
610
625
  });
611
626
  const ev = { name: action.name };
@@ -613,6 +628,10 @@ export class BrowserAdapter {
613
628
  ev.files = files;
614
629
  on(ev);
615
630
  };
631
+ // Children dispatch through the file-aware path too — so a ButtonNode (or a
632
+ // FieldNode.action Enter) nested anywhere in the form carries files per the
633
+ // uploadOn contract, identical to a footer buttons[] trigger.
634
+ this.kids(n.children, form, dispatchWithFiles);
616
635
  // #22 — submitButton takes precedence: the form renders the consumer's own
617
636
  // button (its label + emphasis/tone/size/width) as the submit and fires its
618
637
  // action; submitLabel/submitAction for the implicit button are then ignored.
@@ -809,6 +828,10 @@ export class BrowserAdapter {
809
828
  inp.className = "vms-field__input";
810
829
  inp.id = `vms-${n.name}`;
811
830
  inp.name = n.name;
831
+ // Carry the declared upload routing to dispatch time — form()'s
832
+ // dispatchWithFiles reads this and attaches the file only to an action
833
+ // named here. Absent/empty => the file rides no action.
834
+ inp.dataset.vmsUploadOn = JSON.stringify(n.uploadOn ?? []);
812
835
  // File-input persistence: re-apply any registered file to the new node.
813
836
  const existingFile = this.fileRegistry.get(n.name);
814
837
  if (existingFile) {
@@ -823,6 +846,13 @@ export class BrowserAdapter {
823
846
  const file = inp.files?.[0];
824
847
  if (file) {
825
848
  this.fileRegistry.set(n.name, file);
849
+ // [vms:orphan-file] — a picked file that declares no uploadOn action
850
+ // will never be sent (the binary rides an action, and this input
851
+ // names none). Silent under-attach is the dangerous failure, so warn.
852
+ if (!n.uploadOn || n.uploadOn.length === 0) {
853
+ this.warnOnce("orphan-file:" + n.name, "[vms:orphan-file] file field '" + n.name + "' has a picked file but no uploadOn action — " +
854
+ "its binary will not be sent; add uploadOn:[\"<action>\"] naming the action that should carry it.");
855
+ }
826
856
  // [vms:type-mismatch] — OBSERVABLE-SUBSET diagnostic. The client is
827
857
  // untyped JS: it CANNOT know a state slot's *declared* server type, so
828
858
  // it only catches the observable case where a file object overwrites a
package/dist/index.d.ts CHANGED
@@ -255,7 +255,10 @@ export interface FormNode {
255
255
  * `bind` path and travel with the dispatch's `_state` payload. Mirrors
256
256
  * HTML's multiple submit buttons / `formaction` — different action per
257
257
  * button, same underlying state. A plain ButtonNode placed in `children`
258
- * has identical dispatch semantics; the buttons[] slot is a layout hint. */
258
+ * has identical dispatch semantics: both flow through the same file-aware
259
+ * dispatch, so file collection is governed by each file input's `uploadOn`
260
+ * (below), NOT by whether the trigger sits in `buttons[]` or `children`. The
261
+ * buttons[] slot is purely a layout hint. */
259
262
  buttons?: ButtonNode[];
260
263
  /** Opt-in: bare Enter inside a descendant <textarea> dispatches submitAction
261
264
  * (chat-composer "Enter sends, Shift/Ctrl/Meta/Alt+Enter = newline"). No-op
@@ -320,6 +323,15 @@ export interface FieldNode {
320
323
  /** Dispatched when Enter is pressed (text-like inputs only). Carries an
321
324
  * action name only — the current value is already in state at the bind path. */
322
325
  action?: ActionEvent;
326
+ /** FILE INPUTS ONLY. The action name(s) whose dispatch carries this file's
327
+ * binary over the multipart wire. A file rides an action iff that action's
328
+ * name is listed here — declared on the *file*, so which trigger sends it no
329
+ * longer depends on where a button sits (the trigger can live anywhere in the
330
+ * form; footer `buttons[]`, `children`, submit, and Enter all honor this
331
+ * equally). An absent or empty `uploadOn` means the file rides **nothing**
332
+ * (there is no positional fallback); the browser warns `[vms:orphan-file]`
333
+ * when a file is picked with no `uploadOn`. Ignored on non-file inputs. */
334
+ uploadOn?: string[];
323
335
  }
324
336
  export interface CheckboxNode {
325
337
  type: "checkbox";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ashley-shrok/viewmodel-shell",
3
- "version": "3.11.0",
3
+ "version": "4.0.0",
4
4
  "description": "A server-driven UI framework where the wire format is structured enough that agents can build full-stack apps without ever opening a browser and all UI tests are pure unit tests with no browser runtime. Server returns a JSON tree of typed nodes; a thin TypeScript adapter renders it to DOM. Backend-agnostic \u2014 a .NET reference backend ships with the repo, but any language can produce the JSON contract.",
5
5
  "type": "module",
6
6
  "license": "MIT",