@superpanel-sdk/runtime 0.2.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -10
- package/dist/builder/codegen/emit.d.ts +25 -12
- package/dist/builder/codegen/emit.js +339 -78
- package/dist/builder/codegen/generate.d.ts +21 -2
- package/dist/builder/codegen/generate.js +147 -34
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +29 -0
- package/dist/builder/company-imports.js +122 -0
- package/dist/builder/compile/compile-sequence.d.ts +61 -8
- package/dist/builder/compile/compile-sequence.js +334 -80
- package/dist/builder/compile/function-code.d.ts +19 -3
- package/dist/builder/compile/function-code.js +123 -45
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +30 -27
- package/dist/builder/errors.d.ts +9 -0
- package/dist/builder/errors.js +17 -0
- package/dist/builder/function-params.d.ts +10 -0
- package/dist/builder/function-params.js +203 -0
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +258 -67
- package/dist/builder/paths.d.ts +9 -1
- package/dist/builder/paths.js +32 -2
- package/dist/builder/schedules.d.ts +25 -0
- package/dist/builder/schedules.js +101 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +102 -0
- package/dist/builder/types.d.ts +127 -19
- package/dist/builder/types.js +21 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/calls/index.d.ts +177 -0
- package/dist/cli/calls/index.js +96 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/debug/index.d.ts +31 -0
- package/dist/cli/debug/index.js +119 -0
- package/dist/cli/exec/index.d.ts +39 -0
- package/dist/cli/exec/index.js +138 -0
- package/dist/cli/exec/session.d.ts +48 -0
- package/dist/cli/exec/session.js +82 -0
- package/dist/cli/exec/trace.d.ts +18 -0
- package/dist/cli/exec/trace.js +52 -0
- package/dist/cli/index.js +112 -9
- package/dist/cli/logs/index.d.ts +47 -0
- package/dist/cli/logs/index.js +113 -0
- package/dist/cli/mobile/index.d.ts +12 -0
- package/dist/cli/mobile/index.js +405 -0
- package/dist/cli/serve/index.d.ts +109 -3
- package/dist/cli/serve/index.js +506 -118
- package/dist/cli/turns/index.d.ts +105 -0
- package/dist/cli/turns/index.js +128 -0
- package/dist/cli/turns/run.d.ts +13 -0
- package/dist/cli/turns/run.js +57 -0
- package/dist/cli/turns/shadow.d.ts +112 -0
- package/dist/cli/turns/shadow.js +54 -0
- package/dist/cli/type-gen/index.js +9 -9
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +14 -23
- package/dist/compute-host/compute-host.js +18 -30
- package/dist/compute-host/index.d.ts +2 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +10 -10
- package/dist/compute-host/source-compute-host.js +33 -40
- package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
- package/dist/core/case-orchestrator/contact-hours.js +127 -0
- package/dist/core/case-orchestrator/index.d.ts +3 -0
- package/dist/core/case-orchestrator/index.js +3 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +244 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/types.d.ts +708 -0
- package/dist/core/case-orchestrator/types.js +42 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +198 -0
- package/dist/core/context/email-message.js +86 -0
- package/dist/core/context/email.d.ts +109 -0
- package/dist/core/context/email.js +90 -0
- package/dist/core/context/exchanges.d.ts +167 -0
- package/dist/core/context/exchanges.js +81 -0
- package/dist/core/context/instances.d.ts +307 -0
- package/dist/core/context/instances.js +137 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +544 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +177 -0
- package/dist/core/context/sms.js +77 -0
- package/dist/core/context/types.d.ts +79 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +85 -0
- package/dist/core/conversation/index.js +133 -0
- package/dist/core/functions/errors.d.ts +74 -0
- package/dist/core/functions/errors.js +26 -0
- package/dist/core/functions/events.d.ts +192 -0
- package/dist/core/functions/events.js +23 -0
- package/dist/core/functions/schedules.d.ts +50 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +29 -73
- package/dist/core/functions/types.js +1 -4
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +904 -0
- package/dist/core/page/define.js +518 -0
- package/dist/core/page/envelope.d.ts +55 -0
- package/dist/core/page/envelope.js +4 -0
- package/dist/core/page/fns.d.ts +448 -0
- package/dist/core/page/fns.js +539 -0
- package/dist/core/page/memory-reader.d.ts +27 -0
- package/dist/core/page/memory-reader.js +299 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/page-host.d.ts +20 -0
- package/dist/core/page/page-host.js +57 -0
- package/dist/core/page/records-query.d.ts +234 -0
- package/dist/core/page/records-query.js +780 -0
- package/dist/core/page/render.d.ts +295 -0
- package/dist/core/page/render.js +1060 -0
- package/dist/core/page/sandbox.d.ts +85 -0
- package/dist/core/page/sandbox.js +357 -0
- package/dist/core/page/time-format.d.ts +46 -0
- package/dist/core/page/time-format.js +125 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +648 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +57 -0
- package/dist/core/page/workspace.js +266 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +208 -0
- package/dist/core/party/schema.js +113 -0
- package/dist/core/party/types.d.ts +35 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +56 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +102 -0
- package/dist/core/slot/company-metadata.js +536 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -25
- package/dist/core/slot/field.js +0 -71
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +17 -0
- package/dist/core/slot/schema-compat.js +103 -0
- package/dist/core/slot/schema.d.ts +353 -76
- package/dist/core/slot/schema.js +163 -10
- package/dist/core/slot/types.d.ts +30 -103
- package/dist/core/slot/value.d.ts +28 -3
- package/dist/core/slot/value.js +93 -57
- package/dist/dev-overlay/protocol.d.ts +74 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +26 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +13 -4
- package/dist/fn-context/fake/index.js +29 -2
- package/dist/fn-context/fn-params.d.ts +3 -0
- package/dist/fn-context/fn-params.js +10 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +20 -9
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
- package/dist/fn-context/rpc/errors.d.ts +13 -0
- package/dist/fn-context/rpc/errors.js +22 -0
- package/dist/fn-context/rpc/index.d.ts +4 -2
- package/dist/fn-context/rpc/index.js +4 -2
- package/dist/fn-context/rpc/integration/index.d.ts +15 -5
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/log.d.ts +11 -1
- package/dist/fn-context/rpc/platform.d.ts +13 -3
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +85 -0
- package/dist/fn-context/rpc/records.js +24 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
- package/dist/fn-context/rpc/trpc-client.js +222 -12
- package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
- package/dist/fn-context/rpc/trpc-init.js +10 -4
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +52 -5
- package/dist/index.d.ts +36 -46
- package/dist/index.js +30 -33
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +49 -0
- package/dist/platform.d.ts +75 -0
- package/dist/platform.js +57 -0
- package/dist/testing-compile-child.d.ts +2 -0
- package/dist/testing-compile-child.js +20 -0
- package/dist/testing.d.ts +368 -0
- package/dist/testing.js +439 -0
- package/dist/voice-service/actions.d.ts +50 -6
- package/dist/voice-service/index.d.ts +2 -0
- package/dist/voice-service/index.js +2 -0
- package/dist/voice-service/protocol.d.ts +604 -0
- package/dist/voice-service/protocol.js +67 -0
- package/dist/voice-service/types.d.ts +55 -8
- package/dist/worker.d.ts +11 -0
- package/dist/worker.js +11 -0
- package/package.json +38 -15
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/functions/func-ref.d.ts +0 -16
- package/dist/core/functions/func-ref.js +0 -20
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -78
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { PageChannel } from '../../core/page/define.js';
|
|
2
|
+
export type TurnSummary = {
|
|
3
|
+
id: string;
|
|
4
|
+
seq: number;
|
|
5
|
+
runId: string;
|
|
6
|
+
callId: string | null;
|
|
7
|
+
instanceId: string;
|
|
8
|
+
/** customer | assistant | silence | wrap_up | run */
|
|
9
|
+
kind: string;
|
|
10
|
+
channel: string;
|
|
11
|
+
heard: string | null;
|
|
12
|
+
said: string[];
|
|
13
|
+
/** The model's thought at each step: what it heard, what it does, what comes next. */
|
|
14
|
+
thoughts: string[];
|
|
15
|
+
actions: Array<{
|
|
16
|
+
key: string;
|
|
17
|
+
name: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
status: string;
|
|
20
|
+
args: unknown;
|
|
21
|
+
result: unknown;
|
|
22
|
+
error: string | null;
|
|
23
|
+
}>;
|
|
24
|
+
writes: Array<{
|
|
25
|
+
rowId: string;
|
|
26
|
+
table: string;
|
|
27
|
+
field: string;
|
|
28
|
+
value: unknown;
|
|
29
|
+
state: string | null;
|
|
30
|
+
}>;
|
|
31
|
+
outcome: string | null;
|
|
32
|
+
error: string | null;
|
|
33
|
+
startedAt: string;
|
|
34
|
+
endedAt: string | null;
|
|
35
|
+
/** Whether its snapshot is still kept (30 days). */
|
|
36
|
+
snapshot: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type TurnRecord = TurnSummary & {
|
|
39
|
+
format: 1;
|
|
40
|
+
sequence: string;
|
|
41
|
+
steps: Array<{
|
|
42
|
+
thought: string | null;
|
|
43
|
+
say: string;
|
|
44
|
+
actions: unknown[];
|
|
45
|
+
outcomes: Array<{
|
|
46
|
+
action: string;
|
|
47
|
+
status: string;
|
|
48
|
+
detail?: string;
|
|
49
|
+
}>;
|
|
50
|
+
}>;
|
|
51
|
+
platformRules: string;
|
|
52
|
+
};
|
|
53
|
+
export type TurnSnapshot = {
|
|
54
|
+
pages: Array<{
|
|
55
|
+
seq: number;
|
|
56
|
+
step: number;
|
|
57
|
+
auto: boolean;
|
|
58
|
+
text: string;
|
|
59
|
+
}>;
|
|
60
|
+
data: Record<string, Array<Record<string, unknown>>>;
|
|
61
|
+
context: Record<string, unknown> | null;
|
|
62
|
+
history: unknown;
|
|
63
|
+
start: unknown;
|
|
64
|
+
};
|
|
65
|
+
export type TurnRead = {
|
|
66
|
+
turn: TurnRecord;
|
|
67
|
+
snapshot: TurnSnapshot | null;
|
|
68
|
+
};
|
|
69
|
+
export type TurnsQuery = {
|
|
70
|
+
instanceId?: string;
|
|
71
|
+
runId?: string;
|
|
72
|
+
callId?: string;
|
|
73
|
+
since?: string;
|
|
74
|
+
limit?: number;
|
|
75
|
+
};
|
|
76
|
+
/** POST to an exec route with the run token; the backend's error as the message. */
|
|
77
|
+
export declare function postExec<T>(backendUrl: string, runToken: string, what: string, body: unknown): Promise<T>;
|
|
78
|
+
/** The turn's directory: `turn.json`, `page/<n>.txt`, `data.json`, `context.json`, `history.json`, `start.json`. */
|
|
79
|
+
export declare function writeTurnExport(dir: string, read: TurnRead): string;
|
|
80
|
+
/** A turn's directory read back. Its snapshot is null when it was exported after the snapshot was dropped. */
|
|
81
|
+
export declare function readTurnExport(dir: string): TurnRead;
|
|
82
|
+
/** One line: where it is in the run, who spoke, what was said, what it did. */
|
|
83
|
+
export declare function formatTurnLine(turn: TurnSummary): string;
|
|
84
|
+
/** The channel of a page a turn's context names. */
|
|
85
|
+
export declare function channelOf(turn: TurnRecord): PageChannel;
|
|
86
|
+
type TurnsOptions = {
|
|
87
|
+
env?: string;
|
|
88
|
+
instance?: string;
|
|
89
|
+
call?: string;
|
|
90
|
+
run?: string;
|
|
91
|
+
since?: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
json?: boolean;
|
|
94
|
+
url?: string;
|
|
95
|
+
};
|
|
96
|
+
/** `turns`: the turns, one line each (or one JSON each with `--json`). */
|
|
97
|
+
export declare function runTurns(repoRoot: string, options: TurnsOptions): Promise<void>;
|
|
98
|
+
/** `turns export <turnId>`: the turn written to `.superpanel/turns/<turnId>/`; prints the directory. */
|
|
99
|
+
export declare function runTurnExport(repoRoot: string, turnId: string, options: {
|
|
100
|
+
env?: string;
|
|
101
|
+
url?: string;
|
|
102
|
+
out?: string;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
export {};
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `turns`: the turns of a case, a run or a call in a non-prod environment (68 §7.4), one line each, and
|
|
3
|
+
* `turns export <turnId>`: one turn written to `.superpanel/turns/<turnId>/` (its record and snapshot),
|
|
4
|
+
* which `fromTurn` reads back for `renderPage`. The same files an integration test's `exportTurn` writes.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { loadCachedServeAuthorization, resolveBackendUrl } from '../auth/auth.js';
|
|
9
|
+
import { apiUrl, requestJson } from '../auth/http.js';
|
|
10
|
+
import { requestExecRun } from '../exec/session.js';
|
|
11
|
+
import { timeOf } from '../logs/index.js';
|
|
12
|
+
/** POST to an exec route with the run token; the backend's error as the message. */
|
|
13
|
+
export async function postExec(backendUrl, runToken, what, body) {
|
|
14
|
+
const { response, payload } = await requestJson(apiUrl(backendUrl, `cli-auth/exec/${what}`), {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: { Authorization: `Bearer ${runToken}`, 'Content-Type': 'application/json' },
|
|
17
|
+
body: JSON.stringify(body),
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok)
|
|
20
|
+
throw new Error(`${what}: ${payload.error ?? `the backend answered ${response.status}`}`);
|
|
21
|
+
return payload;
|
|
22
|
+
}
|
|
23
|
+
/** The turn's directory: `turn.json`, `page/<n>.txt`, `data.json`, `context.json`, `history.json`, `start.json`. */
|
|
24
|
+
export function writeTurnExport(dir, read) {
|
|
25
|
+
mkdirSync(dir, { recursive: true });
|
|
26
|
+
const json = (name, value) => writeFileSync(path.join(dir, name), `${JSON.stringify(value, null, 2)}\n`);
|
|
27
|
+
json('turn.json', read.turn);
|
|
28
|
+
if (read.snapshot) {
|
|
29
|
+
mkdirSync(path.join(dir, 'page'), { recursive: true });
|
|
30
|
+
for (const page of read.snapshot.pages)
|
|
31
|
+
if (!page.auto)
|
|
32
|
+
writeFileSync(path.join(dir, 'page', `${page.seq}.txt`), page.text);
|
|
33
|
+
json('data.json', read.snapshot.data);
|
|
34
|
+
json('context.json', read.snapshot.context);
|
|
35
|
+
json('history.json', read.snapshot.history);
|
|
36
|
+
json('start.json', read.snapshot.start);
|
|
37
|
+
}
|
|
38
|
+
return dir;
|
|
39
|
+
}
|
|
40
|
+
/** A turn's directory read back. Its snapshot is null when it was exported after the snapshot was dropped. */
|
|
41
|
+
export function readTurnExport(dir) {
|
|
42
|
+
const file = (name) => path.join(dir, name);
|
|
43
|
+
if (!existsSync(file('turn.json')))
|
|
44
|
+
throw new Error(`${dir}: no turn.json (export a turn with \`turns export <turnId>\`)`);
|
|
45
|
+
const turn = JSON.parse(readFileSync(file('turn.json'), 'utf8'));
|
|
46
|
+
if (turn.format !== 1)
|
|
47
|
+
throw new Error(`${dir}: turn.json format ${String(turn.format)}; this runtime reads format 1`);
|
|
48
|
+
if (!existsSync(file('data.json')))
|
|
49
|
+
return { turn, snapshot: null };
|
|
50
|
+
const json = (name) => JSON.parse(readFileSync(file(name), 'utf8'));
|
|
51
|
+
const pages = existsSync(file('page'))
|
|
52
|
+
? readdirSync(file('page'))
|
|
53
|
+
.filter((name) => /^\d+\.txt$/.test(name))
|
|
54
|
+
.map((name) => ({ seq: Number(name.slice(0, -4)), step: 0, auto: false, text: readFileSync(path.join(file('page'), name), 'utf8') }))
|
|
55
|
+
.sort((a, b) => a.seq - b.seq)
|
|
56
|
+
: [];
|
|
57
|
+
return {
|
|
58
|
+
turn,
|
|
59
|
+
snapshot: {
|
|
60
|
+
pages,
|
|
61
|
+
data: json('data.json'),
|
|
62
|
+
context: json('context.json'),
|
|
63
|
+
history: json('history.json'),
|
|
64
|
+
start: json('start.json'),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const clip = (text, max = 80) => {
|
|
69
|
+
const one = (text ?? '').replace(/\s+/g, ' ').trim();
|
|
70
|
+
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
|
71
|
+
};
|
|
72
|
+
/** One line: where it is in the run, who spoke, what was said, what it did. */
|
|
73
|
+
export function formatTurnLine(turn) {
|
|
74
|
+
const parts = [`#${turn.seq} ${turn.kind}`, turn.id];
|
|
75
|
+
if (turn.heard)
|
|
76
|
+
parts.push(`heard "${clip(turn.heard)}"`);
|
|
77
|
+
if (turn.said.length)
|
|
78
|
+
parts.push(`said "${clip(turn.said.join(' '))}"`);
|
|
79
|
+
if (turn.actions.length)
|
|
80
|
+
parts.push(`did ${turn.actions.map((a) => `${a.key}:${a.status}`).join(', ')}`);
|
|
81
|
+
if (turn.writes.length)
|
|
82
|
+
parts.push(`wrote ${turn.writes.map((w) => `${w.table}.${w.field}`).join(', ')}`);
|
|
83
|
+
if (turn.outcome && turn.outcome !== 'done')
|
|
84
|
+
parts.push(turn.outcome);
|
|
85
|
+
if (turn.error)
|
|
86
|
+
parts.push(`error: ${clip(turn.error)}`);
|
|
87
|
+
return parts.join(' ');
|
|
88
|
+
}
|
|
89
|
+
/** The channel of a page a turn's context names. */
|
|
90
|
+
export function channelOf(turn) {
|
|
91
|
+
return turn.channel === 'call' || turn.channel === 'sms' || turn.channel === 'email' ? turn.channel : 'call';
|
|
92
|
+
}
|
|
93
|
+
async function execToken(repoRoot, options) {
|
|
94
|
+
const backendUrl = resolveBackendUrl(repoRoot, options.url);
|
|
95
|
+
const authorization = await loadCachedServeAuthorization(backendUrl);
|
|
96
|
+
if (!authorization)
|
|
97
|
+
throw new Error('not logged in: run `superpanel-sdk-runtime login` first');
|
|
98
|
+
const run = await requestExecRun(backendUrl, authorization.token, options.env ?? 'sandbox', undefined);
|
|
99
|
+
return { backendUrl, runToken: run.runToken };
|
|
100
|
+
}
|
|
101
|
+
/** `turns`: the turns, one line each (or one JSON each with `--json`). */
|
|
102
|
+
export async function runTurns(repoRoot, options) {
|
|
103
|
+
if (!options.instance && !options.call && !options.run)
|
|
104
|
+
throw new Error('turns: name the case (--instance), the call (--call) or the run (--run)');
|
|
105
|
+
const { backendUrl, runToken } = await execToken(repoRoot, options);
|
|
106
|
+
const since = timeOf(options.since);
|
|
107
|
+
const { turns } = await postExec(backendUrl, runToken, 'turns', {
|
|
108
|
+
...(options.instance ? { instanceId: options.instance } : {}),
|
|
109
|
+
...(options.call ? { callId: options.call } : {}),
|
|
110
|
+
...(options.run ? { runId: options.run } : {}),
|
|
111
|
+
...(since ? { since } : {}),
|
|
112
|
+
...(options.limit ? { limit: options.limit } : {}),
|
|
113
|
+
});
|
|
114
|
+
if (!turns.length)
|
|
115
|
+
console.error('no turns');
|
|
116
|
+
for (const turn of turns)
|
|
117
|
+
console.log(options.json ? JSON.stringify(turn) : formatTurnLine(turn));
|
|
118
|
+
}
|
|
119
|
+
/** `turns export <turnId>`: the turn written to `.superpanel/turns/<turnId>/`; prints the directory. */
|
|
120
|
+
export async function runTurnExport(repoRoot, turnId, options) {
|
|
121
|
+
const { backendUrl, runToken } = await execToken(repoRoot, options);
|
|
122
|
+
const read = await postExec(backendUrl, runToken, 'turns/read', { turnId });
|
|
123
|
+
const dir = writeTurnExport(path.resolve(repoRoot, options.out ?? path.join('.superpanel', 'turns', turnId)), read);
|
|
124
|
+
if (!read.snapshot)
|
|
125
|
+
console.error(`turn ${turnId}: its snapshot is no longer kept (30 days); only turn.json was written`);
|
|
126
|
+
console.log(dir);
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type TurnCliOptions = {
|
|
2
|
+
env?: string;
|
|
3
|
+
url?: string;
|
|
4
|
+
from?: string;
|
|
5
|
+
instance?: string;
|
|
6
|
+
channel?: 'sms' | 'email' | 'call';
|
|
7
|
+
say?: string;
|
|
8
|
+
caller?: string;
|
|
9
|
+
repeat?: number;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function runTurnCli(repoRoot: string, options: TurnCliOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `superpanel-sdk-runtime turn` (68 §8.1): one turn as a shadow, from the command line — on a case now, or
|
|
3
|
+
* from a turn that ran (its id or its exported directory), with this repository's code serving the
|
|
4
|
+
* environment while it runs. Each run's words, buttons, writes and functions, one block per run.
|
|
5
|
+
*/
|
|
6
|
+
import { connect } from '../../testing.js';
|
|
7
|
+
function describe(run, n) {
|
|
8
|
+
const lines = [`── run ${n}`];
|
|
9
|
+
for (const thought of run.turns.flatMap((t) => t.thoughts ?? []))
|
|
10
|
+
lines.push(` (thought) ${thought}`);
|
|
11
|
+
for (const said of run.said)
|
|
12
|
+
lines.push(`AI: ${said}`);
|
|
13
|
+
if (run.outcome && run.outcome.kind !== 'reply')
|
|
14
|
+
lines.push(`ended: ${run.outcome.kind}${'reason' in run.outcome ? ` (${run.outcome.reason})` : ''}`);
|
|
15
|
+
for (const action of run.actions)
|
|
16
|
+
lines.push(` ${action.name}: ${action.status}${action.error ? ` (${action.error})` : ''}`);
|
|
17
|
+
for (const write of run.writes)
|
|
18
|
+
lines.push(` wrote ${write.table}.${write.field} = ${JSON.stringify(write.value)}${write.state && write.state !== 'filled' ? ` (${write.state})` : ''}`);
|
|
19
|
+
for (const event of run.events)
|
|
20
|
+
lines.push(` on the line: ${JSON.stringify(event)}`);
|
|
21
|
+
for (const call of run.functions)
|
|
22
|
+
lines.push(` function ${call.name}: ${call.how}${call.error ? ` (${call.error})` : ''}`);
|
|
23
|
+
for (const warning of run.warnings)
|
|
24
|
+
lines.push(` ! ${warning}`);
|
|
25
|
+
return lines.join('\n');
|
|
26
|
+
}
|
|
27
|
+
export async function runTurnCli(repoRoot, options) {
|
|
28
|
+
if (!options.from && !options.instance)
|
|
29
|
+
throw new Error('turn: --from <turnId|dir>, or --instance <case id> with --say');
|
|
30
|
+
const sandbox = await connect({ env: options.env ?? 'sandbox', repoRoot, ...(options.url ? { url: options.url } : {}) });
|
|
31
|
+
let result;
|
|
32
|
+
try {
|
|
33
|
+
result = await sandbox.turn({
|
|
34
|
+
...(options.from ? { from: options.from } : {}),
|
|
35
|
+
...(options.instance ? { instanceId: options.instance } : {}),
|
|
36
|
+
...(options.channel ? { channel: options.channel } : {}),
|
|
37
|
+
...(options.say ? { say: options.say } : {}),
|
|
38
|
+
...(options.caller ? { caller: options.caller } : {}),
|
|
39
|
+
...(options.repeat ? { repeat: options.repeat } : {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await sandbox.close();
|
|
44
|
+
}
|
|
45
|
+
if (options.json) {
|
|
46
|
+
for (const run of result.runs)
|
|
47
|
+
console.log(JSON.stringify(run));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (result.from)
|
|
51
|
+
console.log(`from turn ${result.from.turnId} (${result.from.kind})${result.from.heard ? `: "${result.from.heard}"` : ''}`);
|
|
52
|
+
result.runs.forEach((run, i) => console.log(describe(run, i + 1)));
|
|
53
|
+
console.log('(a shadow: nothing was kept, sent or booked)');
|
|
54
|
+
}
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { TextCallEvent } from '../calls/index.js';
|
|
2
|
+
import type { TurnSummary } from './index.js';
|
|
3
|
+
export type TurnInput = {
|
|
4
|
+
/** The case; left out with `from` (the turn's). */
|
|
5
|
+
instanceId?: string;
|
|
6
|
+
channel?: 'sms' | 'email' | 'call';
|
|
7
|
+
/** What the customer writes or says; with `from`, in place of what they said then. */
|
|
8
|
+
say?: string;
|
|
9
|
+
/** The conversation's contact; the case's subject when it is a contact and none is named. */
|
|
10
|
+
caller?: string;
|
|
11
|
+
/** The conversation so far, by hand, oldest first; the case's real one when left out. */
|
|
12
|
+
history?: Array<{
|
|
13
|
+
customer?: string;
|
|
14
|
+
ai?: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Start where a turn started: its id, or the directory it was exported to (relative to the repository). */
|
|
17
|
+
from?: string;
|
|
18
|
+
/** Run it this many times (1–10), each from the same start: the model answers differently each time. */
|
|
19
|
+
repeat?: number;
|
|
20
|
+
/** Results for the company's functions the turn presses, by name; a recorded call (`from`) is replayed first. */
|
|
21
|
+
functions?: {
|
|
22
|
+
results?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/** One run of the turn. */
|
|
26
|
+
export type ShadowRun = {
|
|
27
|
+
runId: string | null;
|
|
28
|
+
/** A text or email run: how it ended (`reply` with its `text`, not sent). A call's turn: null. */
|
|
29
|
+
outcome: {
|
|
30
|
+
kind: 'reply';
|
|
31
|
+
text: string;
|
|
32
|
+
email?: {
|
|
33
|
+
subject?: string;
|
|
34
|
+
cc?: string[];
|
|
35
|
+
};
|
|
36
|
+
steps: number;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'noReply' | 'handoff' | 'abnormal';
|
|
39
|
+
reason: string;
|
|
40
|
+
steps: number;
|
|
41
|
+
} | null;
|
|
42
|
+
/** What the AI said, or would have sent. */
|
|
43
|
+
said: string[];
|
|
44
|
+
/** `act`: what the platform told the model after running the actions. */
|
|
45
|
+
stepResult?: string;
|
|
46
|
+
actions: Array<{
|
|
47
|
+
name: string;
|
|
48
|
+
kind: string;
|
|
49
|
+
args: unknown;
|
|
50
|
+
status: string;
|
|
51
|
+
error: string | null;
|
|
52
|
+
result: unknown;
|
|
53
|
+
}>;
|
|
54
|
+
/** Each field it wrote: its row, table and field, the value and state it took, and what it was. */
|
|
55
|
+
writes: Array<{
|
|
56
|
+
rowId: string;
|
|
57
|
+
table: string;
|
|
58
|
+
field: string;
|
|
59
|
+
value: unknown;
|
|
60
|
+
state: string | null;
|
|
61
|
+
from: {
|
|
62
|
+
value: unknown;
|
|
63
|
+
state: string | null;
|
|
64
|
+
};
|
|
65
|
+
reason: string | null;
|
|
66
|
+
}>;
|
|
67
|
+
/** A call: what it did on the line (a keypad, a transfer, a voicemail). */
|
|
68
|
+
events: TextCallEvent[];
|
|
69
|
+
/** A call the AI ended in this turn. */
|
|
70
|
+
ended: boolean;
|
|
71
|
+
turns: TurnSummary[];
|
|
72
|
+
/** Each company function the turn pressed: `replayed` (as it ran then), `given` (yours), `unrecorded` (not run), `skipped` (an event handler). */
|
|
73
|
+
functions: Array<{
|
|
74
|
+
name: string;
|
|
75
|
+
args: unknown;
|
|
76
|
+
how: 'replayed' | 'given' | 'unrecorded' | 'skipped';
|
|
77
|
+
result?: unknown;
|
|
78
|
+
error?: string;
|
|
79
|
+
}>;
|
|
80
|
+
/** What it would have done outside the database (a text, an email, an Orchestrator run): none of it happened. */
|
|
81
|
+
held: string[];
|
|
82
|
+
/** Where it could not start exactly as asked (a row gone since). */
|
|
83
|
+
warnings: string[];
|
|
84
|
+
/** Whether it pressed the button with this run key (or name). */
|
|
85
|
+
clicked(key: string): boolean;
|
|
86
|
+
/** Whether it wrote `table.field` (to `value`, when given). */
|
|
87
|
+
wrote(field: string, value?: unknown): boolean;
|
|
88
|
+
};
|
|
89
|
+
/** What a `turn` or an `act` did: its first run's, and every run with `repeat`. */
|
|
90
|
+
export type RunResult = ShadowRun & {
|
|
91
|
+
runs: ShadowRun[];
|
|
92
|
+
/** The turn it started from. */
|
|
93
|
+
from: {
|
|
94
|
+
turnId: string;
|
|
95
|
+
kind: string;
|
|
96
|
+
heard: string | null;
|
|
97
|
+
} | null;
|
|
98
|
+
/** The share of runs `check` holds for, 0–1. */
|
|
99
|
+
rate(check: (run: ShadowRun) => boolean): number;
|
|
100
|
+
};
|
|
101
|
+
type Post = <T>(what: string, body: unknown) => Promise<T>;
|
|
102
|
+
/** `from` as the backend takes it: a turn id as it is, a directory's files read. */
|
|
103
|
+
export declare function fromOf(repoRoot: string, from: string): string | {
|
|
104
|
+
turn: unknown;
|
|
105
|
+
history: unknown;
|
|
106
|
+
data: unknown;
|
|
107
|
+
};
|
|
108
|
+
export declare function shadowTurn(post: Post, repoRoot: string, what: 'turn' | 'act', input: TurnInput & {
|
|
109
|
+
actions?: unknown[];
|
|
110
|
+
}): Promise<RunResult>;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=shadow.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single turn, always a shadow (68 §8): `sandbox.turn` / `sandbox.act` and `superpanel-sdk-runtime turn`.
|
|
3
|
+
* The backend runs it on a shadow of the environment's database, rolled back afterwards; what it did comes
|
|
4
|
+
* back. `from` names a turn by id, or the directory `turns export` wrote it to (kept in the repository,
|
|
5
|
+
* it outlives the 30 days a turn's snapshot is kept): its files are sent as they are.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
/** `from` as the backend takes it: a turn id as it is, a directory's files read. */
|
|
10
|
+
export function fromOf(repoRoot, from) {
|
|
11
|
+
const dir = path.resolve(repoRoot, from);
|
|
12
|
+
const isDir = (() => {
|
|
13
|
+
try {
|
|
14
|
+
return statSync(dir).isDirectory();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
if (!isDir) {
|
|
21
|
+
if (/[\\/]/.test(from))
|
|
22
|
+
throw new Error(`turn: from ${from}: no such directory`);
|
|
23
|
+
return from;
|
|
24
|
+
}
|
|
25
|
+
const json = (name, required) => {
|
|
26
|
+
const file = path.join(dir, name);
|
|
27
|
+
if (!existsSync(file)) {
|
|
28
|
+
if (required)
|
|
29
|
+
throw new Error(`turn: ${from} has no ${name} (export a turn with \`turns export <turnId>\`)`);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
33
|
+
};
|
|
34
|
+
return { turn: json('turn.json', true), history: json('history.json', true), data: json('data.json', false) ?? {} };
|
|
35
|
+
}
|
|
36
|
+
function withChecks(run) {
|
|
37
|
+
return {
|
|
38
|
+
...run,
|
|
39
|
+
clicked: (key) => run.actions.some((a) => a.status !== 'failed' && (a.name === key || run.turns.some((t) => t.actions.some((ta) => ta.key === key && ta.status !== 'failed')))),
|
|
40
|
+
wrote: (field, ...value) => run.writes.some((w) => `${w.table}.${w.field}` === field && (value.length === 0 || JSON.stringify(w.value) === JSON.stringify(value[0]))),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export async function shadowTurn(post, repoRoot, what, input) {
|
|
44
|
+
const body = { ...input, ...(input.from ? { from: fromOf(repoRoot, input.from) } : {}) };
|
|
45
|
+
const wire = await post(what, body);
|
|
46
|
+
const runs = wire.runs.map(withChecks);
|
|
47
|
+
return {
|
|
48
|
+
...runs[0],
|
|
49
|
+
runs,
|
|
50
|
+
from: wire.from,
|
|
51
|
+
rate: (check) => (runs.length ? runs.filter(check).length / runs.length : 0),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=shadow.js.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import chokidar from 'chokidar';
|
|
3
|
-
import { checkAll,
|
|
4
|
-
async function runOnce(repoRoot) {
|
|
5
|
-
const results = await generateAll(repoRoot);
|
|
3
|
+
import { checkAll, companyGenPaths, generateAll, listSequenceIds } from '../../builder/codegen/generate.js';
|
|
4
|
+
async function runOnce(repoRoot, sequenceIds) {
|
|
5
|
+
const results = await generateAll(repoRoot, { sequenceIds });
|
|
6
|
+
if (!sequenceIds) {
|
|
7
|
+
for (const outPath of Object.values(companyGenPaths(repoRoot)))
|
|
8
|
+
console.log(`wrote ${path.relative(repoRoot, outPath)}`);
|
|
9
|
+
}
|
|
6
10
|
for (const result of results) {
|
|
7
11
|
console.log(`wrote ${path.relative(repoRoot, result.outPath)}`);
|
|
8
|
-
console.log(`wrote ${path.relative(repoRoot, result.
|
|
12
|
+
console.log(`wrote ${path.relative(repoRoot, result.indexOutPath)}`);
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
15
|
/** `sequences/<id>/…` → sequence id */
|
|
@@ -36,11 +40,7 @@ async function runWatch(repoRoot) {
|
|
|
36
40
|
await runOnce(repoRoot);
|
|
37
41
|
return;
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
const result = await generateSequence(repoRoot, sequenceId);
|
|
41
|
-
console.log(`wrote ${path.relative(repoRoot, result.outPath)}`);
|
|
42
|
-
console.log(`wrote ${path.relative(repoRoot, result.caseContextOutPath)}`);
|
|
43
|
-
}
|
|
43
|
+
await runOnce(repoRoot, [...job.sequences]);
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
46
46
|
console.error('[type:gen] regenerate failed:', error instanceof Error ? error.message : error);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the platform's compile child loads from the runtime the company repo installed
|
|
3
|
+
* (`packages/services/src/release/compile-child.ts`). Platform-only: the package resolves
|
|
4
|
+
* `./compiler` under the `superpanel-platform` condition, and the child loads it by file path.
|
|
5
|
+
*/
|
|
6
|
+
export { compileRepo, type CompileRepoEvent, type CompileRepoOptions, type CompileRepoSequenceResult, } from './builder/compile/compile-sequence.js';
|
|
7
|
+
//# sourceMappingURL=compiler.d.ts.map
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the platform's compile child loads from the runtime the company repo installed
|
|
3
|
+
* (`packages/services/src/release/compile-child.ts`). Platform-only: the package resolves
|
|
4
|
+
* `./compiler` under the `superpanel-platform` condition, and the child loads it by file path.
|
|
5
|
+
*/
|
|
6
|
+
export { compileRepo, } from './builder/compile/compile-sequence.js';
|
|
7
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
import type { CaseContextViewFn } from '../core/functions/define/case-context.js';
|
|
2
|
-
import type { RuntimeSlotsSnapshot } from '../core/slot/types.js';
|
|
3
1
|
/**
|
|
4
|
-
* Pluggable host for sequence functions (
|
|
2
|
+
* Pluggable host for sequence functions: every one is `(ctx, args)` (38 §2.1); the host builds `ctx`.
|
|
5
3
|
*
|
|
6
4
|
* - Local unit tests / company CI: {@link createLocalComputeHost} (direct JS call)
|
|
7
5
|
* - Author FuncMap: `createSourceComputeHost`
|
|
8
6
|
* - Platform backend: QuickJS / Cloudflare Worker hosts with the same `execute` surface
|
|
9
7
|
*/
|
|
10
8
|
export interface ComputeHost {
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
* Compute/boolCompute/custom: `args[0]` is the raw snapshot (projected internally).
|
|
14
|
-
* `caseContextView`: `args[0]` is the raw snapshot (identity when the sequence has no view).
|
|
15
|
-
*/
|
|
16
|
-
execute(name: string, args?: unknown[]): Promise<unknown>;
|
|
9
|
+
/** Invoke a registered function with its type-specific invocation. */
|
|
10
|
+
execute(name: string, invocation?: ComputeInvocation): Promise<unknown>;
|
|
17
11
|
/** Release host-owned resources. No-op when the host has nothing to free. */
|
|
18
12
|
dispose(): void;
|
|
19
13
|
}
|
|
14
|
+
/** What a function is called with besides `ctx`: its `args`, one object (`{}` when left out). */
|
|
15
|
+
export type FunctionInvocation = {
|
|
16
|
+
args?: object;
|
|
17
|
+
};
|
|
18
|
+
export type ComputeInvocation = FunctionInvocation;
|
|
19
|
+
export declare function parseComputeInvocation(value: unknown): ComputeInvocation | null;
|
|
20
20
|
/**
|
|
21
|
-
* Name →
|
|
22
|
-
* `
|
|
21
|
+
* Name → plain function of `args` (local tests stand in sequence functions with these).
|
|
22
|
+
* Parameter typed as `never` so company-narrowed maps remain assignable (TS contravariance).
|
|
23
23
|
*/
|
|
24
|
-
export type ComputeFnMap = Record<string, (
|
|
24
|
+
export type ComputeFnMap = Record<string, (args: never) => unknown | Promise<unknown>>;
|
|
25
25
|
export type ComputeHostOrFns = ComputeHost | ComputeFnMap;
|
|
26
|
-
export
|
|
27
|
-
/**
|
|
28
|
-
* Optional `(slots) => CaseContext` projector. Registered under the view.ts
|
|
29
|
-
* export name `caseContextView` and invoked before each compute fn
|
|
30
|
-
* (no cross-call cache — snapshot may change mid-recompute).
|
|
31
|
-
*/
|
|
32
|
-
caseContextView?: CaseContextViewFn<RuntimeSlotsSnapshot, unknown>;
|
|
33
|
-
};
|
|
34
|
-
/** In-process host: call plain JS computeFns. No VM, no I/O fence. */
|
|
35
|
-
export declare function createLocalComputeHost(fns: ComputeFnMap, options?: LocalComputeHostOptions): ComputeHost;
|
|
26
|
+
export declare function createLocalComputeHost(fns: ComputeFnMap): ComputeHost;
|
|
36
27
|
/** Accept either a host or a name→fn map (map is wrapped as local host). */
|
|
37
|
-
export declare function resolveComputeHost(hostOrFns: ComputeHostOrFns
|
|
28
|
+
export declare function resolveComputeHost(hostOrFns: ComputeHostOrFns): ComputeHost;
|
|
38
29
|
//# sourceMappingURL=compute-host.d.ts.map
|
|
@@ -1,45 +1,33 @@
|
|
|
1
|
+
export function parseComputeInvocation(value) {
|
|
2
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
3
|
+
return null;
|
|
4
|
+
const record = value;
|
|
5
|
+
if (record.args !== undefined &&
|
|
6
|
+
(typeof record.args !== 'object' || record.args === null || Array.isArray(record.args))) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return record.args !== undefined ? { args: record.args } : {};
|
|
10
|
+
}
|
|
1
11
|
function isComputeHost(value) {
|
|
2
12
|
return typeof value.execute === 'function';
|
|
3
13
|
}
|
|
4
|
-
function
|
|
5
|
-
const slots = args[0];
|
|
6
|
-
if (slots == null) {
|
|
7
|
-
throw new Error(`Function ${name}: args[0] (slots) required`);
|
|
8
|
-
}
|
|
9
|
-
return slots;
|
|
10
|
-
}
|
|
11
|
-
/** In-process host: call plain JS computeFns. No VM, no I/O fence. */
|
|
12
|
-
export function createLocalComputeHost(fns, options = {}) {
|
|
13
|
-
if (Object.hasOwn(fns, 'caseContextView')) {
|
|
14
|
-
throw new Error(`computeFn name 'caseContextView' collides with the sequence view`);
|
|
15
|
-
}
|
|
16
|
-
const viewFn = options.caseContextView ?? ((slots) => slots);
|
|
17
|
-
const registry = {
|
|
18
|
-
caseContextView: { kind: 'caseContextView', main: viewFn },
|
|
19
|
-
};
|
|
20
|
-
for (const [name, fn] of Object.entries(fns)) {
|
|
21
|
-
registry[name] = { kind: 'compute', main: fn };
|
|
22
|
-
}
|
|
14
|
+
export function createLocalComputeHost(fns) {
|
|
23
15
|
return {
|
|
24
|
-
async execute(name,
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
27
|
-
throw new Error(`Missing
|
|
28
|
-
}
|
|
29
|
-
const snapshot = requireSlots(name, args);
|
|
30
|
-
if (def.kind === 'caseContextView') {
|
|
31
|
-
return def.main(snapshot);
|
|
16
|
+
async execute(name, invocation = {}) {
|
|
17
|
+
const fn = fns[name];
|
|
18
|
+
if (!fn) {
|
|
19
|
+
throw new Error(`Missing function implementation: ${name}`);
|
|
32
20
|
}
|
|
33
|
-
return
|
|
21
|
+
return fn((invocation.args ?? {}));
|
|
34
22
|
},
|
|
35
23
|
dispose() { },
|
|
36
24
|
};
|
|
37
25
|
}
|
|
38
26
|
/** Accept either a host or a name→fn map (map is wrapped as local host). */
|
|
39
|
-
export function resolveComputeHost(hostOrFns
|
|
27
|
+
export function resolveComputeHost(hostOrFns) {
|
|
40
28
|
if (isComputeHost(hostOrFns)) {
|
|
41
29
|
return hostOrFns;
|
|
42
30
|
}
|
|
43
|
-
return createLocalComputeHost(hostOrFns
|
|
31
|
+
return createLocalComputeHost(hostOrFns);
|
|
44
32
|
}
|
|
45
33
|
//# sourceMappingURL=compute-host.js.map
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export { createLocalComputeHost, resolveComputeHost } from './compute-host.js';
|
|
2
|
-
export type { ComputeFnMap, ComputeHost, ComputeHostOrFns,
|
|
1
|
+
export { createLocalComputeHost, parseComputeInvocation, resolveComputeHost } from './compute-host.js';
|
|
2
|
+
export type { ComputeFnMap, ComputeHost, ComputeHostOrFns, ComputeInvocation, FunctionInvocation, } from './compute-host.js';
|
|
3
3
|
export { createSourceComputeHost } from './source-compute-host.js';
|
|
4
4
|
export type { SourceComputeHost, SourceComputeHostOptions } from './source-compute-host.js';
|
|
5
|
-
export { readOnlyComputeNames, withReadOnlyComputeCache } from './read-only-cache.js';
|
|
6
|
-
export type { ReadOnlyComputeCacheOptions } from './read-only-cache.js';
|
|
7
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { createLocalComputeHost, resolveComputeHost } from './compute-host.js';
|
|
1
|
+
export { createLocalComputeHost, parseComputeInvocation, resolveComputeHost } from './compute-host.js';
|
|
2
2
|
export { createSourceComputeHost } from './source-compute-host.js';
|
|
3
|
-
export { readOnlyComputeNames, withReadOnlyComputeCache } from './read-only-cache.js';
|
|
4
3
|
//# sourceMappingURL=index.js.map
|