@peac/adapter-openclaw 0.10.7
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/README.md +190 -0
- package/dist/emitter.d.ts +129 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/emitter.js +197 -0
- package/dist/emitter.js.map +1 -0
- package/dist/hooks.d.ts +112 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +157 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/mapper.d.ts +33 -0
- package/dist/mapper.d.ts.map +1 -0
- package/dist/mapper.js +320 -0
- package/dist/mapper.js.map +1 -0
- package/dist/plugin.d.ts +213 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +331 -0
- package/dist/plugin.js.map +1 -0
- package/dist/tools.d.ts +45 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +732 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +57 -0
- package/dist/types.js.map +1 -0
- package/openclaw.plugin.json +117 -0
- package/package.json +46 -0
- package/skills/peac/SKILL.md +172 -0
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @peac/adapter-openclaw - Plugin Entry Point
|
|
3
|
+
*
|
|
4
|
+
* OpenClaw plugin types and utilities for PEAC receipts.
|
|
5
|
+
* This module provides types and factory functions for OpenClaw integration.
|
|
6
|
+
*
|
|
7
|
+
* Note: Full plugin activation requires OpenClaw's plugin runtime.
|
|
8
|
+
* The types and utilities here allow building custom integrations.
|
|
9
|
+
*/
|
|
10
|
+
import type { CaptureSession, SpoolStore, DedupeIndex } from '@peac/capture-core';
|
|
11
|
+
import type { OpenClawAdapterConfig } from './types.js';
|
|
12
|
+
import { type OpenClawHookHandler } from './hooks.js';
|
|
13
|
+
import { type Signer, type ReceiptWriter, type BackgroundEmitterService } from './emitter.js';
|
|
14
|
+
/**
|
|
15
|
+
* JSON Web Key structure for signing keys (Ed25519).
|
|
16
|
+
*/
|
|
17
|
+
export interface JWK {
|
|
18
|
+
kty: string;
|
|
19
|
+
crv?: string;
|
|
20
|
+
x?: string;
|
|
21
|
+
d?: string;
|
|
22
|
+
kid?: string;
|
|
23
|
+
alg?: string;
|
|
24
|
+
use?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Plugin configuration from openclaw.plugin.json configSchema.
|
|
28
|
+
*
|
|
29
|
+
* @experimental This interface is experimental and may change.
|
|
30
|
+
*/
|
|
31
|
+
export interface PluginConfig {
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
output_dir?: string;
|
|
34
|
+
capture?: {
|
|
35
|
+
mode?: 'hash_only' | 'allowlist';
|
|
36
|
+
allowlist?: string[];
|
|
37
|
+
max_payload_size?: number;
|
|
38
|
+
};
|
|
39
|
+
signing: {
|
|
40
|
+
key_ref: string;
|
|
41
|
+
issuer: string;
|
|
42
|
+
audience?: string;
|
|
43
|
+
};
|
|
44
|
+
correlation?: {
|
|
45
|
+
include_workflow?: boolean;
|
|
46
|
+
};
|
|
47
|
+
background?: {
|
|
48
|
+
drain_interval_ms?: number;
|
|
49
|
+
batch_size?: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* OpenClaw plugin context provided by the runtime.
|
|
54
|
+
*/
|
|
55
|
+
export interface PluginContext {
|
|
56
|
+
/** Plugin configuration from gateway config */
|
|
57
|
+
config: PluginConfig;
|
|
58
|
+
/** Agent workspace directory */
|
|
59
|
+
workspaceDir: string;
|
|
60
|
+
/** Logger instance */
|
|
61
|
+
logger: PluginLogger;
|
|
62
|
+
/** Register a tool call hook */
|
|
63
|
+
onToolCall: (handler: ToolCallHandler) => void;
|
|
64
|
+
/** Register a tool result hook */
|
|
65
|
+
onToolResult: (handler: ToolResultHandler) => void;
|
|
66
|
+
/** Register tools */
|
|
67
|
+
registerTools: (tools: PluginTool[]) => void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Plugin logger interface.
|
|
71
|
+
*/
|
|
72
|
+
export interface PluginLogger {
|
|
73
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
74
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
75
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
76
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Tool call event from OpenClaw.
|
|
80
|
+
*/
|
|
81
|
+
export interface ToolCallEvent {
|
|
82
|
+
tool_call_id: string;
|
|
83
|
+
run_id: string;
|
|
84
|
+
session_key?: string;
|
|
85
|
+
tool_name: string;
|
|
86
|
+
tool_provider?: string;
|
|
87
|
+
input: unknown;
|
|
88
|
+
started_at: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Tool result event from OpenClaw.
|
|
92
|
+
*/
|
|
93
|
+
export interface ToolResultEvent {
|
|
94
|
+
tool_call_id: string;
|
|
95
|
+
run_id: string;
|
|
96
|
+
session_key?: string;
|
|
97
|
+
tool_name: string;
|
|
98
|
+
output: unknown;
|
|
99
|
+
completed_at: string;
|
|
100
|
+
status: 'ok' | 'error' | 'timeout' | 'canceled';
|
|
101
|
+
error_code?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Tool call handler function.
|
|
105
|
+
*/
|
|
106
|
+
export type ToolCallHandler = (event: ToolCallEvent) => void | Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Tool result handler function.
|
|
109
|
+
*/
|
|
110
|
+
export type ToolResultHandler = (event: ToolResultEvent) => void | Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Plugin tool definition.
|
|
113
|
+
*/
|
|
114
|
+
export interface PluginTool {
|
|
115
|
+
name: string;
|
|
116
|
+
description: string;
|
|
117
|
+
parameters?: Record<string, unknown>;
|
|
118
|
+
execute: (params: Record<string, unknown>) => Promise<unknown>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a signer from a JWK private key.
|
|
122
|
+
*
|
|
123
|
+
* @param jwk - Ed25519 private key in JWK format
|
|
124
|
+
* @param issuer - Issuer URI for receipts
|
|
125
|
+
* @param audience - Optional audience URI
|
|
126
|
+
* @returns Signer instance
|
|
127
|
+
*/
|
|
128
|
+
export declare function createJwkSigner(jwk: JWK, issuer: string, audience?: string): Signer;
|
|
129
|
+
/**
|
|
130
|
+
* Resolve a signer from a key reference string.
|
|
131
|
+
*
|
|
132
|
+
* Supported formats:
|
|
133
|
+
* - env:VAR_NAME - Load key from environment variable
|
|
134
|
+
* - file:/path - Load from file (development only)
|
|
135
|
+
*
|
|
136
|
+
* @param keyRef - Key reference string
|
|
137
|
+
* @param issuer - Issuer URI
|
|
138
|
+
* @param audience - Optional audience URI
|
|
139
|
+
* @returns Promise resolving to Signer
|
|
140
|
+
*/
|
|
141
|
+
export declare function resolveSigner(keyRef: string, issuer: string, audience?: string): Promise<Signer>;
|
|
142
|
+
/**
|
|
143
|
+
* Generate a key ID from a JWK by hashing its public components.
|
|
144
|
+
*/
|
|
145
|
+
export declare function generateKeyId(jwk: JWK): string;
|
|
146
|
+
/**
|
|
147
|
+
* Create a file system receipt writer with atomic writes.
|
|
148
|
+
*
|
|
149
|
+
* Writes are atomic: write to .tmp, fsync, rename. This ensures
|
|
150
|
+
* partially written files are never observable.
|
|
151
|
+
*
|
|
152
|
+
* @param outputDir - Directory for receipt files
|
|
153
|
+
* @returns Promise resolving to ReceiptWriter
|
|
154
|
+
*/
|
|
155
|
+
export declare function createFileReceiptWriter(outputDir: string): Promise<ReceiptWriter>;
|
|
156
|
+
/**
|
|
157
|
+
* Plugin instance state.
|
|
158
|
+
*/
|
|
159
|
+
export interface PluginInstance {
|
|
160
|
+
/** Capture session */
|
|
161
|
+
session: CaptureSession;
|
|
162
|
+
/** Hook handler for tool calls */
|
|
163
|
+
hookHandler: OpenClawHookHandler;
|
|
164
|
+
/** Background emitter service */
|
|
165
|
+
backgroundService: BackgroundEmitterService;
|
|
166
|
+
/** Start the plugin */
|
|
167
|
+
start(): void;
|
|
168
|
+
/** Stop the plugin */
|
|
169
|
+
stop(): Promise<void>;
|
|
170
|
+
/** Get plugin stats */
|
|
171
|
+
getStats(): PluginStats;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Plugin statistics.
|
|
175
|
+
*/
|
|
176
|
+
export interface PluginStats {
|
|
177
|
+
totalCaptured: number;
|
|
178
|
+
duplicatesSkipped: number;
|
|
179
|
+
pendingCount: number;
|
|
180
|
+
totalEmitted: number;
|
|
181
|
+
totalErrors: number;
|
|
182
|
+
keyId: string;
|
|
183
|
+
isRunning: boolean;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Options for creating a plugin instance.
|
|
187
|
+
*/
|
|
188
|
+
export interface CreatePluginOptions {
|
|
189
|
+
/** Signer for receipts */
|
|
190
|
+
signer: Signer;
|
|
191
|
+
/** Receipt writer */
|
|
192
|
+
writer: ReceiptWriter;
|
|
193
|
+
/** Adapter configuration */
|
|
194
|
+
adapterConfig?: OpenClawAdapterConfig;
|
|
195
|
+
/** Spool store implementation (required) */
|
|
196
|
+
store: SpoolStore;
|
|
197
|
+
/** Dedupe index implementation (required) */
|
|
198
|
+
dedupe: DedupeIndex;
|
|
199
|
+
/** Background drain interval in ms (default: 1000) */
|
|
200
|
+
drainIntervalMs?: number;
|
|
201
|
+
/** Batch size for draining (default: 100) */
|
|
202
|
+
batchSize?: number;
|
|
203
|
+
/** Error callback */
|
|
204
|
+
onError?: (error: Error) => void;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Create a plugin instance.
|
|
208
|
+
*
|
|
209
|
+
* @param options - Plugin options
|
|
210
|
+
* @returns Plugin instance
|
|
211
|
+
*/
|
|
212
|
+
export declare function createPluginInstance(options: CreatePluginOptions): Promise<PluginInstance>;
|
|
213
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAqB,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAMtB;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAMD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;QACjC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,CAAC,EAAE;QACZ,gBAAgB,CAAC,E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c,CAAC,CA6IhG"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @peac/adapter-openclaw - Plugin Entry Point
|
|
4
|
+
*
|
|
5
|
+
* OpenClaw plugin types and utilities for PEAC receipts.
|
|
6
|
+
* This module provides types and factory functions for OpenClaw integration.
|
|
7
|
+
*
|
|
8
|
+
* Note: Full plugin activation requires OpenClaw's plugin runtime.
|
|
9
|
+
* The types and utilities here allow building custom integrations.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.createJwkSigner = createJwkSigner;
|
|
46
|
+
exports.resolveSigner = resolveSigner;
|
|
47
|
+
exports.generateKeyId = generateKeyId;
|
|
48
|
+
exports.createFileReceiptWriter = createFileReceiptWriter;
|
|
49
|
+
exports.createPluginInstance = createPluginInstance;
|
|
50
|
+
const capture_core_1 = require("@peac/capture-core");
|
|
51
|
+
const crypto_1 = require("@peac/crypto");
|
|
52
|
+
const hooks_js_1 = require("./hooks.js");
|
|
53
|
+
const emitter_js_1 = require("./emitter.js");
|
|
54
|
+
// =============================================================================
|
|
55
|
+
// Signer Creation
|
|
56
|
+
// =============================================================================
|
|
57
|
+
/**
|
|
58
|
+
* Create a signer from a JWK private key.
|
|
59
|
+
*
|
|
60
|
+
* @param jwk - Ed25519 private key in JWK format
|
|
61
|
+
* @param issuer - Issuer URI for receipts
|
|
62
|
+
* @param audience - Optional audience URI
|
|
63
|
+
* @returns Signer instance
|
|
64
|
+
*/
|
|
65
|
+
function createJwkSigner(jwk, issuer, audience) {
|
|
66
|
+
const kid = jwk.kid || generateKeyId(jwk);
|
|
67
|
+
// Extract the private key bytes from JWK
|
|
68
|
+
if (!jwk.d) {
|
|
69
|
+
throw new Error('JWK must include private key (d parameter)');
|
|
70
|
+
}
|
|
71
|
+
// Decode base64url to get raw key bytes
|
|
72
|
+
const privateKeyBytes = (0, crypto_1.base64urlDecode)(jwk.d);
|
|
73
|
+
return {
|
|
74
|
+
async sign(payload) {
|
|
75
|
+
return (0, crypto_1.sign)(payload, privateKeyBytes, kid);
|
|
76
|
+
},
|
|
77
|
+
getKeyId() {
|
|
78
|
+
return kid;
|
|
79
|
+
},
|
|
80
|
+
getIssuer() {
|
|
81
|
+
return issuer;
|
|
82
|
+
},
|
|
83
|
+
getAudience() {
|
|
84
|
+
return audience;
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolve a signer from a key reference string.
|
|
90
|
+
*
|
|
91
|
+
* Supported formats:
|
|
92
|
+
* - env:VAR_NAME - Load key from environment variable
|
|
93
|
+
* - file:/path - Load from file (development only)
|
|
94
|
+
*
|
|
95
|
+
* @param keyRef - Key reference string
|
|
96
|
+
* @param issuer - Issuer URI
|
|
97
|
+
* @param audience - Optional audience URI
|
|
98
|
+
* @returns Promise resolving to Signer
|
|
99
|
+
*/
|
|
100
|
+
async function resolveSigner(keyRef, issuer, audience) {
|
|
101
|
+
const colonIndex = keyRef.indexOf(':');
|
|
102
|
+
if (colonIndex === -1) {
|
|
103
|
+
throw new Error(`Invalid key reference format: ${keyRef}. Expected scheme:value`);
|
|
104
|
+
}
|
|
105
|
+
const scheme = keyRef.slice(0, colonIndex);
|
|
106
|
+
const value = keyRef.slice(colonIndex + 1);
|
|
107
|
+
switch (scheme) {
|
|
108
|
+
case 'env': {
|
|
109
|
+
const keyData = process.env[value];
|
|
110
|
+
if (!keyData) {
|
|
111
|
+
throw new Error(`Environment variable ${value} not set for signing key`);
|
|
112
|
+
}
|
|
113
|
+
const jwk = JSON.parse(keyData);
|
|
114
|
+
return createJwkSigner(jwk, issuer, audience);
|
|
115
|
+
}
|
|
116
|
+
case 'file': {
|
|
117
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
118
|
+
const keyData = await fs.promises.readFile(value, 'utf-8');
|
|
119
|
+
const jwk = JSON.parse(keyData);
|
|
120
|
+
return createJwkSigner(jwk, issuer, audience);
|
|
121
|
+
}
|
|
122
|
+
case 'keychain':
|
|
123
|
+
throw new Error('Keychain signing not yet implemented. Use env: for development.');
|
|
124
|
+
case 'sidecar':
|
|
125
|
+
throw new Error('Sidecar signing not yet implemented. Use env: for development.');
|
|
126
|
+
default:
|
|
127
|
+
throw new Error(`Unknown key reference scheme: ${scheme}. Use env: or file:`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Generate a key ID from a JWK by hashing its public components.
|
|
132
|
+
*/
|
|
133
|
+
function generateKeyId(jwk) {
|
|
134
|
+
const publicPart = jwk.x || '';
|
|
135
|
+
let hash = 0;
|
|
136
|
+
for (let i = 0; i < publicPart.length; i++) {
|
|
137
|
+
const char = publicPart.charCodeAt(i);
|
|
138
|
+
hash = (hash << 5) - hash + char;
|
|
139
|
+
hash = hash & hash;
|
|
140
|
+
}
|
|
141
|
+
return `k_${Math.abs(hash).toString(16).padStart(8, '0')}`;
|
|
142
|
+
}
|
|
143
|
+
// =============================================================================
|
|
144
|
+
// Receipt Writer
|
|
145
|
+
// =============================================================================
|
|
146
|
+
/**
|
|
147
|
+
* Create a file system receipt writer with atomic writes.
|
|
148
|
+
*
|
|
149
|
+
* Writes are atomic: write to .tmp, fsync, rename. This ensures
|
|
150
|
+
* partially written files are never observable.
|
|
151
|
+
*
|
|
152
|
+
* @param outputDir - Directory for receipt files
|
|
153
|
+
* @returns Promise resolving to ReceiptWriter
|
|
154
|
+
*/
|
|
155
|
+
async function createFileReceiptWriter(outputDir) {
|
|
156
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
157
|
+
const pathModule = await Promise.resolve().then(() => __importStar(require('path')));
|
|
158
|
+
// Use path.resolve for portability
|
|
159
|
+
const resolvedOutputDir = pathModule.resolve(outputDir);
|
|
160
|
+
// Ensure directory exists
|
|
161
|
+
await fs.promises.mkdir(resolvedOutputDir, { recursive: true });
|
|
162
|
+
return {
|
|
163
|
+
async write(receipt) {
|
|
164
|
+
const filename = `${receipt.rid}.peac.json`;
|
|
165
|
+
const filepath = pathModule.join(resolvedOutputDir, filename);
|
|
166
|
+
const tempPath = `${filepath}.tmp`;
|
|
167
|
+
const content = JSON.stringify({
|
|
168
|
+
rid: receipt.rid,
|
|
169
|
+
interaction_id: receipt.interaction_id,
|
|
170
|
+
entry_digest: receipt.entry_digest,
|
|
171
|
+
_jws: receipt.jws,
|
|
172
|
+
}, null, 2);
|
|
173
|
+
// Atomic write: write to .tmp, fsync, rename, fsync dir
|
|
174
|
+
await fs.promises.writeFile(tempPath, content, 'utf-8');
|
|
175
|
+
// fsync file for durability (open, sync, close)
|
|
176
|
+
const fd = await fs.promises.open(tempPath, 'r');
|
|
177
|
+
await fd.sync();
|
|
178
|
+
await fd.close();
|
|
179
|
+
// Atomic rename (POSIX guarantees atomicity)
|
|
180
|
+
await fs.promises.rename(tempPath, filepath);
|
|
181
|
+
// fsync parent directory for full crash durability (POSIX best practice)
|
|
182
|
+
// This ensures the rename is persisted even on power loss
|
|
183
|
+
// Best-effort: may fail on some platforms (Windows, network FS)
|
|
184
|
+
try {
|
|
185
|
+
const dirFd = await fs.promises.open(resolvedOutputDir, 'r');
|
|
186
|
+
await dirFd.sync();
|
|
187
|
+
await dirFd.close();
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// Directory fsync not supported on this platform - continue anyway
|
|
191
|
+
// Receipt is still atomic via rename, just not fully durable on power loss
|
|
192
|
+
}
|
|
193
|
+
return filepath;
|
|
194
|
+
},
|
|
195
|
+
async close() {
|
|
196
|
+
// No-op for file writer
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Create a plugin instance.
|
|
202
|
+
*
|
|
203
|
+
* @param options - Plugin options
|
|
204
|
+
* @returns Plugin instance
|
|
205
|
+
*/
|
|
206
|
+
async function createPluginInstance(options) {
|
|
207
|
+
const { signer, writer, adapterConfig, store, dedupe, drainIntervalMs = 1000, batchSize = 100, onError, } = options;
|
|
208
|
+
// Create hasher
|
|
209
|
+
const hasher = await (0, capture_core_1.createHasher)();
|
|
210
|
+
// Create capture session
|
|
211
|
+
const session = (0, capture_core_1.createCaptureSession)({
|
|
212
|
+
store,
|
|
213
|
+
dedupe,
|
|
214
|
+
hasher,
|
|
215
|
+
});
|
|
216
|
+
// Track stats
|
|
217
|
+
const stats = {
|
|
218
|
+
totalCaptured: 0,
|
|
219
|
+
duplicatesSkipped: 0,
|
|
220
|
+
pendingCount: 0,
|
|
221
|
+
totalEmitted: 0,
|
|
222
|
+
totalErrors: 0,
|
|
223
|
+
keyId: signer.getKeyId(),
|
|
224
|
+
isRunning: false,
|
|
225
|
+
};
|
|
226
|
+
// Create hook handler
|
|
227
|
+
const hookHandler = (0, hooks_js_1.createHookHandler)({
|
|
228
|
+
session,
|
|
229
|
+
config: adapterConfig,
|
|
230
|
+
onCapture: (result) => {
|
|
231
|
+
if (result.success) {
|
|
232
|
+
stats.totalCaptured++;
|
|
233
|
+
stats.pendingCount++;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
stats.duplicatesSkipped++;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
// Create receipt emitter
|
|
241
|
+
const emitter = (0, emitter_js_1.createReceiptEmitter)({
|
|
242
|
+
signer,
|
|
243
|
+
writer,
|
|
244
|
+
onEmit: (result) => {
|
|
245
|
+
if (result.success) {
|
|
246
|
+
stats.totalEmitted++;
|
|
247
|
+
stats.pendingCount = Math.max(0, stats.pendingCount - 1);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
onError: (error) => {
|
|
251
|
+
stats.totalErrors++;
|
|
252
|
+
if (onError)
|
|
253
|
+
onError(error);
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
// Track last emitted sequence for cursor-based emission
|
|
257
|
+
// This is the in-memory cursor; on restart, we rebuild from dedupe index
|
|
258
|
+
let lastEmittedSequence = 0;
|
|
259
|
+
// Mutex to prevent overlapping drain cycles
|
|
260
|
+
let drainInProgress = false;
|
|
261
|
+
// Create background service with proper cursor tracking
|
|
262
|
+
// Note: For full restart safety, the dedupe index should be persistent.
|
|
263
|
+
// The getPendingEntries filters out already-emitted entries using the dedupe index.
|
|
264
|
+
const backgroundService = (0, emitter_js_1.createBackgroundService)({
|
|
265
|
+
emitter,
|
|
266
|
+
drainIntervalMs,
|
|
267
|
+
getPendingEntries: async () => {
|
|
268
|
+
// Prevent overlapping drain cycles
|
|
269
|
+
if (drainInProgress)
|
|
270
|
+
return [];
|
|
271
|
+
drainInProgress = true;
|
|
272
|
+
try {
|
|
273
|
+
// Read entries after the last emitted sequence
|
|
274
|
+
const currentSequence = await store.getSequence();
|
|
275
|
+
if (currentSequence <= lastEmittedSequence)
|
|
276
|
+
return [];
|
|
277
|
+
// Read from cursor position
|
|
278
|
+
const entries = await store.read(lastEmittedSequence, batchSize);
|
|
279
|
+
// Filter out entries that are already emitted (restart safety)
|
|
280
|
+
// This uses the persistent dedupe index as source of truth
|
|
281
|
+
const pending = [];
|
|
282
|
+
for (const entry of entries) {
|
|
283
|
+
if (entry.sequence <= lastEmittedSequence)
|
|
284
|
+
continue;
|
|
285
|
+
// Check if already emitted in dedupe index
|
|
286
|
+
const dedupeEntry = await dedupe.get(entry.action.id);
|
|
287
|
+
if (dedupeEntry?.emitted)
|
|
288
|
+
continue;
|
|
289
|
+
pending.push(entry);
|
|
290
|
+
}
|
|
291
|
+
return pending;
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
drainInProgress = false;
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
markEmitted: async (digest) => {
|
|
298
|
+
// Find the entry with this digest and update cursor
|
|
299
|
+
const entries = await store.read(lastEmittedSequence, batchSize);
|
|
300
|
+
const entry = entries.find((e) => e.entry_digest === digest);
|
|
301
|
+
if (entry) {
|
|
302
|
+
// Update in-memory cursor
|
|
303
|
+
if (entry.sequence > lastEmittedSequence) {
|
|
304
|
+
lastEmittedSequence = entry.sequence;
|
|
305
|
+
}
|
|
306
|
+
// Mark in persistent dedupe index (restart-safe)
|
|
307
|
+
await dedupe.markEmitted(entry.action.id);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
onError,
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
session,
|
|
314
|
+
hookHandler,
|
|
315
|
+
backgroundService,
|
|
316
|
+
start() {
|
|
317
|
+
stats.isRunning = true;
|
|
318
|
+
backgroundService.start();
|
|
319
|
+
},
|
|
320
|
+
async stop() {
|
|
321
|
+
backgroundService.stop();
|
|
322
|
+
await backgroundService.drain();
|
|
323
|
+
await hookHandler.close();
|
|
324
|
+
stats.isRunning = false;
|
|
325
|
+
},
|
|
326
|
+
getStats() {
|
|
327
|
+
return { ...stats };
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuJH,0CA4BC;AAcD,sCAuCC;AAKD,sCASC;AAeD,0DAyDC;AAiED,oDA6IC;AAzgBD,qDAAwE;AACxE,yCAAqD;AAErD,yCAAyE;AACzE,6CAMsB;AA8HtB,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,GAAQ,EAAE,MAAc,EAAE,QAAiB;IACzE,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;IAE1C,yCAAyC;IACzC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,wCAAwC;IACxC,MAAM,eAAe,GAAG,IAAA,wBAAe,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAE/C,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,OAAgB;YACzB,OAAO,IAAA,aAAI,EAAC,OAA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,EAAE,CAAC;YAC1B,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC;QAC1B,CAAC;QAED,QAAQ;YACN,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @peac/adapter-openclaw - Plugin Tools
|
|
3
|
+
*
|
|
4
|
+
* Tools exposed by the PEAC receipts plugin for OpenClaw.
|
|
5
|
+
*
|
|
6
|
+
* @experimental This module is experimental and may change.
|
|
7
|
+
*/
|
|
8
|
+
import type { PluginTool, PluginLogger } from './plugin.js';
|
|
9
|
+
/**
|
|
10
|
+
* Plugin stats interface matching plugin.ts PluginStats.
|
|
11
|
+
*/
|
|
12
|
+
interface PluginStats {
|
|
13
|
+
totalCaptured: number;
|
|
14
|
+
duplicatesSkipped: number;
|
|
15
|
+
pendingCount: number;
|
|
16
|
+
totalEmitted: number;
|
|
17
|
+
totalErrors: number;
|
|
18
|
+
keyId: string;
|
|
19
|
+
isRunning: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create the peac_receipts.status tool.
|
|
23
|
+
* Shows spool size, last receipt time, and config summary.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createStatusTool(stats: PluginStats, outputDir: string): PluginTool;
|
|
26
|
+
/**
|
|
27
|
+
* Create the peac_receipts.export_bundle tool.
|
|
28
|
+
* Exports receipts as a bundle directory for audit.
|
|
29
|
+
*
|
|
30
|
+
* Note: Creates a directory structure, not a ZIP archive.
|
|
31
|
+
* Use @peac/audit createDisputeBundle for production ZIP bundles.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createExportBundleTool(outputDir: string, logger: PluginLogger): PluginTool;
|
|
34
|
+
/**
|
|
35
|
+
* Create the peac_receipts.verify tool.
|
|
36
|
+
* Verifies a receipt or bundle offline.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createVerifyTool(logger: PluginLogger): PluginTool;
|
|
39
|
+
/**
|
|
40
|
+
* Create the peac_receipts.query tool.
|
|
41
|
+
* Query receipts by workflow_id, tool name, or time range.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createQueryTool(outputDir: string, logger: PluginLogger): PluginTool;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiC5D;;GAEG;AACH,UAAU,WAAW;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;CACpB;AAMD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAoElF;AA4BD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CA2J1F;AAoBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAmDjE;AA6RD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAoNnF"}
|