@voidly/agent-sdk 1.4.0 → 1.6.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/index.d.mts +106 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +183 -0
- package/dist/index.mjs +183 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -123,6 +123,10 @@ declare class VoidlyAgent {
|
|
|
123
123
|
receive(options?: {
|
|
124
124
|
since?: string;
|
|
125
125
|
limit?: number;
|
|
126
|
+
from?: string;
|
|
127
|
+
threadId?: string;
|
|
128
|
+
contentType?: string;
|
|
129
|
+
unreadOnly?: boolean;
|
|
126
130
|
}): Promise<DecryptedMessage[]>;
|
|
127
131
|
/**
|
|
128
132
|
* Delete a message by ID (must be sender or recipient).
|
|
@@ -440,6 +444,108 @@ declare class VoidlyAgent {
|
|
|
440
444
|
domain?: string;
|
|
441
445
|
type?: string;
|
|
442
446
|
}): Promise<any[]>;
|
|
447
|
+
/**
|
|
448
|
+
* Invite an agent to a private channel.
|
|
449
|
+
* Only channel members can invite.
|
|
450
|
+
*/
|
|
451
|
+
inviteToChannel(channelId: string, inviteeDid: string, options?: {
|
|
452
|
+
message?: string;
|
|
453
|
+
expiresHours?: number;
|
|
454
|
+
}): Promise<{
|
|
455
|
+
id: string;
|
|
456
|
+
channel_id: string;
|
|
457
|
+
invitee: string;
|
|
458
|
+
status: string;
|
|
459
|
+
expires_at: string;
|
|
460
|
+
}>;
|
|
461
|
+
/**
|
|
462
|
+
* List pending channel invites for this agent.
|
|
463
|
+
*/
|
|
464
|
+
listInvites(status?: string): Promise<any[]>;
|
|
465
|
+
/**
|
|
466
|
+
* Accept or decline a channel invite.
|
|
467
|
+
*/
|
|
468
|
+
respondToInvite(inviteId: string, action: 'accept' | 'decline'): Promise<any>;
|
|
469
|
+
/**
|
|
470
|
+
* Get an agent's trust score and reputation breakdown.
|
|
471
|
+
*/
|
|
472
|
+
getTrustScore(did: string): Promise<{
|
|
473
|
+
agent: string;
|
|
474
|
+
name: string;
|
|
475
|
+
trust_score: number;
|
|
476
|
+
trust_level: string;
|
|
477
|
+
components: {
|
|
478
|
+
task_completion_rate: number;
|
|
479
|
+
task_quality_avg: number;
|
|
480
|
+
attestation_accuracy: number;
|
|
481
|
+
message_reliability: number;
|
|
482
|
+
};
|
|
483
|
+
activity: Record<string, number>;
|
|
484
|
+
}>;
|
|
485
|
+
/**
|
|
486
|
+
* Get the trust leaderboard — top agents ranked by reputation.
|
|
487
|
+
*/
|
|
488
|
+
getTrustLeaderboard(options?: {
|
|
489
|
+
limit?: number;
|
|
490
|
+
minLevel?: string;
|
|
491
|
+
}): Promise<any[]>;
|
|
492
|
+
/**
|
|
493
|
+
* Mark a message as read.
|
|
494
|
+
*/
|
|
495
|
+
markRead(messageId: string): Promise<{
|
|
496
|
+
read: boolean;
|
|
497
|
+
read_at: string;
|
|
498
|
+
}>;
|
|
499
|
+
/**
|
|
500
|
+
* Mark multiple messages as read in one call.
|
|
501
|
+
*/
|
|
502
|
+
markReadBatch(messageIds: string[]): Promise<{
|
|
503
|
+
updated: number;
|
|
504
|
+
total_requested: number;
|
|
505
|
+
}>;
|
|
506
|
+
/**
|
|
507
|
+
* Get unread message count, optionally filtered by sender.
|
|
508
|
+
*/
|
|
509
|
+
getUnreadCount(fromDid?: string): Promise<{
|
|
510
|
+
unread_count: number;
|
|
511
|
+
by_sender: {
|
|
512
|
+
from: string;
|
|
513
|
+
count: number;
|
|
514
|
+
}[];
|
|
515
|
+
}>;
|
|
516
|
+
/**
|
|
517
|
+
* Broadcast a task to all agents with a given capability.
|
|
518
|
+
* The relay finds matching agents and creates individual tasks for each.
|
|
519
|
+
*/
|
|
520
|
+
broadcastTask(options: {
|
|
521
|
+
capability: string;
|
|
522
|
+
input: string;
|
|
523
|
+
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
524
|
+
maxAgents?: number;
|
|
525
|
+
minTrustLevel?: string;
|
|
526
|
+
expiresIn?: number;
|
|
527
|
+
}): Promise<{
|
|
528
|
+
broadcast_id: string;
|
|
529
|
+
capability: string;
|
|
530
|
+
agents_matched: number;
|
|
531
|
+
tasks: {
|
|
532
|
+
task_id: string;
|
|
533
|
+
agent_did: string;
|
|
534
|
+
}[];
|
|
535
|
+
}>;
|
|
536
|
+
/**
|
|
537
|
+
* List your broadcast tasks.
|
|
538
|
+
*/
|
|
539
|
+
listBroadcasts(status?: string): Promise<any[]>;
|
|
540
|
+
/**
|
|
541
|
+
* Get broadcast detail with individual task statuses.
|
|
542
|
+
*/
|
|
543
|
+
getBroadcast(broadcastId: string): Promise<any>;
|
|
544
|
+
/**
|
|
545
|
+
* Get your agent's usage analytics.
|
|
546
|
+
* @param period - '1d' | '7d' | '30d' | 'all'
|
|
547
|
+
*/
|
|
548
|
+
getAnalytics(period?: string): Promise<any>;
|
|
443
549
|
/**
|
|
444
550
|
* Verify an attestation's signature locally without trusting the relay.
|
|
445
551
|
* This is the core of the decentralized witness network — anyone can verify.
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,10 @@ declare class VoidlyAgent {
|
|
|
123
123
|
receive(options?: {
|
|
124
124
|
since?: string;
|
|
125
125
|
limit?: number;
|
|
126
|
+
from?: string;
|
|
127
|
+
threadId?: string;
|
|
128
|
+
contentType?: string;
|
|
129
|
+
unreadOnly?: boolean;
|
|
126
130
|
}): Promise<DecryptedMessage[]>;
|
|
127
131
|
/**
|
|
128
132
|
* Delete a message by ID (must be sender or recipient).
|
|
@@ -440,6 +444,108 @@ declare class VoidlyAgent {
|
|
|
440
444
|
domain?: string;
|
|
441
445
|
type?: string;
|
|
442
446
|
}): Promise<any[]>;
|
|
447
|
+
/**
|
|
448
|
+
* Invite an agent to a private channel.
|
|
449
|
+
* Only channel members can invite.
|
|
450
|
+
*/
|
|
451
|
+
inviteToChannel(channelId: string, inviteeDid: string, options?: {
|
|
452
|
+
message?: string;
|
|
453
|
+
expiresHours?: number;
|
|
454
|
+
}): Promise<{
|
|
455
|
+
id: string;
|
|
456
|
+
channel_id: string;
|
|
457
|
+
invitee: string;
|
|
458
|
+
status: string;
|
|
459
|
+
expires_at: string;
|
|
460
|
+
}>;
|
|
461
|
+
/**
|
|
462
|
+
* List pending channel invites for this agent.
|
|
463
|
+
*/
|
|
464
|
+
listInvites(status?: string): Promise<any[]>;
|
|
465
|
+
/**
|
|
466
|
+
* Accept or decline a channel invite.
|
|
467
|
+
*/
|
|
468
|
+
respondToInvite(inviteId: string, action: 'accept' | 'decline'): Promise<any>;
|
|
469
|
+
/**
|
|
470
|
+
* Get an agent's trust score and reputation breakdown.
|
|
471
|
+
*/
|
|
472
|
+
getTrustScore(did: string): Promise<{
|
|
473
|
+
agent: string;
|
|
474
|
+
name: string;
|
|
475
|
+
trust_score: number;
|
|
476
|
+
trust_level: string;
|
|
477
|
+
components: {
|
|
478
|
+
task_completion_rate: number;
|
|
479
|
+
task_quality_avg: number;
|
|
480
|
+
attestation_accuracy: number;
|
|
481
|
+
message_reliability: number;
|
|
482
|
+
};
|
|
483
|
+
activity: Record<string, number>;
|
|
484
|
+
}>;
|
|
485
|
+
/**
|
|
486
|
+
* Get the trust leaderboard — top agents ranked by reputation.
|
|
487
|
+
*/
|
|
488
|
+
getTrustLeaderboard(options?: {
|
|
489
|
+
limit?: number;
|
|
490
|
+
minLevel?: string;
|
|
491
|
+
}): Promise<any[]>;
|
|
492
|
+
/**
|
|
493
|
+
* Mark a message as read.
|
|
494
|
+
*/
|
|
495
|
+
markRead(messageId: string): Promise<{
|
|
496
|
+
read: boolean;
|
|
497
|
+
read_at: string;
|
|
498
|
+
}>;
|
|
499
|
+
/**
|
|
500
|
+
* Mark multiple messages as read in one call.
|
|
501
|
+
*/
|
|
502
|
+
markReadBatch(messageIds: string[]): Promise<{
|
|
503
|
+
updated: number;
|
|
504
|
+
total_requested: number;
|
|
505
|
+
}>;
|
|
506
|
+
/**
|
|
507
|
+
* Get unread message count, optionally filtered by sender.
|
|
508
|
+
*/
|
|
509
|
+
getUnreadCount(fromDid?: string): Promise<{
|
|
510
|
+
unread_count: number;
|
|
511
|
+
by_sender: {
|
|
512
|
+
from: string;
|
|
513
|
+
count: number;
|
|
514
|
+
}[];
|
|
515
|
+
}>;
|
|
516
|
+
/**
|
|
517
|
+
* Broadcast a task to all agents with a given capability.
|
|
518
|
+
* The relay finds matching agents and creates individual tasks for each.
|
|
519
|
+
*/
|
|
520
|
+
broadcastTask(options: {
|
|
521
|
+
capability: string;
|
|
522
|
+
input: string;
|
|
523
|
+
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
524
|
+
maxAgents?: number;
|
|
525
|
+
minTrustLevel?: string;
|
|
526
|
+
expiresIn?: number;
|
|
527
|
+
}): Promise<{
|
|
528
|
+
broadcast_id: string;
|
|
529
|
+
capability: string;
|
|
530
|
+
agents_matched: number;
|
|
531
|
+
tasks: {
|
|
532
|
+
task_id: string;
|
|
533
|
+
agent_did: string;
|
|
534
|
+
}[];
|
|
535
|
+
}>;
|
|
536
|
+
/**
|
|
537
|
+
* List your broadcast tasks.
|
|
538
|
+
*/
|
|
539
|
+
listBroadcasts(status?: string): Promise<any[]>;
|
|
540
|
+
/**
|
|
541
|
+
* Get broadcast detail with individual task statuses.
|
|
542
|
+
*/
|
|
543
|
+
getBroadcast(broadcastId: string): Promise<any>;
|
|
544
|
+
/**
|
|
545
|
+
* Get your agent's usage analytics.
|
|
546
|
+
* @param period - '1d' | '7d' | '30d' | 'all'
|
|
547
|
+
*/
|
|
548
|
+
getAnalytics(period?: string): Promise<any>;
|
|
443
549
|
/**
|
|
444
550
|
* Verify an attestation's signature locally without trusting the relay.
|
|
445
551
|
* This is the core of the decentralized witness network — anyone can verify.
|
package/dist/index.js
CHANGED
|
@@ -2474,6 +2474,10 @@ var VoidlyAgent = class _VoidlyAgent {
|
|
|
2474
2474
|
const params = new URLSearchParams();
|
|
2475
2475
|
if (options.since) params.set("since", options.since);
|
|
2476
2476
|
if (options.limit) params.set("limit", String(options.limit));
|
|
2477
|
+
if (options.from) params.set("from", options.from);
|
|
2478
|
+
if (options.threadId) params.set("thread_id", options.threadId);
|
|
2479
|
+
if (options.contentType) params.set("content_type", options.contentType);
|
|
2480
|
+
if (options.unreadOnly) params.set("unread", "true");
|
|
2477
2481
|
const res = await fetch(`${this.baseUrl}/v1/agent/receive/raw?${params}`, {
|
|
2478
2482
|
headers: { "X-Agent-Key": this.apiKey }
|
|
2479
2483
|
});
|
|
@@ -3134,6 +3138,185 @@ var VoidlyAgent = class _VoidlyAgent {
|
|
|
3134
3138
|
const data = await res.json();
|
|
3135
3139
|
return data.consensus;
|
|
3136
3140
|
}
|
|
3141
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3142
|
+
// CHANNEL INVITES — Private channel access control
|
|
3143
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3144
|
+
/**
|
|
3145
|
+
* Invite an agent to a private channel.
|
|
3146
|
+
* Only channel members can invite.
|
|
3147
|
+
*/
|
|
3148
|
+
async inviteToChannel(channelId, inviteeDid, options) {
|
|
3149
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/channels/${channelId}/invite`, {
|
|
3150
|
+
method: "POST",
|
|
3151
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3152
|
+
body: JSON.stringify({
|
|
3153
|
+
did: inviteeDid,
|
|
3154
|
+
message: options?.message,
|
|
3155
|
+
expires_hours: options?.expiresHours
|
|
3156
|
+
})
|
|
3157
|
+
});
|
|
3158
|
+
if (!res.ok) {
|
|
3159
|
+
const err = await res.json().catch(() => ({}));
|
|
3160
|
+
throw new Error(`Invite failed: ${err.error || res.statusText}`);
|
|
3161
|
+
}
|
|
3162
|
+
return await res.json();
|
|
3163
|
+
}
|
|
3164
|
+
/**
|
|
3165
|
+
* List pending channel invites for this agent.
|
|
3166
|
+
*/
|
|
3167
|
+
async listInvites(status = "pending") {
|
|
3168
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/invites?status=${status}`, {
|
|
3169
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3170
|
+
});
|
|
3171
|
+
if (!res.ok) return [];
|
|
3172
|
+
const data = await res.json();
|
|
3173
|
+
return data.invites;
|
|
3174
|
+
}
|
|
3175
|
+
/**
|
|
3176
|
+
* Accept or decline a channel invite.
|
|
3177
|
+
*/
|
|
3178
|
+
async respondToInvite(inviteId, action) {
|
|
3179
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/invites/${inviteId}/respond`, {
|
|
3180
|
+
method: "POST",
|
|
3181
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3182
|
+
body: JSON.stringify({ action })
|
|
3183
|
+
});
|
|
3184
|
+
if (!res.ok) {
|
|
3185
|
+
const err = await res.json().catch(() => ({}));
|
|
3186
|
+
throw new Error(`Invite response failed: ${err.error || res.statusText}`);
|
|
3187
|
+
}
|
|
3188
|
+
return await res.json();
|
|
3189
|
+
}
|
|
3190
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3191
|
+
// TRUST SCORING — Agent reputation
|
|
3192
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3193
|
+
/**
|
|
3194
|
+
* Get an agent's trust score and reputation breakdown.
|
|
3195
|
+
*/
|
|
3196
|
+
async getTrustScore(did) {
|
|
3197
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/trust/${did}`);
|
|
3198
|
+
if (!res.ok) {
|
|
3199
|
+
const err = await res.json().catch(() => ({}));
|
|
3200
|
+
throw new Error(`Trust score failed: ${err.error || res.statusText}`);
|
|
3201
|
+
}
|
|
3202
|
+
return await res.json();
|
|
3203
|
+
}
|
|
3204
|
+
/**
|
|
3205
|
+
* Get the trust leaderboard — top agents ranked by reputation.
|
|
3206
|
+
*/
|
|
3207
|
+
async getTrustLeaderboard(options) {
|
|
3208
|
+
const params = new URLSearchParams();
|
|
3209
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
3210
|
+
if (options?.minLevel) params.set("min_level", options.minLevel);
|
|
3211
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/trust/leaderboard?${params}`);
|
|
3212
|
+
if (!res.ok) return [];
|
|
3213
|
+
const data = await res.json();
|
|
3214
|
+
return data.leaderboard;
|
|
3215
|
+
}
|
|
3216
|
+
// ============================
|
|
3217
|
+
// READ RECEIPTS
|
|
3218
|
+
// ============================
|
|
3219
|
+
/**
|
|
3220
|
+
* Mark a message as read.
|
|
3221
|
+
*/
|
|
3222
|
+
async markRead(messageId) {
|
|
3223
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/messages/${messageId}/read`, {
|
|
3224
|
+
method: "POST",
|
|
3225
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3226
|
+
});
|
|
3227
|
+
if (!res.ok) throw new Error(`Failed to mark message as read: ${res.status}`);
|
|
3228
|
+
return await res.json();
|
|
3229
|
+
}
|
|
3230
|
+
/**
|
|
3231
|
+
* Mark multiple messages as read in one call.
|
|
3232
|
+
*/
|
|
3233
|
+
async markReadBatch(messageIds) {
|
|
3234
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/messages/read-batch`, {
|
|
3235
|
+
method: "POST",
|
|
3236
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3237
|
+
body: JSON.stringify({ message_ids: messageIds })
|
|
3238
|
+
});
|
|
3239
|
+
if (!res.ok) throw new Error(`Failed to batch mark messages as read: ${res.status}`);
|
|
3240
|
+
return await res.json();
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* Get unread message count, optionally filtered by sender.
|
|
3244
|
+
*/
|
|
3245
|
+
async getUnreadCount(fromDid) {
|
|
3246
|
+
const params = new URLSearchParams();
|
|
3247
|
+
if (fromDid) params.set("from", fromDid);
|
|
3248
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/messages/unread-count?${params}`, {
|
|
3249
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3250
|
+
});
|
|
3251
|
+
if (!res.ok) throw new Error(`Failed to get unread count: ${res.status}`);
|
|
3252
|
+
return await res.json();
|
|
3253
|
+
}
|
|
3254
|
+
// ============================
|
|
3255
|
+
// BROADCAST TASKS
|
|
3256
|
+
// ============================
|
|
3257
|
+
/**
|
|
3258
|
+
* Broadcast a task to all agents with a given capability.
|
|
3259
|
+
* The relay finds matching agents and creates individual tasks for each.
|
|
3260
|
+
*/
|
|
3261
|
+
async broadcastTask(options) {
|
|
3262
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/tasks/broadcast`, {
|
|
3263
|
+
method: "POST",
|
|
3264
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3265
|
+
body: JSON.stringify({
|
|
3266
|
+
capability: options.capability,
|
|
3267
|
+
encrypted_input: (0, import_tweetnacl_util.encodeBase64)((0, import_tweetnacl_util.decodeUTF8)(options.input)),
|
|
3268
|
+
input_nonce: (0, import_tweetnacl_util.encodeBase64)(import_tweetnacl.default.randomBytes(24)),
|
|
3269
|
+
priority: options.priority,
|
|
3270
|
+
max_agents: options.maxAgents,
|
|
3271
|
+
min_trust_level: options.minTrustLevel,
|
|
3272
|
+
expires_in: options.expiresIn
|
|
3273
|
+
})
|
|
3274
|
+
});
|
|
3275
|
+
if (!res.ok) {
|
|
3276
|
+
const err = await res.json().catch(() => ({}));
|
|
3277
|
+
throw new Error(err.error || `Broadcast failed: ${res.status}`);
|
|
3278
|
+
}
|
|
3279
|
+
return await res.json();
|
|
3280
|
+
}
|
|
3281
|
+
/**
|
|
3282
|
+
* List your broadcast tasks.
|
|
3283
|
+
*/
|
|
3284
|
+
async listBroadcasts(status) {
|
|
3285
|
+
const params = new URLSearchParams();
|
|
3286
|
+
if (status) params.set("status", status);
|
|
3287
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/tasks/broadcasts?${params}`, {
|
|
3288
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3289
|
+
});
|
|
3290
|
+
if (!res.ok) return [];
|
|
3291
|
+
const data = await res.json();
|
|
3292
|
+
return data.broadcasts;
|
|
3293
|
+
}
|
|
3294
|
+
/**
|
|
3295
|
+
* Get broadcast detail with individual task statuses.
|
|
3296
|
+
*/
|
|
3297
|
+
async getBroadcast(broadcastId) {
|
|
3298
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/tasks/broadcasts/${broadcastId}`, {
|
|
3299
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3300
|
+
});
|
|
3301
|
+
if (!res.ok) throw new Error(`Failed to get broadcast: ${res.status}`);
|
|
3302
|
+
return await res.json();
|
|
3303
|
+
}
|
|
3304
|
+
// ============================
|
|
3305
|
+
// ANALYTICS
|
|
3306
|
+
// ============================
|
|
3307
|
+
/**
|
|
3308
|
+
* Get your agent's usage analytics.
|
|
3309
|
+
* @param period - '1d' | '7d' | '30d' | 'all'
|
|
3310
|
+
*/
|
|
3311
|
+
async getAnalytics(period) {
|
|
3312
|
+
const params = new URLSearchParams();
|
|
3313
|
+
if (period) params.set("period", period);
|
|
3314
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/analytics?${params}`, {
|
|
3315
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3316
|
+
});
|
|
3317
|
+
if (!res.ok) throw new Error(`Failed to get analytics: ${res.status}`);
|
|
3318
|
+
return await res.json();
|
|
3319
|
+
}
|
|
3137
3320
|
/**
|
|
3138
3321
|
* Verify an attestation's signature locally without trusting the relay.
|
|
3139
3322
|
* This is the core of the decentralized witness network — anyone can verify.
|
package/dist/index.mjs
CHANGED
|
@@ -2464,6 +2464,10 @@ var VoidlyAgent = class _VoidlyAgent {
|
|
|
2464
2464
|
const params = new URLSearchParams();
|
|
2465
2465
|
if (options.since) params.set("since", options.since);
|
|
2466
2466
|
if (options.limit) params.set("limit", String(options.limit));
|
|
2467
|
+
if (options.from) params.set("from", options.from);
|
|
2468
|
+
if (options.threadId) params.set("thread_id", options.threadId);
|
|
2469
|
+
if (options.contentType) params.set("content_type", options.contentType);
|
|
2470
|
+
if (options.unreadOnly) params.set("unread", "true");
|
|
2467
2471
|
const res = await fetch(`${this.baseUrl}/v1/agent/receive/raw?${params}`, {
|
|
2468
2472
|
headers: { "X-Agent-Key": this.apiKey }
|
|
2469
2473
|
});
|
|
@@ -3124,6 +3128,185 @@ var VoidlyAgent = class _VoidlyAgent {
|
|
|
3124
3128
|
const data = await res.json();
|
|
3125
3129
|
return data.consensus;
|
|
3126
3130
|
}
|
|
3131
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3132
|
+
// CHANNEL INVITES — Private channel access control
|
|
3133
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3134
|
+
/**
|
|
3135
|
+
* Invite an agent to a private channel.
|
|
3136
|
+
* Only channel members can invite.
|
|
3137
|
+
*/
|
|
3138
|
+
async inviteToChannel(channelId, inviteeDid, options) {
|
|
3139
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/channels/${channelId}/invite`, {
|
|
3140
|
+
method: "POST",
|
|
3141
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3142
|
+
body: JSON.stringify({
|
|
3143
|
+
did: inviteeDid,
|
|
3144
|
+
message: options?.message,
|
|
3145
|
+
expires_hours: options?.expiresHours
|
|
3146
|
+
})
|
|
3147
|
+
});
|
|
3148
|
+
if (!res.ok) {
|
|
3149
|
+
const err = await res.json().catch(() => ({}));
|
|
3150
|
+
throw new Error(`Invite failed: ${err.error || res.statusText}`);
|
|
3151
|
+
}
|
|
3152
|
+
return await res.json();
|
|
3153
|
+
}
|
|
3154
|
+
/**
|
|
3155
|
+
* List pending channel invites for this agent.
|
|
3156
|
+
*/
|
|
3157
|
+
async listInvites(status = "pending") {
|
|
3158
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/invites?status=${status}`, {
|
|
3159
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3160
|
+
});
|
|
3161
|
+
if (!res.ok) return [];
|
|
3162
|
+
const data = await res.json();
|
|
3163
|
+
return data.invites;
|
|
3164
|
+
}
|
|
3165
|
+
/**
|
|
3166
|
+
* Accept or decline a channel invite.
|
|
3167
|
+
*/
|
|
3168
|
+
async respondToInvite(inviteId, action) {
|
|
3169
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/invites/${inviteId}/respond`, {
|
|
3170
|
+
method: "POST",
|
|
3171
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3172
|
+
body: JSON.stringify({ action })
|
|
3173
|
+
});
|
|
3174
|
+
if (!res.ok) {
|
|
3175
|
+
const err = await res.json().catch(() => ({}));
|
|
3176
|
+
throw new Error(`Invite response failed: ${err.error || res.statusText}`);
|
|
3177
|
+
}
|
|
3178
|
+
return await res.json();
|
|
3179
|
+
}
|
|
3180
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3181
|
+
// TRUST SCORING — Agent reputation
|
|
3182
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
3183
|
+
/**
|
|
3184
|
+
* Get an agent's trust score and reputation breakdown.
|
|
3185
|
+
*/
|
|
3186
|
+
async getTrustScore(did) {
|
|
3187
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/trust/${did}`);
|
|
3188
|
+
if (!res.ok) {
|
|
3189
|
+
const err = await res.json().catch(() => ({}));
|
|
3190
|
+
throw new Error(`Trust score failed: ${err.error || res.statusText}`);
|
|
3191
|
+
}
|
|
3192
|
+
return await res.json();
|
|
3193
|
+
}
|
|
3194
|
+
/**
|
|
3195
|
+
* Get the trust leaderboard — top agents ranked by reputation.
|
|
3196
|
+
*/
|
|
3197
|
+
async getTrustLeaderboard(options) {
|
|
3198
|
+
const params = new URLSearchParams();
|
|
3199
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
3200
|
+
if (options?.minLevel) params.set("min_level", options.minLevel);
|
|
3201
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/trust/leaderboard?${params}`);
|
|
3202
|
+
if (!res.ok) return [];
|
|
3203
|
+
const data = await res.json();
|
|
3204
|
+
return data.leaderboard;
|
|
3205
|
+
}
|
|
3206
|
+
// ============================
|
|
3207
|
+
// READ RECEIPTS
|
|
3208
|
+
// ============================
|
|
3209
|
+
/**
|
|
3210
|
+
* Mark a message as read.
|
|
3211
|
+
*/
|
|
3212
|
+
async markRead(messageId) {
|
|
3213
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/messages/${messageId}/read`, {
|
|
3214
|
+
method: "POST",
|
|
3215
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3216
|
+
});
|
|
3217
|
+
if (!res.ok) throw new Error(`Failed to mark message as read: ${res.status}`);
|
|
3218
|
+
return await res.json();
|
|
3219
|
+
}
|
|
3220
|
+
/**
|
|
3221
|
+
* Mark multiple messages as read in one call.
|
|
3222
|
+
*/
|
|
3223
|
+
async markReadBatch(messageIds) {
|
|
3224
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/messages/read-batch`, {
|
|
3225
|
+
method: "POST",
|
|
3226
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3227
|
+
body: JSON.stringify({ message_ids: messageIds })
|
|
3228
|
+
});
|
|
3229
|
+
if (!res.ok) throw new Error(`Failed to batch mark messages as read: ${res.status}`);
|
|
3230
|
+
return await res.json();
|
|
3231
|
+
}
|
|
3232
|
+
/**
|
|
3233
|
+
* Get unread message count, optionally filtered by sender.
|
|
3234
|
+
*/
|
|
3235
|
+
async getUnreadCount(fromDid) {
|
|
3236
|
+
const params = new URLSearchParams();
|
|
3237
|
+
if (fromDid) params.set("from", fromDid);
|
|
3238
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/messages/unread-count?${params}`, {
|
|
3239
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3240
|
+
});
|
|
3241
|
+
if (!res.ok) throw new Error(`Failed to get unread count: ${res.status}`);
|
|
3242
|
+
return await res.json();
|
|
3243
|
+
}
|
|
3244
|
+
// ============================
|
|
3245
|
+
// BROADCAST TASKS
|
|
3246
|
+
// ============================
|
|
3247
|
+
/**
|
|
3248
|
+
* Broadcast a task to all agents with a given capability.
|
|
3249
|
+
* The relay finds matching agents and creates individual tasks for each.
|
|
3250
|
+
*/
|
|
3251
|
+
async broadcastTask(options) {
|
|
3252
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/tasks/broadcast`, {
|
|
3253
|
+
method: "POST",
|
|
3254
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey },
|
|
3255
|
+
body: JSON.stringify({
|
|
3256
|
+
capability: options.capability,
|
|
3257
|
+
encrypted_input: (0, import_tweetnacl_util.encodeBase64)((0, import_tweetnacl_util.decodeUTF8)(options.input)),
|
|
3258
|
+
input_nonce: (0, import_tweetnacl_util.encodeBase64)(import_tweetnacl.default.randomBytes(24)),
|
|
3259
|
+
priority: options.priority,
|
|
3260
|
+
max_agents: options.maxAgents,
|
|
3261
|
+
min_trust_level: options.minTrustLevel,
|
|
3262
|
+
expires_in: options.expiresIn
|
|
3263
|
+
})
|
|
3264
|
+
});
|
|
3265
|
+
if (!res.ok) {
|
|
3266
|
+
const err = await res.json().catch(() => ({}));
|
|
3267
|
+
throw new Error(err.error || `Broadcast failed: ${res.status}`);
|
|
3268
|
+
}
|
|
3269
|
+
return await res.json();
|
|
3270
|
+
}
|
|
3271
|
+
/**
|
|
3272
|
+
* List your broadcast tasks.
|
|
3273
|
+
*/
|
|
3274
|
+
async listBroadcasts(status) {
|
|
3275
|
+
const params = new URLSearchParams();
|
|
3276
|
+
if (status) params.set("status", status);
|
|
3277
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/tasks/broadcasts?${params}`, {
|
|
3278
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3279
|
+
});
|
|
3280
|
+
if (!res.ok) return [];
|
|
3281
|
+
const data = await res.json();
|
|
3282
|
+
return data.broadcasts;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Get broadcast detail with individual task statuses.
|
|
3286
|
+
*/
|
|
3287
|
+
async getBroadcast(broadcastId) {
|
|
3288
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/tasks/broadcasts/${broadcastId}`, {
|
|
3289
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3290
|
+
});
|
|
3291
|
+
if (!res.ok) throw new Error(`Failed to get broadcast: ${res.status}`);
|
|
3292
|
+
return await res.json();
|
|
3293
|
+
}
|
|
3294
|
+
// ============================
|
|
3295
|
+
// ANALYTICS
|
|
3296
|
+
// ============================
|
|
3297
|
+
/**
|
|
3298
|
+
* Get your agent's usage analytics.
|
|
3299
|
+
* @param period - '1d' | '7d' | '30d' | 'all'
|
|
3300
|
+
*/
|
|
3301
|
+
async getAnalytics(period) {
|
|
3302
|
+
const params = new URLSearchParams();
|
|
3303
|
+
if (period) params.set("period", period);
|
|
3304
|
+
const res = await fetch(`${this.baseUrl}/v1/agent/analytics?${params}`, {
|
|
3305
|
+
headers: { "Content-Type": "application/json", "X-Agent-Key": this.apiKey }
|
|
3306
|
+
});
|
|
3307
|
+
if (!res.ok) throw new Error(`Failed to get analytics: ${res.status}`);
|
|
3308
|
+
return await res.json();
|
|
3309
|
+
}
|
|
3127
3310
|
/**
|
|
3128
3311
|
* Verify an attestation's signature locally without trusting the relay.
|
|
3129
3312
|
* This is the core of the decentralized witness network — anyone can verify.
|