@leitwerk-dev/worker-protocol 0.1.9 → 0.2.1
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/dist/{chunk-DVN32ANP.js → chunk-VR7BWTD7.js} +5 -1
- package/dist/chunk-VR7BWTD7.js.map +1 -0
- package/dist/docker-config.d.ts +39 -0
- package/dist/docker-config.d.ts.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +529 -10
- package/dist/index.js.map +1 -1
- package/dist/ipc-codec.d.ts +22 -0
- package/dist/ipc-codec.d.ts.map +1 -1
- package/dist/ipc-decode.d.ts +7 -0
- package/dist/ipc-decode.d.ts.map +1 -1
- package/dist/ipc-messages.d.ts +339 -25
- package/dist/ipc-messages.d.ts.map +1 -1
- package/dist/pi-resource-bundle.d.ts +13 -2
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/pi-resource-manifest.d.ts +35 -1
- package/dist/pi-resource-manifest.d.ts.map +1 -1
- package/dist/testing.d.ts +3 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/worker-api-version.d.ts +2 -1
- package/dist/worker-api-version.d.ts.map +1 -1
- package/dist/worker-ipc-transport.d.ts +7 -0
- package/dist/worker-ipc-transport.d.ts.map +1 -1
- package/dist/worker-result-image-public.d.ts +2 -0
- package/dist/worker-result-image-public.d.ts.map +1 -0
- package/dist/worker-result-image-public.js +7 -0
- package/dist/worker-result-image-public.js.map +1 -0
- package/dist/worker-result-image.d.ts +22 -0
- package/dist/worker-result-image.d.ts.map +1 -1
- package/dist/worker-result-image.js +28 -54
- package/dist/worker-result-image.js.map +1 -1
- package/dist/worker-session-snapshot.d.ts +5 -0
- package/dist/worker-session-snapshot.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/docker-config.ts +50 -0
- package/src/index.ts +63 -5
- package/src/ipc-codec.ts +40 -6
- package/src/ipc-decode.ts +17 -2
- package/src/ipc-messages.ts +368 -32
- package/src/pi-resource-bundle.ts +13 -2
- package/src/pi-resource-manifest.ts +35 -1
- package/src/testing.ts +8 -0
- package/src/worker-api-version.ts +2 -1
- package/src/worker-ipc-transport.ts +7 -0
- package/src/worker-result-image-public.ts +1 -0
- package/src/worker-result-image.ts +25 -1
- package/src/worker-session-snapshot.ts +5 -0
- package/dist/chunk-DVN32ANP.js.map +0 -1
- package/dist/ipc-codec.js +0 -48
- package/dist/ipc-codec.js.map +0 -1
- package/dist/ipc-decode.js +0 -72
- package/dist/ipc-decode.js.map +0 -1
- package/dist/ipc-messages.js +0 -14
- package/dist/ipc-messages.js.map +0 -1
- package/dist/pi-resource-bundle.js +0 -139
- package/dist/pi-resource-bundle.js.map +0 -1
- package/dist/pi-resource-manifest.js +0 -101
- package/dist/pi-resource-manifest.js.map +0 -1
- package/dist/testing.js +0 -33
- package/dist/testing.js.map +0 -1
- package/dist/worker-api-version.js +0 -9
- package/dist/worker-api-version.js.map +0 -1
- package/dist/worker-ipc-transport.js +0 -8
- package/dist/worker-ipc-transport.js.map +0 -1
- package/dist/worker-session-snapshot.js +0 -8
- package/dist/worker-session-snapshot.js.map +0 -1
package/src/ipc-codec.ts
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
1
|
import { parseSchema } from "@leitwerk-dev/protocol";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
|
|
4
|
+
/** @internal */
|
|
4
5
|
export const IPC_PROTOCOL_VERSION = "leitwerk/worker-ipc/v1" as const;
|
|
5
6
|
|
|
7
|
+
/** @internal */
|
|
6
8
|
export const IPC_ENVELOPE_SCHEMA = v.object({
|
|
9
|
+
/** @internal */
|
|
7
10
|
protocol: v.literal(IPC_PROTOCOL_VERSION),
|
|
11
|
+
/** @internal */
|
|
8
12
|
messageId: v.string(),
|
|
13
|
+
/** @internal */
|
|
9
14
|
correlationId: v.optional(v.string()),
|
|
15
|
+
/** @internal */
|
|
10
16
|
type: v.string(),
|
|
17
|
+
/** @internal */
|
|
11
18
|
instanceId: v.string(),
|
|
19
|
+
/** @internal */
|
|
12
20
|
workerId: v.string(),
|
|
21
|
+
/** @internal */
|
|
13
22
|
sentAt: v.string(),
|
|
23
|
+
/** @internal */
|
|
14
24
|
payload: v.unknown(),
|
|
15
25
|
});
|
|
16
26
|
|
|
27
|
+
/** @internal */
|
|
17
28
|
export type IpcEnvelope = v.InferOutput<typeof IPC_ENVELOPE_SCHEMA>;
|
|
18
29
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
/** @internal */
|
|
31
|
+
export function validateEnvelope(msg: unknown):
|
|
32
|
+
| {
|
|
33
|
+
/** @internal */
|
|
34
|
+
ok: true;
|
|
35
|
+
/** @internal */
|
|
36
|
+
envelope: IpcEnvelope;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
/** @internal */
|
|
40
|
+
ok: false;
|
|
41
|
+
/** @internal */
|
|
42
|
+
error: string;
|
|
43
|
+
} {
|
|
22
44
|
if (
|
|
23
45
|
typeof msg === "object" &&
|
|
24
46
|
msg !== null &&
|
|
@@ -37,13 +59,25 @@ export function validateEnvelope(
|
|
|
37
59
|
: { ok: false, error: envelope.error };
|
|
38
60
|
}
|
|
39
61
|
|
|
62
|
+
/** @internal */
|
|
40
63
|
export function serializeMessage<TEnvelope extends IpcEnvelope>(envelope: TEnvelope): string {
|
|
41
64
|
return JSON.stringify(envelope);
|
|
42
65
|
}
|
|
43
66
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
/** @internal */
|
|
68
|
+
export function deserializeMessage(line: string):
|
|
69
|
+
| {
|
|
70
|
+
/** @internal */
|
|
71
|
+
ok: true;
|
|
72
|
+
/** @internal */
|
|
73
|
+
message: IpcEnvelope;
|
|
74
|
+
}
|
|
75
|
+
| {
|
|
76
|
+
/** @internal */
|
|
77
|
+
ok: false;
|
|
78
|
+
/** @internal */
|
|
79
|
+
error: string;
|
|
80
|
+
} {
|
|
47
81
|
const trimmed =
|
|
48
82
|
line.length > 0 && line.charCodeAt(line.length - 1) === 0x0d ? line.slice(0, -1) : line;
|
|
49
83
|
let parsed: unknown;
|
package/src/ipc-decode.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { validateEnvelope } from "./ipc-codec.js";
|
|
2
2
|
import type { ServerToWorkerMessage, WorkerToServerMessage } from "./ipc-messages.js";
|
|
3
3
|
|
|
4
|
+
/** @internal */
|
|
4
5
|
export type IpcDecodeResult<TMessage> =
|
|
5
|
-
| {
|
|
6
|
-
|
|
6
|
+
| {
|
|
7
|
+
/** @internal */
|
|
8
|
+
ok: true;
|
|
9
|
+
/** @internal */
|
|
10
|
+
message: TMessage;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
/** @internal */
|
|
14
|
+
ok: false;
|
|
15
|
+
/** @internal */
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
7
18
|
|
|
8
19
|
const SERVER_TO_WORKER_TYPES = [
|
|
9
20
|
"worker.start",
|
|
@@ -20,6 +31,8 @@ const SERVER_TO_WORKER_TYPES = [
|
|
|
20
31
|
const WORKER_TO_SERVER_TYPES = [
|
|
21
32
|
"worker.hello",
|
|
22
33
|
"worker.credential_update",
|
|
34
|
+
"worker.bootstrap_progress",
|
|
35
|
+
"worker.diagnostic_trace",
|
|
23
36
|
"worker.ready",
|
|
24
37
|
"worker.heartbeat",
|
|
25
38
|
"worker.state",
|
|
@@ -76,6 +89,7 @@ function decodeKnownMessage<TMessage extends { type: string }>(
|
|
|
76
89
|
* Decode a parsed envelope coming from the server side of the IPC channel.
|
|
77
90
|
* Only envelope structure + message type are runtime-validated.
|
|
78
91
|
*/
|
|
92
|
+
/** @internal */
|
|
79
93
|
export function decodeServerToWorkerMessage(msg: unknown): IpcDecodeResult<ServerToWorkerMessage> {
|
|
80
94
|
return decodeKnownMessage(msg, SERVER_TO_WORKER_TYPES, "server-to-worker");
|
|
81
95
|
}
|
|
@@ -84,6 +98,7 @@ export function decodeServerToWorkerMessage(msg: unknown): IpcDecodeResult<Serve
|
|
|
84
98
|
* Decode a parsed envelope coming from the worker side of the IPC channel.
|
|
85
99
|
* Only envelope structure + message type are runtime-validated.
|
|
86
100
|
*/
|
|
101
|
+
/** @internal */
|
|
87
102
|
export function decodeWorkerToServerMessage(msg: unknown): IpcDecodeResult<WorkerToServerMessage> {
|
|
88
103
|
return decodeKnownMessage(msg, WORKER_TO_SERVER_TYPES, "worker-to-server");
|
|
89
104
|
}
|