@verax-ai/body 0.6.1 → 0.8.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/alarm-outbox.d.ts +18 -0
- package/dist/alarm-outbox.js +199 -0
- package/dist/alarm-webhook.d.ts +16 -0
- package/dist/alarm-webhook.js +106 -0
- package/dist/approval-bound.d.ts +9 -0
- package/dist/approval-bound.js +16 -0
- package/dist/approve-cli.d.ts +7 -0
- package/dist/approve-cli.js +37 -17
- package/dist/cli.js +14 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +35 -0
- package/dist/control-signature.d.ts +1 -0
- package/dist/control-signature.js +15 -3
- package/dist/doctor.js +9 -0
- package/dist/downstream.js +13 -7
- package/dist/halt.d.ts +28 -9
- package/dist/halt.js +126 -18
- package/dist/held-spend.d.ts +1 -1
- package/dist/held-spend.js +11 -6
- package/dist/incidents.d.ts +67 -0
- package/dist/incidents.js +627 -0
- package/dist/keys.d.ts +18 -1
- package/dist/keys.js +109 -5
- package/dist/memory-reattest-cli.d.ts +9 -0
- package/dist/memory-reattest-cli.js +110 -0
- package/dist/memory-rehead-cli.d.ts +9 -0
- package/dist/memory-rehead-cli.js +65 -0
- package/dist/memory-store.d.ts +157 -0
- package/dist/memory-store.js +917 -0
- package/dist/operator-door.js +7 -3
- package/dist/operator-handlers.js +36 -8
- package/dist/reconcile-cli.js +3 -1
- package/dist/server.js +49 -17
- package/dist/tools/memory.d.ts +12 -6
- package/dist/tools/memory.js +80 -124
- package/dist/verify-cli.js +1 -0
- package/dist/watch.js +3 -1
- package/dist/wiring.d.ts +14 -1
- package/dist/wiring.js +71 -14
- package/package.json +3 -3
package/dist/wiring.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { createProxy, FileLedger, loadPolicy, tenantKey, } from "@verax-ai/proxy";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { pokeAlarmDelivery, startAlarmDelivery } from "./alarm-webhook.js";
|
|
4
|
+
import { ALARM_WEBHOOK_URL_ERROR, alarmRetryMs, isAllowedAlarmWebhookUrl, POLICY_FILE_ERROR_PREFIX, policyFileRefusal, } from "./config.js";
|
|
5
|
+
import { completeMemoryIntegrityIncident, raiseMemoryIntegrityIncident } from "./incidents.js";
|
|
4
6
|
import { persistPolicySnapshot } from "./policy-store.js";
|
|
5
7
|
import { inputsPrincipal } from "./inputs-read.js";
|
|
6
|
-
import {
|
|
8
|
+
import { assertRecordKeyTrust, resolveHeadDir } from "./keys.js";
|
|
9
|
+
import { openMemoryStoreSync, publishMemoryStore } from "./memory-store.js";
|
|
10
|
+
import { memoryBelongsToOtherTenant, memoryExistsForTenant, memoryGet, memoryHistoryUnavailable, memoryPut, readMemoryMeta, } from "./tools/memory.js";
|
|
7
11
|
import { auditExplain } from "./tools/audit.js";
|
|
8
12
|
import { messageRead, messageSend } from "./tools/message.js";
|
|
9
13
|
import { spendAuthorize } from "./tools/spend.js";
|
|
@@ -16,6 +20,9 @@ export const TOOL_NAMES = [
|
|
|
16
20
|
"message.send",
|
|
17
21
|
"spend",
|
|
18
22
|
];
|
|
23
|
+
function isLegacyExplainPin(value) {
|
|
24
|
+
return value.includes("BEGIN") && value.includes("PUBLIC KEY");
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* Tool functions live in a Map that is not exported. The only way to
|
|
21
28
|
* reach them at runtime is `proxy.call` -> `inner`. Extra tools (a
|
|
@@ -24,6 +31,11 @@ export const TOOL_NAMES = [
|
|
|
24
31
|
*/
|
|
25
32
|
export function createBodyServices(opts) {
|
|
26
33
|
const extraNames = [];
|
|
34
|
+
const alarmUrl = opts.alarmWebhookUrl?.trim() ?? "";
|
|
35
|
+
if (alarmUrl !== "" && !isAllowedAlarmWebhookUrl(alarmUrl)) {
|
|
36
|
+
throw new Error(ALARM_WEBHOOK_URL_ERROR);
|
|
37
|
+
}
|
|
38
|
+
const retryMs = alarmRetryMs(opts.alarmRetryMs);
|
|
27
39
|
const reserved = new Set(TOOL_NAMES);
|
|
28
40
|
for (const tool of opts.extraTools ?? []) {
|
|
29
41
|
if (reserved.has(tool.name) || extraNames.includes(tool.name)) {
|
|
@@ -52,6 +64,7 @@ export function createBodyServices(opts) {
|
|
|
52
64
|
}
|
|
53
65
|
const policyDocument = JSON.parse(policyText);
|
|
54
66
|
const policy = loadPolicy(policyText);
|
|
67
|
+
const publicKeyPem = assertRecordKeyTrust(opts);
|
|
55
68
|
const ledger = new FileLedger(opts.stateDir);
|
|
56
69
|
ledger.remoteWitness = (row, resultHash) => requestWitnessSign(opts.stateDir, row, resultHash);
|
|
57
70
|
ledger.onPieceClose = async (window) => {
|
|
@@ -61,27 +74,65 @@ export function createBodyServices(opts) {
|
|
|
61
74
|
endMs: window.endMs,
|
|
62
75
|
});
|
|
63
76
|
};
|
|
77
|
+
let store;
|
|
78
|
+
const now = opts.now ?? (() => Date.now());
|
|
79
|
+
const nonce = opts.nonce ?? (() => crypto.randomUUID());
|
|
64
80
|
try {
|
|
65
81
|
persistPolicySnapshot(opts.stateDir, policy.hash, policyDocument);
|
|
82
|
+
store = publishMemoryStore(openMemoryStoreSync({
|
|
83
|
+
stateDir: opts.stateDir,
|
|
84
|
+
publicKeyPem,
|
|
85
|
+
privateKeyPem: opts.recordSigner.privateKeyPem,
|
|
86
|
+
headDir: resolveHeadDir(opts.stateDir, opts.keysDir, opts.headDir ?? process.env.VERAX_MEMORY_HEAD_DIR),
|
|
87
|
+
}));
|
|
88
|
+
completeMemoryIntegrityIncident({
|
|
89
|
+
stateDir: opts.stateDir,
|
|
90
|
+
publicKeyPem,
|
|
91
|
+
privateKeyPem: opts.recordSigner.privateKeyPem,
|
|
92
|
+
memoryHead: store.memoryHead(),
|
|
93
|
+
...(alarmUrl !== "" ? { alarmWebhookUrl: alarmUrl } : {}),
|
|
94
|
+
});
|
|
66
95
|
}
|
|
67
96
|
catch (err) {
|
|
68
97
|
ledger.close();
|
|
69
98
|
throw err;
|
|
70
99
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
100
|
+
const finishPending = () => {
|
|
101
|
+
completeMemoryIntegrityIncident({
|
|
102
|
+
stateDir: opts.stateDir,
|
|
103
|
+
publicKeyPem,
|
|
104
|
+
privateKeyPem: opts.recordSigner.privateKeyPem,
|
|
105
|
+
memoryHead: store.memoryHead(),
|
|
106
|
+
...(alarmUrl !== "" ? { alarmWebhookUrl: alarmUrl } : {}),
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const stopAlarms = alarmUrl === ""
|
|
110
|
+
? async () => { }
|
|
111
|
+
: startAlarmDelivery({ stateDir: opts.stateDir, url: alarmUrl, retryMs, onTick: finishPending });
|
|
112
|
+
const onIntegrity = (reason) => {
|
|
113
|
+
raiseMemoryIntegrityIncident({
|
|
114
|
+
stateDir: opts.stateDir,
|
|
115
|
+
reason,
|
|
116
|
+
publicKeyPem,
|
|
117
|
+
privateKeyPem: opts.recordSigner.privateKeyPem,
|
|
118
|
+
memoryHead: store.memoryHead(),
|
|
119
|
+
now: now(),
|
|
120
|
+
...(alarmUrl !== "" ? { alarmWebhookUrl: alarmUrl } : {}),
|
|
121
|
+
});
|
|
122
|
+
pokeAlarmDelivery(opts.stateDir);
|
|
123
|
+
};
|
|
73
124
|
const registry = new Map();
|
|
74
|
-
registry.set("memory.get", (call, principal) => memoryGet(call, opts.stateDir, now, principal));
|
|
75
|
-
registry.set("memory.put", (call, principal) => memoryPut(call, opts.stateDir, principal));
|
|
125
|
+
registry.set("memory.get", (call, principal, _ref, bound) => memoryGet(call, opts.stateDir, now, principal, store, bound, onIntegrity));
|
|
126
|
+
registry.set("memory.put", (call, principal, ref) => memoryPut(call, opts.stateDir, principal, ref ?? "", store));
|
|
76
127
|
const explainOpts = async () => {
|
|
77
|
-
const env = process.env.VERAX_RECORD_PUBKEY_PIN;
|
|
78
|
-
const pem = env && env
|
|
128
|
+
const env = process.env.VERAX_RECORD_PUBKEY_PIN?.trim() ?? "";
|
|
129
|
+
const pem = env !== "" && isLegacyExplainPin(env) ? env : opts.recordSigner.publicKeyPem;
|
|
79
130
|
return {
|
|
80
131
|
...(pem
|
|
81
132
|
? {
|
|
82
133
|
issuerTrust: {
|
|
83
134
|
publicKeyPem: pem,
|
|
84
|
-
source: env && env
|
|
135
|
+
source: env !== "" && isLegacyExplainPin(env) ? "env" : "own-key",
|
|
85
136
|
},
|
|
86
137
|
}
|
|
87
138
|
: {}),
|
|
@@ -94,7 +145,7 @@ export function createBodyServices(opts) {
|
|
|
94
145
|
for (const tool of opts.extraTools ?? []) {
|
|
95
146
|
registry.set(tool.name, tool.fn);
|
|
96
147
|
}
|
|
97
|
-
const inner = async (call, principal, ref) => {
|
|
148
|
+
const inner = async (call, principal, ref, bound) => {
|
|
98
149
|
const fn = registry.get(call.name);
|
|
99
150
|
if (!fn) {
|
|
100
151
|
return {
|
|
@@ -102,7 +153,7 @@ export function createBodyServices(opts) {
|
|
|
102
153
|
isError: true,
|
|
103
154
|
};
|
|
104
155
|
}
|
|
105
|
-
return fn(call, principal, ref);
|
|
156
|
+
return fn(call, principal, ref, bound);
|
|
106
157
|
};
|
|
107
158
|
// Halt and resume lines are copied into the ledger when the body opens
|
|
108
159
|
// (`listen` awaits `proxy.syncControlRecords` before the socket accepts)
|
|
@@ -115,15 +166,17 @@ export function createBodyServices(opts) {
|
|
|
115
166
|
now,
|
|
116
167
|
nonce,
|
|
117
168
|
inner,
|
|
118
|
-
resolveInput: (id, principal) => readMemoryMeta(opts.stateDir, id, principal),
|
|
169
|
+
resolveInput: (id, principal) => readMemoryMeta(opts.stateDir, id, principal, store, onIntegrity),
|
|
119
170
|
checkTenantMismatch: async (call, principal) => {
|
|
120
171
|
if (call.name === "memory.get") {
|
|
172
|
+
if (memoryHistoryUnavailable(opts.stateDir, store))
|
|
173
|
+
return false;
|
|
121
174
|
const id = call.arguments.id;
|
|
122
175
|
if (typeof id !== "string")
|
|
123
176
|
return false;
|
|
124
|
-
if (memoryExistsForTenant(opts.stateDir, id, principal))
|
|
177
|
+
if (memoryExistsForTenant(opts.stateDir, id, principal, store))
|
|
125
178
|
return false;
|
|
126
|
-
return memoryBelongsToOtherTenant(opts.stateDir, id, tenantKey(principal));
|
|
179
|
+
return memoryBelongsToOtherTenant(opts.stateDir, id, tenantKey(principal), store);
|
|
127
180
|
}
|
|
128
181
|
if (call.name === "audit.explain") {
|
|
129
182
|
const ref = call.arguments.ref;
|
|
@@ -148,5 +201,9 @@ export function createBodyServices(opts) {
|
|
|
148
201
|
policyDocument,
|
|
149
202
|
listTools: () => (extraNames.length === 0 ? TOOL_NAMES : [...TOOL_NAMES, ...extraNames]),
|
|
150
203
|
explainOpts,
|
|
204
|
+
recordSigner: opts.recordSigner,
|
|
205
|
+
memoryStore: store,
|
|
206
|
+
stopAlarms,
|
|
207
|
+
...(opts.keysDir ? { keysDir: opts.keysDir } : {}),
|
|
151
208
|
};
|
|
152
209
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verax-ai/body",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@cedulon/cose": "0.13.1",
|
|
27
27
|
"@cedulon/effect-extract": "0.13.1",
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
29
|
-
"@verax-ai/inventory": "^0.
|
|
30
|
-
"@verax-ai/proxy": "^0.
|
|
29
|
+
"@verax-ai/inventory": "^0.8.0",
|
|
30
|
+
"@verax-ai/proxy": "^0.8.0",
|
|
31
31
|
"jose": "^6.2.12"
|
|
32
32
|
},
|
|
33
33
|
"description": "VERAX body: an MCP server that decides, records and proves what an agent did.",
|