@superpanel-sdk/runtime 0.2.2 → 0.5.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/README.md +28 -8
- package/dist/builder/codegen/emit.d.ts +29 -11
- package/dist/builder/codegen/emit.js +328 -61
- package/dist/builder/codegen/generate.d.ts +21 -0
- package/dist/builder/codegen/generate.js +152 -20
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +24 -0
- package/dist/builder/company-imports.js +114 -0
- package/dist/builder/compile/compile-sequence.d.ts +59 -8
- package/dist/builder/compile/compile-sequence.js +279 -77
- package/dist/builder/compile/function-code.d.ts +12 -2
- package/dist/builder/compile/function-code.js +87 -39
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +24 -23
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +250 -61
- package/dist/builder/paths.d.ts +3 -0
- package/dist/builder/paths.js +16 -0
- package/dist/builder/schedules.d.ts +23 -0
- package/dist/builder/schedules.js +102 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +105 -0
- package/dist/builder/types.d.ts +91 -19
- package/dist/builder/types.js +2 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/index.js +28 -8
- package/dist/cli/serve/index.d.ts +73 -3
- package/dist/cli/serve/index.js +410 -113
- package/dist/cli/type-gen/index.js +9 -8
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +15 -23
- package/dist/compute-host/compute-host.js +25 -28
- package/dist/compute-host/index.d.ts +2 -2
- package/dist/compute-host/index.js +1 -1
- package/dist/compute-host/source-compute-host.d.ts +11 -9
- package/dist/compute-host/source-compute-host.js +50 -31
- package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
- package/dist/core/case-orchestrator/contact-hours.js +108 -0
- package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
- package/dist/core/case-orchestrator/follow-ups.js +103 -0
- package/dist/core/case-orchestrator/index.d.ts +6 -0
- package/dist/core/case-orchestrator/index.js +6 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +239 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/tools.d.ts +29 -0
- package/dist/core/case-orchestrator/tools.js +31 -0
- package/dist/core/case-orchestrator/types.d.ts +753 -0
- package/dist/core/case-orchestrator/types.js +46 -0
- package/dist/core/case-orchestrator/validate.d.ts +11 -0
- package/dist/core/case-orchestrator/validate.js +63 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +159 -0
- package/dist/core/context/email-message.js +59 -0
- package/dist/core/context/email.d.ts +97 -0
- package/dist/core/context/email.js +91 -0
- package/dist/core/context/exchanges.d.ts +142 -0
- package/dist/core/context/exchanges.js +63 -0
- package/dist/core/context/instances.d.ts +278 -0
- package/dist/core/context/instances.js +123 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +509 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +147 -0
- package/dist/core/context/sms.js +57 -0
- package/dist/core/context/types.d.ts +51 -30
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +31 -0
- package/dist/core/conversation/index.js +14 -0
- package/dist/core/functions/define/bind.d.ts +25 -0
- package/dist/core/functions/define/bind.js +14 -0
- package/dist/core/functions/define/case.d.ts +9 -0
- package/dist/core/functions/define/case.js +13 -0
- package/dist/core/functions/define/events.d.ts +20 -0
- package/dist/core/functions/define/events.js +21 -0
- package/dist/core/functions/define/no-case.d.ts +4 -0
- package/dist/core/functions/define/no-case.js +9 -0
- package/dist/core/functions/events.d.ts +247 -0
- package/dist/core/functions/events.js +32 -0
- package/dist/core/functions/func-ref.d.ts +11 -2
- package/dist/core/functions/schedules.d.ts +51 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +62 -51
- package/dist/core/functions/types.js +6 -1
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +834 -0
- package/dist/core/page/define.js +477 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/render.d.ts +253 -0
- package/dist/core/page/render.js +840 -0
- package/dist/core/page/time-format.d.ts +19 -0
- package/dist/core/page/time-format.js +41 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +642 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +33 -0
- package/dist/core/page/workspace.js +231 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +137 -0
- package/dist/core/party/schema.js +80 -0
- package/dist/core/party/types.d.ts +40 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +57 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +113 -0
- package/dist/core/slot/company-metadata.js +563 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -24
- package/dist/core/slot/field.js +0 -69
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +16 -0
- package/dist/core/slot/schema-compat.js +112 -0
- package/dist/core/slot/schema.d.ts +409 -76
- package/dist/core/slot/schema.js +178 -10
- package/dist/core/slot/types.d.ts +27 -92
- package/dist/core/slot/value.d.ts +26 -3
- package/dist/core/slot/value.js +89 -57
- package/dist/dev-overlay/protocol.d.ts +41 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +20 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +11 -4
- package/dist/fn-context/fake/index.js +27 -2
- package/dist/fn-context/fn-params.d.ts +6 -0
- package/dist/fn-context/fn-params.js +13 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +18 -8
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
- package/dist/fn-context/rpc/index.d.ts +3 -1
- package/dist/fn-context/rpc/index.js +3 -1
- package/dist/fn-context/rpc/integration/index.d.ts +4 -4
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/platform.d.ts +2 -2
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +78 -0
- package/dist/fn-context/rpc/records.js +26 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-client.js +89 -5
- package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +36 -3
- package/dist/index.d.ts +37 -46
- package/dist/index.js +33 -33
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +41 -0
- package/dist/platform.d.ts +76 -0
- package/dist/platform.js +56 -0
- package/dist/voice-service/actions.d.ts +71 -4
- package/dist/voice-service/types.d.ts +42 -2
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +10 -0
- package/package.json +38 -19
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -59
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -41
- package/dist/core/slot/write.js +0 -319
- package/dist/core/stage/builders.d.ts +0 -36
- package/dist/core/stage/builders.js +0 -28
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -77
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -464
- package/dist/core/stage/index.d.ts +0 -11
- package/dist/core/stage/index.js +0 -10
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -14
- package/dist/core/stage/transfer-fields.js +0 -88
- package/dist/core/stage/types.d.ts +0 -177
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -226
- package/dist/core/stage/walk.d.ts +0 -34
- package/dist/core/stage/walk.js +0 -96
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
package/dist/core/stage/drive.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { evaluateWhen } from './finish-when.js';
|
|
2
|
-
import { unresolvedFinishWhenFields, walkAgenda } from './walk.js';
|
|
3
|
-
export const DEFAULT_MAX_ACTIONS_PER_TURN = 10;
|
|
4
|
-
/**
|
|
5
|
-
* Walk until a topic/transfer/complete, executing actions inline.
|
|
6
|
-
* Action returning null is skipped for this tick; writes trigger a full re-walk.
|
|
7
|
-
*/
|
|
8
|
-
export async function driveAgenda(items, state, compute, hooks, options = {}) {
|
|
9
|
-
const maxActions = options.maxActions ?? DEFAULT_MAX_ACTIONS_PER_TURN;
|
|
10
|
-
let snapshot = state.snapshot;
|
|
11
|
-
let currentPlacementId = state.currentPlacementId;
|
|
12
|
-
const skip = new Set();
|
|
13
|
-
let actionsRun = 0;
|
|
14
|
-
let lastWalk = await walkAgenda(items, snapshot, { currentPlacementId, compute, skipPlacementIds: skip });
|
|
15
|
-
while (true) {
|
|
16
|
-
lastWalk = await walkAgenda(items, snapshot, { currentPlacementId, compute, skipPlacementIds: skip });
|
|
17
|
-
const hit = lastWalk.hit;
|
|
18
|
-
if (!hit || hit.kind === 'topic' || hit.kind === 'transfer') {
|
|
19
|
-
return {
|
|
20
|
-
snapshot,
|
|
21
|
-
currentPlacementId: hit?.placementId ?? currentPlacementId,
|
|
22
|
-
walk: lastWalk,
|
|
23
|
-
actionsRun,
|
|
24
|
-
fused: false,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
if (actionsRun >= maxActions) {
|
|
28
|
-
return {
|
|
29
|
-
snapshot,
|
|
30
|
-
currentPlacementId: hit.placementId,
|
|
31
|
-
walk: lastWalk,
|
|
32
|
-
actionsRun,
|
|
33
|
-
fused: true,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
actionsRun += 1;
|
|
37
|
-
const writes = await hooks.runAction(hit, snapshot);
|
|
38
|
-
if (writes && Object.keys(writes).length > 0) {
|
|
39
|
-
snapshot = await hooks.applyWrites(writes, snapshot);
|
|
40
|
-
skip.clear();
|
|
41
|
-
currentPlacementId = hit.placementId;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
skip.add(hit.placementId);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export async function advanceAgenda(items, state, compute, hooks, options = {}) {
|
|
48
|
-
const current = (state.currentPlacementId ? items.find((item) => item.placementId === state.currentPlacementId) : null) ??
|
|
49
|
-
(await walkAgenda(items, state.snapshot, { compute })).hit;
|
|
50
|
-
if (current?.kind === 'topic') {
|
|
51
|
-
const finished = await evaluateWhen(current.finishWhen, state.snapshot, compute);
|
|
52
|
-
if (!finished.done) {
|
|
53
|
-
return {
|
|
54
|
-
ok: false,
|
|
55
|
-
missing: await unresolvedFinishWhenFields(current, state.snapshot, compute),
|
|
56
|
-
item: current,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const drive = await driveAgenda(items, state, compute, hooks, options);
|
|
61
|
-
return { ok: true, drive };
|
|
62
|
-
}
|
|
63
|
-
export async function watchdogHint(item, snapshot, compute) {
|
|
64
|
-
if (!item || item.kind !== 'topic')
|
|
65
|
-
return null;
|
|
66
|
-
const finished = await evaluateWhen(item.finishWhen, snapshot, compute);
|
|
67
|
-
if (!finished.done)
|
|
68
|
-
return null;
|
|
69
|
-
return 'This section is complete. Wrap up naturally and advance.';
|
|
70
|
-
}
|
|
71
|
-
export function transferWrites(item, result) {
|
|
72
|
-
return {
|
|
73
|
-
[item.resultField]: result,
|
|
74
|
-
'session.last_transfer_result': result,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=drive.js.map
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FuncMap } from '../functions/types.js';
|
|
2
|
-
import type { ComputeHost } from '../../compute-host/compute-host.js';
|
|
3
|
-
import type { FieldPath } from '../slot/path.js';
|
|
4
|
-
import type { RuntimeSlotsSnapshot } from '../slot/types.js';
|
|
5
|
-
import { type ConditionEval } from './condition.js';
|
|
6
|
-
import type { AuthoringWhen, CompiledWhen, When } from './types.js';
|
|
7
|
-
export declare function compileWhen(raw: When, functions?: FuncMap): CompiledWhen;
|
|
8
|
-
export declare function compileAuthoringWhen(raw: AuthoringWhen, functions?: FuncMap): CompiledWhen;
|
|
9
|
-
export declare function andCompiledWhen(a: CompiledWhen, b: CompiledWhen): CompiledWhen;
|
|
10
|
-
export declare function notAnyWhen(items: CompiledWhen[]): CompiledWhen;
|
|
11
|
-
export declare function whenFields(when: CompiledWhen): FieldPath[];
|
|
12
|
-
export type WhenEval = ConditionEval & {
|
|
13
|
-
done: boolean;
|
|
14
|
-
};
|
|
15
|
-
export declare function evaluateWhen(when: CompiledWhen, snapshot: RuntimeSlotsSnapshot, compute?: ComputeHost): Promise<WhenEval>;
|
|
16
|
-
export declare const compileFinishWhen: typeof compileWhen;
|
|
17
|
-
export declare const evaluateFinishWhen: typeof evaluateWhen;
|
|
18
|
-
export declare const finishWhenFields: typeof whenFields;
|
|
19
|
-
export type FinishWhenEval = WhenEval;
|
|
20
|
-
//# sourceMappingURL=finish-when.d.ts.map
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { resolveFuncName } from '../functions/func-ref.js';
|
|
2
|
-
import { collectJsonRulesFacts, evaluateJsonRules, isOtherwise, looksLikeJsonRules, normalizeJsonRules, parseJsonRules, } from './condition.js';
|
|
3
|
-
function isDefinedFunc(value) {
|
|
4
|
-
return (value != null &&
|
|
5
|
-
typeof value === 'object' &&
|
|
6
|
-
'kind' in value &&
|
|
7
|
-
'main' in value &&
|
|
8
|
-
(value.kind === 'compute' || value.kind === 'boolCompute' || value.kind === 'custom' || value.kind === 'system'));
|
|
9
|
-
}
|
|
10
|
-
export function compileWhen(raw, functions) {
|
|
11
|
-
if (raw == null)
|
|
12
|
-
return { kind: 'always' };
|
|
13
|
-
if (typeof raw === 'string') {
|
|
14
|
-
if (looksLikeJsonRules(raw)) {
|
|
15
|
-
return { kind: 'rules', condition: parseJsonRules(raw) };
|
|
16
|
-
}
|
|
17
|
-
if (!raw)
|
|
18
|
-
throw new Error('When function name must be a non-empty string');
|
|
19
|
-
return { kind: 'fn', fn: raw };
|
|
20
|
-
}
|
|
21
|
-
if (isDefinedFunc(raw)) {
|
|
22
|
-
return { kind: 'fn', fn: resolveFuncName(raw, functions) };
|
|
23
|
-
}
|
|
24
|
-
return { kind: 'rules', condition: normalizeJsonRules(raw) };
|
|
25
|
-
}
|
|
26
|
-
export function compileAuthoringWhen(raw, functions) {
|
|
27
|
-
if (isOtherwise(raw)) {
|
|
28
|
-
const items = (raw.notAny ?? []).map((item) => compileWhen(item, functions));
|
|
29
|
-
return notAnyWhen(items);
|
|
30
|
-
}
|
|
31
|
-
return compileWhen(raw, functions);
|
|
32
|
-
}
|
|
33
|
-
export function andCompiledWhen(a, b) {
|
|
34
|
-
if (a.kind === 'always')
|
|
35
|
-
return b;
|
|
36
|
-
if (b.kind === 'always')
|
|
37
|
-
return a;
|
|
38
|
-
if (a.kind === 'rules' && b.kind === 'rules') {
|
|
39
|
-
return { kind: 'rules', condition: { all: [a.condition, b.condition] } };
|
|
40
|
-
}
|
|
41
|
-
throw new Error('Cannot combine boolFunction with another when; use json-rules all/any/not');
|
|
42
|
-
}
|
|
43
|
-
export function notAnyWhen(items) {
|
|
44
|
-
if (items.length === 0)
|
|
45
|
-
return { kind: 'always' };
|
|
46
|
-
if (!items.every((item) => item.kind === 'rules')) {
|
|
47
|
-
throw new Error('otherwise() siblings must be json-rules; use json-rules any/not');
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
kind: 'rules',
|
|
51
|
-
condition: { not: { any: items.map((item) => item.condition) } },
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export function whenFields(when) {
|
|
55
|
-
if (when.kind !== 'rules')
|
|
56
|
-
return [];
|
|
57
|
-
return collectJsonRulesFacts(when.condition);
|
|
58
|
-
}
|
|
59
|
-
export async function evaluateWhen(when, snapshot, compute) {
|
|
60
|
-
if (when.kind === 'always')
|
|
61
|
-
return { done: true, pass: true, failedFields: [] };
|
|
62
|
-
if (when.kind === 'rules') {
|
|
63
|
-
const caseContext = compute ? await compute.execute('caseContextView', [snapshot]) : snapshot;
|
|
64
|
-
const result = await evaluateJsonRules(when.condition, caseContext);
|
|
65
|
-
return { ...result, done: result.pass };
|
|
66
|
-
}
|
|
67
|
-
if (when.kind === 'fn') {
|
|
68
|
-
if (!compute)
|
|
69
|
-
throw new Error(`when fn '${when.fn}' requires a ComputeHost`);
|
|
70
|
-
const raw = await compute.execute(when.fn, [snapshot]);
|
|
71
|
-
if (typeof raw !== 'boolean') {
|
|
72
|
-
throw new Error(`when fn '${when.fn}' must return boolean, got ${typeof raw}`);
|
|
73
|
-
}
|
|
74
|
-
return { done: raw, pass: raw, failedFields: [] };
|
|
75
|
-
}
|
|
76
|
-
const _exhaustive = when;
|
|
77
|
-
return _exhaustive;
|
|
78
|
-
}
|
|
79
|
-
export const compileFinishWhen = compileWhen;
|
|
80
|
-
export const evaluateFinishWhen = evaluateWhen;
|
|
81
|
-
export const finishWhenFields = whenFields;
|
|
82
|
-
//# sourceMappingURL=finish-when.js.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { FuncMap } from '../functions/types.js';
|
|
2
|
-
import type { ValidationIssue } from '../slot/types.js';
|
|
3
|
-
import type { AgendaBlock, AgendaTree, AuthoringNode, CompiledAgendaBlock, FlatAgendaItem, SequenceAgendas, Placement } from './types.js';
|
|
4
|
-
export type FlattenOptions = {
|
|
5
|
-
functions?: FuncMap;
|
|
6
|
-
};
|
|
7
|
-
export type FlattenResult = {
|
|
8
|
-
items: FlatAgendaItem[];
|
|
9
|
-
blocks: Record<string, CompiledAgendaBlock>;
|
|
10
|
-
issues: ValidationIssue[];
|
|
11
|
-
};
|
|
12
|
-
/** Extract reusable blocks from an inline agenda tree. */
|
|
13
|
-
export declare function extractBlocksFromTree(tree: AuthoringNode[], blocks?: Record<string, AgendaBlock>): Record<string, AgendaBlock>;
|
|
14
|
-
export declare function flattenAgendaTree(tree: AuthoringNode[], options?: FlattenOptions): FlattenResult;
|
|
15
|
-
export declare function flattenAgendaPlacements(placements: Placement[], blocks: Record<string, AgendaBlock>, options?: FlattenOptions): FlattenResult;
|
|
16
|
-
export declare function flattenAgendaConfig(config: {
|
|
17
|
-
placements?: Placement[];
|
|
18
|
-
tree?: AuthoringNode[];
|
|
19
|
-
}, blocks: Record<string, AgendaBlock>, options?: FlattenOptions): FlattenResult;
|
|
20
|
-
export declare function treeToPlacements(tree: AuthoringNode[]): {
|
|
21
|
-
blocks: Record<string, AgendaBlock>;
|
|
22
|
-
placements: Placement[];
|
|
23
|
-
};
|
|
24
|
-
export declare function isAgendaTree(value: unknown): value is AgendaTree;
|
|
25
|
-
export declare function isSequenceAgendas(value: unknown): value is SequenceAgendas;
|
|
26
|
-
export declare function normalizeSequenceAgendas(value: unknown): SequenceAgendas;
|
|
27
|
-
//# sourceMappingURL=flatten.d.ts.map
|
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
import { resolveFuncName } from '../functions/func-ref.js';
|
|
2
|
-
import { isOtherwise, jsonRules } from './condition.js';
|
|
3
|
-
import { andCompiledWhen, compileAuthoringWhen, compileWhen, whenFields } from './finish-when.js';
|
|
4
|
-
import { transferResultField } from './transfer-fields.js';
|
|
5
|
-
function isTopicNode(node) {
|
|
6
|
-
return node.kind === 'topic';
|
|
7
|
-
}
|
|
8
|
-
function isActionNode(node) {
|
|
9
|
-
return node.kind === 'action';
|
|
10
|
-
}
|
|
11
|
-
function isTransferNode(node) {
|
|
12
|
-
return node.kind === 'transfer';
|
|
13
|
-
}
|
|
14
|
-
function isSectionNode(node) {
|
|
15
|
-
return node.kind === 'section';
|
|
16
|
-
}
|
|
17
|
-
function applyWhenOf(node) {
|
|
18
|
-
if (node.kind === 'branch' || node.kind === 'switchOn')
|
|
19
|
-
return null;
|
|
20
|
-
return node.applyWhen;
|
|
21
|
-
}
|
|
22
|
-
function toAgendaBlock(node) {
|
|
23
|
-
if (node.kind === 'topic') {
|
|
24
|
-
return {
|
|
25
|
-
kind: 'topic',
|
|
26
|
-
id: node.id,
|
|
27
|
-
label: node.label,
|
|
28
|
-
instructions: node.instructions,
|
|
29
|
-
fields: node.fields,
|
|
30
|
-
finishWhen: node.finishWhen,
|
|
31
|
-
onNoProgress: node.onNoProgress,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (node.kind === 'action') {
|
|
35
|
-
return {
|
|
36
|
-
kind: 'action',
|
|
37
|
-
id: node.id,
|
|
38
|
-
label: node.label,
|
|
39
|
-
run: node.run,
|
|
40
|
-
finishWhen: node.finishWhen,
|
|
41
|
-
say: node.say,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
kind: 'transfer',
|
|
46
|
-
id: node.id,
|
|
47
|
-
label: node.label,
|
|
48
|
-
numbers: node.numbers,
|
|
49
|
-
mode: node.mode,
|
|
50
|
-
say: node.say,
|
|
51
|
-
unsuccessfulSay: node.unsuccessfulSay,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function compileBlock(block, functions, issues, path) {
|
|
55
|
-
try {
|
|
56
|
-
if (block.kind === 'topic') {
|
|
57
|
-
const finishWhen = compileWhen(block.finishWhen, functions);
|
|
58
|
-
const fields = block.fields ?? whenFields(finishWhen);
|
|
59
|
-
return { ...block, fields, finishWhen };
|
|
60
|
-
}
|
|
61
|
-
if (block.kind === 'action') {
|
|
62
|
-
const finishWhen = compileWhen(block.finishWhen, functions);
|
|
63
|
-
const run = resolveFuncName(block.run, functions);
|
|
64
|
-
return { ...block, run, finishWhen };
|
|
65
|
-
}
|
|
66
|
-
const resultField = transferResultField(block.id);
|
|
67
|
-
const finishWhen = compileWhen(jsonRules({
|
|
68
|
-
fact: resultField,
|
|
69
|
-
path: '$.state',
|
|
70
|
-
operator: 'in',
|
|
71
|
-
value: ['filled', 'asked_unknown', 'declined'],
|
|
72
|
-
}), functions);
|
|
73
|
-
return { ...block, finishWhen, resultField };
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
issues.push({
|
|
77
|
-
code: 'invalid-finish-when',
|
|
78
|
-
message: error instanceof Error ? error.message : String(error),
|
|
79
|
-
path,
|
|
80
|
-
});
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function registerBlock(block, compiled, functions, issues, path) {
|
|
85
|
-
const existing = compiled[block.id];
|
|
86
|
-
if (existing && existing.kind !== block.kind) {
|
|
87
|
-
issues.push({
|
|
88
|
-
code: 'block-kind-mismatch',
|
|
89
|
-
message: `Block ${block.id} kind mismatch`,
|
|
90
|
-
path,
|
|
91
|
-
});
|
|
92
|
-
return existing;
|
|
93
|
-
}
|
|
94
|
-
const next = compileBlock(block, functions, issues, path);
|
|
95
|
-
if (!next)
|
|
96
|
-
return existing ?? null;
|
|
97
|
-
compiled[block.id] = next;
|
|
98
|
-
return next;
|
|
99
|
-
}
|
|
100
|
-
function expandSugar(nodes, issues, path) {
|
|
101
|
-
const out = [];
|
|
102
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
103
|
-
const node = nodes[i];
|
|
104
|
-
const childPath = `${path}[${i}]`;
|
|
105
|
-
if (node.kind === 'branch') {
|
|
106
|
-
out.push(...expandBranch(node, issues, childPath));
|
|
107
|
-
}
|
|
108
|
-
else if (node.kind === 'switchOn') {
|
|
109
|
-
out.push(...expandSwitchOn(node, issues, childPath));
|
|
110
|
-
}
|
|
111
|
-
else if (node.kind === 'section') {
|
|
112
|
-
out.push({ ...node, children: expandSugar(node.children, issues, `${childPath}/${node.id}`) });
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
out.push(node);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return out;
|
|
119
|
-
}
|
|
120
|
-
function expandBranch(node, issues, path) {
|
|
121
|
-
const children = expandSugar(node.children, issues, path);
|
|
122
|
-
const otherwiseIndexes = [];
|
|
123
|
-
for (let i = 0; i < children.length; i++) {
|
|
124
|
-
if (isOtherwise(applyWhenOf(children[i])))
|
|
125
|
-
otherwiseIndexes.push(i);
|
|
126
|
-
}
|
|
127
|
-
if (otherwiseIndexes.length > 1) {
|
|
128
|
-
issues.push({
|
|
129
|
-
code: 'otherwise-not-unique',
|
|
130
|
-
message: 'branch() otherwise must appear at most once',
|
|
131
|
-
path,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
if (otherwiseIndexes.length === 1 && otherwiseIndexes[0] !== children.length - 1) {
|
|
135
|
-
issues.push({
|
|
136
|
-
code: 'otherwise-not-last',
|
|
137
|
-
message: 'branch() otherwise must be last',
|
|
138
|
-
path,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
const explicit = children.filter((child) => !isOtherwise(applyWhenOf(child)));
|
|
142
|
-
if (explicit.length === 0) {
|
|
143
|
-
issues.push({
|
|
144
|
-
code: 'branch-no-explicit',
|
|
145
|
-
message: 'branch() needs at least one explicit condition branch',
|
|
146
|
-
path,
|
|
147
|
-
});
|
|
148
|
-
return children;
|
|
149
|
-
}
|
|
150
|
-
const explicitWhens = [];
|
|
151
|
-
for (const child of explicit) {
|
|
152
|
-
const when = applyWhenOf(child);
|
|
153
|
-
if (when == null) {
|
|
154
|
-
issues.push({
|
|
155
|
-
code: 'branch-null-sibling',
|
|
156
|
-
message: 'branch() explicit sibling cannot have applyWhen: null',
|
|
157
|
-
path,
|
|
158
|
-
});
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
if (isOtherwise(when))
|
|
162
|
-
continue;
|
|
163
|
-
explicitWhens.push(when);
|
|
164
|
-
}
|
|
165
|
-
if (otherwiseIndexes.length === 1 && explicitWhens.length > 0) {
|
|
166
|
-
const index = otherwiseIndexes[0];
|
|
167
|
-
const child = children[index];
|
|
168
|
-
children[index] = withApplyWhen(child, { op: 'otherwise', notAny: explicitWhens });
|
|
169
|
-
}
|
|
170
|
-
return children;
|
|
171
|
-
}
|
|
172
|
-
function expandSwitchOn(node, issues, path) {
|
|
173
|
-
const children = [];
|
|
174
|
-
for (const [key, tree] of Object.entries(node.cases)) {
|
|
175
|
-
children.push({
|
|
176
|
-
kind: 'section',
|
|
177
|
-
id: key,
|
|
178
|
-
label: key,
|
|
179
|
-
applyWhen: jsonRules({ fact: node.field, operator: 'equal', value: key }),
|
|
180
|
-
children: tree,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (node.otherwise) {
|
|
184
|
-
children.push({
|
|
185
|
-
kind: 'section',
|
|
186
|
-
id: 'otherwise',
|
|
187
|
-
label: 'otherwise',
|
|
188
|
-
applyWhen: { op: 'otherwise' },
|
|
189
|
-
children: node.otherwise,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
return expandBranch({ kind: 'branch', children }, issues, path);
|
|
193
|
-
}
|
|
194
|
-
function withApplyWhen(node, applyWhen) {
|
|
195
|
-
if (node.kind === 'branch' || node.kind === 'switchOn')
|
|
196
|
-
return node;
|
|
197
|
-
return { ...node, applyWhen };
|
|
198
|
-
}
|
|
199
|
-
function tryCompileAuthoringWhen(raw, functions, issues, path) {
|
|
200
|
-
try {
|
|
201
|
-
return compileAuthoringWhen(raw, functions);
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
issues.push({
|
|
205
|
-
code: 'invalid-apply-when',
|
|
206
|
-
message: error instanceof Error ? error.message : String(error),
|
|
207
|
-
path,
|
|
208
|
-
});
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
function uniquePlacementId(base, used) {
|
|
213
|
-
if (!used.has(base)) {
|
|
214
|
-
used.add(base);
|
|
215
|
-
return base;
|
|
216
|
-
}
|
|
217
|
-
let i = 2;
|
|
218
|
-
while (used.has(`${base}-${i}`))
|
|
219
|
-
i += 1;
|
|
220
|
-
const id = `${base}-${i}`;
|
|
221
|
-
used.add(id);
|
|
222
|
-
return id;
|
|
223
|
-
}
|
|
224
|
-
function flattenAuthoring(nodes, inherited, groupPath, compiled, functions, issues, usedIds, path) {
|
|
225
|
-
const expanded = expandSugar(nodes, issues, path);
|
|
226
|
-
const items = [];
|
|
227
|
-
for (let i = 0; i < expanded.length; i++) {
|
|
228
|
-
const node = expanded[i];
|
|
229
|
-
const childPath = `${path}[${i}]`;
|
|
230
|
-
if (isSectionNode(node)) {
|
|
231
|
-
if (isOtherwise(node.applyWhen) && node.applyWhen.notAny == null) {
|
|
232
|
-
issues.push({
|
|
233
|
-
code: 'otherwise-unexpanded',
|
|
234
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
235
|
-
path: childPath,
|
|
236
|
-
});
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const compiledWhen = tryCompileAuthoringWhen(node.applyWhen, functions, issues, childPath);
|
|
240
|
-
if (!compiledWhen)
|
|
241
|
-
continue;
|
|
242
|
-
const merged = andCompiledWhen(inherited, compiledWhen);
|
|
243
|
-
const sectionId = uniquePlacementId(node.id, usedIds);
|
|
244
|
-
items.push(...flattenAuthoring(node.children, merged, [...groupPath, sectionId], compiled, functions, issues, usedIds, `${childPath}/${node.id}`));
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (node.kind === 'branch') {
|
|
248
|
-
items.push(...flattenAuthoring(node.children, inherited, groupPath, compiled, functions, issues, usedIds, childPath));
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
if (node.kind === 'switchOn') {
|
|
252
|
-
items.push(...flattenAuthoring(expandSwitchOn(node, issues, childPath), inherited, groupPath, compiled, functions, issues, usedIds, childPath));
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
if (isOtherwise(node.applyWhen) && node.applyWhen.notAny == null) {
|
|
256
|
-
issues.push({
|
|
257
|
-
code: 'otherwise-unexpanded',
|
|
258
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
259
|
-
path: childPath,
|
|
260
|
-
});
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
const compiledBlock = registerBlock(toAgendaBlock(node), compiled, functions, issues, childPath);
|
|
264
|
-
if (!compiledBlock)
|
|
265
|
-
continue;
|
|
266
|
-
const compiledWhen = tryCompileAuthoringWhen(node.applyWhen, functions, issues, childPath);
|
|
267
|
-
if (!compiledWhen)
|
|
268
|
-
continue;
|
|
269
|
-
const placementId = uniquePlacementId(node.id, usedIds);
|
|
270
|
-
items.push({
|
|
271
|
-
...compiledBlock,
|
|
272
|
-
placementId,
|
|
273
|
-
applyWhen: andCompiledWhen(inherited, compiledWhen),
|
|
274
|
-
groupPath,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
return items;
|
|
278
|
-
}
|
|
279
|
-
function flattenPlacements(placements, blocks, inherited, groupPath, compiled, functions, issues, usedIds, path) {
|
|
280
|
-
const items = [];
|
|
281
|
-
for (let i = 0; i < placements.length; i++) {
|
|
282
|
-
const placement = placements[i];
|
|
283
|
-
const childPath = `${path}[${i}]`;
|
|
284
|
-
if (placement.kind === 'section') {
|
|
285
|
-
if (isOtherwise(placement.applyWhen) && placement.applyWhen.notAny == null) {
|
|
286
|
-
issues.push({
|
|
287
|
-
code: 'otherwise-unexpanded',
|
|
288
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
289
|
-
path: childPath,
|
|
290
|
-
});
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
const compiledWhen = tryCompileAuthoringWhen(placement.applyWhen, functions, issues, childPath);
|
|
294
|
-
if (!compiledWhen)
|
|
295
|
-
continue;
|
|
296
|
-
const merged = andCompiledWhen(inherited, compiledWhen);
|
|
297
|
-
const sectionId = uniquePlacementId(placement.placementId, usedIds);
|
|
298
|
-
items.push(...flattenPlacements(placement.children, blocks, merged, [...groupPath, sectionId], compiled, functions, issues, usedIds, `${childPath}/${placement.placementId}`));
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
const block = blocks[placement.blockId];
|
|
302
|
-
if (!block) {
|
|
303
|
-
issues.push({
|
|
304
|
-
code: 'unknown-block',
|
|
305
|
-
message: `Unknown block: ${placement.blockId}`,
|
|
306
|
-
path: childPath,
|
|
307
|
-
});
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
if (isOtherwise(placement.applyWhen) && placement.applyWhen.notAny == null) {
|
|
311
|
-
issues.push({
|
|
312
|
-
code: 'otherwise-unexpanded',
|
|
313
|
-
message: 'otherwise() is only valid inside branch() / switchOn()',
|
|
314
|
-
path: childPath,
|
|
315
|
-
});
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
const compiledBlock = registerBlock(block, compiled, functions, issues, childPath);
|
|
319
|
-
if (!compiledBlock)
|
|
320
|
-
continue;
|
|
321
|
-
const compiledWhen = tryCompileAuthoringWhen(placement.applyWhen, functions, issues, childPath);
|
|
322
|
-
if (!compiledWhen)
|
|
323
|
-
continue;
|
|
324
|
-
const placementId = uniquePlacementId(placement.placementId, usedIds);
|
|
325
|
-
items.push({
|
|
326
|
-
...compiledBlock,
|
|
327
|
-
placementId,
|
|
328
|
-
applyWhen: andCompiledWhen(inherited, compiledWhen),
|
|
329
|
-
groupPath,
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
return items;
|
|
333
|
-
}
|
|
334
|
-
function asSectionPlacement(node, usedIds, path, issues) {
|
|
335
|
-
if (isSectionNode(node)) {
|
|
336
|
-
return {
|
|
337
|
-
kind: 'section',
|
|
338
|
-
placementId: uniquePlacementId(node.id, usedIds),
|
|
339
|
-
label: node.label,
|
|
340
|
-
applyWhen: node.applyWhen,
|
|
341
|
-
children: node.children.map((child, i) => asPlacement(child, usedIds, `${path}/${node.id}[${i}]`, issues)),
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
if (isTopicNode(node) || isActionNode(node) || isTransferNode(node)) {
|
|
345
|
-
return {
|
|
346
|
-
kind: 'node',
|
|
347
|
-
placementId: uniquePlacementId(node.id, usedIds),
|
|
348
|
-
blockId: node.id,
|
|
349
|
-
applyWhen: node.applyWhen,
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
issues.push({
|
|
353
|
-
code: 'invalid-placement',
|
|
354
|
-
message: `Cannot place ${node.kind} as a placement child before sugar expansion`,
|
|
355
|
-
path,
|
|
356
|
-
});
|
|
357
|
-
return {
|
|
358
|
-
kind: 'section',
|
|
359
|
-
placementId: uniquePlacementId('_invalid', usedIds),
|
|
360
|
-
label: '_invalid',
|
|
361
|
-
applyWhen: null,
|
|
362
|
-
children: [],
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
function asPlacement(node, usedIds, path, issues) {
|
|
366
|
-
return asSectionPlacement(node, usedIds, path, issues);
|
|
367
|
-
}
|
|
368
|
-
/** Extract reusable blocks from an inline agenda tree. */
|
|
369
|
-
export function extractBlocksFromTree(tree, blocks = {}) {
|
|
370
|
-
visit(tree);
|
|
371
|
-
return blocks;
|
|
372
|
-
function visit(nodes) {
|
|
373
|
-
for (const node of nodes) {
|
|
374
|
-
if (isTopicNode(node) || isActionNode(node) || isTransferNode(node)) {
|
|
375
|
-
blocks[node.id] = toAgendaBlock(node);
|
|
376
|
-
}
|
|
377
|
-
else if (isSectionNode(node) || node.kind === 'branch') {
|
|
378
|
-
visit(node.children);
|
|
379
|
-
}
|
|
380
|
-
else if (node.kind === 'switchOn') {
|
|
381
|
-
for (const children of Object.values(node.cases))
|
|
382
|
-
visit(children);
|
|
383
|
-
if (node.otherwise)
|
|
384
|
-
visit(node.otherwise);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
export function flattenAgendaTree(tree, options = {}) {
|
|
390
|
-
const issues = [];
|
|
391
|
-
const compiled = {};
|
|
392
|
-
const items = flattenAuthoring(tree, { kind: 'always' }, [], compiled, options.functions, issues, new Set(), 'tree');
|
|
393
|
-
return { items, blocks: compiled, issues };
|
|
394
|
-
}
|
|
395
|
-
export function flattenAgendaPlacements(placements, blocks, options = {}) {
|
|
396
|
-
const issues = [];
|
|
397
|
-
const compiled = {};
|
|
398
|
-
const items = flattenPlacements(placements, blocks, { kind: 'always' }, [], compiled, options.functions, issues, new Set(), 'placements');
|
|
399
|
-
return { items, blocks: compiled, issues };
|
|
400
|
-
}
|
|
401
|
-
export function flattenAgendaConfig(config, blocks, options = {}) {
|
|
402
|
-
if (config.tree)
|
|
403
|
-
return flattenAgendaTree(config.tree, options);
|
|
404
|
-
return flattenAgendaPlacements(config.placements ?? [], blocks, options);
|
|
405
|
-
}
|
|
406
|
-
export function treeToPlacements(tree) {
|
|
407
|
-
const issues = [];
|
|
408
|
-
const expanded = expandSugar(tree, issues, 'tree');
|
|
409
|
-
const blocks = extractBlocksFromTree(expanded);
|
|
410
|
-
const usedIds = new Set();
|
|
411
|
-
const placements = expanded.map((node, i) => asPlacement(node, usedIds, `tree[${i}]`, issues));
|
|
412
|
-
return { blocks, placements };
|
|
413
|
-
}
|
|
414
|
-
export function isAgendaTree(value) {
|
|
415
|
-
return (value != null &&
|
|
416
|
-
typeof value === 'object' &&
|
|
417
|
-
value.kind === 'agenda' &&
|
|
418
|
-
typeof value.id === 'string' &&
|
|
419
|
-
Array.isArray(value.tree));
|
|
420
|
-
}
|
|
421
|
-
export function isSequenceAgendas(value) {
|
|
422
|
-
if (value == null || typeof value !== 'object' || Array.isArray(value))
|
|
423
|
-
return false;
|
|
424
|
-
const obj = value;
|
|
425
|
-
return isPlainBlocks(obj.blocks) && isPlainAgendas(obj.agendas);
|
|
426
|
-
}
|
|
427
|
-
function isPlainBlocks(value) {
|
|
428
|
-
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
429
|
-
}
|
|
430
|
-
function isPlainAgendas(value) {
|
|
431
|
-
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
432
|
-
}
|
|
433
|
-
export function normalizeSequenceAgendas(value) {
|
|
434
|
-
if (isSequenceAgendas(value))
|
|
435
|
-
return value;
|
|
436
|
-
if (isAgendaTree(value)) {
|
|
437
|
-
const { blocks, placements } = treeToPlacements(value.tree);
|
|
438
|
-
return {
|
|
439
|
-
blocks,
|
|
440
|
-
agendas: {
|
|
441
|
-
[value.id]: { id: value.id, header: value.header, placements },
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
if (Array.isArray(value) && value.every(isAgendaTree)) {
|
|
446
|
-
const blocks = {};
|
|
447
|
-
const agendas = {};
|
|
448
|
-
for (const tree of value) {
|
|
449
|
-
const extracted = treeToPlacements(tree.tree);
|
|
450
|
-
Object.assign(blocks, extracted.blocks);
|
|
451
|
-
agendas[tree.id] = { id: tree.id, header: tree.header, placements: extracted.placements };
|
|
452
|
-
}
|
|
453
|
-
return { blocks, agendas };
|
|
454
|
-
}
|
|
455
|
-
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
|
456
|
-
const record = value;
|
|
457
|
-
const trees = Object.values(record);
|
|
458
|
-
if (trees.length > 0 && trees.every(isAgendaTree)) {
|
|
459
|
-
return normalizeSequenceAgendas(trees);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
throw new Error('Could not find agendas export as SequenceAgendas or agenda() tree');
|
|
463
|
-
}
|
|
464
|
-
//# sourceMappingURL=flatten.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type { ActionBlock, ActionNode, AgendaBlock, AgendaConfig, AgendaHeader, AgendaTree, ApplyWhen, AuthoringNode, AuthoringWhen, BranchNode, Channel, CompiledActionBlock, CompiledAgenda, CompiledAgendaBlock, CompiledTopicBlock, CompiledTransferBlock, CompiledWhen, Condition, FirstMessage, FinishWhen, FlatActionItem, FlatAgendaItem, FlatNodePlacement, FlatTopicItem, FlatTransferItem, Interrupt, SequenceAgendas, JsonRulesCondition, NodePlacement, OnNoProgress, OtherwiseSentinel, Placement, SectionNode, SectionPlacement, SwitchOnNode, TopicBlock, TopicNode, TransferBlock, TransferNode, When, } from './types.js';
|
|
2
|
-
export { collectJsonRulesFacts, evaluateJsonRules, extractTemplateFields, isOtherwise, jsonRules, looksLikeJsonRules, normalizeJsonRules, otherwise, parseJsonRules, type ConditionEval, } from './condition.js';
|
|
3
|
-
export { andCompiledWhen, compileAuthoringWhen, compileFinishWhen, compileWhen, evaluateFinishWhen, evaluateWhen, finishWhenFields, notAnyWhen, whenFields, type FinishWhenEval, type WhenEval, } from './finish-when.js';
|
|
4
|
-
export { action, agenda, branch, section, switchOn, topic, transfer } from './builders.js';
|
|
5
|
-
export { extractBlocksFromTree, flattenAgendaConfig, flattenAgendaPlacements, flattenAgendaTree, isAgendaTree, isSequenceAgendas, normalizeSequenceAgendas, treeToPlacements, type FlattenOptions, type FlattenResult, } from './flatten.js';
|
|
6
|
-
export { LAST_TRANSFER_RESULT_FIELD, collectTransferBlocks, registerTransferSessionFields, transferFieldKey, transferResultField, } from './transfer-fields.js';
|
|
7
|
-
export { fatalAgendaIssues, validateCompiledAgenda, type ValidateAgendaOptions } from './validate.js';
|
|
8
|
-
export { unresolvedFinishWhenFields, walkAgenda, type WalkDecision, type WalkHitReason, type WalkOptions, type WalkResult, type WalkSkip, type WalkSkipReason, } from './walk.js';
|
|
9
|
-
export { simulateAgenda, type SimulateResult, type SimulatedItem, type SimulatedItemStatus } from './simulate.js';
|
|
10
|
-
export { DEFAULT_MAX_ACTIONS_PER_TURN, advanceAgenda, driveAgenda, transferWrites, watchdogHint, type AdvanceResult, type StageDriveHooks, type StageDriveResult, type StageDriveState, } from './drive.js';
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|