@blokjs/shared 2.1.0 → 2.2.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/dist/AgentSessionContracts.d.ts +316 -0
- package/dist/AgentSessionContracts.js +331 -0
- package/dist/BlokError.d.ts +23 -0
- package/dist/BlokError.js +65 -0
- package/dist/CapabilityContracts.d.ts +91 -0
- package/dist/CapabilityContracts.js +104 -0
- package/dist/CapabilityManifest.d.ts +67 -0
- package/dist/CapabilityManifest.js +172 -0
- package/dist/EnforcementContracts.d.ts +61 -0
- package/dist/EnforcementContracts.js +17 -0
- package/dist/EnforcementProfileContracts.d.ts +36 -0
- package/dist/EnforcementProfileContracts.js +55 -0
- package/dist/EvidenceContracts.d.ts +884 -0
- package/dist/EvidenceContracts.js +237 -0
- package/dist/GitCapabilityContracts.d.ts +103 -0
- package/dist/GitCapabilityContracts.js +222 -0
- package/dist/GlobalLogger.d.ts +2 -0
- package/dist/GlobalLogger.js +4 -0
- package/dist/GraphContracts.d.ts +1643 -0
- package/dist/GraphContracts.js +333 -0
- package/dist/InteractionContracts.d.ts +76 -0
- package/dist/InteractionContracts.js +218 -0
- package/dist/JoinContracts.d.ts +593 -0
- package/dist/JoinContracts.js +329 -0
- package/dist/NodeBase.d.ts +20 -0
- package/dist/NodeBase.js +57 -6
- package/dist/PermissionAlgebra.d.ts +51 -0
- package/dist/PermissionAlgebra.js +125 -0
- package/dist/PolicyContracts.d.ts +184 -0
- package/dist/PolicyContracts.js +1 -0
- package/dist/ProcessCapabilityContracts.d.ts +146 -0
- package/dist/ProcessCapabilityContracts.js +263 -0
- package/dist/RuntimeContracts.d.ts +125 -0
- package/dist/RuntimeContracts.js +108 -0
- package/dist/SecretContracts.d.ts +43 -0
- package/dist/SecretContracts.js +1 -0
- package/dist/WasiComponentContracts.d.ts +582 -0
- package/dist/WasiComponentContracts.js +192 -0
- package/dist/WorkflowBindingContracts.d.ts +1062 -0
- package/dist/WorkflowBindingContracts.js +339 -0
- package/dist/index.d.ts +33 -2
- package/dist/index.js +21 -2
- package/dist/types/LoggerContext.d.ts +7 -0
- package/dist/utils/Mapper.d.ts +14 -0
- package/dist/utils/Mapper.js +32 -0
- package/package.json +3 -2
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CAPABILITY_CLASSIFICATIONS, CAPABILITY_DETERMINISM, CAPABILITY_EFFECTS, CAPABILITY_IDEMPOTENCY, CAPABILITY_MANIFEST_VERSION, CAPABILITY_MATURITY, parseCapabilityManifest, } from "./CapabilityManifest.js";
|
|
3
|
+
/** The version of the Blok-owned component manifest, independent of WASI. */
|
|
4
|
+
export const WASI_COMPONENT_MANIFEST_VERSION = "1";
|
|
5
|
+
/** The version of the runner↔host request/response seam. */
|
|
6
|
+
export const WASI_COMPONENT_CONTRACT_VERSION = "1";
|
|
7
|
+
export const WASI_COMPONENT_WIT_PACKAGE = "blok:runtime";
|
|
8
|
+
export const WASI_COMPONENT_WIT_WORLD = "blok-node";
|
|
9
|
+
export const WASI_COMPONENT_WIT_VERSION = "1.0.0";
|
|
10
|
+
/** v1 targets the stable WASI 0.2 Component Model surface. */
|
|
11
|
+
export const WASI_COMPONENT_WASI_VERSION = "0.2";
|
|
12
|
+
export const WASI_COMPONENT_MEDIA_TYPE = "application/wasm-component";
|
|
13
|
+
const SHA256_DIGEST = /^sha256:[a-f0-9]{64}$/;
|
|
14
|
+
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?$/;
|
|
15
|
+
const IDENTIFIER = /^[A-Za-z][A-Za-z0-9._:/-]{0,127}$/;
|
|
16
|
+
const ERROR_CODE = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
17
|
+
const CapabilityManifestSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
version: z.literal(CAPABILITY_MANIFEST_VERSION),
|
|
20
|
+
classification: z.enum(CAPABILITY_CLASSIFICATIONS),
|
|
21
|
+
effects: z.array(z.enum(CAPABILITY_EFFECTS)),
|
|
22
|
+
capabilities: z.array(z.string()),
|
|
23
|
+
secrets: z.array(z.string()),
|
|
24
|
+
determinism: z.enum(CAPABILITY_DETERMINISM),
|
|
25
|
+
idempotency: z.enum(CAPABILITY_IDEMPOTENCY),
|
|
26
|
+
maturity: z.enum(CAPABILITY_MATURITY),
|
|
27
|
+
resources: z
|
|
28
|
+
.object({
|
|
29
|
+
maxDurationMs: z.number().int().positive().optional(),
|
|
30
|
+
maxMemoryBytes: z.number().int().positive().optional(),
|
|
31
|
+
maxInputBytes: z.number().int().positive().optional(),
|
|
32
|
+
maxOutputBytes: z.number().int().positive().optional(),
|
|
33
|
+
maxConcurrency: z.number().int().positive().optional(),
|
|
34
|
+
})
|
|
35
|
+
.strict()
|
|
36
|
+
.optional(),
|
|
37
|
+
runtimes: z.array(z.string()).optional(),
|
|
38
|
+
triggers: z.array(z.string()).optional(),
|
|
39
|
+
})
|
|
40
|
+
.strict();
|
|
41
|
+
export const WasiComponentLimitsSchema = z
|
|
42
|
+
.object({
|
|
43
|
+
/** Deterministic compute budget. The host must translate this to fuel. */
|
|
44
|
+
fuel: z.number().int().positive().optional(),
|
|
45
|
+
/** Wall-clock guard used with epoch interruption, not as a fuel substitute. */
|
|
46
|
+
maxDurationMs: z.number().int().positive().optional(),
|
|
47
|
+
maxMemoryBytes: z.number().int().positive().optional(),
|
|
48
|
+
maxInputBytes: z.number().int().positive().optional(),
|
|
49
|
+
maxOutputBytes: z.number().int().positive().optional(),
|
|
50
|
+
maxLogBytes: z.number().int().positive().optional(),
|
|
51
|
+
maxHostCalls: z.number().int().positive().optional(),
|
|
52
|
+
maxConcurrentExecutions: z.number().int().positive().optional(),
|
|
53
|
+
maxQueueDepth: z.number().int().positive().optional(),
|
|
54
|
+
})
|
|
55
|
+
.strict()
|
|
56
|
+
.optional();
|
|
57
|
+
export const WasiComponentArtifactSchema = z
|
|
58
|
+
.object({
|
|
59
|
+
/** Development may use a local path; production policy still requires digest. */
|
|
60
|
+
uri: z.string().min(1).max(2048),
|
|
61
|
+
digest: z.string().regex(SHA256_DIGEST, "artifact.digest must be a lowercase sha256 digest"),
|
|
62
|
+
mediaType: z.literal(WASI_COMPONENT_MEDIA_TYPE),
|
|
63
|
+
sizeBytes: z.number().int().positive().optional(),
|
|
64
|
+
})
|
|
65
|
+
.strict();
|
|
66
|
+
export const WasiComponentWorldSchema = z
|
|
67
|
+
.object({
|
|
68
|
+
package: z.literal(WASI_COMPONENT_WIT_PACKAGE),
|
|
69
|
+
world: z.literal(WASI_COMPONENT_WIT_WORLD),
|
|
70
|
+
version: z.string().regex(SEMVER, "world.version must be semantic versioning"),
|
|
71
|
+
})
|
|
72
|
+
.strict();
|
|
73
|
+
export const WasiComponentNodeSchema = z
|
|
74
|
+
.object({
|
|
75
|
+
name: z.string().regex(IDENTIFIER),
|
|
76
|
+
description: z.string().max(4096).optional(),
|
|
77
|
+
tags: z.array(z.string().regex(IDENTIFIER)).max(64).optional(),
|
|
78
|
+
inputSchema: z.unknown().optional(),
|
|
79
|
+
outputSchema: z.unknown().optional(),
|
|
80
|
+
})
|
|
81
|
+
.strict();
|
|
82
|
+
export const WasiComponentManifestSchema = z
|
|
83
|
+
.object({
|
|
84
|
+
version: z.literal(WASI_COMPONENT_MANIFEST_VERSION),
|
|
85
|
+
runtime: z.literal("runtime.wasi"),
|
|
86
|
+
artifact: WasiComponentArtifactSchema,
|
|
87
|
+
world: WasiComponentWorldSchema,
|
|
88
|
+
wasiVersion: z.literal(WASI_COMPONENT_WASI_VERSION),
|
|
89
|
+
componentModelVersion: z.literal(WASI_COMPONENT_WASI_VERSION),
|
|
90
|
+
exportName: z.string().regex(IDENTIFIER),
|
|
91
|
+
node: WasiComponentNodeSchema,
|
|
92
|
+
capabilityManifest: CapabilityManifestSchema,
|
|
93
|
+
limits: WasiComponentLimitsSchema,
|
|
94
|
+
})
|
|
95
|
+
.strict();
|
|
96
|
+
/** Parse and normalize the only manifest accepted by the v1 WASI seam. */
|
|
97
|
+
export function parseWasiComponentManifest(value) {
|
|
98
|
+
const parsed = WasiComponentManifestSchema.parse(value);
|
|
99
|
+
return {
|
|
100
|
+
...parsed,
|
|
101
|
+
capabilityManifest: parseCapabilityManifest(parsed.capabilityManifest),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function serializeWasiComponentManifest(value) {
|
|
105
|
+
return JSON.stringify(parseWasiComponentManifest(value));
|
|
106
|
+
}
|
|
107
|
+
export const WasiComponentErrorSchema = z
|
|
108
|
+
.object({
|
|
109
|
+
code: z.string().regex(ERROR_CODE),
|
|
110
|
+
category: z.enum([
|
|
111
|
+
"VALIDATION",
|
|
112
|
+
"CONFIGURATION",
|
|
113
|
+
"DEPENDENCY",
|
|
114
|
+
"TIMEOUT",
|
|
115
|
+
"PERMISSION",
|
|
116
|
+
"RATE_LIMIT",
|
|
117
|
+
"NOT_FOUND",
|
|
118
|
+
"CONFLICT",
|
|
119
|
+
"CANCELLED",
|
|
120
|
+
"INTERNAL",
|
|
121
|
+
"PROTOCOL",
|
|
122
|
+
"DATA",
|
|
123
|
+
]),
|
|
124
|
+
message: z.string().min(1).max(1024),
|
|
125
|
+
retryable: z.boolean(),
|
|
126
|
+
details: z.record(z.unknown()).optional(),
|
|
127
|
+
})
|
|
128
|
+
.strict();
|
|
129
|
+
export const WasiComponentExecutionRequestSchema = z
|
|
130
|
+
.object({
|
|
131
|
+
contractVersion: z.literal(WASI_COMPONENT_CONTRACT_VERSION),
|
|
132
|
+
componentDigest: z.string().regex(SHA256_DIGEST),
|
|
133
|
+
exportName: z.string().regex(IDENTIFIER),
|
|
134
|
+
input: z.unknown(),
|
|
135
|
+
request: z.object({
|
|
136
|
+
body: z.unknown(),
|
|
137
|
+
headers: z.record(z.string()),
|
|
138
|
+
params: z.record(z.string()),
|
|
139
|
+
query: z.record(z.string()),
|
|
140
|
+
}),
|
|
141
|
+
contentType: z.string().min(1).max(256),
|
|
142
|
+
deadlineMs: z.number().int().positive(),
|
|
143
|
+
traceparent: z.string().max(512).optional(),
|
|
144
|
+
})
|
|
145
|
+
.strict();
|
|
146
|
+
export const WasiComponentExecutionResponseSchema = z
|
|
147
|
+
.object({
|
|
148
|
+
contractVersion: z.literal(WASI_COMPONENT_CONTRACT_VERSION),
|
|
149
|
+
success: z.boolean(),
|
|
150
|
+
output: z.unknown().nullable(),
|
|
151
|
+
contentType: z.string().min(1).max(256).optional(),
|
|
152
|
+
logs: z
|
|
153
|
+
.array(z
|
|
154
|
+
.object({
|
|
155
|
+
level: z.enum(["debug", "info", "warn", "error"]),
|
|
156
|
+
message: z.string().max(8192),
|
|
157
|
+
})
|
|
158
|
+
.strict())
|
|
159
|
+
.max(1024),
|
|
160
|
+
metrics: z
|
|
161
|
+
.object({
|
|
162
|
+
durationMs: z.number().nonnegative().optional(),
|
|
163
|
+
cpuMs: z.number().nonnegative().optional(),
|
|
164
|
+
memoryBytes: z.number().int().nonnegative().optional(),
|
|
165
|
+
})
|
|
166
|
+
.strict()
|
|
167
|
+
.optional(),
|
|
168
|
+
error: WasiComponentErrorSchema.optional(),
|
|
169
|
+
})
|
|
170
|
+
.strict()
|
|
171
|
+
.refine((value) => value.success === (value.error === undefined), {
|
|
172
|
+
message: "success and error must agree",
|
|
173
|
+
path: ["error"],
|
|
174
|
+
});
|
|
175
|
+
/** The boundary intentionally carries only these host-mediated capabilities in v1. */
|
|
176
|
+
export const WASI_COMPONENT_CAPABILITIES = [
|
|
177
|
+
"wasi.log",
|
|
178
|
+
"wasi.trace",
|
|
179
|
+
"wasi.secret.read",
|
|
180
|
+
"wasi.blob.read",
|
|
181
|
+
"wasi.fs.read",
|
|
182
|
+
"wasi.fs.write",
|
|
183
|
+
"wasi.net.connect",
|
|
184
|
+
"wasi.env.read",
|
|
185
|
+
"wasi.clock.read",
|
|
186
|
+
"wasi.random.read",
|
|
187
|
+
"wasi.http.request",
|
|
188
|
+
"wasi.socket.connect",
|
|
189
|
+
"wasi.process.spawn",
|
|
190
|
+
"wasi.state.read",
|
|
191
|
+
"wasi.state.write",
|
|
192
|
+
];
|