openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
72 lines (71 loc) • 3.86 kB
JavaScript
import { Et as _enum, Jn as string, Lt as boolean, Nt as array, Pn as number, qn as strictObject, xn as literal } from "./schemas-Cy6abvsu.mjs";
//#region src/worker/node-workspace-retain-protocol.ts
const NODE_WORKER_RETAIN_REQUEST_MAX_BYTES = 1048576;
const RETAIN_MAX_ENTRIES = 4096;
const MANIFEST_REFS_MAX_ENTRIES = 32;
const NODE_WORKER_BUNDLE_RETAIN_MAX_HASHES = 4096;
const GATEWAY_NAMESPACE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
const MANIFEST_REF_PATTERN = /^sha256:[a-f0-9]{64}$/u;
const BUNDLE_HASH_PATTERN = /^[a-f0-9]{64}$/u;
const BoundedIdentifierSchema = string().min(1).max(256).refine((e) => e.trim() === e && !e.includes("\0"));
const ManifestRefsSchema = array(string().regex(MANIFEST_REF_PATTERN)).max(MANIFEST_REFS_MAX_ENTRIES).refine((e) => new Set(e).size === e.length, "manifestRefs must not contain duplicates").transform((e) => e.toSorted()).nullable();
const RetainEntrySchema = strictObject({
environmentId: BoundedIdentifierSchema,
sessionId: BoundedIdentifierSchema,
generation: number().int().min(1).max(Number.MAX_SAFE_INTEGER),
manifestRefs: ManifestRefsSchema
});
const BundleHashesSchema = array(string().regex(BUNDLE_HASH_PATTERN)).max(NODE_WORKER_BUNDLE_RETAIN_MAX_HASHES).refine((e) => new Set(e).size === e.length, "bundleHashes must not contain duplicates").transform((e) => e.toSorted());
const RetainInputSchema = strictObject({
version: literal(1),
gatewayNamespace: BoundedIdentifierSchema.regex(GATEWAY_NAMESPACE_PATTERN),
controllerId: BoundedIdentifierSchema.max(128),
sequence: number().int().min(1).max(Number.MAX_SAFE_INTEGER),
retain: array(RetainEntrySchema).max(RETAIN_MAX_ENTRIES),
bundleHashes: BundleHashesSchema.optional(),
acknowledgedBundleGeneration: number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
bundleStatusHash: string().regex(BUNDLE_HASH_PATTERN).optional()
}).superRefine((e, t) => {
if (e.acknowledgedBundleGeneration !== void 0 && e.bundleHashes === void 0) t.addIssue({
code: "custom",
message: "acknowledgedBundleGeneration requires bundleHashes"
});
if (e.bundleStatusHash !== void 0 && !e.bundleHashes?.includes(e.bundleStatusHash)) t.addIssue({
code: "custom",
message: "bundleStatusHash must be retained by bundleHashes"
});
});
const BundleStatusSchema = strictObject({
bundleHash: string().regex(BUNDLE_HASH_PATTERN),
status: _enum(["installed", "missing"])
});
const RetainResultSchema = strictObject({
applied: boolean(),
deleted: number().int().min(0).max(Number.MAX_SAFE_INTEGER),
hasMore: boolean(),
bundleDeleted: number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
bundleGeneration: number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
bundleStatus: BundleStatusSchema.optional()
});
function parseNodeWorkerWorkspaceRetainInput(e) {
if (!e || Buffer.byteLength(e, "utf8") > 1048576) throw new Error("INVALID_REQUEST: invalid node worker workspace retain request");
try {
const t = RetainInputSchema.parse(JSON.parse(e));
const n = /* @__PURE__ */ new Set();
for (const e of t.retain) {
const t = `${e.environmentId}\0${e.sessionId}\0${e.generation}`;
if (n.has(t)) throw new Error("workspace retain entries must be unique");
n.add(t);
}
t.retain.sort((e, t) => e.environmentId.localeCompare(t.environmentId) || e.sessionId.localeCompare(t.sessionId) || e.generation - t.generation);
return t;
} catch (e) {
const t = e instanceof Error ? e.message : String(e);
throw new Error(`INVALID_REQUEST: invalid node worker workspace retain request: ${t}`, { cause: e });
}
}
function parseNodeWorkerWorkspaceRetainResult(e) {
return RetainResultSchema.safeParse(e).data ?? null;
}
//#endregion
export { parseNodeWorkerWorkspaceRetainResult as i, NODE_WORKER_RETAIN_REQUEST_MAX_BYTES as n, parseNodeWorkerWorkspaceRetainInput as r, NODE_WORKER_BUNDLE_RETAIN_MAX_HASHES as t };