@superpanel-sdk/runtime 0.0.1-internal.1
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 +35 -0
- package/bin/superpanel-sdk-runtime.mjs +22 -0
- package/dist/builder/codegen/emit.d.ts +17 -0
- package/dist/builder/codegen/emit.js +143 -0
- package/dist/builder/codegen/generate.d.ts +21 -0
- package/dist/builder/codegen/generate.js +90 -0
- package/dist/builder/compile/compile-agenda.d.ts +15 -0
- package/dist/builder/compile/compile-agenda.js +59 -0
- package/dist/builder/compile/compile-sequence.d.ts +24 -0
- package/dist/builder/compile/compile-sequence.js +121 -0
- package/dist/builder/compile/function-code.d.ts +6 -0
- package/dist/builder/compile/function-code.js +30 -0
- package/dist/builder/compile/registry.d.ts +13 -0
- package/dist/builder/compile/registry.js +42 -0
- package/dist/builder/load.d.ts +22 -0
- package/dist/builder/load.js +169 -0
- package/dist/builder/merge.d.ts +4 -0
- package/dist/builder/merge.js +19 -0
- package/dist/builder/paths.d.ts +10 -0
- package/dist/builder/paths.js +22 -0
- package/dist/builder/types.d.ts +31 -0
- package/dist/builder/types.js +2 -0
- package/dist/cli/compile/index.d.ts +4 -0
- package/dist/cli/compile/index.js +11 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +64 -0
- package/dist/cli/serve/index.d.ts +9 -0
- package/dist/cli/serve/index.js +340 -0
- package/dist/cli/type-gen/index.d.ts +5 -0
- package/dist/cli/type-gen/index.js +90 -0
- package/dist/compute-host/compute-host.d.ts +38 -0
- package/dist/compute-host/compute-host.js +45 -0
- package/dist/compute-host/index.d.ts +5 -0
- package/dist/compute-host/index.js +3 -0
- package/dist/compute-host/source-compute-host.d.ts +29 -0
- package/dist/compute-host/source-compute-host.js +72 -0
- package/dist/core/context/account-fields.d.ts +12 -0
- package/dist/core/context/account-fields.js +2 -0
- package/dist/core/context/contact.d.ts +60 -0
- package/dist/core/context/contact.js +34 -0
- package/dist/core/context/db.d.ts +69 -0
- package/dist/core/context/db.js +44 -0
- package/dist/core/context/docusign.d.ts +134 -0
- package/dist/core/context/docusign.js +108 -0
- package/dist/core/context/env.d.ts +9 -0
- package/dist/core/context/env.js +19 -0
- package/dist/core/context/filevine.d.ts +323 -0
- package/dist/core/context/filevine.js +254 -0
- package/dist/core/context/http.d.ts +9 -0
- package/dist/core/context/http.js +4 -0
- package/dist/core/context/hubspot.d.ts +250 -0
- package/dist/core/context/hubspot.js +191 -0
- package/dist/core/context/platform-registry.d.ts +67 -0
- package/dist/core/context/platform-registry.js +11 -0
- package/dist/core/context/platform.d.ts +33 -0
- package/dist/core/context/platform.js +2 -0
- package/dist/core/context/twilio.d.ts +50 -0
- package/dist/core/context/twilio.js +42 -0
- package/dist/core/context/types.d.ts +87 -0
- package/dist/core/context/types.js +9 -0
- package/dist/core/functions/define/case-context.d.ts +14 -0
- package/dist/core/functions/define/case-context.js +15 -0
- package/dist/core/functions/define/compute.d.ts +7 -0
- package/dist/core/functions/define/compute.js +17 -0
- package/dist/core/functions/define/custom.d.ts +4 -0
- package/dist/core/functions/define/custom.js +8 -0
- package/dist/core/functions/define/system.d.ts +7 -0
- package/dist/core/functions/define/system.js +12 -0
- package/dist/core/functions/func-ref.d.ts +16 -0
- package/dist/core/functions/func-ref.js +20 -0
- package/dist/core/functions/types.d.ts +78 -0
- package/dist/core/functions/types.js +5 -0
- package/dist/core/slot/compile-schema.d.ts +24 -0
- package/dist/core/slot/compile-schema.js +336 -0
- package/dist/core/slot/deps.d.ts +15 -0
- package/dist/core/slot/deps.js +88 -0
- package/dist/core/slot/derived.d.ts +32 -0
- package/dist/core/slot/derived.js +115 -0
- package/dist/core/slot/field.d.ts +36 -0
- package/dist/core/slot/field.js +97 -0
- package/dist/core/slot/id-ref.d.ts +4 -0
- package/dist/core/slot/id-ref.js +15 -0
- package/dist/core/slot/index.d.ts +15 -0
- package/dist/core/slot/index.js +14 -0
- package/dist/core/slot/path.d.ts +18 -0
- package/dist/core/slot/path.js +22 -0
- package/dist/core/slot/row.d.ts +22 -0
- package/dist/core/slot/row.js +54 -0
- package/dist/core/slot/schema.d.ts +102 -0
- package/dist/core/slot/schema.js +17 -0
- package/dist/core/slot/sf-schema.d.ts +23 -0
- package/dist/core/slot/sf-schema.js +125 -0
- package/dist/core/slot/sf-validate.d.ts +14 -0
- package/dist/core/slot/sf-validate.js +132 -0
- package/dist/core/slot/snapshot.d.ts +18 -0
- package/dist/core/slot/snapshot.js +138 -0
- package/dist/core/slot/types.d.ts +144 -0
- package/dist/core/slot/types.js +2 -0
- package/dist/core/slot/value.d.ts +9 -0
- package/dist/core/slot/value.js +97 -0
- package/dist/core/slot/write.d.ts +41 -0
- package/dist/core/slot/write.js +319 -0
- package/dist/core/stage/builders.d.ts +36 -0
- package/dist/core/stage/builders.js +28 -0
- package/dist/core/stage/condition.d.ts +17 -0
- package/dist/core/stage/condition.js +198 -0
- package/dist/core/stage/drive.d.ts +43 -0
- package/dist/core/stage/drive.js +77 -0
- package/dist/core/stage/finish-when.d.ts +20 -0
- package/dist/core/stage/finish-when.js +82 -0
- package/dist/core/stage/flatten.d.ts +27 -0
- package/dist/core/stage/flatten.js +464 -0
- package/dist/core/stage/index.d.ts +11 -0
- package/dist/core/stage/index.js +10 -0
- package/dist/core/stage/simulate.d.ts +24 -0
- package/dist/core/stage/simulate.js +33 -0
- package/dist/core/stage/transfer-fields.d.ts +14 -0
- package/dist/core/stage/transfer-fields.js +88 -0
- package/dist/core/stage/types.d.ts +177 -0
- package/dist/core/stage/types.js +2 -0
- package/dist/core/stage/validate.d.ts +11 -0
- package/dist/core/stage/validate.js +226 -0
- package/dist/core/stage/walk.d.ts +34 -0
- package/dist/core/stage/walk.js +96 -0
- package/dist/dev-overlay/protocol.d.ts +53 -0
- package/dist/dev-overlay/protocol.js +21 -0
- package/dist/fn-context/build-context.d.ts +11 -0
- package/dist/fn-context/build-context.js +21 -0
- package/dist/fn-context/fake/empty-api.d.ts +9 -0
- package/dist/fn-context/fake/empty-api.js +50 -0
- package/dist/fn-context/fake/index.d.ts +12 -0
- package/dist/fn-context/fake/index.js +22 -0
- package/dist/fn-context/index.d.ts +9 -0
- package/dist/fn-context/index.js +8 -0
- package/dist/fn-context/log.d.ts +8 -0
- package/dist/fn-context/log.js +29 -0
- package/dist/fn-context/make-ctx.d.ts +9 -0
- package/dist/fn-context/make-ctx.js +51 -0
- package/dist/fn-context/rpc/errors.d.ts +25 -0
- package/dist/fn-context/rpc/errors.js +23 -0
- package/dist/fn-context/rpc/index.d.ts +10 -0
- package/dist/fn-context/rpc/index.js +9 -0
- package/dist/fn-context/rpc/integration/index.d.ts +51 -0
- package/dist/fn-context/rpc/integration/index.js +19 -0
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +21 -0
- package/dist/fn-context/rpc/integration/list-bindings.js +18 -0
- package/dist/fn-context/rpc/log.d.ts +36 -0
- package/dist/fn-context/rpc/log.js +16 -0
- package/dist/fn-context/rpc/platform.d.ts +28 -0
- package/dist/fn-context/rpc/platform.js +15 -0
- package/dist/fn-context/rpc/request-id.d.ts +5 -0
- package/dist/fn-context/rpc/request-id.js +13 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +7 -0
- package/dist/fn-context/rpc/trpc-client.js +109 -0
- package/dist/fn-context/rpc/trpc-init.d.ts +17 -0
- package/dist/fn-context/rpc/trpc-init.js +17 -0
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +84 -0
- package/dist/fn-context/rpc/trpc-router-factory.js +9 -0
- package/dist/fn-context/types.d.ts +17 -0
- package/dist/fn-context/types.js +2 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +34 -0
- package/dist/voice-service/actions.d.ts +20 -0
- package/dist/voice-service/actions.js +2 -0
- package/dist/voice-service/index.d.ts +3 -0
- package/dist/voice-service/index.js +3 -0
- package/dist/voice-service/types.d.ts +1010 -0
- package/dist/voice-service/types.js +16 -0
- package/package.json +55 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { FieldPath } from '../slot/path.js';
|
|
2
|
+
import type { PlatformApis } from './platform-registry.js';
|
|
3
|
+
import type { DocusignApi } from './docusign.js';
|
|
4
|
+
import type { EnvApi } from './env.js';
|
|
5
|
+
import type { FilevineApi } from './filevine.js';
|
|
6
|
+
import type { HubspotApi } from './hubspot.js';
|
|
7
|
+
import type { TwilioApi } from './twilio.js';
|
|
8
|
+
import type { HttpApi } from './http.js';
|
|
9
|
+
import type { IntegrationAccountFields } from './account-fields.js';
|
|
10
|
+
export type { IntegrationAccountFields, IntegrationTarget } from './account-fields.js';
|
|
11
|
+
export type FieldState = 'empty' | 'filled' | 'asked_unknown' | 'declined';
|
|
12
|
+
/**
|
|
13
|
+
* Fallback Slots. Sequence `__gen/slots.type.ts` provides the narrowed shape;
|
|
14
|
+
* `view.ts` selectors import that type.
|
|
15
|
+
*/
|
|
16
|
+
export type Slots = Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Fallback CaseContext (no view / before narrowing).
|
|
19
|
+
* With `view.ts`, use `CaseContextOf<typeof caseContextView>` from that module.
|
|
20
|
+
*/
|
|
21
|
+
export type CaseContext = Record<string, unknown>;
|
|
22
|
+
export type Writes = Record<FieldPath, unknown>;
|
|
23
|
+
export type Logger = {
|
|
24
|
+
info: (message: string, extra?: Record<string, unknown>) => void;
|
|
25
|
+
warn: (message: string, extra?: Record<string, unknown>) => void;
|
|
26
|
+
error: (message: string, extra?: Record<string, unknown>) => void;
|
|
27
|
+
};
|
|
28
|
+
export type { DocusignApi, DocusignService } from './docusign.js';
|
|
29
|
+
export type { EnvApi, EnvService } from './env.js';
|
|
30
|
+
export type { FilevineApi, FilevineService } from './filevine.js';
|
|
31
|
+
export type { HubspotApi, HubspotService } from './hubspot.js';
|
|
32
|
+
export type { TwilioApi, TwilioCreateCallInput, TwilioCreateCallOutput, TwilioIncomingNumber, TwilioListIncomingNumbersOutput, TwilioSendSmsInput, TwilioSendSmsOutput, TwilioService, } from './twilio.js';
|
|
33
|
+
export type { ContactApi, ContactListParams, ContactListResult, ContactSummary } from './contact.js';
|
|
34
|
+
export type { HttpApi } from './http.js';
|
|
35
|
+
/**
|
|
36
|
+
* Integration API: surfaceKey → array of bound stubs.
|
|
37
|
+
* Add a key here when the platform adds a script surface; the provider table must implement it.
|
|
38
|
+
*/
|
|
39
|
+
export type IntegrationApi = {
|
|
40
|
+
hubspots?: HubspotApi[];
|
|
41
|
+
twilios?: TwilioApi[];
|
|
42
|
+
filevines?: FilevineApi[];
|
|
43
|
+
docusigns?: DocusignApi[];
|
|
44
|
+
envs?: EnvApi[];
|
|
45
|
+
};
|
|
46
|
+
export type IntegrationSurfaceKey = keyof IntegrationApi;
|
|
47
|
+
type SurfaceItem<K extends IntegrationSurfaceKey> = NonNullable<IntegrationApi[K]>[number];
|
|
48
|
+
export type IntegrationStub = SurfaceItem<IntegrationSurfaceKey>;
|
|
49
|
+
export declare const integrationSurfaceKeys: readonly ["hubspots", "twilios", "filevines", "docusigns", "envs"];
|
|
50
|
+
export type BoundIntegrationMeta = IntegrationAccountFields & {
|
|
51
|
+
surfaceKey: IntegrationSurfaceKey;
|
|
52
|
+
methods: string[];
|
|
53
|
+
};
|
|
54
|
+
/** Context injected into custom and system functions. */
|
|
55
|
+
export type SystemContext = {
|
|
56
|
+
time: Readonly<{
|
|
57
|
+
now: number;
|
|
58
|
+
timezone: string;
|
|
59
|
+
today: string;
|
|
60
|
+
}>;
|
|
61
|
+
meta: Readonly<{
|
|
62
|
+
companyId: string;
|
|
63
|
+
environmentId: string;
|
|
64
|
+
sequenceId: string;
|
|
65
|
+
entry: string;
|
|
66
|
+
contactId: string;
|
|
67
|
+
caseId: string;
|
|
68
|
+
}>;
|
|
69
|
+
config: Readonly<{
|
|
70
|
+
frontendUrl: string;
|
|
71
|
+
backendUrl: string;
|
|
72
|
+
}>;
|
|
73
|
+
api: PlatformApis & {
|
|
74
|
+
integration: IntegrationApi;
|
|
75
|
+
log: Logger;
|
|
76
|
+
http: HttpApi;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export type MakeCtxOverrides = {
|
|
80
|
+
today?: string;
|
|
81
|
+
timezone?: string;
|
|
82
|
+
now?: number;
|
|
83
|
+
meta?: Partial<SystemContext['meta']>;
|
|
84
|
+
config?: Partial<SystemContext['config']>;
|
|
85
|
+
api?: Partial<SystemContext['api']>;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** `(slots) => CaseContext` — pure projection; not persisted. */
|
|
2
|
+
export type CaseContextViewFn<S = unknown, C = unknown> = (slots: S) => C;
|
|
3
|
+
/** Tagged by {@link defineCaseContext} so compile can find it. */
|
|
4
|
+
export type DefinedCaseContextView<S = unknown, C = unknown> = CaseContextViewFn<S, C> & {
|
|
5
|
+
kind: 'caseContextView';
|
|
6
|
+
main: CaseContextViewFn<S, C>;
|
|
7
|
+
};
|
|
8
|
+
/** Mark a projector for sequence `view.ts`. */
|
|
9
|
+
export declare function defineCaseContext<S, C>(main: CaseContextViewFn<S, C>): DefinedCaseContextView<S, C>;
|
|
10
|
+
/** `export type CaseContext = CaseContextOf<typeof caseContextView>` */
|
|
11
|
+
export type CaseContextOf<T> = T extends (...args: never) => infer C ? C : never;
|
|
12
|
+
/** Unwrap for compile / host (prefers `.main` when tagged). */
|
|
13
|
+
export declare function resolveCaseContextViewFn(value: unknown): CaseContextViewFn | undefined;
|
|
14
|
+
//# sourceMappingURL=case-context.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Mark a projector for sequence `view.ts`. */
|
|
2
|
+
export function defineCaseContext(main) {
|
|
3
|
+
return Object.assign(main, { kind: 'caseContextView', main });
|
|
4
|
+
}
|
|
5
|
+
/** Unwrap for compile / host (prefers `.main` when tagged). */
|
|
6
|
+
export function resolveCaseContextViewFn(value) {
|
|
7
|
+
if (typeof value !== 'function')
|
|
8
|
+
return undefined;
|
|
9
|
+
const tagged = value;
|
|
10
|
+
if (tagged.kind === 'caseContextView' && typeof tagged.main === 'function') {
|
|
11
|
+
return tagged.main;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=case-context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComputeFn, DefinedFunc, FuncOptions } from '../types.js';
|
|
2
|
+
import type { CaseContext } from '../../context/types.js';
|
|
3
|
+
/** Pure compute / derived field fn. No I/O; no SystemContext. Name = functions-map key. */
|
|
4
|
+
export declare function defineComputeFunc<S = CaseContext, R = unknown>(main: ComputeFn<S, R>, options?: FuncOptions): DefinedFunc;
|
|
5
|
+
/** Boolean compute (finishWhen / applyWhen helpers). */
|
|
6
|
+
export declare function defineBoolComputeFunc<S = CaseContext>(main: ComputeFn<S, boolean>, options?: FuncOptions): DefinedFunc;
|
|
7
|
+
//# sourceMappingURL=compute.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Pure compute / derived field fn. No I/O; no SystemContext. Name = functions-map key. */
|
|
2
|
+
export function defineComputeFunc(main, options) {
|
|
3
|
+
return {
|
|
4
|
+
kind: 'compute',
|
|
5
|
+
main: main,
|
|
6
|
+
...options,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/** Boolean compute (finishWhen / applyWhen helpers). */
|
|
10
|
+
export function defineBoolComputeFunc(main, options) {
|
|
11
|
+
return {
|
|
12
|
+
kind: 'boolCompute',
|
|
13
|
+
main: main,
|
|
14
|
+
...options,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=compute.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CustomFn, DefinedFunc, FuncOptions } from '../types.js';
|
|
2
|
+
import type { CaseContext } from '../../context/types.js';
|
|
3
|
+
export declare function defineCustomFunc<S = CaseContext>(main: CustomFn<S>, options?: FuncOptions): DefinedFunc;
|
|
4
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DefinedFunc, FuncOptions, FunctionCall, WebHookFunctionParams } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Platform lifecycle / webhook entry. Register under the matching key
|
|
4
|
+
* (e.g. `webhook: defineSystemFunc(...)`, `getFirstMessage: defineSystemFunc(...)`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function defineSystemFunc<P extends object = WebHookFunctionParams, R = void>(main: FunctionCall<P, R>, options?: FuncOptions): DefinedFunc;
|
|
7
|
+
//# sourceMappingURL=system.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform lifecycle / webhook entry. Register under the matching key
|
|
3
|
+
* (e.g. `webhook: defineSystemFunc(...)`, `getFirstMessage: defineSystemFunc(...)`).
|
|
4
|
+
*/
|
|
5
|
+
export function defineSystemFunc(main, options) {
|
|
6
|
+
return {
|
|
7
|
+
kind: 'system',
|
|
8
|
+
main: main,
|
|
9
|
+
...options,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DefinedFunc, FuncMap } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Author-time function reference:
|
|
4
|
+
* - string key: `'computeIsQualified'`
|
|
5
|
+
* - map value: `functions.computeIsQualified` ({@link DefinedFunc})
|
|
6
|
+
*
|
|
7
|
+
* Compiled / runtime schemas always store the string name.
|
|
8
|
+
*/
|
|
9
|
+
export type FuncRef = string | DefinedFunc;
|
|
10
|
+
/**
|
|
11
|
+
* Normalize a {@link FuncRef} to the functions-map key.
|
|
12
|
+
* Object refs need the same `functions` map for identity lookup
|
|
13
|
+
* (plain map values do not carry `name`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveFuncName(ref: FuncRef, functions?: FuncMap): string;
|
|
16
|
+
//# sourceMappingURL=func-ref.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a {@link FuncRef} to the functions-map key.
|
|
3
|
+
* Object refs need the same `functions` map for identity lookup
|
|
4
|
+
* (plain map values do not carry `name`).
|
|
5
|
+
*/
|
|
6
|
+
export function resolveFuncName(ref, functions) {
|
|
7
|
+
if (typeof ref === 'string') {
|
|
8
|
+
if (!ref)
|
|
9
|
+
throw new Error('Function reference name must be a non-empty string');
|
|
10
|
+
return ref;
|
|
11
|
+
}
|
|
12
|
+
if (functions) {
|
|
13
|
+
for (const [key, value] of Object.entries(functions)) {
|
|
14
|
+
if (value === ref)
|
|
15
|
+
return key;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw new Error('Invalid function reference; expected a string name or a value from the functions map');
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=func-ref.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { FieldPath } from '../slot/path.js';
|
|
2
|
+
import type { CaseContext, SystemContext, Writes } from '../context/types.js';
|
|
3
|
+
export type FuncOptions = {
|
|
4
|
+
args?: Record<string, unknown>;
|
|
5
|
+
description?: string;
|
|
6
|
+
};
|
|
7
|
+
/** First arg is CaseContext (or Slots when the sequence has no view). */
|
|
8
|
+
export type ComputeFn<S = CaseContext, R = unknown> = (caseContext: S) => R | Promise<R>;
|
|
9
|
+
export type CustomFn<S = CaseContext> = (caseContext: S, ctx: SystemContext) => Promise<Writes | null>;
|
|
10
|
+
/** Inbound webhook request payload. */
|
|
11
|
+
export type WebHookFunctionParams = {
|
|
12
|
+
headers: Record<string, string | string[] | undefined>;
|
|
13
|
+
body: unknown;
|
|
14
|
+
rawBody?: string;
|
|
15
|
+
};
|
|
16
|
+
export type FunctionCtx<Params extends object> = SystemContext & {
|
|
17
|
+
params: Params;
|
|
18
|
+
};
|
|
19
|
+
export type FunctionCall<Params extends object, Return> = (ctx: FunctionCtx<Params>) => Promise<Return>;
|
|
20
|
+
export type WebHookFunction = FunctionCall<WebHookFunctionParams, void>;
|
|
21
|
+
export type GetFirstMessageParams<S = CaseContext> = {
|
|
22
|
+
caseContext: S;
|
|
23
|
+
};
|
|
24
|
+
export type GetFirstMessageFunction<S = CaseContext> = FunctionCall<GetFirstMessageParams<S>, string>;
|
|
25
|
+
/** Object-key → implementation type for platform-invoked entries. */
|
|
26
|
+
export type SystemFuncMap = {
|
|
27
|
+
webhook: WebHookFunction;
|
|
28
|
+
getFirstMessage: GetFirstMessageFunction;
|
|
29
|
+
};
|
|
30
|
+
type FuncMeta = {
|
|
31
|
+
description?: string;
|
|
32
|
+
args?: Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
/** One entry in a plain `functions` map (`{ name: define*Func(...) }`). */
|
|
35
|
+
export type DefinedFunc = (FuncMeta & {
|
|
36
|
+
kind: 'compute' | 'boolCompute';
|
|
37
|
+
/** Implementation retained for compile → registry `code`; stripped from JSON via toFunctionRegistry. */
|
|
38
|
+
main: ComputeFn;
|
|
39
|
+
}) | (FuncMeta & {
|
|
40
|
+
kind: 'custom';
|
|
41
|
+
main: CustomFn;
|
|
42
|
+
}) | (FuncMeta & {
|
|
43
|
+
kind: 'system';
|
|
44
|
+
main: FunctionCall<object, unknown>;
|
|
45
|
+
});
|
|
46
|
+
/** Author map: key is the function name. */
|
|
47
|
+
export type FuncMap = Record<string, DefinedFunc>;
|
|
48
|
+
/** Map entry with name stamped from the key (for platform loaders). */
|
|
49
|
+
export type FuncRegistration = DefinedFunc & {
|
|
50
|
+
name: string;
|
|
51
|
+
};
|
|
52
|
+
type RegistryCode = {
|
|
53
|
+
/**
|
|
54
|
+
* Standalone JS function expression (esbuild-normalized).
|
|
55
|
+
* Present on published builds; omitted on local serve overlay (`includeCode: false`).
|
|
56
|
+
*/
|
|
57
|
+
code?: string;
|
|
58
|
+
};
|
|
59
|
+
/** Compiled function registry entry shapes (JSON-safe). */
|
|
60
|
+
export type FunctionRegistryEntry = (RegistryCode & {
|
|
61
|
+
kind: 'compute' | 'boolCompute';
|
|
62
|
+
}) | (RegistryCode & {
|
|
63
|
+
kind: 'custom';
|
|
64
|
+
writes: FieldPath[];
|
|
65
|
+
}) | (RegistryCode & {
|
|
66
|
+
kind: 'system';
|
|
67
|
+
});
|
|
68
|
+
export type FunctionRegistry = Record<string, FunctionRegistryEntry>;
|
|
69
|
+
/** Compiled CaseContext projector (optional on SequenceBuild). */
|
|
70
|
+
export type CaseContextViewRegistryEntry = {
|
|
71
|
+
kind: 'caseContextView';
|
|
72
|
+
/** Present on published builds; omitted on local serve overlay. */
|
|
73
|
+
code?: string;
|
|
74
|
+
};
|
|
75
|
+
/** Stamp `name` from object keys when the platform loads a functions map. */
|
|
76
|
+
export declare function toFuncRegistrations(functions: FuncMap): FuncRegistration[];
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CompanySchema, EffectiveSchema, SequenceSlots } from './schema.js';
|
|
2
|
+
import type { FuncMap } from '../functions/types.js';
|
|
3
|
+
import type { CompiledSlotSchema, RuntimeTableDef, ValidationResult } from './types.js';
|
|
4
|
+
import { type FieldPath } from './path.js';
|
|
5
|
+
/**
|
|
6
|
+
* Inherit every company table, then apply sequence overlays + session.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compileSlotSchema(company: CompanySchema, sequenceSlots: SequenceSlots, options?: {
|
|
9
|
+
computeFns?: ReadonlySet<string>;
|
|
10
|
+
functions?: FuncMap;
|
|
11
|
+
}): {
|
|
12
|
+
schema: CompiledSlotSchema;
|
|
13
|
+
validation: ValidationResult;
|
|
14
|
+
};
|
|
15
|
+
/** Validate field paths exist on a compiled schema. */
|
|
16
|
+
export declare function validateFieldRefs(schema: CompiledSlotSchema, refs: Iterable<string>): ValidationResult;
|
|
17
|
+
export declare function getCompiledTable(schema: CompiledSlotSchema, tableName: string): RuntimeTableDef | undefined;
|
|
18
|
+
export declare function compiledTableEntries(schema: CompiledSlotSchema): Array<[string, RuntimeTableDef]>;
|
|
19
|
+
/** Snapshot / SF presentation: single → field dict, multi → row array. */
|
|
20
|
+
export declare function isSnapshotSingleRow(table: RuntimeTableDef): boolean;
|
|
21
|
+
/** Effective schema for Slots codegen (multi → array, single → dict). */
|
|
22
|
+
export declare function toEffectiveSchema(compiled: CompiledSlotSchema): EffectiveSchema;
|
|
23
|
+
export declare function listConversationFields(schema: CompiledSlotSchema): FieldPath[];
|
|
24
|
+
//# sourceMappingURL=compile-schema.d.ts.map
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { ROW_ID_FIELD } from './schema.js';
|
|
2
|
+
import { isReservedTableName, isRowIdField } from './row.js';
|
|
3
|
+
import { resolveFuncName } from '../functions/func-ref.js';
|
|
4
|
+
import { buildDependencyGraph } from './deps.js';
|
|
5
|
+
import { formatFieldPath, parseFieldPath } from './path.js';
|
|
6
|
+
function isSessionTable(tableName, table) {
|
|
7
|
+
return tableName === 'session' && 'rows' in table && table.rows === 'single' && 'label' in table;
|
|
8
|
+
}
|
|
9
|
+
function toRuntimeField(field, functions) {
|
|
10
|
+
if (field.derived) {
|
|
11
|
+
return {
|
|
12
|
+
derived: true,
|
|
13
|
+
label: field.label,
|
|
14
|
+
dataType: field.dataType,
|
|
15
|
+
dependsOn: field.dependsOn,
|
|
16
|
+
computeFn: resolveFuncName(field.computeFn, functions),
|
|
17
|
+
deprecated: 'deprecated' in field ? field.deprecated : undefined,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
derived: false,
|
|
22
|
+
label: field.label,
|
|
23
|
+
dataType: field.dataType,
|
|
24
|
+
source: field.source,
|
|
25
|
+
extraction: field.extraction,
|
|
26
|
+
enum: field.enum,
|
|
27
|
+
nullable: field.nullable,
|
|
28
|
+
identifier: 'identifier' in field ? field.identifier : null,
|
|
29
|
+
ref: 'ref' in field && field.ref ? field.ref : null,
|
|
30
|
+
deprecated: 'deprecated' in field ? field.deprecated : undefined,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function applyFieldOverride(field, override) {
|
|
34
|
+
const next = { ...field };
|
|
35
|
+
if (override.label !== undefined)
|
|
36
|
+
next.label = override.label;
|
|
37
|
+
if (override.extraction !== undefined && !next.derived) {
|
|
38
|
+
next.extraction = override.extraction;
|
|
39
|
+
}
|
|
40
|
+
return next;
|
|
41
|
+
}
|
|
42
|
+
function isValidIdField(field) {
|
|
43
|
+
return (!!field && !field.derived && field.dataType === 'string' && field.source === 'system' && field.nullable === false);
|
|
44
|
+
}
|
|
45
|
+
function requireRowIdField(fields, path, issues) {
|
|
46
|
+
const existing = fields[ROW_ID_FIELD];
|
|
47
|
+
if (!existing) {
|
|
48
|
+
issues.push({
|
|
49
|
+
code: 'missing-id-field',
|
|
50
|
+
message: `${path} is required`,
|
|
51
|
+
path,
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!isValidIdField(existing)) {
|
|
56
|
+
issues.push({
|
|
57
|
+
code: 'invalid-id-field',
|
|
58
|
+
message: `${path} must be a non-null system string`,
|
|
59
|
+
path,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function validateCompanyRefs(company, issues) {
|
|
64
|
+
for (const [tableName, table] of Object.entries(company)) {
|
|
65
|
+
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
66
|
+
if (field.derived)
|
|
67
|
+
continue;
|
|
68
|
+
if (!field.ref)
|
|
69
|
+
continue;
|
|
70
|
+
const targetTable = field.ref.table;
|
|
71
|
+
if (isRowIdField(fieldName)) {
|
|
72
|
+
issues.push({
|
|
73
|
+
code: 'id-cannot-ref',
|
|
74
|
+
message: `${tableName}.${ROW_ID_FIELD} cannot be a ref`,
|
|
75
|
+
path: formatFieldPath(tableName, fieldName),
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!company[targetTable]) {
|
|
80
|
+
issues.push({
|
|
81
|
+
code: 'unknown-ref-table',
|
|
82
|
+
message: `ref table not in company schema: ${targetTable}`,
|
|
83
|
+
path: formatFieldPath(tableName, fieldName),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Inherit every company table, then apply sequence overlays + session.
|
|
91
|
+
*/
|
|
92
|
+
export function compileSlotSchema(company, sequenceSlots, options = {}) {
|
|
93
|
+
const issues = [];
|
|
94
|
+
const tables = {};
|
|
95
|
+
if (!sequenceSlots.session) {
|
|
96
|
+
issues.push({
|
|
97
|
+
code: 'missing-session',
|
|
98
|
+
message: 'Sequence slots must define a session table',
|
|
99
|
+
path: 'session',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
for (const [tableName, companyTable] of Object.entries(company)) {
|
|
103
|
+
if (tableName === 'session' || isReservedTableName(tableName)) {
|
|
104
|
+
if (isReservedTableName(tableName)) {
|
|
105
|
+
issues.push({
|
|
106
|
+
code: 'reserved-table-name',
|
|
107
|
+
message: `Table name is reserved: ${tableName}`,
|
|
108
|
+
path: tableName,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const fields = {};
|
|
114
|
+
for (const [fieldName, field] of Object.entries(companyTable.fields)) {
|
|
115
|
+
fields[fieldName] = toRuntimeField(field, options.functions);
|
|
116
|
+
}
|
|
117
|
+
requireRowIdField(fields, formatFieldPath(tableName, ROW_ID_FIELD), issues);
|
|
118
|
+
tables[tableName] = {
|
|
119
|
+
label: companyTable.label,
|
|
120
|
+
rows: companyTable.rows,
|
|
121
|
+
description: companyTable.description,
|
|
122
|
+
fields,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
for (const [tableName, tableView] of Object.entries(sequenceSlots)) {
|
|
126
|
+
if (isReservedTableName(tableName)) {
|
|
127
|
+
issues.push({
|
|
128
|
+
code: 'reserved-table-name',
|
|
129
|
+
message: `Table name is reserved: ${tableName}`,
|
|
130
|
+
path: tableName,
|
|
131
|
+
});
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (isSessionTable(tableName, tableView)) {
|
|
135
|
+
const fields = {};
|
|
136
|
+
for (const [fieldName, fieldDef] of Object.entries(tableView.fields)) {
|
|
137
|
+
if (fieldDef.derived) {
|
|
138
|
+
issues.push({
|
|
139
|
+
code: 'session-derived-forbidden',
|
|
140
|
+
message: 'session table must not define derived fields',
|
|
141
|
+
path: formatFieldPath('session', fieldName),
|
|
142
|
+
});
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
fields[fieldName] = toRuntimeField(fieldDef, options.functions);
|
|
146
|
+
}
|
|
147
|
+
requireRowIdField(fields, formatFieldPath('session', ROW_ID_FIELD), issues);
|
|
148
|
+
tables.session = {
|
|
149
|
+
label: tableView.label,
|
|
150
|
+
rows: 'single',
|
|
151
|
+
description: tableView.description,
|
|
152
|
+
fields,
|
|
153
|
+
};
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const inherited = tables[tableName];
|
|
157
|
+
if (!inherited) {
|
|
158
|
+
issues.push({
|
|
159
|
+
code: 'unknown-table',
|
|
160
|
+
message: `Sequence overrides unknown table: ${tableName}`,
|
|
161
|
+
path: tableName,
|
|
162
|
+
});
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
for (const [fieldName, override] of Object.entries(tableView.fields)) {
|
|
166
|
+
const existing = inherited.fields[fieldName];
|
|
167
|
+
if (!existing) {
|
|
168
|
+
issues.push({
|
|
169
|
+
code: 'unknown-field',
|
|
170
|
+
message: `Sequence overrides unknown field: ${tableName}.${fieldName}`,
|
|
171
|
+
path: formatFieldPath(tableName, fieldName),
|
|
172
|
+
});
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
inherited.fields[fieldName] = applyFieldOverride(existing, override);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
validateCompanyRefs(company, issues);
|
|
179
|
+
// Validate derived placement + dependsOn existence
|
|
180
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
181
|
+
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
182
|
+
const path = formatFieldPath(tableName, fieldName);
|
|
183
|
+
if (!field.derived)
|
|
184
|
+
continue;
|
|
185
|
+
if (table.rows === 'multi') {
|
|
186
|
+
issues.push({
|
|
187
|
+
code: 'multi-derived-forbidden',
|
|
188
|
+
message: `Derived fields are not allowed on multi-row tables: ${path}`,
|
|
189
|
+
path,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (tableName === 'session') {
|
|
193
|
+
issues.push({
|
|
194
|
+
code: 'session-derived-forbidden',
|
|
195
|
+
message: `Derived fields are not allowed on session: ${path}`,
|
|
196
|
+
path,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (options.computeFns && !options.computeFns.has(field.computeFn)) {
|
|
200
|
+
issues.push({
|
|
201
|
+
code: 'missing-compute-fn',
|
|
202
|
+
message: `computeFn not found: ${field.computeFn}`,
|
|
203
|
+
path,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
for (const dep of field.dependsOn) {
|
|
207
|
+
const parsed = parseFieldPath(dep);
|
|
208
|
+
if (!parsed) {
|
|
209
|
+
issues.push({
|
|
210
|
+
code: 'invalid-depends-on',
|
|
211
|
+
message: `Invalid dependsOn path: ${dep}`,
|
|
212
|
+
path,
|
|
213
|
+
});
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const depTable = tables[parsed.table];
|
|
217
|
+
const depField = depTable?.fields[parsed.field];
|
|
218
|
+
if (!depTable || !depField) {
|
|
219
|
+
issues.push({
|
|
220
|
+
code: 'missing-depends-on',
|
|
221
|
+
message: `dependsOn refers to unknown field: ${dep}`,
|
|
222
|
+
path,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Enum / normal field shape checks
|
|
228
|
+
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
229
|
+
if (field.derived)
|
|
230
|
+
continue;
|
|
231
|
+
const path = formatFieldPath(tableName, fieldName);
|
|
232
|
+
if (field.enum) {
|
|
233
|
+
for (const member of field.enum) {
|
|
234
|
+
const memberType = typeof member;
|
|
235
|
+
if ((field.dataType === 'number' && memberType !== 'number') ||
|
|
236
|
+
(field.dataType !== 'number' && field.dataType !== 'boolean' && memberType !== 'string') ||
|
|
237
|
+
(field.dataType === 'boolean' && memberType !== 'boolean')) {
|
|
238
|
+
issues.push({
|
|
239
|
+
code: 'invalid-enum-member',
|
|
240
|
+
message: `enum member ${String(member)} incompatible with dataType ${field.dataType}`,
|
|
241
|
+
path,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const graph = buildDependencyGraph(tables);
|
|
249
|
+
issues.push(...graph.issues);
|
|
250
|
+
const schema = {
|
|
251
|
+
...tables,
|
|
252
|
+
derivedOrder: graph.derivedOrder,
|
|
253
|
+
reverseDeps: graph.reverseDeps,
|
|
254
|
+
};
|
|
255
|
+
return {
|
|
256
|
+
schema,
|
|
257
|
+
validation: issues.length === 0 ? { ok: true } : { ok: false, issues },
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Validate field paths exist on a compiled schema. */
|
|
261
|
+
export function validateFieldRefs(schema, refs) {
|
|
262
|
+
const issues = [];
|
|
263
|
+
for (const ref of refs) {
|
|
264
|
+
const parsed = parseFieldPath(ref);
|
|
265
|
+
if (!parsed) {
|
|
266
|
+
issues.push({
|
|
267
|
+
code: 'invalid-field-path',
|
|
268
|
+
message: `Invalid field path: ${ref}`,
|
|
269
|
+
path: ref,
|
|
270
|
+
});
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const field = getCompiledTable(schema, parsed.table)?.fields[parsed.field];
|
|
274
|
+
if (!field) {
|
|
275
|
+
issues.push({
|
|
276
|
+
code: 'unknown-field',
|
|
277
|
+
message: `Unknown field: ${ref}`,
|
|
278
|
+
path: ref,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return issues.length === 0 ? { ok: true } : { ok: false, issues };
|
|
283
|
+
}
|
|
284
|
+
export function getCompiledTable(schema, tableName) {
|
|
285
|
+
if (isReservedTableName(tableName))
|
|
286
|
+
return undefined;
|
|
287
|
+
const value = schema[tableName];
|
|
288
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || !('fields' in value)) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
return value;
|
|
292
|
+
}
|
|
293
|
+
export function compiledTableEntries(schema) {
|
|
294
|
+
const out = [];
|
|
295
|
+
for (const key of Object.keys(schema)) {
|
|
296
|
+
const table = getCompiledTable(schema, key);
|
|
297
|
+
if (table)
|
|
298
|
+
out.push([key, table]);
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
/** Snapshot / SF presentation: single → field dict, multi → row array. */
|
|
303
|
+
export function isSnapshotSingleRow(table) {
|
|
304
|
+
return table.rows === 'single';
|
|
305
|
+
}
|
|
306
|
+
/** Effective schema for Slots codegen (multi → array, single → dict). */
|
|
307
|
+
export function toEffectiveSchema(compiled) {
|
|
308
|
+
const tables = {};
|
|
309
|
+
for (const [tableName, table] of compiledTableEntries(compiled)) {
|
|
310
|
+
const fields = {};
|
|
311
|
+
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
312
|
+
fields[fieldName] = {
|
|
313
|
+
dataType: field.dataType,
|
|
314
|
+
enum: field.derived ? null : field.enum,
|
|
315
|
+
nullable: field.derived ? true : field.nullable,
|
|
316
|
+
ref: field.derived ? null : (field.ref ?? null),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
tables[tableName] = { rows: table.rows, fields };
|
|
320
|
+
}
|
|
321
|
+
return tables;
|
|
322
|
+
}
|
|
323
|
+
export function listConversationFields(schema) {
|
|
324
|
+
const out = [];
|
|
325
|
+
for (const [tableName, table] of compiledTableEntries(schema)) {
|
|
326
|
+
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
327
|
+
if (field.derived)
|
|
328
|
+
continue;
|
|
329
|
+
if (field.source !== 'conversation')
|
|
330
|
+
continue;
|
|
331
|
+
out.push(formatFieldPath(tableName, fieldName));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=compile-schema.js.map
|