@claw-network/sdk 0.2.3 → 0.4.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.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/messaging.d.ts +115 -0
- package/dist/messaging.d.ts.map +1 -0
- package/dist/messaging.js +61 -0
- package/dist/messaging.js.map +1 -0
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export { ReputationApi } from './reputation.js';
|
|
|
22
22
|
export { MarketsApi, InfoMarketApi, TaskMarketApi, CapabilityMarketApi, MarketDisputeApi } from './markets.js';
|
|
23
23
|
export { ContractsApi } from './contracts.js';
|
|
24
24
|
export { DaoApi } from './dao.js';
|
|
25
|
+
export { MessagingApi, RECEIPT_TOPIC } from './messaging.js';
|
|
26
|
+
export type { SendMessageParams, SendMessageResult, SendBatchParams, SendBatchResult, InboxMessage, InboxQueryParams, InboxResponse, } from './messaging.js';
|
|
25
27
|
export * from './types.js';
|
|
26
28
|
import { HttpClient, type HttpClientConfig } from './http.js';
|
|
27
29
|
import { NodeApi } from './node.js';
|
|
@@ -31,6 +33,7 @@ import { ReputationApi } from './reputation.js';
|
|
|
31
33
|
import { MarketsApi } from './markets.js';
|
|
32
34
|
import { ContractsApi } from './contracts.js';
|
|
33
35
|
import { DaoApi } from './dao.js';
|
|
36
|
+
import { MessagingApi } from './messaging.js';
|
|
34
37
|
/** Configuration for the top-level client. */
|
|
35
38
|
export type ClientConfig = HttpClientConfig;
|
|
36
39
|
/**
|
|
@@ -49,6 +52,7 @@ export declare class ClawNetClient {
|
|
|
49
52
|
readonly markets: MarketsApi;
|
|
50
53
|
readonly contracts: ContractsApi;
|
|
51
54
|
readonly dao: DaoApi;
|
|
55
|
+
readonly messaging: MessagingApi;
|
|
52
56
|
constructor(config?: Partial<ClientConfig>);
|
|
53
57
|
}
|
|
54
58
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAA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,CAAC;CAc3C"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export { ReputationApi } from './reputation.js';
|
|
|
23
23
|
export { MarketsApi, InfoMarketApi, TaskMarketApi, CapabilityMarketApi, MarketDisputeApi } from './markets.js';
|
|
24
24
|
export { ContractsApi } from './contracts.js';
|
|
25
25
|
export { DaoApi } from './dao.js';
|
|
26
|
+
export { MessagingApi, RECEIPT_TOPIC } from './messaging.js';
|
|
26
27
|
// ── Shared types ─────────────────────────────────────────────────────────
|
|
27
28
|
export * from './types.js';
|
|
28
29
|
import { HttpClient } from './http.js';
|
|
@@ -33,6 +34,7 @@ import { ReputationApi } from './reputation.js';
|
|
|
33
34
|
import { MarketsApi } from './markets.js';
|
|
34
35
|
import { ContractsApi } from './contracts.js';
|
|
35
36
|
import { DaoApi } from './dao.js';
|
|
37
|
+
import { MessagingApi } from './messaging.js';
|
|
36
38
|
const DEFAULT_BASE_URL = 'http://127.0.0.1:9528';
|
|
37
39
|
/**
|
|
38
40
|
* Top-level client that exposes all ClawNet APIs via REST.
|
|
@@ -50,6 +52,7 @@ export class ClawNetClient {
|
|
|
50
52
|
markets;
|
|
51
53
|
contracts;
|
|
52
54
|
dao;
|
|
55
|
+
messaging;
|
|
53
56
|
constructor(config) {
|
|
54
57
|
this.http = new HttpClient({
|
|
55
58
|
baseUrl: config?.baseUrl ?? DEFAULT_BASE_URL,
|
|
@@ -62,6 +65,7 @@ export class ClawNetClient {
|
|
|
62
65
|
this.markets = new MarketsApi(this.http);
|
|
63
66
|
this.contracts = new ContractsApi(this.http);
|
|
64
67
|
this.dao = new DaoApi(this.http);
|
|
68
|
+
this.messaging = new MessagingApi(this.http);
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging API — send/receive P2P direct messages via the ClawNet node.
|
|
3
|
+
*/
|
|
4
|
+
import type { HttpClient, RequestOptions } from './http.js';
|
|
5
|
+
/** Topic used for delivery receipt notifications via WebSocket. */
|
|
6
|
+
export declare const RECEIPT_TOPIC: "_receipt";
|
|
7
|
+
export interface SendMessageParams {
|
|
8
|
+
/** Target node's DID (did:claw:z...) */
|
|
9
|
+
targetDid: string;
|
|
10
|
+
/** Topic / channel name (e.g. "telagent/envelope") */
|
|
11
|
+
topic: string;
|
|
12
|
+
/** Opaque payload — typically base64-encoded */
|
|
13
|
+
payload: string;
|
|
14
|
+
/** Time-to-live in seconds (default: 86400 = 24h) */
|
|
15
|
+
ttlSec?: number;
|
|
16
|
+
/** Priority level: 0=low, 1=normal, 2=high, 3=urgent */
|
|
17
|
+
priority?: number;
|
|
18
|
+
/** Enable gzip compression for payloads > 1KB */
|
|
19
|
+
compress?: boolean;
|
|
20
|
+
/** Recipient's X25519 public key hex for E2E encryption */
|
|
21
|
+
encryptForKeyHex?: string;
|
|
22
|
+
/** Idempotency key for deduplication (unique per message) */
|
|
23
|
+
idempotencyKey?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SendBatchParams {
|
|
26
|
+
/** Target DIDs (max 100) */
|
|
27
|
+
targetDids: string[];
|
|
28
|
+
/** Topic / channel name */
|
|
29
|
+
topic: string;
|
|
30
|
+
/** Opaque payload */
|
|
31
|
+
payload: string;
|
|
32
|
+
/** Time-to-live in seconds (default: 86400 = 24h) */
|
|
33
|
+
ttlSec?: number;
|
|
34
|
+
/** Priority level: 0=low, 1=normal, 2=high, 3=urgent */
|
|
35
|
+
priority?: number;
|
|
36
|
+
/** Enable gzip compression for payloads > 1KB */
|
|
37
|
+
compress?: boolean;
|
|
38
|
+
/** Idempotency key for deduplication */
|
|
39
|
+
idempotencyKey?: string;
|
|
40
|
+
/** Per-recipient X25519 public key hex for E2E encryption (DID → key hex) */
|
|
41
|
+
recipientKeys?: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
export interface SendMessageResult {
|
|
44
|
+
messageId: string;
|
|
45
|
+
delivered: boolean;
|
|
46
|
+
compressed?: boolean;
|
|
47
|
+
encrypted?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface SendBatchResult {
|
|
50
|
+
results: Array<SendMessageResult & {
|
|
51
|
+
targetDid: string;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
export interface InboxMessage {
|
|
55
|
+
messageId: string;
|
|
56
|
+
sourceDid: string;
|
|
57
|
+
topic: string;
|
|
58
|
+
payload: string;
|
|
59
|
+
receivedAtMs: number;
|
|
60
|
+
priority: number;
|
|
61
|
+
seq: number;
|
|
62
|
+
}
|
|
63
|
+
export interface InboxQueryParams {
|
|
64
|
+
/** Filter by topic */
|
|
65
|
+
topic?: string;
|
|
66
|
+
/** Only messages received after this timestamp (ms) */
|
|
67
|
+
since?: number;
|
|
68
|
+
/** Only messages with sequence number > sinceSeq (for replay) */
|
|
69
|
+
sinceSeq?: number;
|
|
70
|
+
/** Max messages to return (1-500, default 100) */
|
|
71
|
+
limit?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface InboxResponse {
|
|
74
|
+
messages: InboxMessage[];
|
|
75
|
+
}
|
|
76
|
+
export interface DidPeerMapResponse {
|
|
77
|
+
didPeerMap: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
export declare class MessagingApi {
|
|
80
|
+
private readonly http;
|
|
81
|
+
constructor(http: HttpClient);
|
|
82
|
+
/**
|
|
83
|
+
* Send a message to a target DID via P2P.
|
|
84
|
+
*
|
|
85
|
+
* If the target peer is online and reachable, the message is delivered
|
|
86
|
+
* directly. Otherwise it is queued for delivery when the peer reconnects.
|
|
87
|
+
*/
|
|
88
|
+
send(params: SendMessageParams, opts?: RequestOptions): Promise<SendMessageResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Multicast: send a message to multiple target DIDs.
|
|
91
|
+
*
|
|
92
|
+
* Each target is attempted independently — partial success is possible.
|
|
93
|
+
* Maximum 100 targets per call.
|
|
94
|
+
*/
|
|
95
|
+
sendBatch(params: SendBatchParams, opts?: RequestOptions): Promise<SendBatchResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Query the local inbox for received messages.
|
|
98
|
+
*
|
|
99
|
+
* Messages remain in the inbox until explicitly acknowledged via `ack()`.
|
|
100
|
+
* Use `topic` to filter by application namespace (e.g. "telagent/envelope").
|
|
101
|
+
*/
|
|
102
|
+
inbox(params?: InboxQueryParams, opts?: RequestOptions): Promise<InboxResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Acknowledge (consume) a message from the inbox.
|
|
105
|
+
*
|
|
106
|
+
* Once acknowledged, the message will no longer appear in inbox queries at
|
|
107
|
+
* all. Call this after your application has processed the message.
|
|
108
|
+
*/
|
|
109
|
+
ack(messageId: string, opts?: RequestOptions): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Get the current DID → PeerId mapping (for debugging).
|
|
112
|
+
*/
|
|
113
|
+
peers(opts?: RequestOptions): Promise<DidPeerMapResponse>;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=messaging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../src/messaging.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE5D,mEAAmE;AACnE,eAAO,MAAM,aAAa,EAAG,UAAmB,CAAC;AAIjD,MAAM,WAAW,iBAAiB;IAChC,wCAA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ifications via WebSocket. */
|
|
2
|
+
export const RECEIPT_TOPIC = '_receipt';
|
|
3
|
+
// ── API Class ────────────────────────────────────────────────────
|
|
4
|
+
export class MessagingApi {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Send a message to a target DID via P2P.
|
|
11
|
+
*
|
|
12
|
+
* If the target peer is online and reachable, the message is delivered
|
|
13
|
+
* directly. Otherwise it is queued for delivery when the peer reconnects.
|
|
14
|
+
*/
|
|
15
|
+
async send(params, opts) {
|
|
16
|
+
return this.http.post('/api/v1/messaging/send', params, opts);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Multicast: send a message to multiple target DIDs.
|
|
20
|
+
*
|
|
21
|
+
* Each target is attempted independently — partial success is possible.
|
|
22
|
+
* Maximum 100 targets per call.
|
|
23
|
+
*/
|
|
24
|
+
async sendBatch(params, opts) {
|
|
25
|
+
return this.http.post('/api/v1/messaging/send/batch', params, opts);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Query the local inbox for received messages.
|
|
29
|
+
*
|
|
30
|
+
* Messages remain in the inbox until explicitly acknowledged via `ack()`.
|
|
31
|
+
* Use `topic` to filter by application namespace (e.g. "telagent/envelope").
|
|
32
|
+
*/
|
|
33
|
+
async inbox(params, opts) {
|
|
34
|
+
const query = {};
|
|
35
|
+
if (params?.topic)
|
|
36
|
+
query.topic = params.topic;
|
|
37
|
+
if (params?.since !== undefined)
|
|
38
|
+
query.since = params.since;
|
|
39
|
+
if (params?.sinceSeq !== undefined)
|
|
40
|
+
query.sinceSeq = params.sinceSeq;
|
|
41
|
+
if (params?.limit !== undefined)
|
|
42
|
+
query.limit = params.limit;
|
|
43
|
+
return this.http.get('/api/v1/messaging/inbox', query, opts);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Acknowledge (consume) a message from the inbox.
|
|
47
|
+
*
|
|
48
|
+
* Once acknowledged, the message will no longer appear in inbox queries at
|
|
49
|
+
* all. Call this after your application has processed the message.
|
|
50
|
+
*/
|
|
51
|
+
async ack(messageId, opts) {
|
|
52
|
+
await this.http.delete(`/api/v1/messaging/inbox/${encodeURIComponent(messageId)}`, undefined, opts);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the current DID → PeerId mapping (for debugging).
|
|
56
|
+
*/
|
|
57
|
+
async peers(opts) {
|
|
58
|
+
return this.http.get('/api/v1/messaging/peers', undefined, opts);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=messaging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging.js","sourceRoot":"","sources":["../src/messaging.ts"],"names":[],"mappings":"AAKA,mEAAmE;AACnE,MAAM,CAAC,MAAM,aAAa,GAAG,UAAmB,CAAC;AAkFjD,oEAAoE;AAEpE,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,MAAyB,EAAE,IAAqB;QACzD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAoB,wBAAwB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACnF,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,MAAuB,EAAE,IAAqB;QAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAkB,8BAA8B,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACvF,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,MAAyB,EAAE,IAAqB;QAC1D,MAAM,KAAK,GAA0D,EAAE,CAAC;QACxE,IAAI,MAAM,EAAE,KAAK;YAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC9C,IAAI,MAAM,EAAE,KAAK,KAAK,SAAS;YAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC5D,IAAI,MAAM,EAAE,QAAQ,KAAK,SAAS;YAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrE,IAAI,MAAM,EAAE,KAAK,KAAK,SAAS;YAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAgB,yBAAyB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAC,SAAiB,EAAE,IAAqB;QAChD,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,2BAA2B,kBAAkB,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACtG,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,IAAqB;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAqB,yBAAyB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACvF,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claw-network/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "TypeScript SDK for the ClawNet decentralized agent economy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./dist/index.js"
|
|
27
27
|
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
28
31
|
"scripts": {
|
|
29
32
|
"build": "tsc -b tsconfig.json",
|
|
30
33
|
"test": "vitest run --passWithNoTests",
|
|
31
34
|
"lint": "eslint src --max-warnings=0"
|
|
32
|
-
},
|
|
33
|
-
"publishConfig": {
|
|
34
|
-
"access": "public"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|