@loomwork/wire-abi 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +61 -2
- package/dist/carrier.d.ts +31 -0
- package/dist/carrier.d.ts.map +1 -0
- package/dist/carrier.js +102 -0
- package/dist/carrier.js.map +1 -0
- package/dist/foldVectors.d.ts +37 -0
- package/dist/foldVectors.d.ts.map +1 -0
- package/dist/foldVectors.js +769 -0
- package/dist/foldVectors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +80 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +66 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +58 -3
- package/src/carrier.ts +168 -0
- package/src/foldVectors.ts +944 -0
- package/src/index.ts +18 -0
- package/src/protocol.ts +122 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
WIRE_ABI,
|
|
3
|
+
WIRE_ABI_VERSION,
|
|
4
|
+
WIRE_METHODS,
|
|
5
|
+
CARRIER_METHODS,
|
|
6
|
+
RPC_ERRORS,
|
|
7
|
+
deriveWireMethods,
|
|
8
|
+
type WireAbi,
|
|
9
|
+
type WireMethod,
|
|
10
|
+
type WireSemantics,
|
|
11
|
+
type CarrierMethod,
|
|
12
|
+
type JsonRpcRequest,
|
|
13
|
+
type JsonRpcResponse,
|
|
14
|
+
type JsonRpcSuccess,
|
|
15
|
+
type JsonRpcError,
|
|
16
|
+
} from "./protocol";
|
|
17
|
+
export { handleRpc, type CarrierOptions, type FlowResolver } from "./carrier";
|
|
18
|
+
export { FOLD_VECTORS, runFoldVectors, type FoldVector } from "./foldVectors";
|
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { KERNEL_ABI_VERSION, KERNEL_SYSCALLS } from "@loomwork/workflow-runtime";
|
|
2
|
+
import type { KernelSyscall } from "@loomwork/workflow-runtime";
|
|
3
|
+
|
|
4
|
+
// ── T2 — the wire-level kernel ABI ────────────────────────────────────────────
|
|
5
|
+
//
|
|
6
|
+
// A versioned wire protocol that is a PROJECTION of the K1 syscall ABI —
|
|
7
|
+
// normative for WIRE CLIENTS ONLY. The TypeScript `ctx` surface (K1) stays
|
|
8
|
+
// authoritative for in-process userland; this is derived FROM it, never the
|
|
9
|
+
// reverse (the amendment's A1 — no authority inversion). Because the projection
|
|
10
|
+
// is generated from `KERNEL_SYSCALLS`, it cannot silently drift from the real
|
|
11
|
+
// syscall set (a conformance test pins the derivation).
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The wire protocol's own version. Independent of `KERNEL_ABI_VERSION` but
|
|
15
|
+
* tracks its major line: a wire client negotiates on this, and the projection
|
|
16
|
+
* it wraps is pinned by the `kernelAbiVersion` it reports.
|
|
17
|
+
*/
|
|
18
|
+
export const WIRE_ABI_VERSION = "1.0.0";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Wire semantics for a syscall (A2): a **unary** call is request→response; a
|
|
22
|
+
* **channel** call carries an incremental stream (`stream`, `ui`) and needs a
|
|
23
|
+
* streaming transport frame. Partitioning these BEFORE choosing JSON-RPC vs gRPC
|
|
24
|
+
* is what the amendment requires — this table is that partition.
|
|
25
|
+
*/
|
|
26
|
+
export type WireSemantics = "unary" | "channel";
|
|
27
|
+
|
|
28
|
+
export interface WireMethod {
|
|
29
|
+
/** The JSON-RPC method name — the syscall namespaced under `ctx.`. */
|
|
30
|
+
method: string;
|
|
31
|
+
/** The K1 syscall this method projects. */
|
|
32
|
+
syscall: string;
|
|
33
|
+
semantics: WireSemantics;
|
|
34
|
+
since: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const CHANNEL_SYSCALLS = new Set(["stream", "ui"]);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Derive the wire-method table from the authoritative K1 syscalls. Generated,
|
|
41
|
+
* not hand-maintained, so the wire ABI is provably a projection of the kernel
|
|
42
|
+
* ABI (T2.1). `ui` is a K1 accessor (a property object) — on the wire it is a
|
|
43
|
+
* channel namespace whose sub-operations stream UI patches.
|
|
44
|
+
*/
|
|
45
|
+
export function deriveWireMethods(
|
|
46
|
+
syscalls: readonly KernelSyscall[] = KERNEL_SYSCALLS
|
|
47
|
+
): WireMethod[] {
|
|
48
|
+
return syscalls.map((s) => ({
|
|
49
|
+
method: `ctx.${s.name}`,
|
|
50
|
+
syscall: s.name,
|
|
51
|
+
semantics: CHANNEL_SYSCALLS.has(s.name) ? "channel" : "unary",
|
|
52
|
+
since: s.since,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const WIRE_METHODS: readonly WireMethod[] = deriveWireMethods();
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The client-facing CARRIER operations (T2.4) — what a non-TS client actually
|
|
60
|
+
* calls to drive an execution over the wire. The kernel folds and stays
|
|
61
|
+
* authoritative for state; the client starts/resumes/reads. Suspended executions
|
|
62
|
+
* are re-driven by the KERNEL (server-side flow code), which is why the staged
|
|
63
|
+
* A2A/worker carrier sidesteps the "who re-drives" problem (A3): the client's
|
|
64
|
+
* surface is task-shaped, not per-syscall.
|
|
65
|
+
*/
|
|
66
|
+
export const CARRIER_METHODS = [
|
|
67
|
+
"execution.start",
|
|
68
|
+
"execution.resume",
|
|
69
|
+
"execution.getState",
|
|
70
|
+
"execution.cancel",
|
|
71
|
+
] as const;
|
|
72
|
+
|
|
73
|
+
export type CarrierMethod = (typeof CARRIER_METHODS)[number];
|
|
74
|
+
|
|
75
|
+
/** The wire ABI descriptor a server advertises (mirrors `KERNEL_ABI`). */
|
|
76
|
+
export interface WireAbi {
|
|
77
|
+
wireVersion: string;
|
|
78
|
+
kernelAbiVersion: string;
|
|
79
|
+
syscalls: readonly WireMethod[];
|
|
80
|
+
carrier: readonly string[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const WIRE_ABI: WireAbi = {
|
|
84
|
+
wireVersion: WIRE_ABI_VERSION,
|
|
85
|
+
kernelAbiVersion: KERNEL_ABI_VERSION,
|
|
86
|
+
syscalls: WIRE_METHODS,
|
|
87
|
+
carrier: CARRIER_METHODS,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// ── JSON-RPC 2.0 framing ──────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
export interface JsonRpcRequest {
|
|
93
|
+
jsonrpc: "2.0";
|
|
94
|
+
id: string | number | null;
|
|
95
|
+
method: string;
|
|
96
|
+
params?: unknown;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface JsonRpcSuccess {
|
|
100
|
+
jsonrpc: "2.0";
|
|
101
|
+
id: string | number | null;
|
|
102
|
+
result: unknown;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface JsonRpcError {
|
|
106
|
+
jsonrpc: "2.0";
|
|
107
|
+
id: string | number | null;
|
|
108
|
+
error: { code: number; message: string; data?: unknown };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type JsonRpcResponse = JsonRpcSuccess | JsonRpcError;
|
|
112
|
+
|
|
113
|
+
/** JSON-RPC error codes used by the carrier (standard + kernel-specific). */
|
|
114
|
+
export const RPC_ERRORS = {
|
|
115
|
+
parseError: -32700,
|
|
116
|
+
invalidRequest: -32600,
|
|
117
|
+
methodNotFound: -32601,
|
|
118
|
+
invalidParams: -32602,
|
|
119
|
+
internalError: -32603,
|
|
120
|
+
/** A kernel ring denied the operation (K2/K3/K6/K7/K12) or it otherwise failed. */
|
|
121
|
+
kernelRefused: -32000,
|
|
122
|
+
} as const;
|