@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,247 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CaseInput } from '../case-orchestrator/types.js';
|
|
3
|
+
import type { PageTablesDesc } from '../page/typed.js';
|
|
4
|
+
import type { FunctionCtx, FunctionKind } from './types.js';
|
|
5
|
+
import type { ExchangeRef } from '../context/exchanges.js';
|
|
6
|
+
/**
|
|
7
|
+
* Platform events.
|
|
8
|
+
*
|
|
9
|
+
* The event name is the key of the company `events` export. For every event the
|
|
10
|
+
* platform fixes the payload, the return type (`void` for every event except
|
|
11
|
+
* `webhook.received`, which returns a {@link WebhookOutcome}) and whether the
|
|
12
|
+
* handler receives `c` — companies only choose which events to subscribe to.
|
|
13
|
+
*
|
|
14
|
+
* A handler is the company's own code, not the conversation: it does not get the page. `c` is the
|
|
15
|
+
* case ({@link CaseInput}: the instance and its business root's id, as the Orchestrator gets it); it
|
|
16
|
+
* reads and writes with `ctx.api.db`. Only `webhook.received` has no `c`: it runs before a case is known.
|
|
17
|
+
*
|
|
18
|
+
* Payloads are provider-neutral on purpose: Twilio / Gmail vocabulary is
|
|
19
|
+
* translated in the channel adapter, never carried into these types.
|
|
20
|
+
*/
|
|
21
|
+
/** Shared by every call event. `id` can be passed directly to `ctx.api.call.get`. */
|
|
22
|
+
export type CallEventBase = {
|
|
23
|
+
id: string;
|
|
24
|
+
/** Provider-neutral name for the channel-native id (voice: Twilio CallSid). */
|
|
25
|
+
externalId: string;
|
|
26
|
+
fromNumber: string;
|
|
27
|
+
toNumber: string;
|
|
28
|
+
};
|
|
29
|
+
export type CallInboundEvent = CallEventBase & {
|
|
30
|
+
startedAt: string;
|
|
31
|
+
};
|
|
32
|
+
export type CallOutboundEvent = CallEventBase & {
|
|
33
|
+
startedAt: string;
|
|
34
|
+
};
|
|
35
|
+
export type CallEndedEvent = CallEventBase & {
|
|
36
|
+
/** Provider-neutral terminal outcome. */
|
|
37
|
+
outcome: 'completed' | 'busy' | 'failed' | 'no-answer' | 'canceled';
|
|
38
|
+
durationSec: number | null;
|
|
39
|
+
};
|
|
40
|
+
/** Shared by every SMS event. `id` can be passed directly to `ctx.api.sms.get`. */
|
|
41
|
+
export type SmsEventBase = {
|
|
42
|
+
id: string;
|
|
43
|
+
fromNumber: string;
|
|
44
|
+
toNumber: string;
|
|
45
|
+
body: string;
|
|
46
|
+
};
|
|
47
|
+
export type SmsReceivedEvent = SmsEventBase & {
|
|
48
|
+
receivedAt: string;
|
|
49
|
+
};
|
|
50
|
+
export type SmsSendRequestedEvent = SmsEventBase & {
|
|
51
|
+
requestedAt: string;
|
|
52
|
+
};
|
|
53
|
+
/** Shared by every email event. `id` can be passed directly to `ctx.api.email.get`. */
|
|
54
|
+
export type EmailEventBase = {
|
|
55
|
+
id: string;
|
|
56
|
+
/** The provider's thread id (null for a thread we start, until its first email went). */
|
|
57
|
+
threadId: string | null;
|
|
58
|
+
fromAddress: string;
|
|
59
|
+
toAddresses: string[];
|
|
60
|
+
subject: string | null;
|
|
61
|
+
body: string | null;
|
|
62
|
+
};
|
|
63
|
+
export type EmailReceivedEvent = EmailEventBase & {
|
|
64
|
+
receivedAt: string;
|
|
65
|
+
};
|
|
66
|
+
export type EmailSendRequestedEvent = EmailEventBase & {
|
|
67
|
+
requestedAt: string;
|
|
68
|
+
};
|
|
69
|
+
/** Events that carry no payload yet: the handler reads what it needs from `c` and `ctx.api.db`. */
|
|
70
|
+
export type EmptyEvent = Record<string, never>;
|
|
71
|
+
/**
|
|
72
|
+
* The HTTP request exactly as the gateway saw it. The platform verifies nothing: every header,
|
|
73
|
+
* the absolute URL and the raw body are forwarded so the handler can check the sender's signature.
|
|
74
|
+
*/
|
|
75
|
+
export type WebhookRequest = {
|
|
76
|
+
method: 'GET' | 'POST' | 'PUT';
|
|
77
|
+
/** Absolute URL as the sender saw it (`https://…/webhook/e/<code>/lead/created?x=1`); signatures are usually computed over it. */
|
|
78
|
+
url: string;
|
|
79
|
+
/** Sub-path after the webhook code: `/webhook/e/<code>/lead/created` → `lead/created`; `''` when absent. */
|
|
80
|
+
path: string;
|
|
81
|
+
query: Record<string, string>;
|
|
82
|
+
/** Every request header, lower-cased names, multi-valued headers joined with `, `. Nothing is removed. */
|
|
83
|
+
headers: Record<string, string>;
|
|
84
|
+
contentType: string | null;
|
|
85
|
+
/** Raw body text, always present (empty string for GET). */
|
|
86
|
+
body: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* One inbound request to one of the environment's webhook URLs (made on the Webhooks page). The
|
|
90
|
+
* platform routes, stores and forwards it; it does not verify it and knows nothing
|
|
91
|
+
* about the sender's event model. The company's `webhook.ts` decides whether the request is genuine
|
|
92
|
+
* and answers with a {@link WebhookOutcome} (22-sequence-as-business-unit §9).
|
|
93
|
+
*/
|
|
94
|
+
export type WebhookEvent = {
|
|
95
|
+
/** Delivery id. Stable across retries: use it as an idempotency key and to find the row in Trigger history. */
|
|
96
|
+
id: string;
|
|
97
|
+
receivedAt: string;
|
|
98
|
+
/** 1 on the first run, higher on worker retries. */
|
|
99
|
+
attempt: number;
|
|
100
|
+
/**
|
|
101
|
+
* Which webhook URL received it: `name` is the URL's name on the Webhooks page (the same in test and
|
|
102
|
+
* prod).
|
|
103
|
+
*/
|
|
104
|
+
webhook: {
|
|
105
|
+
id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Body parsed by Content-Type: JSON → the parsed value (object, array or scalar);
|
|
110
|
+
* form-urlencoded → flat object; anything else → null. `request.body` always has the raw text.
|
|
111
|
+
*/
|
|
112
|
+
payload: unknown;
|
|
113
|
+
request: WebhookRequest;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* What `webhook.received` must return. Explicit on purpose: a plain `return` is a type error.
|
|
117
|
+
* - `accepted`: the request was genuine and handled; the delivery is marked succeeded.
|
|
118
|
+
* - `rejected`: the handler's own verification failed (bad signature, unknown sender, …); the
|
|
119
|
+
* delivery is marked rejected with `reason` and is never retried.
|
|
120
|
+
* Throwing means "something went wrong on our side": the delivery is marked failed and retried.
|
|
121
|
+
*/
|
|
122
|
+
export type WebhookOutcome = {
|
|
123
|
+
status: 'accepted';
|
|
124
|
+
} | {
|
|
125
|
+
status: 'rejected';
|
|
126
|
+
reason: string;
|
|
127
|
+
};
|
|
128
|
+
/** Wire schema of {@link WebhookOutcome}; the worker validates the handler's return with it. */
|
|
129
|
+
export declare const webhookOutcome: z.ZodType<WebhookOutcome>;
|
|
130
|
+
/**
|
|
131
|
+
* A text or email conversation needs a person (20 §5.7, 24 §5.3): the AI marked it stuck, or its run
|
|
132
|
+
* failed; nothing was sent for what the customer wrote. The company decides who is told and how (a
|
|
133
|
+
* task, a message to the team, a field on the case).
|
|
134
|
+
*/
|
|
135
|
+
export type ConversationHandoffEvent = {
|
|
136
|
+
/** A call only when its model failed and the call was ended (25 §12); a stuck call reads `session.stuck`. */
|
|
137
|
+
channel: 'call' | 'sms' | 'email';
|
|
138
|
+
/** The exchange waiting for a person: the call, the text line, the email thread (21 §11.4). */
|
|
139
|
+
exchange: ExchangeRef;
|
|
140
|
+
/** The run that stopped. */
|
|
141
|
+
runId: string;
|
|
142
|
+
contactId: string;
|
|
143
|
+
/** Why: the AI marked the conversation stuck, or the run failed. */
|
|
144
|
+
cause: 'stuck' | 'error';
|
|
145
|
+
/** What went wrong, when the run failed. */
|
|
146
|
+
error?: string;
|
|
147
|
+
/** What the customer sent that is waiting for an answer. */
|
|
148
|
+
waiting: string;
|
|
149
|
+
at: string;
|
|
150
|
+
};
|
|
151
|
+
/** Event name → { whether the handler gets `c`, payload, handler return }. */
|
|
152
|
+
export type SystemEventMap = {
|
|
153
|
+
'call.inbound': {
|
|
154
|
+
case: true;
|
|
155
|
+
event: CallInboundEvent;
|
|
156
|
+
result: void;
|
|
157
|
+
};
|
|
158
|
+
'call.outbound': {
|
|
159
|
+
case: true;
|
|
160
|
+
event: CallOutboundEvent;
|
|
161
|
+
result: void;
|
|
162
|
+
};
|
|
163
|
+
'call.ended': {
|
|
164
|
+
case: true;
|
|
165
|
+
event: CallEndedEvent;
|
|
166
|
+
result: void;
|
|
167
|
+
};
|
|
168
|
+
'sms.received': {
|
|
169
|
+
case: true;
|
|
170
|
+
event: SmsReceivedEvent;
|
|
171
|
+
result: void;
|
|
172
|
+
};
|
|
173
|
+
'sms.send-requested': {
|
|
174
|
+
case: true;
|
|
175
|
+
event: SmsSendRequestedEvent;
|
|
176
|
+
result: void;
|
|
177
|
+
};
|
|
178
|
+
'email.received': {
|
|
179
|
+
case: true;
|
|
180
|
+
event: EmailReceivedEvent;
|
|
181
|
+
result: void;
|
|
182
|
+
};
|
|
183
|
+
'email.send-requested': {
|
|
184
|
+
case: true;
|
|
185
|
+
event: EmailSendRequestedEvent;
|
|
186
|
+
result: void;
|
|
187
|
+
};
|
|
188
|
+
/** A conversation needs a person (20 §5.7): a text or email stuck or failed, a call whose model failed (25 §12). */
|
|
189
|
+
'conversation.handoff': {
|
|
190
|
+
case: true;
|
|
191
|
+
event: ConversationHandoffEvent;
|
|
192
|
+
result: void;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Reserved and unused: the platform does not send it yet (the Orchestrator hands a run to the next
|
|
196
|
+
* sequence with `scheduleNextSequence`).
|
|
197
|
+
*/
|
|
198
|
+
'sequence.next': {
|
|
199
|
+
case: true;
|
|
200
|
+
event: EmptyEvent;
|
|
201
|
+
result: void;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
export type SystemEventName = keyof SystemEventMap;
|
|
205
|
+
export type SystemEventPayload<K extends SystemEventName> = SystemEventMap[K]['event'];
|
|
206
|
+
export type SystemEventResult<K extends SystemEventName> = SystemEventMap[K]['result'];
|
|
207
|
+
/**
|
|
208
|
+
* Runtime table mirroring {@link SystemEventMap}. The build uses it to pick the
|
|
209
|
+
* registry kind of each handler; the dispatcher uses it to pick the invocation path.
|
|
210
|
+
*/
|
|
211
|
+
export declare const SYSTEM_EVENTS: {
|
|
212
|
+
readonly [K in SystemEventName]: {
|
|
213
|
+
readonly case: SystemEventMap[K]['case'];
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
export declare const SYSTEM_EVENT_NAMES: readonly SystemEventName[];
|
|
217
|
+
export declare function isSystemEventName(value: string): value is SystemEventName;
|
|
218
|
+
/** Registry kind of an event handler: fixed per event by {@link SYSTEM_EVENTS}. */
|
|
219
|
+
export declare function systemEventKind(name: SystemEventName): Extract<FunctionKind, 'case' | 'noCase'>;
|
|
220
|
+
export type EventHandlerParams<K extends SystemEventName> = {
|
|
221
|
+
event: SystemEventPayload<K>;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Handler signature for one event; whether it gets `c` (the case) and the return type come from the
|
|
225
|
+
* event table. Like any function, a handler reads and writes with `ctx.api.db`, typed by the sequence's
|
|
226
|
+
* `PageTables` (`D`).
|
|
227
|
+
*/
|
|
228
|
+
export type EventHandler<C, K extends SystemEventName, D extends PageTablesDesc | undefined = undefined> = SystemEventMap[K]['case'] extends true ? (c: C, ctx: FunctionCtx<EventHandlerParams<K>, D>) => Promise<SystemEventResult<K>> : (ctx: FunctionCtx<EventHandlerParams<K>, D>) => Promise<SystemEventResult<K>>;
|
|
229
|
+
/** Company `events` export: subscribe to any subset of platform events. */
|
|
230
|
+
export type EventHandlers<C = CaseInput, D extends PageTablesDesc | undefined = undefined> = {
|
|
231
|
+
[K in SystemEventName]?: EventHandler<C, K, D>;
|
|
232
|
+
};
|
|
233
|
+
/** Loader/host-side view of an events map: handler `c` and `ctx` types are not known. */
|
|
234
|
+
export type AnyEventHandlers = {
|
|
235
|
+
[K in SystemEventName]?: (...args: any[]) => Promise<unknown>;
|
|
236
|
+
};
|
|
237
|
+
/** The company function that receives webhooks: `received` of `webhook.ts` at the repository root. */
|
|
238
|
+
export declare const WEBHOOK_RECEIVED_FUNCTION = "webhook.received";
|
|
239
|
+
/**
|
|
240
|
+
* `received` of `webhook.ts` (22 §9): every webhook of the environment comes here, told apart by
|
|
241
|
+
* `event.webhook.name`. It runs with no sequence; to hand a request to one, start an instance or call
|
|
242
|
+
* its code through the platform API. Return accepted / rejected explicitly; throw to be retried.
|
|
243
|
+
*/
|
|
244
|
+
export type WebhookHandler<D extends PageTablesDesc | undefined = undefined> = (ctx: FunctionCtx<{
|
|
245
|
+
event: WebhookEvent;
|
|
246
|
+
}, D>) => Promise<WebhookOutcome>;
|
|
247
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Wire schema of {@link WebhookOutcome}; the worker validates the handler's return with it. */
|
|
3
|
+
export const webhookOutcome = z.discriminatedUnion('status', [
|
|
4
|
+
z.object({ status: z.literal('accepted') }),
|
|
5
|
+
z.object({ status: z.literal('rejected'), reason: z.string() }),
|
|
6
|
+
]);
|
|
7
|
+
/**
|
|
8
|
+
* Runtime table mirroring {@link SystemEventMap}. The build uses it to pick the
|
|
9
|
+
* registry kind of each handler; the dispatcher uses it to pick the invocation path.
|
|
10
|
+
*/
|
|
11
|
+
export const SYSTEM_EVENTS = {
|
|
12
|
+
'call.inbound': { case: true },
|
|
13
|
+
'call.outbound': { case: true },
|
|
14
|
+
'call.ended': { case: true },
|
|
15
|
+
'sms.received': { case: true },
|
|
16
|
+
'sms.send-requested': { case: true },
|
|
17
|
+
'email.received': { case: true },
|
|
18
|
+
'email.send-requested': { case: true },
|
|
19
|
+
'conversation.handoff': { case: true },
|
|
20
|
+
'sequence.next': { case: true },
|
|
21
|
+
};
|
|
22
|
+
export const SYSTEM_EVENT_NAMES = Object.keys(SYSTEM_EVENTS);
|
|
23
|
+
export function isSystemEventName(value) {
|
|
24
|
+
return Object.hasOwn(SYSTEM_EVENTS, value);
|
|
25
|
+
}
|
|
26
|
+
/** Registry kind of an event handler: fixed per event by {@link SYSTEM_EVENTS}. */
|
|
27
|
+
export function systemEventKind(name) {
|
|
28
|
+
return SYSTEM_EVENTS[name].case ? 'case' : 'noCase';
|
|
29
|
+
}
|
|
30
|
+
/** The company function that receives webhooks: `received` of `webhook.ts` at the repository root. */
|
|
31
|
+
export const WEBHOOK_RECEIVED_FUNCTION = 'webhook.received';
|
|
32
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DefinedFunc, FuncMap } from './types.js';
|
|
1
|
+
import type { DefinedFunc, FuncMap, FunctionKind } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Author-time function reference:
|
|
4
4
|
* - string key: `'computeIsQualified'`
|
|
@@ -7,10 +7,19 @@ import type { DefinedFunc, FuncMap } from './types.js';
|
|
|
7
7
|
* Compiled / runtime schemas always store the string name.
|
|
8
8
|
*/
|
|
9
9
|
export type FuncRef = string | DefinedFunc;
|
|
10
|
+
/**
|
|
11
|
+
* Structural stand-in for narrowed refs such as `DefinedCaseFunc<never, …>`: a function whose
|
|
12
|
+
* `caseContext` is typed `never` is not assignable to `DefinedFunc<any>` (any → never fails),
|
|
13
|
+
* but identity lookup only needs the object.
|
|
14
|
+
*/
|
|
15
|
+
export type FuncRefLike = FuncRef | {
|
|
16
|
+
kind: FunctionKind;
|
|
17
|
+
main: unknown;
|
|
18
|
+
};
|
|
10
19
|
/**
|
|
11
20
|
* Normalize a {@link FuncRef} to the functions-map key.
|
|
12
21
|
* Object refs need the same `functions` map for identity lookup
|
|
13
22
|
* (plain map values do not carry `name`).
|
|
14
23
|
*/
|
|
15
|
-
export declare function resolveFuncName(ref:
|
|
24
|
+
export declare function resolveFuncName(ref: FuncRefLike, functions?: FuncMap): string;
|
|
16
25
|
//# sourceMappingURL=func-ref.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { PageTablesDesc } from '../page/typed.js';
|
|
2
|
+
import type { FunctionCtx } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Recurring jobs (25 §6.4): `schedules.ts` at the repository root (company level, next to
|
|
5
|
+
* `webhook.ts`) or in `sequences/<id>/` (sequence level). Each runs on its cron in every environment
|
|
6
|
+
* whose live release has it, with no case and no contact; `ctx.api` is the webhook handler's
|
|
7
|
+
* (`db`, `integration`, `instances.start`, `instances.notify`, `log`, `kv`).
|
|
8
|
+
*/
|
|
9
|
+
/** What `ctx.params.schedule` tells a run: which job, and the tick it runs for. */
|
|
10
|
+
export type ScheduleTick = {
|
|
11
|
+
/** The job's key in `defineSchedules({ … })`. */
|
|
12
|
+
name: string;
|
|
13
|
+
cron: string;
|
|
14
|
+
timezone: string;
|
|
15
|
+
/** The tick this run is for (ISO). A run made up after the worker was down has the missed tick's time. */
|
|
16
|
+
scheduledAt: string;
|
|
17
|
+
};
|
|
18
|
+
export type ScheduleCtx<D extends PageTablesDesc | undefined = undefined> = FunctionCtx<{
|
|
19
|
+
schedule: ScheduleTick;
|
|
20
|
+
}, D>;
|
|
21
|
+
export type ScheduleDefinition<D extends PageTablesDesc | undefined = undefined> = {
|
|
22
|
+
/** Five fields: minute hour day-of-month month day-of-week (`'0 2 * * *'`: every day at 02:00). */
|
|
23
|
+
cron: string;
|
|
24
|
+
/** IANA name the cron is read in (`'UTC'`, `'America/Phoenix'`). */
|
|
25
|
+
timezone: string;
|
|
26
|
+
/** Throw to have the run recorded as failed; it is not retried, the next tick runs as usual. */
|
|
27
|
+
run: (ctx: ScheduleCtx<D>) => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
/** The `schedules` export: job name → definition. */
|
|
30
|
+
export type Schedules<D extends PageTablesDesc | undefined = undefined> = Record<string, ScheduleDefinition<D>>;
|
|
31
|
+
/**
|
|
32
|
+
* Author-side helper for `schedules.ts`:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* export const schedules = defineSchedules({
|
|
36
|
+
* nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx) => { … } },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function defineSchedules<D extends PageTablesDesc | undefined = undefined>(schedules: Schedules<D>): Schedules<D>;
|
|
41
|
+
/** The module a repository root or a sequence defines its jobs in. */
|
|
42
|
+
export declare const SCHEDULES_MODULE = "schedules";
|
|
43
|
+
/** A job's name in the build's function registry: `schedule.<name>` (a `noCase` function). */
|
|
44
|
+
export declare const SCHEDULE_FUNCTION_PREFIX = "schedule.";
|
|
45
|
+
export declare function scheduleFunctionName(name: string): string;
|
|
46
|
+
/** When each job of a build runs, by job name; its code is `functions[scheduleFunctionName(name)]`. */
|
|
47
|
+
export type ScheduleManifest = Record<string, {
|
|
48
|
+
cron: string;
|
|
49
|
+
timezone: string;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=schedules.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Author-side helper for `schedules.ts`:
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* export const schedules = defineSchedules({
|
|
6
|
+
* nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx) => { … } },
|
|
7
|
+
* });
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export function defineSchedules(schedules) {
|
|
11
|
+
return schedules;
|
|
12
|
+
}
|
|
13
|
+
/** The module a repository root or a sequence defines its jobs in. */
|
|
14
|
+
export const SCHEDULES_MODULE = 'schedules';
|
|
15
|
+
/** A job's name in the build's function registry: `schedule.<name>` (a `noCase` function). */
|
|
16
|
+
export const SCHEDULE_FUNCTION_PREFIX = 'schedule.';
|
|
17
|
+
export function scheduleFunctionName(name) {
|
|
18
|
+
return `${SCHEDULE_FUNCTION_PREFIX}${name}`;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=schedules.js.map
|
|
@@ -1,48 +1,70 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { CaseOrchestrator } from '../case-orchestrator/types.js';
|
|
2
|
+
import type { SystemContext } from '../context/types.js';
|
|
3
|
+
import type { CaseInput } from '../case-orchestrator/types.js';
|
|
4
|
+
import type { Db } from '../page/define.js';
|
|
5
|
+
import type { PageTablesDesc, TypedDb } from '../page/typed.js';
|
|
3
6
|
export type FuncOptions = {
|
|
4
7
|
args?: Record<string, unknown>;
|
|
5
8
|
description?: string;
|
|
6
9
|
};
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Runtime function kinds. All of them take `ctx` and run on the Worker host; a host only needs to
|
|
12
|
+
* know whether a function takes `c` (the case).
|
|
13
|
+
*
|
|
14
|
+
* | kind | signature | host |
|
|
15
|
+
* | ------------------ | -------------------------- | ------- |
|
|
16
|
+
* | `case` | `(c, ctx) => R` | Worker |
|
|
17
|
+
* | `noCase` | `(ctx) => R` | Worker |
|
|
18
|
+
* | `orchestrator` | `(c, ctx) => R` | Worker |
|
|
19
|
+
*
|
|
20
|
+
* `define*` names map 1:1 onto kinds; tooling derives the kind from the define name.
|
|
21
|
+
* `orchestrator` has no define: the compiler stamps it on `orchestrator.ts`, and its `ctx`
|
|
22
|
+
* is a `CaseOrchestratorContext` instead of a `SystemContext`.
|
|
23
|
+
*/
|
|
24
|
+
export type FunctionKind = 'case' | 'noCase' | 'orchestrator';
|
|
25
|
+
/** Kinds that take `ctx` and run on the Worker host. */
|
|
26
|
+
export declare const WORKER_FUNCTION_KINDS: readonly ['case', 'noCase', 'orchestrator'];
|
|
27
|
+
export type WorkerFunctionKind = (typeof WORKER_FUNCTION_KINDS)[number];
|
|
28
|
+
export declare function isWorkerFunctionKind(kind: string): kind is WorkerFunctionKind;
|
|
29
|
+
/**
|
|
30
|
+
* `ctx` of every function. `ctx.api.db` reads and writes records like a page script and its actions
|
|
31
|
+
* (15 §10.15 task 4): any row of the company and environment, each write its own transaction. `D` (the sequence's `PageTables`, bound by `__gen`) types them.
|
|
32
|
+
*/
|
|
33
|
+
export type FunctionCtx<Params extends object, D extends PageTablesDesc | undefined = undefined> = Omit<SystemContext, 'api'> & {
|
|
34
|
+
api: Omit<SystemContext['api'], 'db'> & {
|
|
35
|
+
db: D extends PageTablesDesc ? TypedDb<D> : Db;
|
|
36
|
+
};
|
|
10
37
|
params: Params;
|
|
11
38
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export type FunctionCall<Params extends object, Return> = (ctx: FunctionCtx<Params>) => Promise<Return>;
|
|
20
|
-
export type WebHookFunction = FunctionCall<WebHookFunctionParams, void>;
|
|
21
|
-
export type GetFirstMessageParams<S = CaseContext> = {
|
|
22
|
-
caseContext: S;
|
|
23
|
-
};
|
|
24
|
-
export type GetFirstMessageFunction<S = CaseContext> = FunctionCall<GetFirstMessageParams<S>, string>;
|
|
25
|
-
/** Object-key → implementation type for platform-invoked entries. */
|
|
26
|
-
export type SystemFuncMap = {
|
|
27
|
-
webhook: WebHookFunction;
|
|
28
|
-
getFirstMessage: GetFirstMessageFunction;
|
|
29
|
-
};
|
|
39
|
+
/**
|
|
40
|
+
* Bound to a case: `(c, ctx)`, `c` the case — the instance and its business root's id ({@link CaseInput}),
|
|
41
|
+
* not the page (the page is the conversation's). Return value is caller-defined (event handlers return nothing).
|
|
42
|
+
*/
|
|
43
|
+
export type CaseFn<S = CaseInput, P extends object = object, R = unknown, D extends PageTablesDesc | undefined = undefined> = (c: S, ctx: FunctionCtx<P, D>) => Promise<R>;
|
|
44
|
+
/** Not bound to a case: `(ctx)` only. */
|
|
45
|
+
export type NoCaseFn<P extends object = object, R = unknown, D extends PageTablesDesc | undefined = undefined> = (ctx: FunctionCtx<P, D>) => Promise<R>;
|
|
30
46
|
type FuncMeta = {
|
|
31
47
|
description?: string;
|
|
32
48
|
args?: Record<string, unknown>;
|
|
33
49
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
export type DefinedCaseFunc<S = CaseInput, P extends object = object, R = unknown, D extends PageTablesDesc | undefined = undefined> = FuncMeta & {
|
|
51
|
+
kind: 'case';
|
|
52
|
+
main: CaseFn<S, P, R, D>;
|
|
53
|
+
};
|
|
54
|
+
export type DefinedNoCaseFunc<P extends object = object, R = unknown, D extends PageTablesDesc | undefined = undefined> = FuncMeta & {
|
|
55
|
+
kind: 'noCase';
|
|
56
|
+
main: NoCaseFn<P, R, D>;
|
|
57
|
+
};
|
|
58
|
+
/** The `orchestrator.ts` entry point, registered by the compiler (never authored in `functions`). */
|
|
59
|
+
export type DefinedCaseOrchestratorFunc<S = CaseInput> = FuncMeta & {
|
|
60
|
+
kind: 'orchestrator';
|
|
61
|
+
main: CaseOrchestrator<S>;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* One entry in a plain `functions` map (`{ name: define*Func(...) }`).
|
|
65
|
+
* Generics are kept (not erased) for the typed helpers that read a function's signature.
|
|
66
|
+
*/
|
|
67
|
+
export type DefinedFunc<S = any, P extends object = any, R = any> = DefinedCaseFunc<S, P, R> | DefinedNoCaseFunc<P, R> | DefinedCaseOrchestratorFunc<S>;
|
|
46
68
|
/** Author map: key is the function name. */
|
|
47
69
|
export type FuncMap = Record<string, DefinedFunc>;
|
|
48
70
|
/** Map entry with name stamped from the key (for platform loaders). */
|
|
@@ -56,23 +78,12 @@ type RegistryCode = {
|
|
|
56
78
|
*/
|
|
57
79
|
code?: string;
|
|
58
80
|
};
|
|
59
|
-
/** Compiled function registry entry
|
|
60
|
-
export type FunctionRegistryEntry =
|
|
61
|
-
kind:
|
|
62
|
-
}) | (RegistryCode & {
|
|
63
|
-
kind: 'custom';
|
|
64
|
-
writes: FieldPath[];
|
|
65
|
-
}) | (RegistryCode & {
|
|
66
|
-
kind: 'system';
|
|
67
|
-
});
|
|
68
|
-
export type FunctionRegistry = Record<string, FunctionRegistryEntry>;
|
|
69
|
-
/** Compiled CaseContext projector (optional on SequenceBuild). */
|
|
70
|
-
export type CaseContextViewRegistryEntry = {
|
|
71
|
-
kind: 'caseContextView';
|
|
72
|
-
/** Present on published builds; omitted on local serve overlay. */
|
|
73
|
-
code?: string;
|
|
81
|
+
/** Compiled function registry entry (JSON-safe). Same shape for `functions` and `events`. */
|
|
82
|
+
export type FunctionRegistryEntry = RegistryCode & {
|
|
83
|
+
kind: FunctionKind;
|
|
74
84
|
};
|
|
75
|
-
|
|
85
|
+
export type FunctionRegistry = Record<string, FunctionRegistryEntry>;
|
|
86
|
+
/** Plain-object FuncMap → array with `name` stamped (platform-side loaders). */
|
|
76
87
|
export declare function toFuncRegistrations(functions: FuncMap): FuncRegistration[];
|
|
77
88
|
export {};
|
|
78
89
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Kinds that take `ctx` and run on the Worker host. */
|
|
2
|
+
export const WORKER_FUNCTION_KINDS = ['case', 'noCase', 'orchestrator'];
|
|
3
|
+
export function isWorkerFunctionKind(kind) {
|
|
4
|
+
return WORKER_FUNCTION_KINDS.includes(kind);
|
|
5
|
+
}
|
|
6
|
+
/** Plain-object FuncMap → array with `name` stamped (platform-side loaders). */
|
|
2
7
|
export function toFuncRegistrations(functions) {
|
|
3
8
|
return Object.entries(functions).map(([name, def]) => ({ ...def, name }));
|
|
4
9
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type Window = {
|
|
2
|
+
start: string;
|
|
3
|
+
end: string;
|
|
4
|
+
};
|
|
5
|
+
export type Weekday = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
|
|
6
|
+
/** Company `office-hours.ts` config. */
|
|
7
|
+
export type OfficeHours = {
|
|
8
|
+
/** IANA timezone name for the office (e.g. `'America/New_York'`). */
|
|
9
|
+
timezone: string;
|
|
10
|
+
/** Standard weekly open windows per weekday (`[]` means closed that weekday). */
|
|
11
|
+
week: Record<Weekday, Window[]>;
|
|
12
|
+
/** Recurring annual dates (`MM-DD`) whose `hours` replace `week` (`[]` means closed all day). */
|
|
13
|
+
holidays: {
|
|
14
|
+
date: string;
|
|
15
|
+
hours: Window[];
|
|
16
|
+
}[];
|
|
17
|
+
/** One-off calendar dates (`YYYY-MM-DD`) whose `hours` take precedence over both `holidays` and `week`. */
|
|
18
|
+
overrides: {
|
|
19
|
+
date: string;
|
|
20
|
+
hours: Window[];
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
/** The office hours now (`ctx.officeHours` of a page). `open` / `today` are filled by `resolveOfficeHours(now)`. */
|
|
24
|
+
export type OfficeHoursSnapshot = OfficeHours & {
|
|
25
|
+
/** Whether the office is currently open at the resolved timestamp (`ctx.time.now`). */
|
|
26
|
+
open: boolean;
|
|
27
|
+
/** Effective open windows for today's date in `timezone` (after applying `overrides` / `holidays` / `week`). */
|
|
28
|
+
today: Window[];
|
|
29
|
+
};
|
|
30
|
+
export type ParseOfficeHoursResult = {
|
|
31
|
+
ok: true;
|
|
32
|
+
value: OfficeHours;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
issues: string[];
|
|
36
|
+
};
|
|
37
|
+
export declare function parseOfficeHours(value: unknown): ParseOfficeHoursResult;
|
|
38
|
+
export declare function resolveOfficeHours(config: OfficeHours | null | undefined, now: number): OfficeHoursSnapshot | null;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|