@superpanel-sdk/runtime 0.5.0 → 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 +3 -3
- package/dist/builder/codegen/emit.d.ts +5 -10
- package/dist/builder/codegen/emit.js +100 -106
- package/dist/builder/codegen/generate.d.ts +3 -5
- package/dist/builder/codegen/generate.js +13 -32
- package/dist/builder/company-imports.d.ts +5 -0
- package/dist/builder/company-imports.js +9 -1
- package/dist/builder/compile/compile-sequence.d.ts +13 -11
- package/dist/builder/compile/compile-sequence.js +135 -83
- package/dist/builder/compile/function-code.d.ts +15 -9
- package/dist/builder/compile/function-code.js +59 -29
- package/dist/builder/compile/registry.d.ts +4 -4
- package/dist/builder/compile/registry.js +14 -12
- 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 +17 -17
- package/dist/builder/load.js +27 -25
- package/dist/builder/paths.d.ts +6 -1
- package/dist/builder/paths.js +16 -2
- package/dist/builder/schedules.d.ts +9 -7
- package/dist/builder/schedules.js +20 -21
- package/dist/builder/typecheck.d.ts +1 -1
- package/dist/builder/typecheck.js +3 -6
- package/dist/builder/types.d.ts +41 -5
- package/dist/builder/types.js +19 -0
- package/dist/cli/calls/index.d.ts +177 -0
- package/dist/cli/calls/index.js +96 -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 +84 -1
- 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 +40 -4
- package/dist/cli/serve/index.js +167 -28
- 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 +0 -1
- package/dist/compute-host/compute-host.d.ts +5 -6
- package/dist/compute-host/compute-host.js +4 -13
- package/dist/compute-host/source-compute-host.d.ts +5 -7
- package/dist/compute-host/source-compute-host.js +12 -33
- package/dist/core/case-orchestrator/contact-hours.d.ts +26 -6
- package/dist/core/case-orchestrator/contact-hours.js +27 -8
- package/dist/core/case-orchestrator/index.d.ts +1 -4
- package/dist/core/case-orchestrator/index.js +1 -4
- package/dist/core/case-orchestrator/render.d.ts +1 -1
- package/dist/core/case-orchestrator/render.js +15 -10
- package/dist/core/case-orchestrator/types.d.ts +83 -128
- package/dist/core/case-orchestrator/types.js +0 -4
- package/dist/core/context/email-message.d.ts +40 -1
- package/dist/core/context/email-message.js +27 -0
- package/dist/core/context/email.d.ts +13 -1
- package/dist/core/context/email.js +2 -3
- package/dist/core/context/exchanges.d.ts +25 -0
- package/dist/core/context/exchanges.js +25 -7
- package/dist/core/context/instances.d.ts +31 -2
- package/dist/core/context/instances.js +18 -4
- package/dist/core/context/platform-registry.d.ts +35 -0
- package/dist/core/context/sms.d.ts +30 -0
- package/dist/core/context/sms.js +20 -0
- package/dist/core/context/types.d.ts +29 -1
- package/dist/core/conversation/index.d.ts +58 -4
- package/dist/core/conversation/index.js +123 -4
- package/dist/core/functions/errors.d.ts +74 -0
- package/dist/core/functions/errors.js +26 -0
- package/dist/core/functions/events.d.ts +23 -78
- package/dist/core/functions/events.js +8 -17
- package/dist/core/functions/schedules.d.ts +9 -10
- package/dist/core/functions/schedules.js +2 -2
- package/dist/core/functions/types.d.ts +17 -72
- package/dist/core/functions/types.js +1 -9
- package/dist/core/page/define.d.ts +230 -160
- package/dist/core/page/define.js +145 -104
- 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/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 +67 -25
- package/dist/core/page/render.js +492 -272
- 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 +27 -0
- package/dist/core/page/time-format.js +84 -0
- package/dist/core/page/typed.d.ts +165 -159
- package/dist/core/page/workspace.d.ts +25 -1
- package/dist/core/page/workspace.js +48 -13
- package/dist/core/party/schema.d.ts +74 -3
- package/dist/core/party/schema.js +39 -6
- package/dist/core/party/types.d.ts +8 -13
- package/dist/core/sequence/define.d.ts +1 -2
- package/dist/core/slot/company-metadata.d.ts +11 -22
- package/dist/core/slot/company-metadata.js +12 -39
- package/dist/core/slot/compile-schema.js +6 -6
- package/dist/core/slot/field.d.ts +1 -2
- package/dist/core/slot/field.js +0 -2
- package/dist/core/slot/index.d.ts +3 -3
- package/dist/core/slot/index.js +3 -3
- package/dist/core/slot/naming.d.ts +1 -1
- package/dist/core/slot/naming.js +1 -1
- package/dist/core/slot/platform-fields.d.ts +4 -4
- package/dist/core/slot/platform-fields.js +5 -5
- package/dist/core/slot/schema-compat.d.ts +8 -7
- package/dist/core/slot/schema-compat.js +22 -31
- package/dist/core/slot/schema.d.ts +3 -59
- package/dist/core/slot/schema.js +0 -15
- package/dist/core/slot/types.d.ts +4 -10
- package/dist/core/slot/value.d.ts +2 -0
- package/dist/core/slot/value.js +6 -2
- package/dist/dev-overlay/protocol.d.ts +38 -5
- package/dist/fn-context/build-context.js +10 -4
- package/dist/fn-context/fake/index.d.ts +2 -0
- package/dist/fn-context/fake/index.js +5 -3
- package/dist/fn-context/fn-params.d.ts +2 -5
- package/dist/fn-context/fn-params.js +6 -9
- package/dist/fn-context/index.d.ts +1 -1
- package/dist/fn-context/make-ctx.js +5 -4
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +11 -3
- package/dist/fn-context/rpc/case-orchestrator-tools.js +0 -1
- 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 +1 -1
- package/dist/fn-context/rpc/index.js +1 -1
- package/dist/fn-context/rpc/integration/index.d.ts +11 -1
- package/dist/fn-context/rpc/log.d.ts +11 -1
- package/dist/fn-context/rpc/platform.d.ts +11 -1
- package/dist/fn-context/rpc/records.d.ts +13 -6
- package/dist/fn-context/rpc/records.js +2 -4
- package/dist/fn-context/rpc/trpc-client.d.ts +42 -0
- package/dist/fn-context/rpc/trpc-client.js +151 -22
- package/dist/fn-context/rpc/trpc-init.d.ts +19 -1
- package/dist/fn-context/rpc/trpc-init.js +10 -4
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +66 -8
- package/dist/fn-context/run-scope.js +1 -1
- package/dist/fn-context/types.d.ts +20 -6
- package/dist/index.d.ts +11 -12
- package/dist/index.js +5 -8
- package/dist/logger.d.ts +4 -0
- package/dist/logger.js +8 -0
- package/dist/platform.d.ts +32 -33
- package/dist/platform.js +23 -22
- 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 +12 -35
- 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 +16 -6
- package/dist/worker.d.ts +2 -1
- package/dist/worker.js +2 -1
- package/package.json +20 -16
- package/dist/core/case-orchestrator/follow-ups.d.ts +0 -31
- package/dist/core/case-orchestrator/follow-ups.js +0 -103
- package/dist/core/case-orchestrator/tools.d.ts +0 -29
- package/dist/core/case-orchestrator/tools.js +0 -31
- package/dist/core/case-orchestrator/validate.d.ts +0 -11
- package/dist/core/case-orchestrator/validate.js +0 -63
- package/dist/core/functions/define/bind.d.ts +0 -25
- package/dist/core/functions/define/bind.js +0 -14
- package/dist/core/functions/define/case.d.ts +0 -9
- package/dist/core/functions/define/case.js +0 -13
- package/dist/core/functions/define/events.d.ts +0 -20
- package/dist/core/functions/define/events.js +0 -21
- package/dist/core/functions/define/no-case.d.ts +0 -4
- package/dist/core/functions/define/no-case.js +0 -9
- package/dist/core/functions/func-ref.d.ts +0 -25
- package/dist/core/functions/func-ref.js +0 -20
|
@@ -4,11 +4,130 @@
|
|
|
4
4
|
/** The channels a conversation runs on. A conversation engine runs on calls and SMS (17b §9.0); email routes and stores only. */
|
|
5
5
|
export const CHANNELS = ['call', 'sms', 'email'];
|
|
6
6
|
/**
|
|
7
|
-
* The languages
|
|
8
|
-
* (
|
|
7
|
+
* The languages a contact can have (`contact.language`, 48 §3) and texts and emails tag their replies with
|
|
8
|
+
* (48 §5.2): BCP-47 base tags. Texts and emails need no voice, so they are not limited to what calls can
|
|
9
|
+
* speak (75 §3); a contact who writes in Chinese keeps `zh`, and a call with them opens in English.
|
|
9
10
|
*/
|
|
10
|
-
export const
|
|
11
|
+
export const CONTACT_LANGUAGES = [
|
|
12
|
+
'en', 'fr', 'de', 'es', 'pt', 'zh', 'ja', 'hi', 'it', 'ko', 'nl', 'pl', 'ru', 'sv', 'tr', 'tl', 'bg', 'ro', 'ar', 'cs',
|
|
13
|
+
'el', 'fi', 'hr', 'ms', 'sk', 'da', 'ta', 'uk', 'hu', 'no', 'vi', 'bn', 'th', 'he', 'ka', 'id', 'te', 'gu', 'kn', 'ml',
|
|
14
|
+
'mr', 'pa',
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* The languages calls can speak (48 §4, narrowed by 75 §3): the platform language table's tags, the ones
|
|
18
|
+
* Deepgram Flux (`flux-general-multi`) turns on, all spoken by Cartesia. Each has a native default voice,
|
|
19
|
+
* the platform's fixed lines and STOP words (services' language table). A caller speaking another language
|
|
20
|
+
* is answered in the call's language, told once it cannot be spoken (48 §1 item 6).
|
|
21
|
+
*/
|
|
22
|
+
export const SPOKEN_LANGUAGES = ['en', 'es', 'fr', 'de', 'hi', 'ru', 'pt', 'ja', 'it', 'nl'];
|
|
23
|
+
/**
|
|
24
|
+
* `value` checked as a `Spoken` (66 §2): an object, at least one language, every key a table tag, every
|
|
25
|
+
* text not empty. Copied, in the order written. No `Intl` (the page sandbox has none).
|
|
26
|
+
*/
|
|
27
|
+
export function checkSpoken(value, at) {
|
|
28
|
+
if (typeof value === 'string')
|
|
29
|
+
throw new Error(`${at}: write it per language, { en: '…', es: '…' } (66 §2), not one string`);
|
|
30
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
31
|
+
throw new Error(`${at}: write it per language, { en: '…', es: '…' } (66 §2)`);
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const [key, text] of Object.entries(value)) {
|
|
34
|
+
if (!SPOKEN_LANGUAGES.includes(key))
|
|
35
|
+
throw new Error(`${at}: '${key}' is not a language of the platform's table (${SPOKEN_LANGUAGES.join(', ')})`);
|
|
36
|
+
if (typeof text !== 'string' || !text.trim())
|
|
37
|
+
throw new Error(`${at}: the ${key} text is empty`);
|
|
38
|
+
out[key] = text;
|
|
39
|
+
}
|
|
40
|
+
if (!Object.keys(out).length)
|
|
41
|
+
throw new Error(`${at}: write it in at least one language`);
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** The text a `Spoken` falls back to (66 §3): `en` when written, else the first language written. */
|
|
45
|
+
export function fallbackSpoken(spoken) {
|
|
46
|
+
const texts = spoken;
|
|
47
|
+
if (texts.en)
|
|
48
|
+
return { text: texts.en, language: 'en' };
|
|
49
|
+
const [language, text] = Object.entries(texts).find(([, t]) => !!t);
|
|
50
|
+
return { text, language };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The line to say on a call in `language` (66 §3): the same tag, else the same base language
|
|
54
|
+
* (`pt-BR` → `pt`), else `en`, else the first written. `missing`: the language it fell back from, to tell
|
|
55
|
+
* the company.
|
|
56
|
+
*/
|
|
57
|
+
export function pickSpoken(spoken, language) {
|
|
58
|
+
const texts = spoken;
|
|
59
|
+
if (language) {
|
|
60
|
+
const exact = texts[language];
|
|
61
|
+
if (exact)
|
|
62
|
+
return { text: exact, missing: null };
|
|
63
|
+
const base = matchSpokenLanguage(language);
|
|
64
|
+
const near = base ? texts[base] : undefined;
|
|
65
|
+
if (near)
|
|
66
|
+
return { text: near, missing: null };
|
|
67
|
+
}
|
|
68
|
+
const fallback = fallbackSpoken(spoken);
|
|
69
|
+
return { text: fallback.text, missing: language && language !== fallback.language ? language : null };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Tags a table entry is not the fallback for (48 §2): the same base language, not understood by its
|
|
73
|
+
* speakers. Matched by language and region (`zh-HK` covers `zh-Hant-HK`); Cantonese (`yue`) is apart already.
|
|
74
|
+
*/
|
|
75
|
+
const NOT_FALLBACK_FOR = { zh: ['zh-HK', 'zh-MO'] };
|
|
76
|
+
/** `value` as a canonical BCP-47 tag (`pt-br` → `pt-BR`), or null when it is not one. */
|
|
77
|
+
export function canonicalLanguage(value) {
|
|
78
|
+
if (typeof value !== 'string' || !value.trim())
|
|
79
|
+
return null;
|
|
80
|
+
try {
|
|
81
|
+
return Intl.getCanonicalLocales(value.trim())[0] ?? null;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Whether `value` is one of the table's tags as stored (a language calls can speak). */
|
|
11
88
|
export function isSpokenLanguage(value) {
|
|
12
|
-
return typeof value === 'string' && SPOKEN_LANGUAGES.includes(value
|
|
89
|
+
return typeof value === 'string' && SPOKEN_LANGUAGES.includes(value);
|
|
90
|
+
}
|
|
91
|
+
/** Whether `value` is a language `contact.language` can hold, as stored (texts and emails: any of them). */
|
|
92
|
+
export function isContactLanguage(value) {
|
|
93
|
+
return typeof value === 'string' && CONTACT_LANGUAGES.includes(value);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The table's language a tag resolves to (48 §2): the same tag, else the first with its base language
|
|
97
|
+
* (`es-MX` → `es`), unless that entry is not the fallback for it (`zh-HK`). Null: calls cannot speak it.
|
|
98
|
+
*/
|
|
99
|
+
export function matchSpokenLanguage(value) {
|
|
100
|
+
return matchIn(SPOKEN_LANGUAGES, value);
|
|
101
|
+
}
|
|
102
|
+
/** The contact language a tag resolves to, as {@link matchSpokenLanguage} (`zh-CN` → `zh`). Null: none. */
|
|
103
|
+
export function matchContactLanguage(value) {
|
|
104
|
+
return matchIn(CONTACT_LANGUAGES, value);
|
|
105
|
+
}
|
|
106
|
+
function matchIn(tags, value) {
|
|
107
|
+
const tag = canonicalLanguage(value);
|
|
108
|
+
if (!tag)
|
|
109
|
+
return null;
|
|
110
|
+
if (tags.includes(tag))
|
|
111
|
+
return tag;
|
|
112
|
+
const locale = new Intl.Locale(tag);
|
|
113
|
+
const hit = tags.find((l) => new Intl.Locale(l).language === locale.language);
|
|
114
|
+
if (!hit)
|
|
115
|
+
return null;
|
|
116
|
+
const excluded = (NOT_FALLBACK_FOR[hit] ?? []).some((x) => {
|
|
117
|
+
const ex = new Intl.Locale(x);
|
|
118
|
+
return ex.language === locale.language && (!ex.region || ex.region === locale.region);
|
|
119
|
+
});
|
|
120
|
+
return excluded ? null : hit;
|
|
121
|
+
}
|
|
122
|
+
let displayNames = null;
|
|
123
|
+
/** A language's name in English, for prompts (`zh` → `Chinese`); the tag itself when it has none. */
|
|
124
|
+
export function languageName(tag) {
|
|
125
|
+
try {
|
|
126
|
+
displayNames ??= new Intl.DisplayNames(['en'], { type: 'language' });
|
|
127
|
+
return displayNames.of(tag) ?? tag;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return tag;
|
|
131
|
+
}
|
|
13
132
|
}
|
|
14
133
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { PageTablesDesc } from '../page/typed.js';
|
|
2
|
+
import type { ExchangeRef } from '../context/exchanges.js';
|
|
3
|
+
import type { Ctx } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Errors of the company's code (67): a failure its code did not catch (a throw, its time or memory up), or
|
|
6
|
+
* a text or email conversation the AI marked stuck, is recorded once and the company's `onError` (root
|
|
7
|
+
* `errors.ts`) runs for it, in the background. What happens at the moment is the platform's and depends
|
|
8
|
+
* only on the channel (67 §3). The company does not throw errors of its own: what its code foresees, it
|
|
9
|
+
* handles where it happens. The platform's own failures are the platform's, not the company's (67 §4.4).
|
|
10
|
+
*/
|
|
11
|
+
/** The module at the repository root `onError` is exported from. */
|
|
12
|
+
export declare const ERRORS_MODULE = "errors";
|
|
13
|
+
/** `onError`'s name in the company build's function registry. */
|
|
14
|
+
export declare const ON_ERROR_FUNCTION = "onError";
|
|
15
|
+
/**
|
|
16
|
+
* `crash` an uncaught throw, `timeout` / `memory` the call's limit, `stuck` the AI marked a text or email
|
|
17
|
+
* conversation stuck, `platform` the platform failed and what the code was doing was not done (74 §3.2: an
|
|
18
|
+
* Orchestrator run the platform cut off or could not run, or a {@link PlatformUnavailableError} not caught).
|
|
19
|
+
*/
|
|
20
|
+
export type CodeErrorKind = 'crash' | 'timeout' | 'memory' | 'stuck' | 'platform';
|
|
21
|
+
/** What the company is told of a `platform` error (74 §3.2): the platform's own failure stays in its logs and alerts. */
|
|
22
|
+
export declare const PLATFORM_UNAVAILABLE_MESSAGE = "The platform was temporarily unavailable; we have been alerted.";
|
|
23
|
+
/**
|
|
24
|
+
* A `ctx.api` call the platform could not answer (74 §3.2): it was unreachable, or failed on its side, after
|
|
25
|
+
* the tries it was worth. Not caught, it is a `platform` error (we are alerted, `onError` is told); caught and
|
|
26
|
+
* thrown again as another error, it is the code's own.
|
|
27
|
+
*/
|
|
28
|
+
export declare class PlatformUnavailableError extends Error {
|
|
29
|
+
readonly name = "PlatformUnavailableError";
|
|
30
|
+
/** The platform's refusal reason, when it gave one (`error.code`, as on any `ctx.api` error). */
|
|
31
|
+
code?: string;
|
|
32
|
+
}
|
|
33
|
+
/** What failed: the kind of entry, and its name (a function's, an event's, a job's, the page's `render` / `start` / `action:<name>`). */
|
|
34
|
+
export type CodeErrorSourceType = 'resolve' | 'page' | 'function' | 'event' | 'orchestrator' | 'schedule' | 'webhook' | 'conversation';
|
|
35
|
+
/** At most this much JSON for `args` (67 §4.2): bigger is cut, and says so. */
|
|
36
|
+
export declare const ERROR_JSON_MAX_BYTES: number;
|
|
37
|
+
/** One error, as `onError` gets it (`args.error`). */
|
|
38
|
+
export type CodeErrorEvent = {
|
|
39
|
+
/** The error's id: find it in the error view, say it to the platform's team. */
|
|
40
|
+
id: string;
|
|
41
|
+
kind: CodeErrorKind;
|
|
42
|
+
message: string;
|
|
43
|
+
/** Where your code threw, in your files; none for `timeout`, `memory`, `stuck`, `platform`. */
|
|
44
|
+
stack?: string;
|
|
45
|
+
source: {
|
|
46
|
+
type: CodeErrorSourceType;
|
|
47
|
+
name: string;
|
|
48
|
+
};
|
|
49
|
+
/** The published company build whose code ran; null when a repository was being served. */
|
|
50
|
+
buildId: string | null;
|
|
51
|
+
at: string;
|
|
52
|
+
ids: {
|
|
53
|
+
sequenceId?: string;
|
|
54
|
+
instanceId?: string;
|
|
55
|
+
contactId?: string;
|
|
56
|
+
runId?: string;
|
|
57
|
+
};
|
|
58
|
+
/** Who is waiting: the call (it was already ended), or a text's or email's exchange and what the customer sent. */
|
|
59
|
+
channel?: {
|
|
60
|
+
type: 'call';
|
|
61
|
+
callId?: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'sms' | 'email';
|
|
64
|
+
exchange?: ExchangeRef;
|
|
65
|
+
waiting: string;
|
|
66
|
+
};
|
|
67
|
+
/** The arguments of the call that failed (cut at {@link ERROR_JSON_MAX_BYTES}). */
|
|
68
|
+
args?: unknown;
|
|
69
|
+
};
|
|
70
|
+
/** `onError` of `errors.ts`: `(ctx, { error })`, run once for each error, with no case. */
|
|
71
|
+
export type OnError<D extends PageTablesDesc | undefined = undefined> = (ctx: Ctx<D>, args: {
|
|
72
|
+
error: CodeErrorEvent;
|
|
73
|
+
}) => Promise<void>;
|
|
74
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors of the company's code (67): a failure its code did not catch (a throw, its time or memory up), or
|
|
3
|
+
* a text or email conversation the AI marked stuck, is recorded once and the company's `onError` (root
|
|
4
|
+
* `errors.ts`) runs for it, in the background. What happens at the moment is the platform's and depends
|
|
5
|
+
* only on the channel (67 §3). The company does not throw errors of its own: what its code foresees, it
|
|
6
|
+
* handles where it happens. The platform's own failures are the platform's, not the company's (67 §4.4).
|
|
7
|
+
*/
|
|
8
|
+
/** The module at the repository root `onError` is exported from. */
|
|
9
|
+
export const ERRORS_MODULE = 'errors';
|
|
10
|
+
/** `onError`'s name in the company build's function registry. */
|
|
11
|
+
export const ON_ERROR_FUNCTION = 'onError';
|
|
12
|
+
/** What the company is told of a `platform` error (74 §3.2): the platform's own failure stays in its logs and alerts. */
|
|
13
|
+
export const PLATFORM_UNAVAILABLE_MESSAGE = 'The platform was temporarily unavailable; we have been alerted.';
|
|
14
|
+
/**
|
|
15
|
+
* A `ctx.api` call the platform could not answer (74 §3.2): it was unreachable, or failed on its side, after
|
|
16
|
+
* the tries it was worth. Not caught, it is a `platform` error (we are alerted, `onError` is told); caught and
|
|
17
|
+
* thrown again as another error, it is the code's own.
|
|
18
|
+
*/
|
|
19
|
+
export class PlatformUnavailableError extends Error {
|
|
20
|
+
name = 'PlatformUnavailableError';
|
|
21
|
+
/** The platform's refusal reason, when it gave one (`error.code`, as on any `ctx.api` error). */
|
|
22
|
+
code;
|
|
23
|
+
}
|
|
24
|
+
/** At most this much JSON for `args` (67 §4.2): bigger is cut, and says so. */
|
|
25
|
+
export const ERROR_JSON_MAX_BYTES = 16 * 1024;
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { FunctionCtx, FunctionKind } from './types.js';
|
|
5
|
-
import type { ExchangeRef } from '../context/exchanges.js';
|
|
2
|
+
import type { Id, PageTablesDesc } from '../page/typed.js';
|
|
3
|
+
import type { Ctx } from './types.js';
|
|
6
4
|
/**
|
|
7
5
|
* Platform events.
|
|
8
6
|
*
|
|
9
7
|
* The event name is the key of the company `events` export. For every event the
|
|
10
|
-
* platform fixes the payload
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* platform fixes the payload and the return type (`void` for every event; `webhook.received`, a
|
|
9
|
+
* function of its own, returns a {@link WebhookOutcome}) — companies only choose which events to
|
|
10
|
+
* subscribe to.
|
|
13
11
|
*
|
|
14
|
-
* A handler is
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* A handler is a function like any other (38 §2.2): `(ctx, { event, subject, instanceId })`, the
|
|
13
|
+
* company's own code, not the conversation's: it does not get the page. It reads and writes with
|
|
14
|
+
* `ctx.api.db`.
|
|
17
15
|
*
|
|
18
16
|
* Payloads are provider-neutral on purpose: Twilio / Gmail vocabulary is
|
|
19
17
|
* translated in the channel adapter, never carried into these types.
|
|
@@ -66,8 +64,6 @@ export type EmailReceivedEvent = EmailEventBase & {
|
|
|
66
64
|
export type EmailSendRequestedEvent = EmailEventBase & {
|
|
67
65
|
requestedAt: string;
|
|
68
66
|
};
|
|
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
67
|
/**
|
|
72
68
|
* The HTTP request exactly as the gateway saw it. The platform verifies nothing: every header,
|
|
73
69
|
* the absolute URL and the raw body are forwarded so the handler can check the sender's signature.
|
|
@@ -127,112 +123,61 @@ export type WebhookOutcome = {
|
|
|
127
123
|
};
|
|
128
124
|
/** Wire schema of {@link WebhookOutcome}; the worker validates the handler's return with it. */
|
|
129
125
|
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 }. */
|
|
126
|
+
/** Event name → { payload, handler return }. */
|
|
152
127
|
export type SystemEventMap = {
|
|
153
128
|
'call.inbound': {
|
|
154
|
-
case: true;
|
|
155
129
|
event: CallInboundEvent;
|
|
156
130
|
result: void;
|
|
157
131
|
};
|
|
158
132
|
'call.outbound': {
|
|
159
|
-
case: true;
|
|
160
133
|
event: CallOutboundEvent;
|
|
161
134
|
result: void;
|
|
162
135
|
};
|
|
163
136
|
'call.ended': {
|
|
164
|
-
case: true;
|
|
165
137
|
event: CallEndedEvent;
|
|
166
138
|
result: void;
|
|
167
139
|
};
|
|
168
140
|
'sms.received': {
|
|
169
|
-
case: true;
|
|
170
141
|
event: SmsReceivedEvent;
|
|
171
142
|
result: void;
|
|
172
143
|
};
|
|
173
144
|
'sms.send-requested': {
|
|
174
|
-
case: true;
|
|
175
145
|
event: SmsSendRequestedEvent;
|
|
176
146
|
result: void;
|
|
177
147
|
};
|
|
178
148
|
'email.received': {
|
|
179
|
-
case: true;
|
|
180
149
|
event: EmailReceivedEvent;
|
|
181
150
|
result: void;
|
|
182
151
|
};
|
|
183
152
|
'email.send-requested': {
|
|
184
|
-
case: true;
|
|
185
153
|
event: EmailSendRequestedEvent;
|
|
186
154
|
result: void;
|
|
187
155
|
};
|
|
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
156
|
};
|
|
204
157
|
export type SystemEventName = keyof SystemEventMap;
|
|
205
158
|
export type SystemEventPayload<K extends SystemEventName> = SystemEventMap[K]['event'];
|
|
206
159
|
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
|
-
*/
|
|
160
|
+
/** Runtime table mirroring {@link SystemEventMap}: the events a handler may be written for. */
|
|
211
161
|
export declare const SYSTEM_EVENTS: {
|
|
212
|
-
readonly [K in SystemEventName]:
|
|
213
|
-
readonly case: SystemEventMap[K]['case'];
|
|
214
|
-
};
|
|
162
|
+
readonly [K in SystemEventName]: true;
|
|
215
163
|
};
|
|
216
164
|
export declare const SYSTEM_EVENT_NAMES: readonly SystemEventName[];
|
|
217
165
|
export declare function isSystemEventName(value: string): value is SystemEventName;
|
|
218
|
-
/**
|
|
219
|
-
export
|
|
220
|
-
export type EventHandlerParams<K extends SystemEventName> = {
|
|
166
|
+
/** What a handler is called with (38 §2.2): the event, and the instance it is on and its business root. */
|
|
167
|
+
export type EventHandlerArgs<K extends SystemEventName, S extends string = string> = {
|
|
221
168
|
event: SystemEventPayload<K>;
|
|
169
|
+
subject: Id<S>;
|
|
170
|
+
instanceId: string;
|
|
222
171
|
};
|
|
223
|
-
/**
|
|
224
|
-
|
|
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>>;
|
|
172
|
+
/** Handler for one event: `(ctx, { event, subject, instanceId })`; `D` types `ctx.api.db`, `S` the business root. */
|
|
173
|
+
export type EventHandler<K extends SystemEventName, D extends PageTablesDesc | undefined = undefined, S extends string = string> = (ctx: Ctx<D>, args: EventHandlerArgs<K, S>) => Promise<SystemEventResult<K>>;
|
|
229
174
|
/** Company `events` export: subscribe to any subset of platform events. */
|
|
230
|
-
export type EventHandlers<
|
|
231
|
-
[K in SystemEventName]?: EventHandler<
|
|
175
|
+
export type EventHandlers<D extends PageTablesDesc | undefined = undefined, S extends string = string> = {
|
|
176
|
+
[K in SystemEventName]?: EventHandler<K, D, S>;
|
|
232
177
|
};
|
|
233
|
-
/** Loader/host-side view of an events map: handler
|
|
178
|
+
/** Loader/host-side view of an events map: handler argument types are not known. */
|
|
234
179
|
export type AnyEventHandlers = {
|
|
235
|
-
[K in SystemEventName]?: (
|
|
180
|
+
[K in SystemEventName]?: (ctx: any, args: any) => Promise<unknown>;
|
|
236
181
|
};
|
|
237
182
|
/** The company function that receives webhooks: `received` of `webhook.ts` at the repository root. */
|
|
238
183
|
export declare const WEBHOOK_RECEIVED_FUNCTION = "webhook.received";
|
|
@@ -241,7 +186,7 @@ export declare const WEBHOOK_RECEIVED_FUNCTION = "webhook.received";
|
|
|
241
186
|
* `event.webhook.name`. It runs with no sequence; to hand a request to one, start an instance or call
|
|
242
187
|
* its code through the platform API. Return accepted / rejected explicitly; throw to be retried.
|
|
243
188
|
*/
|
|
244
|
-
export type WebhookHandler<D extends PageTablesDesc | undefined = undefined> = (ctx:
|
|
189
|
+
export type WebhookHandler<D extends PageTablesDesc | undefined = undefined> = (ctx: Ctx<D>, args: {
|
|
245
190
|
event: WebhookEvent;
|
|
246
|
-
}
|
|
191
|
+
}) => Promise<WebhookOutcome>;
|
|
247
192
|
//# sourceMappingURL=events.d.ts.map
|
|
@@ -4,29 +4,20 @@ export const webhookOutcome = z.discriminatedUnion('status', [
|
|
|
4
4
|
z.object({ status: z.literal('accepted') }),
|
|
5
5
|
z.object({ status: z.literal('rejected'), reason: z.string() }),
|
|
6
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
|
-
*/
|
|
7
|
+
/** Runtime table mirroring {@link SystemEventMap}: the events a handler may be written for. */
|
|
11
8
|
export const SYSTEM_EVENTS = {
|
|
12
|
-
'call.inbound':
|
|
13
|
-
'call.outbound':
|
|
14
|
-
'call.ended':
|
|
15
|
-
'sms.received':
|
|
16
|
-
'sms.send-requested':
|
|
17
|
-
'email.received':
|
|
18
|
-
'email.send-requested':
|
|
19
|
-
'conversation.handoff': { case: true },
|
|
20
|
-
'sequence.next': { case: true },
|
|
9
|
+
'call.inbound': true,
|
|
10
|
+
'call.outbound': true,
|
|
11
|
+
'call.ended': true,
|
|
12
|
+
'sms.received': true,
|
|
13
|
+
'sms.send-requested': true,
|
|
14
|
+
'email.received': true,
|
|
15
|
+
'email.send-requested': true,
|
|
21
16
|
};
|
|
22
17
|
export const SYSTEM_EVENT_NAMES = Object.keys(SYSTEM_EVENTS);
|
|
23
18
|
export function isSystemEventName(value) {
|
|
24
19
|
return Object.hasOwn(SYSTEM_EVENTS, value);
|
|
25
20
|
}
|
|
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
21
|
/** The company function that receives webhooks: `received` of `webhook.ts` at the repository root. */
|
|
31
22
|
export const WEBHOOK_RECEIVED_FUNCTION = 'webhook.received';
|
|
32
23
|
//# sourceMappingURL=events.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { PageTablesDesc } from '../page/typed.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Ctx } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Recurring jobs (25 §6.4): `schedules.ts` at the repository root
|
|
5
|
-
*
|
|
4
|
+
* Recurring jobs (25 §6.4): `schedules.ts` at the repository root, next to `webhook.ts`; the
|
|
5
|
+
* company's only (a sequence has none). Each runs on its cron in every environment
|
|
6
6
|
* whose live release has it, with no case and no contact; `ctx.api` is the webhook handler's
|
|
7
7
|
* (`db`, `integration`, `instances.start`, `instances.notify`, `log`, `kv`).
|
|
8
8
|
*/
|
|
9
|
-
/** What `
|
|
9
|
+
/** What a job's `run` is told (`args.schedule`): which job, and the tick it runs for. */
|
|
10
10
|
export type ScheduleTick = {
|
|
11
11
|
/** The job's key in `defineSchedules({ … })`. */
|
|
12
12
|
name: string;
|
|
@@ -15,16 +15,15 @@ export type ScheduleTick = {
|
|
|
15
15
|
/** The tick this run is for (ISO). A run made up after the worker was down has the missed tick's time. */
|
|
16
16
|
scheduledAt: string;
|
|
17
17
|
};
|
|
18
|
-
export type ScheduleCtx<D extends PageTablesDesc | undefined = undefined> = FunctionCtx<{
|
|
19
|
-
schedule: ScheduleTick;
|
|
20
|
-
}, D>;
|
|
21
18
|
export type ScheduleDefinition<D extends PageTablesDesc | undefined = undefined> = {
|
|
22
19
|
/** Five fields: minute hour day-of-month month day-of-week (`'0 2 * * *'`: every day at 02:00). */
|
|
23
20
|
cron: string;
|
|
24
21
|
/** IANA name the cron is read in (`'UTC'`, `'America/Phoenix'`). */
|
|
25
22
|
timezone: string;
|
|
26
23
|
/** Throw to have the run recorded as failed; it is not retried, the next tick runs as usual. */
|
|
27
|
-
run: (ctx:
|
|
24
|
+
run: (ctx: Ctx<D>, args: {
|
|
25
|
+
schedule: ScheduleTick;
|
|
26
|
+
}) => Promise<void>;
|
|
28
27
|
};
|
|
29
28
|
/** The `schedules` export: job name → definition. */
|
|
30
29
|
export type Schedules<D extends PageTablesDesc | undefined = undefined> = Record<string, ScheduleDefinition<D>>;
|
|
@@ -33,12 +32,12 @@ export type Schedules<D extends PageTablesDesc | undefined = undefined> = Record
|
|
|
33
32
|
*
|
|
34
33
|
* ```ts
|
|
35
34
|
* export const schedules = defineSchedules({
|
|
36
|
-
* nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx) => { … } },
|
|
35
|
+
* nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx, { schedule }) => { … } },
|
|
37
36
|
* });
|
|
38
37
|
* ```
|
|
39
38
|
*/
|
|
40
39
|
export declare function defineSchedules<D extends PageTablesDesc | undefined = undefined>(schedules: Schedules<D>): Schedules<D>;
|
|
41
|
-
/** The module
|
|
40
|
+
/** The module the repository root defines its jobs in. */
|
|
42
41
|
export declare const SCHEDULES_MODULE = "schedules";
|
|
43
42
|
/** A job's name in the build's function registry: `schedule.<name>` (a `noCase` function). */
|
|
44
43
|
export declare const SCHEDULE_FUNCTION_PREFIX = "schedule.";
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ```ts
|
|
5
5
|
* export const schedules = defineSchedules({
|
|
6
|
-
* nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx) => { … } },
|
|
6
|
+
* nightlySync: { cron: '0 2 * * *', timezone: 'UTC', run: async (ctx, { schedule }) => { … } },
|
|
7
7
|
* });
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
10
|
export function defineSchedules(schedules) {
|
|
11
11
|
return schedules;
|
|
12
12
|
}
|
|
13
|
-
/** The module
|
|
13
|
+
/** The module the repository root defines its jobs in. */
|
|
14
14
|
export const SCHEDULES_MODULE = 'schedules';
|
|
15
15
|
/** A job's name in the build's function registry: `schedule.<name>` (a `noCase` function). */
|
|
16
16
|
export const SCHEDULE_FUNCTION_PREFIX = 'schedule.';
|
|
@@ -1,89 +1,34 @@
|
|
|
1
|
-
import type { CaseOrchestrator } from '../case-orchestrator/types.js';
|
|
2
1
|
import type { SystemContext } from '../context/types.js';
|
|
3
|
-
import type { CaseInput } from '../case-orchestrator/types.js';
|
|
4
2
|
import type { Db } from '../page/define.js';
|
|
5
3
|
import type { PageTablesDesc, TypedDb } from '../page/typed.js';
|
|
6
|
-
export type FuncOptions = {
|
|
7
|
-
args?: Record<string, unknown>;
|
|
8
|
-
description?: string;
|
|
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
4
|
/**
|
|
30
|
-
* `ctx` of every function
|
|
31
|
-
* (15 §10.15 task 4): any row of the
|
|
5
|
+
* `ctx` of every function and entry (38 §2.3): what it is called with besides its `args`. `ctx.api.db`
|
|
6
|
+
* reads and writes records like a page script and its actions (15 §10.15 task 4): any row of the
|
|
7
|
+
* company and environment, each write its own transaction. `D` (the company's `PageTables`, bound by
|
|
8
|
+
* `__gen`) types them.
|
|
32
9
|
*/
|
|
33
|
-
export type
|
|
10
|
+
export type Ctx<D extends PageTablesDesc | undefined = undefined> = Omit<SystemContext, 'api' | 'meta'> & {
|
|
11
|
+
/** What runs, where (38 §2.3): the instance a function works on is in its `args`, not here. */
|
|
12
|
+
meta: Omit<SystemContext['meta'], 'instanceId'>;
|
|
34
13
|
api: Omit<SystemContext['api'], 'db'> & {
|
|
35
14
|
db: D extends PageTablesDesc ? TypedDb<D> : Db;
|
|
36
15
|
};
|
|
37
|
-
params: Params;
|
|
38
16
|
};
|
|
39
17
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
18
|
+
* A function as the company writes it (38 §2.1): `(ctx, args)`, `args` one object (`{}` when it takes
|
|
19
|
+
* none). Every entry the platform calls (functions, event handlers, `resolve`, the webhook, a schedule's
|
|
20
|
+
* `run`, the Orchestrator) is one; the platform tells its entries apart by name.
|
|
42
21
|
*/
|
|
43
|
-
export type
|
|
44
|
-
/**
|
|
45
|
-
export type
|
|
46
|
-
type FuncMeta = {
|
|
47
|
-
description?: string;
|
|
48
|
-
args?: Record<string, unknown>;
|
|
49
|
-
};
|
|
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
|
-
};
|
|
22
|
+
export type PlainFn = (ctx: any, args: any) => Promise<unknown>;
|
|
23
|
+
/** Author map: key is the function name. */
|
|
24
|
+
export type FuncMap = Record<string, PlainFn>;
|
|
63
25
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
26
|
+
* Compiled function registry entry (JSON-safe). Same shape for `functions` and `events`. `code` is the
|
|
27
|
+
* standalone JS function expression (esbuild-normalized): present on published builds, omitted on the
|
|
28
|
+
* local serve overlay (`includeCode: false`).
|
|
66
29
|
*/
|
|
67
|
-
export type
|
|
68
|
-
/** Author map: key is the function name. */
|
|
69
|
-
export type FuncMap = Record<string, DefinedFunc>;
|
|
70
|
-
/** Map entry with name stamped from the key (for platform loaders). */
|
|
71
|
-
export type FuncRegistration = DefinedFunc & {
|
|
72
|
-
name: string;
|
|
73
|
-
};
|
|
74
|
-
type RegistryCode = {
|
|
75
|
-
/**
|
|
76
|
-
* Standalone JS function expression (esbuild-normalized).
|
|
77
|
-
* Present on published builds; omitted on local serve overlay (`includeCode: false`).
|
|
78
|
-
*/
|
|
30
|
+
export type FunctionRegistryEntry = {
|
|
79
31
|
code?: string;
|
|
80
32
|
};
|
|
81
|
-
/** Compiled function registry entry (JSON-safe). Same shape for `functions` and `events`. */
|
|
82
|
-
export type FunctionRegistryEntry = RegistryCode & {
|
|
83
|
-
kind: FunctionKind;
|
|
84
|
-
};
|
|
85
33
|
export type FunctionRegistry = Record<string, FunctionRegistryEntry>;
|
|
86
|
-
/** Plain-object FuncMap → array with `name` stamped (platform-side loaders). */
|
|
87
|
-
export declare function toFuncRegistrations(functions: FuncMap): FuncRegistration[];
|
|
88
|
-
export {};
|
|
89
34
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
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). */
|
|
7
|
-
export function toFuncRegistrations(functions) {
|
|
8
|
-
return Object.entries(functions).map(([name, def]) => ({ ...def, name }));
|
|
9
|
-
}
|
|
1
|
+
export {};
|
|
10
2
|
//# sourceMappingURL=types.js.map
|