@tai42/studio-sdk 13.3.0 → 15.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.
Files changed (104) hide show
  1. package/dist/components/components.css +19 -0
  2. package/dist/components/icons.d.ts +2 -0
  3. package/dist/components/icons.d.ts.map +1 -1
  4. package/dist/components/icons.js +2 -0
  5. package/dist/components/icons.js.map +1 -1
  6. package/dist/components/templated-text-field.d.ts +98 -0
  7. package/dist/components/templated-text-field.d.ts.map +1 -0
  8. package/dist/components/templated-text-field.js +217 -0
  9. package/dist/components/templated-text-field.js.map +1 -0
  10. package/dist/hooks/useApi.d.ts +461 -59
  11. package/dist/hooks/useApi.d.ts.map +1 -1
  12. package/dist/index.d.ts +6 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +5 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/navigation/types.d.ts +2 -1
  17. package/dist/navigation/types.d.ts.map +1 -1
  18. package/dist/query-keys.d.ts +13 -0
  19. package/dist/query-keys.d.ts.map +1 -1
  20. package/dist/query-keys.js +13 -0
  21. package/dist/query-keys.js.map +1 -1
  22. package/dist/state-binding/AdapterMapping.d.ts +33 -0
  23. package/dist/state-binding/AdapterMapping.d.ts.map +1 -0
  24. package/dist/state-binding/AdapterMapping.js +205 -0
  25. package/dist/state-binding/AdapterMapping.js.map +1 -0
  26. package/dist/state-binding/BindingJqField.d.ts +43 -0
  27. package/dist/state-binding/BindingJqField.d.ts.map +1 -0
  28. package/dist/state-binding/BindingJqField.js +57 -0
  29. package/dist/state-binding/BindingJqField.js.map +1 -0
  30. package/dist/state-binding/BindingTemplatedJqField.d.ts +24 -0
  31. package/dist/state-binding/BindingTemplatedJqField.d.ts.map +1 -0
  32. package/dist/state-binding/BindingTemplatedJqField.js +7 -0
  33. package/dist/state-binding/BindingTemplatedJqField.js.map +1 -0
  34. package/dist/state-binding/InputInjectionRow.d.ts +18 -0
  35. package/dist/state-binding/InputInjectionRow.d.ts.map +1 -0
  36. package/dist/state-binding/InputInjectionRow.js +55 -0
  37. package/dist/state-binding/InputInjectionRow.js.map +1 -0
  38. package/dist/state-binding/StateAttachRow.d.ts +27 -0
  39. package/dist/state-binding/StateAttachRow.d.ts.map +1 -0
  40. package/dist/state-binding/StateAttachRow.js +102 -0
  41. package/dist/state-binding/StateAttachRow.js.map +1 -0
  42. package/dist/state-binding/StateBindingEditor.d.ts +37 -0
  43. package/dist/state-binding/StateBindingEditor.d.ts.map +1 -0
  44. package/dist/state-binding/StateBindingEditor.js +54 -0
  45. package/dist/state-binding/StateBindingEditor.js.map +1 -0
  46. package/dist/state-binding/StateBindingSection.d.ts +14 -0
  47. package/dist/state-binding/StateBindingSection.d.ts.map +1 -0
  48. package/dist/state-binding/StateBindingSection.js +17 -0
  49. package/dist/state-binding/StateBindingSection.js.map +1 -0
  50. package/dist/state-binding/SubjectScopeFields.d.ts +20 -0
  51. package/dist/state-binding/SubjectScopeFields.d.ts.map +1 -0
  52. package/dist/state-binding/SubjectScopeFields.js +8 -0
  53. package/dist/state-binding/SubjectScopeFields.js.map +1 -0
  54. package/dist/state-binding/UpdateRow.d.ts +20 -0
  55. package/dist/state-binding/UpdateRow.d.ts.map +1 -0
  56. package/dist/state-binding/UpdateRow.js +89 -0
  57. package/dist/state-binding/UpdateRow.js.map +1 -0
  58. package/dist/state-binding/adapter.d.ts +93 -0
  59. package/dist/state-binding/adapter.d.ts.map +1 -0
  60. package/dist/state-binding/adapter.js +251 -0
  61. package/dist/state-binding/adapter.js.map +1 -0
  62. package/dist/state-binding/build-catalog.d.ts +19 -0
  63. package/dist/state-binding/build-catalog.d.ts.map +1 -0
  64. package/dist/state-binding/build-catalog.js +43 -0
  65. package/dist/state-binding/build-catalog.js.map +1 -0
  66. package/dist/state-binding/catalog.d.ts +26 -0
  67. package/dist/state-binding/catalog.d.ts.map +1 -0
  68. package/dist/state-binding/catalog.js +71 -0
  69. package/dist/state-binding/catalog.js.map +1 -0
  70. package/dist/state-binding/index.d.ts +33 -0
  71. package/dist/state-binding/index.d.ts.map +1 -0
  72. package/dist/state-binding/index.js +20 -0
  73. package/dist/state-binding/index.js.map +1 -0
  74. package/dist/state-binding/templated-text-catalog.d.ts +21 -0
  75. package/dist/state-binding/templated-text-catalog.d.ts.map +1 -0
  76. package/dist/state-binding/templated-text-catalog.js +48 -0
  77. package/dist/state-binding/templated-text-catalog.js.map +1 -0
  78. package/dist/state-binding/types.d.ts +78 -0
  79. package/dist/state-binding/types.d.ts.map +1 -0
  80. package/dist/state-binding/types.js +2 -0
  81. package/dist/state-binding/types.js.map +1 -0
  82. package/package.json +5 -5
  83. package/src/components/components.css +19 -0
  84. package/src/components/icons.tsx +8 -0
  85. package/src/components/templated-text-field.tsx +508 -0
  86. package/src/index.ts +76 -1
  87. package/src/navigation/types.ts +4 -1
  88. package/src/query-keys.ts +15 -0
  89. package/src/state-binding/AdapterMapping.tsx +468 -0
  90. package/src/state-binding/BindingJqField.tsx +146 -0
  91. package/src/state-binding/BindingTemplatedJqField.tsx +73 -0
  92. package/src/state-binding/InputInjectionRow.tsx +157 -0
  93. package/src/state-binding/README.md +46 -0
  94. package/src/state-binding/StateAttachRow.tsx +289 -0
  95. package/src/state-binding/StateBindingEditor.tsx +166 -0
  96. package/src/state-binding/StateBindingSection.tsx +37 -0
  97. package/src/state-binding/SubjectScopeFields.tsx +57 -0
  98. package/src/state-binding/UpdateRow.tsx +227 -0
  99. package/src/state-binding/adapter.ts +276 -0
  100. package/src/state-binding/build-catalog.ts +59 -0
  101. package/src/state-binding/catalog.ts +87 -0
  102. package/src/state-binding/index.ts +67 -0
  103. package/src/state-binding/templated-text-catalog.ts +69 -0
  104. package/src/state-binding/types.ts +91 -0
@@ -0,0 +1,508 @@
1
+ /**
2
+ * `TemplatedTextField` — the ONE control that authors a {@link TemplatedText}
3
+ * value: an authored-text field that is either inline `content` (text written in
4
+ * place) or a stored template `id` (a template resource fetched and rendered at
5
+ * run time), with the render `kwargs` that apply in BOTH cases.
6
+ *
7
+ * The two sources are mutually exclusive by CONSTRUCTION: the mode toggle only ever
8
+ * writes `content` XOR `id`, so a value can never carry both. "Neither" is a `null`
9
+ * value, allowed only when the field is optional; a `required` field emits its
10
+ * empty source instead so the schema's non-empty guard (and the field error) refuse
11
+ * the save. The kwargs editor is shared across both modes.
12
+ *
13
+ * It seeds its editing state from `value` ONCE and drives itself thereafter,
14
+ * emitting a normalized value on every change (a caller resets it by remounting
15
+ * under a fresh `key`). The inline editor is a plain multiline textarea by default;
16
+ * a caller authoring jq or another rich field passes `renderInline` to supply its
17
+ * own editor. The stored-template list, its loading/error state, the verbatim
18
+ * server message for an id that no longer resolves, and whether storage is present
19
+ * are passed in by the caller — this control holds no data edge of its own.
20
+ *
21
+ * When storage is absent (a supported configuration in which stored templates
22
+ * cannot be fetched or resolved) the stored source is not offered: an inline or
23
+ * empty value edits inline; a value already carrying an `id` is shown read-only with
24
+ * its kwargs, never converted or dropped. See `storageAbsent` /
25
+ * `storagePresenceLoading`.
26
+ */
27
+ import { useState, type ReactNode } from 'react';
28
+
29
+ import type { TemplatedText } from '@tai42/api-client';
30
+
31
+ import { Button, ErrorState, Skeleton } from './primitives';
32
+ import { Field } from './field';
33
+ import { RadioGroup } from './radio-group';
34
+ import { Select } from './select';
35
+ import { Textarea, TextInput } from './inputs';
36
+ import { CloseIcon } from './icons';
37
+
38
+ /** One stored template the id picker offers. */
39
+ export interface TemplatedTextTemplateOption {
40
+ readonly id: string;
41
+ /** The label shown for the id; defaults to the id itself. */
42
+ readonly label?: string;
43
+ }
44
+
45
+ /** The props `renderInline` receives to draw the inline-content editor. */
46
+ export interface TemplatedTextInlineProps {
47
+ readonly label: string;
48
+ readonly value: string;
49
+ readonly onChange: (value: string) => void;
50
+ readonly error?: string;
51
+ /**
52
+ * The field renders its own group header (label + description) above the source
53
+ * toggle, so the inline editor's OWN visible label is redundant: an editor honours
54
+ * this by rendering that label visually hidden while keeping it as its accessible
55
+ * name (its `<label for>` association stays intact). Always `true` — the control is
56
+ * always grouped — so an editor that draws its own label must respect it.
57
+ */
58
+ readonly hideLabel: boolean;
59
+ }
60
+
61
+ export interface TemplatedTextFieldProps {
62
+ /** The field's accessible name, shown on the active editor. */
63
+ readonly label: string;
64
+ readonly value: TemplatedText | null;
65
+ readonly onChange: (value: TemplatedText | null) => void;
66
+ /** Group-level helper shown under the label, above the source toggle. */
67
+ readonly description?: string;
68
+ /** A field-level error surfaced beneath the control. */
69
+ readonly error?: string;
70
+ /**
71
+ * When true the field must carry a source: clearing the inline text or leaving
72
+ * the template unchosen emits an EMPTY source (not `null`), so the schema guard
73
+ * and the field error refuse the save rather than silently dropping the field.
74
+ */
75
+ readonly required?: boolean;
76
+ /** The stored templates the id picker offers. */
77
+ readonly templates?: readonly TemplatedTextTemplateOption[];
78
+ /** The template list fetch is in flight. */
79
+ readonly templatesLoading?: boolean;
80
+ /** The template list fetch failed — surfaced with a retry. */
81
+ readonly templatesError?: string;
82
+ readonly onTemplatesRetry?: () => void;
83
+ /** The verbatim server message when the stored `id` no longer resolves. */
84
+ readonly resolveError?: string;
85
+ /**
86
+ * Storage is registered ABSENT (`GET /api/storage` → `present: false`) — a fully
87
+ * supported configuration in which stored templates can be neither browsed nor
88
+ * resolved. The stored source is therefore not offered: an inline or empty value
89
+ * shows the inline editor alone (no toggle, no catalog); a value that already
90
+ * carries an `id` is shown READ-ONLY with its kwargs and a note that stored
91
+ * templates are unavailable here — the authored value is never converted to inline,
92
+ * dropped, or blanked.
93
+ */
94
+ readonly storageAbsent?: boolean;
95
+ /**
96
+ * Storage presence is not yet known. A placeholder stands in for the source region
97
+ * so the toggle is not shown and then removed once presence resolves.
98
+ */
99
+ readonly storagePresenceLoading?: boolean;
100
+ /** Supply a custom inline-content editor (jq, rich text); defaults to a textarea. */
101
+ readonly renderInline?: (props: TemplatedTextInlineProps) => ReactNode;
102
+ readonly disabled?: boolean;
103
+ /** Placeholder for the default textarea editor (ignored when `renderInline` is given). */
104
+ readonly placeholder?: string;
105
+ }
106
+
107
+ /** A short one-line rendering of a templated-text value, for read-only summaries. */
108
+ export function templatedTextSummary(value: TemplatedText | null): string {
109
+ if (value === null) return '(unset)';
110
+ if (value.id !== undefined) return `template: ${value.id}`;
111
+ return value.content ?? '';
112
+ }
113
+
114
+ type Mode = 'inline' | 'stored';
115
+
116
+ interface KwargRow {
117
+ readonly key: string;
118
+ readonly value: string;
119
+ /**
120
+ * The stored value this row was seeded from, kept so an UNTOUCHED row re-emits it
121
+ * BYTE-FOR-BYTE: the row form cannot tell a stored string `"7"` from the number `7`,
122
+ * so re-parsing an untouched row would silently coerce the stored type. `undefined`
123
+ * for a row the author added.
124
+ */
125
+ readonly original?: unknown;
126
+ }
127
+
128
+ /** The row's canonical string form, matched against `value` to detect an untouched row. */
129
+ function stringifyRowValue(raw: unknown): string {
130
+ return typeof raw === 'string' ? raw : JSON.stringify(raw);
131
+ }
132
+
133
+ /** Parse a cell as JSON when it can be (numbers/bools/objects), else keep the string. */
134
+ function parseCellValue(raw: string): unknown {
135
+ const trimmed = raw.trim();
136
+ if (trimmed.length === 0) return '';
137
+ try {
138
+ return JSON.parse(trimmed);
139
+ } catch {
140
+ return raw;
141
+ }
142
+ }
143
+
144
+ /** Collapse the kwargs rows into an object, dropping rows with a blank key. */
145
+ function rowsToObject(rows: readonly KwargRow[]): Record<string, unknown> {
146
+ const out: Record<string, unknown> = {};
147
+ for (const row of rows) {
148
+ const key = row.key.trim();
149
+ if (key.length === 0) continue;
150
+ // An untouched seeded row re-emits its stored value verbatim (no JSON-type coerce);
151
+ // an edited or added row is parsed from the cell text.
152
+ out[key] =
153
+ row.original !== undefined && stringifyRowValue(row.original) === row.value
154
+ ? row.original
155
+ : parseCellValue(row.value);
156
+ }
157
+ return out;
158
+ }
159
+
160
+ /** Seed rows from a stored kwargs object (stringifying non-string values). */
161
+ function objectToRows(kwargs: Record<string, unknown> | undefined): KwargRow[] {
162
+ if (kwargs === undefined) return [];
163
+ return Object.entries(kwargs).map(([key, raw]) => ({
164
+ key,
165
+ value: stringifyRowValue(raw),
166
+ original: raw,
167
+ }));
168
+ }
169
+
170
+ /** The add/remove kwargs editor, revealed on demand and open when kwargs already exist. */
171
+ function KwargsEditor({
172
+ label,
173
+ rows,
174
+ disabled,
175
+ onChange,
176
+ }: {
177
+ readonly label: string;
178
+ readonly rows: readonly KwargRow[];
179
+ readonly disabled: boolean;
180
+ readonly onChange: (rows: KwargRow[]) => void;
181
+ }): ReactNode {
182
+ const [open, setOpen] = useState(rows.length > 0);
183
+ const groupLabel = `${label} render parameters`;
184
+
185
+ if (!open) {
186
+ // Wrapped so the ghost button keeps its content width and stays left-aligned
187
+ // in the field's column, marking it as this field's own disclosure rather than
188
+ // a full-width control floating between two fields.
189
+ return (
190
+ <div>
191
+ <Button
192
+ type="button"
193
+ variant="ghost"
194
+ disabled={disabled}
195
+ onClick={() => {
196
+ setOpen(true);
197
+ onChange([...rows, { key: '', value: '' }]);
198
+ }}
199
+ >
200
+ Add render parameters
201
+ </Button>
202
+ </div>
203
+ );
204
+ }
205
+
206
+ return (
207
+ <div
208
+ role="group"
209
+ aria-label={groupLabel}
210
+ style={{ display: 'flex', flexDirection: 'column', gap: 'var(--tai-space-2)' }}
211
+ >
212
+ <span style={{ fontSize: 'var(--tai-text-sm)', color: 'var(--tai-color-text-muted)' }}>
213
+ Render parameters
214
+ </span>
215
+ {rows.map((row, index) => (
216
+ <div
217
+ key={index}
218
+ style={{ display: 'flex', gap: 'var(--tai-space-2)', alignItems: 'center' }}
219
+ >
220
+ <TextInput
221
+ aria-label={`${groupLabel} key ${String(index + 1)}`}
222
+ placeholder="name"
223
+ value={row.key}
224
+ autoComplete="off"
225
+ disabled={disabled}
226
+ onChange={(event) => {
227
+ const next = [...rows];
228
+ next[index] = { ...row, key: event.target.value };
229
+ onChange(next);
230
+ }}
231
+ />
232
+ <TextInput
233
+ aria-label={`${groupLabel} value ${String(index + 1)}`}
234
+ placeholder="value"
235
+ value={row.value}
236
+ autoComplete="off"
237
+ disabled={disabled}
238
+ onChange={(event) => {
239
+ const next = [...rows];
240
+ next[index] = { ...row, value: event.target.value };
241
+ onChange(next);
242
+ }}
243
+ />
244
+ <Button
245
+ type="button"
246
+ variant="ghost"
247
+ aria-label={`Remove ${groupLabel} ${String(index + 1)}`}
248
+ disabled={disabled}
249
+ onClick={() => {
250
+ onChange(rows.filter((_, position) => position !== index));
251
+ }}
252
+ >
253
+ <CloseIcon aria-hidden="true" />
254
+ </Button>
255
+ </div>
256
+ ))}
257
+ <div>
258
+ <Button
259
+ type="button"
260
+ variant="ghost"
261
+ disabled={disabled}
262
+ onClick={() => {
263
+ onChange([...rows, { key: '', value: '' }]);
264
+ }}
265
+ >
266
+ Add parameter
267
+ </Button>
268
+ </div>
269
+ </div>
270
+ );
271
+ }
272
+
273
+ /** The initial mode: stored when the seed carries an `id`, inline otherwise. */
274
+ function initialMode(value: TemplatedText | null): Mode {
275
+ return value?.id !== undefined ? 'stored' : 'inline';
276
+ }
277
+
278
+ export function TemplatedTextField({
279
+ label,
280
+ value,
281
+ onChange,
282
+ description,
283
+ error,
284
+ required = false,
285
+ templates = [],
286
+ templatesLoading = false,
287
+ templatesError,
288
+ onTemplatesRetry,
289
+ resolveError,
290
+ storageAbsent = false,
291
+ storagePresenceLoading = false,
292
+ renderInline,
293
+ disabled = false,
294
+ placeholder,
295
+ }: TemplatedTextFieldProps): ReactNode {
296
+ const [mode, setMode] = useState<Mode>(() => initialMode(value));
297
+ const [inlineDraft, setInlineDraft] = useState(() => value?.content ?? '');
298
+ const [storedDraft, setStoredDraft] = useState(() => value?.id ?? '');
299
+ const [kwargsRows, setKwargsRows] = useState<KwargRow[]>(() => objectToRows(value?.kwargs));
300
+
301
+ const emit = (
302
+ nextMode: Mode,
303
+ nextInline: string,
304
+ nextStored: string,
305
+ nextKwargs: readonly KwargRow[],
306
+ ): void => {
307
+ const kwargs = rowsToObject(nextKwargs);
308
+ const kw = Object.keys(kwargs).length > 0 ? { kwargs } : {};
309
+ if (nextMode === 'stored') {
310
+ const id = nextStored.trim();
311
+ if (id === '') {
312
+ onChange(required ? { id: '', ...kw } : null);
313
+ return;
314
+ }
315
+ onChange({ id, ...kw });
316
+ return;
317
+ }
318
+ if (nextInline.trim() === '') {
319
+ onChange(required ? { content: '', ...kw } : null);
320
+ return;
321
+ }
322
+ onChange({ content: nextInline, ...kw });
323
+ };
324
+
325
+ const changeMode = (next: Mode): void => {
326
+ setMode(next);
327
+ emit(next, inlineDraft, storedDraft, kwargsRows);
328
+ };
329
+
330
+ const changeInline = (next: string): void => {
331
+ setInlineDraft(next);
332
+ emit('inline', next, storedDraft, kwargsRows);
333
+ };
334
+
335
+ const changeStored = (next: string): void => {
336
+ setStoredDraft(next);
337
+ emit('stored', inlineDraft, next, kwargsRows);
338
+ };
339
+
340
+ const changeKwargs = (next: KwargRow[]): void => {
341
+ setKwargsRows(next);
342
+ emit(mode, inlineDraft, storedDraft, next);
343
+ };
344
+
345
+ const templateOptions = templates.map((template) => ({
346
+ value: template.id,
347
+ label: template.label ?? template.id,
348
+ }));
349
+ // A stored id the catalog does not offer cannot be picked from the list; it is
350
+ // shown as an unresolved note rather than silently blanked.
351
+ const unresolvedId =
352
+ mode === 'stored' &&
353
+ storedDraft.trim() !== '' &&
354
+ !templatesLoading &&
355
+ templatesError === undefined &&
356
+ !templates.some((template) => template.id === storedDraft.trim())
357
+ ? storedDraft.trim()
358
+ : undefined;
359
+
360
+ // The inline editor, shared by the present-storage inline mode and the
361
+ // absent-storage inline-only rendering: the caller's rich editor when supplied,
362
+ // else a plain textarea.
363
+ const inlineEditor =
364
+ renderInline !== undefined ? (
365
+ renderInline({ label, value: inlineDraft, onChange: changeInline, error, hideLabel: true })
366
+ ) : (
367
+ <Field label={label} hideLabel error={error}>
368
+ <Textarea
369
+ value={inlineDraft}
370
+ placeholder={placeholder}
371
+ disabled={disabled}
372
+ onChange={(event) => {
373
+ changeInline(event.target.value);
374
+ }}
375
+ />
376
+ </Field>
377
+ );
378
+
379
+ // A stored `id` already authored on the value: with storage absent it is shown
380
+ // read-only rather than resolved, browsed, converted, or dropped.
381
+ const authoredStoredId = value?.id;
382
+ const showsReadOnlyStored = storageAbsent && authoredStoredId !== undefined;
383
+
384
+ // The source region. While presence is unknown a placeholder stands in, so the
385
+ // toggle is never shown and then removed. With storage absent the stored source
386
+ // cannot work and is not offered: an inline or empty value edits inline; a value
387
+ // carrying an `id` is shown read-only with an unavailability note. With storage
388
+ // present the full inline/stored toggle and picker render.
389
+ let source: ReactNode;
390
+ if (storagePresenceLoading) {
391
+ source = <Skeleton height={36} />;
392
+ } else if (storageAbsent) {
393
+ source = showsReadOnlyStored ? (
394
+ <>
395
+ {/* A labeled read-only reference, NOT an editable field: no input box, a
396
+ "Stored template" caption, and the id in monospace — so it reads as a stored
397
+ reference the way the state-template screen shows one, never as literal text a
398
+ reader could mistake for the condition itself. A long id wraps rather than
399
+ overflowing its row. */}
400
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--tai-space-1)' }}>
401
+ <span style={{ fontSize: 'var(--tai-text-sm)', color: 'var(--tai-color-text-muted)' }}>
402
+ Stored template
403
+ </span>
404
+ <code style={{ fontFamily: 'var(--tai-font-mono)', wordBreak: 'break-all' }}>
405
+ {authoredStoredId}
406
+ </code>
407
+ </div>
408
+ <p
409
+ style={{
410
+ margin: 0,
411
+ fontSize: 'var(--tai-text-sm)',
412
+ color: 'var(--tai-color-text-muted)',
413
+ }}
414
+ >
415
+ Stored templates are unavailable — this deployment has no storage backend.
416
+ </p>
417
+ </>
418
+ ) : (
419
+ inlineEditor
420
+ );
421
+ } else {
422
+ source = (
423
+ <>
424
+ <RadioGroup
425
+ aria-label={`${label} source`}
426
+ variant="segmented"
427
+ value={mode}
428
+ disabled={disabled}
429
+ options={[
430
+ { value: 'inline', label: 'Inline text' },
431
+ { value: 'stored', label: 'Stored template' },
432
+ ]}
433
+ onValueChange={(next) => {
434
+ changeMode(next as Mode);
435
+ }}
436
+ />
437
+
438
+ {mode === 'inline' ? (
439
+ inlineEditor
440
+ ) : templatesError !== undefined ? (
441
+ <ErrorState message={templatesError} onRetry={onTemplatesRetry} />
442
+ ) : templatesLoading ? (
443
+ <Skeleton height={36} />
444
+ ) : (
445
+ <Field label={label} hideLabel error={error}>
446
+ <Select
447
+ placeholder={templates.length === 0 ? 'No templates available' : 'Select a template'}
448
+ value={storedDraft}
449
+ disabled={disabled || templates.length === 0}
450
+ options={templateOptions}
451
+ onValueChange={changeStored}
452
+ />
453
+ </Field>
454
+ )}
455
+
456
+ {unresolvedId !== undefined ? (
457
+ <p role="alert" style={{ margin: 0, color: 'var(--tai-color-err-text)' }}>
458
+ {resolveError ?? `The stored template "${unresolvedId}" is not available.`}
459
+ </p>
460
+ ) : null}
461
+ </>
462
+ );
463
+ }
464
+
465
+ // ONE coherent group per field: the label + description form the group header, and
466
+ // the source region and the render-parameters disclosure sit under it — so the
467
+ // controls unambiguously belong to THIS field, read label → description → source →
468
+ // parameters like every sibling field. The header names the `role="group"`
469
+ // container; the active editor is named by the field's own name through its
470
+ // visually-hidden `<label for>` (see `hideLabel`). The container-name redundancy
471
+ // `Field` accepts by design (a redundant container is audible, an unnamed group is
472
+ // silent).
473
+ //
474
+ // A read-only stored value shows its render parameters as read-only text — the values
475
+ // in normal weight, NOT the muted disabled inputs a reader could mistake for empty
476
+ // placeholders — matching the read-only treatment of the id above; every editable
477
+ // rendering keeps the full add/remove editor.
478
+ return (
479
+ <Field label={label} description={description} group>
480
+ {source}
481
+ {showsReadOnlyStored ? (
482
+ kwargsRows.length > 0 ? (
483
+ <div
484
+ role="group"
485
+ aria-label={`${label} render parameters`}
486
+ style={{ display: 'flex', flexDirection: 'column', gap: 'var(--tai-space-1)' }}
487
+ >
488
+ <span style={{ fontSize: 'var(--tai-text-sm)', color: 'var(--tai-color-text-muted)' }}>
489
+ Render parameters
490
+ </span>
491
+ {kwargsRows.map((row) => (
492
+ <div
493
+ key={row.key}
494
+ style={{ fontFamily: 'var(--tai-font-mono)', wordBreak: 'break-all' }}
495
+ >
496
+ <code>{row.key}</code>
497
+ <span style={{ color: 'var(--tai-color-text-muted)' }}>: </span>
498
+ <code>{row.value}</code>
499
+ </div>
500
+ ))}
501
+ </div>
502
+ ) : null
503
+ ) : (
504
+ <KwargsEditor label={label} rows={kwargsRows} disabled={disabled} onChange={changeKwargs} />
505
+ )}
506
+ </Field>
507
+ );
508
+ }
package/src/index.ts CHANGED
@@ -140,7 +140,14 @@ export { isFeatureDisabled, featureDisabledMessage, FeatureDisabled } from './fe
140
140
  export type { FeatureDisabledProps } from './feature-disabled';
141
141
 
142
142
  // -- Cross-feature query keys ------------------------------------------------
143
- export { toolsListKey, extensionsQueryKey, subMcpKey, tokensPayloadKey } from './query-keys';
143
+ export {
144
+ toolsListKey,
145
+ extensionsQueryKey,
146
+ subMcpKey,
147
+ tokensPayloadKey,
148
+ statesListKey,
149
+ stateTemplatesKey,
150
+ } from './query-keys';
144
151
 
145
152
  // -- Extension-combo editing helpers -----------------------------------------
146
153
  export { comboElementNames, extensionElementName } from './extension-combos';
@@ -183,6 +190,12 @@ export { Checkbox } from './components/checkbox';
183
190
  export type { CheckboxProps } from './components/checkbox';
184
191
  export { RadioGroup } from './components/radio-group';
185
192
  export type { RadioGroupProps, RadioOption } from './components/radio-group';
193
+ export { TemplatedTextField, templatedTextSummary } from './components/templated-text-field';
194
+ export type {
195
+ TemplatedTextFieldProps,
196
+ TemplatedTextInlineProps,
197
+ TemplatedTextTemplateOption,
198
+ } from './components/templated-text-field';
186
199
  export { Badge } from './components/badge';
187
200
  export type { BadgeProps } from './components/badge';
188
201
  export { Tabs } from './components/tabs';
@@ -345,6 +358,7 @@ export {
345
358
  ChevronRightIcon,
346
359
  CheckIcon,
347
360
  MinusIcon,
361
+ PlusIcon,
348
362
  EditIcon,
349
363
  UnplugIcon,
350
364
  CopyIcon,
@@ -400,6 +414,67 @@ export type {
400
414
  export { SchemaEditor, lintSchemaText } from './schema-editor';
401
415
  export type { SchemaEditorProps, SchemaEditorChange, SchemaLintResult } from './schema-editor';
402
416
 
417
+ // -- State-binding editor (the one binding shape every door + flow node authors) --
418
+ export {
419
+ StateBindingEditor,
420
+ StateBindingSection,
421
+ StateAttachRow,
422
+ InjectionList,
423
+ UpdateList,
424
+ AdapterMapping,
425
+ SubjectScopeFields,
426
+ BindingJqField,
427
+ BindingTemplatedJqField,
428
+ appendTjq,
429
+ resolveTemplateJq,
430
+ findByRef,
431
+ resolveCallName,
432
+ templatesCatalogFromList,
433
+ statesCatalogFromList,
434
+ fieldPathsFromSchema,
435
+ compileAdapter,
436
+ rowValueJq,
437
+ fieldPathToJq,
438
+ jqKey,
439
+ defaultRowsForInput,
440
+ parseAdapter,
441
+ parseFieldPath,
442
+ generateTemplateCall,
443
+ parseTemplateCall,
444
+ encodeTemplateSegment,
445
+ templatedTextCatalog,
446
+ } from './state-binding';
447
+ export type {
448
+ StoragePresenceQueryLike,
449
+ TemplateNamesQueryLike,
450
+ StateBindingEditorProps,
451
+ StateBindingSectionProps,
452
+ StateAttachRowProps,
453
+ InheritedSubject,
454
+ InjectionListProps,
455
+ UpdateListProps,
456
+ AdapterMappingProps,
457
+ SubjectScopeFieldsProps,
458
+ BindingJqFieldProps,
459
+ BindingTemplatedJqFieldProps,
460
+ TemplateJqSuggestion,
461
+ ResolvedTemplateJq,
462
+ MappingRow,
463
+ MappingSource,
464
+ FieldSource,
465
+ LiteralSource,
466
+ JqSource,
467
+ FieldRoot,
468
+ AdapterCompileResult,
469
+ BindingStateOption,
470
+ BindingTemplateOption,
471
+ BindingTemplateJqOption,
472
+ BindingSourceSchemas,
473
+ SchemaFieldPath,
474
+ TemplatedText,
475
+ TemplatedTextCatalog,
476
+ } from './state-binding';
477
+
403
478
  // -- MCP context widgets (elicitation / progress / completions / output) -----
404
479
  export { ProgressBar } from './components/progress-bar';
405
480
  export type { ProgressBarProps } from './components/progress-bar';
@@ -32,9 +32,12 @@ export interface RouteSearchByToken {
32
32
  // for deep-linking and reload.
33
33
  states: {
34
34
  state?: string;
35
- tab?: 'declaration' | 'modules' | 'records' | 'consumers';
35
+ tab?: 'declaration' | 'templates' | 'records' | 'consumers';
36
36
  subject?: string;
37
37
  target?: string;
38
+ // `template` opens one state-template document (its Template / Jq tabs) in place
39
+ // of the state list — a read-only view of the whole uploaded document.
40
+ template?: string;
38
41
  };
39
42
  extensions: Record<string, never>;
40
43
  interactions: Record<string, never>;
package/src/query-keys.ts CHANGED
@@ -32,3 +32,18 @@ export const subMcpKey = ['sub-mcp'] as const;
32
32
 
33
33
  /** The api-key payloads; read by settings AND the hooks execution-key picker. */
34
34
  export const tokensPayloadKey = ['auth-tokens-payload'] as const;
35
+
36
+ /**
37
+ * The state catalog (`GET /api/states`). The states feature owns it, and every door
38
+ * screen that hosts the state-binding editor (a preset, a route, a hook, a schedule)
39
+ * reads the same catalog to populate the binding's state picker — so both key the one
40
+ * authoritative tuple and a single fetch serves both.
41
+ */
42
+ export const statesListKey = ['states', 'list'] as const;
43
+
44
+ /**
45
+ * The state-template document catalog (`GET /api/state-templates`). Read by the states
46
+ * feature AND every state-binding door screen (the templates a binding attaches),
47
+ * keyed here so the two never fetch the same catalog under diverging tuples.
48
+ */
49
+ export const stateTemplatesKey = ['states', 'state-templates'] as const;