beam-protocol-sdk 0.1.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/client.d.ts +63 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +254 -0
- package/dist/client.js.map +1 -0
- package/dist/directory.d.ts +15 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +82 -0
- package/dist/directory.js.map +1 -0
- package/dist/frames.d.ts +29 -0
- package/dist/frames.d.ts.map +1 -0
- package/dist/frames.js +133 -0
- package/dist/frames.js.map +1 -0
- package/dist/identity.d.ts +19 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +65 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BeamDirectory } from './directory.js';
|
|
2
|
+
import type { BeamClientConfig, BeamIdString, IntentFrame, ResultFrame, AgentRecord } from './types.js';
|
|
3
|
+
type IntentHandler = (frame: IntentFrame, respond: (options: {
|
|
4
|
+
success: boolean;
|
|
5
|
+
payload?: Record<string, unknown>;
|
|
6
|
+
error?: string;
|
|
7
|
+
errorCode?: string;
|
|
8
|
+
latency?: number;
|
|
9
|
+
}) => ResultFrame) => void | Promise<void>;
|
|
10
|
+
export declare class BeamClient {
|
|
11
|
+
private readonly _identity;
|
|
12
|
+
private readonly _directory;
|
|
13
|
+
private readonly _directoryUrl;
|
|
14
|
+
private _ws;
|
|
15
|
+
private _wsConnected;
|
|
16
|
+
private readonly _pendingResults;
|
|
17
|
+
private readonly _intentHandlers;
|
|
18
|
+
constructor(config: BeamClientConfig);
|
|
19
|
+
get beamId(): BeamIdString;
|
|
20
|
+
get directory(): BeamDirectory;
|
|
21
|
+
register(displayName: string, capabilities: string[]): Promise<AgentRecord>;
|
|
22
|
+
connect(): Promise<void>;
|
|
23
|
+
private _handleMessage;
|
|
24
|
+
send(to: BeamIdString, intent: string, payload?: Record<string, unknown>, timeoutMs?: number): Promise<ResultFrame>;
|
|
25
|
+
private _sendViaWebSocket;
|
|
26
|
+
private _sendViaHttp;
|
|
27
|
+
on(intent: string, handler: IntentHandler): this;
|
|
28
|
+
/**
|
|
29
|
+
* Send a natural language message to another agent.
|
|
30
|
+
* The receiving agent uses its LLM to interpret and respond.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const reply = await client.talk(
|
|
34
|
+
* 'clara@coppen.beam.directory',
|
|
35
|
+
* 'Was weißt du über Chris Schnorrenberg?'
|
|
36
|
+
* )
|
|
37
|
+
* console.log(reply.message) // Natural language response
|
|
38
|
+
* console.log(reply.structured) // Optional structured data
|
|
39
|
+
*/
|
|
40
|
+
talk(to: BeamIdString, message: string, options?: {
|
|
41
|
+
context?: Record<string, unknown>;
|
|
42
|
+
language?: string;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
message: string;
|
|
46
|
+
structured?: Record<string, unknown>;
|
|
47
|
+
raw: ResultFrame;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Register a natural language handler.
|
|
51
|
+
* Convenience wrapper that listens for conversation.message intents.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* client.onTalk(async (message, from, respond) => {
|
|
55
|
+
* const answer = await myLLM.generate(message)
|
|
56
|
+
* respond(answer)
|
|
57
|
+
* })
|
|
58
|
+
*/
|
|
59
|
+
onTalk(handler: (message: string, from: BeamIdString, respond: (reply: string, structured?: Record<string, unknown>) => void, frame: IntentFrame) => void | Promise<void>): this;
|
|
60
|
+
disconnect(): void;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceM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EAChB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,SAAS,SAAS,GACjB,OAAO,CAAC,WAAW,CAAC;IAUvB,OAAO,CAAC,iBAAiB;YAmBX,YAAY;IAa1B,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAKhD;;;;;;;;;;;OAWG;IACG,IAAI,CACR,EAAE,EAAE,YAAY,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,GACA,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,GAAG,EAAE,WAAW,CAAA;KAAE,CAAC;IA4BvF;;;;;;;;;OASG;IACH,MAAM,CACJ,OAAO,EAAE,CACP,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,EACtE,KAAK,EAAE,WAAW,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACxB,IAAI;IAiBP,UAAU,IAAI,IAAI;CAanB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { BeamIdentity } from './identity.js';
|
|
2
|
+
import { BeamDirectory } from './directory.js';
|
|
3
|
+
import { createIntentFrame, createResultFrame, signFrame, validateIntentFrame } from './frames.js';
|
|
4
|
+
async function openWebSocket(url) {
|
|
5
|
+
if (typeof globalThis.WebSocket !== 'undefined') {
|
|
6
|
+
return new globalThis.WebSocket(url);
|
|
7
|
+
}
|
|
8
|
+
// Node 18-20: use ws package
|
|
9
|
+
const { default: WS } = await import('ws');
|
|
10
|
+
return new WS(url);
|
|
11
|
+
}
|
|
12
|
+
export class BeamClient {
|
|
13
|
+
_identity;
|
|
14
|
+
_directory;
|
|
15
|
+
_directoryUrl;
|
|
16
|
+
_ws = null;
|
|
17
|
+
_wsConnected = false;
|
|
18
|
+
_pendingResults = new Map();
|
|
19
|
+
_intentHandlers = new Map();
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this._identity = BeamIdentity.fromData(config.identity);
|
|
22
|
+
this._directoryUrl = config.directoryUrl;
|
|
23
|
+
this._directory = new BeamDirectory({ baseUrl: config.directoryUrl });
|
|
24
|
+
}
|
|
25
|
+
get beamId() {
|
|
26
|
+
return this._identity.beamId;
|
|
27
|
+
}
|
|
28
|
+
get directory() {
|
|
29
|
+
return this._directory;
|
|
30
|
+
}
|
|
31
|
+
async register(displayName, capabilities) {
|
|
32
|
+
const parsed = BeamIdentity.parseBeamId(this._identity.beamId);
|
|
33
|
+
if (!parsed)
|
|
34
|
+
throw new Error('Invalid beam ID on identity');
|
|
35
|
+
return this._directory.register({
|
|
36
|
+
beamId: this._identity.beamId,
|
|
37
|
+
displayName,
|
|
38
|
+
capabilities,
|
|
39
|
+
publicKey: this._identity.publicKeyBase64,
|
|
40
|
+
org: parsed.org
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async connect() {
|
|
44
|
+
if (this._ws && this._wsConnected)
|
|
45
|
+
return;
|
|
46
|
+
// Convert http(s) scheme to ws(s) and append /ws path with beamId query param
|
|
47
|
+
const wsUrl = this._directoryUrl
|
|
48
|
+
.replace(/^http:\/\//, 'ws://')
|
|
49
|
+
.replace(/^https:\/\//, 'wss://')
|
|
50
|
+
.replace(/\/$/, '') + `/ws?beamId=${encodeURIComponent(this._identity.beamId)}`;
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
openWebSocket(wsUrl).then((ws) => {
|
|
53
|
+
this._ws = ws;
|
|
54
|
+
ws.onopen = () => {
|
|
55
|
+
// Wait for the server's connected message before resolving
|
|
56
|
+
};
|
|
57
|
+
ws.onmessage = (event) => {
|
|
58
|
+
this._handleMessage(event.data);
|
|
59
|
+
};
|
|
60
|
+
ws.onclose = () => {
|
|
61
|
+
this._wsConnected = false;
|
|
62
|
+
this._ws = null;
|
|
63
|
+
// Reject all pending results
|
|
64
|
+
for (const [nonce, pending] of this._pendingResults) {
|
|
65
|
+
clearTimeout(pending.timer);
|
|
66
|
+
pending.reject(new Error('WebSocket connection closed'));
|
|
67
|
+
this._pendingResults.delete(nonce);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
ws.onerror = (event) => {
|
|
71
|
+
if (!this._wsConnected) {
|
|
72
|
+
reject(new Error(`WebSocket connection error: ${String(event)}`));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
// We resolve after receiving the 'connected' message
|
|
76
|
+
const originalHandleMessage = this._handleMessage.bind(this);
|
|
77
|
+
this._handleMessage = (data) => {
|
|
78
|
+
try {
|
|
79
|
+
const msg = JSON.parse(data);
|
|
80
|
+
if (msg.type === 'connected') {
|
|
81
|
+
this._wsConnected = true;
|
|
82
|
+
this._handleMessage = originalHandleMessage;
|
|
83
|
+
resolve();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// ignore parse errors during connect phase
|
|
89
|
+
}
|
|
90
|
+
originalHandleMessage(data);
|
|
91
|
+
};
|
|
92
|
+
}).catch(reject);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
_handleMessage(data) {
|
|
96
|
+
let msg;
|
|
97
|
+
try {
|
|
98
|
+
msg = JSON.parse(data);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (msg['type'] === 'result') {
|
|
104
|
+
const frame = msg['frame'];
|
|
105
|
+
if (!frame)
|
|
106
|
+
return;
|
|
107
|
+
const pending = this._pendingResults.get(frame.nonce);
|
|
108
|
+
if (pending) {
|
|
109
|
+
clearTimeout(pending.timer);
|
|
110
|
+
this._pendingResults.delete(frame.nonce);
|
|
111
|
+
pending.resolve(frame);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (msg['type'] === 'intent') {
|
|
115
|
+
const frame = msg['frame'];
|
|
116
|
+
const senderPublicKey = msg['senderPublicKey'];
|
|
117
|
+
if (!frame || !senderPublicKey)
|
|
118
|
+
return;
|
|
119
|
+
const validation = validateIntentFrame(frame, senderPublicKey);
|
|
120
|
+
if (!validation.valid)
|
|
121
|
+
return;
|
|
122
|
+
const handler = this._intentHandlers.get(frame.intent) ?? this._intentHandlers.get('*');
|
|
123
|
+
if (!handler)
|
|
124
|
+
return;
|
|
125
|
+
const startTime = Date.now();
|
|
126
|
+
const respond = (options) => {
|
|
127
|
+
const latency = options.latency ?? (Date.now() - startTime);
|
|
128
|
+
const resultFrame = createResultFrame({ ...options, nonce: frame.nonce, latency }, this._identity);
|
|
129
|
+
if (this._ws && this._wsConnected) {
|
|
130
|
+
this._ws.send(JSON.stringify({ type: 'result', frame: resultFrame }));
|
|
131
|
+
}
|
|
132
|
+
return resultFrame;
|
|
133
|
+
};
|
|
134
|
+
Promise.resolve(handler(frame, respond)).catch(() => {
|
|
135
|
+
// Swallow handler errors to avoid unhandled rejections
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async send(to, intent, payload, timeoutMs = 30_000) {
|
|
140
|
+
const frame = createIntentFrame({ intent, from: this._identity.beamId, to, payload }, this._identity);
|
|
141
|
+
signFrame(frame, this._identity.export().privateKeyBase64);
|
|
142
|
+
if (this._ws && this._wsConnected) {
|
|
143
|
+
return this._sendViaWebSocket(frame, timeoutMs);
|
|
144
|
+
}
|
|
145
|
+
return this._sendViaHttp(frame);
|
|
146
|
+
}
|
|
147
|
+
_sendViaWebSocket(frame, timeoutMs) {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const timer = setTimeout(() => {
|
|
150
|
+
this._pendingResults.delete(frame.nonce);
|
|
151
|
+
reject(new Error(`Intent "${frame.intent}" timed out after ${timeoutMs}ms`));
|
|
152
|
+
}, timeoutMs);
|
|
153
|
+
this._pendingResults.set(frame.nonce, { resolve, reject, timer });
|
|
154
|
+
try {
|
|
155
|
+
this._ws.send(JSON.stringify({ type: 'intent', frame }));
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
this._pendingResults.delete(frame.nonce);
|
|
160
|
+
reject(err);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async _sendViaHttp(frame) {
|
|
165
|
+
const baseUrl = this._directoryUrl.replace(/\/$/, '');
|
|
166
|
+
const res = await fetch(`${baseUrl}/intents`, {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
headers: { 'Content-Type': 'application/json' },
|
|
169
|
+
body: JSON.stringify(frame)
|
|
170
|
+
});
|
|
171
|
+
if (!res.ok) {
|
|
172
|
+
throw new Error(`HTTP intent delivery failed: ${res.status} ${res.statusText}`);
|
|
173
|
+
}
|
|
174
|
+
return res.json();
|
|
175
|
+
}
|
|
176
|
+
on(intent, handler) {
|
|
177
|
+
this._intentHandlers.set(intent, handler);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Send a natural language message to another agent.
|
|
182
|
+
* The receiving agent uses its LLM to interpret and respond.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* const reply = await client.talk(
|
|
186
|
+
* 'clara@coppen.beam.directory',
|
|
187
|
+
* 'Was weißt du über Chris Schnorrenberg?'
|
|
188
|
+
* )
|
|
189
|
+
* console.log(reply.message) // Natural language response
|
|
190
|
+
* console.log(reply.structured) // Optional structured data
|
|
191
|
+
*/
|
|
192
|
+
async talk(to, message, options) {
|
|
193
|
+
if (!message || message.length === 0) {
|
|
194
|
+
throw new Error('Message must be non-empty');
|
|
195
|
+
}
|
|
196
|
+
if (message.length > 32768) {
|
|
197
|
+
throw new Error('Message exceeds maximum length of 32768 characters');
|
|
198
|
+
}
|
|
199
|
+
const payload = {
|
|
200
|
+
message,
|
|
201
|
+
};
|
|
202
|
+
if (options?.context)
|
|
203
|
+
payload['context'] = options.context;
|
|
204
|
+
if (options?.language)
|
|
205
|
+
payload['language'] = options.language;
|
|
206
|
+
const result = await this.send(to, 'conversation.message', payload, options?.timeoutMs ?? 60_000 // Longer default for NL (LLM processing)
|
|
207
|
+
);
|
|
208
|
+
return {
|
|
209
|
+
message: result.payload?.['message'] ?? '',
|
|
210
|
+
structured: result.payload?.['structured'],
|
|
211
|
+
raw: result,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Register a natural language handler.
|
|
216
|
+
* Convenience wrapper that listens for conversation.message intents.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* client.onTalk(async (message, from, respond) => {
|
|
220
|
+
* const answer = await myLLM.generate(message)
|
|
221
|
+
* respond(answer)
|
|
222
|
+
* })
|
|
223
|
+
*/
|
|
224
|
+
onTalk(handler) {
|
|
225
|
+
this.on('conversation.message', (frame, rawRespond) => {
|
|
226
|
+
const message = frame.payload?.['message'] ?? '';
|
|
227
|
+
const respond = (reply, structured) => {
|
|
228
|
+
rawRespond({
|
|
229
|
+
success: true,
|
|
230
|
+
payload: {
|
|
231
|
+
message: reply,
|
|
232
|
+
...(structured ? { structured } : {}),
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
return handler(message, frame.from, respond, frame);
|
|
237
|
+
});
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
disconnect() {
|
|
241
|
+
if (this._ws) {
|
|
242
|
+
this._wsConnected = false;
|
|
243
|
+
// Reject all pending results before closing
|
|
244
|
+
for (const [nonce, pending] of this._pendingResults) {
|
|
245
|
+
clearTimeout(pending.timer);
|
|
246
|
+
pending.reject(new Error('Client disconnected'));
|
|
247
|
+
this._pendingResults.delete(nonce);
|
|
248
|
+
}
|
|
249
|
+
this._ws.close();
|
|
250
|
+
this._ws = null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAqClG,KAAK,UAAU,aAAa,CAAC,GAAW;IACtC,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;QAChD,OAAO,IAAK,UAAU,CAAC,SAAgD,CAAC,GAAG,CAAC,CAAA;IAC9E,CAAC;IACD,6BAA6B;IAC7B,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1C,OAAO,IAAI,EAAE,CAAC,GAAG,CAA6B,CAAA;AAChD,CAAC;AAED,MAAM,OAAO,UAAU;IACJ,SAAS,CAAc;IACvB,UAAU,CAAe;IACzB,aAAa,CAAQ;IAC9B,GAAG,GAAyB,IAAI,CAAA;IAChC,YAAY,GAAG,KAAK,CAAA;IACX,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAA;IAClD,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAA;IAEnE,YAAY,MAAwB;QAClC,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACvD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,YAAY,CA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C,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC3B,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAA;gBAChD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACpC,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;YAChB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentRecord, AgentRegistration, AgentSearchQuery, BeamIdString, DirectoryConfig } from './types.js';
|
|
2
|
+
export declare class BeamDirectoryError extends Error {
|
|
3
|
+
readonly statusCode: number;
|
|
4
|
+
constructor(message: string, statusCode: number);
|
|
5
|
+
}
|
|
6
|
+
export declare class BeamDirectory {
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
private readonly headers;
|
|
9
|
+
constructor(config: DirectoryConfig);
|
|
10
|
+
register(registration: AgentRegistration): Promise<AgentRecord>;
|
|
11
|
+
lookup(beamId: BeamIdString): Promise<AgentRecord | null>;
|
|
12
|
+
search(query: AgentSearchQuery): Promise<AgentRecord[]>;
|
|
13
|
+
heartbeat(beamId: BeamIdString): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,eAAe,EAChB,MAAM,YAAY,CAAA;AAiBnB,qBAAa,kBAAmB,SAAQ,KAAK;aAGzB,UAAU,EAAE,MAAM;gBADlC,OAAO,EAAE,MAAM,EACC,UAAU,EAAE,MAAM;CAKrC;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;gBAEpC,MAAM,EAAE,eAAe;IAQ7B,QAAQ,CAAC,YAAY,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAa/D,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IASzD,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAcvD,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CASrD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Normalize snake_case server response to camelCase AgentRecord */
|
|
2
|
+
function normalizeAgent(raw) {
|
|
3
|
+
return {
|
|
4
|
+
beamId: (raw.beamId ?? raw.beam_id),
|
|
5
|
+
displayName: (raw.displayName ?? raw.display_name ?? ''),
|
|
6
|
+
capabilities: (raw.capabilities ?? []),
|
|
7
|
+
publicKey: (raw.publicKey ?? raw.public_key ?? ''),
|
|
8
|
+
org: (raw.org ?? ''),
|
|
9
|
+
trustScore: (raw.trustScore ?? raw.trust_score ?? 0),
|
|
10
|
+
verified: (raw.verified ?? false),
|
|
11
|
+
createdAt: (raw.createdAt ?? raw.created_at ?? ''),
|
|
12
|
+
lastSeen: (raw.lastSeen ?? raw.last_seen ?? ''),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export class BeamDirectoryError extends Error {
|
|
16
|
+
statusCode;
|
|
17
|
+
constructor(message, statusCode) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.statusCode = statusCode;
|
|
20
|
+
this.name = 'BeamDirectoryError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class BeamDirectory {
|
|
24
|
+
baseUrl;
|
|
25
|
+
headers;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
28
|
+
this.headers = {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
...(config.apiKey && { Authorization: `Bearer ${config.apiKey}` })
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async register(registration) {
|
|
34
|
+
const res = await fetch(`${this.baseUrl}/agents/register`, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: this.headers,
|
|
37
|
+
body: JSON.stringify(registration)
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
41
|
+
throw new BeamDirectoryError(`Registration failed: ${body.error}`, res.status);
|
|
42
|
+
}
|
|
43
|
+
return res.json();
|
|
44
|
+
}
|
|
45
|
+
async lookup(beamId) {
|
|
46
|
+
const res = await fetch(`${this.baseUrl}/agents/${encodeURIComponent(beamId)}`, {
|
|
47
|
+
headers: this.headers
|
|
48
|
+
});
|
|
49
|
+
if (res.status === 404)
|
|
50
|
+
return null;
|
|
51
|
+
if (!res.ok)
|
|
52
|
+
throw new BeamDirectoryError(`Lookup failed: ${res.statusText}`, res.status);
|
|
53
|
+
return res.json();
|
|
54
|
+
}
|
|
55
|
+
async search(query) {
|
|
56
|
+
const params = new URLSearchParams();
|
|
57
|
+
if (query.org)
|
|
58
|
+
params.set('org', query.org);
|
|
59
|
+
if (query.capabilities?.length)
|
|
60
|
+
params.set('capabilities', query.capabilities.join(','));
|
|
61
|
+
if (query.minTrustScore !== undefined)
|
|
62
|
+
params.set('minTrustScore', String(query.minTrustScore));
|
|
63
|
+
if (query.limit !== undefined)
|
|
64
|
+
params.set('limit', String(query.limit));
|
|
65
|
+
const res = await fetch(`${this.baseUrl}/agents/search?${params}`, { headers: this.headers });
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
throw new BeamDirectoryError(`Search failed: ${res.statusText}`, res.status);
|
|
68
|
+
const body = await res.json();
|
|
69
|
+
const raw = Array.isArray(body) ? body : (body?.agents ?? []);
|
|
70
|
+
return raw.map(normalizeAgent);
|
|
71
|
+
}
|
|
72
|
+
async heartbeat(beamId) {
|
|
73
|
+
const res = await fetch(`${this.baseUrl}/agents/${encodeURIComponent(beamId)}/heartbeat`, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: this.headers
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok && res.status !== 404) {
|
|
78
|
+
throw new BeamDirectoryError(`Heartbeat failed: ${res.statusText}`, res.status);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAQA,oEAAoE;AACpE,SAAS,cAAc,CAAC,GAA4B;IAClD,OAAO;QACL,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,OAAO,CAA0B;QAC5D,WAAW,EAAE,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,CAAW;QAClE,YAAY,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAa;QAClD,SAAS,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,UAAU,IAAI,EAAE,CAAW;QAC5D,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAW;QAC9B,UAAU,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,WAAW,IAAI,CAAC,CAAW;QAC9D,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,KAAK,CAAY;QAC5C,SAAS,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,UAAU,IAAI,EAAE,CAAW;QAC5D,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,SAAS,IAAI,EAAE,CAAW;KAC1D,CAAA;AACH,CAAC;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzB;IA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C,MAAM,CAAC,CAAA;QACzF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAwE,CAAA;QACnG,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,CAAC,CAAA;QAC7D,OAAO,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAoB;QAClC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,kBAAkB,CAAC,MAAM,CAAC,YAAY,EAAE;YACxF,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;QACF,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAClC,MAAM,IAAI,kBAAkB,CAAC,qBAAqB,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QACjF,CAAC;IACH,CAAC;CACF"}
|
package/dist/frames.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IntentFrame, ResultFrame, BeamIdString } from './types.js';
|
|
2
|
+
import { BeamIdentity } from './identity.js';
|
|
3
|
+
export declare const MAX_FRAME_SIZE: number;
|
|
4
|
+
export declare const REPLAY_WINDOW_MS: number;
|
|
5
|
+
export declare function createIntentFrame(options: {
|
|
6
|
+
intent: string;
|
|
7
|
+
from: BeamIdString;
|
|
8
|
+
to: BeamIdString;
|
|
9
|
+
payload?: Record<string, unknown>;
|
|
10
|
+
}, identity: BeamIdentity): IntentFrame;
|
|
11
|
+
export declare function signFrame(frame: IntentFrame, privateKeyBase64: string): IntentFrame;
|
|
12
|
+
export declare function createResultFrame(options: {
|
|
13
|
+
nonce: string;
|
|
14
|
+
success: boolean;
|
|
15
|
+
payload?: Record<string, unknown>;
|
|
16
|
+
error?: string;
|
|
17
|
+
errorCode?: string;
|
|
18
|
+
latency?: number;
|
|
19
|
+
}, identity: BeamIdentity): ResultFrame;
|
|
20
|
+
export declare function validateIntentFrame(frame: unknown, senderPublicKey: string): {
|
|
21
|
+
valid: boolean;
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function validateResultFrame(frame: unknown, senderPublicKey: string): {
|
|
25
|
+
valid: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function canonicalizeFrame(frame: Record<string, unknown>): string;
|
|
29
|
+
//# sourceMappingURL=frames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.d.ts","sourceRoot":"","sources":["../src/frames.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,eAAO,MAAM,cAAc,QAAW,CAAA;AACtC,eAAO,MAAM,gBAAgB,QAAgB,CAAA;AAE7C,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,YAAY,CAAA;IAClB,EAAE,EAAE,YAAY,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC,EACD,QAAQ,EAAE,YAAY,GACrB,WAAW,CAWb;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAiBnF;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,EACD,QAAQ,EAAE,YAAY,GACrB,WAAW,CAab;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,MAAM,GACtB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CA8CpC;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,MAAM,GACtB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAkBpC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAExE"}
|
package/dist/frames.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { randomUUID, createPrivateKey, sign } from 'node:crypto';
|
|
2
|
+
import { BeamIdentity } from './identity.js';
|
|
3
|
+
export const MAX_FRAME_SIZE = 4 * 1024; // 4KB hard limit
|
|
4
|
+
export const REPLAY_WINDOW_MS = 5 * 60 * 1000; // 5 minutes
|
|
5
|
+
export function createIntentFrame(options, identity) {
|
|
6
|
+
const frame = {
|
|
7
|
+
v: '1',
|
|
8
|
+
intent: options.intent,
|
|
9
|
+
from: options.from,
|
|
10
|
+
to: options.to,
|
|
11
|
+
payload: options.payload ?? {},
|
|
12
|
+
nonce: randomUUID(),
|
|
13
|
+
timestamp: new Date().toISOString()
|
|
14
|
+
};
|
|
15
|
+
return signFrame(frame, identity.export().privateKeyBase64);
|
|
16
|
+
}
|
|
17
|
+
export function signFrame(frame, privateKeyBase64) {
|
|
18
|
+
const signedPayload = JSON.stringify({
|
|
19
|
+
type: 'intent',
|
|
20
|
+
from: frame.from,
|
|
21
|
+
to: frame.to,
|
|
22
|
+
intent: frame.intent,
|
|
23
|
+
payload: frame.payload,
|
|
24
|
+
timestamp: frame.timestamp,
|
|
25
|
+
nonce: frame.nonce,
|
|
26
|
+
});
|
|
27
|
+
const privateKey = createPrivateKey({
|
|
28
|
+
key: Buffer.from(privateKeyBase64, 'base64'),
|
|
29
|
+
format: 'der',
|
|
30
|
+
type: 'pkcs8',
|
|
31
|
+
});
|
|
32
|
+
frame.signature = sign(null, Buffer.from(signedPayload, 'utf8'), privateKey).toString('base64');
|
|
33
|
+
return frame;
|
|
34
|
+
}
|
|
35
|
+
export function createResultFrame(options, identity) {
|
|
36
|
+
const frame = {
|
|
37
|
+
v: '1',
|
|
38
|
+
success: options.success,
|
|
39
|
+
nonce: options.nonce,
|
|
40
|
+
timestamp: new Date().toISOString(),
|
|
41
|
+
...(options.payload !== undefined && { payload: options.payload }),
|
|
42
|
+
...(options.error !== undefined && { error: options.error }),
|
|
43
|
+
...(options.errorCode !== undefined && { errorCode: options.errorCode }),
|
|
44
|
+
...(options.latency !== undefined && { latency: options.latency })
|
|
45
|
+
};
|
|
46
|
+
frame.signature = identity.sign(canonicalizeFrame(frame));
|
|
47
|
+
return frame;
|
|
48
|
+
}
|
|
49
|
+
export function validateIntentFrame(frame, senderPublicKey) {
|
|
50
|
+
if (!frame || typeof frame !== 'object') {
|
|
51
|
+
return { valid: false, error: 'Frame must be an object' };
|
|
52
|
+
}
|
|
53
|
+
const f = frame;
|
|
54
|
+
if (f['v'] !== '1')
|
|
55
|
+
return { valid: false, error: 'Invalid protocol version' };
|
|
56
|
+
if (typeof f['intent'] !== 'string' || !f['intent'])
|
|
57
|
+
return { valid: false, error: 'Missing or empty intent' };
|
|
58
|
+
if (typeof f['from'] !== 'string' || !BeamIdentity.parseBeamId(f['from'])) {
|
|
59
|
+
return { valid: false, error: 'Invalid from Beam ID' };
|
|
60
|
+
}
|
|
61
|
+
if (typeof f['to'] !== 'string' || !BeamIdentity.parseBeamId(f['to'])) {
|
|
62
|
+
return { valid: false, error: 'Invalid to Beam ID' };
|
|
63
|
+
}
|
|
64
|
+
if (typeof f['nonce'] !== 'string' || !f['nonce'])
|
|
65
|
+
return { valid: false, error: 'Missing nonce' };
|
|
66
|
+
if (typeof f['timestamp'] !== 'string')
|
|
67
|
+
return { valid: false, error: 'Missing timestamp' };
|
|
68
|
+
if (!f['payload'] || typeof f['payload'] !== 'object' || Array.isArray(f['payload'])) {
|
|
69
|
+
return { valid: false, error: 'Payload must be an object' };
|
|
70
|
+
}
|
|
71
|
+
const size = Buffer.byteLength(JSON.stringify(frame), 'utf8');
|
|
72
|
+
if (size > MAX_FRAME_SIZE) {
|
|
73
|
+
return { valid: false, error: `Frame size ${size} exceeds limit of ${MAX_FRAME_SIZE} bytes` };
|
|
74
|
+
}
|
|
75
|
+
const frameTime = new Date(f['timestamp']).getTime();
|
|
76
|
+
if (isNaN(frameTime))
|
|
77
|
+
return { valid: false, error: 'Invalid timestamp format' };
|
|
78
|
+
if (Math.abs(Date.now() - frameTime) > REPLAY_WINDOW_MS) {
|
|
79
|
+
return { valid: false, error: 'Frame timestamp outside replay window (±5 minutes)' };
|
|
80
|
+
}
|
|
81
|
+
if (typeof f['signature'] !== 'string')
|
|
82
|
+
return { valid: false, error: 'Missing signature' };
|
|
83
|
+
const signedPayload = JSON.stringify({
|
|
84
|
+
type: 'intent',
|
|
85
|
+
from: f['from'],
|
|
86
|
+
to: f['to'],
|
|
87
|
+
intent: f['intent'],
|
|
88
|
+
payload: f['payload'],
|
|
89
|
+
timestamp: f['timestamp'],
|
|
90
|
+
nonce: f['nonce'],
|
|
91
|
+
});
|
|
92
|
+
if (!BeamIdentity.verify(signedPayload, f['signature'], senderPublicKey)) {
|
|
93
|
+
return { valid: false, error: 'Signature verification failed' };
|
|
94
|
+
}
|
|
95
|
+
return { valid: true };
|
|
96
|
+
}
|
|
97
|
+
export function validateResultFrame(frame, senderPublicKey) {
|
|
98
|
+
if (!frame || typeof frame !== 'object') {
|
|
99
|
+
return { valid: false, error: 'Frame must be an object' };
|
|
100
|
+
}
|
|
101
|
+
const f = frame;
|
|
102
|
+
if (f['v'] !== '1')
|
|
103
|
+
return { valid: false, error: 'Invalid protocol version' };
|
|
104
|
+
if (typeof f['success'] !== 'boolean')
|
|
105
|
+
return { valid: false, error: 'Missing success boolean' };
|
|
106
|
+
if (typeof f['nonce'] !== 'string' || !f['nonce'])
|
|
107
|
+
return { valid: false, error: 'Missing nonce' };
|
|
108
|
+
if (typeof f['timestamp'] !== 'string')
|
|
109
|
+
return { valid: false, error: 'Missing timestamp' };
|
|
110
|
+
if (typeof f['signature'] !== 'string')
|
|
111
|
+
return { valid: false, error: 'Missing signature' };
|
|
112
|
+
const { signature, ...unsigned } = f;
|
|
113
|
+
if (!BeamIdentity.verify(canonicalizeFrame(unsigned), signature, senderPublicKey)) {
|
|
114
|
+
return { valid: false, error: 'Signature verification failed' };
|
|
115
|
+
}
|
|
116
|
+
return { valid: true };
|
|
117
|
+
}
|
|
118
|
+
export function canonicalizeFrame(frame) {
|
|
119
|
+
return JSON.stringify(deepSortKeys(frame));
|
|
120
|
+
}
|
|
121
|
+
function deepSortKeys(value) {
|
|
122
|
+
if (Array.isArray(value))
|
|
123
|
+
return value.map(deepSortKeys);
|
|
124
|
+
if (value !== null && typeof value === 'object') {
|
|
125
|
+
const sorted = {};
|
|
126
|
+
for (const key of Object.keys(value).sort()) {
|
|
127
|
+
sorted[key] = deepSortKeys(value[key]);
|
|
128
|
+
}
|
|
129
|
+
return sorted;
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=frames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.js","sourceRoot":"","sources":["../src/frames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,MAAM,CAAC,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,EAAE,+BAA+B,EAAE,CAAA;IACjE,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAA8B;IAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;AAC5C,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;IACxD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,MAAM,GAA4B,EAAE,CAAA;QAC1C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACtD,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAE,KAAiC,CAAC,GAAG,CAAC,CAAC,CAAA;QACrE,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BeamIdString, BeamIdentityConfig, BeamIdentityData } from './types.js';
|
|
2
|
+
export declare class BeamIdentity {
|
|
3
|
+
readonly beamId: BeamIdString;
|
|
4
|
+
readonly publicKeyBase64: string;
|
|
5
|
+
private readonly _privateKey;
|
|
6
|
+
private readonly _publicKey;
|
|
7
|
+
private constructor();
|
|
8
|
+
static generate(config: BeamIdentityConfig): BeamIdentity;
|
|
9
|
+
static fromData(data: BeamIdentityData): BeamIdentity;
|
|
10
|
+
export(): BeamIdentityData;
|
|
11
|
+
sign(data: string): string;
|
|
12
|
+
static verify(data: string, signatureBase64: string, publicKeyBase64: string): boolean;
|
|
13
|
+
static parseBeamId(beamId: string): {
|
|
14
|
+
agent: string;
|
|
15
|
+
org: string;
|
|
16
|
+
} | null;
|
|
17
|
+
static generateNonce(): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEpF,qBAAa,YAAY;IACvB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IAEtC,OAAO;IAOP,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY;IAMzD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,YAAY;IAcrD,MAAM,IAAI,gBAAgB;IAQ1B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAK1B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;IAkBtF,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAMzE,MAAM,CAAC,aAAa,IAAI,MAAM;CAG/B"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { generateKeyPairSync, sign, verify, createPrivateKey, createPublicKey, randomUUID } from 'node:crypto';
|
|
2
|
+
export class BeamIdentity {
|
|
3
|
+
beamId;
|
|
4
|
+
publicKeyBase64;
|
|
5
|
+
_privateKey;
|
|
6
|
+
_publicKey;
|
|
7
|
+
constructor(beamId, privateKey, publicKey) {
|
|
8
|
+
this.beamId = beamId;
|
|
9
|
+
this._privateKey = privateKey;
|
|
10
|
+
this._publicKey = publicKey;
|
|
11
|
+
this.publicKeyBase64 = publicKey.export({ type: 'spki', format: 'der' }).toString('base64');
|
|
12
|
+
}
|
|
13
|
+
static generate(config) {
|
|
14
|
+
const { privateKey, publicKey } = generateKeyPairSync('ed25519');
|
|
15
|
+
const beamId = `${config.agentName}@${config.orgName}.beam.directory`;
|
|
16
|
+
return new BeamIdentity(beamId, privateKey, publicKey);
|
|
17
|
+
}
|
|
18
|
+
static fromData(data) {
|
|
19
|
+
const privateKey = createPrivateKey({
|
|
20
|
+
key: Buffer.from(data.privateKeyBase64, 'base64'),
|
|
21
|
+
format: 'der',
|
|
22
|
+
type: 'pkcs8'
|
|
23
|
+
});
|
|
24
|
+
const publicKey = createPublicKey({
|
|
25
|
+
key: Buffer.from(data.publicKeyBase64, 'base64'),
|
|
26
|
+
format: 'der',
|
|
27
|
+
type: 'spki'
|
|
28
|
+
});
|
|
29
|
+
return new BeamIdentity(data.beamId, privateKey, publicKey);
|
|
30
|
+
}
|
|
31
|
+
export() {
|
|
32
|
+
return {
|
|
33
|
+
beamId: this.beamId,
|
|
34
|
+
publicKeyBase64: this.publicKeyBase64,
|
|
35
|
+
privateKeyBase64: this._privateKey.export({ type: 'pkcs8', format: 'der' }).toString('base64')
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
sign(data) {
|
|
39
|
+
const signature = sign(null, Buffer.from(data, 'utf8'), this._privateKey);
|
|
40
|
+
return signature.toString('base64');
|
|
41
|
+
}
|
|
42
|
+
static verify(data, signatureBase64, publicKeyBase64) {
|
|
43
|
+
try {
|
|
44
|
+
const publicKey = createPublicKey({
|
|
45
|
+
key: Buffer.from(publicKeyBase64, 'base64'),
|
|
46
|
+
format: 'der',
|
|
47
|
+
type: 'spki'
|
|
48
|
+
});
|
|
49
|
+
return verify(null, Buffer.from(data, 'utf8'), publicKey, Buffer.from(signatureBase64, 'base64'));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
static parseBeamId(beamId) {
|
|
56
|
+
const match = beamId.match(/^([a-z0-9_-]+)@([a-z0-9_-]+)\.beam\.directory$/);
|
|
57
|
+
if (!match)
|
|
58
|
+
return null;
|
|
59
|
+
return { agent: match[1], org: match[2] };
|
|
60
|
+
}
|
|
61
|
+
static generateNonce() {
|
|
62
|
+
return randomUUID();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,UAAU,EAEX,MAAM,aAAa,CAAA;AAGpB,MAAM,OAAO,YAAY;IACd,MAAM,CAAc;IACpB,eAAe,CAAQ;IACf,WAAW,CAAW;IACtB,UAAU,CAAW;IAEtC,YAAoB,MAAoB,EAAE,UAAqB,EAAE,SAAoB;QACnF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAA;QAC7B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,eAAe,GAAI,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACzG,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,MAA0B;QACxC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAA;QAChE,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,OAAO,iBAAiC,CAAA;QACrF,OAAO,I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AQ,CAAC;gBAC3C,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,MAAM;aACb,CAAC,CAAA;YACF,OAAO,MAAM,CACX,IAAI,EACJ,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EACzB,SAAS,EACT,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CACvC,CAAA;QACH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAc;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAA;QAC5E,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QACvB,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IAC3C,CAAC;IAED,MAAM,CAAC,aAAa;QAClB,OAAO,UAAU,EAAE,CAAA;IACrB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BeamIdentity } from './identity.js';
|
|
2
|
+
export { BeamDirectory, BeamDirectoryError } from './directory.js';
|
|
3
|
+
export { BeamClient } from './client.js';
|
|
4
|
+
export { createIntentFrame, createResultFrame, signFrame, validateIntentFrame, validateResultFrame, canonicalizeFrame, MAX_FRAME_SIZE, REPLAY_WINDOW_MS } from './frames.js';
|
|
5
|
+
export type { BeamIdString, BeamIdentityConfig, BeamIdentityData, IntentFrame, ResultFrame, AgentRegistration, AgentRecord, DirectoryConfig, BeamClientConfig, AgentSearchQuery } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,aAAa,CAAA;AACpB,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BeamIdentity } from './identity.js';
|
|
2
|
+
export { BeamDirectory, BeamDirectoryError } from './directory.js';
|
|
3
|
+
export { BeamClient } from './client.js';
|
|
4
|
+
export { createIntentFrame, createResultFrame, signFrame, validateIntentFrame, validateResultFrame, canonicalizeFrame, MAX_FRAME_SIZE, REPLAY_WINDOW_MS } from './frames.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,aAAa,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Beam ID format: agent@org.beam.directory */
|
|
2
|
+
export type BeamIdString = `${string}@${string}.beam.directory`;
|
|
3
|
+
export interface BeamIdentityConfig {
|
|
4
|
+
agentName: string;
|
|
5
|
+
orgName: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BeamIdentityData {
|
|
8
|
+
beamId: BeamIdString;
|
|
9
|
+
publicKeyBase64: string;
|
|
10
|
+
privateKeyBase64: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IntentFrame {
|
|
13
|
+
v: '1';
|
|
14
|
+
intent: string;
|
|
15
|
+
from: BeamIdString;
|
|
16
|
+
to: BeamIdString;
|
|
17
|
+
payload: Record<string, unknown>;
|
|
18
|
+
nonce: string;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
signature?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ResultFrame {
|
|
23
|
+
v: '1';
|
|
24
|
+
success: boolean;
|
|
25
|
+
payload?: Record<string, unknown>;
|
|
26
|
+
error?: string;
|
|
27
|
+
errorCode?: string;
|
|
28
|
+
nonce: string;
|
|
29
|
+
timestamp: string;
|
|
30
|
+
latency?: number;
|
|
31
|
+
signature?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AgentRegistration {
|
|
34
|
+
beamId: BeamIdString;
|
|
35
|
+
displayName: string;
|
|
36
|
+
capabilities: string[];
|
|
37
|
+
publicKey: string;
|
|
38
|
+
org: string;
|
|
39
|
+
}
|
|
40
|
+
export interface AgentRecord extends AgentRegistration {
|
|
41
|
+
trustScore: number;
|
|
42
|
+
verified: boolean;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
lastSeen: string;
|
|
45
|
+
}
|
|
46
|
+
export interface DirectoryConfig {
|
|
47
|
+
baseUrl: string;
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BeamClientConfig {
|
|
51
|
+
identity: BeamIdentityData;
|
|
52
|
+
directoryUrl: string;
|
|
53
|
+
}
|
|
54
|
+
export interface AgentSearchQuery {
|
|
55
|
+
org?: string;
|
|
56
|
+
capabilities?: string[];
|
|
57
|
+
minTrustScore?: number;
|
|
58
|
+
limit?: number;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GAAG,GAAG,MAAM,IAAI,MAAM,iBAAiB,CAAA;AAE/D,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,YAAY,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,GAAG,CAAA;IACN,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,YAAY,CAAA;IAClB,EAAE,EAAE,YAAY,CAAA;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,GAAG,CAAA;IACN,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,YAAY,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,WAAY,SAAQ,iBAAiB;IACpD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "beam-protocol-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for the Beam Protocol \u2014 Agent-to-Agent communication",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"typecheck": "tsc --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.11.0",
|
|
22
|
+
"@types/ws": "^8.5.10",
|
|
23
|
+
"typescript": "^5.3.3",
|
|
24
|
+
"vitest": "^1.2.0"
|
|
25
|
+
},
|
|
26
|
+
"optionalDependencies": {
|
|
27
|
+
"ws": "^8.16.0"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/Beam-directory/beam-protocol.git",
|
|
41
|
+
"directory": "packages/sdk-typescript"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://beam.directory",
|
|
44
|
+
"keywords": [
|
|
45
|
+
"beam",
|
|
46
|
+
"protocol",
|
|
47
|
+
"agent",
|
|
48
|
+
"a2a",
|
|
49
|
+
"ai",
|
|
50
|
+
"communication",
|
|
51
|
+
"ed25519"
|
|
52
|
+
]
|
|
53
|
+
}
|