@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
@@ -65,3 +65,79 @@ describe('the argument form an assign blok places', () => {
65
65
  expect(bare.queryByTestId('args-form')).toBeNull();
66
66
  });
67
67
  });
68
+
69
+ describe('the time slider a task blok places', () => {
70
+ it('draws what the host gives for <timeline />, and nothing without a host', () => {
71
+ const tree = [{id: 'root', component: 'Html', children: [{id: 'slider', component: 'timeline'}]}];
72
+ const run: BlokRunHost = {agentsFor: () => [], renderAsk: () => null, renderTimeline: () => <div data-testid="timeline" />};
73
+ const hosted = render(
74
+ <BlokRunHostProvider value={run}>
75
+ <BlokRenderer catalog={testCatalog()} uiComponents={tree} />
76
+ </BlokRunHostProvider>,
77
+ );
78
+ expect(hosted.getByTestId('timeline')).toBeTruthy();
79
+ hosted.unmount();
80
+ const bare = render(<BlokRenderer catalog={testCatalog()} uiComponents={tree} />);
81
+ expect(bare.queryByTestId('timeline')).toBeNull();
82
+ });
83
+ });
84
+
85
+ describe('what an assign blok places one by one', () => {
86
+ it('hands <args /> its options, and <arg />, <deps />, <dep /> their keys', () => {
87
+ const tree = [
88
+ {
89
+ id: 'root',
90
+ component: 'Html',
91
+ children: [
92
+ {id: 'one', component: 'arg', props: [{key: 'key', static_value: 'exposure'}]},
93
+ {id: 'rest', component: 'args', props: [{key: 'omit', static_value: 'gain offset'}, {key: 'given', static_value: 'show'}]},
94
+ {id: 'dep', component: 'dep', props: [{key: 'key', static_value: 'robot'}]},
95
+ {id: 'deps', component: 'deps'},
96
+ ],
97
+ },
98
+ ];
99
+ const renderArgs = vi.fn(() => <div data-testid="args-form" />);
100
+ const run: BlokRunHost = {
101
+ agentsFor: () => [],
102
+ renderAsk: () => null,
103
+ renderArgs,
104
+ renderArg: key => <div data-testid={`arg-${key}`} />,
105
+ renderDeps: () => <div data-testid="deps" />,
106
+ renderDep: key => <div data-testid={`dep-${key}`} />,
107
+ };
108
+ const hosted = render(
109
+ <BlokRunHostProvider value={run}>
110
+ <BlokRenderer catalog={testCatalog()} uiComponents={tree} />
111
+ </BlokRunHostProvider>,
112
+ );
113
+ expect(hosted.getByTestId('arg-exposure')).toBeTruthy();
114
+ expect(hosted.getByTestId('dep-robot')).toBeTruthy();
115
+ expect(hosted.getByTestId('deps')).toBeTruthy();
116
+ expect(renderArgs).toHaveBeenLastCalledWith({only: undefined, omit: ['gain', 'offset'], given: 'show'});
117
+ });
118
+ });
119
+
120
+ describe('what a task blok places of its run', () => {
121
+ it('draws what the host gives for <returns /> and <status />', () => {
122
+ const tree = [
123
+ {
124
+ id: 'root',
125
+ component: 'Html',
126
+ children: [
127
+ {id: 'status', component: 'status'},
128
+ {id: 'result', component: 'returns', props: [{key: 'only', static_value: ['image']}]},
129
+ ],
130
+ },
131
+ ];
132
+ const renderReturns = vi.fn(() => <div data-testid="returns" />);
133
+ const run: BlokRunHost = {agentsFor: () => [], renderAsk: () => null, renderReturns, renderStatus: () => <div data-testid="status" />};
134
+ const hosted = render(
135
+ <BlokRunHostProvider value={run}>
136
+ <BlokRenderer catalog={testCatalog()} uiComponents={tree} />
137
+ </BlokRunHostProvider>,
138
+ );
139
+ expect(hosted.getByTestId('status')).toBeTruthy();
140
+ expect(hosted.getByTestId('returns')).toBeTruthy();
141
+ expect(renderReturns).toHaveBeenLastCalledWith({only: ['image'], omit: undefined});
142
+ });
143
+ });
@@ -18,7 +18,7 @@ describe('coverage', () => {
18
18
  it('implements every pure vocabulary function, and nothing else', () => {
19
19
  const declared = [...loadVocabulary().functions.values()].filter(fn => !fn.effect).map(fn => fn.name).sort();
20
20
  expect([...v2Functions.keys()].sort()).toEqual(declared);
21
- expect(declared).toHaveLength(107);
21
+ expect(declared).toHaveLength(117);
22
22
  expect(undeclaredImplementations()).toEqual([]);
23
23
  });
24
24
 
@@ -153,6 +153,16 @@ describe('the null table', () => {
153
153
  ['fmt.quantity', {value: null}, ''],
154
154
  ['time.diff', {start: null, end: NOW}, null],
155
155
  ['time.diff', {start: NOW, end: null}, null],
156
+ ['time.add', {value: null, seconds: 5}, null],
157
+ ['time.before', {a: null, b: NOW}, false],
158
+ ['time.after', {a: NOW, b: null}, false],
159
+ ['list.where', {value: null, key: 'x'}, []],
160
+ ['list.find', {value: null, key: 'x'}, null],
161
+ ['list.count', {value: null, key: 'x'}, 0],
162
+ ['list.concat', {value: null, other: [1]}, [1]],
163
+ ['obj.merge', {value: null, other: {a: 1}}, {a: 1}],
164
+ ['obj.pick', {value: null, keys: ['a']}, {}],
165
+ ['obj.omit', {value: null, keys: ['a']}, {}],
156
166
  ];
157
167
 
158
168
  it.each(nullCases)('%s(%j) is %j', (name, args, expected) => {
@@ -313,3 +323,32 @@ describe('semantics', () => {
313
323
  expect(call('fmt.duration', {seconds: time('2026-10-25T13:30:00Z')})).toBe('1h 30m');
314
324
  });
315
325
  });
326
+
327
+ describe('filtering, joining and moments', () => {
328
+ const rows = [
329
+ {name: 'a', state: {ok: true}, n: 1},
330
+ {name: 'b', state: {ok: false}, n: 2},
331
+ {name: 'c', state: {ok: true}, n: 2},
332
+ ];
333
+
334
+ it('keeps, finds and counts the items a key picks', () => {
335
+ expect(call('list.where', {value: rows, key: 'n', equals: 2})).toEqual([rows[1], rows[2]]);
336
+ expect(call('list.where', {value: rows, key: 'state.ok'})).toEqual([rows[0], rows[2]]);
337
+ expect(call('list.find', {value: rows, key: 'name', equals: 'b'})).toEqual(rows[1]);
338
+ expect(call('list.find', {value: rows, key: 'name', equals: 'z'})).toBeNull();
339
+ expect(call('list.count', {value: rows, key: 'state.ok'})).toBe(2);
340
+ expect(call('list.concat', {value: [1], other: [2, 3]})).toEqual([1, 2, 3]);
341
+ });
342
+
343
+ it('merges, picks and omits keys', () => {
344
+ expect(call('obj.merge', {value: {a: 1, b: 1}, other: {b: 2}})).toEqual({a: 1, b: 2});
345
+ expect(call('obj.pick', {value: {a: 1, b: 2}, keys: ['a']})).toEqual({a: 1});
346
+ expect(call('obj.omit', {value: {a: 1, b: 2}, keys: ['a']})).toEqual({b: 2});
347
+ });
348
+
349
+ it('moves and orders moments without reading the clock', () => {
350
+ expect(call('time.add', {value: '2026-01-01T00:00:00Z', seconds: 90})).toBe('2026-01-01T00:01:30.000Z');
351
+ expect(call('time.before', {a: '2026-01-01T00:00:00Z', b: '2026-01-02T00:00:00Z'})).toBe(true);
352
+ expect(call('time.after', {a: '2026-01-01T00:00:00Z', b: '2026-01-02T00:00:00Z'})).toBe(false);
353
+ });
354
+ });
@@ -282,6 +282,19 @@ const strTest =
282
282
  return value !== null && other !== null && test(value, other);
283
283
  };
284
284
 
285
+ /** What list.where keeps: the items whose `key` deep-equals `equals`, or is truthy when `equals` is left out. */
286
+ const matching = (args: Args): ((item: unknown) => boolean) => {
287
+ const key = optStr(args.key, '', 'key');
288
+ const any = isNull(args.equals);
289
+ return item => {
290
+ const found = readDotted(item, key).value;
291
+ return any ? truthy(found) : deepEqual(found, args.equals);
292
+ };
293
+ };
294
+
295
+ /** Key names as a list holds them. */
296
+ const keyNames = (value: unknown): string[] => (list(value) ?? []).filter((key): key is string => typeof key === 'string');
297
+
285
298
  const listOr =
286
299
  (fallback: () => unknown, operate: (value: unknown[], args: Args) => unknown): Impl =>
287
300
  args => {
@@ -517,6 +530,10 @@ const IMPLEMENTATIONS: Readonly<Partial<Record<string, Impl>>> = {
517
530
  .map(entry => entry.item);
518
531
  },
519
532
  ),
533
+ 'list.where': listOr(() => [], (value, args) => value.filter(matching(args))),
534
+ 'list.find': listOr(() => null, (value, args) => value.find(matching(args)) ?? null),
535
+ 'list.count': listOr(() => 0, (value, args) => value.filter(matching(args)).length),
536
+ 'list.concat': args => [...(list(args.value) ?? []), ...(list(args.other) ?? [])],
520
537
  'list.range': args => {
521
538
  const start = num(args.start);
522
539
  const end = num(args.end);
@@ -547,6 +564,21 @@ const IMPLEMENTATIONS: Readonly<Partial<Record<string, Impl>>> = {
547
564
  return key !== null && Object.prototype.hasOwnProperty.call(value, key);
548
565
  },
549
566
  ),
567
+ 'obj.merge': args => ({...(dict(args.value) ?? {}), ...(dict(args.other) ?? {})}),
568
+ 'obj.pick': dictOr(
569
+ () => ({}),
570
+ (value, args) => {
571
+ const keys = keyNames(args.keys);
572
+ return Object.fromEntries(Object.entries(value).filter(([key]) => keys.includes(key)));
573
+ },
574
+ ),
575
+ 'obj.omit': dictOr(
576
+ () => ({}),
577
+ (value, args) => {
578
+ const keys = keyNames(args.keys);
579
+ return Object.fromEntries(Object.entries(value).filter(([key]) => !keys.includes(key)));
580
+ },
581
+ ),
550
582
  'obj.keys': dictOr(() => [], value => Object.keys(value)),
551
583
  'obj.values': dictOr(() => [], value => Object.values(value)),
552
584
  'obj.entries': dictOr(() => [], value => Object.entries(value).map(([key, item]) => ({key, value: item}))),
@@ -649,6 +681,21 @@ const IMPLEMENTATIONS: Readonly<Partial<Record<string, Impl>>> = {
649
681
  const end = timeOf(args.end);
650
682
  return start === null || end === null ? null : (end - start) / 1000;
651
683
  },
684
+ 'time.add': args => {
685
+ const start = timeOf(args.value);
686
+ const seconds = num(args.seconds);
687
+ return start === null || seconds === null ? null : new Date(start + seconds * 1000).toISOString();
688
+ },
689
+ 'time.before': args => {
690
+ const a = timeOf(args.a);
691
+ const b = timeOf(args.b);
692
+ return a !== null && b !== null && a < b;
693
+ },
694
+ 'time.after': args => {
695
+ const a = timeOf(args.a);
696
+ const b = timeOf(args.b);
697
+ return a !== null && b !== null && a > b;
698
+ },
652
699
  };
653
700
 
654
701
  const build = (): ReadonlyMap<string, BlokV2Function> => {
@@ -1,3 +1,4 @@
1
+ import type {BlokTaskControl} from './task';
1
2
  import * as React from 'react';
2
3
  import {useStore} from 'zustand';
3
4
  import {createStore} from 'zustand/vanilla';
@@ -151,6 +152,7 @@ export const createBlokRuntimeStore = (config?: {
151
152
  travelAt?: string | null;
152
153
  answerTask?: (values: Record<string, unknown>) => unknown;
153
154
  startRun?: () => unknown;
155
+ controlTask?: (operation: BlokTaskControl) => unknown;
154
156
  }): BlokRuntimeStore => {
155
157
  const initialDataModel = config?.initialDataModel;
156
158
  const keptValues = config?.keptValues ?? {};
@@ -175,6 +177,7 @@ export const createBlokRuntimeStore = (config?: {
175
177
  fetchMoreQuery: undefined,
176
178
  answerTask: config?.answerTask,
177
179
  startRun: config?.startRun,
180
+ controlTask: config?.controlTask,
178
181
  setStatus: (path, status) => {
179
182
  const key = canonicalStatusPath(path);
180
183
  set(currentState => {
@@ -214,6 +217,9 @@ export const createBlokRuntimeStore = (config?: {
214
217
  setStartRun: start => {
215
218
  set({startRun: start});
216
219
  },
220
+ setControlTask: control => {
221
+ set({controlTask: control});
222
+ },
217
223
  setInitialDataModel: nextInitialDataModel => {
218
224
  set(currentState => {
219
225
  if (Object.is(currentState.initialDataModel, nextInitialDataModel)) {
@@ -195,6 +195,7 @@ const createLiveResolutionContext = (
195
195
  fetchMoreQuery: (name, variables) => store.getState().fetchMoreQuery?.(name, variables),
196
196
  answerTask: values => store.getState().answerTask?.(values),
197
197
  startRun: () => store.getState().startRun?.(),
198
+ controlTask: store.getState().controlTask ? operation => store.getState().controlTask?.(operation) : undefined,
198
199
  travelling: store.getState().travelAt !== null,
199
200
  invokeFunction: (name, args, options) => store.getState().invokeFunction(name, args, options),
200
201
  dispatchAction: (action, component, observe) =>
@@ -441,6 +441,20 @@ describe("a callback does exactly one thing (v2)", () => {
441
441
  expect(runActionCall(call, createContext({}), component).ok).toBe(false);
442
442
  });
443
443
 
444
+ it("controls the task with task.cancel and its kin, where a host controls one, and never in the past", () => {
445
+ const controlTask = vi.fn(() => "taken");
446
+ for (const operation of ["cancel", "pause", "resume", "step", "interrupt"]) {
447
+ const call = {type: "util" as const, call: {operation: `task.${operation}`, arguments: []}};
448
+ expect(runActionCall(call, createContext({}, {controlTask}), component)).toEqual({ok: true, value: "taken"});
449
+ expect(controlTask).toHaveBeenLastCalledWith(operation);
450
+ expect(runActionCall(call, createContext({}), component).ok).toBe(false);
451
+ }
452
+ controlTask.mockClear();
453
+ const cancel = {type: "util" as const, call: {operation: "task.cancel", arguments: []}};
454
+ expect(runActionCall(cancel, createContext({}, {controlTask, travelling: true}), component)).toEqual({ok: true, value: undefined});
455
+ expect(controlTask).not.toHaveBeenCalled();
456
+ });
457
+
444
458
  it("refuses a pure function as a callback", () => {
445
459
  const result = runActionCall({type: "util", call: {operation: "str.upper", arguments: []}}, createContext({}), component);
446
460
  expect(result.ok).toBe(false);
@@ -1,3 +1,4 @@
1
+ import {TASK_CONTROLS, type BlokTaskControl} from './task';
1
2
  import {z} from 'zod';
2
3
  import {blokPlatform} from '../../platform';
3
4
  import {loadVocabulary} from '../../spec/vocabulary';
@@ -391,6 +392,12 @@ const resolvePropValue = (
391
392
  export const COPY_EFFECT = 'ui.copy';
392
393
  export const ANSWER_EFFECT = 'task.answer';
393
394
  export const START_EFFECT = 'assign.start';
395
+ /** `task.cancel()` and its kin: what the viewer does to the task the blok is about. */
396
+ const TASK_CONTROL_PREFIX = 'task.';
397
+ export const taskControlOf = (operation: string): BlokTaskControl | null => {
398
+ const name = operation.startsWith(TASK_CONTROL_PREFIX) ? operation.slice(TASK_CONTROL_PREFIX.length) : '';
399
+ return (TASK_CONTROLS as readonly string[]).includes(name) ? (name as BlokTaskControl) : null;
400
+ };
394
401
  export const REFETCH_EFFECT = 'query.refetch';
395
402
  export const FETCH_MORE_EFFECT = 'query.fetch_more';
396
403
 
@@ -417,7 +424,7 @@ const getPropActionCall = (
417
424
  export const isCommand = (actionCall: BlokActionCall | undefined): boolean =>
418
425
  actionCall !== undefined &&
419
426
  (actionCall.type === 'agent' ||
420
- (actionCall.type === 'util' && (actionCall.call.operation === ANSWER_EFFECT || actionCall.call.operation === START_EFFECT)));
427
+ (actionCall.type === 'util' && loadVocabulary().functions.get(actionCall.call.operation)?.command === true));
421
428
 
422
429
  const copyToClipboard = (value: unknown): void => {
423
430
  const text = value === null || value === undefined ? '' : typeof value === 'string' ? value : JSON.stringify(value);
@@ -509,6 +516,13 @@ const runActionCall = (
509
516
  );
510
517
  return {ok: true, value: answered};
511
518
  }
519
+ const control = taskControlOf(operation);
520
+ if (control !== null) {
521
+ if (context.travelling) return {ok: true, value: undefined};
522
+ if (!context.controlTask) return {ok: false, error: `${operation}: nothing here controls a task.`};
523
+ // What the host returns (a promise, while the task takes it) keeps the control busy.
524
+ return {ok: true, value: context.controlTask(control)};
525
+ }
512
526
  if (operation === START_EFFECT) {
513
527
  if (context.travelling) return {ok: true, value: undefined};
514
528
  if (!context.startRun) return {ok: false, error: 'assign.start: nothing here starts a run.'};
@@ -11,16 +11,28 @@ import type {BlokRuntimeStore, BlokTaskObserver, BlokTaskUpdate} from './types';
11
11
  * An `into` record is the viewer's own state: nothing is published to the
12
12
  * agent, and a reload forgets it.
13
13
  */
14
- export type BlokTaskStatus = 'idle' | 'queued' | 'running' | 'asking' | 'done' | 'failed' | 'cancelled';
14
+ export type BlokTaskStatus = 'idle' | 'queued' | 'running' | 'asking' | 'paused' | 'done' | 'failed' | 'cancelled';
15
15
 
16
16
  export type BlokTaskAsk = {question: string; form: Record<string, unknown>};
17
17
 
18
+ /** One thing a task reported. */
19
+ export type BlokTaskLogEntry = {at: string | null; kind: string; message: string | null};
20
+
21
+ /** What may be done to a task: one flag per `task.<operation>()`. */
22
+ export type BlokTaskControl = 'cancel' | 'pause' | 'resume' | 'step' | 'interrupt';
23
+ export const TASK_CONTROLS: readonly BlokTaskControl[] = ['cancel', 'pause', 'resume', 'step', 'interrupt'];
24
+ export type BlokTaskCan = Record<BlokTaskControl, boolean>;
25
+
26
+ export const NO_TASK_CONTROL: BlokTaskCan = Object.freeze({cancel: false, pause: false, resume: false, step: false, interrupt: false});
27
+
18
28
  export type BlokTaskRecord = {
19
29
  /** The task's id; null before it was started. */
20
30
  id: string | null;
21
31
  status: BlokTaskStatus;
22
- /** queued, running or asking. */
32
+ /** Started and not ended: queued, running, asking or paused. */
23
33
  running: boolean;
34
+ /** Waiting for someone to resume it. */
35
+ paused: boolean;
24
36
  done: boolean;
25
37
  failed: boolean;
26
38
  /** 0-100, as last reported; 100 once done. */
@@ -37,9 +49,19 @@ export type BlokTaskRecord = {
37
49
  answer: Record<string, unknown> | null;
38
50
  /** The latest yield, by return port key. */
39
51
  returns: Record<string, unknown>;
52
+ /** When it was started (ISO 8601); null before. */
53
+ started_at: string | null;
54
+ /** When it ended; null while it has not. */
55
+ ended_at: string | null;
56
+ /** Seconds from start to end; null while it has not ended. */
57
+ duration: number | null;
58
+ /** What it reported, oldest first. */
59
+ log: BlokTaskLogEntry[];
60
+ /** What the viewer may do to it right now (`task.cancel()` and its kin); all false where the host controls nothing. */
61
+ can: BlokTaskCan;
40
62
  };
41
63
 
42
- const TASK_STATUSES: readonly BlokTaskStatus[] = ['idle', 'queued', 'running', 'asking', 'done', 'failed', 'cancelled'];
64
+ const TASK_STATUSES: readonly BlokTaskStatus[] = ['idle', 'queued', 'running', 'asking', 'paused', 'done', 'failed', 'cancelled'];
43
65
  export const isTaskStatus = (value: unknown): value is BlokTaskStatus =>
44
66
  typeof value === 'string' && (TASK_STATUSES as readonly string[]).includes(value);
45
67
 
@@ -50,6 +72,7 @@ export const idleTaskRecord = (): BlokTaskRecord => {
50
72
  id: null,
51
73
  status: 'idle',
52
74
  running: false,
75
+ paused: false,
53
76
  done: false,
54
77
  failed: false,
55
78
  progress: 0,
@@ -59,6 +82,11 @@ export const idleTaskRecord = (): BlokTaskRecord => {
59
82
  ask: null,
60
83
  answer: null,
61
84
  returns: {},
85
+ started_at: null,
86
+ ended_at: null,
87
+ duration: null,
88
+ log: [],
89
+ can: NO_TASK_CONTROL,
62
90
  ...(idle as Partial<BlokTaskRecord>),
63
91
  };
64
92
  };
@@ -71,7 +99,8 @@ export const isSettledStatus = (status: BlokTaskStatus): boolean =>
71
99
  export const withTaskStatus = (record: BlokTaskRecord, status: BlokTaskStatus): BlokTaskRecord => ({
72
100
  ...record,
73
101
  status,
74
- running: status === 'queued' || status === 'running' || status === 'asking',
102
+ running: status === 'queued' || status === 'running' || status === 'asking' || status === 'paused',
103
+ paused: status === 'paused',
75
104
  done: status === 'done',
76
105
  failed: status === 'failed',
77
106
  });
@@ -1,7 +1,7 @@
1
1
  import type {StoreApi} from 'zustand/vanilla';
2
2
  import {z} from 'zod';
3
3
  import type {BlokSourceStatus} from './status';
4
- import type {BlokTaskAsk, BlokTaskBinding} from './task';
4
+ import type {BlokTaskAsk, BlokTaskBinding, BlokTaskControl} from './task';
5
5
 
6
6
  export type ChildDescriptor = string | {id: string; basePath?: string};
7
7
 
@@ -116,7 +116,7 @@ export type BlokTaskUpdate = {
116
116
  /** The task's id, once the host knows it. */
117
117
  id?: string;
118
118
  /** Where it stands while it has not ended. */
119
- status?: 'queued' | 'running' | 'asking';
119
+ status?: 'queued' | 'running' | 'asking' | 'paused';
120
120
  /** The ask it opened (null: answered or withdrawn). */
121
121
  ask?: BlokTaskAsk | null;
122
122
  /** The values given for its ask. */
@@ -216,6 +216,8 @@ export type BlokResolutionContext = {
216
216
  answerTask?: (values: Record<string, unknown>) => unknown;
217
217
  /** Starts the run an assign blok prepares (`assign.start()`); undefined where the host starts none. */
218
218
  startRun?: () => unknown;
219
+ /** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin); undefined where the host controls no task. */
220
+ controlTask?: (operation: BlokTaskControl) => unknown;
219
221
  /** Set while the blok shows a moment in the past: no command runs. */
220
222
  travelling?: boolean;
221
223
  resolvePath: (path: string) => string;
@@ -252,12 +254,15 @@ export type BlokRuntimeContext = {
252
254
  answerTask: ((values: Record<string, unknown>) => unknown) | undefined;
253
255
  /** Starts the run an assign blok prepares; set by a host that can start one. */
254
256
  startRun: (() => unknown) | undefined;
257
+ /** Controls `task`; set by a host that can. */
258
+ controlTask: ((operation: BlokTaskControl) => unknown) | undefined;
255
259
  setStatus: (path: string, status: BlokSourceStatus | null) => void;
256
260
  setTravelAt: (at: string | null) => void;
257
261
  setRefetchQuery: (refetch: ((name: string) => void) | undefined) => void;
258
262
  setFetchMoreQuery: (fetchMore: ((name: string, variables: Record<string, unknown>) => void) | undefined) => void;
259
263
  setAnswerTask: (answer: ((values: Record<string, unknown>) => unknown) | undefined) => void;
260
264
  setStartRun: (start: (() => unknown) | undefined) => void;
265
+ setControlTask: (control: ((operation: BlokTaskControl) => unknown) | undefined) => void;
261
266
  agentMappingStateUpdates: BlokAgentMappingStateUpdates;
262
267
  invokeFunction: BlokInvokeFunctionHandler;
263
268
  dispatchAction: BlokDispatchActionHandler;
package/src/shadcn.ts CHANGED
@@ -145,6 +145,8 @@ export const shadcnExtrasRenders = {
145
145
  ButtonGroup: domRenders.ButtonGroup,
146
146
  Calendar: domRenders.Calendar,
147
147
  Carousel: domRenders.Carousel,
148
+ Combobox: domRenders.Combobox,
149
+ DatePicker: domRenders.DatePicker,
148
150
  CarouselItem: domRenders.CarouselItem,
149
151
  Chart: domRenders.Chart,
150
152
  Collapsible: domRenders.Collapsible,
@@ -386,6 +386,14 @@
386
386
  "accepts_children": true,
387
387
  "catalog": "ui@1"
388
388
  },
389
+ "Combobox": {
390
+ "text_prop": null,
391
+ "context": "HTML",
392
+ "children_context": null,
393
+ "inherits_context": false,
394
+ "accepts_children": false,
395
+ "catalog": "shadcn@1"
396
+ },
389
397
  "ContextMenu": {
390
398
  "text_prop": null,
391
399
  "context": "HTML",
@@ -450,6 +458,14 @@
450
458
  "accepts_children": true,
451
459
  "catalog": "logo@1"
452
460
  },
461
+ "DatePicker": {
462
+ "text_prop": null,
463
+ "context": "HTML",
464
+ "children_context": null,
465
+ "inherits_context": false,
466
+ "accepts_children": false,
467
+ "catalog": "shadcn@1"
468
+ },
453
469
  "Dialog": {
454
470
  "text_prop": null,
455
471
  "context": "HTML",
@@ -1490,6 +1506,14 @@
1490
1506
  "accepts_children": false,
1491
1507
  "catalog": "scene@1"
1492
1508
  },
1509
+ "arg": {
1510
+ "text_prop": null,
1511
+ "context": "HTML",
1512
+ "children_context": null,
1513
+ "inherits_context": false,
1514
+ "accepts_children": false,
1515
+ "catalog": "base@2"
1516
+ },
1493
1517
  "args": {
1494
1518
  "text_prop": null,
1495
1519
  "context": "HTML",
@@ -1530,6 +1554,22 @@
1530
1554
  "accepts_children": true,
1531
1555
  "catalog": "base@2"
1532
1556
  },
1557
+ "dep": {
1558
+ "text_prop": null,
1559
+ "context": "HTML",
1560
+ "children_context": null,
1561
+ "inherits_context": false,
1562
+ "accepts_children": false,
1563
+ "catalog": "base@2"
1564
+ },
1565
+ "deps": {
1566
+ "text_prop": null,
1567
+ "context": "HTML",
1568
+ "children_context": null,
1569
+ "inherits_context": false,
1570
+ "accepts_children": false,
1571
+ "catalog": "base@2"
1572
+ },
1533
1573
  "div": {
1534
1574
  "text_prop": null,
1535
1575
  "context": "HTML",
@@ -1618,6 +1658,14 @@
1618
1658
  "accepts_children": true,
1619
1659
  "catalog": "html@1"
1620
1660
  },
1661
+ "returns": {
1662
+ "text_prop": null,
1663
+ "context": "HTML",
1664
+ "children_context": null,
1665
+ "inherits_context": false,
1666
+ "accepts_children": false,
1667
+ "catalog": "base@2"
1668
+ },
1621
1669
  "span": {
1622
1670
  "text_prop": "text",
1623
1671
  "context": "HTML",
@@ -1626,6 +1674,14 @@
1626
1674
  "accepts_children": true,
1627
1675
  "catalog": "html@1"
1628
1676
  },
1677
+ "status": {
1678
+ "text_prop": null,
1679
+ "context": "HTML",
1680
+ "children_context": null,
1681
+ "inherits_context": false,
1682
+ "accepts_children": false,
1683
+ "catalog": "base@2"
1684
+ },
1629
1685
  "suspense": {
1630
1686
  "text_prop": null,
1631
1687
  "context": "HTML",
@@ -1633,6 +1689,14 @@
1633
1689
  "inherits_context": true,
1634
1690
  "accepts_children": true,
1635
1691
  "catalog": "base@2"
1692
+ },
1693
+ "timeline": {
1694
+ "text_prop": null,
1695
+ "context": "HTML",
1696
+ "children_context": null,
1697
+ "inherits_context": false,
1698
+ "accepts_children": false,
1699
+ "catalog": "base@2"
1636
1700
  }
1637
1701
  },
1638
1702
  "cases": [