@superpanel-sdk/runtime 0.2.3 → 0.7.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 +30 -10
- package/dist/builder/codegen/emit.d.ts +25 -12
- package/dist/builder/codegen/emit.js +339 -78
- package/dist/builder/codegen/generate.d.ts +21 -2
- package/dist/builder/codegen/generate.js +147 -34
- 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 +29 -0
- package/dist/builder/company-imports.js +122 -0
- package/dist/builder/compile/compile-sequence.d.ts +61 -8
- package/dist/builder/compile/compile-sequence.js +334 -80
- package/dist/builder/compile/function-code.d.ts +19 -3
- package/dist/builder/compile/function-code.js +123 -45
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +30 -27
- package/dist/builder/errors.d.ts +9 -0
- package/dist/builder/errors.js +17 -0
- package/dist/builder/function-params.d.ts +10 -0
- package/dist/builder/function-params.js +203 -0
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +258 -67
- package/dist/builder/paths.d.ts +9 -1
- package/dist/builder/paths.js +32 -2
- package/dist/builder/schedules.d.ts +25 -0
- package/dist/builder/schedules.js +101 -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 +102 -0
- package/dist/builder/types.d.ts +127 -19
- package/dist/builder/types.js +21 -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/calls/index.d.ts +177 -0
- package/dist/cli/calls/index.js +96 -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/debug/index.d.ts +31 -0
- package/dist/cli/debug/index.js +119 -0
- package/dist/cli/exec/index.d.ts +39 -0
- package/dist/cli/exec/index.js +138 -0
- package/dist/cli/exec/session.d.ts +48 -0
- package/dist/cli/exec/session.js +82 -0
- package/dist/cli/exec/trace.d.ts +18 -0
- package/dist/cli/exec/trace.js +52 -0
- package/dist/cli/index.js +112 -9
- package/dist/cli/logs/index.d.ts +47 -0
- package/dist/cli/logs/index.js +113 -0
- package/dist/cli/mobile/index.d.ts +12 -0
- package/dist/cli/mobile/index.js +405 -0
- package/dist/cli/serve/index.d.ts +109 -3
- package/dist/cli/serve/index.js +506 -118
- package/dist/cli/turns/index.d.ts +105 -0
- package/dist/cli/turns/index.js +128 -0
- package/dist/cli/turns/run.d.ts +13 -0
- package/dist/cli/turns/run.js +57 -0
- package/dist/cli/turns/shadow.d.ts +112 -0
- package/dist/cli/turns/shadow.js +54 -0
- package/dist/cli/type-gen/index.js +9 -9
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +14 -23
- package/dist/compute-host/compute-host.js +18 -30
- 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 +10 -10
- package/dist/compute-host/source-compute-host.js +33 -40
- package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
- package/dist/core/case-orchestrator/contact-hours.js +127 -0
- package/dist/core/case-orchestrator/index.d.ts +3 -0
- package/dist/core/case-orchestrator/index.js +3 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +244 -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/types.d.ts +708 -0
- package/dist/core/case-orchestrator/types.js +42 -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 +198 -0
- package/dist/core/context/email-message.js +86 -0
- package/dist/core/context/email.d.ts +109 -0
- package/dist/core/context/email.js +90 -0
- package/dist/core/context/exchanges.d.ts +167 -0
- package/dist/core/context/exchanges.js +81 -0
- package/dist/core/context/instances.d.ts +307 -0
- package/dist/core/context/instances.js +137 -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 +544 -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 +177 -0
- package/dist/core/context/sms.js +77 -0
- package/dist/core/context/types.d.ts +79 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +85 -0
- package/dist/core/conversation/index.js +133 -0
- package/dist/core/functions/errors.d.ts +74 -0
- package/dist/core/functions/errors.js +26 -0
- package/dist/core/functions/events.d.ts +192 -0
- package/dist/core/functions/events.js +23 -0
- package/dist/core/functions/schedules.d.ts +50 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +29 -73
- package/dist/core/functions/types.js +1 -4
- 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 +904 -0
- package/dist/core/page/define.js +518 -0
- package/dist/core/page/envelope.d.ts +55 -0
- package/dist/core/page/envelope.js +4 -0
- package/dist/core/page/fns.d.ts +448 -0
- package/dist/core/page/fns.js +539 -0
- package/dist/core/page/memory-reader.d.ts +27 -0
- package/dist/core/page/memory-reader.js +299 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/page-host.d.ts +20 -0
- package/dist/core/page/page-host.js +57 -0
- package/dist/core/page/records-query.d.ts +234 -0
- package/dist/core/page/records-query.js +780 -0
- package/dist/core/page/render.d.ts +295 -0
- package/dist/core/page/render.js +1060 -0
- package/dist/core/page/sandbox.d.ts +85 -0
- package/dist/core/page/sandbox.js +357 -0
- package/dist/core/page/time-format.d.ts +46 -0
- package/dist/core/page/time-format.js +125 -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 +648 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +57 -0
- package/dist/core/page/workspace.js +266 -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 +208 -0
- package/dist/core/party/schema.js +113 -0
- package/dist/core/party/types.d.ts +35 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +56 -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 +102 -0
- package/dist/core/slot/company-metadata.js +536 -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 -25
- package/dist/core/slot/field.js +0 -71
- 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 +17 -0
- package/dist/core/slot/schema-compat.js +103 -0
- package/dist/core/slot/schema.d.ts +353 -76
- package/dist/core/slot/schema.js +163 -10
- package/dist/core/slot/types.d.ts +30 -103
- package/dist/core/slot/value.d.ts +28 -3
- package/dist/core/slot/value.js +93 -57
- package/dist/dev-overlay/protocol.d.ts +74 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +26 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +13 -4
- package/dist/fn-context/fake/index.js +29 -2
- package/dist/fn-context/fn-params.d.ts +3 -0
- package/dist/fn-context/fn-params.js +10 -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 +20 -9
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
- package/dist/fn-context/rpc/errors.d.ts +13 -0
- package/dist/fn-context/rpc/errors.js +22 -0
- package/dist/fn-context/rpc/index.d.ts +4 -2
- package/dist/fn-context/rpc/index.js +4 -2
- package/dist/fn-context/rpc/integration/index.d.ts +15 -5
- 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/log.d.ts +11 -1
- package/dist/fn-context/rpc/platform.d.ts +13 -3
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +85 -0
- package/dist/fn-context/rpc/records.js +24 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
- package/dist/fn-context/rpc/trpc-client.js +222 -12
- package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
- package/dist/fn-context/rpc/trpc-init.js +10 -4
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
- 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 +52 -5
- package/dist/index.d.ts +36 -46
- package/dist/index.js +30 -33
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +49 -0
- package/dist/platform.d.ts +75 -0
- package/dist/platform.js +57 -0
- package/dist/testing-compile-child.d.ts +2 -0
- package/dist/testing-compile-child.js +20 -0
- package/dist/testing.d.ts +368 -0
- package/dist/testing.js +439 -0
- package/dist/voice-service/actions.d.ts +50 -6
- package/dist/voice-service/index.d.ts +2 -0
- package/dist/voice-service/index.js +2 -0
- package/dist/voice-service/protocol.d.ts +604 -0
- package/dist/voice-service/protocol.js +67 -0
- package/dist/voice-service/types.d.ts +55 -8
- package/dist/worker.d.ts +11 -0
- package/dist/worker.js +11 -0
- package/package.json +38 -15
- 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/functions/func-ref.d.ts +0 -16
- package/dist/core/functions/func-ref.js +0 -20
- 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/write.js
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
import { getCompiledTable, isSnapshotSingleRow } from './compile-schema.js';
|
|
2
|
-
import { commitFieldWrite, makeFieldValue } from './field.js';
|
|
3
|
-
import { formatFieldPath, parseFieldPath, requireFieldPath } from './path.js';
|
|
4
|
-
import { getRowField, isReservedTableName, isRowIdField, mintRowId, slotFieldNames } from './row.js';
|
|
5
|
-
import { cloneSnapshot, getSnapshotTable } from './snapshot.js';
|
|
6
|
-
import { validateBareValue, validateExtractedField } from './value.js';
|
|
7
|
-
export function isRowWrite(value) {
|
|
8
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
9
|
-
return false;
|
|
10
|
-
const o = value;
|
|
11
|
-
return (typeof o.table === 'string' &&
|
|
12
|
-
typeof o.rowId === 'string' &&
|
|
13
|
-
o.values !== null &&
|
|
14
|
-
typeof o.values === 'object' &&
|
|
15
|
-
!Array.isArray(o.values));
|
|
16
|
-
}
|
|
17
|
-
export function isStructuredWrites(value) {
|
|
18
|
-
if (!value || typeof value !== 'object' || Array.isArray(value) || isRowWrite(value))
|
|
19
|
-
return false;
|
|
20
|
-
const keys = Object.keys(value);
|
|
21
|
-
return keys.length > 0 && keys.every((key) => key === 'fields' || key === 'rows');
|
|
22
|
-
}
|
|
23
|
-
export function normalizeWrites(writes) {
|
|
24
|
-
if (writes == null)
|
|
25
|
-
return null;
|
|
26
|
-
if (isRowWrite(writes)) {
|
|
27
|
-
return { fields: {}, rows: [writes] };
|
|
28
|
-
}
|
|
29
|
-
if (isStructuredWrites(writes)) {
|
|
30
|
-
const fields = writes.fields && typeof writes.fields === 'object' && !Array.isArray(writes.fields) ? writes.fields : {};
|
|
31
|
-
const rows = Array.isArray(writes.rows) ? writes.rows.filter(isRowWrite) : [];
|
|
32
|
-
if (Object.keys(fields).length === 0 && rows.length === 0)
|
|
33
|
-
return null;
|
|
34
|
-
return { fields, rows };
|
|
35
|
-
}
|
|
36
|
-
if (Object.keys(writes).length === 0)
|
|
37
|
-
return null;
|
|
38
|
-
return { fields: writes, rows: [] };
|
|
39
|
-
}
|
|
40
|
-
function boundRowId(tableName, current) {
|
|
41
|
-
if (!current)
|
|
42
|
-
return undefined;
|
|
43
|
-
if (tableName === 'contact')
|
|
44
|
-
return current.contactId;
|
|
45
|
-
if (tableName === 'case_contact')
|
|
46
|
-
return current.caseContactId;
|
|
47
|
-
if (tableName === 'case_file')
|
|
48
|
-
return current.caseFileId;
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
function writeTargetRow(schema, snapshot, tableName, rowId) {
|
|
52
|
-
const table = getCompiledTable(schema, tableName);
|
|
53
|
-
if (!table)
|
|
54
|
-
return null;
|
|
55
|
-
const data = getSnapshotTable(snapshot, tableName);
|
|
56
|
-
if (!data)
|
|
57
|
-
return null;
|
|
58
|
-
if (isSnapshotSingleRow(table) && !Array.isArray(data)) {
|
|
59
|
-
if (rowId && data.id && data.id !== rowId)
|
|
60
|
-
return null;
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
if (Array.isArray(data)) {
|
|
64
|
-
const id = rowId ?? boundRowId(tableName, snapshot.current);
|
|
65
|
-
if (!id)
|
|
66
|
-
return null;
|
|
67
|
-
return data.find((row) => row.id === id) ?? null;
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
function extractedToFieldValue(extracted, updatedBy, now) {
|
|
72
|
-
return makeFieldValue({
|
|
73
|
-
reason: extracted.reason,
|
|
74
|
-
value: extracted.value,
|
|
75
|
-
state: extracted.state,
|
|
76
|
-
updatedBy,
|
|
77
|
-
updatedAt: now,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function assertWritableNormal(schema, snapshot, path, options, rowId) {
|
|
81
|
-
const { table, field: fieldName } = requireFieldPath(path);
|
|
82
|
-
const tableDef = getCompiledTable(schema, table);
|
|
83
|
-
const field = tableDef?.fields[fieldName];
|
|
84
|
-
if (!tableDef || !field) {
|
|
85
|
-
return [{ code: 'unknown-field', message: `Unknown field: ${path}`, path }];
|
|
86
|
-
}
|
|
87
|
-
if (isRowIdField(fieldName)) {
|
|
88
|
-
return [
|
|
89
|
-
{
|
|
90
|
-
code: 'id-readonly',
|
|
91
|
-
message: `Cannot write row id: ${path}`,
|
|
92
|
-
path,
|
|
93
|
-
},
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
if (field.derived) {
|
|
97
|
-
return [
|
|
98
|
-
{
|
|
99
|
-
code: 'derived-readonly',
|
|
100
|
-
message: `Cannot write derived field: ${path}`,
|
|
101
|
-
path,
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
const systemOnly = options.systemOnly ??
|
|
106
|
-
(options.source === 'function' || options.source === 'platform' || options.source === 'import');
|
|
107
|
-
if (systemOnly && field.source !== 'system') {
|
|
108
|
-
return [
|
|
109
|
-
{
|
|
110
|
-
code: 'write-forbidden',
|
|
111
|
-
message: `Source ${options.source} cannot write conversation field ${path}`,
|
|
112
|
-
path,
|
|
113
|
-
},
|
|
114
|
-
];
|
|
115
|
-
}
|
|
116
|
-
if (!isSnapshotSingleRow(tableDef) && !writeTargetRow(schema, snapshot, table, rowId)) {
|
|
117
|
-
return [
|
|
118
|
-
{
|
|
119
|
-
code: rowId ? 'row-not-found' : 'multi-path-write',
|
|
120
|
-
message: rowId
|
|
121
|
-
? `Row ${rowId} not found in ${table}`
|
|
122
|
-
: `Use Slot Filling or { table, rowId, values } to write multi-row field ${path}`,
|
|
123
|
-
path,
|
|
124
|
-
},
|
|
125
|
-
];
|
|
126
|
-
}
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
function applyBareFieldWrite(schema, original, next, path, value, rowId, options, now, errors, changed, history) {
|
|
130
|
-
const writeIssues = assertWritableNormal(schema, original, path, options, rowId);
|
|
131
|
-
if (writeIssues.length > 0) {
|
|
132
|
-
errors.push(...writeIssues);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const parsed = parseFieldPath(path);
|
|
136
|
-
if (!parsed) {
|
|
137
|
-
errors.push({ code: 'unknown-field', message: `Invalid field path: ${path}`, path });
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const field = getCompiledTable(schema, parsed.table)?.fields[parsed.field];
|
|
141
|
-
if (!field) {
|
|
142
|
-
errors.push({ code: 'unknown-field', message: `Unknown field: ${path}`, path });
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const valueIssues = validateBareValue(field, value, path, {
|
|
146
|
-
allowNull: !field.derived && field.nullable,
|
|
147
|
-
});
|
|
148
|
-
if (valueIssues.length > 0) {
|
|
149
|
-
errors.push(...valueIssues);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const tableData = writeTargetRow(schema, next, parsed.table, rowId);
|
|
153
|
-
if (!tableData)
|
|
154
|
-
return;
|
|
155
|
-
const prev = getRowField(tableData, parsed.field);
|
|
156
|
-
if (!prev)
|
|
157
|
-
return;
|
|
158
|
-
const committed = commitFieldWrite(prev, makeFieldValue({
|
|
159
|
-
value: (value ?? null),
|
|
160
|
-
state: 'filled',
|
|
161
|
-
reason: null,
|
|
162
|
-
updatedBy: options.source,
|
|
163
|
-
updatedAt: now,
|
|
164
|
-
}));
|
|
165
|
-
tableData[parsed.field] = committed.field;
|
|
166
|
-
if (committed.changed) {
|
|
167
|
-
changed.push(parsed.path);
|
|
168
|
-
if (committed.historyEntry) {
|
|
169
|
-
history.push({
|
|
170
|
-
path: parsed.path,
|
|
171
|
-
entry: committed.historyEntry,
|
|
172
|
-
rowId: typeof tableData.id === 'string' && tableData.id ? tableData.id : undefined,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Apply bare Writes (function / human / import / platform) onto a snapshot.
|
|
179
|
-
* Validates type/enum and write permissions. Detects C5 changes and appends history.
|
|
180
|
-
* Multi-row tables: pass `{ table, rowId, values }` (or `rows` on StructuredWrites).
|
|
181
|
-
*/
|
|
182
|
-
export function applyWrites(schema, snapshot, writes, options) {
|
|
183
|
-
const normalized = normalizeWrites(writes);
|
|
184
|
-
if (!normalized) {
|
|
185
|
-
return { snapshot, changed: [], history: [] };
|
|
186
|
-
}
|
|
187
|
-
const now = options.now ?? Date.now();
|
|
188
|
-
const next = cloneSnapshot(snapshot);
|
|
189
|
-
const changed = [];
|
|
190
|
-
const history = [];
|
|
191
|
-
const errors = [];
|
|
192
|
-
for (const [path, value] of Object.entries(normalized.fields)) {
|
|
193
|
-
applyBareFieldWrite(schema, snapshot, next, path, value, undefined, options, now, errors, changed, history);
|
|
194
|
-
}
|
|
195
|
-
for (const row of normalized.rows) {
|
|
196
|
-
if (!row.table || !row.rowId) {
|
|
197
|
-
errors.push({
|
|
198
|
-
code: 'row-not-found',
|
|
199
|
-
message: 'Row write requires table and rowId',
|
|
200
|
-
path: row.table || undefined,
|
|
201
|
-
});
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
for (const [fieldName, value] of Object.entries(row.values)) {
|
|
205
|
-
const path = formatFieldPath(row.table, fieldName);
|
|
206
|
-
applyBareFieldWrite(schema, snapshot, next, path, value, row.rowId, options, now, errors, changed, history);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (errors.length > 0) {
|
|
210
|
-
throw new Error(`applyWrites failed:\n${errors.map((e) => `- ${e.path ?? ''}: ${e.message}`).join('\n')}`);
|
|
211
|
-
}
|
|
212
|
-
return { snapshot: next, changed, history };
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Apply one human/admin field edit, including explicit slot state.
|
|
216
|
-
* Unlike bare writes, this supports a selected row in a multi-row entity table.
|
|
217
|
-
*/
|
|
218
|
-
export function applyFieldPatch(schema, snapshot, patch, options) {
|
|
219
|
-
const parsed = requireFieldPath(patch.path);
|
|
220
|
-
const table = getCompiledTable(schema, parsed.table);
|
|
221
|
-
const field = table?.fields[parsed.field];
|
|
222
|
-
if (!table || !field)
|
|
223
|
-
throw new Error(`Unknown field: ${patch.path}`);
|
|
224
|
-
if (isRowIdField(parsed.field))
|
|
225
|
-
throw new Error(`Cannot write row id: ${patch.path}`);
|
|
226
|
-
if (field.derived)
|
|
227
|
-
throw new Error(`Cannot write derived field: ${patch.path}`);
|
|
228
|
-
const value = patch.state === 'filled' ? patch.value : null;
|
|
229
|
-
if (patch.state !== 'empty') {
|
|
230
|
-
const issues = validateExtractedField(field, {
|
|
231
|
-
value,
|
|
232
|
-
state: patch.state,
|
|
233
|
-
reason: patch.reason ?? 'Human edit',
|
|
234
|
-
}, patch.path);
|
|
235
|
-
if (issues.length > 0) {
|
|
236
|
-
throw new Error(`applyFieldPatch failed:\n${issues.map((issue) => `- ${issue.path ?? ''}: ${issue.message}`).join('\n')}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const now = options.now ?? Date.now();
|
|
240
|
-
const next = cloneSnapshot(snapshot);
|
|
241
|
-
const data = getSnapshotTable(next, parsed.table);
|
|
242
|
-
const row = isSnapshotSingleRow(table)
|
|
243
|
-
? data
|
|
244
|
-
: data?.find((candidate) => candidate.id === patch.rowId);
|
|
245
|
-
if (!row)
|
|
246
|
-
throw new Error(`Slot row not found: ${parsed.table}:${patch.rowId ?? 'single'}`);
|
|
247
|
-
const previous = getRowField(row, parsed.field);
|
|
248
|
-
if (!previous)
|
|
249
|
-
throw new Error(`Slot field not initialized: ${patch.path}`);
|
|
250
|
-
const committed = commitFieldWrite(previous, makeFieldValue({
|
|
251
|
-
value,
|
|
252
|
-
state: patch.state,
|
|
253
|
-
reason: patch.reason ?? 'Human edit',
|
|
254
|
-
updatedBy: options.source,
|
|
255
|
-
updatedAt: now,
|
|
256
|
-
}));
|
|
257
|
-
row[parsed.field] = committed.field;
|
|
258
|
-
if (!committed.changed)
|
|
259
|
-
return { snapshot: next, changed: [], history: [] };
|
|
260
|
-
return {
|
|
261
|
-
snapshot: next,
|
|
262
|
-
changed: [parsed.path],
|
|
263
|
-
history: committed.historyEntry ? [{ path: parsed.path, entry: committed.historyEntry }] : [],
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* C4: apply accepted Slot Filling projection (full replace for present fields/rows).
|
|
268
|
-
* Multi-row: projection is the full set of rows; omitted existing rows are deleted.
|
|
269
|
-
*/
|
|
270
|
-
export function applySlotFilling(schema, snapshot, output, options = {}) {
|
|
271
|
-
const now = options.now ?? Date.now();
|
|
272
|
-
const next = cloneSnapshot(snapshot);
|
|
273
|
-
const changed = new Set();
|
|
274
|
-
const history = [];
|
|
275
|
-
const rowKeyMap = options.rowKeyMap ?? new Map();
|
|
276
|
-
for (const [tableName, projection] of Object.entries(output)) {
|
|
277
|
-
if (isReservedTableName(tableName))
|
|
278
|
-
continue;
|
|
279
|
-
const table = getCompiledTable(schema, tableName);
|
|
280
|
-
if (!table)
|
|
281
|
-
continue;
|
|
282
|
-
if (isSnapshotSingleRow(table)) {
|
|
283
|
-
const tableData = getSnapshotTable(next, tableName);
|
|
284
|
-
for (const [fieldName, extracted] of Object.entries(projection)) {
|
|
285
|
-
const field = table.fields[fieldName];
|
|
286
|
-
if (!field || field.derived || field.source !== 'conversation')
|
|
287
|
-
continue;
|
|
288
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
289
|
-
const issues = validateExtractedField(field, extracted, path);
|
|
290
|
-
if (issues.length > 0) {
|
|
291
|
-
throw new Error(issues.map((i) => i.message).join('; '));
|
|
292
|
-
}
|
|
293
|
-
if (isRowIdField(fieldName))
|
|
294
|
-
continue;
|
|
295
|
-
const prev = getRowField(tableData, fieldName);
|
|
296
|
-
if (!prev)
|
|
297
|
-
continue;
|
|
298
|
-
const committed = commitFieldWrite(prev, extractedToFieldValue(extracted, 'slot-filling', now));
|
|
299
|
-
tableData[fieldName] = committed.field;
|
|
300
|
-
if (committed.changed) {
|
|
301
|
-
changed.add(path);
|
|
302
|
-
if (committed.historyEntry) {
|
|
303
|
-
history.push({
|
|
304
|
-
path,
|
|
305
|
-
entry: committed.historyEntry,
|
|
306
|
-
rowId: typeof tableData.id === 'string' && tableData.id ? tableData.id : undefined,
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
const prevRows = getSnapshotTable(snapshot, tableName) ?? [];
|
|
314
|
-
const prevById = new Map(prevRows.map((r) => [r.id, r]));
|
|
315
|
-
const projectionRows = projection;
|
|
316
|
-
const nextRows = [];
|
|
317
|
-
let structuralChange = false;
|
|
318
|
-
for (const row of projectionRows) {
|
|
319
|
-
let id = row.rowKey;
|
|
320
|
-
if (row.rowKey.startsWith('new-')) {
|
|
321
|
-
id = rowKeyMap.get(row.rowKey) ?? mintRowId();
|
|
322
|
-
rowKeyMap.set(row.rowKey, id);
|
|
323
|
-
structuralChange = true;
|
|
324
|
-
}
|
|
325
|
-
else if (!prevById.has(row.rowKey)) {
|
|
326
|
-
structuralChange = true;
|
|
327
|
-
}
|
|
328
|
-
const prevRow = prevById.get(id);
|
|
329
|
-
const nextRow = { id };
|
|
330
|
-
for (const fieldName of slotFieldNames(table.fields)) {
|
|
331
|
-
const field = table.fields[fieldName];
|
|
332
|
-
if (field.derived)
|
|
333
|
-
continue;
|
|
334
|
-
const extracted = row.fields[fieldName];
|
|
335
|
-
const prevFv = prevRow ? getRowField(prevRow, fieldName) : undefined;
|
|
336
|
-
if (extracted) {
|
|
337
|
-
const path = formatFieldPath(tableName, fieldName);
|
|
338
|
-
const issues = validateExtractedField(field, extracted, path);
|
|
339
|
-
if (issues.length > 0) {
|
|
340
|
-
throw new Error(issues.map((i) => i.message).join('; '));
|
|
341
|
-
}
|
|
342
|
-
const committed = commitFieldWrite(prevFv, extractedToFieldValue(extracted, 'slot-filling', now));
|
|
343
|
-
nextRow[fieldName] = committed.field;
|
|
344
|
-
if (committed.changed) {
|
|
345
|
-
changed.add(path);
|
|
346
|
-
if (committed.historyEntry) {
|
|
347
|
-
history.push({ path, entry: committed.historyEntry, rowId: id });
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
else if (prevFv) {
|
|
352
|
-
nextRow[fieldName] = prevFv;
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
nextRow[fieldName] = makeFieldValue({
|
|
356
|
-
value: null,
|
|
357
|
-
state: 'empty',
|
|
358
|
-
updatedBy: 'slot-filling',
|
|
359
|
-
updatedAt: now,
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
nextRows.push(nextRow);
|
|
364
|
-
}
|
|
365
|
-
const prevIds = new Set(prevRows.map((r) => r.id));
|
|
366
|
-
const nextIds = new Set(nextRows.map((r) => r.id));
|
|
367
|
-
for (const id of prevIds) {
|
|
368
|
-
if (!nextIds.has(id))
|
|
369
|
-
structuralChange = true;
|
|
370
|
-
}
|
|
371
|
-
if (prevRows.length !== nextRows.length)
|
|
372
|
-
structuralChange = true;
|
|
373
|
-
next[tableName] = nextRows;
|
|
374
|
-
if (structuralChange) {
|
|
375
|
-
for (const fieldName of slotFieldNames(table.fields)) {
|
|
376
|
-
changed.add(formatFieldPath(tableName, fieldName));
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
return { snapshot: next, changed: [...changed], history };
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Mark remaining conversation fields as asked_unknown (Topic move-on).
|
|
385
|
-
*/
|
|
386
|
-
export function markAskedUnknown(schema, snapshot, fields, options = {}) {
|
|
387
|
-
const now = options.now ?? Date.now();
|
|
388
|
-
const next = cloneSnapshot(snapshot);
|
|
389
|
-
const changed = [];
|
|
390
|
-
const history = [];
|
|
391
|
-
for (const path of fields) {
|
|
392
|
-
const parsed = requireFieldPath(path);
|
|
393
|
-
const table = getCompiledTable(schema, parsed.table);
|
|
394
|
-
const field = table?.fields[parsed.field];
|
|
395
|
-
if (!table || !field || field.derived)
|
|
396
|
-
continue;
|
|
397
|
-
if (field.source !== 'conversation')
|
|
398
|
-
continue;
|
|
399
|
-
if (!isSnapshotSingleRow(table))
|
|
400
|
-
continue;
|
|
401
|
-
const tableData = getSnapshotTable(next, parsed.table);
|
|
402
|
-
const prev = getRowField(tableData, parsed.field);
|
|
403
|
-
if (!prev || prev.state !== 'empty')
|
|
404
|
-
continue;
|
|
405
|
-
const committed = commitFieldWrite(prev, makeFieldValue({
|
|
406
|
-
value: null,
|
|
407
|
-
state: 'asked_unknown',
|
|
408
|
-
reason: options.reason ?? 'move-on',
|
|
409
|
-
updatedBy: 'platform',
|
|
410
|
-
updatedAt: now,
|
|
411
|
-
}));
|
|
412
|
-
tableData[parsed.field] = committed.field;
|
|
413
|
-
if (committed.changed) {
|
|
414
|
-
changed.push(parsed.path);
|
|
415
|
-
if (committed.historyEntry) {
|
|
416
|
-
history.push({
|
|
417
|
-
path: parsed.path,
|
|
418
|
-
entry: committed.historyEntry,
|
|
419
|
-
rowId: typeof tableData.id === 'string' && tableData.id ? tableData.id : undefined,
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return { snapshot: next, changed, history };
|
|
425
|
-
}
|
|
426
|
-
//# sourceMappingURL=write.js.map
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { FuncRef } from '../functions/func-ref.js';
|
|
2
|
-
import type { FieldPath } from '../slot/path.js';
|
|
3
|
-
import type { ActionNode, AgendaHeader, AgendaTree, AuthoringNode, AuthoringWhen, BranchNode, FinishWhen, IvrDigit, IvrFallbackAction, IvrNode, OnNoProgress, SectionNode, SwitchOnNode, TopicNode, TransferNode } from './types.js';
|
|
4
|
-
import type { TransferDial, TransferMode, TransferSay } from './transfer-spec.js';
|
|
5
|
-
export declare function topic(id: string, config: {
|
|
6
|
-
label: string;
|
|
7
|
-
applyWhen: AuthoringWhen;
|
|
8
|
-
instructions: string;
|
|
9
|
-
fields: FieldPath[] | null;
|
|
10
|
-
finishWhen: FinishWhen;
|
|
11
|
-
onNoProgress: OnNoProgress | null;
|
|
12
|
-
}): TopicNode;
|
|
13
|
-
export declare function action(id: string, config: {
|
|
14
|
-
label: string;
|
|
15
|
-
applyWhen: AuthoringWhen;
|
|
16
|
-
finishWhen: FinishWhen;
|
|
17
|
-
run: FuncRef;
|
|
18
|
-
say: string | null;
|
|
19
|
-
}): ActionNode;
|
|
20
|
-
export declare function transfer(id: string, config: {
|
|
21
|
-
label: string;
|
|
22
|
-
applyWhen: AuthoringWhen;
|
|
23
|
-
numbers: string[];
|
|
24
|
-
mode: TransferMode;
|
|
25
|
-
say: TransferSay;
|
|
26
|
-
unsuccessfulSay: TransferSay | null;
|
|
27
|
-
} & Omit<TransferDial, 'numbers' | 'mode' | 'say' | 'unsuccessfulSay'>): TransferNode;
|
|
28
|
-
export declare function ivr(id: string, config: {
|
|
29
|
-
label: string;
|
|
30
|
-
applyWhen: AuthoringWhen;
|
|
31
|
-
onDtmfResult: FuncRef;
|
|
32
|
-
finishWhen: FinishWhen;
|
|
33
|
-
fallbackAction: IvrFallbackAction;
|
|
34
|
-
confirmTimeoutMs: number;
|
|
35
|
-
pauseAfterSayMs: number;
|
|
36
|
-
loopSay: string;
|
|
37
|
-
enterSay: string | null;
|
|
38
|
-
succeedSay: string | null;
|
|
39
|
-
unsuccessSay: string | null;
|
|
40
|
-
finishOnKey?: IvrDigit | null;
|
|
41
|
-
minDigits?: number | null;
|
|
42
|
-
maxDigits?: number | null;
|
|
43
|
-
validateDigits?: IvrDigit[] | null;
|
|
44
|
-
}): IvrNode;
|
|
45
|
-
export declare function section(id: string, config: {
|
|
46
|
-
label: string;
|
|
47
|
-
applyWhen: AuthoringWhen;
|
|
48
|
-
}, children: AuthoringNode[]): SectionNode;
|
|
49
|
-
export declare function branch(children: AuthoringNode[]): BranchNode;
|
|
50
|
-
export declare function switchOn(field: FieldPath, cases: Record<string, AuthoringNode[]> & {
|
|
51
|
-
otherwise?: AuthoringNode[];
|
|
52
|
-
}): SwitchOnNode;
|
|
53
|
-
export declare function agenda(id: string, header: AgendaHeader | null, tree: AuthoringNode[]): AgendaTree;
|
|
54
|
-
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export function topic(id, config) {
|
|
2
|
-
return { kind: 'topic', id, ...config };
|
|
3
|
-
}
|
|
4
|
-
export function action(id, config) {
|
|
5
|
-
return { kind: 'action', id, ...config };
|
|
6
|
-
}
|
|
7
|
-
export function transfer(id, config) {
|
|
8
|
-
return { kind: 'transfer', id, ...config };
|
|
9
|
-
}
|
|
10
|
-
export function ivr(id, config) {
|
|
11
|
-
return { kind: 'ivr', id, ...config };
|
|
12
|
-
}
|
|
13
|
-
export function section(id, config, children) {
|
|
14
|
-
return { kind: 'section', id, label: config.label, applyWhen: config.applyWhen, children };
|
|
15
|
-
}
|
|
16
|
-
export function branch(children) {
|
|
17
|
-
return { kind: 'branch', children };
|
|
18
|
-
}
|
|
19
|
-
export function switchOn(field, cases) {
|
|
20
|
-
const { otherwise: otherwiseChildren, ...rest } = cases;
|
|
21
|
-
return {
|
|
22
|
-
kind: 'switchOn',
|
|
23
|
-
field,
|
|
24
|
-
cases: rest,
|
|
25
|
-
...(otherwiseChildren ? { otherwise: otherwiseChildren } : {}),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export function agenda(id, header, tree) {
|
|
29
|
-
return { kind: 'agenda', id, header, tree };
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=builders.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { FieldPath } from '../slot/path.js';
|
|
2
|
-
import type { Condition, JsonRulesCondition, OtherwiseSentinel } from './types.js';
|
|
3
|
-
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
4
|
-
export declare function isOtherwise(value: unknown): value is OtherwiseSentinel;
|
|
5
|
-
export declare function looksLikeJsonRules(value: string): boolean;
|
|
6
|
-
export declare function jsonRules(rules: Condition | Condition[] | string): Condition;
|
|
7
|
-
export declare function otherwise(): OtherwiseSentinel;
|
|
8
|
-
export declare function parseJsonRules(input: string): JsonRulesCondition;
|
|
9
|
-
export declare function normalizeJsonRules(raw: unknown): JsonRulesCondition;
|
|
10
|
-
export declare function collectJsonRulesFacts(condition: JsonRulesCondition | null | undefined): FieldPath[];
|
|
11
|
-
export type ConditionEval = {
|
|
12
|
-
pass: boolean;
|
|
13
|
-
failedFields: FieldPath[];
|
|
14
|
-
};
|
|
15
|
-
export declare function evaluateJsonRules(condition: JsonRulesCondition, caseContext: unknown): Promise<ConditionEval>;
|
|
16
|
-
export declare function extractTemplateFields(text: string): FieldPath[];
|
|
17
|
-
//# sourceMappingURL=condition.d.ts.map
|