@superpanel-sdk/runtime 0.2.3 → 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 +365 -116
- 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 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +11 -9
- package/dist/compute-host/source-compute-host.js +46 -32
- 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 -48
- 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 -94
- 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 +88 -7
- 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 -5
- 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 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- 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 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- 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 -78
- 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 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- 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 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- 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/slot/deps.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { formatFieldPath, parseFieldPath } from './path.js';
|
|
2
|
-
/**
|
|
3
|
-
* Build topological order of derived fields and reverse dependency index.
|
|
4
|
-
* Reports cycles instead of throwing.
|
|
5
|
-
*/
|
|
6
|
-
export function buildDependencyGraph(tables) {
|
|
7
|
-
const issues = [];
|
|
8
|
-
const derivedPaths = [];
|
|
9
|
-
const edges = new Map();
|
|
10
|
-
const reverseDeps = {};
|
|
11
|
-
for (const [tableName, table] of Object.entries(tables)) {
|
|
12
|
-
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
13
|
-
if (!field.derived)
|
|
14
|
-
continue;
|
|
15
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
16
|
-
derivedPaths.push(path);
|
|
17
|
-
const deps = [];
|
|
18
|
-
for (const dep of field.dependsOn) {
|
|
19
|
-
const parsed = parseFieldPath(dep);
|
|
20
|
-
if (!parsed) {
|
|
21
|
-
issues.push({
|
|
22
|
-
code: 'invalid-depends-on',
|
|
23
|
-
message: `Invalid dependsOn path: ${dep}`,
|
|
24
|
-
path,
|
|
25
|
-
});
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
deps.push(parsed.path);
|
|
29
|
-
if (!reverseDeps[parsed.path])
|
|
30
|
-
reverseDeps[parsed.path] = [];
|
|
31
|
-
reverseDeps[parsed.path].push(path);
|
|
32
|
-
}
|
|
33
|
-
edges.set(path, deps);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// Kahn topological sort over derived nodes only; edges point to dependencies.
|
|
37
|
-
const indegree = new Map();
|
|
38
|
-
const dependents = new Map();
|
|
39
|
-
for (const path of derivedPaths) {
|
|
40
|
-
indegree.set(path, 0);
|
|
41
|
-
dependents.set(path, []);
|
|
42
|
-
}
|
|
43
|
-
for (const [path, deps] of edges) {
|
|
44
|
-
for (const dep of deps) {
|
|
45
|
-
if (!indegree.has(dep))
|
|
46
|
-
continue; // dependency is a normal field
|
|
47
|
-
indegree.set(path, (indegree.get(path) ?? 0) + 1);
|
|
48
|
-
dependents.get(dep).push(path);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const queue = derivedPaths.filter((p) => (indegree.get(p) ?? 0) === 0);
|
|
52
|
-
const derivedOrder = [];
|
|
53
|
-
while (queue.length > 0) {
|
|
54
|
-
const path = queue.shift();
|
|
55
|
-
derivedOrder.push(path);
|
|
56
|
-
for (const next of dependents.get(path) ?? []) {
|
|
57
|
-
const nextDeg = (indegree.get(next) ?? 0) - 1;
|
|
58
|
-
indegree.set(next, nextDeg);
|
|
59
|
-
if (nextDeg === 0)
|
|
60
|
-
queue.push(next);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (derivedOrder.length !== derivedPaths.length) {
|
|
64
|
-
const remaining = derivedPaths.filter((p) => !derivedOrder.includes(p));
|
|
65
|
-
issues.push({
|
|
66
|
-
code: 'cyclic-dependency',
|
|
67
|
-
message: `Cyclic derived dependency involving: ${remaining.join(' → ')}`,
|
|
68
|
-
path: remaining[0],
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return { derivedOrder, reverseDeps, issues };
|
|
72
|
-
}
|
|
73
|
-
/** Collect derived fields affected by changed columns, in topo order. */
|
|
74
|
-
export function affectedDerivedFields(changed, reverseDeps, derivedOrder) {
|
|
75
|
-
const hit = new Set();
|
|
76
|
-
const stack = [...changed];
|
|
77
|
-
while (stack.length > 0) {
|
|
78
|
-
const path = stack.pop();
|
|
79
|
-
for (const derived of reverseDeps[path] ?? []) {
|
|
80
|
-
if (hit.has(derived))
|
|
81
|
-
continue;
|
|
82
|
-
hit.add(derived);
|
|
83
|
-
stack.push(derived);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return derivedOrder.filter((path) => hit.has(path));
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=deps.js.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Writes } from '../context/types.js';
|
|
2
|
-
import type { FieldPath } from './path.js';
|
|
3
|
-
import type { ApplyWritesOptions, CompiledSlotSchema, RecomputeResult, RuntimeSlotsSnapshot, SlotFillingOutput } from './types.js';
|
|
4
|
-
import { createLocalComputeHost, resolveComputeHost, type ComputeFnMap, type ComputeHost, type ComputeHostOrFns, type LocalComputeHostOptions } from '../../compute-host/compute-host.js';
|
|
5
|
-
import { createSourceComputeHost } from '../../compute-host/source-compute-host.js';
|
|
6
|
-
import { type ApplySlotFillingOptions, type FieldPatchInput } from './write.js';
|
|
7
|
-
export type { ComputeFnMap, ComputeHost, ComputeHostOrFns, LocalComputeHostOptions };
|
|
8
|
-
export { createLocalComputeHost, createSourceComputeHost, resolveComputeHost };
|
|
9
|
-
export type RecomputeOptions = {
|
|
10
|
-
now?: number;
|
|
11
|
-
/**
|
|
12
|
-
* When true, recompute every derived field in topo order (session start heal).
|
|
13
|
-
* When false (default), only fields affected by `changed`.
|
|
14
|
-
*/
|
|
15
|
-
all?: boolean;
|
|
16
|
-
changed?: Iterable<FieldPath>;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* C6: recompute derived fields in topological order via {@link ComputeHost}.
|
|
20
|
-
* `null` return means no conclusion yet (stored as filled+null).
|
|
21
|
-
*/
|
|
22
|
-
export declare function recomputeDerived(schema: CompiledSlotSchema, snapshot: RuntimeSlotsSnapshot, hostOrFns: ComputeHostOrFns, options?: RecomputeOptions): Promise<RecomputeResult>;
|
|
23
|
-
/** C4→C6: apply normal writes then recompute affected derived fields. */
|
|
24
|
-
export declare function applyWritesAndRecompute(schema: CompiledSlotSchema, snapshot: RuntimeSlotsSnapshot, writes: Writes | null | undefined, hostOrFns: ComputeHostOrFns, writeOptions: ApplyWritesOptions): Promise<RecomputeResult>;
|
|
25
|
-
/** Apply an explicit-state field edit, then recompute every affected derived field. */
|
|
26
|
-
export declare function applyFieldPatchAndRecompute(schema: CompiledSlotSchema, snapshot: RuntimeSlotsSnapshot, patch: FieldPatchInput, hostOrFns: ComputeHostOrFns, options: {
|
|
27
|
-
source: ApplyWritesOptions['source'];
|
|
28
|
-
now?: number;
|
|
29
|
-
}): Promise<RecomputeResult>;
|
|
30
|
-
/** C4→C6 for accepted Slot Filling output. */
|
|
31
|
-
export declare function applySlotFillingAndRecompute(schema: CompiledSlotSchema, snapshot: RuntimeSlotsSnapshot, output: SlotFillingOutput, hostOrFns: ComputeHostOrFns, options?: ApplySlotFillingOptions): Promise<RecomputeResult>;
|
|
32
|
-
//# sourceMappingURL=derived.d.ts.map
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { getCompiledTable, isSnapshotSingleRow } from './compile-schema.js';
|
|
2
|
-
import { createLocalComputeHost, resolveComputeHost, } from '../../compute-host/compute-host.js';
|
|
3
|
-
import { createSourceComputeHost } from '../../compute-host/source-compute-host.js';
|
|
4
|
-
import { affectedDerivedFields } from './deps.js';
|
|
5
|
-
import { commitFieldWrite, makeFieldValue } from './field.js';
|
|
6
|
-
import { requireFieldPath } from './path.js';
|
|
7
|
-
import { getRowField } from './row.js';
|
|
8
|
-
import { cloneSnapshot, getSnapshotTable } from './snapshot.js';
|
|
9
|
-
import { validateBareValue } from './value.js';
|
|
10
|
-
import { applyFieldPatch, applySlotFilling, applyWrites, } from './write.js';
|
|
11
|
-
export { createLocalComputeHost, createSourceComputeHost, resolveComputeHost };
|
|
12
|
-
/**
|
|
13
|
-
* C6: recompute derived fields in topological order via {@link ComputeHost}.
|
|
14
|
-
* `null` return means no conclusion yet (stored as filled+null).
|
|
15
|
-
*/
|
|
16
|
-
export async function recomputeDerived(schema, snapshot, hostOrFns, options = {}) {
|
|
17
|
-
const host = resolveComputeHost(hostOrFns);
|
|
18
|
-
const now = options.now ?? Date.now();
|
|
19
|
-
const next = cloneSnapshot(snapshot);
|
|
20
|
-
const changedOut = [];
|
|
21
|
-
const history = [];
|
|
22
|
-
const targets = options.all
|
|
23
|
-
? schema.derivedOrder
|
|
24
|
-
: affectedDerivedFields(options.changed ?? [], schema.reverseDeps, schema.derivedOrder);
|
|
25
|
-
for (const path of targets) {
|
|
26
|
-
const parsed = requireFieldPath(path);
|
|
27
|
-
const table = getCompiledTable(schema, parsed.table);
|
|
28
|
-
const field = table?.fields[parsed.field];
|
|
29
|
-
if (!table || !field || !field.derived)
|
|
30
|
-
continue;
|
|
31
|
-
if (!isSnapshotSingleRow(table))
|
|
32
|
-
continue;
|
|
33
|
-
const raw = await host.execute(field.computeFn, [next]);
|
|
34
|
-
const issues = validateBareValue(field, raw, path, { allowNull: true });
|
|
35
|
-
if (issues.length > 0) {
|
|
36
|
-
throw new Error(`Derived ${path} returned invalid value: ${issues.map((i) => i.message).join('; ')}`);
|
|
37
|
-
}
|
|
38
|
-
const tableData = getSnapshotTable(next, parsed.table);
|
|
39
|
-
const prev = getRowField(tableData, parsed.field);
|
|
40
|
-
if (!prev)
|
|
41
|
-
continue;
|
|
42
|
-
const committed = commitFieldWrite(prev, makeFieldValue({
|
|
43
|
-
value: (raw ?? null),
|
|
44
|
-
state: 'filled',
|
|
45
|
-
reason: null,
|
|
46
|
-
updatedBy: 'derived',
|
|
47
|
-
updatedAt: now,
|
|
48
|
-
}));
|
|
49
|
-
tableData[parsed.field] = committed.field;
|
|
50
|
-
if (committed.changed) {
|
|
51
|
-
changedOut.push(path);
|
|
52
|
-
if (committed.historyEntry) {
|
|
53
|
-
history.push({ path, entry: committed.historyEntry });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return { snapshot: next, changed: changedOut, history };
|
|
58
|
-
}
|
|
59
|
-
/** C4→C6: apply normal writes then recompute affected derived fields. */
|
|
60
|
-
export async function applyWritesAndRecompute(schema, snapshot, writes, hostOrFns, writeOptions) {
|
|
61
|
-
const applied = applyWrites(schema, snapshot, writes, writeOptions);
|
|
62
|
-
if (applied.changed.length === 0) {
|
|
63
|
-
return {
|
|
64
|
-
snapshot: applied.snapshot,
|
|
65
|
-
changed: [],
|
|
66
|
-
history: applied.history,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const recomputed = await recomputeDerived(schema, applied.snapshot, hostOrFns, {
|
|
70
|
-
now: writeOptions.now,
|
|
71
|
-
changed: applied.changed,
|
|
72
|
-
});
|
|
73
|
-
return {
|
|
74
|
-
snapshot: recomputed.snapshot,
|
|
75
|
-
changed: [...applied.changed, ...recomputed.changed],
|
|
76
|
-
history: [...applied.history, ...recomputed.history],
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/** Apply an explicit-state field edit, then recompute every affected derived field. */
|
|
80
|
-
export async function applyFieldPatchAndRecompute(schema, snapshot, patch, hostOrFns, options) {
|
|
81
|
-
const applied = applyFieldPatch(schema, snapshot, patch, options);
|
|
82
|
-
if (applied.changed.length === 0) {
|
|
83
|
-
return { snapshot: applied.snapshot, changed: [], history: applied.history };
|
|
84
|
-
}
|
|
85
|
-
const recomputed = await recomputeDerived(schema, applied.snapshot, hostOrFns, {
|
|
86
|
-
now: options.now,
|
|
87
|
-
changed: applied.changed,
|
|
88
|
-
});
|
|
89
|
-
return {
|
|
90
|
-
snapshot: recomputed.snapshot,
|
|
91
|
-
changed: [...applied.changed, ...recomputed.changed],
|
|
92
|
-
history: [...applied.history, ...recomputed.history],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/** C4→C6 for accepted Slot Filling output. */
|
|
96
|
-
export async function applySlotFillingAndRecompute(schema, snapshot, output, hostOrFns, options = {}) {
|
|
97
|
-
const applied = applySlotFilling(schema, snapshot, output, options);
|
|
98
|
-
if (applied.changed.length === 0) {
|
|
99
|
-
return {
|
|
100
|
-
snapshot: applied.snapshot,
|
|
101
|
-
changed: [],
|
|
102
|
-
history: applied.history,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const recomputed = await recomputeDerived(schema, applied.snapshot, hostOrFns, {
|
|
106
|
-
now: options.now,
|
|
107
|
-
changed: applied.changed,
|
|
108
|
-
});
|
|
109
|
-
return {
|
|
110
|
-
snapshot: recomputed.snapshot,
|
|
111
|
-
changed: [...applied.changed, ...recomputed.changed],
|
|
112
|
-
history: [...applied.history, ...recomputed.history],
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=derived.js.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { RuntimeTableDef } from './types.js';
|
|
2
|
-
export declare const PLATFORM_SESSION_FIELDS: {
|
|
3
|
-
readonly is_inbound_call: {
|
|
4
|
-
readonly derived: false;
|
|
5
|
-
readonly label: 'Inbound call';
|
|
6
|
-
readonly dataType: 'boolean';
|
|
7
|
-
readonly source: 'system';
|
|
8
|
-
readonly extraction: 'Set by the conversation entry pipeline';
|
|
9
|
-
readonly enum: null;
|
|
10
|
-
readonly nullable: false;
|
|
11
|
-
readonly identifier: null;
|
|
12
|
-
readonly ref: null;
|
|
13
|
-
};
|
|
14
|
-
readonly is_first_call: {
|
|
15
|
-
readonly derived: false;
|
|
16
|
-
readonly label: 'First call';
|
|
17
|
-
readonly dataType: 'boolean';
|
|
18
|
-
readonly source: 'system';
|
|
19
|
-
readonly extraction: 'No prior session for this case contact';
|
|
20
|
-
readonly enum: null;
|
|
21
|
-
readonly nullable: false;
|
|
22
|
-
readonly identifier: null;
|
|
23
|
-
readonly ref: null;
|
|
24
|
-
};
|
|
25
|
-
readonly is_new_user: {
|
|
26
|
-
readonly derived: false;
|
|
27
|
-
readonly label: 'New user';
|
|
28
|
-
readonly dataType: 'boolean';
|
|
29
|
-
readonly source: 'system';
|
|
30
|
-
readonly extraction: 'No existing contact for this party';
|
|
31
|
-
readonly enum: null;
|
|
32
|
-
readonly nullable: false;
|
|
33
|
-
readonly identifier: null;
|
|
34
|
-
readonly ref: null;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export declare function createPlatformSessionTable(): RuntimeTableDef;
|
|
38
|
-
//# sourceMappingURL=platform-session-fields.d.ts.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { idField } from './schema.js';
|
|
2
|
-
export const PLATFORM_SESSION_FIELDS = {
|
|
3
|
-
is_inbound_call: {
|
|
4
|
-
derived: false,
|
|
5
|
-
label: 'Inbound call',
|
|
6
|
-
dataType: 'boolean',
|
|
7
|
-
source: 'system',
|
|
8
|
-
extraction: 'Set by the conversation entry pipeline',
|
|
9
|
-
enum: null,
|
|
10
|
-
nullable: false,
|
|
11
|
-
identifier: null,
|
|
12
|
-
ref: null,
|
|
13
|
-
},
|
|
14
|
-
is_first_call: {
|
|
15
|
-
derived: false,
|
|
16
|
-
label: 'First call',
|
|
17
|
-
dataType: 'boolean',
|
|
18
|
-
source: 'system',
|
|
19
|
-
extraction: 'No prior session for this case contact',
|
|
20
|
-
enum: null,
|
|
21
|
-
nullable: false,
|
|
22
|
-
identifier: null,
|
|
23
|
-
ref: null,
|
|
24
|
-
},
|
|
25
|
-
is_new_user: {
|
|
26
|
-
derived: false,
|
|
27
|
-
label: 'New user',
|
|
28
|
-
dataType: 'boolean',
|
|
29
|
-
source: 'system',
|
|
30
|
-
extraction: 'No existing contact for this party',
|
|
31
|
-
enum: null,
|
|
32
|
-
nullable: false,
|
|
33
|
-
identifier: null,
|
|
34
|
-
ref: null,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
export function createPlatformSessionTable() {
|
|
38
|
-
return {
|
|
39
|
-
label: 'Session',
|
|
40
|
-
rows: 'single',
|
|
41
|
-
description: 'Per-conversation session fields',
|
|
42
|
-
fields: {
|
|
43
|
-
id: { ...idField, ref: null },
|
|
44
|
-
...PLATFORM_SESSION_FIELDS,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=platform-session-fields.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { FieldPath } from './path.js';
|
|
2
|
-
import type { CompiledSlotSchema } from './types.js';
|
|
3
|
-
type JsonSchema = Record<string, unknown>;
|
|
4
|
-
export type SfSchemaOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* Field paths included with full definitions.
|
|
7
|
-
* When omitted, all conversation fields are included (full-schema / hangup pass).
|
|
8
|
-
*/
|
|
9
|
-
focusFields?: Iterable<FieldPath>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Build JSON Schema for Slot Filling structured output.
|
|
13
|
-
* Derived and `source: system` fields are never included.
|
|
14
|
-
*/
|
|
15
|
-
export declare function buildSlotFillingJsonSchema(schema: CompiledSlotSchema, options?: SfSchemaOptions): JsonSchema;
|
|
16
|
-
/** Compact catalog for out-of-focus conversation fields (C1). */
|
|
17
|
-
export declare function buildFieldCatalog(schema: CompiledSlotSchema, exclude?: Iterable<FieldPath>): Array<{
|
|
18
|
-
path: FieldPath;
|
|
19
|
-
label: string;
|
|
20
|
-
extraction: string;
|
|
21
|
-
}>;
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=sf-schema.d.ts.map
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { compiledTableEntries, isSnapshotSingleRow } from './compile-schema.js';
|
|
2
|
-
import { formatFieldPath, parseFieldPath } from './path.js';
|
|
3
|
-
function dataTypeToJsonSchema(dataType, enumValues, nullable) {
|
|
4
|
-
let base;
|
|
5
|
-
if (enumValues && enumValues.length > 0) {
|
|
6
|
-
base = { enum: [...enumValues] };
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
switch (dataType) {
|
|
10
|
-
case 'string':
|
|
11
|
-
case 'date':
|
|
12
|
-
case 'datetime':
|
|
13
|
-
base = { type: 'string' };
|
|
14
|
-
break;
|
|
15
|
-
case 'number':
|
|
16
|
-
base = { type: 'number' };
|
|
17
|
-
break;
|
|
18
|
-
case 'boolean':
|
|
19
|
-
base = { type: 'boolean' };
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (nullable) {
|
|
24
|
-
if (base.enum) {
|
|
25
|
-
return { enum: [...base.enum, null] };
|
|
26
|
-
}
|
|
27
|
-
return { type: [base.type, 'null'] };
|
|
28
|
-
}
|
|
29
|
-
return base;
|
|
30
|
-
}
|
|
31
|
-
function extractedFieldSchema(field) {
|
|
32
|
-
return {
|
|
33
|
-
type: 'object',
|
|
34
|
-
additionalProperties: false,
|
|
35
|
-
required: ['reason', 'value', 'state'],
|
|
36
|
-
properties: {
|
|
37
|
-
reason: { type: 'string', minLength: 1 },
|
|
38
|
-
value: dataTypeToJsonSchema(field.dataType, field.enum, true),
|
|
39
|
-
state: { type: 'string', enum: ['filled', 'asked_unknown', 'declined'] },
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Build JSON Schema for Slot Filling structured output.
|
|
45
|
-
* Derived and `source: system` fields are never included.
|
|
46
|
-
*/
|
|
47
|
-
export function buildSlotFillingJsonSchema(schema, options = {}) {
|
|
48
|
-
const focus = options.focusFields
|
|
49
|
-
? new Set([...options.focusFields].map((p) => {
|
|
50
|
-
const parsed = parseFieldPath(p);
|
|
51
|
-
if (!parsed)
|
|
52
|
-
throw new Error(`Invalid focus field: ${p}`);
|
|
53
|
-
return parsed.path;
|
|
54
|
-
}))
|
|
55
|
-
: null;
|
|
56
|
-
const tableSchemas = {};
|
|
57
|
-
for (const [tableName, table] of compiledTableEntries(schema)) {
|
|
58
|
-
const fieldProps = {};
|
|
59
|
-
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
60
|
-
if (field.derived)
|
|
61
|
-
continue;
|
|
62
|
-
if (field.source !== 'conversation')
|
|
63
|
-
continue;
|
|
64
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
65
|
-
if (focus && !focus.has(path))
|
|
66
|
-
continue;
|
|
67
|
-
fieldProps[fieldName] = extractedFieldSchema(field);
|
|
68
|
-
}
|
|
69
|
-
if (Object.keys(fieldProps).length === 0)
|
|
70
|
-
continue;
|
|
71
|
-
if (isSnapshotSingleRow(table)) {
|
|
72
|
-
tableSchemas[tableName] = {
|
|
73
|
-
type: 'object',
|
|
74
|
-
additionalProperties: false,
|
|
75
|
-
properties: fieldProps,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
tableSchemas[tableName] = {
|
|
80
|
-
type: 'array',
|
|
81
|
-
items: {
|
|
82
|
-
type: 'object',
|
|
83
|
-
additionalProperties: false,
|
|
84
|
-
required: ['rowKey', 'fields'],
|
|
85
|
-
properties: {
|
|
86
|
-
rowKey: { type: 'string', minLength: 1 },
|
|
87
|
-
fields: {
|
|
88
|
-
type: 'object',
|
|
89
|
-
additionalProperties: false,
|
|
90
|
-
properties: fieldProps,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
type: 'object',
|
|
99
|
-
additionalProperties: false,
|
|
100
|
-
properties: tableSchemas,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/** Compact catalog for out-of-focus conversation fields (C1). */
|
|
104
|
-
export function buildFieldCatalog(schema, exclude = []) {
|
|
105
|
-
const excluded = new Set([...exclude].map((p) => parseFieldPath(p)?.path).filter(Boolean));
|
|
106
|
-
const catalog = [];
|
|
107
|
-
for (const [tableName, table] of compiledTableEntries(schema)) {
|
|
108
|
-
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
109
|
-
if (field.derived)
|
|
110
|
-
continue;
|
|
111
|
-
if (field.source !== 'conversation')
|
|
112
|
-
continue;
|
|
113
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
114
|
-
if (excluded.has(path))
|
|
115
|
-
continue;
|
|
116
|
-
catalog.push({
|
|
117
|
-
path,
|
|
118
|
-
label: field.label,
|
|
119
|
-
extraction: field.extraction,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return catalog;
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=sf-schema.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CompiledSlotSchema, SlotFillingValidateResult } from './types.js';
|
|
2
|
-
export type ValidateSlotFillingOptions = {
|
|
3
|
-
/** Conversation version carried by the SF task. */
|
|
4
|
-
taskVersion: number;
|
|
5
|
-
/** Current conversation version; mismatch → whole pack discarded. */
|
|
6
|
-
currentVersion: number;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* C3 gates for Slot Filling output: version gate, type/enum, write protection.
|
|
10
|
-
* Derived / system fields in the payload are dropped (write protection).
|
|
11
|
-
* Type/enum failures are rejected per-field; valid fields stay accepted.
|
|
12
|
-
*/
|
|
13
|
-
export declare function validateSlotFillingOutput(schema: CompiledSlotSchema, raw: unknown, options: ValidateSlotFillingOptions): SlotFillingValidateResult;
|
|
14
|
-
//# sourceMappingURL=sf-validate.d.ts.map
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { getCompiledTable, isSnapshotSingleRow } from './compile-schema.js';
|
|
2
|
-
import { formatFieldPath } from './path.js';
|
|
3
|
-
import { isReservedTableName } from './row.js';
|
|
4
|
-
import { validateExtractedField } from './value.js';
|
|
5
|
-
function isExtractedField(value) {
|
|
6
|
-
if (!value || typeof value !== 'object')
|
|
7
|
-
return false;
|
|
8
|
-
const v = value;
|
|
9
|
-
return (typeof v.reason === 'string' &&
|
|
10
|
-
'value' in v &&
|
|
11
|
-
(v.state === 'filled' || v.state === 'asked_unknown' || v.state === 'declined'));
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* C3 gates for Slot Filling output: version gate, type/enum, write protection.
|
|
15
|
-
* Derived / system fields in the payload are dropped (write protection).
|
|
16
|
-
* Type/enum failures are rejected per-field; valid fields stay accepted.
|
|
17
|
-
*/
|
|
18
|
-
export function validateSlotFillingOutput(schema, raw, options) {
|
|
19
|
-
if (options.taskVersion !== options.currentVersion) {
|
|
20
|
-
return {
|
|
21
|
-
ok: false,
|
|
22
|
-
reason: 'stale-version',
|
|
23
|
-
issues: [
|
|
24
|
-
{
|
|
25
|
-
code: 'stale-version',
|
|
26
|
-
message: `SF version ${options.taskVersion} != current ${options.currentVersion}`,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
32
|
-
return {
|
|
33
|
-
ok: false,
|
|
34
|
-
reason: 'invalid-shape',
|
|
35
|
-
issues: [
|
|
36
|
-
{
|
|
37
|
-
code: 'invalid-shape',
|
|
38
|
-
message: 'SlotFillingOutput must be an object of table projections',
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
const accepted = {};
|
|
44
|
-
const rejected = [];
|
|
45
|
-
const shapeIssues = [];
|
|
46
|
-
for (const [tableName, projection] of Object.entries(raw)) {
|
|
47
|
-
if (isReservedTableName(tableName))
|
|
48
|
-
continue;
|
|
49
|
-
const table = getCompiledTable(schema, tableName);
|
|
50
|
-
if (!table) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (isSnapshotSingleRow(table)) {
|
|
54
|
-
if (!projection || typeof projection !== 'object' || Array.isArray(projection)) {
|
|
55
|
-
shapeIssues.push({
|
|
56
|
-
code: 'invalid-projection',
|
|
57
|
-
message: `single-row table ${tableName} expects an object projection`,
|
|
58
|
-
path: tableName,
|
|
59
|
-
});
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const outFields = {};
|
|
63
|
-
for (const [fieldName, extracted] of Object.entries(projection)) {
|
|
64
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
65
|
-
const field = table.fields[fieldName];
|
|
66
|
-
if (!field || field.derived || field.source !== 'conversation') {
|
|
67
|
-
continue; // write protection: drop
|
|
68
|
-
}
|
|
69
|
-
if (!isExtractedField(extracted)) {
|
|
70
|
-
rejected.push(path);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const issues = validateExtractedField(field, extracted, path);
|
|
74
|
-
if (issues.length > 0) {
|
|
75
|
-
rejected.push(path);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
outFields[fieldName] = extracted;
|
|
79
|
-
}
|
|
80
|
-
if (Object.keys(outFields).length > 0) {
|
|
81
|
-
accepted[tableName] = outFields;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
if (!Array.isArray(projection)) {
|
|
86
|
-
shapeIssues.push({
|
|
87
|
-
code: 'invalid-projection',
|
|
88
|
-
message: `multi-row table ${tableName} expects an array projection`,
|
|
89
|
-
path: tableName,
|
|
90
|
-
});
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
const outRows = [];
|
|
94
|
-
for (const row of projection) {
|
|
95
|
-
if (!row || typeof row !== 'object' || typeof row.rowKey !== 'string') {
|
|
96
|
-
shapeIssues.push({
|
|
97
|
-
code: 'invalid-row',
|
|
98
|
-
message: `multi-row table ${tableName} row missing rowKey`,
|
|
99
|
-
path: tableName,
|
|
100
|
-
});
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const fieldsIn = row.fields ?? {};
|
|
104
|
-
const outFields = {};
|
|
105
|
-
for (const [fieldName, extracted] of Object.entries(fieldsIn)) {
|
|
106
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
107
|
-
const field = table.fields[fieldName];
|
|
108
|
-
if (!field || field.derived || field.source !== 'conversation') {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (!isExtractedField(extracted)) {
|
|
112
|
-
rejected.push(path);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const issues = validateExtractedField(field, extracted, path);
|
|
116
|
-
if (issues.length > 0) {
|
|
117
|
-
rejected.push(path);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
outFields[fieldName] = extracted;
|
|
121
|
-
}
|
|
122
|
-
outRows.push({ rowKey: row.rowKey, fields: outFields });
|
|
123
|
-
}
|
|
124
|
-
accepted[tableName] = outRows;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (shapeIssues.length > 0) {
|
|
128
|
-
return { ok: false, reason: 'invalid-shape', issues: shapeIssues };
|
|
129
|
-
}
|
|
130
|
-
return { ok: true, accepted, rejected };
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=sf-validate.js.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { FieldPath } from './path.js';
|
|
2
|
-
import type { CompiledSlotSchema, FieldValue, RuntimeSlotsSnapshot, TableData } from './types.js';
|
|
3
|
-
export type SnapshotSeed = Record<string, unknown>;
|
|
4
|
-
/**
|
|
5
|
-
* Build a runtime snapshot for local tests.
|
|
6
|
-
*
|
|
7
|
-
* - `table.field` keys seed single-row (or current-party) fields
|
|
8
|
-
* - bare multi-table name keys seed row arrays:
|
|
9
|
-
* `children: [{ id?: string, name: 'Lily', age: 8 }]`
|
|
10
|
-
*/
|
|
11
|
-
export declare function snapshotFrom(schema: CompiledSlotSchema, seed?: SnapshotSeed, options?: {
|
|
12
|
-
now?: number;
|
|
13
|
-
}): RuntimeSlotsSnapshot;
|
|
14
|
-
/** Deep-clone a snapshot (structuredClone when available). */
|
|
15
|
-
export declare function cloneSnapshot(snapshot: RuntimeSlotsSnapshot): RuntimeSlotsSnapshot;
|
|
16
|
-
export declare function getSnapshotTable(snapshot: RuntimeSlotsSnapshot, tableName: string): TableData | undefined;
|
|
17
|
-
export declare function getSingleField(snapshot: RuntimeSlotsSnapshot, path: FieldPath): FieldValue | undefined;
|
|
18
|
-
//# sourceMappingURL=snapshot.d.ts.map
|