@superpanel-sdk/runtime 0.2.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -10
- package/dist/builder/codegen/emit.d.ts +25 -12
- package/dist/builder/codegen/emit.js +339 -78
- package/dist/builder/codegen/generate.d.ts +21 -2
- package/dist/builder/codegen/generate.js +147 -34
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +29 -0
- package/dist/builder/company-imports.js +122 -0
- package/dist/builder/compile/compile-sequence.d.ts +61 -8
- package/dist/builder/compile/compile-sequence.js +334 -80
- package/dist/builder/compile/function-code.d.ts +19 -3
- package/dist/builder/compile/function-code.js +123 -45
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +30 -27
- package/dist/builder/errors.d.ts +9 -0
- package/dist/builder/errors.js +17 -0
- package/dist/builder/function-params.d.ts +10 -0
- package/dist/builder/function-params.js +203 -0
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +258 -67
- package/dist/builder/paths.d.ts +9 -1
- package/dist/builder/paths.js +32 -2
- package/dist/builder/schedules.d.ts +25 -0
- package/dist/builder/schedules.js +101 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +102 -0
- package/dist/builder/types.d.ts +127 -19
- package/dist/builder/types.js +21 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/calls/index.d.ts +177 -0
- package/dist/cli/calls/index.js +96 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/debug/index.d.ts +31 -0
- package/dist/cli/debug/index.js +119 -0
- package/dist/cli/exec/index.d.ts +39 -0
- package/dist/cli/exec/index.js +138 -0
- package/dist/cli/exec/session.d.ts +48 -0
- package/dist/cli/exec/session.js +82 -0
- package/dist/cli/exec/trace.d.ts +18 -0
- package/dist/cli/exec/trace.js +52 -0
- package/dist/cli/index.js +112 -9
- package/dist/cli/logs/index.d.ts +47 -0
- package/dist/cli/logs/index.js +113 -0
- package/dist/cli/mobile/index.d.ts +12 -0
- package/dist/cli/mobile/index.js +405 -0
- package/dist/cli/serve/index.d.ts +109 -3
- package/dist/cli/serve/index.js +506 -118
- package/dist/cli/turns/index.d.ts +105 -0
- package/dist/cli/turns/index.js +128 -0
- package/dist/cli/turns/run.d.ts +13 -0
- package/dist/cli/turns/run.js +57 -0
- package/dist/cli/turns/shadow.d.ts +112 -0
- package/dist/cli/turns/shadow.js +54 -0
- package/dist/cli/type-gen/index.js +9 -9
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +14 -23
- package/dist/compute-host/compute-host.js +18 -30
- package/dist/compute-host/index.d.ts +2 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +10 -10
- package/dist/compute-host/source-compute-host.js +33 -40
- package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
- package/dist/core/case-orchestrator/contact-hours.js +127 -0
- package/dist/core/case-orchestrator/index.d.ts +3 -0
- package/dist/core/case-orchestrator/index.js +3 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +244 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/types.d.ts +708 -0
- package/dist/core/case-orchestrator/types.js +42 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +198 -0
- package/dist/core/context/email-message.js +86 -0
- package/dist/core/context/email.d.ts +109 -0
- package/dist/core/context/email.js +90 -0
- package/dist/core/context/exchanges.d.ts +167 -0
- package/dist/core/context/exchanges.js +81 -0
- package/dist/core/context/instances.d.ts +307 -0
- package/dist/core/context/instances.js +137 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +544 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +177 -0
- package/dist/core/context/sms.js +77 -0
- package/dist/core/context/types.d.ts +79 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +85 -0
- package/dist/core/conversation/index.js +133 -0
- package/dist/core/functions/errors.d.ts +74 -0
- package/dist/core/functions/errors.js +26 -0
- package/dist/core/functions/events.d.ts +192 -0
- package/dist/core/functions/events.js +23 -0
- package/dist/core/functions/schedules.d.ts +50 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +29 -73
- package/dist/core/functions/types.js +1 -4
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +904 -0
- package/dist/core/page/define.js +518 -0
- package/dist/core/page/envelope.d.ts +55 -0
- package/dist/core/page/envelope.js +4 -0
- package/dist/core/page/fns.d.ts +448 -0
- package/dist/core/page/fns.js +539 -0
- package/dist/core/page/memory-reader.d.ts +27 -0
- package/dist/core/page/memory-reader.js +299 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/page-host.d.ts +20 -0
- package/dist/core/page/page-host.js +57 -0
- package/dist/core/page/records-query.d.ts +234 -0
- package/dist/core/page/records-query.js +780 -0
- package/dist/core/page/render.d.ts +295 -0
- package/dist/core/page/render.js +1060 -0
- package/dist/core/page/sandbox.d.ts +85 -0
- package/dist/core/page/sandbox.js +357 -0
- package/dist/core/page/time-format.d.ts +46 -0
- package/dist/core/page/time-format.js +125 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +648 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +57 -0
- package/dist/core/page/workspace.js +266 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +208 -0
- package/dist/core/party/schema.js +113 -0
- package/dist/core/party/types.d.ts +35 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +56 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +102 -0
- package/dist/core/slot/company-metadata.js +536 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -25
- package/dist/core/slot/field.js +0 -71
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +17 -0
- package/dist/core/slot/schema-compat.js +103 -0
- package/dist/core/slot/schema.d.ts +353 -76
- package/dist/core/slot/schema.js +163 -10
- package/dist/core/slot/types.d.ts +30 -103
- package/dist/core/slot/value.d.ts +28 -3
- package/dist/core/slot/value.js +93 -57
- package/dist/dev-overlay/protocol.d.ts +74 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +26 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +13 -4
- package/dist/fn-context/fake/index.js +29 -2
- package/dist/fn-context/fn-params.d.ts +3 -0
- package/dist/fn-context/fn-params.js +10 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +20 -9
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
- package/dist/fn-context/rpc/errors.d.ts +13 -0
- package/dist/fn-context/rpc/errors.js +22 -0
- package/dist/fn-context/rpc/index.d.ts +4 -2
- package/dist/fn-context/rpc/index.js +4 -2
- package/dist/fn-context/rpc/integration/index.d.ts +15 -5
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/log.d.ts +11 -1
- package/dist/fn-context/rpc/platform.d.ts +13 -3
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +85 -0
- package/dist/fn-context/rpc/records.js +24 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
- package/dist/fn-context/rpc/trpc-client.js +222 -12
- package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
- package/dist/fn-context/rpc/trpc-init.js +10 -4
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +52 -5
- package/dist/index.d.ts +36 -46
- package/dist/index.js +30 -33
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +49 -0
- package/dist/platform.d.ts +75 -0
- package/dist/platform.js +57 -0
- package/dist/testing-compile-child.d.ts +2 -0
- package/dist/testing-compile-child.js +20 -0
- package/dist/testing.d.ts +368 -0
- package/dist/testing.js +439 -0
- package/dist/voice-service/actions.d.ts +50 -6
- package/dist/voice-service/index.d.ts +2 -0
- package/dist/voice-service/index.js +2 -0
- package/dist/voice-service/protocol.d.ts +604 -0
- package/dist/voice-service/protocol.js +67 -0
- package/dist/voice-service/types.d.ts +55 -8
- package/dist/worker.d.ts +11 -0
- package/dist/worker.js +11 -0
- package/package.json +38 -15
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/functions/func-ref.d.ts +0 -16
- package/dist/core/functions/func-ref.js +0 -20
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -78
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AnyEventHandlers } from '../core/functions/events.js';
|
|
2
2
|
import type { FuncMap } from '../core/functions/types.js';
|
|
3
3
|
import type { ComputeHost } from './compute-host.js';
|
|
4
|
-
import type {
|
|
5
|
-
import type { ActionDataSlice, ApiHost } from '../fn-context/types.js';
|
|
4
|
+
import type { ActionDataSlice, ApiHost, CaseOrchestratorApiHost } from '../fn-context/types.js';
|
|
6
5
|
export type SourceComputeHostOptions = {
|
|
7
6
|
functions: FuncMap;
|
|
8
|
-
|
|
7
|
+
/** Company `events` export; handlers are registered under the event name. */
|
|
8
|
+
events?: AnyEventHandlers;
|
|
9
9
|
/** Override ApiHost; default Fake, or Rpc when runToken + data.config.backendUrl. */
|
|
10
|
-
apiHost?: ApiHost;
|
|
11
|
-
/** ActionDataSlice used to build
|
|
10
|
+
apiHost?: ApiHost & CaseOrchestratorApiHost;
|
|
11
|
+
/** ActionDataSlice used to build every function's ctx. */
|
|
12
12
|
data?: ActionDataSlice;
|
|
13
13
|
/** When set with data.config.backendUrl, uses Http RpcApiHost. */
|
|
14
14
|
runToken?: string;
|
|
@@ -23,13 +23,13 @@ export type SourceComputeHostOptions = {
|
|
|
23
23
|
};
|
|
24
24
|
export interface SourceComputeHost extends ComputeHost {
|
|
25
25
|
}
|
|
26
|
+
/** Company `events` handlers, by event name. */
|
|
27
|
+
export declare function eventsToFuncMap(events: AnyEventHandlers | undefined): FuncMap;
|
|
26
28
|
/**
|
|
27
29
|
* Local host: call author FuncMap implementations directly (no SequenceBuild.code).
|
|
28
30
|
*
|
|
29
|
-
* Lookup by name, then
|
|
30
|
-
*
|
|
31
|
-
* - compute / boolCompute / custom: `args[0]` is the raw snapshot (projected internally).
|
|
32
|
-
* - system: `args[0]` is the params object.
|
|
31
|
+
* Lookup by name, then `fn(ctx, args)` (38 §2.1): the Orchestrator gets its own ctx (with `api.tools`),
|
|
32
|
+
* every other function a function's.
|
|
33
33
|
*/
|
|
34
34
|
export declare function createSourceComputeHost(options: SourceComputeHostOptions): SourceComputeHost;
|
|
35
35
|
//# sourceMappingURL=source-compute-host.d.ts.map
|
|
@@ -1,63 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { isSystemEventName } from '../core/functions/events.js';
|
|
2
|
+
import { ORCHESTRATOR_FUNCTION } from '../core/case-orchestrator/types.js';
|
|
3
|
+
import { buildActionContext, buildCaseOrchestratorContext } from '../fn-context/build-context.js';
|
|
4
|
+
import { resolveFnParams } from '../fn-context/fn-params.js';
|
|
4
5
|
import { createFakeApiHost } from '../fn-context/fake/index.js';
|
|
5
6
|
import { createRpcApiHost } from '../fn-context/rpc/index.js';
|
|
6
|
-
import { makeCtx } from '../fn-context/make-ctx.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { makeCaseOrchestratorCtx, makeCtx } from '../fn-context/make-ctx.js';
|
|
8
|
+
import { getLogger } from '../logger.js';
|
|
9
|
+
const logger = getLogger(['runtime', 'source']);
|
|
10
|
+
/** Company `events` handlers, by event name. */
|
|
11
|
+
export function eventsToFuncMap(events) {
|
|
12
|
+
const out = {};
|
|
13
|
+
for (const [name, handler] of Object.entries(events ?? {})) {
|
|
14
|
+
if (isSystemEventName(name) && typeof handler === 'function')
|
|
15
|
+
out[name] = handler;
|
|
11
16
|
}
|
|
12
|
-
return
|
|
17
|
+
return out;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Local host: call author FuncMap implementations directly (no SequenceBuild.code).
|
|
16
21
|
*
|
|
17
|
-
* Lookup by name, then
|
|
18
|
-
*
|
|
19
|
-
* - compute / boolCompute / custom: `args[0]` is the raw snapshot (projected internally).
|
|
20
|
-
* - system: `args[0]` is the params object.
|
|
22
|
+
* Lookup by name, then `fn(ctx, args)` (38 §2.1): the Orchestrator gets its own ctx (with `api.tools`),
|
|
23
|
+
* every other function a function's.
|
|
21
24
|
*/
|
|
22
25
|
export function createSourceComputeHost(options) {
|
|
23
26
|
const { functions, data } = options;
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const eventFns = eventsToFuncMap(options.events);
|
|
28
|
+
for (const name of Object.keys(eventFns)) {
|
|
29
|
+
if (Object.hasOwn(functions, name)) {
|
|
30
|
+
throw new Error(`functions and events must not share names: ${name}`);
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
const apiHost = resolveApiHost(options);
|
|
28
|
-
const
|
|
29
|
-
const registry = {
|
|
30
|
-
...functions,
|
|
31
|
-
caseContextView: { kind: 'caseContextView', main: viewFn },
|
|
32
|
-
};
|
|
34
|
+
const registry = { ...functions, ...eventFns };
|
|
33
35
|
async function systemContext() {
|
|
34
36
|
return data ? buildActionContext(data, apiHost) : makeCtx();
|
|
35
37
|
}
|
|
38
|
+
async function caseOrchestratorContext() {
|
|
39
|
+
return data ? buildCaseOrchestratorContext(data, apiHost) : makeCaseOrchestratorCtx();
|
|
40
|
+
}
|
|
36
41
|
return {
|
|
37
|
-
async execute(name,
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
42
|
+
async execute(name, invocation = {}) {
|
|
43
|
+
const fn = registry[name];
|
|
44
|
+
if (!fn) {
|
|
40
45
|
throw new Error(`Missing function: ${name}`);
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
return def.main(requireSlots(name, args));
|
|
44
|
-
}
|
|
45
|
-
if (def.kind === 'compute' || def.kind === 'boolCompute') {
|
|
46
|
-
return def.main(viewFn(requireSlots(name, args)));
|
|
47
|
-
}
|
|
48
|
-
if (def.kind === 'custom') {
|
|
49
|
-
const caseContext = viewFn(requireSlots(name, args));
|
|
50
|
-
const ctx = await systemContext();
|
|
51
|
-
const fn = def.main;
|
|
52
|
-
return fn(caseContext, { ...ctx, params: args[1] ?? {} });
|
|
53
|
-
}
|
|
54
|
-
const params = resolveSystemFnParams(args);
|
|
47
|
+
const args = resolveFnParams(invocation.args);
|
|
55
48
|
const contextStarted = Date.now();
|
|
56
|
-
const ctx = await systemContext();
|
|
57
|
-
|
|
49
|
+
const ctx = name === ORCHESTRATOR_FUNCTION ? await caseOrchestratorContext() : await systemContext();
|
|
50
|
+
logger.info('context built', { name, durationMs: Date.now() - contextStarted });
|
|
58
51
|
const functionStarted = Date.now();
|
|
59
|
-
const result = await
|
|
60
|
-
|
|
52
|
+
const result = await fn(ctx, args);
|
|
53
|
+
logger.info('function executed', { name, durationMs: Date.now() - functionStarted });
|
|
61
54
|
return result;
|
|
62
55
|
},
|
|
63
56
|
dispose() { },
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contact hours in company code (25 §3): when a company may reach a contact on its own. The platform
|
|
3
|
+
* does not check them; the company writes its rules (by topic, state, channel) in the repository and
|
|
4
|
+
* books `at` with these helpers. Pure calendar math in the contact's local time, with no legal content
|
|
5
|
+
* (no built-in quiet hours). Part of the company API (`src/index.ts`), bundled into
|
|
6
|
+
* company code as is: no imports.
|
|
7
|
+
*/
|
|
8
|
+
export type ContactHoursWeekday = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
|
|
9
|
+
/** A local time range, `HH:MM` to `HH:MM` (`24:00` ends at midnight), start before end. */
|
|
10
|
+
export type ContactHoursRange = {
|
|
11
|
+
start: string;
|
|
12
|
+
end: string;
|
|
13
|
+
};
|
|
14
|
+
/** `OfficeHours` without `timezone`: always read in the contact's own zone. */
|
|
15
|
+
export type ContactHours = {
|
|
16
|
+
week: Record<ContactHoursWeekday, ContactHoursRange[]>;
|
|
17
|
+
/** Recurring dates (`MM-DD`) whose hours replace `week`; `[]` means no contact that day. */
|
|
18
|
+
holidays?: {
|
|
19
|
+
date: string;
|
|
20
|
+
hours: ContactHoursRange[];
|
|
21
|
+
}[];
|
|
22
|
+
/** One-off dates (`YYYY-MM-DD`) whose hours replace `holidays` and `week`. */
|
|
23
|
+
overrides?: {
|
|
24
|
+
date: string;
|
|
25
|
+
hours: ContactHoursRange[];
|
|
26
|
+
}[];
|
|
27
|
+
/**
|
|
28
|
+
* Whose hours: left out, the company's contact-hours rules; `contact_schedule`, a contact's own
|
|
29
|
+
* (`contactScheduleHours`); `cadence`, the code's own pacing (one call a day: today closed once it had
|
|
30
|
+
* its call), which holds whatever an environment being tested lets go (`ctx.time.ignore`).
|
|
31
|
+
*/
|
|
32
|
+
source?: 'contact_schedule' | 'cadence';
|
|
33
|
+
};
|
|
34
|
+
/** What does not hold while the environment is tested (`ctx.time.ignore`, 68 §6.2). */
|
|
35
|
+
export type ContactHoursIgnore = Readonly<{
|
|
36
|
+
contactHours: boolean;
|
|
37
|
+
contactSchedule: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
/** The contact's own `contact_schedule` value (when they said they may be reached). */
|
|
40
|
+
export type ContactScheduleValue = {
|
|
41
|
+
weekly: Record<ContactHoursWeekday, ContactHoursRange[]> | null;
|
|
42
|
+
dateOverrides: {
|
|
43
|
+
dates: string[];
|
|
44
|
+
windows: ContactHoursRange[];
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
/** Every day of the week with the same hours. */
|
|
48
|
+
export declare function everyDay(hours: ContactHoursRange[]): Record<ContactHoursWeekday, ContactHoursRange[]>;
|
|
49
|
+
/** A contact's `contact_schedule` as contact hours (no schedule: any time), to intersect with the company's. */
|
|
50
|
+
export declare function contactScheduleHours(schedule: ContactScheduleValue | null | undefined): ContactHours;
|
|
51
|
+
/** The hours on a local date (`YYYY-MM-DD`): an override, else a holiday, else the weekday. */
|
|
52
|
+
export declare function contactHoursOn(hours: ContactHours, day: string): ContactHoursRange[];
|
|
53
|
+
/**
|
|
54
|
+
* Whether `at` (a Date, ISO string or epoch ms) falls inside `hours` (one, or a list that must all allow it)
|
|
55
|
+
* in `timezone`. `ignore` (`ctx.time.ignore`): what does not hold while the environment is tested; when
|
|
56
|
+
* nothing is left to hold, any time is.
|
|
57
|
+
*/
|
|
58
|
+
export declare function withinContactHours(hours: ContactHours | readonly ContactHours[], at: Date | string | number, timezone: string, ignore?: ContactHoursIgnore): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The first time at or after `from` inside `hours` (one, or a list that must all allow it: the company's
|
|
61
|
+
* rules and the contact's own schedule), in `timezone`, as an ISO string for `at`; null when there is none
|
|
62
|
+
* within `days` (default 14). `from` is `ctx.time` (its `now`, and what does not hold while the environment
|
|
63
|
+
* is tested: `ctx.time.ignore`, 68 §6.2), or a Date, ISO string or epoch ms. When nothing is left to hold,
|
|
64
|
+
* `from` itself.
|
|
65
|
+
*/
|
|
66
|
+
export declare function nextContactTime(hours: ContactHours | readonly ContactHours[], from: Date | string | number | {
|
|
67
|
+
now: number;
|
|
68
|
+
ignore?: ContactHoursIgnore;
|
|
69
|
+
}, timezone: string, days?: number): string | null;
|
|
70
|
+
//# sourceMappingURL=contact-hours.d.ts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contact hours in company code (25 §3): when a company may reach a contact on its own. The platform
|
|
3
|
+
* does not check them; the company writes its rules (by topic, state, channel) in the repository and
|
|
4
|
+
* books `at` with these helpers. Pure calendar math in the contact's local time, with no legal content
|
|
5
|
+
* (no built-in quiet hours). Part of the company API (`src/index.ts`), bundled into
|
|
6
|
+
* company code as is: no imports.
|
|
7
|
+
*/
|
|
8
|
+
const WEEKDAYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
9
|
+
const ALL_DAY = [{ start: '00:00', end: '24:00' }];
|
|
10
|
+
const DAY_MS = 86_400_000;
|
|
11
|
+
/** Every day of the week with the same hours. */
|
|
12
|
+
export function everyDay(hours) {
|
|
13
|
+
return { mon: hours, tue: hours, wed: hours, thu: hours, fri: hours, sat: hours, sun: hours };
|
|
14
|
+
}
|
|
15
|
+
/** A contact's `contact_schedule` as contact hours (no schedule: any time), to intersect with the company's. */
|
|
16
|
+
export function contactScheduleHours(schedule) {
|
|
17
|
+
return {
|
|
18
|
+
week: schedule?.weekly ?? everyDay(ALL_DAY),
|
|
19
|
+
overrides: (schedule?.dateOverrides ?? []).flatMap((override) => override.dates.map((date) => ({ date, hours: override.windows }))),
|
|
20
|
+
source: 'contact_schedule',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** `hours` without what `ignore` lets go: the company's rules, the contact's own schedule; never a cadence. */
|
|
24
|
+
function held(hours, ignore) {
|
|
25
|
+
if (!ignore)
|
|
26
|
+
return hours;
|
|
27
|
+
return hours.filter((entry) => entry.source === 'cadence' ? true : entry.source === 'contact_schedule' ? !ignore.contactSchedule : !ignore.contactHours);
|
|
28
|
+
}
|
|
29
|
+
/** The hours on a local date (`YYYY-MM-DD`): an override, else a holiday, else the weekday. */
|
|
30
|
+
export function contactHoursOn(hours, day) {
|
|
31
|
+
const override = hours.overrides?.find((entry) => entry.date === day);
|
|
32
|
+
if (override)
|
|
33
|
+
return override.hours;
|
|
34
|
+
const holiday = hours.holidays?.find((entry) => entry.date === day.slice(5));
|
|
35
|
+
if (holiday)
|
|
36
|
+
return holiday.hours;
|
|
37
|
+
return hours.week[WEEKDAYS[new Date(`${day}T12:00:00Z`).getUTCDay()]] ?? [];
|
|
38
|
+
}
|
|
39
|
+
function minutes(time) {
|
|
40
|
+
const match = /^(\d{2}):(\d{2})$/.exec(time);
|
|
41
|
+
if (!match)
|
|
42
|
+
throw new Error(`contact hours: "${time}" is not HH:MM`);
|
|
43
|
+
return Number(match[1]) * 60 + Number(match[2]);
|
|
44
|
+
}
|
|
45
|
+
function clock(total) {
|
|
46
|
+
return `${String(Math.floor(total / 60)).padStart(2, '0')}:${String(total % 60).padStart(2, '0')}`;
|
|
47
|
+
}
|
|
48
|
+
/** Where two lists of ranges overlap. */
|
|
49
|
+
function intersect(a, b) {
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const x of a) {
|
|
52
|
+
for (const y of b) {
|
|
53
|
+
const start = Math.max(minutes(x.start), minutes(y.start));
|
|
54
|
+
const end = Math.min(minutes(x.end), minutes(y.end));
|
|
55
|
+
if (start < end)
|
|
56
|
+
out.push({ start: clock(start), end: clock(end) });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out.sort((p, q) => minutes(p.start) - minutes(q.start));
|
|
60
|
+
}
|
|
61
|
+
/** The ranges on a local date that every one of `all` allows. */
|
|
62
|
+
function rangesOn(all, day) {
|
|
63
|
+
return all.reduce((ranges, hours) => intersect(ranges, contactHoursOn(hours, day)), ALL_DAY);
|
|
64
|
+
}
|
|
65
|
+
function localParts(at, timezone) {
|
|
66
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', { timeZone: timezone, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
|
|
67
|
+
.formatToParts(at)
|
|
68
|
+
.map((part) => [part.type, part.value]));
|
|
69
|
+
return { day: `${parts.year}-${parts.month}-${parts.day}`, minute: Number(parts.hour) * 60 + Number(parts.minute) };
|
|
70
|
+
}
|
|
71
|
+
/** The UTC instant of a local wall time (two passes, right on DST days). */
|
|
72
|
+
function instantOf(day, minute, timezone) {
|
|
73
|
+
const wall = Date.parse(`${day}T00:00:00Z`) + minute * 60_000;
|
|
74
|
+
let guess = wall;
|
|
75
|
+
for (let pass = 0; pass < 2; pass += 1) {
|
|
76
|
+
const seen = localParts(new Date(guess), timezone);
|
|
77
|
+
const seenWall = Date.parse(`${seen.day}T00:00:00Z`) + seen.minute * 60_000;
|
|
78
|
+
guess += wall - seenWall;
|
|
79
|
+
}
|
|
80
|
+
return guess;
|
|
81
|
+
}
|
|
82
|
+
function addDays(day, count) {
|
|
83
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + count * DAY_MS).toISOString().slice(0, 10);
|
|
84
|
+
}
|
|
85
|
+
function list(hours) {
|
|
86
|
+
return Array.isArray(hours) ? hours : [hours];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Whether `at` (a Date, ISO string or epoch ms) falls inside `hours` (one, or a list that must all allow it)
|
|
90
|
+
* in `timezone`. `ignore` (`ctx.time.ignore`): what does not hold while the environment is tested; when
|
|
91
|
+
* nothing is left to hold, any time is.
|
|
92
|
+
*/
|
|
93
|
+
export function withinContactHours(hours, at, timezone, ignore) {
|
|
94
|
+
const kept = held(list(hours), ignore);
|
|
95
|
+
if (kept.length === 0)
|
|
96
|
+
return true;
|
|
97
|
+
const local = localParts(new Date(at), timezone);
|
|
98
|
+
return rangesOn(kept, local.day).some((range) => local.minute >= minutes(range.start) && local.minute < minutes(range.end));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The first time at or after `from` inside `hours` (one, or a list that must all allow it: the company's
|
|
102
|
+
* rules and the contact's own schedule), in `timezone`, as an ISO string for `at`; null when there is none
|
|
103
|
+
* within `days` (default 14). `from` is `ctx.time` (its `now`, and what does not hold while the environment
|
|
104
|
+
* is tested: `ctx.time.ignore`, 68 §6.2), or a Date, ISO string or epoch ms. When nothing is left to hold,
|
|
105
|
+
* `from` itself.
|
|
106
|
+
*/
|
|
107
|
+
export function nextContactTime(hours, from, timezone, days = 14) {
|
|
108
|
+
const time = typeof from === 'object' && !(from instanceof Date) ? from : null;
|
|
109
|
+
const start = new Date(time ? time.now : from).getTime();
|
|
110
|
+
if (!Number.isFinite(start))
|
|
111
|
+
throw new Error('nextContactTime: from must be a time');
|
|
112
|
+
const all = held(list(hours), time?.ignore);
|
|
113
|
+
if (all.length === 0)
|
|
114
|
+
return new Date(start).toISOString();
|
|
115
|
+
const today = localParts(new Date(start), timezone).day;
|
|
116
|
+
for (let offset = 0; offset <= days; offset += 1) {
|
|
117
|
+
const day = addDays(today, offset);
|
|
118
|
+
for (const range of rangesOn(all, day)) {
|
|
119
|
+
const end = instantOf(day, minutes(range.end), timezone);
|
|
120
|
+
if (end <= start)
|
|
121
|
+
continue;
|
|
122
|
+
return new Date(Math.max(start, instantOf(day, minutes(range.start), timezone))).toISOString();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=contact-hours.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ACTIVITY_RECENT_LIMIT, ORCHESTRATOR_ENTRY, ORCHESTRATOR_FUNCTION, CASE_ORCHESTRATOR_TOOL_NAMES, EMPTY_CASE_ACTIVITY, RECENT_AGREED_ACTIONS_DAYS, type ActivityStats, type AgreementFields, type CaseActivity, type CaseOrchestrator, type CaseOrchestratorApi, type CaseOrchestratorArgs, type CaseOrchestratorContext, type CaseOrchestratorManifest, type CaseOrchestratorParams, type CaseOrchestratorToolName, type CaseOrchestratorTools, type ChannelAvailability, type ChannelUnavailableReason, type ExchangeEntry, type ExchangeEvent, type ExchangeSearchHit, type ContactActionInput, type ContactActionView, type ContactChannel, type PartyContactHours, type FinishedAgreedActionView, type PartyActivity, type ReadExchangeResult, type RescheduledResult, type RunTrigger, type RunTriggerType, type ScheduleUpdateSlotsInput, type SlotFieldWriteInput, type SlotInsertInput, type SlotWriteInput, type ScheduleTiming, type ScheduledActionInput, type ScheduledActionInputs, type ScheduledActionKind, type ScheduledActionTiming, type ScheduledActionView, type SearchExchangesResult, type ToolCallArgs, type ToolCallResult, type ToolResult, type UpdateSlotsActionInput, type UpdateSlotsActionView, type ScheduleWakeInput, type WakeActionInput, type WakeActionView, type WakeResult, } from './types.js';
|
|
2
|
+
export { localDateTime, localDay, render, zonedIso, type ConversationOptions, type TimelineOptions } from './render.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ACTIVITY_RECENT_LIMIT, ORCHESTRATOR_ENTRY, ORCHESTRATOR_FUNCTION, CASE_ORCHESTRATOR_TOOL_NAMES, EMPTY_CASE_ACTIVITY, RECENT_AGREED_ACTIONS_DAYS, } from './types.js';
|
|
2
|
+
export { localDateTime, localDay, render, zonedIso } from './render.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { CaseActivity, ChannelAvailability, FinishedAgreedActionView, PartyActivity, ReadExchangeResult, RunTrigger, ScheduledActionView } from './types.js';
|
|
2
|
+
/** `YYYY-MM-DD` of an instant in `timezone`. */
|
|
3
|
+
export declare function localDay(at: string | Date, timezone: string): string;
|
|
4
|
+
/** `YYYY-MM-DD HH:mm:ss` of an instant in `timezone`. */
|
|
5
|
+
export declare function localDateTime(at: string | Date, timezone: string): string;
|
|
6
|
+
/** ISO 8601 in `timezone` with its UTC offset, e.g. `2026-10-09T06:25:00-04:00`: a time that names its own zone. */
|
|
7
|
+
export declare function zonedIso(at: string | Date, timezone: string): string;
|
|
8
|
+
/** `Current local time: 2026-10-08 10:05:00, Thursday, and October has 31 days`. */
|
|
9
|
+
declare function renderLocalClock(now: Date, timezone: string): string;
|
|
10
|
+
/** One party: `Today is [day 3]` and today's counts. */
|
|
11
|
+
declare function partyActivitySummary(party: PartyActivity): string;
|
|
12
|
+
/** The whole case: the Case day and today's counts. */
|
|
13
|
+
declare function caseActivitySummary(activity: CaseActivity): string;
|
|
14
|
+
/**
|
|
15
|
+
* The party's own contact hours (their `contact_schedule`), in their timezone: a line per weekday
|
|
16
|
+
* (`every day` when all are the same), then one per date that differs. None on file: one line saying
|
|
17
|
+
* so. The company's rules for when to reach them are its own (25 §3), not shown here.
|
|
18
|
+
*/
|
|
19
|
+
declare function partyContactHours(party: Pick<PartyActivity, 'contactHours'>): string;
|
|
20
|
+
/** `sms: true` per channel; an unavailable one says why. */
|
|
21
|
+
declare function partyChannelAvailability(availability: ChannelAvailability): string;
|
|
22
|
+
export type TimelineOptions = {
|
|
23
|
+
/** Only the last `sinceDays` days (today counts as one). */
|
|
24
|
+
sinceDays?: number;
|
|
25
|
+
/** At most this many of the newest events. */
|
|
26
|
+
limit?: number;
|
|
27
|
+
};
|
|
28
|
+
/** Events grouped by day: `[day N] [YYYY-MM-DD]:`, then `[YYYY-MM-DD HH:mm:ss] <event> exchangeId …`. */
|
|
29
|
+
declare function partyTimeline(party: PartyActivity, options?: TimelineOptions): string;
|
|
30
|
+
/**
|
|
31
|
+
* `- <id>: <kind> at <local time> [agreed in …] (<note or reason>) {"timing":…}`; an agreed
|
|
32
|
+
* follow-up is marked, scheduled slot writes say why and carry their `writes`, a hand-over names its
|
|
33
|
+
* sequence, a wake-up its name. `(none)` when empty.
|
|
34
|
+
*/
|
|
35
|
+
declare function pendingActions(actions: readonly ScheduledActionView[], timezone: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Why the Run woke up when nothing happened in a conversation (25 §6): each `timer` (a wake-up the
|
|
38
|
+
* Orchestrator booked) and `external` trigger (company code's `instances.notify`), as
|
|
39
|
+
* `- timer <name> at <local time> (<note>)` / `- external <reason> at <local time>`.
|
|
40
|
+
* `(none)` when there are none.
|
|
41
|
+
*/
|
|
42
|
+
declare function wakeUps(triggers: readonly RunTrigger[], timezone: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Finished agreed follow-ups: `- <id>: <kind> at <local time> [agreed in …], <status> at <local time> (<note>)`,
|
|
45
|
+
* the second time being when it finished. `(none)` when empty.
|
|
46
|
+
*/
|
|
47
|
+
declare function recentAgreedActions(actions: readonly FinishedAgreedActionView[], timezone: string): string;
|
|
48
|
+
export type ConversationOptions = {
|
|
49
|
+
/** Only the newest `limit` entries. */
|
|
50
|
+
limit?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* One exchange's words (a `readExchange` result): a head line naming it, then
|
|
54
|
+
* `[YYYY-MM-DD HH:mm:ss] customer|rep: <text>` per entry, in `timezone`.
|
|
55
|
+
*/
|
|
56
|
+
declare function conversation(result: ReadExchangeResult, timezone: string, options?: ConversationOptions): string;
|
|
57
|
+
/**
|
|
58
|
+
* Text for company code to show or log (docs/design/08-case-orchestrator.md §5.3), in the mars next-step
|
|
59
|
+
* format. Party functions take one contact's activity (`activity.byContact[contactId]`) and
|
|
60
|
+
* write its local wall-clock times.
|
|
61
|
+
*/
|
|
62
|
+
export declare const render: {
|
|
63
|
+
localClock: typeof renderLocalClock;
|
|
64
|
+
activitySummary: typeof partyActivitySummary;
|
|
65
|
+
caseActivitySummary: typeof caseActivitySummary;
|
|
66
|
+
contactHours: typeof partyContactHours;
|
|
67
|
+
channelAvailability: typeof partyChannelAvailability;
|
|
68
|
+
timeline: typeof partyTimeline;
|
|
69
|
+
pendingActions: typeof pendingActions;
|
|
70
|
+
recentAgreedActions: typeof recentAgreedActions;
|
|
71
|
+
wakeUps: typeof wakeUps;
|
|
72
|
+
conversation: typeof conversation;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=render.d.ts.map
|