@arkitektio/bsx 6.6.2 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +2 -2
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +25 -1
- package/dist/bsx/declared.d.ts.map +1 -1
- package/dist/bsx/declared.js +34 -2
- package/dist/bsx/declared.js.map +1 -1
- package/dist/bsx/expr.d.ts +18 -4
- package/dist/bsx/expr.d.ts.map +1 -1
- package/dist/bsx/expr.js +46 -9
- package/dist/bsx/expr.js.map +1 -1
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +4 -2
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +2 -0
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +63 -6
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +53 -10
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +23 -1
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +266 -14
- package/dist/bsx/references.js.map +1 -1
- package/dist/ports/rekuest.d.ts +1 -0
- package/dist/ports/rekuest.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +4 -2
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +5 -1
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +5 -1
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +25 -3
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/run/host.d.ts +5 -0
- package/dist/renderer/bloks/run/host.d.ts.map +1 -1
- package/dist/renderer/bloks/run/host.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +2 -1
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +4 -0
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts +2 -0
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +12 -0
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/resolution.d.ts +1 -0
- package/dist/renderer/runtime/resolution.d.ts.map +1 -1
- package/dist/renderer/runtime/resolution.js +11 -0
- package/dist/renderer/runtime/resolution.js.map +1 -1
- package/dist/renderer/runtime/schemas.d.ts.map +1 -1
- package/dist/renderer/runtime/schemas.js +1 -0
- package/dist/renderer/runtime/schemas.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +13 -0
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/renderer/runtime/types.js.map +1 -1
- package/dist/spec/bsx_v2.json +4804 -440
- package/dist/spec/catalogs/base@4.json +57 -1
- package/dist/spec/catalogs/base@4.json.js +57 -1
- package/dist/spec/vocabulary.d.ts +2 -0
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +2 -0
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +19 -10
- package/dist/spec/vocabulary.json.js +19 -10
- package/package.json +1 -1
- package/src/bsx/analyze.ts +2 -2
- package/src/bsx/declared.ts +48 -2
- package/src/bsx/expr.ts +55 -11
- package/src/bsx/infer.test.ts +1 -1
- package/src/bsx/language.test.ts +17 -16
- package/src/bsx/language.ts +4 -2
- package/src/bsx/parse.ts +61 -5
- package/src/bsx/print.ts +50 -8
- package/src/bsx/references.test.ts +12 -11
- package/src/bsx/references.ts +277 -12
- package/src/ports/rekuest.ts +1 -1
- package/src/renderer/BlokRenderer.tsx +9 -0
- package/src/renderer/bloks/control.tsx +36 -4
- package/src/renderer/bloks/run/host.tsx +5 -0
- package/src/renderer/runtime/context.tsx +6 -0
- package/src/renderer/runtime/hooks.ts +13 -0
- package/src/renderer/runtime/resolution.ts +11 -1
- package/src/renderer/runtime/schemas.ts +1 -0
- package/src/renderer/runtime/types.ts +14 -0
- package/src/renderer/unbound.test.tsx +34 -1
- package/src/spec/bsx_v2.json +4804 -440
- package/src/spec/catalogs/base@4.json +57 -1
- package/src/spec/spec.test.ts +2 -2
- package/src/spec/vocabulary.json +19 -10
- package/src/spec/vocabulary.ts +4 -0
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
BlokAgentMappingStateUpdates,
|
|
10
10
|
BlokDispatchActionHandler,
|
|
11
11
|
BlokInvokeFunctionHandler,
|
|
12
|
+
BlokPickDependenciesHandler,
|
|
12
13
|
BlokRefuseActionHandler,
|
|
13
14
|
BlokUnavailableDependencies,
|
|
14
15
|
BlokLockedActions,
|
|
@@ -160,6 +161,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
160
161
|
travelAt?: string | null;
|
|
161
162
|
answerTask?: (values: Record<string, unknown>) => unknown;
|
|
162
163
|
startRun?: () => unknown;
|
|
164
|
+
pickDependencies?: BlokPickDependenciesHandler;
|
|
163
165
|
writePort?: (operation: BlokPortOperation, value?: unknown) => unknown;
|
|
164
166
|
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
165
167
|
}): BlokRuntimeStore => {
|
|
@@ -186,6 +188,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
186
188
|
fetchMoreQuery: undefined,
|
|
187
189
|
answerTask: config?.answerTask,
|
|
188
190
|
startRun: config?.startRun,
|
|
191
|
+
pickDependencies: config?.pickDependencies,
|
|
189
192
|
writePort: config?.writePort,
|
|
190
193
|
controlTask: config?.controlTask,
|
|
191
194
|
setStatus: (path, status) => {
|
|
@@ -227,6 +230,9 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
227
230
|
setStartRun: start => {
|
|
228
231
|
set({startRun: start});
|
|
229
232
|
},
|
|
233
|
+
setPickDependencies: pick => {
|
|
234
|
+
set({pickDependencies: pick});
|
|
235
|
+
},
|
|
230
236
|
setWritePort: write => {
|
|
231
237
|
set({writePort: write});
|
|
232
238
|
},
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import {isActionSchema} from './schemas';
|
|
19
19
|
import {isWritableScopedPath, readScopedPath, resolveScopedPath, scopedWrite, useBlokScope} from './scope';
|
|
20
20
|
import {defaultBlokView} from '../../spec/catalogs';
|
|
21
|
+
import {REFERENCE_SEPARATOR} from '../../bsx/expr';
|
|
21
22
|
import {useBlokNodeState} from './nodeState';
|
|
22
23
|
import {combineStatus, READY, type BlokSourceStatus} from './status';
|
|
23
24
|
import {bindTask} from './task';
|
|
@@ -195,6 +196,7 @@ const createLiveResolutionContext = (
|
|
|
195
196
|
fetchMoreQuery: (name, variables) => store.getState().fetchMoreQuery?.(name, variables),
|
|
196
197
|
answerTask: values => store.getState().answerTask?.(values),
|
|
197
198
|
startRun: () => store.getState().startRun?.(),
|
|
199
|
+
pickDependencies: (key, picks) => store.getState().pickDependencies?.(key, picks),
|
|
198
200
|
writePort: store.getState().writePort ? (operation, value) => store.getState().writePort?.(operation, value) : undefined,
|
|
199
201
|
controlTask: store.getState().controlTask ? operation => store.getState().controlTask?.(operation) : undefined,
|
|
200
202
|
travelling: store.getState().travelAt !== null,
|
|
@@ -355,12 +357,19 @@ const useCallbackRunner = (handle: BlokPropHandle<z.ZodTypeAny> | undefined): Ca
|
|
|
355
357
|
const record = readScopedPath(state.dataModel, into, scope);
|
|
356
358
|
return typeof record === 'object' && record !== null && (record as {running?: unknown}).running === true;
|
|
357
359
|
});
|
|
360
|
+
const given = prop?.agent_call?.given ?? null;
|
|
358
361
|
const unavailable = useBlokRuntime(state => {
|
|
359
362
|
if (command && state.travelAt !== null) return TRAVEL_REASON;
|
|
360
363
|
for (const dependency of dependencies) {
|
|
361
364
|
const reason = state.unavailableDependencies.get(dependency);
|
|
362
365
|
if (reason) return reason;
|
|
363
366
|
}
|
|
367
|
+
// `with cells`: the run gets every dependency declared under the key (`cells__<name>`).
|
|
368
|
+
if (given) {
|
|
369
|
+
for (const [dependency, reason] of state.unavailableDependencies) {
|
|
370
|
+
if (reason && isGivenDependency(dependency, given)) return reason;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
364
373
|
return undefined;
|
|
365
374
|
});
|
|
366
375
|
|
|
@@ -429,6 +438,10 @@ export function useAction(
|
|
|
429
438
|
return React.useMemo(() => (run ? () => run() : undefined), [run]);
|
|
430
439
|
}
|
|
431
440
|
|
|
441
|
+
/** Whether `dependency` is one declared under `key` (`cells__microscope`), its options (`cells__options`) left out. */
|
|
442
|
+
export const isGivenDependency = (dependency: string, key: string): boolean =>
|
|
443
|
+
dependency.startsWith(`${key}${REFERENCE_SEPARATOR}`) && dependency !== `${key}${REFERENCE_SEPARATOR}options`;
|
|
444
|
+
|
|
432
445
|
/** Every dependency a callback prop calls. */
|
|
433
446
|
export const actionDependenciesOf = (prop: BlokComponentProp | undefined): string[] => {
|
|
434
447
|
const found = new Set<string>();
|
|
@@ -407,6 +407,7 @@ export const taskControlOf = (operation: string): BlokTaskControl | null => {
|
|
|
407
407
|
return (TASK_CONTROLS as readonly string[]).includes(name) ? (name as BlokTaskControl) : null;
|
|
408
408
|
};
|
|
409
409
|
export const REFETCH_EFFECT = 'query.refetch';
|
|
410
|
+
export const PICK_EFFECT = 'deps.pick';
|
|
410
411
|
export const FETCH_MORE_EFFECT = 'query.fetch_more';
|
|
411
412
|
|
|
412
413
|
export type BlokActionCall =
|
|
@@ -468,10 +469,11 @@ const runActionCall = (
|
|
|
468
469
|
}
|
|
469
470
|
|
|
470
471
|
if (actionCall.type === 'agent') {
|
|
471
|
-
const action = {
|
|
472
|
+
const action: BlokResolvedAgentCall = {
|
|
472
473
|
dependency: actionCall.call.dependency,
|
|
473
474
|
operation: actionCall.call.operation,
|
|
474
475
|
arguments: resolvedArguments.value,
|
|
476
|
+
...(actionCall.call.given ? {given: actionCall.call.given} : {}),
|
|
475
477
|
};
|
|
476
478
|
if (context.travelling) {
|
|
477
479
|
return {ok: true, value: undefined};
|
|
@@ -538,6 +540,14 @@ const runActionCall = (
|
|
|
538
540
|
// `port.set(null)` empties the port, as `port.clear()` does.
|
|
539
541
|
return {ok: true, value: context.writePort(portOperation, portOperation === 'set' ? resolvedArguments.value.value : undefined)};
|
|
540
542
|
}
|
|
543
|
+
if (operation === PICK_EFFECT) {
|
|
544
|
+
const {key, picks} = resolvedArguments.value;
|
|
545
|
+
if (typeof key !== 'string' || typeof picks !== 'object' || picks === null || Array.isArray(picks)) {
|
|
546
|
+
return {ok: false, error: 'deps.pick: takes a literal key and the picks, per dependency an agent id.'};
|
|
547
|
+
}
|
|
548
|
+
if (!context.pickDependencies) return {ok: false, error: 'deps.pick: nothing here binds a dependency.'};
|
|
549
|
+
return {ok: true, value: context.pickDependencies(key, picks as Record<string, unknown>)};
|
|
550
|
+
}
|
|
541
551
|
if (operation === START_EFFECT) {
|
|
542
552
|
if (context.travelling) return {ok: true, value: undefined};
|
|
543
553
|
if (!context.startRun) return {ok: false, error: 'assign.start: nothing here starts a run.'};
|
|
@@ -29,6 +29,7 @@ const agentCallInputSchema: z.ZodType<BlokAgentCall> = z.object({
|
|
|
29
29
|
dependency: z.string(),
|
|
30
30
|
operation: z.string(),
|
|
31
31
|
arguments: z.array(actionArgumentInputSchema).nullish(),
|
|
32
|
+
given: z.string().nullish(),
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
const utilCallInputSchema: z.ZodType<BlokUtilCall> = z.object({
|
|
@@ -25,6 +25,8 @@ export type BlokAgentCall = {
|
|
|
25
25
|
dependency: string;
|
|
26
26
|
operation: string;
|
|
27
27
|
arguments?: BlokActionArgument[] | null;
|
|
28
|
+
/** `with <key>`: the dependencies the blok declares under that key; only on a call to `self`, absent when not written. */
|
|
29
|
+
given?: string | null;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
export type BlokUtilCall = {
|
|
@@ -61,8 +63,16 @@ export type BlokResolvedAgentCall = {
|
|
|
61
63
|
dependency: string;
|
|
62
64
|
operation: string;
|
|
63
65
|
arguments?: Record<string, unknown>;
|
|
66
|
+
/** `with <key>`: the key of the `<dependencies>` whose agents the run gets. Absent without a `with`. */
|
|
67
|
+
given?: string;
|
|
64
68
|
};
|
|
65
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Binds the dependencies an agent blok declares under `key` (`<dependencies key=... />`) to
|
|
72
|
+
* agents: `picks` is, per dependency, the id of an agent (`cells.pick(microscope: o.id)`).
|
|
73
|
+
*/
|
|
74
|
+
export type BlokPickDependenciesHandler = (key: string, picks: Record<string, unknown>) => void | Promise<unknown>;
|
|
75
|
+
|
|
66
76
|
export type BlokValidationState = {
|
|
67
77
|
isValid: boolean;
|
|
68
78
|
validationErrors: string[];
|
|
@@ -222,6 +232,8 @@ export type BlokResolutionContext = {
|
|
|
222
232
|
answerTask?: (values: Record<string, unknown>) => unknown;
|
|
223
233
|
/** Starts the run an assign blok prepares (`assign.start()`); undefined where the host starts none. */
|
|
224
234
|
startRun?: () => unknown;
|
|
235
|
+
/** Binds declared dependencies to agents (`<key>.pick(...)`, stored `deps.pick`); undefined where the host binds none. */
|
|
236
|
+
pickDependencies?: BlokPickDependenciesHandler;
|
|
225
237
|
/** Writes the port a port blok is the widget of (`port.set(value)`, `port.clear()`, `port.reset()`, `port.touch()`); undefined outside a form. */
|
|
226
238
|
writePort?: (operation: BlokPortOperation, value?: unknown) => unknown;
|
|
227
239
|
/** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin); undefined where the host controls no task. */
|
|
@@ -262,6 +274,7 @@ export type BlokRuntimeContext = {
|
|
|
262
274
|
answerTask: ((values: Record<string, unknown>) => unknown) | undefined;
|
|
263
275
|
/** Starts the run an assign blok prepares; set by a host that can start one. */
|
|
264
276
|
startRun: (() => unknown) | undefined;
|
|
277
|
+
pickDependencies: BlokPickDependenciesHandler | undefined;
|
|
265
278
|
/** Writes the port a port blok is the widget of; set by the form that holds the field. */
|
|
266
279
|
writePort: ((operation: BlokPortOperation, value?: unknown) => unknown) | undefined;
|
|
267
280
|
/** Controls `task`; set by a host that can. */
|
|
@@ -272,6 +285,7 @@ export type BlokRuntimeContext = {
|
|
|
272
285
|
setFetchMoreQuery: (fetchMore: ((name: string, variables: Record<string, unknown>) => void) | undefined) => void;
|
|
273
286
|
setAnswerTask: (answer: ((values: Record<string, unknown>) => unknown) | undefined) => void;
|
|
274
287
|
setStartRun: (start: (() => unknown) | undefined) => void;
|
|
288
|
+
setPickDependencies: (pick: BlokPickDependenciesHandler | undefined) => void;
|
|
275
289
|
setWritePort: (write: ((operation: BlokPortOperation, value?: unknown) => unknown) | undefined) => void;
|
|
276
290
|
setControlTask: (control: ((operation: BlokTaskControl) => unknown) | undefined) => void;
|
|
277
291
|
agentMappingStateUpdates: BlokAgentMappingStateUpdates;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
-
import {act, cleanup, render, screen} from '@testing-library/react';
|
|
2
|
+
import {act, cleanup, fireEvent, render, screen} from '@testing-library/react';
|
|
3
3
|
import {afterEach, describe, expect, it} from 'vitest';
|
|
4
4
|
import {parseBsx} from '../bsx/parse';
|
|
5
5
|
import BlokRenderer from './BlokRenderer';
|
|
@@ -73,3 +73,36 @@ describe('an unbound dependency', () => {
|
|
|
73
73
|
expect((screen.getByRole('button') as HTMLButtonElement).disabled).toBe(true);
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
|
+
|
|
77
|
+
describe('the dependencies an agent blok declares', () => {
|
|
78
|
+
const source =
|
|
79
|
+
'<Blok kind="agent" context="panel"><dependencies key="cells" like="self.analyze" /><Button label="Go" onClick={self.analyze(tiles: 3) with cells} /><Button label="Pick" onClick={cells.pick(microscope: "7")} /></Blok>';
|
|
80
|
+
|
|
81
|
+
it('draw nothing, are handed to a run (given) and are picked through the host', () => {
|
|
82
|
+
const dispatched: unknown[] = [];
|
|
83
|
+
const picked: unknown[] = [];
|
|
84
|
+
const {container} = render(
|
|
85
|
+
<BlokRenderer catalog={testCatalog()}
|
|
86
|
+
uiComponents={tree(source)}
|
|
87
|
+
dispatchAction={action => void dispatched.push(action)}
|
|
88
|
+
pickDependencies={(key, picks) => void picked.push([key, picks])}
|
|
89
|
+
/>,
|
|
90
|
+
);
|
|
91
|
+
expect(container.textContent).toBe('GoPick');
|
|
92
|
+
fireEvent.click(screen.getByRole('button', {name: 'Go'}));
|
|
93
|
+
expect(dispatched).toEqual([{dependency: 'self', operation: 'analyze', arguments: {tiles: 3}, given: 'cells'}]);
|
|
94
|
+
fireEvent.click(screen.getByRole('button', {name: 'Pick'}));
|
|
95
|
+
expect(picked).toEqual([['cells', {microscope: '7'}]]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('disable a call they are handed to while one of them is bound to no agent', () => {
|
|
99
|
+
render(
|
|
100
|
+
<BlokRenderer catalog={testCatalog()}
|
|
101
|
+
uiComponents={tree(source)}
|
|
102
|
+
unavailableDependencies={new Map([['cells__microscope', 'No agent is bound to "cells.microscope", so this does nothing']])}
|
|
103
|
+
/>,
|
|
104
|
+
);
|
|
105
|
+
expect((screen.getByRole('button', {name: 'Go'}) as HTMLButtonElement).disabled).toBe(true);
|
|
106
|
+
expect((screen.getByRole('button', {name: 'Pick'}) as HTMLButtonElement).disabled).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
});
|