openclaw-overlay-plugin 0.8.18 → 0.8.20
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/index.js +607 -853
- package/dist/index.js.map +4 -4
- package/dist/src/cli.js +30 -568
- package/dist/src/cli.js.map +4 -4
- package/package.json +5 -5
- package/index.ts +0 -379
- package/src/ambient.d.ts +0 -1
- package/src/cli-main.ts +0 -240
- package/src/cli.ts +0 -16
- package/src/compatibility.test.ts +0 -46
- package/src/scripts/baemail/commands.ts +0 -311
- package/src/scripts/baemail/handler.ts +0 -338
- package/src/scripts/baemail/index.ts +0 -6
- package/src/scripts/config.ts +0 -89
- package/src/scripts/index.ts +0 -8
- package/src/scripts/messaging/connect.ts +0 -162
- package/src/scripts/messaging/handlers.ts +0 -394
- package/src/scripts/messaging/inbox.ts +0 -64
- package/src/scripts/messaging/index.ts +0 -9
- package/src/scripts/messaging/poll.ts +0 -59
- package/src/scripts/messaging/send.ts +0 -54
- package/src/scripts/output.ts +0 -30
- package/src/scripts/overlay/advertisement.ts +0 -138
- package/src/scripts/overlay/discover.ts +0 -83
- package/src/scripts/overlay/index.ts +0 -8
- package/src/scripts/overlay/registration.ts +0 -199
- package/src/scripts/overlay/services.ts +0 -199
- package/src/scripts/overlay/transaction.ts +0 -124
- package/src/scripts/payment/build.ts +0 -65
- package/src/scripts/payment/commands.ts +0 -92
- package/src/scripts/payment/index.ts +0 -7
- package/src/scripts/payment/types.ts +0 -62
- package/src/scripts/services/index.ts +0 -7
- package/src/scripts/services/queue.ts +0 -35
- package/src/scripts/services/request.ts +0 -98
- package/src/scripts/services/respond.ts +0 -149
- package/src/scripts/types.ts +0 -121
- package/src/scripts/utils/index.ts +0 -7
- package/src/scripts/utils/merkle.ts +0 -57
- package/src/scripts/utils/storage.ts +0 -231
- package/src/scripts/utils/woc.ts +0 -106
- package/src/scripts/wallet/balance.ts +0 -277
- package/src/scripts/wallet/identity.ts +0 -204
- package/src/scripts/wallet/index.ts +0 -7
- package/src/scripts/wallet/setup.ts +0 -137
- package/src/scripts/x-verification/commands.ts +0 -261
- package/src/scripts/x-verification/index.ts +0 -5
- package/src/services/built-in/api-proxy/index.ts +0 -26
- package/src/services/built-in/api-proxy/prompt.md +0 -26
- package/src/services/built-in/code-develop/index.ts +0 -26
- package/src/services/built-in/code-develop/prompt.md +0 -35
- package/src/services/built-in/code-review/index.ts +0 -54
- package/src/services/built-in/code-review/prompt.md +0 -105
- package/src/services/built-in/image-analysis/index.ts +0 -36
- package/src/services/built-in/image-analysis/prompt.md +0 -42
- package/src/services/built-in/memory-store/index.ts +0 -25
- package/src/services/built-in/memory-store/prompt.md +0 -45
- package/src/services/built-in/roulette/index.ts +0 -30
- package/src/services/built-in/roulette/prompt.md +0 -35
- package/src/services/built-in/summarize/index.ts +0 -24
- package/src/services/built-in/summarize/prompt.md +0 -27
- package/src/services/built-in/tell-joke/handler.ts +0 -134
- package/src/services/built-in/tell-joke/index.ts +0 -34
- package/src/services/built-in/tell-joke/prompt.md +0 -59
- package/src/services/built-in/translate/index.ts +0 -24
- package/src/services/built-in/translate/prompt.md +0 -23
- package/src/services/built-in/web-research/index.ts +0 -54
- package/src/services/built-in/web-research/prompt.md +0 -110
- package/src/services/index.ts +0 -16
- package/src/services/loader.ts +0 -344
- package/src/services/manager.ts +0 -304
- package/src/services/registry.ts +0 -246
- package/src/services/types.ts +0 -259
- package/src/test/cli.test.ts +0 -353
- package/src/test/comprehensive-overlay.test.ts +0 -729
- package/src/test/identity-consistency.test.ts +0 -68
- package/src/test/key-derivation.test.ts +0 -102
- package/src/test/network-address.test.ts +0 -46
- package/src/test/overlay-submit.test.ts +0 -570
- package/src/test/request-response-flow.test.ts +0 -253
- package/src/test/service-system.test.ts +0 -241
- package/src/test/taskflow.test.ts +0 -95
- package/src/test/utils/server-logic.ts +0 -368
- package/src/test/wallet.test.ts +0 -165
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inbox and ack commands.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { OVERLAY_URL } from '../config.js';
|
|
6
|
-
import { ok, fail } from '../output.js';
|
|
7
|
-
import { loadIdentity, verifyRelaySignature } from '../wallet/identity.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Inbox command: fetch pending messages.
|
|
11
|
-
*/
|
|
12
|
-
export async function cmdInbox(args: string[]): Promise<any> {
|
|
13
|
-
const { identityKey } = await loadIdentity();
|
|
14
|
-
|
|
15
|
-
let since = '';
|
|
16
|
-
for (let i = 0; i < args.length; i++) {
|
|
17
|
-
if (args[i] === '--since' && args[i + 1]) since = `&since=${args[++i]}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const resp = await fetch(`${OVERLAY_URL}/relay/inbox?identity=${identityKey}${since}`);
|
|
21
|
-
if (!resp.ok) {
|
|
22
|
-
const body = await resp.text();
|
|
23
|
-
return fail(`Relay inbox failed (${resp.status}): ${body}`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const result = await resp.json();
|
|
27
|
-
|
|
28
|
-
// Verify signatures on received messages
|
|
29
|
-
const messages = await Promise.all(
|
|
30
|
-
result.messages.map(async (msg: any) => ({
|
|
31
|
-
...msg,
|
|
32
|
-
signatureValid: msg.signature
|
|
33
|
-
? (await verifyRelaySignature(msg.from, msg.to, msg.type, msg.payload, msg.signature)).valid
|
|
34
|
-
: null,
|
|
35
|
-
}))
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
return ok({ messages, count: messages.length, identityKey });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Ack command: acknowledge processed messages.
|
|
43
|
-
*/
|
|
44
|
-
export async function cmdAck(messageIds: string[]): Promise<any> {
|
|
45
|
-
if (!messageIds || messageIds.length === 0) {
|
|
46
|
-
return fail('Usage: ack <messageId> [messageId2 ...]');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const { identityKey } = await loadIdentity();
|
|
50
|
-
|
|
51
|
-
const resp = await fetch(`${OVERLAY_URL}/relay/ack`, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: { 'Content-Type': 'application/json' },
|
|
54
|
-
body: JSON.stringify({ identity: identityKey, messageIds }),
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (!resp.ok) {
|
|
58
|
-
const body = await resp.text();
|
|
59
|
-
return fail(`Relay ack failed (${resp.status}): ${body}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const result = await resp.json();
|
|
63
|
-
return ok({ acked: result.acked, messageIds });
|
|
64
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Poll command: fetch and process all pending messages.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { OVERLAY_URL } from '../config.js';
|
|
6
|
-
import { ok, fail } from '../output.js';
|
|
7
|
-
import { loadIdentity } from '../wallet/identity.js';
|
|
8
|
-
import { processMessage } from './handlers.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Poll command: fetch all pending messages and process them.
|
|
12
|
-
*/
|
|
13
|
-
export async function cmdPoll(): Promise<any> {
|
|
14
|
-
const { identityKey, privKey } = await loadIdentity();
|
|
15
|
-
|
|
16
|
-
// Fetch inbox
|
|
17
|
-
const inboxResp = await fetch(`${OVERLAY_URL}/relay/inbox?identity=${identityKey}`);
|
|
18
|
-
if (!inboxResp.ok) {
|
|
19
|
-
const body = await inboxResp.text();
|
|
20
|
-
return fail(`Relay inbox failed (${inboxResp.status}): ${body}`);
|
|
21
|
-
}
|
|
22
|
-
const inbox = await inboxResp.json();
|
|
23
|
-
|
|
24
|
-
if (inbox.count === 0) {
|
|
25
|
-
return ok({ processed: 0, messages: [], summary: 'No pending messages.' });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const processed: any[] = [];
|
|
29
|
-
const ackedIds: string[] = [];
|
|
30
|
-
const unhandled: any[] = [];
|
|
31
|
-
|
|
32
|
-
for (const msg of inbox.messages) {
|
|
33
|
-
const result = await processMessage(msg, identityKey, privKey);
|
|
34
|
-
if (result.ack) {
|
|
35
|
-
ackedIds.push(result.id);
|
|
36
|
-
processed.push(result);
|
|
37
|
-
} else {
|
|
38
|
-
unhandled.push(result);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ACK processed messages
|
|
43
|
-
if (ackedIds.length > 0) {
|
|
44
|
-
await fetch(`${OVERLAY_URL}/relay/ack`, {
|
|
45
|
-
method: 'POST',
|
|
46
|
-
headers: { 'Content-Type': 'application/json' },
|
|
47
|
-
body: JSON.stringify({ identity: identityKey, messageIds: ackedIds }),
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return ok({
|
|
52
|
-
processed: processed.length,
|
|
53
|
-
unhandled: unhandled.length,
|
|
54
|
-
total: inbox.count,
|
|
55
|
-
messages: processed,
|
|
56
|
-
unhandledMessages: unhandled,
|
|
57
|
-
ackedIds,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Send relay message command.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { OVERLAY_URL } from '../config.js';
|
|
6
|
-
import { ok, fail } from '../output.js';
|
|
7
|
-
import { loadIdentity, signRelayMessage } from '../wallet/identity.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Send command: send a typed message to another agent.
|
|
11
|
-
*/
|
|
12
|
-
export async function cmdSend(
|
|
13
|
-
targetKey: string | undefined,
|
|
14
|
-
type: string | undefined,
|
|
15
|
-
payloadStr: string | undefined
|
|
16
|
-
): Promise<any> {
|
|
17
|
-
if (!targetKey || !type || !payloadStr) {
|
|
18
|
-
return fail('Usage: send <identityKey> <type> <json_payload>');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (!/^0[23][0-9a-fA-F]{64}$/.test(targetKey)) {
|
|
22
|
-
return fail('Target must be a compressed public key (66 hex chars, 02/03 prefix)');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let payload: unknown;
|
|
26
|
-
try {
|
|
27
|
-
payload = JSON.parse(payloadStr);
|
|
28
|
-
} catch {
|
|
29
|
-
return fail('payload must be valid JSON');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const { identityKey, privKey } = await loadIdentity();
|
|
33
|
-
const signature = await signRelayMessage(privKey, targetKey, type, payload);
|
|
34
|
-
|
|
35
|
-
const resp = await fetch(`${OVERLAY_URL}/relay/send`, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
headers: { 'Content-Type': 'application/json' },
|
|
38
|
-
body: JSON.stringify({
|
|
39
|
-
from: identityKey,
|
|
40
|
-
to: targetKey,
|
|
41
|
-
type,
|
|
42
|
-
payload,
|
|
43
|
-
signature,
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (!resp.ok) {
|
|
48
|
-
const body = await resp.text();
|
|
49
|
-
return fail(`Relay send failed (${resp.status}): ${body}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const result = await resp.json();
|
|
53
|
-
return ok({ sent: true, messageId: result.id, to: targetKey, type, signed: true });
|
|
54
|
-
}
|
package/src/scripts/output.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON output helpers for CLI commands.
|
|
3
|
-
* All CLI output follows the { success, data/error } wrapper format.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Global flag to prevent exit when used as a library
|
|
7
|
-
let noExitFlag = false;
|
|
8
|
-
|
|
9
|
-
export function setNoExit(value: boolean) {
|
|
10
|
-
noExitFlag = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Output a successful result and exit (unless noExit is set).
|
|
15
|
-
*/
|
|
16
|
-
export function ok<T>(data: T): any {
|
|
17
|
-
if (noExitFlag) return { success: true, data };
|
|
18
|
-
console.log(JSON.stringify({ success: true, data }));
|
|
19
|
-
process.exit(0);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Output an error and exit (unless noExit is set).
|
|
24
|
-
*/
|
|
25
|
-
export function fail(error: string | Error): any {
|
|
26
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
27
|
-
if (noExitFlag) return { success: false, error: message };
|
|
28
|
-
console.log(JSON.stringify({ success: false, error: message }));
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SHIP and SLAP advertisement commands.
|
|
3
|
-
*
|
|
4
|
-
* SHIP: Service Health & Information Protocol (tm_ship)
|
|
5
|
-
* SLAP: Service Level Agreement Protocol (tm_slap)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { PushDrop, Utils } from '@bsv/sdk';
|
|
9
|
-
import { NETWORK, WALLET_DIR, TOPICS, DEFAULT_SLAP_TRACKERS } from '../config.js';
|
|
10
|
-
import { BSVAgentWallet } from 'openclaw-plugin-core';
|
|
11
|
-
import { ok, fail } from '../output.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Advertise a SHIP record.
|
|
15
|
-
* Announce that you host a specific Topic Manager (tm_).
|
|
16
|
-
*/
|
|
17
|
-
export async function cmdAdvertiseSHIP(domain?: string, topic?: string): Promise<any> {
|
|
18
|
-
if (!domain || !topic) {
|
|
19
|
-
return fail('Usage: advertise-ship <domain> <topic>');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!topic.startsWith('tm_')) {
|
|
23
|
-
return fail('Topic must start with "tm_"');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
|
|
28
|
-
const token = new PushDrop(wallet._setup.wallet);
|
|
29
|
-
|
|
30
|
-
// SHIP format: Payload is the domain hosting the topic
|
|
31
|
-
const fields = [Utils.toArray(domain, 'utf8')];
|
|
32
|
-
// Context is [0, topic] to identify the topic manager being advertised
|
|
33
|
-
const lockingScript = (await token.lock(fields, [0, topic], '1', 'self', true, true)).toHex();
|
|
34
|
-
|
|
35
|
-
const response = await wallet._setup.wallet.createAction({
|
|
36
|
-
description: `advertise SHIP for ${topic}`,
|
|
37
|
-
outputs: [{
|
|
38
|
-
lockingScript,
|
|
39
|
-
satoshis: 1,
|
|
40
|
-
outputDescription: 'SHIP advertisement',
|
|
41
|
-
basket: TOPICS.SHIP
|
|
42
|
-
}]
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Broadcast to primary overlay and SLAP trackers
|
|
46
|
-
const trackers = [
|
|
47
|
-
...DEFAULT_SLAP_TRACKERS[NETWORK]
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const results = await broadcastToTrackers(response.tx as number[], [TOPICS.SHIP, topic], trackers);
|
|
51
|
-
|
|
52
|
-
return ok({
|
|
53
|
-
advertised: 'SHIP',
|
|
54
|
-
topic,
|
|
55
|
-
domain,
|
|
56
|
-
txid: response.txid,
|
|
57
|
-
broadcasts: results
|
|
58
|
-
});
|
|
59
|
-
} catch (err: any) {
|
|
60
|
-
return fail(`SHIP advertisement failed: ${err.message}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Advertise a SLAP record.
|
|
66
|
-
* Announce that you host a specific Lookup Service (ls_).
|
|
67
|
-
*/
|
|
68
|
-
export async function cmdAdvertiseSLAP(domain?: string, service?: string): Promise<any> {
|
|
69
|
-
if (!domain || !service) {
|
|
70
|
-
return fail('Usage: advertise-slap <domain> <service>');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!service.startsWith('ls_')) {
|
|
74
|
-
return fail('Service must start with "ls_"');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
|
|
79
|
-
const token = new PushDrop(wallet._setup.wallet);
|
|
80
|
-
|
|
81
|
-
// SLAP format: Payload is the domain hosting the lookup service
|
|
82
|
-
const fields = [Utils.toArray(domain, 'utf8')];
|
|
83
|
-
// Context is [0, service] to identify the lookup service being advertised
|
|
84
|
-
const lockingScript = (await token.lock(fields, [0, service], '1', 'self', true, true)).toHex();
|
|
85
|
-
|
|
86
|
-
const response = await wallet._setup.wallet.createAction({
|
|
87
|
-
description: `advertise SLAP for ${service}`,
|
|
88
|
-
outputs: [{
|
|
89
|
-
lockingScript,
|
|
90
|
-
satoshis: 1,
|
|
91
|
-
outputDescription: 'SLAP advertisement',
|
|
92
|
-
basket: TOPICS.SLAP
|
|
93
|
-
}]
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Broadcast to primary overlay and SLAP trackers
|
|
97
|
-
const trackers = [
|
|
98
|
-
...DEFAULT_SLAP_TRACKERS[NETWORK]
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
const results = await broadcastToTrackers(response.tx as number[], [TOPICS.SLAP, service], trackers);
|
|
102
|
-
|
|
103
|
-
return ok({
|
|
104
|
-
advertised: 'SLAP',
|
|
105
|
-
service,
|
|
106
|
-
domain,
|
|
107
|
-
txid: response.txid,
|
|
108
|
-
broadcasts: results
|
|
109
|
-
});
|
|
110
|
-
} catch (err: any) {
|
|
111
|
-
return fail(`SLAP advertisement failed: ${err.message}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Helper to broadcast BEEF to multiple trackers/overlays.
|
|
117
|
-
*/
|
|
118
|
-
async function broadcastToTrackers(tx: number[], topics: string[], trackers: string[]) {
|
|
119
|
-
const results: Record<string, any> = {};
|
|
120
|
-
const body = new Uint8Array(tx);
|
|
121
|
-
|
|
122
|
-
for (const url of trackers) {
|
|
123
|
-
try {
|
|
124
|
-
const resp = await fetch(`${url.replace(/\/$/, '')}/submit`, {
|
|
125
|
-
method: 'POST',
|
|
126
|
-
headers: {
|
|
127
|
-
'Content-Type': 'application/octet-stream',
|
|
128
|
-
'X-Topics': JSON.stringify(topics)
|
|
129
|
-
},
|
|
130
|
-
body
|
|
131
|
-
});
|
|
132
|
-
results[url] = resp.ok ? 'success' : `error: ${resp.status}`;
|
|
133
|
-
} catch (err: any) {
|
|
134
|
-
results[url] = `failed: ${err.message}`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return results;
|
|
138
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Overlay discovery commands.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { OVERLAY_URL, LOOKUP_SERVICES } from '../config.js';
|
|
6
|
-
import { ok } from '../output.js';
|
|
7
|
-
import { lookupOverlay, parseOverlayOutput } from './transaction.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Discover command: query the overlay for agents and services.
|
|
11
|
-
*/
|
|
12
|
-
export async function cmdDiscover(args: string[]): Promise<any> {
|
|
13
|
-
|
|
14
|
-
// Parse flags
|
|
15
|
-
let serviceFilter: string | null = null;
|
|
16
|
-
let agentFilter: string | null = null;
|
|
17
|
-
|
|
18
|
-
for (let i = 0; i < args.length; i++) {
|
|
19
|
-
if (args[i] === '--service' && args[i + 1]) serviceFilter = args[++i];
|
|
20
|
-
else if (args[i] === '--agent' && args[i + 1]) agentFilter = args[++i];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const results: {
|
|
24
|
-
agents: any[];
|
|
25
|
-
services: any[];
|
|
26
|
-
agentError?: string;
|
|
27
|
-
serviceError?: string;
|
|
28
|
-
} = { agents: [], services: [] };
|
|
29
|
-
|
|
30
|
-
// Query agents
|
|
31
|
-
if (!serviceFilter) {
|
|
32
|
-
try {
|
|
33
|
-
const agentQuery = agentFilter ? { name: agentFilter } : { type: 'list' };
|
|
34
|
-
const agentResult = await lookupOverlay(LOOKUP_SERVICES.AGENTS, agentQuery);
|
|
35
|
-
|
|
36
|
-
if (agentResult.outputs) {
|
|
37
|
-
for (const output of agentResult.outputs) {
|
|
38
|
-
try {
|
|
39
|
-
const { data, txid } = await parseOverlayOutput(output.beef, output.outputIndex);
|
|
40
|
-
if (data?.type === 'identity') {
|
|
41
|
-
// Handle both 'name' and 'agentName' for backward compatibility
|
|
42
|
-
const name = data.name || data.agentName || 'Unknown Agent';
|
|
43
|
-
results.agents.push({ ...data, name, txid });
|
|
44
|
-
}
|
|
45
|
-
} catch { /* ignore */ }
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch (err: any) {
|
|
49
|
-
results.agentError = String(err);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Query services
|
|
54
|
-
if (!agentFilter) {
|
|
55
|
-
try {
|
|
56
|
-
const serviceQuery = serviceFilter ? { serviceType: serviceFilter } : {};
|
|
57
|
-
const serviceResult = await lookupOverlay(LOOKUP_SERVICES.SERVICES, serviceQuery);
|
|
58
|
-
|
|
59
|
-
if (serviceResult.outputs) {
|
|
60
|
-
for (const output of serviceResult.outputs) {
|
|
61
|
-
try {
|
|
62
|
-
const { data, txid } = await parseOverlayOutput(output.beef, output.outputIndex);
|
|
63
|
-
if (data?.type === 'service') {
|
|
64
|
-
results.services.push({ ...data, txid });
|
|
65
|
-
}
|
|
66
|
-
} catch { /* ignore */ }
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch (err: any) {
|
|
70
|
-
results.serviceError = String(err);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return ok({
|
|
75
|
-
overlayUrl: OVERLAY_URL,
|
|
76
|
-
agentCount: results.agents.length,
|
|
77
|
-
serviceCount: results.services.length,
|
|
78
|
-
agents: results.agents,
|
|
79
|
-
services: results.services,
|
|
80
|
-
...(results.agentError && { agentError: results.agentError }),
|
|
81
|
-
...(results.serviceError && { serviceError: results.serviceError }),
|
|
82
|
-
});
|
|
83
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Overlay registration commands: register, unregister.
|
|
3
|
-
*
|
|
4
|
-
* Registration creates an identity record on the overlay network with:
|
|
5
|
-
* - identityKey: compressed public key (66 hex chars)
|
|
6
|
-
* - name: agent display name
|
|
7
|
-
* - description: what the agent does
|
|
8
|
-
* - channels: contact methods (e.g., { overlay: "https://..." })
|
|
9
|
-
* - capabilities: what the agent can do (e.g., ["services", "jokes"])
|
|
10
|
-
* - timestamp: ISO 8601 registration time
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import fs from 'node:fs';
|
|
14
|
-
import { NETWORK, WALLET_DIR, OVERLAY_URL, PROTOCOL_ID, TOPICS, PATHS, AGENT_NAME, AGENT_DESCRIPTION } from '../config.js';
|
|
15
|
-
import { ok, fail } from '../output.js';
|
|
16
|
-
import { loadRegistration, saveRegistration, deleteRegistration, loadServices } from '../utils/storage.js';
|
|
17
|
-
import { buildRealOverlayTransaction } from './transaction.js';
|
|
18
|
-
import { Transaction, Beef, Script, PushDrop, WalletOutput } from '@bsv/sdk'
|
|
19
|
-
|
|
20
|
-
import { BSVAgentWallet } from 'openclaw-plugin-core';
|
|
21
|
-
|
|
22
|
-
async function getBSVAgentWallet(): Promise<typeof BSVAgentWallet> {
|
|
23
|
-
return BSVAgentWallet;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Register command: register this agent on the overlay network.
|
|
28
|
-
*/
|
|
29
|
-
export async function cmdRegister(): Promise<any> {
|
|
30
|
-
if (!fs.existsSync(PATHS.walletIdentity)) {
|
|
31
|
-
return fail('Wallet not initialized. Run: setup');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const BSVAgentWallet = await getBSVAgentWallet();
|
|
35
|
-
const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
|
|
36
|
-
const identityKey = await wallet.getIdentityKey();
|
|
37
|
-
await wallet.destroy();
|
|
38
|
-
|
|
39
|
-
const existingReg = loadRegistration();
|
|
40
|
-
if (existingReg && existingReg.identityKey === identityKey) {
|
|
41
|
-
return ok({
|
|
42
|
-
alreadyRegistered: true,
|
|
43
|
-
identityKey,
|
|
44
|
-
identityTxid: existingReg.identityTxid,
|
|
45
|
-
overlayUrl: OVERLAY_URL,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Agent metadata from environment/config
|
|
50
|
-
const agentName = AGENT_NAME;
|
|
51
|
-
const agentDescription = AGENT_DESCRIPTION;
|
|
52
|
-
|
|
53
|
-
// Build capabilities list based on what services we might offer
|
|
54
|
-
const capabilities: string[] = ['services'];
|
|
55
|
-
const services = loadServices();
|
|
56
|
-
if (services.some(s => s.serviceId === 'tell-joke')) {
|
|
57
|
-
capabilities.push('jokes');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Create identity record on-chain
|
|
61
|
-
// This payload format matches the openclaw-overlay server's expected schema
|
|
62
|
-
const identityPayload = {
|
|
63
|
-
protocol: PROTOCOL_ID,
|
|
64
|
-
type: 'identity' as const,
|
|
65
|
-
identityKey,
|
|
66
|
-
name: agentName,
|
|
67
|
-
description: agentDescription,
|
|
68
|
-
channels: {
|
|
69
|
-
overlay: OVERLAY_URL,
|
|
70
|
-
},
|
|
71
|
-
capabilities,
|
|
72
|
-
timestamp: new Date().toISOString(),
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
let identityResult: { txid: string; funded: string };
|
|
76
|
-
try {
|
|
77
|
-
identityResult = await buildRealOverlayTransaction(identityPayload, TOPICS.IDENTITY);
|
|
78
|
-
} catch (err: any) {
|
|
79
|
-
return fail(`Registration failed: ${err.message}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Optionally register services if pre-configured
|
|
83
|
-
let serviceTxid: string | null = null;
|
|
84
|
-
|
|
85
|
-
if (services.length > 0) {
|
|
86
|
-
// Register each service individually (server expects 'service' type, not 'service-bundle')
|
|
87
|
-
for (const service of services) {
|
|
88
|
-
const servicePayload = {
|
|
89
|
-
protocol: PROTOCOL_ID,
|
|
90
|
-
type: 'service' as const,
|
|
91
|
-
identityKey,
|
|
92
|
-
serviceId: service.serviceId,
|
|
93
|
-
name: service.name,
|
|
94
|
-
description: service.description,
|
|
95
|
-
pricing: {
|
|
96
|
-
model: 'per-task',
|
|
97
|
-
amountSats: service.priceSats,
|
|
98
|
-
},
|
|
99
|
-
timestamp: new Date().toISOString(),
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const serviceResult = await buildRealOverlayTransaction(servicePayload, TOPICS.SERVICES);
|
|
104
|
-
serviceTxid = serviceResult.txid; // Keep last one for backward compat
|
|
105
|
-
} catch {
|
|
106
|
-
// Non-fatal — identity registered but this service failed
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Save registration
|
|
112
|
-
const registration = {
|
|
113
|
-
identityKey,
|
|
114
|
-
agentName,
|
|
115
|
-
agentDescription,
|
|
116
|
-
overlayUrl: OVERLAY_URL,
|
|
117
|
-
identityTxid: identityResult.txid,
|
|
118
|
-
serviceTxid,
|
|
119
|
-
funded: identityResult.funded,
|
|
120
|
-
registeredAt: new Date().toISOString(),
|
|
121
|
-
};
|
|
122
|
-
saveRegistration(registration);
|
|
123
|
-
|
|
124
|
-
return ok({
|
|
125
|
-
registered: true,
|
|
126
|
-
identityKey,
|
|
127
|
-
identityTxid: identityResult.txid,
|
|
128
|
-
serviceTxid,
|
|
129
|
-
overlayUrl: OVERLAY_URL,
|
|
130
|
-
funded: identityResult.funded,
|
|
131
|
-
stateFile: PATHS.registration,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Unregister command: submit revocation tx to remove agent from overlay network.
|
|
137
|
-
*/
|
|
138
|
-
export async function cmdUnregister(): Promise<any> {
|
|
139
|
-
|
|
140
|
-
const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
|
|
141
|
-
const { outputs, BEEF } = await wallet._setup.wallet.listOutputs({ basket: TOPICS.IDENTITY, include: 'entire transactions' });
|
|
142
|
-
|
|
143
|
-
const token = new PushDrop(wallet._setup.wallet);
|
|
144
|
-
const unlockingScriptTemplate = await token.unlock([0, PROTOCOL_ID], '1', 'self', 'none', true)
|
|
145
|
-
const tempTx = new Transaction()
|
|
146
|
-
const beef = Beef.fromBinary(BEEF as number[])
|
|
147
|
-
outputs.forEach((o: WalletOutput) => {
|
|
148
|
-
const [txid, v] = o.outpoint.split('.')
|
|
149
|
-
const sourceOutputIndex = Number(v)
|
|
150
|
-
const sourceTransaction = beef.findTransactionForSigning(txid)
|
|
151
|
-
tempTx.addInput({
|
|
152
|
-
unlockingScriptTemplate,
|
|
153
|
-
sourceOutputIndex,
|
|
154
|
-
sourceTransaction
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
tempTx.addOutput({
|
|
158
|
-
lockingScript: Script.fromASM('OP_FALSE OP_RETURN 330123'),
|
|
159
|
-
satoshis: 0
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
await tempTx.sign()
|
|
163
|
-
|
|
164
|
-
const response = await wallet._setup.wallet.createAction({
|
|
165
|
-
inputBEEF: BEEF,
|
|
166
|
-
description: 'revoke registration token',
|
|
167
|
-
inputs: tempTx.inputs.map(o => ({
|
|
168
|
-
inputDescription: 'previous registration',
|
|
169
|
-
outpoint: o.sourceTXID + '.' + String(o.sourceOutputIndex),
|
|
170
|
-
unlockingScript: o.unlockingScript?.toHex() as string
|
|
171
|
-
}))
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
const txid = response.txid as string;
|
|
175
|
-
|
|
176
|
-
// --- Submit to overlay ---
|
|
177
|
-
// Use binary BEEF with X-Topics header (matches openclaw-overlay server API)
|
|
178
|
-
const submitResp = await fetch(`${OVERLAY_URL}/submit`, {
|
|
179
|
-
method: 'POST',
|
|
180
|
-
headers: {
|
|
181
|
-
'Content-Type': 'application/octet-stream',
|
|
182
|
-
'X-Topics': JSON.stringify([TOPICS.IDENTITY]),
|
|
183
|
-
},
|
|
184
|
-
body: new Uint8Array(response.tx as number[]),
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
if (!submitResp.ok) {
|
|
188
|
-
const errText = await submitResp.text();
|
|
189
|
-
throw new Error(`Overlay submission failed: ${submitResp.status} — ${errText}`);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Delete local registration
|
|
193
|
-
deleteRegistration();
|
|
194
|
-
|
|
195
|
-
return ok({
|
|
196
|
-
unregistered: true,
|
|
197
|
-
txid
|
|
198
|
-
});
|
|
199
|
-
}
|