@arkitektio/bsx 4.2.0 → 4.3.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 (122) hide show
  1. package/dist/bsx/references.d.ts.map +1 -1
  2. package/dist/bsx/references.js +28 -7
  3. package/dist/bsx/references.js.map +1 -1
  4. package/dist/catalogs/index.d.ts +83 -27
  5. package/dist/catalogs/index.d.ts.map +1 -1
  6. package/dist/catalogs/parts/data.d.ts +1 -1
  7. package/dist/catalogs/parts/feedback.d.ts +3 -3
  8. package/dist/catalogs/parts/forms.d.ts +35 -7
  9. package/dist/catalogs/parts/forms.d.ts.map +1 -1
  10. package/dist/catalogs/parts/forms.js +32 -0
  11. package/dist/catalogs/parts/forms.js.map +1 -1
  12. package/dist/catalogs/parts/icons.d.ts +2 -2
  13. package/dist/catalogs/parts/index.d.ts +63 -27
  14. package/dist/catalogs/parts/index.d.ts.map +1 -1
  15. package/dist/catalogs/parts/navigation.d.ts +4 -4
  16. package/dist/catalogs/parts/overlays.d.ts +11 -11
  17. package/dist/catalogs/parts/run.d.ts +8 -0
  18. package/dist/catalogs/parts/run.d.ts.map +1 -1
  19. package/dist/catalogs/parts/scene.d.ts +8 -0
  20. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  21. package/dist/catalogs/parts/scene.js +4 -0
  22. package/dist/catalogs/parts/scene.js.map +1 -1
  23. package/dist/catalogs/props.d.ts +1 -1
  24. package/dist/catalogs/scene.d.ts +8 -0
  25. package/dist/catalogs/scene.d.ts.map +1 -1
  26. package/dist/catalogs/shadcn.d.ts +59 -11
  27. package/dist/catalogs/shadcn.d.ts.map +1 -1
  28. package/dist/catalogs/shadcn.js +2 -0
  29. package/dist/catalogs/shadcn.js.map +1 -1
  30. package/dist/catalogs/ui.d.ts +16 -16
  31. package/dist/renderer/BlokRenderer.d.ts +4 -1
  32. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  33. package/dist/renderer/BlokRenderer.js +5 -1
  34. package/dist/renderer/BlokRenderer.js.map +1 -1
  35. package/dist/renderer/bloks/control.d.ts +12 -0
  36. package/dist/renderer/bloks/control.d.ts.map +1 -1
  37. package/dist/renderer/bloks/control.js +92 -5
  38. package/dist/renderer/bloks/control.js.map +1 -1
  39. package/dist/renderer/bloks/data.d.ts +1 -1
  40. package/dist/renderer/bloks/feedback.d.ts +3 -3
  41. package/dist/renderer/bloks/forms.d.ts +31 -7
  42. package/dist/renderer/bloks/forms.d.ts.map +1 -1
  43. package/dist/renderer/bloks/forms.js +56 -0
  44. package/dist/renderer/bloks/forms.js.map +1 -1
  45. package/dist/renderer/bloks/icons.d.ts +1 -1
  46. package/dist/renderer/bloks/index.d.ts +51 -27
  47. package/dist/renderer/bloks/index.d.ts.map +1 -1
  48. package/dist/renderer/bloks/navigation.d.ts +4 -4
  49. package/dist/renderer/bloks/overlays.d.ts +11 -11
  50. package/dist/renderer/bloks/run/components.d.ts +4 -0
  51. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  52. package/dist/renderer/bloks/run/host.d.ts +32 -3
  53. package/dist/renderer/bloks/run/host.d.ts.map +1 -1
  54. package/dist/renderer/bloks/run/host.js.map +1 -1
  55. package/dist/renderer/bloks/scene/index.d.ts +4 -0
  56. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  57. package/dist/renderer/functions/v2/index.d.ts.map +1 -1
  58. package/dist/renderer/functions/v2/index.js +39 -0
  59. package/dist/renderer/functions/v2/index.js.map +1 -1
  60. package/dist/renderer/runtime/context.d.ts +2 -0
  61. package/dist/renderer/runtime/context.d.ts.map +1 -1
  62. package/dist/renderer/runtime/context.js +4 -0
  63. package/dist/renderer/runtime/context.js.map +1 -1
  64. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  65. package/dist/renderer/runtime/hooks.js +1 -0
  66. package/dist/renderer/runtime/hooks.js.map +1 -1
  67. package/dist/renderer/runtime/resolution.d.ts +2 -0
  68. package/dist/renderer/runtime/resolution.d.ts.map +1 -1
  69. package/dist/renderer/runtime/resolution.js +17 -1
  70. package/dist/renderer/runtime/resolution.js.map +1 -1
  71. package/dist/renderer/runtime/schemas.d.ts +5 -5
  72. package/dist/renderer/runtime/task.d.ts +25 -2
  73. package/dist/renderer/runtime/task.d.ts.map +1 -1
  74. package/dist/renderer/runtime/task.js +11 -2
  75. package/dist/renderer/runtime/task.js.map +1 -1
  76. package/dist/renderer/runtime/types.d.ts +7 -2
  77. package/dist/renderer/runtime/types.d.ts.map +1 -1
  78. package/dist/shadcn.d.ts +51 -27
  79. package/dist/shadcn.d.ts.map +1 -1
  80. package/dist/shadcn.js +2 -0
  81. package/dist/shadcn.js.map +1 -1
  82. package/dist/spec/bsx_v2.json +64 -0
  83. package/dist/spec/catalogs/base@2.json +136 -3
  84. package/dist/spec/catalogs/base@2.json.js +136 -3
  85. package/dist/spec/catalogs/scene@1.json +20 -0
  86. package/dist/spec/catalogs/scene@1.json.js +20 -0
  87. package/dist/spec/catalogs/shadcn@1.json +142 -0
  88. package/dist/spec/catalogs/shadcn@1.json.js +142 -0
  89. package/dist/spec/vocabulary.d.ts +2 -0
  90. package/dist/spec/vocabulary.d.ts.map +1 -1
  91. package/dist/spec/vocabulary.js +1 -0
  92. package/dist/spec/vocabulary.js.map +1 -1
  93. package/dist/spec/vocabulary.json +43 -11
  94. package/dist/spec/vocabulary.json.js +43 -11
  95. package/package.json +1 -1
  96. package/src/bsx/language.test.ts +1 -1
  97. package/src/bsx/references.test.ts +59 -0
  98. package/src/bsx/references.ts +28 -7
  99. package/src/catalogs/parts/forms.ts +32 -0
  100. package/src/catalogs/parts/scene.ts +6 -0
  101. package/src/catalogs/shadcn.ts +2 -0
  102. package/src/renderer/BlokRenderer.tsx +9 -0
  103. package/src/renderer/bloks/control.tsx +116 -5
  104. package/src/renderer/bloks/forms.tsx +126 -0
  105. package/src/renderer/bloks/run/host.tsx +33 -3
  106. package/src/renderer/bloks/run/space.test.tsx +76 -0
  107. package/src/renderer/functions/v2/functions.test.ts +40 -1
  108. package/src/renderer/functions/v2/index.ts +47 -0
  109. package/src/renderer/runtime/context.tsx +6 -0
  110. package/src/renderer/runtime/hooks.ts +1 -0
  111. package/src/renderer/runtime/resolution.test.ts +14 -0
  112. package/src/renderer/runtime/resolution.ts +15 -1
  113. package/src/renderer/runtime/task.ts +33 -4
  114. package/src/renderer/runtime/types.ts +7 -2
  115. package/src/shadcn.ts +2 -0
  116. package/src/spec/bsx_v2.json +64 -0
  117. package/src/spec/catalogs/base@2.json +136 -3
  118. package/src/spec/catalogs/scene@1.json +20 -0
  119. package/src/spec/catalogs/shadcn@1.json +142 -0
  120. package/src/spec/spec.test.ts +20 -0
  121. package/src/spec/vocabulary.json +43 -11
  122. package/src/spec/vocabulary.ts +3 -0
@@ -159,3 +159,62 @@ describe('findings', () => {
159
159
  expect(checkBlokTree(tree, emptyBlokScope('agent'))).toEqual([]);
160
160
  });
161
161
  });
162
+
163
+ describe('what an assign blok places and reads of the run it prepares', () => {
164
+ const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
165
+ const assign = {...emptyBlokScope('assign'), args: ['image', 'exposure']};
166
+
167
+ it('reads assign.given.<key>, assign.missing and assign.ready', () => {
168
+ const source =
169
+ '<Html><if when={assign.given.image}><Text text={args.image} /></if><arg key="exposure" /><args /><deps /><Button onClick={assign.start()} disabled={!assign.ready}>Run</Button></Html>';
170
+ expect(codes(source, assign)).toEqual([]);
171
+ });
172
+
173
+ it('refuses a given flag for an argument the action has not, and a field assign has not', () => {
174
+ expect(codes('<Html><Text text={assign.given.nope} /></Html>', assign)).toEqual(['args.unknown']);
175
+ expect(codes('<Html><Text text={assign.nope} /></Html>', assign)).toEqual(['path.unknown']);
176
+ });
177
+
178
+ it('keeps <arg>, <deps>, <dep> and the assign root to an assign blok', () => {
179
+ const task = emptyBlokScope('task');
180
+ expect(codes('<Html><arg key="image" /></Html>', task)).toEqual(['assign.kind']);
181
+ expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['assign.kind', 'assign.kind']);
182
+ expect(codes('<Html><Text text={assign.ready} /></Html>', task)).toEqual(['roots.not_in_kind']);
183
+ });
184
+ });
185
+
186
+ describe('what a blok does to the task it is about', () => {
187
+ const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
188
+
189
+ it('cancels, pauses, resumes, steps and interrupts it, and reads whether it may', () => {
190
+ const source =
191
+ '<Html><Button onClick={task.cancel()} disabled={!task.can.cancel}>Stop</Button><Button onClick={task.pause()}>Pause</Button><Button onClick={task.resume()}>Resume</Button><Button onClick={task.step()}>Step</Button><Button onClick={task.interrupt()}>Kill</Button><Text text={deps.robot.connected ? task.started_at : task.status} /></Html>';
192
+ const scope = {...emptyBlokScope('action'), dependencies: [{key: 'robot'}]} as BlokCheckScope;
193
+ expect(codes(source, scope)).toEqual([]);
194
+ });
195
+
196
+ it('starts no run again: a rerun is the page\'s, never a blok\'s', () => {
197
+ expect(() => parseBsx('<Html><Button onClick={task.rerun()}>Again</Button></Html>')).toThrow(/calls nothing/);
198
+ });
199
+
200
+ it('refuses them where there is no task', () => {
201
+ expect(codes('<Html><Button onClick={task.cancel()}>Stop</Button></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind']);
202
+ });
203
+ });
204
+
205
+ describe('what a blok places of its task, and what it leaves the host', () => {
206
+ const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
207
+
208
+ it('places the result, the status line and the time slider, and says how much chrome it wants', () => {
209
+ const source = '<Html chrome="none"><status /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} /></Html>';
210
+ expect(codes(source, emptyBlokScope('action'))).toEqual([]);
211
+ });
212
+
213
+ it('keeps <returns> and <status> to a blok that has a task', () => {
214
+ expect(codes('<Html><returns /><status /></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind', 'roots.not_in_kind']);
215
+ });
216
+
217
+ it('reads what an assign blok knows of starting', () => {
218
+ expect(codes('<Html><Text text={assign.blocked} /><Button disabled={assign.starting} onClick={assign.start()}>Run</Button></Html>', emptyBlokScope('assign'))).toEqual([]);
219
+ });
220
+ });
@@ -173,8 +173,14 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
173
173
  /** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
174
174
  const RUN_KINDS: readonly string[] = ['action', 'assign'];
175
175
  const ASSIGN_KIND = 'assign';
176
- /** The form of the run's arguments, placed by an assign blok. */
177
- const ARGS_COMPONENT = 'args';
176
+ /** What an assign blok places of the host's own: the argument form or one argument, the dependency picker or one dependency. */
177
+ const ASSIGN_COMPONENTS: ReadonlySet<string> = new Set(['args', 'arg', 'deps', 'dep']);
178
+ /** What a blok places of the task it is about: only a kind with a `task`. */
179
+ const TASK_COMPONENTS: ReadonlySet<string> = new Set(['returns', 'status']);
180
+ /** The one field of an agent that is not text. */
181
+ const AGENT_CONNECTED = 'connected';
182
+ /** Where an assign blok reads which arguments the caller decided. */
183
+ const GIVEN_FIELD = 'given';
178
184
  /** Starts the run an assign blok prepares. */
179
185
  const START_EFFECT = 'assign.start';
180
186
 
@@ -575,8 +581,11 @@ class Checker {
575
581
  this.shadowed.add(node.component);
576
582
  this.add('catalog.shadow', node.id, {component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner});
577
583
  }
578
- if (node.component === ARGS_COMPONENT && this.scope.kind !== ASSIGN_KIND) {
579
- this.add('assign.kind', node.id, {what: '<args>', n: article(this.scope.kind), kind: this.scope.kind});
584
+ if (TASK_COMPONENTS.has(node.component) && !this.kind.roots.includes('task')) {
585
+ this.notInKind(node.id, `<${node.component}>`, 'task');
586
+ }
587
+ if (ASSIGN_COMPONENTS.has(node.component) && this.scope.kind !== ASSIGN_KIND) {
588
+ this.add('assign.kind', node.id, {what: `<${node.component}>`, n: article(this.scope.kind), kind: this.scope.kind});
580
589
  }
581
590
  for (const prop of node.props ?? []) this.checkProp(node, prop, spec);
582
591
  }
@@ -667,8 +676,10 @@ class Checker {
667
676
  }
668
677
  }
669
678
  }
670
- if (prop.util_call?.operation === 'task.answer' && !this.kind.roots.includes('task')) {
671
- this.notInKind(node.id, 'task.answer', 'task', prop.key);
679
+ // `task.answer(...)`, `task.cancel()` and their kin act on the task the blok is about.
680
+ const effect = prop.util_call?.operation;
681
+ if (effect?.startsWith('task.') && vocabulary.functions.get(effect)?.effect && !this.kind.roots.includes('task')) {
682
+ this.notInKind(node.id, effect, 'task', prop.key);
672
683
  }
673
684
  if (prop.key === BIND_PROP) {
674
685
  const path = prop.dynamic_value?.path ?? null;
@@ -979,6 +990,16 @@ class Checker {
979
990
  return null;
980
991
  }
981
992
  return openMatch(path);
993
+ case 'assign':
994
+ // `assign.given.<key>` is open below `given`: one flag per argument of the action.
995
+ if (rest[0] === GIVEN_FIELD && rest.length > 1) {
996
+ if (this.scope.args !== null && !this.scope.args.includes(rest[1])) {
997
+ report('args.unknown', {path, key: rest[1], keys: this.scope.args.join(', ') || 'none'});
998
+ return null;
999
+ }
1000
+ return {key: rest[1], kind: 'BOOL'};
1001
+ }
1002
+ return this.descend(recordMatch('assign', vocabulary.records.assign.fields), rest, path, nodeId, propKey);
982
1003
  case 'task':
983
1004
  this.checkReturns(path, rest, nodeId, propKey);
984
1005
  return this.descend(taskRecordMatch('task'), rest, path, nodeId, propKey);
@@ -1050,7 +1071,7 @@ class Checker {
1050
1071
  const report = (code: string, fields: DiagnosticFields) => this.add(code, nodeId, fields, propKey);
1051
1072
  if (head in agentSegments.fields) {
1052
1073
  if (tail.length) report('path.unknown', {path, detail: `${head} of an agent has no fields`});
1053
- return {key: head, kind: 'STRING'};
1074
+ return {key: head, kind: head === AGENT_CONNECTED ? 'BOOL' : 'STRING'};
1054
1075
  }
1055
1076
  if (head === agentSegments.tasks) {
1056
1077
  if (!tail.length) {
@@ -320,6 +320,38 @@ export const formContracts = {
320
320
  })
321
321
  .describe('A labelled form field with description and error slots.'),
322
322
  },
323
+ Combobox: {
324
+ schema: z
325
+ .object({
326
+ bind: markBindSchema(bindSchema.describe('Data-model path holding the picked value.')),
327
+ value: BlokPropSchemas.DynamicString.optional().describe('Controlled value.'),
328
+ defaultValue: BlokPropSchemas.DynamicString.optional().describe('Initial value.'),
329
+ options: z
330
+ .array(z.union([z.string(), z.object({value: z.string(), label: z.string().optional()})]))
331
+ .optional()
332
+ .describe('What can be picked: strings, or `{value, label}` objects. Typing narrows them.'),
333
+ placeholder: BlokPropSchemas.DynamicString.optional().describe('Shown while nothing is picked.'),
334
+ searchPlaceholder: BlokPropSchemas.DynamicString.optional().describe('Shown in the search field.'),
335
+ emptyText: BlokPropSchemas.DynamicString.optional().describe('Shown when typing matches nothing.'),
336
+ disabled: disabledSchema,
337
+ className: classNameSchema,
338
+ onChange: actionProp('Runs on selection. Arguments may read event.value.'),
339
+ })
340
+ .describe('A select with a search field: for a list too long to scan.'),
341
+ },
342
+ DatePicker: {
343
+ schema: z
344
+ .object({
345
+ bind: markBindSchema(bindSchema.describe('Data-model path holding an ISO date string (YYYY-MM-DD).')),
346
+ value: BlokPropSchemas.DynamicString.optional().describe('Controlled ISO date.'),
347
+ defaultValue: BlokPropSchemas.DynamicString.optional().describe('Initial ISO date.'),
348
+ placeholder: BlokPropSchemas.DynamicString.optional().describe('Shown while no date is picked.'),
349
+ disabled: disabledSchema,
350
+ className: classNameSchema,
351
+ onChange: actionProp('Runs on selection. Arguments may read event.value.'),
352
+ })
353
+ .describe('A button that opens a calendar and shows the date picked.'),
354
+ },
323
355
  Calendar: {
324
356
  schema: z
325
357
  .object({
@@ -19,6 +19,12 @@ import {actionProp, bindSchema, describedString} from '../props';
19
19
 
20
20
  export const sceneSchema = z
21
21
  .object({
22
+ chrome: z
23
+ .enum(['auto', 'none'])
24
+ .optional()
25
+ .describe(
26
+ "What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
27
+ ),
22
28
  camera: z
23
29
  .enum(['iso', 'front', 'side', 'top'])
24
30
  .optional()
@@ -26,6 +26,8 @@ export const shadcnCatalog = defineBlokCatalog({
26
26
  ButtonGroup: parts.ButtonGroup,
27
27
  Calendar: {...parts.Calendar, events: {onChange: [{key: "value", kind: "STRING", description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: "STRING"}},
28
28
  Carousel: parts.Carousel,
29
+ Combobox: {...parts.Combobox, events: {onChange: [{key: "value", kind: "STRING", description: "The value picked."}]}, bindKinds: {bind: "STRING"}},
30
+ DatePicker: {...parts.DatePicker, events: {onChange: [{key: "value", kind: "STRING", description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: "STRING"}},
29
31
  CarouselItem: parts.CarouselItem,
30
32
  Chart: parts.Chart,
31
33
  Collapsible: {...parts.Collapsible, events: {onChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
@@ -1,3 +1,4 @@
1
+ import type {BlokTaskControl} from './runtime/task';
1
2
  import {useEffect, useId, useMemo, useRef, useState} from 'react';
2
3
  import {cn} from '../vendor/core/util/utils';
3
4
  import {useBlokTailwind} from '../tailwind/useBlokTailwind';
@@ -84,6 +85,8 @@ type BlokRendererProps = {
84
85
  answerTask?: (values: Record<string, unknown>) => unknown;
85
86
  /** Starts the run an assign blok prepares (`assign.start()`). */
86
87
  startRun?: () => unknown;
88
+ /** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin). */
89
+ controlTask?: (operation: BlokTaskControl) => unknown;
87
90
  /** Where `persist` components keep their state by id; none: they keep nothing. */
88
91
  componentState?: BlokComponentStateStore | null;
89
92
  children?: React.ReactNode;
@@ -148,6 +151,7 @@ export default function BlokRenderer({
148
151
  readExecutor,
149
152
  answerTask,
150
153
  startRun,
154
+ controlTask,
151
155
  componentState = null,
152
156
  children,
153
157
  }: BlokRendererProps) {
@@ -202,6 +206,7 @@ export default function BlokRenderer({
202
206
  travelAt,
203
207
  answerTask,
204
208
  startRun,
209
+ controlTask,
205
210
  });
206
211
  return store;
207
212
  });
@@ -229,6 +234,10 @@ export default function BlokRenderer({
229
234
  runtimeStore.getState().setStartRun(startRun);
230
235
  }, [startRun, runtimeStore]);
231
236
 
237
+ useEffect(() => {
238
+ runtimeStore.getState().setControlTask(controlTask);
239
+ }, [controlTask, runtimeStore]);
240
+
232
241
  useEffect(() => {
233
242
  if (keptRoots) runtimeStore.getState().setKeptRoots(keptRoots);
234
243
  }, [keptRoots, runtimeStore]);
@@ -238,12 +238,22 @@ export const Fragment = createBlokComponent(
238
238
  ({buildChild, component}) => renderDeclaredChildren(component, buildChild),
239
239
  );
240
240
 
241
+ /** What the host adds around a blok; read by the host off the root, the blok itself draws the same either way. */
242
+ export const chromeSchema = z
243
+ .enum(['auto', 'none'])
244
+ .optional()
245
+ .describe(
246
+ "What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
247
+ );
248
+
241
249
  export const Html = createBlokComponent(
242
250
  {
243
251
  name: 'Html',
244
252
  acceptsChildren: true,
245
253
  placement: {childrenContext: 'html', notDownstreamOf: ['Html']},
246
- schema: z.object({}).describe("The root of an html blok (a panel, a dashboard, a popout's page): lays its children out as a fragment does, and names the blok's context."),
254
+ schema: z
255
+ .object({chrome: chromeSchema})
256
+ .describe("The root of an html blok (a panel, a dashboard, a popout's page): lays its children out as a fragment does, and names the blok's context."),
247
257
  },
248
258
  ({buildChild, component}) => renderDeclaredChildren(component, buildChild),
249
259
  );
@@ -424,14 +434,109 @@ export const Ask = createBlokComponent(
424
434
  /* args */
425
435
  /* -------------------------------------------------------------------------- */
426
436
 
427
- export const Args = createBlokComponent(
437
+ /** Port or dependency keys as a prop holds them: a list, or one string with spaces between. */
438
+ const keysOf = (value: unknown): string[] | undefined => {
439
+ if (Array.isArray(value)) return value.filter((key): key is string => typeof key === 'string');
440
+ if (typeof value === 'string') return value.split(/[\s,]+/).filter(Boolean);
441
+ return undefined;
442
+ };
443
+
444
+ const keyList = (what: string) => z.union([z.string(), z.array(z.string())]).optional().describe(what);
445
+
446
+ const argsSchema = z
447
+ .object({
448
+ only: keyList('Only these port keys: `only="exposure gain"` or `only={["exposure", "gain"]}`.'),
449
+ omit: keyList('Not these port keys.'),
450
+ given: z
451
+ .enum(['hide', 'show'])
452
+ .optional()
453
+ .describe('What to do with the arguments the caller gave (`assign.given.<key>`): `hide` leaves them out (the default), `show` lists them, locked.'),
454
+ })
455
+ .describe(
456
+ "The arguments of the run an assign blok starts, as a form generated from the action's ports: filled in right here, read as `args.<key>`. It draws the rest: every argument the caller did not give and no `<arg />` places.",
457
+ );
458
+
459
+ export const Args = createBlokComponent({name: 'args', schema: argsSchema}, ({component, schema}) => {
460
+ const blok = useBlok(component, schema);
461
+ const only = keysOf(useValue(blok.only));
462
+ const omit = keysOf(useValue(blok.omit));
463
+ const given = useValue(blok.given);
464
+ const host = useBlokRunHost();
465
+ return <>{host.renderArgs?.({only, omit, given: given === 'show' ? 'show' : 'hide'}) ?? null}</>;
466
+ });
467
+
468
+ const argSchema = z
469
+ .object({key: z.string().describe('The port key of the argument: `key="exposure"`.')})
470
+ .describe('One argument of the run an assign blok starts, as its port draws it; `<args />` then leaves it out. Nothing for an argument the caller gave: it is locked.');
471
+
472
+ export const Arg = createBlokComponent({name: 'arg', schema: argSchema}, ({component, schema}) => {
473
+ const key = useValue(useBlok(component, schema).key);
474
+ const host = useBlokRunHost();
475
+ return <>{typeof key === 'string' ? (host.renderArg?.(key) ?? null) : null}</>;
476
+ });
477
+
478
+ /* -------------------------------------------------------------------------- */
479
+ /* deps */
480
+ /* -------------------------------------------------------------------------- */
481
+
482
+ export const Deps = createBlokComponent(
483
+ {
484
+ name: 'deps',
485
+ schema: z
486
+ .object({})
487
+ .describe("The picker of the agents the run an assign blok starts would get: every dependency no `<dep />` places. Without it the host shows the picker beside the blok."),
488
+ },
489
+ () => <>{useBlokRunHost().renderDeps?.() ?? null}</>,
490
+ );
491
+
492
+ const depSchema = z
493
+ .object({key: z.string().describe('The dependency key: `key="microscope"`.')})
494
+ .describe('The picker of one dependency of the run an assign blok starts; `<deps />` then leaves it out.');
495
+
496
+ export const Dep = createBlokComponent({name: 'dep', schema: depSchema}, ({component, schema}) => {
497
+ const key = useValue(useBlok(component, schema).key);
498
+ const host = useBlokRunHost();
499
+ return <>{typeof key === 'string' ? (host.renderDep?.(key) ?? null) : null}</>;
500
+ });
501
+
502
+ /* -------------------------------------------------------------------------- */
503
+ /* returns, status */
504
+ /* -------------------------------------------------------------------------- */
505
+
506
+ const returnsSchema = z
507
+ .object({
508
+ only: keyList('Only these return port keys.'),
509
+ omit: keyList('Not these return port keys.'),
510
+ })
511
+ .describe("What `task` returned, as the action's return ports show it (an image as an image, a table as a table). Nothing before the first yield.");
512
+
513
+ export const Returns = createBlokComponent({name: 'returns', schema: returnsSchema}, ({component, schema}) => {
514
+ const blok = useBlok(component, schema);
515
+ const only = keysOf(useValue(blok.only));
516
+ const omit = keysOf(useValue(blok.omit));
517
+ return <>{useBlokRunHost().renderReturns?.({only, omit}) ?? null}</>;
518
+ });
519
+
520
+ export const Status = createBlokComponent(
521
+ {
522
+ name: 'status',
523
+ schema: z.object({}).describe('Where `task` stands, as one line the host draws: its state, how long it took, what it last said.'),
524
+ },
525
+ () => <>{useBlokRunHost().renderStatus?.() ?? null}</>,
526
+ );
527
+
528
+ /* -------------------------------------------------------------------------- */
529
+ /* timeline */
530
+ /* -------------------------------------------------------------------------- */
531
+
532
+ export const Timeline = createBlokComponent(
428
533
  {
429
- name: 'args',
534
+ name: 'timeline',
430
535
  schema: z
431
536
  .object({})
432
- .describe("The arguments of the run an assign blok starts, as a form generated from the action's ports: filled in right here, read as `args.<key>`."),
537
+ .describe("The time slider of what the blok shows (the run of `task`, or the history of its agents): dragging it shows the whole blok as it was at that moment. Nothing where the host has no clock."),
433
538
  },
434
- () => <>{useBlokRunHost().renderArgs?.() ?? null}</>,
539
+ () => <>{useBlokRunHost().renderTimeline?.() ?? null}</>,
435
540
  );
436
541
 
437
542
  export const controlBlokComponents = [
@@ -448,4 +553,10 @@ export const controlBlokComponents = [
448
553
  ErrorSlot,
449
554
  Ask,
450
555
  Args,
556
+ Arg,
557
+ Deps,
558
+ Dep,
559
+ Returns,
560
+ Status,
561
+ Timeline,
451
562
  ];
@@ -3,6 +3,16 @@ import {Button as ShadButton} from '../../vendor/core/ui/button';
3
3
  import {ButtonGroup as ShadButtonGroup} from '../../vendor/core/ui/button-group';
4
4
  import {Calendar as ShadCalendar} from '../../vendor/core/ui/calendar';
5
5
  import {Checkbox as ShadCheckbox} from '../../vendor/core/ui/checkbox';
6
+ import {
7
+ Command as ShadCommand,
8
+ CommandEmpty as ShadCommandEmpty,
9
+ CommandGroup as ShadCommandGroup,
10
+ CommandInput as ShadCommandInput,
11
+ CommandItem as ShadCommandItem,
12
+ CommandList as ShadCommandList,
13
+ } from '../../vendor/core/ui/command';
14
+ import {Popover as ShadPopover, PopoverContent as ShadPopoverContent, PopoverTrigger as ShadPopoverTrigger} from '../../vendor/core/ui/popover';
15
+ import {CalendarDays, Check, ChevronsUpDown} from 'lucide-react';
6
16
  import {
7
17
  Field as ShadField,
8
18
  FieldDescription as ShadFieldDescription,
@@ -765,6 +775,120 @@ const CalendarRender: BlokRender<Contracts['Calendar']> = ({component, schema})
765
775
  );
766
776
  };
767
777
 
778
+ const optionsOf = (raw: unknown): {value: string; label: string}[] =>
779
+ (Array.isArray(raw) ? raw : []).flatMap(option => {
780
+ if (typeof option === 'string') return [{value: option, label: option}];
781
+ if (option !== null && typeof option === 'object' && typeof (option as {value?: unknown}).value === 'string') {
782
+ const {value, label} = option as {value: string; label?: unknown};
783
+ return [{value, label: typeof label === 'string' ? label : value}];
784
+ }
785
+ return [];
786
+ });
787
+
788
+ const ComboboxRender: BlokRender<Contracts['Combobox']> = ({component, schema}) => {
789
+ const blok = useBlok(component, schema);
790
+ const bind = useValue(blok.bind);
791
+ const value = useValue(blok.value);
792
+ const defaultValue = useValue(blok.defaultValue);
793
+ const options = optionsOf(useValue(blok.options));
794
+ const placeholder = useValue(blok.placeholder);
795
+ const searchPlaceholder = useValue(blok.searchPlaceholder);
796
+ const emptyText = useValue(blok.emptyText);
797
+ const disabled = useValue(blok.disabled);
798
+ const className = useValue(blok.className);
799
+ const onChange = useEventAction(blok.onChange);
800
+ const [open, setOpen] = React.useState(false);
801
+
802
+ const controlled = useControlledValue<string>({bind, value, defaultValue, fallback: '', parse: asString});
803
+ const picked = options.find(option => option.value === controlled.value);
804
+
805
+ return (
806
+ <ShadPopover open={open} onOpenChange={setOpen}>
807
+ <ShadPopoverTrigger asChild>
808
+ <ShadButton
809
+ type="button"
810
+ variant="outline"
811
+ role="combobox"
812
+ aria-expanded={open}
813
+ disabled={disabled === true}
814
+ className={cn('w-full justify-between font-normal', !picked && 'text-muted-foreground', className)}
815
+ >
816
+ <span className="truncate">{picked?.label ?? (asString(placeholder) || 'Pick one')}</span>
817
+ <ChevronsUpDown className="size-4 shrink-0 opacity-50" />
818
+ </ShadButton>
819
+ </ShadPopoverTrigger>
820
+ <ShadPopoverContent className="w-(--radix-popover-trigger-width) p-0" align="start">
821
+ <ShadCommand>
822
+ <ShadCommandInput placeholder={asString(searchPlaceholder) || 'Search'} />
823
+ <ShadCommandList>
824
+ <ShadCommandEmpty>{asString(emptyText) || 'Nothing found'}</ShadCommandEmpty>
825
+ <ShadCommandGroup>
826
+ {options.map(option => (
827
+ <ShadCommandItem
828
+ key={option.value}
829
+ // Typing matches what is read, not the value behind it.
830
+ value={option.label}
831
+ onSelect={() => {
832
+ controlled.setValue(option.value);
833
+ onChange?.(option.value);
834
+ setOpen(false);
835
+ }}
836
+ >
837
+ <span className="truncate">{option.label}</span>
838
+ {option.value === controlled.value ? <Check className="ml-auto size-4" /> : null}
839
+ </ShadCommandItem>
840
+ ))}
841
+ </ShadCommandGroup>
842
+ </ShadCommandList>
843
+ </ShadCommand>
844
+ </ShadPopoverContent>
845
+ </ShadPopover>
846
+ );
847
+ };
848
+
849
+ const DatePickerRender: BlokRender<Contracts['DatePicker']> = ({component, schema}) => {
850
+ const blok = useBlok(component, schema);
851
+ const bind = useValue(blok.bind);
852
+ const value = useValue(blok.value);
853
+ const defaultValue = useValue(blok.defaultValue);
854
+ const placeholder = useValue(blok.placeholder);
855
+ const disabled = useValue(blok.disabled);
856
+ const className = useValue(blok.className);
857
+ const onChange = useEventAction(blok.onChange);
858
+ const [open, setOpen] = React.useState(false);
859
+
860
+ const controlled = useControlledValue<string>({bind, value, defaultValue, fallback: '', parse: asString});
861
+ const picked = parseIsoDate(controlled.value);
862
+
863
+ return (
864
+ <ShadPopover open={open} onOpenChange={setOpen}>
865
+ <ShadPopoverTrigger asChild>
866
+ <ShadButton
867
+ type="button"
868
+ variant="outline"
869
+ disabled={disabled === true}
870
+ className={cn('w-full justify-start gap-2 font-normal', !picked && 'text-muted-foreground', className)}
871
+ >
872
+ <CalendarDays className="size-4 shrink-0 opacity-50" />
873
+ <span className="truncate">{picked ? picked.toLocaleDateString(undefined, {dateStyle: 'medium', timeZone: 'UTC'}) : asString(placeholder) || 'Pick a date'}</span>
874
+ </ShadButton>
875
+ </ShadPopoverTrigger>
876
+ <ShadPopoverContent className="w-auto p-0" align="start">
877
+ <ShadCalendar
878
+ mode="single"
879
+ selected={picked}
880
+ onSelect={next => {
881
+ const nextValue = next ? toIsoDate(next) : '';
882
+ controlled.setValue(nextValue);
883
+ onChange?.(nextValue);
884
+ setOpen(false);
885
+ }}
886
+ />
887
+ </ShadPopoverContent>
888
+ </ShadPopover>
889
+ );
890
+ };
891
+
768
892
  export const formRenders = {
769
893
  Button: ButtonRender,
770
894
  ButtonGroup: ButtonGroupRender,
@@ -791,4 +915,6 @@ export const formRenders = {
791
915
  FieldSet: FieldSetRender,
792
916
  Field: FieldRender,
793
917
  Calendar: CalendarRender,
918
+ Combobox: ComboboxRender,
919
+ DatePicker: DatePickerRender,
794
920
  };
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  /**
4
4
  * What an action's own blok needs from the app that shows a run of it.
5
5
  *
6
- * The blok core draws `Space`, `Placed`, `Route` and `ask`; it does not know
6
+ * The blok core draws `Space`, `Placed`, `Route`, `ask` and `timeline`; it does not know
7
7
  * which agents a run got, how an agent's own scene blok is found, where a room
8
8
  * keeps its devices, or how an ask is answered. The host answers those through
9
9
  * these contexts: the run (rekuest, from the task or a dry run) and the rooms
@@ -13,6 +13,16 @@ import * as React from 'react';
13
13
  * `Popout`'s card is rendered by the scene's HTML half, outside the blok.
14
14
  */
15
15
 
16
+ /** How an `<args />` narrows the form it draws. */
17
+ export type BlokArgsOptions = {
18
+ /** Only these port keys. */
19
+ only?: readonly string[];
20
+ /** Not these port keys. */
21
+ omit?: readonly string[];
22
+ /** What it does with the arguments the caller gave: leaves them out (`hide`, the default) or lists them, locked (`show`). */
23
+ given?: 'hide' | 'show';
24
+ };
25
+
16
26
  /** An agent a run binds a dependency key to. */
17
27
  export type BlokRunAgent = {id: string; name: string};
18
28
 
@@ -21,8 +31,28 @@ export type BlokRunHost = {
21
31
  agentsFor: (key: string) => readonly BlokRunAgent[];
22
32
  /** The run's open ask, answered in place (answering resumes the run); nothing while none is open. */
23
33
  renderAsk: () => React.ReactNode;
24
- /** The form of the arguments of the run an assign blok starts (`<args />`); absent where no run is being started. */
25
- renderArgs?: () => React.ReactNode;
34
+ /**
35
+ * The form of the arguments of the run an assign blok starts (`<args />`); absent where no run is
36
+ * being started. It draws the rest: every argument the caller did not give and no `<arg />` places,
37
+ * narrowed by `options`.
38
+ */
39
+ renderArgs?: (options?: BlokArgsOptions) => React.ReactNode;
40
+ /** One argument of that run, by port key (`<arg key="image" />`); nothing for one the caller gave. */
41
+ renderArg?: (key: string) => React.ReactNode;
42
+ /** The picker of the run's dependencies (`<deps />`): every dependency no `<dep />` places. */
43
+ renderDeps?: () => React.ReactNode;
44
+ /** The picker of one dependency of that run, by key (`<dep key="microscope" />`). */
45
+ renderDep?: (key: string) => React.ReactNode;
46
+ /** What the run returned, as its return ports show it (`<returns />`); nothing before the first yield. */
47
+ renderReturns?: (options?: Pick<BlokArgsOptions, 'only' | 'omit'>) => React.ReactNode;
48
+ /** Where the run stands, as one line (`<status />`). */
49
+ renderStatus?: () => React.ReactNode;
50
+ /**
51
+ * The run's time slider (`<timeline />`): moving it moves what the host shows of the run, this
52
+ * blok with it. Absent where the run has no clock; a host that draws a slider of its own leaves
53
+ * that out for a blok that places this one.
54
+ */
55
+ renderTimeline?: () => React.ReactNode;
26
56
  };
27
57
 
28
58
  const NO_AGENTS: readonly BlokRunAgent[] = Object.freeze([]);