@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
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import type { SystemContext } from '../context/types.js';
|
|
2
|
+
import type { Db } from '../page/define.js';
|
|
3
|
+
import type { Id, PageTablesDesc, TypedDb } from '../page/typed.js';
|
|
4
|
+
import type { ContactSchedule } from '../slot/schema.js';
|
|
5
|
+
/** Reserved export of `sequences/<id>/orchestrator.ts` and its name in the build's `functions`. */
|
|
6
|
+
export declare const ORCHESTRATOR_FUNCTION = "orchestrator";
|
|
7
|
+
/** `ctx.meta.entry` / RunScope entry of a Case Orchestrator call. */
|
|
8
|
+
export declare const ORCHESTRATOR_ENTRY = "orchestrator";
|
|
9
|
+
/** `SequenceBuild.orchestrator`: the entry point. */
|
|
10
|
+
export type CaseOrchestratorManifest = {
|
|
11
|
+
fn: string;
|
|
12
|
+
};
|
|
13
|
+
/** Platform tools a Run may open. Names, descriptions, schemas and executors belong to the platform. */
|
|
14
|
+
export declare const CASE_ORCHESTRATOR_TOOL_NAMES: readonly ['readExchange', 'searchExchanges', 'scheduleCall', 'scheduleSms', 'scheduleEmail', 'scheduleUpdateSlots', 'rescheduleAction', 'cancelScheduledAction', 'scheduleNextSequence', 'scheduleWake', 'cancelWake'];
|
|
15
|
+
export type CaseOrchestratorToolName = (typeof CASE_ORCHESTRATOR_TOOL_NAMES)[number];
|
|
16
|
+
/** Channels a contact is reached on. */
|
|
17
|
+
export type ContactChannel = 'call' | 'sms' | 'email';
|
|
18
|
+
/**
|
|
19
|
+
* Kinds of actions that can be scheduled: contacting a contact, slot writes at a later time,
|
|
20
|
+
* handing the instance over to the next sequence (14-sequence-instance §4.3), or waking the
|
|
21
|
+
* Orchestrator up (`wake`, 25 §6.3).
|
|
22
|
+
*/
|
|
23
|
+
export type ScheduledActionKind = ContactChannel | 'update_slots' | 'next_sequence' | 'wake';
|
|
24
|
+
/** Fields every trigger has. `key` is a stable event id: triggers with the same key merge into one. */
|
|
25
|
+
type TriggerBase = {
|
|
26
|
+
key: string;
|
|
27
|
+
occurredAt: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Why a Run started. Handed to `orchestrator` as is, so it is a public contract: grow it only
|
|
31
|
+
* (new `type`s, new optional fields); never rename or remove.
|
|
32
|
+
*/
|
|
33
|
+
export type RunTrigger = TriggerBase & ({
|
|
34
|
+
type: 'call.ended';
|
|
35
|
+
exchangeId: string;
|
|
36
|
+
direction: 'inbound' | 'outbound';
|
|
37
|
+
/** Null when the call never connected. Read it with `ctx.api.db.session.findUnique({ where: { id } })`. */
|
|
38
|
+
sessionId: Id<'session'> | null;
|
|
39
|
+
/** Set when the call was a scheduled action. */
|
|
40
|
+
scheduledActionId: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* `'connected'` when a session opened (corresponds to `result === 'answered'` on `ExchangeEvent`);
|
|
43
|
+
* `'voicemail'` when a message was left on it (65 §3.3).
|
|
44
|
+
*/
|
|
45
|
+
result: 'connected' | 'no-answer' | 'busy' | 'failed' | 'voicemail';
|
|
46
|
+
}
|
|
47
|
+
/** An outbound SMS was handed to the provider, or failed to send. */
|
|
48
|
+
| {
|
|
49
|
+
type: 'sms.sent';
|
|
50
|
+
exchangeId: string;
|
|
51
|
+
scheduledActionId: string | null;
|
|
52
|
+
result: 'sent' | 'failed';
|
|
53
|
+
/** Provider or platform error code when `result === 'failed'`; null otherwise. */
|
|
54
|
+
errorCode: string | null;
|
|
55
|
+
}
|
|
56
|
+
/** An outbound email was handed to the provider, or failed to send. */
|
|
57
|
+
| {
|
|
58
|
+
type: 'email.sent';
|
|
59
|
+
exchangeId: string;
|
|
60
|
+
scheduledActionId: string | null;
|
|
61
|
+
result: 'sent' | 'failed';
|
|
62
|
+
/** Provider or platform error code when `result === 'failed'`; null otherwise. */
|
|
63
|
+
errorCode: string | null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* One SMS run finished: its hooks ran and the reply was stored (21 §6.1). `exchangeId` holds the
|
|
67
|
+
* text line's exchange id (`sms:<our number id>:<their number>`, 21 §12.3).
|
|
68
|
+
*/
|
|
69
|
+
| {
|
|
70
|
+
type: 'sms.turn-ended';
|
|
71
|
+
exchangeId: string;
|
|
72
|
+
runId: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One email run finished: its hooks ran and the reply was stored (21 §6.1). `exchangeId` holds the
|
|
76
|
+
* thread's exchange id (`email:<emailThreadId>`, 21 §12.3).
|
|
77
|
+
*/
|
|
78
|
+
| {
|
|
79
|
+
type: 'email.turn-ended';
|
|
80
|
+
exchangeId: string;
|
|
81
|
+
runId: string;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'contact.communication-preferences.updated';
|
|
84
|
+
contactId: Id<'contact'>;
|
|
85
|
+
/** The `SlotWriteLog` row of the preference field this write changed: what changed, by whom (41 §2). */
|
|
86
|
+
slotWriteLogId: string;
|
|
87
|
+
}
|
|
88
|
+
/** The instance started (a first conversation, a script, a hand-over). */
|
|
89
|
+
| {
|
|
90
|
+
type: 'instance_started';
|
|
91
|
+
}
|
|
92
|
+
/** Requested after an edit in the frontend. */
|
|
93
|
+
| {
|
|
94
|
+
type: 'manual';
|
|
95
|
+
requestedBy: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A scheduled action failed its checks when it came due (the instance closed, the contact left
|
|
99
|
+
* the page, an opt-out, a deadline passed, a write no longer valid, …): nothing was done.
|
|
100
|
+
*/
|
|
101
|
+
| {
|
|
102
|
+
type: 'scheduled_action.failed';
|
|
103
|
+
scheduledActionId: string;
|
|
104
|
+
kind: ScheduledActionKind;
|
|
105
|
+
errorCode: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A scheduled action ended with nothing else to say so (74 §4.7): every action that ends wakes the
|
|
109
|
+
* Orchestrator, to book the next step or close the case. `not_sent`: a text or email whose page decided to
|
|
110
|
+
* send nothing (`reason` says why); `written`: slot writes made.
|
|
111
|
+
*/
|
|
112
|
+
| {
|
|
113
|
+
type: 'scheduled_action.ended';
|
|
114
|
+
scheduledActionId: string;
|
|
115
|
+
kind: ScheduledActionKind;
|
|
116
|
+
outcome: 'not_sent' | 'written';
|
|
117
|
+
/** Why it was not sent (`noReply: …`, `handoff: …`); null for `written`. */
|
|
118
|
+
reason: string | null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Company code told the instance about something outside the platform (a payment posted, a CRM
|
|
122
|
+
* change): `ctx.api.instances.notify` from a webhook, a function or an event handler (25 §6.2).
|
|
123
|
+
* Only a label: the facts are in the records, read them with `ctx.api.db`.
|
|
124
|
+
*/
|
|
125
|
+
| {
|
|
126
|
+
type: 'external';
|
|
127
|
+
reason: string;
|
|
128
|
+
}
|
|
129
|
+
/** A wake-up the Orchestrator booked with `scheduleWake` came due (25 §6.3). */
|
|
130
|
+
| {
|
|
131
|
+
type: 'timer';
|
|
132
|
+
name: string;
|
|
133
|
+
note: string | null;
|
|
134
|
+
scheduledActionId: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A call, texts or an email came in while the case was fully paused (29 §4.1): the AI did not take
|
|
138
|
+
* it; a call went to the fallback number, a message was kept unanswered. Told once the pause is lifted.
|
|
139
|
+
*/
|
|
140
|
+
| {
|
|
141
|
+
type: 'inbound.paused';
|
|
142
|
+
channel: ContactChannel;
|
|
143
|
+
exchangeId: string;
|
|
144
|
+
});
|
|
145
|
+
export type RunTriggerType = RunTrigger['type'];
|
|
146
|
+
/** A stored action's timing: `at`, the exact time (ISO 8601) it runs (25 §4). */
|
|
147
|
+
export type ScheduledActionTiming = {
|
|
148
|
+
mode: 'at';
|
|
149
|
+
at: string;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* What a contact (call / SMS / email) was asked for: its stored `input`. `timing` says when: it is
|
|
153
|
+
* what two requests are compared on and what a reschedule replaces; the other keys ride along. Why
|
|
154
|
+
* it happens is the action's `reason` (40 §2.6).
|
|
155
|
+
*/
|
|
156
|
+
export type ContactActionInput = {
|
|
157
|
+
timing: ScheduledActionTiming;
|
|
158
|
+
/** The contact's address to use: its `phone` (a call, a text) or `email`, the default. */
|
|
159
|
+
to?: string;
|
|
160
|
+
/** Our number to use; default the contact's assigned number, else the sequence's outbound numbers. */
|
|
161
|
+
from?: string;
|
|
162
|
+
/**
|
|
163
|
+
* An agreed follow-up (the party asked for it or agreed to it): where, in which message (its
|
|
164
|
+
* time, ISO 8601) and in which words they said it. Absent for a regular follow-up.
|
|
165
|
+
* docs/design/09-agreed-follow-up.md
|
|
166
|
+
*/
|
|
167
|
+
agreement?: {
|
|
168
|
+
exchangeId: string;
|
|
169
|
+
agreedAt: string;
|
|
170
|
+
customerQuote: string;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
/** What scheduled slot writes (`update_slots`) were asked for: when, and what is written (why: the action's `reason`). */
|
|
174
|
+
export type UpdateSlotsActionInput = {
|
|
175
|
+
timing: {
|
|
176
|
+
mode: 'at';
|
|
177
|
+
at: string;
|
|
178
|
+
};
|
|
179
|
+
writes: SlotWriteInput[];
|
|
180
|
+
};
|
|
181
|
+
/** What a hand-over (`next_sequence`) was asked for: when, to which sequence, on which row, its variables (why: the action's `reason`). */
|
|
182
|
+
export type NextSequenceActionInput = {
|
|
183
|
+
timing: {
|
|
184
|
+
mode: 'at';
|
|
185
|
+
at: string;
|
|
186
|
+
};
|
|
187
|
+
/** Name of the sequence the next instance runs. */
|
|
188
|
+
sequence: string;
|
|
189
|
+
/** The row the next instance starts on, when one was named; else this instance's own. */
|
|
190
|
+
subjectRecordId?: string;
|
|
191
|
+
variables?: Record<string, unknown>;
|
|
192
|
+
};
|
|
193
|
+
/** When a wake-up fires. Its business name and explanation are the action's `name` and `reason` columns (51). */
|
|
194
|
+
export type WakeActionInput = {
|
|
195
|
+
timing: {
|
|
196
|
+
mode: 'at';
|
|
197
|
+
at: string;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
/** Each kind's stored `input`. */
|
|
201
|
+
export type ScheduledActionInputs = {
|
|
202
|
+
call: ContactActionInput;
|
|
203
|
+
sms: ContactActionInput;
|
|
204
|
+
email: ContactActionInput;
|
|
205
|
+
update_slots: UpdateSlotsActionInput;
|
|
206
|
+
next_sequence: NextSequenceActionInput;
|
|
207
|
+
wake: WakeActionInput;
|
|
208
|
+
};
|
|
209
|
+
export type ScheduledActionInput = ScheduledActionInputs[ScheduledActionKind];
|
|
210
|
+
/** A pending contact: who and its `input`. */
|
|
211
|
+
export type ContactActionView = {
|
|
212
|
+
id: string;
|
|
213
|
+
name?: string | null;
|
|
214
|
+
status?: 'scheduled' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
215
|
+
kind: ContactChannel;
|
|
216
|
+
/** The contact to reach. */
|
|
217
|
+
contactId: string;
|
|
218
|
+
/**
|
|
219
|
+
* When it runs (ISO 8601): `input.timing.at`, as given (25 §4).
|
|
220
|
+
*/
|
|
221
|
+
scheduledFor: string;
|
|
222
|
+
input: ContactActionInput;
|
|
223
|
+
/** Why it was booked (40 §2.6); null when nobody said. */
|
|
224
|
+
reason: string | null;
|
|
225
|
+
};
|
|
226
|
+
/** Pending scheduled slot writes: instance-level, no contact. */
|
|
227
|
+
export type UpdateSlotsActionView = {
|
|
228
|
+
id: string;
|
|
229
|
+
name?: string | null;
|
|
230
|
+
status?: 'scheduled' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
231
|
+
kind: 'update_slots';
|
|
232
|
+
contactId: null;
|
|
233
|
+
/** Execution time (`input.timing.at`, ISO 8601). */
|
|
234
|
+
scheduledFor: string;
|
|
235
|
+
input: UpdateSlotsActionInput;
|
|
236
|
+
/** Why it was booked (40 §2.6); null when nobody said. */
|
|
237
|
+
reason: string | null;
|
|
238
|
+
};
|
|
239
|
+
/** A pending hand-over to the next sequence: instance-level, no contact. */
|
|
240
|
+
export type NextSequenceActionView = {
|
|
241
|
+
id: string;
|
|
242
|
+
name?: string | null;
|
|
243
|
+
status?: 'scheduled' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
244
|
+
kind: 'next_sequence';
|
|
245
|
+
contactId: null;
|
|
246
|
+
/** Execution time (`input.timing.at`, ISO 8601). */
|
|
247
|
+
scheduledFor: string;
|
|
248
|
+
input: NextSequenceActionInput;
|
|
249
|
+
/** Why it was booked (40 §2.6); null when nobody said. */
|
|
250
|
+
reason: string | null;
|
|
251
|
+
};
|
|
252
|
+
/** A pending wake-up of the Orchestrator: instance-level, no contact. */
|
|
253
|
+
export type WakeActionView = {
|
|
254
|
+
id: string;
|
|
255
|
+
name?: string | null;
|
|
256
|
+
status?: 'scheduled' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
257
|
+
kind: 'wake';
|
|
258
|
+
contactId: null;
|
|
259
|
+
/** When it wakes the Orchestrator (`input.timing.at`, ISO 8601). */
|
|
260
|
+
scheduledFor: string;
|
|
261
|
+
input: WakeActionInput;
|
|
262
|
+
/** Why it was booked (40 §2.6); null when nobody said. */
|
|
263
|
+
reason: string | null;
|
|
264
|
+
};
|
|
265
|
+
/** A scheduled action still active when the Run input is built; `kind` tells which `input` it has. */
|
|
266
|
+
export type ScheduledActionView = ContactActionView | UpdateSlotsActionView | NextSequenceActionView | WakeActionView;
|
|
267
|
+
/** An agreed follow-up (`input.agreement` set) that already ran, failed or was cancelled. */
|
|
268
|
+
export type FinishedAgreedActionView = ContactActionView & {
|
|
269
|
+
status: 'completed' | 'failed' | 'cancelled';
|
|
270
|
+
finishedAt: string;
|
|
271
|
+
};
|
|
272
|
+
/** One real contact (a call, or a sent / received SMS or email). */
|
|
273
|
+
export type ExchangeEvent = {
|
|
274
|
+
exchangeId: string;
|
|
275
|
+
channel: 'call' | 'sms' | 'email';
|
|
276
|
+
direction: 'inbound' | 'outbound';
|
|
277
|
+
occurredAt: string;
|
|
278
|
+
/** Day of the interaction, counting the first interaction's day as 1. */
|
|
279
|
+
dayNumber: number;
|
|
280
|
+
/**
|
|
281
|
+
* Outcome of the contact:
|
|
282
|
+
* - `call`: `'answered'` | `'no-answer'` (includes busy) | `'failed'`
|
|
283
|
+
* - outbound `sms` / `email`: `'sent'` | `'failed'`
|
|
284
|
+
* - inbound `sms` / `email`: `'received'`
|
|
285
|
+
*/
|
|
286
|
+
result: 'answered' | 'no-answer' | 'sent' | 'failed' | 'received';
|
|
287
|
+
/** A call's length in seconds; null for SMS and email, or a call whose length is not known yet. */
|
|
288
|
+
durationSec: number | null;
|
|
289
|
+
/** Set when it was a scheduled action. */
|
|
290
|
+
scheduledActionId: string | null;
|
|
291
|
+
};
|
|
292
|
+
/** Exchange counts, last events by kind, and recent timeline for the Case (`all`) or one party. */
|
|
293
|
+
export type ActivityStats = {
|
|
294
|
+
/** Timestamp of the very first interaction (day 1); null when none happened yet. */
|
|
295
|
+
firstAt: string | null;
|
|
296
|
+
/** Real contacts counted, of which `recent` holds the newest. */
|
|
297
|
+
total: number;
|
|
298
|
+
/** Today's day number; 1 when nothing happened yet. */
|
|
299
|
+
dayNumber: number;
|
|
300
|
+
/** Today's interaction counts: the party's contact timezone, or the primary party's for `all`. */
|
|
301
|
+
today: {
|
|
302
|
+
calls: number;
|
|
303
|
+
answeredCalls: number;
|
|
304
|
+
smsOut: number;
|
|
305
|
+
smsIn: number;
|
|
306
|
+
emailsOut: number;
|
|
307
|
+
emailsIn: number;
|
|
308
|
+
};
|
|
309
|
+
/** Most recent event of each kind (null when none happened yet). */
|
|
310
|
+
last: {
|
|
311
|
+
/** Most recent exchange across all channels and directions. */
|
|
312
|
+
exchange: ExchangeEvent | null;
|
|
313
|
+
/** Most recent inbound exchange (call, SMS, or email from the contact). */
|
|
314
|
+
inbound: ExchangeEvent | null;
|
|
315
|
+
/** Most recent outbound exchange (call, SMS, or email to the contact). */
|
|
316
|
+
outbound: ExchangeEvent | null;
|
|
317
|
+
/** Most recent call (inbound or outbound, answered or not). */
|
|
318
|
+
call: ExchangeEvent | null;
|
|
319
|
+
/** Most recent call that was answered (`result === 'answered'`). */
|
|
320
|
+
answeredCall: ExchangeEvent | null;
|
|
321
|
+
/** Most recent SMS (inbound or outbound). */
|
|
322
|
+
sms: ExchangeEvent | null;
|
|
323
|
+
/** Most recent email (inbound or outbound). */
|
|
324
|
+
email: ExchangeEvent | null;
|
|
325
|
+
};
|
|
326
|
+
/** Most recent events, oldest first (at most {@link ACTIVITY_RECENT_LIMIT}). */
|
|
327
|
+
recent: readonly ExchangeEvent[];
|
|
328
|
+
};
|
|
329
|
+
export declare const ACTIVITY_RECENT_LIMIT = 50;
|
|
330
|
+
/** How far back `recentAgreedActions` reaches. */
|
|
331
|
+
export declare const RECENT_AGREED_ACTIONS_DAYS = 14;
|
|
332
|
+
/**
|
|
333
|
+
* Why a channel cannot be used: no phone / email on file, the contact opted out of it, or the address
|
|
334
|
+
* cannot take it (a number Twilio said is a landline or out of service, 21 §5.10).
|
|
335
|
+
*/
|
|
336
|
+
export type ChannelUnavailableReason = 'no_address' | 'opted_out' | 'unreachable';
|
|
337
|
+
export type ChannelAvailability = {
|
|
338
|
+
/** The address exists and the channel is not opted out (globally or alone). */
|
|
339
|
+
channels: Record<ContactChannel, boolean>;
|
|
340
|
+
/** Why each unavailable channel is unavailable. */
|
|
341
|
+
unavailableChannels: Partial<Record<ContactChannel, ChannelUnavailableReason>>;
|
|
342
|
+
};
|
|
343
|
+
/** One party's activity, counted from its own first contact, in its own timezone. */
|
|
344
|
+
export type PartyActivity = ActivityStats & ChannelAvailability & {
|
|
345
|
+
contactId: string;
|
|
346
|
+
timezone: string;
|
|
347
|
+
/** Local time of the party, ISO 8601 with offset. */
|
|
348
|
+
localNow: string;
|
|
349
|
+
localWeekday: string;
|
|
350
|
+
contactHours: PartyContactHours;
|
|
351
|
+
};
|
|
352
|
+
type ContactHoursWeekday = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
|
|
353
|
+
/**
|
|
354
|
+
* When a party may be contacted, in their timezone: their `contact_schedule` within the platform
|
|
355
|
+
* window, or default working hours when they have none. The platform places regular follow-ups (and
|
|
356
|
+
* agreed ones without an exact time) inside these hours.
|
|
357
|
+
*/
|
|
358
|
+
export type PartyContactHours = {
|
|
359
|
+
/**
|
|
360
|
+
* `contact_schedule`: the party's own schedule; `none`: none on file (every day all day). The
|
|
361
|
+
* company's rules for when to reach them are not here (25 §3): they are the company's own.
|
|
362
|
+
*/
|
|
363
|
+
source: 'contact_schedule' | 'none';
|
|
364
|
+
/** Each weekday's windows; an empty list: never on that weekday. */
|
|
365
|
+
weekly: Readonly<Record<ContactHoursWeekday, readonly {
|
|
366
|
+
start: string;
|
|
367
|
+
end: string;
|
|
368
|
+
}[]>>;
|
|
369
|
+
/** Dates from today on whose hours replace the weekly ones, soonest first; an empty list: not that day. */
|
|
370
|
+
dateOverrides: readonly {
|
|
371
|
+
date: string;
|
|
372
|
+
windows: readonly {
|
|
373
|
+
start: string;
|
|
374
|
+
end: string;
|
|
375
|
+
}[];
|
|
376
|
+
}[];
|
|
377
|
+
};
|
|
378
|
+
/** Exchange aggregates of an instance with the contacts its code names (`ctx.api.exchanges.activity`, 38 §2.8). */
|
|
379
|
+
export type CaseActivity = {
|
|
380
|
+
/** Timezone of the instance-level day numbers: the first named contact's. */
|
|
381
|
+
timezone: string;
|
|
382
|
+
all: ActivityStats;
|
|
383
|
+
/** Every named contact, keyed by contactId, in the order named. */
|
|
384
|
+
byContact: Readonly<Record<string, PartyActivity>>;
|
|
385
|
+
};
|
|
386
|
+
export declare const EMPTY_CASE_ACTIVITY: CaseActivity;
|
|
387
|
+
/** Frozen inputs of one orchestration Run. */
|
|
388
|
+
export type CaseOrchestratorParams = {
|
|
389
|
+
/** This Run's triggers, frozen when it started, oldest first. */
|
|
390
|
+
triggers: readonly RunTrigger[];
|
|
391
|
+
/**
|
|
392
|
+
* Scheduled actions still waiting to run when the Run started. Writes through `ctx.api.tools`
|
|
393
|
+
* do not update it.
|
|
394
|
+
*/
|
|
395
|
+
scheduledActions: readonly ScheduledActionView[];
|
|
396
|
+
/** Agreed follow-ups that finished in the last {@link RECENT_AGREED_ACTIONS_DAYS} days, newest first: a promise already kept is not booked again. */
|
|
397
|
+
recentAgreedActions: readonly FinishedAgreedActionView[];
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* The Orchestrator's API: everything a function's `ctx.api` has (25 §7: the platform surfaces, every
|
|
401
|
+
* integration, `log`, the company's records), so a function of the sequence can be called from the
|
|
402
|
+
* Orchestrator with its `ctx` and works the same, plus the awaitable platform `tools`. Like a
|
|
403
|
+
* function's, `call` / `sms` / `email` read the history of the whole company and environment: pass
|
|
404
|
+
* `instanceId: ctx.meta.instanceId` to `list` for this instance's. `db` reads the records the way a page script does
|
|
405
|
+
* (Prisma-shaped, every `where` anchored) and changes them the way a page action does (`create` /
|
|
406
|
+
* `update` / `delete`), any row of the company and environment. Each call is one request: a write is
|
|
407
|
+
* its own transaction, and the same write sent again within the Run is not made twice; a Run run again
|
|
408
|
+
* (after it failed) writes again, so read first, then create.
|
|
409
|
+
* `D` is the sequence's `PageTables` (`__gen` binds it): tables, fields and ids typed.
|
|
410
|
+
*/
|
|
411
|
+
export type CaseOrchestratorApi<D extends PageTablesDesc | undefined = undefined> = Omit<SystemContext['api'], 'db'> & {
|
|
412
|
+
/**
|
|
413
|
+
* The platform's tools: scheduling goes through them, where opt-outs and the
|
|
414
|
+
* instance's state are checked. A text or email sent with an integration directly is not.
|
|
415
|
+
*/
|
|
416
|
+
tools: CaseOrchestratorTools;
|
|
417
|
+
db: D extends PageTablesDesc ? TypedDb<D> : Db;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* `ctx` of `orchestrator`: a function's `ctx` (38 §2.3), so a function can be called with it, plus
|
|
421
|
+
* `api.tools`. `D` types `ctx.api.db`.
|
|
422
|
+
*/
|
|
423
|
+
export type CaseOrchestratorContext<D extends PageTablesDesc | undefined = undefined> = Omit<SystemContext, 'api' | 'meta'> & {
|
|
424
|
+
/** What runs, where (38 §2.3): the instance is `args.instanceId`. */
|
|
425
|
+
meta: Omit<SystemContext['meta'], 'instanceId'>;
|
|
426
|
+
api: CaseOrchestratorApi<D>;
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* When a scheduled action runs (25 §4): `at`, an exact instant (ISO 8601 with an offset or Z; its
|
|
430
|
+
* offset need not be the contact's); pass the current time for now. It runs then: the platform does
|
|
431
|
+
* not check contact hours (25 §3). The company's rules decide `at`: `nextContactTime` for the first
|
|
432
|
+
* allowed time, `randomTimeBetween` to spread contacts.
|
|
433
|
+
*/
|
|
434
|
+
export type ScheduleTiming = {
|
|
435
|
+
at: string;
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* What makes a contact an agreed follow-up: the party asked for it or agreed to it in
|
|
439
|
+
* `agreedInExchangeId`, in their message at `agreedAt`, in the words `customerQuote` (all three
|
|
440
|
+
* together; the platform does not check them, and they serve only as evidence, not deduplication). Like any
|
|
441
|
+
* action it runs at its `at`; an opt-out still stops it.
|
|
442
|
+
* docs/design/09-agreed-follow-up.md
|
|
443
|
+
*/
|
|
444
|
+
export type AgreementFields = {
|
|
445
|
+
agreedInExchangeId?: string;
|
|
446
|
+
/** The time of the party's message, as the conversation shows it, ISO 8601 with an offset or Z. */
|
|
447
|
+
agreedAt?: string;
|
|
448
|
+
customerQuote?: string;
|
|
449
|
+
/** Why this contact happens; the conversation it opens gets it. Any action may have one. */
|
|
450
|
+
note?: string;
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Whom to contact and, optionally, the addresses: `to` one of the
|
|
454
|
+
* contact's phone / email fields' values (default: its `phone` / `email`), `from` one of our numbers
|
|
455
|
+
* (default: the contact's assigned number, else this sequence's outbound numbers, 14 §10).
|
|
456
|
+
*/
|
|
457
|
+
export type ScheduleActionInput = {
|
|
458
|
+
contactId: string;
|
|
459
|
+
to?: string;
|
|
460
|
+
from?: string;
|
|
461
|
+
name?: string;
|
|
462
|
+
} & ScheduleTiming & AgreementFields;
|
|
463
|
+
/** One field on an existing row, as `scheduleUpdateSlots` takes it. */
|
|
464
|
+
export type SlotFieldWriteInput = {
|
|
465
|
+
/** `table.field`. */
|
|
466
|
+
path: string;
|
|
467
|
+
value?: string | number | boolean | string[] | null;
|
|
468
|
+
state?: 'filled' | 'empty' | 'asked_unknown' | 'declined';
|
|
469
|
+
reason?: string;
|
|
470
|
+
/** A multi-row table (`contact` included): the existing row's id. */
|
|
471
|
+
rowId?: string;
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* A new row of a multi-row table other than contact. Any field, conversation ones included; its
|
|
475
|
+
* parent when the parent is not the business root (which the platform fills).
|
|
476
|
+
*/
|
|
477
|
+
export type SlotInsertInput = {
|
|
478
|
+
insert: string;
|
|
479
|
+
values: Record<string, string | number | boolean | string[] | null | ContactSchedule>;
|
|
480
|
+
};
|
|
481
|
+
/** One slot write, as `scheduleUpdateSlots` takes it. */
|
|
482
|
+
export type SlotWriteInput = SlotFieldWriteInput | SlotInsertInput;
|
|
483
|
+
/**
|
|
484
|
+
* Slot writes to make at a set time, and why. Validated now, written as given when due (checked
|
|
485
|
+
* again then); nothing is re-decided, so cancel or reschedule it when it no longer fits. Not a
|
|
486
|
+
* contact: no window or opt-out applies.
|
|
487
|
+
*/
|
|
488
|
+
export type ScheduleUpdateSlotsInput = {
|
|
489
|
+
at: string;
|
|
490
|
+
writes: SlotWriteInput[];
|
|
491
|
+
reason: string;
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Hand the instance over to the next sequence at `at` (now when left out): when due, this instance
|
|
495
|
+
* closes (`superseded`) and an instance of `sequence` starts, in one transaction. It starts on
|
|
496
|
+
* `subjectRecordId`, a row of the table `sequence` declares as `subject`; left out, on this
|
|
497
|
+
* instance's own row, which then must be of that table (`subject_required`). A row with an active
|
|
498
|
+
* instance is refused (`subject_busy`).
|
|
499
|
+
*/
|
|
500
|
+
export type ScheduleNextSequenceInput = {
|
|
501
|
+
sequence: string;
|
|
502
|
+
subjectRecordId?: string;
|
|
503
|
+
at?: string;
|
|
504
|
+
variables?: Record<string, unknown>;
|
|
505
|
+
reason: string;
|
|
506
|
+
};
|
|
507
|
+
/** One utterance of a call, or one SMS / email, inside an exchange. */
|
|
508
|
+
export type ExchangeEntry = {
|
|
509
|
+
at: string;
|
|
510
|
+
/** `party`: the person on the other side; `ai`: what the platform said or sent. */
|
|
511
|
+
speaker: 'party' | 'ai';
|
|
512
|
+
text: string;
|
|
513
|
+
/** Set when `text` was cut to fit the result. */
|
|
514
|
+
truncated?: true;
|
|
515
|
+
};
|
|
516
|
+
/** One exchange's content, a window of its entries at a time, newest window first. */
|
|
517
|
+
export type ReadExchangeResult = {
|
|
518
|
+
exchangeId: string;
|
|
519
|
+
contactId: string | null;
|
|
520
|
+
direction: 'inbound' | 'outbound';
|
|
521
|
+
occurredAt: string;
|
|
522
|
+
totalEntries: number;
|
|
523
|
+
/** These are entries [from, to) of all of them; `from > 0`: pass `before: from` for earlier ones. */
|
|
524
|
+
range: {
|
|
525
|
+
from: number;
|
|
526
|
+
to: number;
|
|
527
|
+
};
|
|
528
|
+
entries: ExchangeEntry[];
|
|
529
|
+
} & ({
|
|
530
|
+
channel: 'call';
|
|
531
|
+
/** Null while the call has not happened yet (still dialing or ringing). */
|
|
532
|
+
result: ExchangeEvent['result'] | null;
|
|
533
|
+
durationSec: number | null;
|
|
534
|
+
} | {
|
|
535
|
+
channel: 'sms';
|
|
536
|
+
} | {
|
|
537
|
+
channel: 'email';
|
|
538
|
+
subject: string | null;
|
|
539
|
+
});
|
|
540
|
+
/** A {@link ExchangeEvent} as `searchExchanges` returns it. */
|
|
541
|
+
export type ExchangeSearchHit = Omit<ExchangeEvent, 'dayNumber' | 'durationSec'> & {
|
|
542
|
+
contactId: string | null;
|
|
543
|
+
/** The case it was on (with scope `contact`, possibly not this one); null when none. */
|
|
544
|
+
instanceId: string | null;
|
|
545
|
+
/** Calls only. */
|
|
546
|
+
durationSec?: number | null;
|
|
547
|
+
/** Emails only. */
|
|
548
|
+
subject?: string | null;
|
|
549
|
+
/** SMS / email: the start of the message body. */
|
|
550
|
+
preview?: string | null;
|
|
551
|
+
};
|
|
552
|
+
export type SearchExchangesResult = {
|
|
553
|
+
/** Every event matching the filters, not only this page. */
|
|
554
|
+
total: number;
|
|
555
|
+
/** Newest first. */
|
|
556
|
+
events: ExchangeSearchHit[];
|
|
557
|
+
/** Pass as `before` for the next (older) page; null on the last page. */
|
|
558
|
+
nextBefore: string | null;
|
|
559
|
+
};
|
|
560
|
+
/** Each tool's arguments: the same parameters the model sends. The tool validates them when it runs. */
|
|
561
|
+
export type ToolCallArgs = {
|
|
562
|
+
/** `before`: exclusive upper entry index for paging back (pass `range.from` from the previous read). */
|
|
563
|
+
readExchange: {
|
|
564
|
+
exchangeId: string;
|
|
565
|
+
before?: number;
|
|
566
|
+
};
|
|
567
|
+
searchExchanges: {
|
|
568
|
+
/** `occurredAt >= from`, ISO 8601 with an offset or Z. */
|
|
569
|
+
from?: string;
|
|
570
|
+
/** `occurredAt < to`, ISO 8601 with an offset or Z. */
|
|
571
|
+
to?: string;
|
|
572
|
+
contactId?: string;
|
|
573
|
+
channel?: ExchangeEvent['channel'];
|
|
574
|
+
direction?: ExchangeEvent['direction'];
|
|
575
|
+
result?: ExchangeEvent['result'][];
|
|
576
|
+
scheduledActionId?: string;
|
|
577
|
+
/** That case's exchanges. Company code names at least one of `instanceId`, `contactId`, `scheduledActionId`. */
|
|
578
|
+
instanceId?: string;
|
|
579
|
+
limit?: number;
|
|
580
|
+
/** Pagination cursor from a previous result's `nextBefore`. */
|
|
581
|
+
before?: string;
|
|
582
|
+
};
|
|
583
|
+
scheduleCall: ScheduleActionInput;
|
|
584
|
+
scheduleSms: ScheduleActionInput;
|
|
585
|
+
scheduleEmail: ScheduleActionInput;
|
|
586
|
+
scheduleUpdateSlots: ScheduleUpdateSlotsInput;
|
|
587
|
+
rescheduleAction: {
|
|
588
|
+
scheduledActionId: string;
|
|
589
|
+
} & ScheduleTiming & {
|
|
590
|
+
/** Required to move an agreed follow-up. */
|
|
591
|
+
reason?: string;
|
|
592
|
+
/** The party changed an agreed follow-up: where, in which message and in which words (all three). */
|
|
593
|
+
agreedInExchangeId?: string;
|
|
594
|
+
agreedAt?: string;
|
|
595
|
+
customerQuote?: string;
|
|
596
|
+
};
|
|
597
|
+
cancelScheduledAction: {
|
|
598
|
+
scheduledActionId: string;
|
|
599
|
+
reason: string;
|
|
600
|
+
};
|
|
601
|
+
scheduleNextSequence: ScheduleNextSequenceInput;
|
|
602
|
+
scheduleWake: ScheduleWakeInput;
|
|
603
|
+
/** Cancel the pending wake-up of this name, if there is one. */
|
|
604
|
+
cancelWake: {
|
|
605
|
+
name: string;
|
|
606
|
+
reason?: string;
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
/**
|
|
610
|
+
* `scheduleWake`: wake this instance's Orchestrator at `at` with a `timer` trigger (25 §6.3). It
|
|
611
|
+
* contacts no one, so it runs exactly then, at any hour. One pending per `name`: booking the same
|
|
612
|
+
* name again moves it. Cancelled with the instance.
|
|
613
|
+
*/
|
|
614
|
+
export type ScheduleWakeInput = {
|
|
615
|
+
/** Its name in this instance (e.g. `payment-check`); the trigger carries it. */
|
|
616
|
+
name: string;
|
|
617
|
+
/** ISO 8601 with an offset or Z; at most 90 days ahead. */
|
|
618
|
+
at: string;
|
|
619
|
+
/** Why, for the Run it starts. */
|
|
620
|
+
note?: string;
|
|
621
|
+
};
|
|
622
|
+
export type WakeResult = {
|
|
623
|
+
/** `rescheduled`: a wake-up of this name was pending and moved; `existing`: it already had this time and note. */
|
|
624
|
+
outcome: 'created' | 'rescheduled' | 'existing';
|
|
625
|
+
scheduledActionId: string;
|
|
626
|
+
scheduledFor: string;
|
|
627
|
+
};
|
|
628
|
+
export type ScheduledResult = {
|
|
629
|
+
/**
|
|
630
|
+
* `existing`: this contact and channel already have an active action with the same timing, or
|
|
631
|
+
* these agreed words were already booked.
|
|
632
|
+
*/
|
|
633
|
+
outcome: 'created' | 'existing';
|
|
634
|
+
scheduledActionId: string;
|
|
635
|
+
scheduledFor: string;
|
|
636
|
+
/** An agreed follow-up replaced this pending regular follow-up on the same channel (it is cancelled). */
|
|
637
|
+
supersededScheduledActionId?: string;
|
|
638
|
+
};
|
|
639
|
+
export type RescheduledResult = {
|
|
640
|
+
/** `unchanged`: the action already had this timing. */
|
|
641
|
+
outcome: 'rescheduled' | 'unchanged';
|
|
642
|
+
scheduledActionId: string;
|
|
643
|
+
scheduledFor: string;
|
|
644
|
+
/** The `scheduledFor` timestamp before rescheduling (equals `scheduledFor` when `unchanged`). */
|
|
645
|
+
previousScheduledFor: string;
|
|
646
|
+
};
|
|
647
|
+
export type ToolCallResult = {
|
|
648
|
+
readExchange: ReadExchangeResult;
|
|
649
|
+
searchExchanges: SearchExchangesResult;
|
|
650
|
+
scheduleCall: ScheduledResult;
|
|
651
|
+
scheduleSms: ScheduledResult;
|
|
652
|
+
scheduleEmail: ScheduledResult;
|
|
653
|
+
scheduleUpdateSlots: ScheduledResult;
|
|
654
|
+
rescheduleAction: RescheduledResult;
|
|
655
|
+
/** `too_late`: it already started; otherwise the action's final status. */
|
|
656
|
+
cancelScheduledAction: {
|
|
657
|
+
outcome: 'cancelled' | 'too_late' | 'completed' | 'failed';
|
|
658
|
+
scheduledActionId: string;
|
|
659
|
+
};
|
|
660
|
+
scheduleNextSequence: ScheduledResult;
|
|
661
|
+
scheduleWake: WakeResult;
|
|
662
|
+
/** `not_pending`: no wake-up of that name was waiting (it never was, already ran, or was cancelled). */
|
|
663
|
+
cancelWake: {
|
|
664
|
+
outcome: 'cancelled' | 'not_pending';
|
|
665
|
+
scheduledActionId: string | null;
|
|
666
|
+
};
|
|
667
|
+
};
|
|
668
|
+
export type ToolResult<T> = {
|
|
669
|
+
ok: true;
|
|
670
|
+
value: T;
|
|
671
|
+
toolCallId?: string;
|
|
672
|
+
} | {
|
|
673
|
+
ok: false;
|
|
674
|
+
error: {
|
|
675
|
+
code: string;
|
|
676
|
+
message: string;
|
|
677
|
+
};
|
|
678
|
+
toolCallId?: string;
|
|
679
|
+
};
|
|
680
|
+
/** The tools that only read: they work on no instance (38 §2.7). */
|
|
681
|
+
export type ReadToolName = 'readExchange' | 'searchExchanges';
|
|
682
|
+
/**
|
|
683
|
+
* `ctx.api.tools` (38 §2.7): a platform API of every function and entry, the same for every caller,
|
|
684
|
+
* held to the caller's company and environment. A command names the instance it works on and acts
|
|
685
|
+
* each time it is called (its record is `toolCallId`); a read names what it reads.
|
|
686
|
+
*/
|
|
687
|
+
export type CaseOrchestratorTools = {
|
|
688
|
+
[N in CaseOrchestratorToolName]: (input: N extends ReadToolName ? ToolCallArgs[N] : ToolCallArgs[N] & {
|
|
689
|
+
instanceId: string;
|
|
690
|
+
}) => Promise<ToolResult<ToolCallResult[N]>>;
|
|
691
|
+
};
|
|
692
|
+
/**
|
|
693
|
+
* What `orchestrator` is called with (38 §2.2): the instance and its business root's id, the anchor of
|
|
694
|
+
* its reads (`ctx.api.db.<root table>.findUnique({ where: { id: args.subject } })`), and the Run's
|
|
695
|
+
* frozen inputs. What changes (run variables, the instance's status) is read with
|
|
696
|
+
* `ctx.api.instances.get`.
|
|
697
|
+
*/
|
|
698
|
+
export type CaseOrchestratorArgs<S extends string = string> = {
|
|
699
|
+
subject: Id<S>;
|
|
700
|
+
instanceId: string;
|
|
701
|
+
} & CaseOrchestratorParams;
|
|
702
|
+
/**
|
|
703
|
+
* `orchestrator.ts`: `export const orchestrator: CaseOrchestrator = async (ctx, args) => …`.
|
|
704
|
+
* `D` is the company's `PageTables`, `S` the sequence's subject table (`__gen` binds both).
|
|
705
|
+
*/
|
|
706
|
+
export type CaseOrchestrator<D extends PageTablesDesc | undefined = undefined, S extends string = string> = (ctx: CaseOrchestratorContext<D>, args: CaseOrchestratorArgs<S>) => Promise<void>;
|
|
707
|
+
export {};
|
|
708
|
+
//# sourceMappingURL=types.d.ts.map
|