@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
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page module (15 §10.2–§10.6): what a sequence's `context.page.ts` is written with. It runs
|
|
3
|
+
* inside the QuickJS sandbox, bundled into the page script, so it imports nothing at runtime and only
|
|
4
|
+
* uses `globalThis.__host` (the sandbox's async host call, services `page/sandbox.ts`).
|
|
5
|
+
*
|
|
6
|
+
* A page script reads with `db` and returns a free-form document: objects are blocks, arrays are
|
|
7
|
+
* lists, a slot is a cell, `field(slot, …)` a cell with page settings, other plain values read-only
|
|
8
|
+
* content, and actions (`createRow`, `deleteRow`, `defineAction`) buttons. The platform turns the
|
|
9
|
+
* document into a `RenderedPage` (`render.ts`).
|
|
10
|
+
*/
|
|
11
|
+
import type { Channel, Direction } from '../conversation/index.js';
|
|
12
|
+
import type { TimelineEntry, TimelineWhere } from './timeline.js';
|
|
13
|
+
export type SlotState = 'filled' | 'empty' | 'asked_unknown' | 'declined';
|
|
14
|
+
export type SlotRef = {
|
|
15
|
+
table: string;
|
|
16
|
+
id: string;
|
|
17
|
+
field: string;
|
|
18
|
+
};
|
|
19
|
+
/** One field as read: plain data, never mutated. */
|
|
20
|
+
export type Slot<V = unknown> = Readonly<{
|
|
21
|
+
value: V | null;
|
|
22
|
+
state: SlotState;
|
|
23
|
+
reason: string | null;
|
|
24
|
+
updatedAt: string | null;
|
|
25
|
+
ref: SlotRef;
|
|
26
|
+
/** The target row, on a lookup that was `include`d. */
|
|
27
|
+
row?: PageRow | null;
|
|
28
|
+
}>;
|
|
29
|
+
/** A row as `db` returns it: `id`, one slot per field. */
|
|
30
|
+
export type PageRow = {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
} & {
|
|
33
|
+
readonly [field: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
export type FindArgs = {
|
|
36
|
+
where?: Record<string, unknown>;
|
|
37
|
+
include?: Record<string, unknown>;
|
|
38
|
+
select?: Record<string, boolean>;
|
|
39
|
+
orderBy?: Record<string, 'asc' | 'desc'> | Array<Record<string, 'asc' | 'desc'>>;
|
|
40
|
+
take?: number;
|
|
41
|
+
skip?: number;
|
|
42
|
+
cursor?: {
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** One table's read methods (Prisma Client's read-only subset). */
|
|
47
|
+
export type TableReader<Row = PageRow> = {
|
|
48
|
+
readonly $table: string;
|
|
49
|
+
findUnique(args: {
|
|
50
|
+
where: Record<string, unknown>;
|
|
51
|
+
include?: FindArgs['include'];
|
|
52
|
+
select?: FindArgs['select'];
|
|
53
|
+
}): Promise<Row | null>;
|
|
54
|
+
findFirst(args: FindArgs): Promise<Row | null>;
|
|
55
|
+
findMany(args: FindArgs): Promise<Row[]>;
|
|
56
|
+
count(args: {
|
|
57
|
+
where: Record<string, unknown>;
|
|
58
|
+
}): Promise<number>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Prisma-shaped writes of an action's `run` (15 §10.6.1): create / update / upsert / delete. `upsert`
|
|
62
|
+
* finds the row by one `unique` field (18-record-search-index §4.5): updated when there is one, else
|
|
63
|
+
* created with that value.
|
|
64
|
+
*/
|
|
65
|
+
export type TableWriter = {
|
|
66
|
+
create(args: {
|
|
67
|
+
data: Record<string, unknown>;
|
|
68
|
+
}): Promise<{
|
|
69
|
+
id: string;
|
|
70
|
+
}>;
|
|
71
|
+
update(args: {
|
|
72
|
+
where: {
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
75
|
+
data: Record<string, unknown>;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
id: string;
|
|
78
|
+
}>;
|
|
79
|
+
upsert(args: {
|
|
80
|
+
where: Record<string, unknown>;
|
|
81
|
+
create: Record<string, unknown>;
|
|
82
|
+
update: Record<string, unknown>;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
id: string;
|
|
85
|
+
}>;
|
|
86
|
+
delete(args: {
|
|
87
|
+
where: {
|
|
88
|
+
id: string;
|
|
89
|
+
};
|
|
90
|
+
reason?: string;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
id: string;
|
|
93
|
+
}>;
|
|
94
|
+
};
|
|
95
|
+
/** `db` where only reading is allowed (a page render): each table's read methods. */
|
|
96
|
+
export type ReadDb = {
|
|
97
|
+
readonly [table: string]: TableReader;
|
|
98
|
+
};
|
|
99
|
+
/** `db`, Prisma-shaped: each table's read and write methods on one object. */
|
|
100
|
+
export type Db = {
|
|
101
|
+
readonly [table: string]: TableReader & TableWriter;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* What the platform knows about this conversation (11-remove-sequence-schema §3.3): written once when
|
|
105
|
+
* its session opened, read-only, never a cell.
|
|
106
|
+
*/
|
|
107
|
+
export type PageConversation = {
|
|
108
|
+
/** The session id. */
|
|
109
|
+
id: string;
|
|
110
|
+
channel: Channel;
|
|
111
|
+
/** Who started this conversation; a resumed one keeps it. */
|
|
112
|
+
direction: Direction;
|
|
113
|
+
/** The contact was created while this conversation opened. */
|
|
114
|
+
isNewContact: boolean;
|
|
115
|
+
/** ISO timestamp the session opened. */
|
|
116
|
+
startedAt: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Counts over this instance, worked out when the page renders (11-remove-sequence-schema §3.3.1).
|
|
120
|
+
* The first call of the instance is `await history.sessionCount({ channel: 'call' }) === 1`.
|
|
121
|
+
*/
|
|
122
|
+
export type PageHistory = {
|
|
123
|
+
/** Conversations (sessions) of this instance, every contact, the current one included. */
|
|
124
|
+
sessionCount(where?: {
|
|
125
|
+
channel?: Channel;
|
|
126
|
+
}): Promise<number>;
|
|
127
|
+
/**
|
|
128
|
+
* Exchanges of this instance recorded so far (an unanswered dial included). The current
|
|
129
|
+
* conversation's own is recorded once its first step is decided, so the opening decision does not
|
|
130
|
+
* count it (a scheduled call's, written before dialing, it does); later turns do. "Is this the first
|
|
131
|
+
* call" is `sessionCount`'s question.
|
|
132
|
+
*/
|
|
133
|
+
exchangeCount(where?: {
|
|
134
|
+
channel?: Channel;
|
|
135
|
+
direction?: Direction;
|
|
136
|
+
}): Promise<number>;
|
|
137
|
+
/**
|
|
138
|
+
* The case's timeline (20 §3): messages, calls, the AI's runs and actions, field changes, scheduled
|
|
139
|
+
* contacts, oldest first; the newest `limit` (50) unless `before` pages back. A text page can show the
|
|
140
|
+
* last call; a call page, the texts since.
|
|
141
|
+
*/
|
|
142
|
+
timeline(where?: TimelineWhere): Promise<TimelineEntry[]>;
|
|
143
|
+
};
|
|
144
|
+
/** The channels a page function is written for (17b §9.1, 20 §5.1): one page function per channel. */
|
|
145
|
+
export type PageChannel = 'call' | 'sms' | 'email';
|
|
146
|
+
/**
|
|
147
|
+
* What the platform recorded (17b §9.8), read-only. `actions` by action key: every run of an action in
|
|
148
|
+
* this run on this case (one the page function returned, or a button the AI pressed), oldest first;
|
|
149
|
+
* `caseActions` the same for the whole case, every channel and run (21 §6.7).
|
|
150
|
+
*/
|
|
151
|
+
export type PageRuns = {
|
|
152
|
+
actions: Record<string, PageActionRun[]>;
|
|
153
|
+
caseActions: Record<string, PageActionRun[]>;
|
|
154
|
+
};
|
|
155
|
+
/** Where `tried()` and `lastActionRun()` look: this run on this case (the default), or the whole case. */
|
|
156
|
+
export type ActionRunScope = 'run' | 'case';
|
|
157
|
+
/** `started`: under way (a keypad or a transfer waiting for its result, a function running). */
|
|
158
|
+
export type PageActionRun = {
|
|
159
|
+
result: 'ok' | 'failed' | 'started';
|
|
160
|
+
/** ISO time. */
|
|
161
|
+
at: string;
|
|
162
|
+
error?: string;
|
|
163
|
+
/** What a channel action brought back (the digits pressed), or what a function returned (25 §11, as text). */
|
|
164
|
+
value?: string;
|
|
165
|
+
};
|
|
166
|
+
/** Whether the action `key` ran at least once (whatever its result), in this run or (`'case'`) on the case. */
|
|
167
|
+
export declare function tried(runs: PageRuns | null | undefined, key: string, scope?: ActionRunScope): boolean;
|
|
168
|
+
/** The latest run of the action `key`, in this run or (`'case'`) on the case, if any. */
|
|
169
|
+
export declare function lastActionRun(runs: PageRuns | null | undefined, key: string, scope?: ActionRunScope): PageActionRun | null;
|
|
170
|
+
/** An agreed follow-up: the channel, when (ISO), and what it is about. */
|
|
171
|
+
export type PageFollowUp = {
|
|
172
|
+
channel: string;
|
|
173
|
+
scheduledFor: string;
|
|
174
|
+
note: string | null;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* The button that books what the customer just asked for or agreed to (25 §5): a call back, a text, an
|
|
178
|
+
* email, at the time they said. The platform books it at once as an agreed follow-up (09): the exchange
|
|
179
|
+
* and the time of their words are its own; the AI gives the channel, the time and their words.
|
|
180
|
+
*/
|
|
181
|
+
export type FollowUpAction = {
|
|
182
|
+
$action: 'followUp';
|
|
183
|
+
/** The run key (default `followUp`). */
|
|
184
|
+
key: string;
|
|
185
|
+
/** The channels the customer may be followed up on, of the ones this sequence has a page for. */
|
|
186
|
+
channels: Array<'call' | 'sms' | 'email'>;
|
|
187
|
+
label?: string;
|
|
188
|
+
description?: string;
|
|
189
|
+
};
|
|
190
|
+
/** `ctx.followUps`: the agreed follow-ups still to come, and `agree(...)`, the button that books one. */
|
|
191
|
+
export type PageFollowUps = PageFollowUp[] & {
|
|
192
|
+
agree(options: {
|
|
193
|
+
channels: Array<'call' | 'sms' | 'email'>;
|
|
194
|
+
key?: string;
|
|
195
|
+
label?: string;
|
|
196
|
+
description?: string;
|
|
197
|
+
}): FollowUpAction;
|
|
198
|
+
};
|
|
199
|
+
/** The agreed follow-ups with the button that books one. */
|
|
200
|
+
export declare function pageFollowUps(list: readonly PageFollowUp[]): PageFollowUps;
|
|
201
|
+
/**
|
|
202
|
+
* One FAQ entry (24 §7): its id, what it covers (the catalog in the prompt shows these two), and the
|
|
203
|
+
* answer (the AI fetches it with `get_faq`).
|
|
204
|
+
*/
|
|
205
|
+
export type PageFaqEntry = {
|
|
206
|
+
id: string;
|
|
207
|
+
description: string;
|
|
208
|
+
content: string;
|
|
209
|
+
};
|
|
210
|
+
/** At most this many FAQ entries in a conversation (24 §7.2): the catalog is in every prompt. */
|
|
211
|
+
export declare const MAX_FAQ_ENTRIES = 100;
|
|
212
|
+
/** What the page decides once, when the conversation starts (24 §4): who the AI is, and its FAQ. */
|
|
213
|
+
export type PageStart = {
|
|
214
|
+
persona: string;
|
|
215
|
+
faq: PageFaqEntry[];
|
|
216
|
+
};
|
|
217
|
+
/** The scheduled contact this conversation carries out (an outbound call or message, 09 §3.5). */
|
|
218
|
+
export type PageScheduledAction = {
|
|
219
|
+
id: string;
|
|
220
|
+
/** What the contact agreed to, in the exchange where they agreed; null for a routine follow-up. */
|
|
221
|
+
agreedInExchangeId: string | null;
|
|
222
|
+
/** The contact's own words agreeing to it; null for a routine follow-up. */
|
|
223
|
+
customerQuote: string | null;
|
|
224
|
+
note: string | null;
|
|
225
|
+
/** ISO time it was scheduled for. */
|
|
226
|
+
scheduledFor: string;
|
|
227
|
+
};
|
|
228
|
+
export type PageBaseContext = {
|
|
229
|
+
/** Read-only: a render never writes. */
|
|
230
|
+
db: ReadDb;
|
|
231
|
+
/** What the platform recorded in this conversation; empty outside one. */
|
|
232
|
+
runs: PageRuns;
|
|
233
|
+
/** Why this conversation happened when the platform started it (17b §9.2); null for an inbound one. */
|
|
234
|
+
scheduledAction: PageScheduledAction | null;
|
|
235
|
+
/** The sequence's office hours now; null when it has none. */
|
|
236
|
+
officeHours: {
|
|
237
|
+
open: boolean;
|
|
238
|
+
timezone: string;
|
|
239
|
+
today: Array<{
|
|
240
|
+
start: string;
|
|
241
|
+
end: string;
|
|
242
|
+
}>;
|
|
243
|
+
} | null;
|
|
244
|
+
/**
|
|
245
|
+
* The contact's agreed follow-ups still to come (09): calls and messages they asked for or agreed to,
|
|
246
|
+
* soonest first. Empty without a Case Orchestrator (nothing books them). `ctx.followUps.agree({ channels })`
|
|
247
|
+
* is the button that books one when the customer asks for it (25 §5).
|
|
248
|
+
*/
|
|
249
|
+
followUps: PageFollowUps;
|
|
250
|
+
/** The business root's id. */
|
|
251
|
+
subject: string;
|
|
252
|
+
/** The contact of the conversation; null outside one. */
|
|
253
|
+
caller: PageRow | null;
|
|
254
|
+
/** This conversation's session row (the session fields, cells); null outside one. */
|
|
255
|
+
session: PageRow | null;
|
|
256
|
+
/** This conversation's platform facts; null outside one. */
|
|
257
|
+
conversation: PageConversation | null;
|
|
258
|
+
/** Counts over this instance. */
|
|
259
|
+
history: PageHistory;
|
|
260
|
+
/** ISO timestamp of this render. */
|
|
261
|
+
now: string;
|
|
262
|
+
/** A text or an email to send now (25 §8): `ctx.messages.text('link', { body })`. */
|
|
263
|
+
messages: PageMessages;
|
|
264
|
+
/** Times for people (25 §11): the sandbox has no `Intl`, so formatting goes through the platform. */
|
|
265
|
+
time: PageTime;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* `ctx.time` (25 §11): the contact's time zone and today there, `format` for a time as people read it,
|
|
269
|
+
* and `day` for the calendar day of a time. `zone` is the contact's `timezone`, else worked out from
|
|
270
|
+
* their postal code, state or phone.
|
|
271
|
+
*/
|
|
272
|
+
export type PageTime = {
|
|
273
|
+
/** The contact's time zone (America/New_York without a contact). */
|
|
274
|
+
zone: string;
|
|
275
|
+
/** Today, `YYYY-MM-DD`, in `zone`. */
|
|
276
|
+
today: string;
|
|
277
|
+
/** `at` as people read it, in `timeZone` (default `zone`): "Tue, Nov 3, 3:00 PM EST". */
|
|
278
|
+
format(at: string, options?: {
|
|
279
|
+
timeZone?: string;
|
|
280
|
+
style?: 'datetime' | 'date' | 'time';
|
|
281
|
+
}): Promise<string>;
|
|
282
|
+
/** The calendar day (`YYYY-MM-DD`) at `at` in `timeZone` (default `zone`), to compare days or key a rule by date. */
|
|
283
|
+
day(at: string | number, timeZone?: string): Promise<string>;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* A text the customer sent since the last run (20 §5.2): what this run is for. `earlier`: sent before,
|
|
287
|
+
* in a run that failed, and not answered yet (20 §5.4).
|
|
288
|
+
*/
|
|
289
|
+
export type PageSmsMessage = {
|
|
290
|
+
id: string;
|
|
291
|
+
body: string;
|
|
292
|
+
at: string;
|
|
293
|
+
earlier?: boolean;
|
|
294
|
+
};
|
|
295
|
+
/** An email the customer sent since the last run (20 §5.2), quoted history and signature taken out. */
|
|
296
|
+
export type PageEmailMessage = {
|
|
297
|
+
id: string;
|
|
298
|
+
from: string;
|
|
299
|
+
to: string[];
|
|
300
|
+
cc: string[];
|
|
301
|
+
subject: string | null;
|
|
302
|
+
body: string;
|
|
303
|
+
at: string;
|
|
304
|
+
/** Listed only (20 §7): their contents are not read yet. */
|
|
305
|
+
attachments: Array<{
|
|
306
|
+
name: string;
|
|
307
|
+
contentType?: string;
|
|
308
|
+
}>;
|
|
309
|
+
/** Sent before, in a run that failed, and not answered yet (20 §5.4). */
|
|
310
|
+
earlier?: boolean;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* This person's previous call on this case (21 §5.2): the facts a page decides by whether to pick up where it
|
|
314
|
+
* left off (a line dropped a minute ago) or open as usual (a call a week ago, or one handed to a person). A
|
|
315
|
+
* new call never carries the previous one's conversation or session fields.
|
|
316
|
+
*/
|
|
317
|
+
export type PagePreviousCall = {
|
|
318
|
+
/** ISO time it ended. */
|
|
319
|
+
endedAt: string;
|
|
320
|
+
direction: Direction;
|
|
321
|
+
/** How the call went: connected, no_answer, busy, failed, fallback, apology. */
|
|
322
|
+
outcome: string | null;
|
|
323
|
+
/** How its conversation ended, when the AI took it: `hangup` (the line closed: the caller hung up, or it dropped), `end` (the AI ended it), `transfer`, `error`. */
|
|
324
|
+
endedBy: string | null;
|
|
325
|
+
/** Its last lines, oldest first. */
|
|
326
|
+
lastLines: Array<{
|
|
327
|
+
speaker: 'party' | 'ai';
|
|
328
|
+
text: string;
|
|
329
|
+
}>;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Who answered an outbound call (25 §13), as the voice service tells it: a person, a voicemail greeting,
|
|
333
|
+
* a call-screening assistant, a phone menu; `said`: what it said. The page decides what to do: leave a
|
|
334
|
+
* message (`ctx.call.voicemail`), tell the screener who calls and why (`announce`), press keys (`keypad`),
|
|
335
|
+
* end. A page that returns nothing for it leaves the voice service to do what it does on its own (hang
|
|
336
|
+
* up on a machine).
|
|
337
|
+
*/
|
|
338
|
+
export type PageFarEnd = {
|
|
339
|
+
kind: 'human' | 'voicemail' | 'screening' | 'ivr';
|
|
340
|
+
said: string;
|
|
341
|
+
};
|
|
342
|
+
/** What only a call can do (20 §5.2): on `ctx.call`, so a text's page cannot even write it. */
|
|
343
|
+
export type PageCallCaps = {
|
|
344
|
+
transferTo: typeof transferTo;
|
|
345
|
+
keypad: typeof keypad;
|
|
346
|
+
announce: typeof announce;
|
|
347
|
+
voicemail: typeof voicemail;
|
|
348
|
+
/** This person's previous call on this case; null when there is none. */
|
|
349
|
+
previous: PagePreviousCall | null;
|
|
350
|
+
/** Who answered, once the voice service knows (25 §13); null until then, and on an inbound call. */
|
|
351
|
+
farEnd: PageFarEnd | null;
|
|
352
|
+
};
|
|
353
|
+
/** What each channel adds to the page function's context (20 §5.2). */
|
|
354
|
+
export type PageChannelCaps = {
|
|
355
|
+
call: {
|
|
356
|
+
call: PageCallCaps;
|
|
357
|
+
};
|
|
358
|
+
sms: {
|
|
359
|
+
sms: {
|
|
360
|
+
inbound: PageSmsMessage[];
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
email: {
|
|
364
|
+
email: {
|
|
365
|
+
inbound: PageEmailMessage[];
|
|
366
|
+
mailbox: string;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
/** The context of one channel's page function. */
|
|
371
|
+
export type PageContextOf<C extends PageChannel> = PageBaseContext & {
|
|
372
|
+
channel: C;
|
|
373
|
+
} & PageChannelCaps[C];
|
|
374
|
+
/** Any channel's context: what a helper shared by several page functions takes (switch on `channel`). */
|
|
375
|
+
export type PageContext = {
|
|
376
|
+
[C in PageChannel]: PageContextOf<C>;
|
|
377
|
+
}[PageChannel];
|
|
378
|
+
export type ActionContext = {
|
|
379
|
+
db: Db;
|
|
380
|
+
subject: string;
|
|
381
|
+
caller: PageRow | null;
|
|
382
|
+
/**
|
|
383
|
+
* On a call, this party's session for this case (25 §9), as `ctx.session` on the page; null by text and
|
|
384
|
+
* email. `db.session.update({ where: { id: session.id }, data })` writes it in the action's transaction.
|
|
385
|
+
*/
|
|
386
|
+
session: PageRow | null;
|
|
387
|
+
now: string;
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Page settings of a cell `field(...)` opens: `readOnly` to show it with these settings without opening
|
|
391
|
+
* it, and `expand` to show the AI its definition (type, allowed values, how to fill it; 24 §2.2), not
|
|
392
|
+
* shown when left out. How to fill a field on this page is the page's `$extraction`, one per field for
|
|
393
|
+
* the whole page (26 §15.3); `extraction` here is refused. `hint` was renamed and is refused;
|
|
394
|
+
* `required` was removed (24 §2.3).
|
|
395
|
+
*/
|
|
396
|
+
export type FieldOptions = {
|
|
397
|
+
readOnly?: boolean;
|
|
398
|
+
expand?: boolean;
|
|
399
|
+
extraction?: MovedOption<'$extraction'>;
|
|
400
|
+
hint?: MovedOption<'$extraction'>;
|
|
401
|
+
required?: RemovedOption;
|
|
402
|
+
};
|
|
403
|
+
/** A removed option: any value is a type error. */
|
|
404
|
+
export type RemovedOption = never;
|
|
405
|
+
/** A removed option: any value is a type error whose message names the new one. */
|
|
406
|
+
export type RenamedOption<New extends string> = `renamed: use ${New}`;
|
|
407
|
+
/** An option that moved to the page: any value is a type error whose message names where it went. */
|
|
408
|
+
export type MovedOption<Where extends string> = `moved: use the page's ${Where}`;
|
|
409
|
+
export type FieldCell<S = Slot> = {
|
|
410
|
+
$field: true;
|
|
411
|
+
slot: S;
|
|
412
|
+
readOnly?: boolean;
|
|
413
|
+
expand?: boolean;
|
|
414
|
+
};
|
|
415
|
+
/** A row a ref field may point at, and what the AI sees of it (26 §16.2 #7). */
|
|
416
|
+
export type RefOption = {
|
|
417
|
+
id: string;
|
|
418
|
+
label: string;
|
|
419
|
+
};
|
|
420
|
+
export type RefFieldOptions = {
|
|
421
|
+
/**
|
|
422
|
+
* The rows it may point at, with their labels: `[{ id, label }]`, or `choose(rows, label)`. Read-only:
|
|
423
|
+
* only to label the current value (put the current row in it). None: only the row's name is shown.
|
|
424
|
+
*/
|
|
425
|
+
options?: readonly RefOption[] | ChooseParam;
|
|
426
|
+
readOnly?: boolean;
|
|
427
|
+
};
|
|
428
|
+
/** A ref field on the page (26 §16.2 #7): its candidates given by the page, each with its label. */
|
|
429
|
+
export type RefFieldCell<S = Slot> = {
|
|
430
|
+
$refField: true;
|
|
431
|
+
slot: S;
|
|
432
|
+
options: RefOption[];
|
|
433
|
+
readOnly?: boolean;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* A parameter taken from the schema (`schemaField('providers.name')`): the platform fills in its type,
|
|
437
|
+
* allowed values, label and `extraction` (the page's `extraction` replaces the schema's). `table.id`,
|
|
438
|
+
* or a lookup field, chooses a row on the page.
|
|
439
|
+
*/
|
|
440
|
+
export type SchemaFieldParam = {
|
|
441
|
+
$schemaField: string;
|
|
442
|
+
extraction?: string;
|
|
443
|
+
};
|
|
444
|
+
/** `schemaField()` options. `description` was renamed `extraction` and is refused. */
|
|
445
|
+
export type SchemaFieldOptions = {
|
|
446
|
+
extraction?: string;
|
|
447
|
+
description?: RenamedOption<'extraction'>;
|
|
448
|
+
};
|
|
449
|
+
/** One parameter of an action: a schema field, or plain JSON Schema (function call `parameters`). */
|
|
450
|
+
export type ActionParam = SchemaFieldParam | {
|
|
451
|
+
type: 'string' | 'number' | 'integer' | 'boolean';
|
|
452
|
+
description?: string;
|
|
453
|
+
enum?: Array<string | number>;
|
|
454
|
+
} | {
|
|
455
|
+
type: 'array';
|
|
456
|
+
items: ActionParam;
|
|
457
|
+
description?: string;
|
|
458
|
+
} | {
|
|
459
|
+
type: 'object';
|
|
460
|
+
properties: Record<string, ActionParam>;
|
|
461
|
+
required?: string[];
|
|
462
|
+
description?: string;
|
|
463
|
+
};
|
|
464
|
+
/** An action's `parameters`, as an LLM function call declares them. */
|
|
465
|
+
export type ActionParameters = {
|
|
466
|
+
type: 'object';
|
|
467
|
+
properties: Record<string, ActionParam>;
|
|
468
|
+
required?: string[];
|
|
469
|
+
};
|
|
470
|
+
export type CreateRowAction = {
|
|
471
|
+
$action: 'createRow';
|
|
472
|
+
table: string;
|
|
473
|
+
label?: string;
|
|
474
|
+
description?: string;
|
|
475
|
+
fields: string[];
|
|
476
|
+
required: string[];
|
|
477
|
+
/** Preset values (the parent, `status: 'active'`): kept on the server, never shown to the AI. */
|
|
478
|
+
prefill: Record<string, unknown>;
|
|
479
|
+
};
|
|
480
|
+
export type DeleteRowAction = {
|
|
481
|
+
$action: 'deleteRow';
|
|
482
|
+
rowId: string;
|
|
483
|
+
label?: string;
|
|
484
|
+
description?: string;
|
|
485
|
+
reason?: string;
|
|
486
|
+
};
|
|
487
|
+
export type CustomAction = {
|
|
488
|
+
$action: 'custom';
|
|
489
|
+
name: string;
|
|
490
|
+
description: string;
|
|
491
|
+
parameters: ActionParameters;
|
|
492
|
+
/** Parameters filled where the page placed the action: kept on the server, never shown to the AI. */
|
|
493
|
+
prefill: Record<string, unknown>;
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* A company function (`functions/`, `defineCaseFunc`) as a button, or returned by the page function to
|
|
497
|
+
* run now (20 §6.2). It runs on the Worker, outside the page's transaction, and is waited for; on a call,
|
|
498
|
+
* `say` is said first and the customer cannot interrupt until it is done (20 §6.3).
|
|
499
|
+
*/
|
|
500
|
+
export type FunctionAction = {
|
|
501
|
+
$action: 'function';
|
|
502
|
+
name: string;
|
|
503
|
+
label?: string;
|
|
504
|
+
description?: string;
|
|
505
|
+
/** Said first, verbatim, on a call only (ignored elsewhere): the customer only listens meanwhile. */
|
|
506
|
+
say?: string;
|
|
507
|
+
/** What the AI fills: plain JSON Schema or schema fields, as a custom action's. */
|
|
508
|
+
parameters?: ActionParameters;
|
|
509
|
+
/** Parameters the page fills (a row's id) or offers rows for (`choose(...)`, 25 §10); kept on the server. */
|
|
510
|
+
prefill?: Record<string, unknown>;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* The rows a row parameter may be chosen among (25 §10), with what the AI sees of each:
|
|
514
|
+
* `cancel({ appointment: choose(appointments, (a) => `${a.date.value} with ${a.provider.value}`) })`. The
|
|
515
|
+
* candidates are these rows, wherever else the page shows them (or not); none: the button is left off.
|
|
516
|
+
*/
|
|
517
|
+
export type ChooseParam = {
|
|
518
|
+
$choose: true;
|
|
519
|
+
table: string | null;
|
|
520
|
+
options: Array<{
|
|
521
|
+
id: string;
|
|
522
|
+
label: string;
|
|
523
|
+
}>;
|
|
524
|
+
};
|
|
525
|
+
export declare function choose<R extends PageRow>(rows: readonly R[], label: (row: R) => string): ChooseParam;
|
|
526
|
+
export declare function isChoose(value: unknown): value is ChooseParam;
|
|
527
|
+
/**
|
|
528
|
+
* A text or an email sent now (25 §8), on the platform's own way out: from this call's number (a text)
|
|
529
|
+
* or the contact's mailbox (an email), opt-outs checked, recorded on the case and this run. What the page
|
|
530
|
+
* leaves out the AI writes: `body`, and an email's `subject`.
|
|
531
|
+
*/
|
|
532
|
+
export type MessageAction = {
|
|
533
|
+
$action: 'message';
|
|
534
|
+
channel: 'sms' | 'email';
|
|
535
|
+
/** The run key: `lastActionRun(ctx.runs, key)` says whether it went. */
|
|
536
|
+
key: string;
|
|
537
|
+
/** The contact it goes to (a contact row the page read); absent: the contact of this conversation. */
|
|
538
|
+
to?: string;
|
|
539
|
+
/** The text, word for word; absent: the AI writes it. */
|
|
540
|
+
body?: string;
|
|
541
|
+
/** An email's subject; absent: the AI writes it. */
|
|
542
|
+
subject?: string;
|
|
543
|
+
/** On a call, said once it went (`'I just texted you the link.'`); ignored elsewhere. */
|
|
544
|
+
say?: string;
|
|
545
|
+
label?: string;
|
|
546
|
+
description?: string;
|
|
547
|
+
};
|
|
548
|
+
export type MessageOptions = {
|
|
549
|
+
to?: PageRow | string;
|
|
550
|
+
body?: string;
|
|
551
|
+
say?: string;
|
|
552
|
+
label?: string;
|
|
553
|
+
description?: string;
|
|
554
|
+
};
|
|
555
|
+
/** `ctx.messages` (25 §8): a text or an email to send now, as a button or returned to run at once. */
|
|
556
|
+
export type PageMessages = {
|
|
557
|
+
text(key: string, options?: MessageOptions): MessageAction;
|
|
558
|
+
email(key: string, options?: MessageOptions & {
|
|
559
|
+
subject?: string;
|
|
560
|
+
}): MessageAction;
|
|
561
|
+
};
|
|
562
|
+
export declare const messages: PageMessages;
|
|
563
|
+
export type PageAction = CreateRowAction | DeleteRowAction | CustomAction | ChannelAction | FunctionAction | MessageAction | FollowUpAction;
|
|
564
|
+
/** Hand the call to a person. */
|
|
565
|
+
export type TransferAction = {
|
|
566
|
+
$action: 'channel';
|
|
567
|
+
channel: 'transfer';
|
|
568
|
+
/** E.164 number to dial, or a SIP URI (`sip:desk@pbx.example.com`, headers after `?`). */
|
|
569
|
+
to: string;
|
|
570
|
+
/** A SIP `to` that asks for credentials: kept on the server, never on the page the AI reads. */
|
|
571
|
+
sipAuth?: {
|
|
572
|
+
username: string;
|
|
573
|
+
password: string;
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* The caller ID the person sees: the customer's number or ours (default: the voice service's own rule).
|
|
577
|
+
* A call that came in by SIP shows ours to a phone number whatever is asked (the carrier refuses it).
|
|
578
|
+
*/
|
|
579
|
+
callerId?: 'customer' | 'service';
|
|
580
|
+
/**
|
|
581
|
+
* cold: connect and leave; warm: brief the person first with `briefing`, the customer on hold meanwhile;
|
|
582
|
+
* background: warm, but the AI keeps talking with the customer while the person is called, and the
|
|
583
|
+
* customer is put through once the person takes it. Nobody takes it: the conversation simply goes on.
|
|
584
|
+
*/
|
|
585
|
+
mode: 'cold' | 'warm' | 'background';
|
|
586
|
+
briefing?: string;
|
|
587
|
+
/**
|
|
588
|
+
* Background only: what is said as the two are put through. `person`: to the person, once they take
|
|
589
|
+
* the call (`{{briefing}}` is the briefing; without it, the briefing). `customer`: to the customer, in
|
|
590
|
+
* their language (without it, a chime only).
|
|
591
|
+
*/
|
|
592
|
+
bridge?: {
|
|
593
|
+
person?: string;
|
|
594
|
+
customer?: string;
|
|
595
|
+
};
|
|
596
|
+
label?: string;
|
|
597
|
+
description?: string;
|
|
598
|
+
};
|
|
599
|
+
/** Collect keypresses on a call: what was pressed is written to `write` (through `map` when given). */
|
|
600
|
+
export type KeypadAction = {
|
|
601
|
+
$action: 'channel';
|
|
602
|
+
channel: 'keypad';
|
|
603
|
+
/** The run key: `tried(ctx.runs, key)` after the first try. */
|
|
604
|
+
key: string;
|
|
605
|
+
/** Said once, verbatim, before waiting for a key. */
|
|
606
|
+
say: string;
|
|
607
|
+
/** The keys that count. */
|
|
608
|
+
digits: string[];
|
|
609
|
+
timeoutMs: number;
|
|
610
|
+
/** Where the key goes: a slot read from db. */
|
|
611
|
+
write?: SlotRef;
|
|
612
|
+
/** Pressed key → value written (`{ '1': 'english', '2': 'spanish' }`); without it the key itself. */
|
|
613
|
+
map?: Record<string, string | number | boolean>;
|
|
614
|
+
label?: string;
|
|
615
|
+
description?: string;
|
|
616
|
+
};
|
|
617
|
+
/** Say a fixed text, verbatim and not interruptible (a compliance statement). */
|
|
618
|
+
export type AnnounceAction = {
|
|
619
|
+
$action: 'channel';
|
|
620
|
+
channel: 'announce';
|
|
621
|
+
key: string;
|
|
622
|
+
text: string;
|
|
623
|
+
};
|
|
624
|
+
/** End the conversation (a call hangs up once the last line has played; an SMS conversation closes). */
|
|
625
|
+
export type EndAction = {
|
|
626
|
+
$action: 'channel';
|
|
627
|
+
channel: 'end';
|
|
628
|
+
label?: string;
|
|
629
|
+
description?: string;
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Leave a message on the voicemail (25 §13): after its beep, word for word (what a regulated business may
|
|
633
|
+
* leave is fixed), then hang up. The call's outcome is `voicemail`.
|
|
634
|
+
*/
|
|
635
|
+
export type VoicemailAction = {
|
|
636
|
+
$action: 'channel';
|
|
637
|
+
channel: 'voicemail';
|
|
638
|
+
text: string;
|
|
639
|
+
label?: string;
|
|
640
|
+
description?: string;
|
|
641
|
+
};
|
|
642
|
+
export type ChannelAction = TransferAction | KeypadAction | AnnounceAction | EndAction | VoicemailAction;
|
|
643
|
+
export declare function transferTo(options: {
|
|
644
|
+
to: string;
|
|
645
|
+
sipAuth?: TransferAction['sipAuth'];
|
|
646
|
+
callerId?: TransferAction['callerId'];
|
|
647
|
+
mode?: TransferAction['mode'];
|
|
648
|
+
briefing?: string;
|
|
649
|
+
bridge?: TransferAction['bridge'];
|
|
650
|
+
label?: string;
|
|
651
|
+
description?: string;
|
|
652
|
+
}): TransferAction;
|
|
653
|
+
/** Whether a transfer's `to` is a SIP URI rather than a phone number. */
|
|
654
|
+
export declare function isSipUri(to: string): boolean;
|
|
655
|
+
export declare function keypad(key: string, options: {
|
|
656
|
+
say: string;
|
|
657
|
+
digits: string[];
|
|
658
|
+
timeoutMs?: number;
|
|
659
|
+
write?: Slot | SlotRef;
|
|
660
|
+
map?: Record<string, string | number | boolean>;
|
|
661
|
+
label?: string;
|
|
662
|
+
description?: string;
|
|
663
|
+
}): KeypadAction;
|
|
664
|
+
/** A company function as a button (20 §6.2): `runFunction('importOrders', { label, say, parameters })`. */
|
|
665
|
+
export declare function runFunction(name: string, options?: {
|
|
666
|
+
label?: string;
|
|
667
|
+
description?: string;
|
|
668
|
+
say?: string;
|
|
669
|
+
parameters?: ActionParameters;
|
|
670
|
+
prefill?: Record<string, unknown>;
|
|
671
|
+
}): FunctionAction;
|
|
672
|
+
export declare function announce(key: string, text: string): AnnounceAction;
|
|
673
|
+
export declare function voicemail(text: string, options?: {
|
|
674
|
+
label?: string;
|
|
675
|
+
description?: string;
|
|
676
|
+
}): VoicemailAction;
|
|
677
|
+
export declare function end(options?: {
|
|
678
|
+
label?: string;
|
|
679
|
+
description?: string;
|
|
680
|
+
}): EndAction;
|
|
681
|
+
/**
|
|
682
|
+
* An action the page function returns to run now, with its run key (default: the action's name, a
|
|
683
|
+
* channel action's key or kind) and whether the conversation waits for it (`wait: false`: run in the
|
|
684
|
+
* background, the conversation goes on; not for channel actions).
|
|
685
|
+
*/
|
|
686
|
+
export type PerformAction = {
|
|
687
|
+
$perform: true;
|
|
688
|
+
action: PageAction;
|
|
689
|
+
key?: string;
|
|
690
|
+
wait?: boolean;
|
|
691
|
+
};
|
|
692
|
+
export declare function perform(action: PageAction | {
|
|
693
|
+
toJSON(): PageAction;
|
|
694
|
+
}, options?: {
|
|
695
|
+
key?: string;
|
|
696
|
+
wait?: boolean;
|
|
697
|
+
}): PerformAction;
|
|
698
|
+
/** Every channel a page may be written for, in order. */
|
|
699
|
+
export declare const PAGE_CHANNELS: readonly PageChannel[];
|
|
700
|
+
/** A page function: the page for one channel, or an action to run now (17b §9.1, §9.8). */
|
|
701
|
+
export type PageFunction<D> = (ctx: PageContext) => D | Promise<D>;
|
|
702
|
+
/**
|
|
703
|
+
* Who the employee is and how they talk on this conversation's channel (`ctx.channel`), and the FAQ the
|
|
704
|
+
* AI may look things up in (24 §4). Called once, when the conversation starts, with the page's context
|
|
705
|
+
* at that moment; what they return holds for the whole conversation (the head of every prompt).
|
|
706
|
+
*/
|
|
707
|
+
export type PagePersona = (ctx: PageContext) => string | Promise<string>;
|
|
708
|
+
export type PageFaq = (ctx: PageContext) => PageFaqEntry[] | Promise<PageFaqEntry[]>;
|
|
709
|
+
export type PageDefinition<D> = {
|
|
710
|
+
persona: PagePersona;
|
|
711
|
+
faq?: PageFaq;
|
|
712
|
+
call?: (ctx: PageContextOf<'call'>) => D | Promise<D>;
|
|
713
|
+
sms?: (ctx: PageContextOf<'sms'>) => D | Promise<D>;
|
|
714
|
+
email?: (ctx: PageContextOf<'email'>) => D | Promise<D>;
|
|
715
|
+
};
|
|
716
|
+
export type DefinedPage<D> = {
|
|
717
|
+
kind: 'page';
|
|
718
|
+
persona: PagePersona;
|
|
719
|
+
faq: PageFaq | null;
|
|
720
|
+
channels: Partial<Record<PageChannel, PageFunction<D>>>;
|
|
721
|
+
};
|
|
722
|
+
/**
|
|
723
|
+
* `context.page.ts` (17b §9.1, 24 §4): `definePage({ persona: (ctx) => '…', faq: (ctx) => [...], call:
|
|
724
|
+
* async (ctx) => page, sms: … })`. One page function per channel; what they share is the company code's
|
|
725
|
+
* own business.
|
|
726
|
+
*/
|
|
727
|
+
export declare function definePage<D>(definition: PageDefinition<D>): DefinedPage<D>;
|
|
728
|
+
/**
|
|
729
|
+
* What `persona` and `faq` returned, checked (24 §4): a persona's text; at most `MAX_FAQ_ENTRIES` FAQ
|
|
730
|
+
* entries, each with an id of its own, a description and an answer. Throws what is wrong.
|
|
731
|
+
*/
|
|
732
|
+
export declare function checkPageStart(raw: unknown): PageStart;
|
|
733
|
+
/**
|
|
734
|
+
* A cell the AI may write (19-page-writable-cells): a slot placed on a page as is is read-only;
|
|
735
|
+
* `field(slot)` opens it, unless `readOnly: true`. The row id and the parent never open; a lookup
|
|
736
|
+
* chooses among its table's rows on the page.
|
|
737
|
+
*/
|
|
738
|
+
/**
|
|
739
|
+
* A ref field (a lookup) on the page (26 §16.2 #7): the rows the AI may set it to, each with its label
|
|
740
|
+
* (`options: [{ id, label }]`, or `choose(rows, label)`); read-only, `options` only labels the current
|
|
741
|
+
* value. Its definition is always on the page. `field()` refuses a ref field.
|
|
742
|
+
*/
|
|
743
|
+
export declare function refField<S extends Slot>(slot: S, options?: RefFieldOptions): RefFieldCell<S>;
|
|
744
|
+
export declare function field<S extends Slot>(slot: S, options?: FieldOptions): FieldCell<S>;
|
|
745
|
+
/** A parameter taken from the schema: `schemaField('providers.name')`, `schemaField('injuries.id')` (a row). */
|
|
746
|
+
export declare function schemaField(path: string, options?: SchemaFieldOptions): SchemaFieldParam;
|
|
747
|
+
/**
|
|
748
|
+
* An action placed on a page: call it to prefill parameters (`addProvider({ injury: i.id })`), or place
|
|
749
|
+
* it as it is (nothing prefilled). It crosses out of the sandbox as its JSON (`toJSON`).
|
|
750
|
+
*/
|
|
751
|
+
export type Placeable<A extends PageAction, P> = ((prefill?: P) => A) & {
|
|
752
|
+
toJSON(): A;
|
|
753
|
+
};
|
|
754
|
+
/** Add a row (15 §10.6): `fields` are what the AI fills; call it to preset the rest (`({ status: 'active' })`). */
|
|
755
|
+
export declare function createRow(table: TableReader | string, options: {
|
|
756
|
+
fields: readonly string[];
|
|
757
|
+
required?: readonly string[];
|
|
758
|
+
label?: string;
|
|
759
|
+
description?: string;
|
|
760
|
+
}): Placeable<CreateRowAction, Record<string, unknown>>;
|
|
761
|
+
/** Delete a row (cascading, 15 §10.6.1): a built-in action with the row prefilled and nothing to fill. */
|
|
762
|
+
export declare function deleteRow(row: PageRow | string, options?: {
|
|
763
|
+
reason?: string;
|
|
764
|
+
label?: string;
|
|
765
|
+
description?: string;
|
|
766
|
+
}): DeleteRowAction;
|
|
767
|
+
type ActionRun<A> = (args: A, ctx: ActionContext) => unknown;
|
|
768
|
+
export type DefinedAction<A> = Placeable<CustomAction, {
|
|
769
|
+
[K in keyof A]?: A[K] | ChooseParam;
|
|
770
|
+
}> & {
|
|
771
|
+
readonly actionName: string;
|
|
772
|
+
readonly run: ActionRun<A>;
|
|
773
|
+
};
|
|
774
|
+
/**
|
|
775
|
+
* A custom action, declared like an LLM function call: `parameters` are everything `run` takes. Where
|
|
776
|
+
* the page places it, some parameters may be prefilled; the AI fills the rest.
|
|
777
|
+
*/
|
|
778
|
+
export declare function defineAction<A = Record<string, unknown>>(definition: {
|
|
779
|
+
name: string;
|
|
780
|
+
description: string;
|
|
781
|
+
parameters?: ActionParameters;
|
|
782
|
+
run: ActionRun<A>;
|
|
783
|
+
}): DefinedAction<A>;
|
|
784
|
+
export type PageEntryArg = {
|
|
785
|
+
/** `start`: `persona` and `faq` once, when the conversation starts (24 §4), with the same context. */
|
|
786
|
+
mode: 'render' | 'start';
|
|
787
|
+
/** The page function to run; outside a conversation, the first one the page defines. */
|
|
788
|
+
channel: PageChannel | null;
|
|
789
|
+
subject: string;
|
|
790
|
+
caller: PageRow | null;
|
|
791
|
+
session: PageRow | null;
|
|
792
|
+
conversation: PageConversation | null;
|
|
793
|
+
runs: PageRuns;
|
|
794
|
+
scheduledAction: PageScheduledAction | null;
|
|
795
|
+
officeHours: PageContext['officeHours'];
|
|
796
|
+
followUps: PageFollowUp[];
|
|
797
|
+
now: string;
|
|
798
|
+
/** The contact's time zone and today there (25 §11). */
|
|
799
|
+
time?: {
|
|
800
|
+
zone: string;
|
|
801
|
+
today: string;
|
|
802
|
+
};
|
|
803
|
+
/** What the customer sent since the last run (20 §5.2): a text run's texts, an email run's emails. */
|
|
804
|
+
sms?: {
|
|
805
|
+
inbound: PageSmsMessage[];
|
|
806
|
+
};
|
|
807
|
+
email?: {
|
|
808
|
+
inbound: PageEmailMessage[];
|
|
809
|
+
mailbox: string;
|
|
810
|
+
};
|
|
811
|
+
call?: {
|
|
812
|
+
previous: PagePreviousCall | null;
|
|
813
|
+
farEnd?: PageFarEnd | null;
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
/** The channels with a page function: read once, when the sequence is compiled. */
|
|
817
|
+
| {
|
|
818
|
+
mode: 'channels';
|
|
819
|
+
} | {
|
|
820
|
+
mode: 'action';
|
|
821
|
+
name: string;
|
|
822
|
+
/** The prefilled parameters and the AI's, merged. */
|
|
823
|
+
args: Record<string, unknown>;
|
|
824
|
+
subject: string;
|
|
825
|
+
caller: PageRow | null;
|
|
826
|
+
session: PageRow | null;
|
|
827
|
+
now: string;
|
|
828
|
+
};
|
|
829
|
+
/** No runs yet. */
|
|
830
|
+
export declare function emptyRuns(): PageRuns;
|
|
831
|
+
/** What the compiled page script evaluates to: renders the page, or runs one of its actions. */
|
|
832
|
+
export declare function pageEntry(mod: Record<string, unknown>): (arg: PageEntryArg) => unknown;
|
|
833
|
+
export {};
|
|
834
|
+
//# sourceMappingURL=define.d.ts.map
|