@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
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { createTRPCClient, httpLink } from '@trpc/client';
|
|
1
|
+
import { createTRPCClient, httpLink, retryLink } from '@trpc/client';
|
|
2
2
|
import { platformSurfaces } from '../../core/context/platform-registry.js';
|
|
3
|
-
import { defaultHttpApi } from '../../core/context/http.js';
|
|
4
3
|
import { integrationSurfaceKeys, } from '../../core/context/types.js';
|
|
5
4
|
import { bindEnvService } from '../../core/context/env.js';
|
|
6
|
-
import {
|
|
5
|
+
import { CASE_ORCHESTRATOR_TOOL_NAMES, } from '../../core/case-orchestrator/types.js';
|
|
6
|
+
import { getLogger } from '../../logger.js';
|
|
7
|
+
import { REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, formatRuntimeVersion } from './request-id.js';
|
|
8
|
+
const logger = getLogger(['runtime', 'rpc']);
|
|
9
|
+
/**
|
|
10
|
+
* A call the platform turned away before doing anything (its company over the rate, or no free slot:
|
|
11
|
+
* `TOO_MANY_REQUESTS`) is sent again after a growing pause, long enough together to outlast a rate window.
|
|
12
|
+
*/
|
|
13
|
+
const BUSY_RETRIES = 5;
|
|
14
|
+
const busyDelayMs = (attempt) => Math.min(500 * 2 ** attempt, 5_000) + Math.floor(Math.random() * 250);
|
|
7
15
|
function rpcLogger(c, getTags, waitUntil) {
|
|
8
16
|
const emit = (level, message, extra) => {
|
|
9
17
|
const pending = c.log.emit.mutate({ level, message, extra, tags: getTags?.() }).catch(() => { });
|
|
@@ -48,6 +56,13 @@ function stubSurface(c, meta) {
|
|
|
48
56
|
if (meta.surfaceKey === 'envs') {
|
|
49
57
|
return bindEnvService(stub);
|
|
50
58
|
}
|
|
59
|
+
if (meta.surfaceKey === 'emails') {
|
|
60
|
+
return {
|
|
61
|
+
...stub,
|
|
62
|
+
address: typeof meta.config.address === 'string' ? meta.config.address : meta.name,
|
|
63
|
+
provider: meta.config.provider === 'hotmail' ? 'hotmail' : 'gmail',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
51
66
|
return stub;
|
|
52
67
|
}
|
|
53
68
|
function buildSurfaces(c, metas) {
|
|
@@ -74,6 +89,56 @@ function buildPlatformApis(c) {
|
|
|
74
89
|
// The registry is what guarantees the shape; TS cannot follow it through Object.fromEntries.
|
|
75
90
|
return Object.fromEntries(surfaces);
|
|
76
91
|
}
|
|
92
|
+
/** Every Case Orchestrator tool routes through one procedure; the platform validates and executes it. */
|
|
93
|
+
function buildCaseOrchestratorTools(c) {
|
|
94
|
+
const tools = CASE_ORCHESTRATOR_TOOL_NAMES.map((tool) => [
|
|
95
|
+
tool,
|
|
96
|
+
(input, callOptions) => rpcSafe(c.caseOrchestratorTools.invoke.mutate({ tool, input, callKey: callOptions.callKey })),
|
|
97
|
+
]);
|
|
98
|
+
// The tool registry guarantees the shape; TS cannot follow it through Object.fromEntries.
|
|
99
|
+
return Object.fromEntries(tools);
|
|
100
|
+
}
|
|
101
|
+
/** A records answer: its value, or the error it was refused with (a write's with its code). */
|
|
102
|
+
function unwrapRecords(result) {
|
|
103
|
+
if (result.ok)
|
|
104
|
+
return result.value;
|
|
105
|
+
const error = new Error(result.error.message);
|
|
106
|
+
error.code = result.error.code;
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* `ctx.api.db` of every function and the Orchestrator (15 §10.15 task 4, §10.16): every table, as a
|
|
111
|
+
* page script and its actions see them, one request per call. Writes are numbered in the order this
|
|
112
|
+
* run makes them; for an Orchestrator Run the same request sent again (a retried request) carries the
|
|
113
|
+
* same key and is not made twice.
|
|
114
|
+
*/
|
|
115
|
+
function buildDbApi(c) {
|
|
116
|
+
let writes = 0;
|
|
117
|
+
const db = new Proxy({}, {
|
|
118
|
+
get(_, table) {
|
|
119
|
+
if (typeof table !== 'string')
|
|
120
|
+
return undefined;
|
|
121
|
+
const read = (method) => async (args) => unwrapRecords(await rpcSafe(c.records.read.mutate({ table, method, args: args ?? {} })));
|
|
122
|
+
const write = (method) => async (args) => {
|
|
123
|
+
writes += 1;
|
|
124
|
+
const callKey = `write:${writes}`;
|
|
125
|
+
return unwrapRecords(await rpcSafe(c.records.write.mutate({ table, method, args: args ?? {}, callKey })));
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
$table: table,
|
|
129
|
+
findUnique: read('findUnique'),
|
|
130
|
+
findFirst: read('findFirst'),
|
|
131
|
+
findMany: read('findMany'),
|
|
132
|
+
count: read('count'),
|
|
133
|
+
create: write('create'),
|
|
134
|
+
update: write('update'),
|
|
135
|
+
upsert: write('upsert'),
|
|
136
|
+
delete: write('delete'),
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
return { db };
|
|
141
|
+
}
|
|
77
142
|
export function createRpcApiHost(options) {
|
|
78
143
|
let client;
|
|
79
144
|
let lastBaseUrl;
|
|
@@ -81,6 +146,10 @@ export function createRpcApiHost(options) {
|
|
|
81
146
|
if (!client || lastBaseUrl !== baseUrl) {
|
|
82
147
|
client = createTRPCClient({
|
|
83
148
|
links: [
|
|
149
|
+
retryLink({
|
|
150
|
+
retry: ({ error, attempts }) => error.data?.code === 'TOO_MANY_REQUESTS' && attempts <= BUSY_RETRIES,
|
|
151
|
+
retryDelayMs: busyDelayMs,
|
|
152
|
+
}),
|
|
84
153
|
httpLink({
|
|
85
154
|
url: baseUrl,
|
|
86
155
|
headers: async () => {
|
|
@@ -104,14 +173,26 @@ export function createRpcApiHost(options) {
|
|
|
104
173
|
async buildApi(_run) {
|
|
105
174
|
const c = getClient(options.baseUrl);
|
|
106
175
|
const started = Date.now();
|
|
107
|
-
|
|
108
|
-
const metas = await rpcSafe(c.integration.
|
|
109
|
-
|
|
176
|
+
logger.info('integration.listSurfaces start', { url: options.baseUrl });
|
|
177
|
+
const metas = await rpcSafe(c.integration.listSurfaces.query());
|
|
178
|
+
logger.info('integration.listSurfaces ok', { durationMs: Date.now() - started, count: metas.length });
|
|
179
|
+
return {
|
|
180
|
+
...buildPlatformApis(c),
|
|
181
|
+
integration: buildSurfaces(c, metas),
|
|
182
|
+
log: rpcLogger(c, options.getTags, options.waitUntil),
|
|
183
|
+
...buildDbApi(c),
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
async buildCaseOrchestratorApi(_run) {
|
|
187
|
+
const c = getClient(options.baseUrl);
|
|
188
|
+
// A function's api (25 §7), so a function called from the Orchestrator with its ctx works the same.
|
|
189
|
+
const metas = await rpcSafe(c.integration.listSurfaces.query());
|
|
110
190
|
return {
|
|
111
191
|
...buildPlatformApis(c),
|
|
112
192
|
integration: buildSurfaces(c, metas),
|
|
113
193
|
log: rpcLogger(c, options.getTags, options.waitUntil),
|
|
114
|
-
|
|
194
|
+
tools: buildCaseOrchestratorTools(c),
|
|
195
|
+
...buildDbApi(c),
|
|
115
196
|
};
|
|
116
197
|
},
|
|
117
198
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { createIntegrationRouter } from './integration/index.js';
|
|
2
2
|
import { createLogRouter } from './log.js';
|
|
3
3
|
import { createPlatformRouter } from './platform.js';
|
|
4
|
+
import { createRecordsRouter } from './records.js';
|
|
5
|
+
import { createCaseOrchestratorToolsRouter } from './case-orchestrator-tools.js';
|
|
4
6
|
export declare function createAppRouter(modules: {
|
|
5
7
|
integration: ReturnType<typeof createIntegrationRouter>;
|
|
6
8
|
platform: ReturnType<typeof createPlatformRouter>;
|
|
7
9
|
log: ReturnType<typeof createLogRouter>;
|
|
10
|
+
caseOrchestratorTools: ReturnType<typeof createCaseOrchestratorToolsRouter>;
|
|
11
|
+
records: ReturnType<typeof createRecordsRouter>;
|
|
8
12
|
}): import("@trpc/server").TRPCBuiltRouter<{
|
|
9
13
|
ctx: import("./trpc-init.js").RpcContext;
|
|
10
14
|
meta: object;
|
|
@@ -17,10 +21,10 @@ export declare function createAppRouter(modules: {
|
|
|
17
21
|
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
18
22
|
transformer: false;
|
|
19
23
|
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
20
|
-
|
|
24
|
+
listSurfaces: import("@trpc/server").TRPCQueryProcedure<{
|
|
21
25
|
input: void;
|
|
22
26
|
output: {
|
|
23
|
-
surfaceKey: "
|
|
27
|
+
surfaceKey: "emails" | "envs";
|
|
24
28
|
target: {
|
|
25
29
|
kind: "account" | "resource";
|
|
26
30
|
id: string;
|
|
@@ -55,7 +59,7 @@ export declare function createAppRouter(modules: {
|
|
|
55
59
|
input: {
|
|
56
60
|
surface: string;
|
|
57
61
|
method: string;
|
|
58
|
-
params?:
|
|
62
|
+
params?: unknown;
|
|
59
63
|
};
|
|
60
64
|
output: unknown;
|
|
61
65
|
meta: object;
|
|
@@ -80,6 +84,48 @@ export declare function createAppRouter(modules: {
|
|
|
80
84
|
meta: object;
|
|
81
85
|
}>;
|
|
82
86
|
}>>;
|
|
87
|
+
caseOrchestratorTools: import("@trpc/server").TRPCBuiltRouter<{
|
|
88
|
+
ctx: import("./trpc-init.js").RpcContext;
|
|
89
|
+
meta: object;
|
|
90
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
91
|
+
transformer: false;
|
|
92
|
+
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
93
|
+
invoke: import("@trpc/server").TRPCMutationProcedure<{
|
|
94
|
+
input: {
|
|
95
|
+
tool: string;
|
|
96
|
+
input: unknown;
|
|
97
|
+
callKey: string;
|
|
98
|
+
};
|
|
99
|
+
output: unknown;
|
|
100
|
+
meta: object;
|
|
101
|
+
}>;
|
|
102
|
+
}>>;
|
|
103
|
+
records: import("@trpc/server").TRPCBuiltRouter<{
|
|
104
|
+
ctx: import("./trpc-init.js").RpcContext;
|
|
105
|
+
meta: object;
|
|
106
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
107
|
+
transformer: false;
|
|
108
|
+
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
109
|
+
read: import("@trpc/server").TRPCMutationProcedure<{
|
|
110
|
+
input: {
|
|
111
|
+
table: string;
|
|
112
|
+
method: "count" | "findFirst" | "findMany" | "findUnique";
|
|
113
|
+
args: unknown;
|
|
114
|
+
};
|
|
115
|
+
output: import("./records.js").RecordsResult;
|
|
116
|
+
meta: object;
|
|
117
|
+
}>;
|
|
118
|
+
write: import("@trpc/server").TRPCMutationProcedure<{
|
|
119
|
+
input: {
|
|
120
|
+
table: string;
|
|
121
|
+
method: "create" | "delete" | "update" | "upsert";
|
|
122
|
+
args: unknown;
|
|
123
|
+
callKey: string;
|
|
124
|
+
};
|
|
125
|
+
output: import("./records.js").RecordsResult;
|
|
126
|
+
meta: object;
|
|
127
|
+
}>;
|
|
128
|
+
}>>;
|
|
83
129
|
}>>;
|
|
84
130
|
export type AppRouter = ReturnType<typeof createAppRouter>;
|
|
85
131
|
//# sourceMappingURL=trpc-router-factory.d.ts.map
|
|
@@ -4,6 +4,8 @@ export function createAppRouter(modules) {
|
|
|
4
4
|
integration: modules.integration,
|
|
5
5
|
platform: modules.platform,
|
|
6
6
|
log: modules.log,
|
|
7
|
+
caseOrchestratorTools: modules.caseOrchestratorTools,
|
|
8
|
+
records: modules.records,
|
|
7
9
|
});
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=trpc-router-factory.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CaseOrchestratorRunScope, RunClaims } from './types.js';
|
|
2
|
+
/** The Case Orchestrator scope of a run, or null when it is not a complete Case Orchestrator run. */
|
|
3
|
+
export declare function asCaseOrchestratorRun(run: RunClaims): CaseOrchestratorRunScope | null;
|
|
4
|
+
//# sourceMappingURL=run-scope.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ORCHESTRATOR_ENTRY } from '../core/case-orchestrator/types.js';
|
|
2
|
+
/** The Case Orchestrator scope of a run, or null when it is not a complete Case Orchestrator run. */
|
|
3
|
+
export function asCaseOrchestratorRun(run) {
|
|
4
|
+
const scoped = run;
|
|
5
|
+
if (run.entry !== ORCHESTRATOR_ENTRY || !scoped.instanceId || !scoped.agentRunId)
|
|
6
|
+
return null;
|
|
7
|
+
return run;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=run-scope.js.map
|
|
@@ -1,17 +1,50 @@
|
|
|
1
|
+
import type { ORCHESTRATOR_ENTRY, CaseOrchestratorApi, CaseOrchestratorContext } from '../core/case-orchestrator/types.js';
|
|
1
2
|
import type { SystemContext } from '../core/context/types.js';
|
|
2
3
|
/** Alias for {@link SystemContext} (08 ActionContext shape). */
|
|
3
4
|
export type ActionContext = SystemContext;
|
|
4
|
-
/**
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* JSON-serializable data slice of ActionContext (no `api`, no `time.format` / `time.day`: added where the
|
|
7
|
+
* function runs). Its ids are plain strings on the wire; the function's `ctx.meta` types them.
|
|
8
|
+
*/
|
|
9
|
+
export type ActionDataSlice = Pick<ActionContext, 'config'> & {
|
|
10
|
+
time: Omit<ActionContext['time'], 'format' | 'day'>;
|
|
11
|
+
meta: ActionContext['meta'];
|
|
12
|
+
};
|
|
6
13
|
/** Identity / scope for a single function invocation (ApiHost may key caches on this). */
|
|
7
14
|
export type RunScope = {
|
|
8
15
|
companyId: string;
|
|
9
16
|
environmentId: string;
|
|
10
|
-
sequenceId: string;
|
|
11
17
|
entry: string;
|
|
18
|
+
/** The instance a case-bound run works on; absent on nocase runs. */
|
|
19
|
+
instanceId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The AI run (`AgentRun`) that called the function, with `instanceId` the case it is on (21 §6.5): what
|
|
22
|
+
* the function writes back through the platform is that run's. Set by the platform only.
|
|
23
|
+
*/
|
|
24
|
+
agentRunId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The published company build (`ReleaseBuildBatch`) the run started on: one run uses one build (22 §5),
|
|
27
|
+
* so `ctx.api` reads the schema from it, not from whatever release is live by then. Absent on the serve
|
|
28
|
+
* overlay, which is not pinned. Set by the platform only.
|
|
29
|
+
*/
|
|
30
|
+
buildId?: string;
|
|
12
31
|
};
|
|
13
32
|
/** Who fulfills `ctx.api` (Fake local vs Rpc remote). */
|
|
14
33
|
export type ApiHost = {
|
|
15
34
|
buildApi(run: RunScope): Promise<ActionContext['api']>;
|
|
16
35
|
};
|
|
36
|
+
/** `ctx` of `orchestrator` before the host adds `params`. */
|
|
37
|
+
export type CaseOrchestratorActionContext = Omit<CaseOrchestratorContext, 'params'>;
|
|
38
|
+
/** Who fulfills the Case Orchestrator's `ctx.api` (Fake local vs Rpc remote). */
|
|
39
|
+
export type CaseOrchestratorApiHost = {
|
|
40
|
+
buildCaseOrchestratorApi(run: RunScope): Promise<CaseOrchestratorApi>;
|
|
41
|
+
};
|
|
42
|
+
/** Run scope of an Orchestrator call: the instance it is limited to and its active run (`AgentRun`). */
|
|
43
|
+
export type CaseOrchestratorRunScope = RunScope & {
|
|
44
|
+
entry: typeof ORCHESTRATOR_ENTRY;
|
|
45
|
+
instanceId: string;
|
|
46
|
+
agentRunId: string;
|
|
47
|
+
};
|
|
48
|
+
/** A verified run token's scope; narrow with {@link asCaseOrchestratorRun}. */
|
|
49
|
+
export type RunClaims = RunScope | CaseOrchestratorRunScope;
|
|
17
50
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export type {
|
|
20
|
-
export type {
|
|
21
|
-
export {
|
|
22
|
-
export type {
|
|
23
|
-
export
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export type {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
export {
|
|
37
|
-
export
|
|
38
|
-
export { defineCustomFunc } from './core/functions/define/custom.js';
|
|
39
|
-
export { defineSystemFunc } from './core/functions/define/system.js';
|
|
40
|
-
export { mergeEffectiveSchema } from './builder/merge.js';
|
|
41
|
-
export { emitCaseContextSource, emitSlotsSource } from './builder/codegen/emit.js';
|
|
42
|
-
export { affectedDerivedFields, applyFieldPatch, applyFieldPatchAndRecompute, applySlotFilling, applySlotFillingAndRecompute, applyWrites, applyWritesAndRecompute, buildDependencyGraph, buildFieldCatalog, buildSlotFillingJsonSchema, cloneSnapshot, commitFieldWrite, compiledTableEntries, compileSlotSchema, emptyFieldValue, emptyMultiRow, emptySlotRow, fieldChanged, formatFieldPath, getCompiledTable, getFieldState, getFieldValue, getLastThreeValues, getRowField, getSingleField, getSnapshotTable, isFieldValue, isReservedTableName, isResolved, isRowIdField, mintRowId, SNAPSHOT_CURRENT_KEY, isSnapshotSingleRow, isValidDataTypeValue, listConversationFields, makeFieldValue, markAskedUnknown, isRowWrite, isStructuredWrites, normalizeWrites, parseFieldPath, recomputeDerived, requireFieldPath, rowValueEntries, slotFieldEntries, slotFieldNames, snapshotFrom, toEffectiveSchema, toHistoryEntry, validateBareValue, validateExtractedField, validateFieldRefs, validateSlotFillingOutput, } from './core/slot/index.js';
|
|
43
|
-
export type { ApplySlotFillingOptions, DependencyGraphResult, FieldPatchInput, FieldPath, ParsedFieldPath, RecomputeOptions, SfSchemaOptions, SlotRow, SnapshotSeed, ValidateSlotFillingOptions, } from './core/slot/index.js';
|
|
44
|
-
export type { ActionBlock, ActionNode, AgendaBlock, AgendaConfig, AgendaHeader, AgendaTree, ApplyWhen, AuthoringNode, AuthoringWhen, BranchNode, Channel, CompiledActionBlock, CompiledAgenda, CompiledAgendaBlock, CompiledTopicBlock, CompiledIvrBlock, CompiledTransferBlock, CompiledWhen, Condition, ConditionEval, FirstMessage, FinishWhen, FinishWhenEval, FlatActionItem, FlatAgendaItem, FlatIvrItem, FlatNodePlacement, FlatTopicItem, FlatTransferItem, DtmfResult, IvrAttemptResult, IvrBlock, IvrDigit, IvrFallbackAction, IvrNode, FlattenOptions, FlattenResult, Interrupt, SpokenLanguage, SequenceAgendas, JsonRulesCondition, NodePlacement, OnNoProgress, OtherwiseSentinel, Placement, SectionNode, SectionPlacement, SimulateResult, SimulatedItem, SimulatedItemStatus, SwitchOnNode, TopicBlock, TopicNode, TransferArguments, TransferBlock, TransferCallerIdShown, TransferConfirmKey, TransferConfirmMethod, TransferDial, TransferFallbackAction, TransferInterruptAction, TransferMode, TransferNode, TransferSay, ValidateAgendaOptions, WalkDecision, WalkHitReason, WalkOptions, WalkResult, WalkSkip, WalkStats, WalkSkipReason, When, WhenEval, AdvanceResult, StageDriveHooks, StageDriveResult, StageDriveState, } from './core/stage/index.js';
|
|
45
|
-
export { DEFAULT_MAX_ACTIONS_PER_TURN, CASE_LAST_TRANSFER_AT, CASE_LAST_TRANSFER_RESULT, CASE_TRANSFER_ATTEMPT_COUNT, E164_NUMBER, LAST_TRANSFER_RESULT_FIELD, CONTACT_LANGUAGE_FIELD, getContactLang, inboundIvrCollect, ivrAttempted, ivrOf, ivrResultField, languageFieldOf, RESERVED_INTERRUPT_TOOL_NAMES, SIP_URI, action, advanceAgenda, agenda, andCompiledWhen, branch, collectJsonRulesFacts, collectTransferBlocks, collectTransferInterruptHeaders, compileAuthoringWhen, compileFinishWhen, compileWhen, driveAgenda, evaluateFinishWhen, evaluateJsonRules, evaluateWhen, extractBlocksFromTree, extractTemplateFields, finishWhenFields, flattenAgendaConfig, flattenAgendaPlacements, flattenAgendaTree, headerHasTransferInterrupt, ivr, interpolateFromSnapshot, interpolateTemplate, isTransferDestinationLiteral, isAgendaTree, isSequenceAgendas, isOtherwise, isSpokenLanguage, jsonRules, looksLikeJsonRules, normalizeJsonRules, normalizeSequenceAgendas, notAnyWhen, otherwise, parseJsonRules, registerIvrSessionFields, collectIvrBlocks, registerTransferSessionFields, resolveTransferArguments, resolveTransferDestinations, resolveTransferSay, section, simulateAgenda, switchOn, topic, transfer, transferArgumentsJson, transferFieldKey, transferResultField, transferWrites, validateTransferDestinations, treeToPlacements, unresolvedFinishWhenFields, validateCompiledAgenda, validateInterrupts, walkAgenda, watchdogHint, whenFields, } from './core/stage/index.js';
|
|
46
|
-
export * from './voice-service/index.js';
|
|
1
|
+
/**
|
|
2
|
+
* The company API: everything company code may import from `@superpanel-sdk/runtime`, and nothing else
|
|
3
|
+
* (09-runtime-compat §6). Company code runs in three places: the compile's Node, the Worker, and the
|
|
4
|
+
* page's QuickJS sandbox. So what is here behaves the same in all three: it imports no package and no
|
|
5
|
+
* Node module, and no module it reaches does work at load. The compile bundles it into each code string
|
|
6
|
+
* as it is; there is no stand-in.
|
|
7
|
+
*
|
|
8
|
+
* Named exports only, from the module that defines each: an `export *` lets whatever a module adds
|
|
9
|
+
* reach company code. `company-api.test.ts` holds the list and checks the entry stays pure. The
|
|
10
|
+
* platform imports `./platform` (`platform.ts`), which this package resolves only under the
|
|
11
|
+
* `superpanel-platform` condition.
|
|
12
|
+
*/
|
|
13
|
+
export { defineSequence, defineVariables, json, type JsonVariableType, type SequenceDefinition, type VariableDecl, type VariableDecls, type VariablesOf, } from './core/sequence/define.js';
|
|
14
|
+
export { defineCaseFunc } from './core/functions/define/case.js';
|
|
15
|
+
export { defineNoCaseFunc } from './core/functions/define/no-case.js';
|
|
16
|
+
export { bindDefines, type BoundDefines } from './core/functions/define/bind.js';
|
|
17
|
+
export { defineEvents, defineWebhook } from './core/functions/define/events.js';
|
|
18
|
+
export { defineSchedules, type Schedules } from './core/functions/schedules.js';
|
|
19
|
+
export type { FunctionCtx } from './core/functions/types.js';
|
|
20
|
+
export type { WebhookHandler } from './core/functions/events.js';
|
|
21
|
+
export { choose, createRow, defineAction, definePage, deleteRow, end, field, refField, lastActionRun, perform, runFunction, schemaField, tried, type PageChannel, type PageFaqEntry, type PageRuns, } from './core/page/define.js';
|
|
22
|
+
export type { Id, RowOf, TypedDb, TypedPageContext, TypedPageModule, TypedReadDb, } from './core/page/typed.js';
|
|
23
|
+
export { followUps } from './core/case-orchestrator/follow-ups.js';
|
|
24
|
+
export { render } from './core/case-orchestrator/render.js';
|
|
25
|
+
export { tools } from './core/case-orchestrator/tools.js';
|
|
26
|
+
export type { CaseActivity, CaseInput, CaseOrchestrator, CaseOrchestratorContacts, ContactActionView, RunTrigger, ScheduledActionView, } from './core/case-orchestrator/types.js';
|
|
27
|
+
export type { CompanyResolve, Resolve } from './core/party/types.js';
|
|
28
|
+
export { contactScheduleHours, everyDay, nextContactTime, withinContactHours, type ContactHours, type ContactHoursRange, type ContactHoursWeekday, } from './core/case-orchestrator/contact-hours.js';
|
|
29
|
+
export { randomTimeBetween } from './core/case-orchestrator/time.js';
|
|
30
|
+
export { contactTimezone } from './core/slot/contact-timezone.js';
|
|
31
|
+
export type { OfficeHours } from './core/office-hours/index.js';
|
|
32
|
+
export { PLATFORM_CONTACT_FIELDS, PLATFORM_SESSION_FIELDS } from './core/slot/platform-fields.js';
|
|
33
|
+
export { lookupRef, parentRef } from './core/slot/id-ref.js';
|
|
34
|
+
export type { CompanySchema, ContactSchedule, SessionSchema } from './core/slot/schema.js';
|
|
35
|
+
export type { CellBinding, RowRef } from './core/slot/binding.js';
|
|
36
|
+
export type { FieldValue } from './core/slot/types.js';
|
|
37
|
+
export type { EnvApi } from './core/context/env.js';
|
|
47
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* The company API: everything company code may import from `@superpanel-sdk/runtime`, and nothing else
|
|
3
|
+
* (09-runtime-compat §6). Company code runs in three places: the compile's Node, the Worker, and the
|
|
4
|
+
* page's QuickJS sandbox. So what is here behaves the same in all three: it imports no package and no
|
|
5
|
+
* Node module, and no module it reaches does work at load. The compile bundles it into each code string
|
|
6
|
+
* as it is; there is no stand-in.
|
|
7
|
+
*
|
|
8
|
+
* Named exports only, from the module that defines each: an `export *` lets whatever a module adds
|
|
9
|
+
* reach company code. `company-api.test.ts` holds the list and checks the entry stays pure. The
|
|
10
|
+
* platform imports `./platform` (`platform.ts`), which this package resolves only under the
|
|
11
|
+
* `superpanel-platform` condition.
|
|
12
|
+
*/
|
|
13
|
+
// Sequence declarations: `index.ts`, `variables.ts`.
|
|
14
|
+
export { defineSequence, defineVariables, json, } from './core/sequence/define.js';
|
|
15
|
+
// Functions, events, the webhook and schedules (the sequence's `__gen` binds them to its tables).
|
|
16
|
+
export { defineCaseFunc } from './core/functions/define/case.js';
|
|
17
|
+
export { defineNoCaseFunc } from './core/functions/define/no-case.js';
|
|
18
|
+
export { bindDefines } from './core/functions/define/bind.js';
|
|
19
|
+
export { defineEvents, defineWebhook } from './core/functions/define/events.js';
|
|
20
|
+
export { defineSchedules } from './core/functions/schedules.js';
|
|
21
|
+
// The page (the sequence's `__gen` binds them to its tables).
|
|
22
|
+
export { choose, createRow, defineAction, definePage, deleteRow, end, field, refField, lastActionRun, perform, runFunction, schemaField, tried, } from './core/page/define.js';
|
|
23
|
+
// The Orchestrator.
|
|
24
|
+
export { followUps } from './core/case-orchestrator/follow-ups.js';
|
|
25
|
+
export { render } from './core/case-orchestrator/render.js';
|
|
26
|
+
export { tools } from './core/case-orchestrator/tools.js';
|
|
27
|
+
// When a contact may be reached, and in which time zone.
|
|
28
|
+
export { contactScheduleHours, everyDay, nextContactTime, withinContactHours, } from './core/case-orchestrator/contact-hours.js';
|
|
29
|
+
export { randomTimeBetween } from './core/case-orchestrator/time.js';
|
|
30
|
+
export { contactTimezone } from './core/slot/contact-timezone.js';
|
|
31
|
+
// The company schema: `schema/`.
|
|
32
|
+
export { PLATFORM_CONTACT_FIELDS, PLATFORM_SESSION_FIELDS } from './core/slot/platform-fields.js';
|
|
33
|
+
export { lookupRef, parentRef } from './core/slot/id-ref.js';
|
|
34
34
|
//# sourceMappingURL=index.js.map
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function formatArgument(value) {
|
|
2
|
+
if (value instanceof Error)
|
|
3
|
+
return value.stack ?? value.message;
|
|
4
|
+
if (typeof value === 'string')
|
|
5
|
+
return value;
|
|
6
|
+
if (typeof value !== 'object' || value === null)
|
|
7
|
+
return String(value);
|
|
8
|
+
try {
|
|
9
|
+
return JSON.stringify(value);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return '[unserializable]';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function write(level, tags, args) {
|
|
16
|
+
const label = tags.length > 0 ? `[${tags.join(',')}] ` : '';
|
|
17
|
+
const line = `${new Date().toISOString()} ${level.padEnd(5)} ${label}${args.map(formatArgument).join(' ')}`;
|
|
18
|
+
if (level === 'ERROR')
|
|
19
|
+
console.error(line);
|
|
20
|
+
else if (level === 'WARN')
|
|
21
|
+
console.warn(line);
|
|
22
|
+
else
|
|
23
|
+
console.info(line);
|
|
24
|
+
}
|
|
25
|
+
export function getLogger(tags = []) {
|
|
26
|
+
return {
|
|
27
|
+
log(...args) {
|
|
28
|
+
write('INFO', tags, args);
|
|
29
|
+
},
|
|
30
|
+
info(...args) {
|
|
31
|
+
write('INFO', tags, args);
|
|
32
|
+
},
|
|
33
|
+
warn(...args) {
|
|
34
|
+
write('WARN', tags, args);
|
|
35
|
+
},
|
|
36
|
+
error(...args) {
|
|
37
|
+
write('ERROR', tags, args);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=logger.js.map
|