trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
56 lines (53 loc) • 1.28 kB
JavaScript
import {
__esm
} from "./chunk-2ESYSVXG.js";
// src/vcs/ops.ts
async function hashVcsOp(op) {
const content = JSON.stringify({
kind: op.kind,
timestamp: op.timestamp,
agentId: op.agentId,
previousHash: op.previousHash,
vcs: op.vcs
});
const msgUint8 = new TextEncoder().encode(content);
const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
return `trellis:op:${hashHex}`;
}
async function verifyVcsOpHash(op) {
return op.hash === await hashVcsOp(op);
}
async function createVcsOp(kind, params) {
const opBase = {
kind,
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
agentId: params.agentId,
previousHash: params.previousHash,
vcs: params.vcs
};
return {
...opBase,
hash: await hashVcsOp(opBase)
};
}
function isVcsOp(op) {
return op.vcs !== void 0 || typeof op.kind === "string" && op.kind.startsWith("vcs:");
}
function isVcsOpKind(kind) {
return kind.startsWith("vcs:");
}
var init_ops = __esm({
"src/vcs/ops.ts"() {
"use strict";
}
});
export {
hashVcsOp,
verifyVcsOpHash,
createVcsOp,
isVcsOp,
isVcsOpKind,
init_ops
};