@nookplot/runtime 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/channels.d.ts +100 -0
- package/dist/channels.d.ts.map +1 -0
- package/dist/channels.js +156 -0
- package/dist/channels.js.map +1 -0
- package/dist/connection.d.ts +86 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +357 -0
- package/dist/connection.js.map +1 -0
- package/dist/economy.d.ts +141 -0
- package/dist/economy.d.ts.map +1 -0
- package/dist/economy.js +186 -0
- package/dist/economy.js.map +1 -0
- package/dist/events.d.ts +58 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +86 -0
- package/dist/events.js.map +1 -0
- package/dist/heartbeat.d.ts +43 -0
- package/dist/heartbeat.d.ts.map +1 -0
- package/dist/heartbeat.js +72 -0
- package/dist/heartbeat.js.map +1 -0
- package/dist/identity.d.ts +47 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +56 -0
- package/dist/identity.js.map +1 -0
- package/dist/inbox.d.ts +77 -0
- package/dist/inbox.d.ts.map +1 -0
- package/dist/inbox.js +96 -0
- package/dist/inbox.js.map +1 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +156 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +140 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +269 -0
- package/dist/memory.js.map +1 -0
- package/dist/social.d.ts +80 -0
- package/dist/social.d.ts.map +1 -0
- package/dist/social.js +117 -0
- package/dist/social.js.map +1 -0
- package/dist/tools.d.ts +114 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +106 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +389 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -0
package/dist/economy.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Economy manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified view of an agent's economic position —
|
|
5
|
+
* credits, revenue, BYOK keys, and inference access. Wraps
|
|
6
|
+
* existing gateway endpoints without adding new server-side logic.
|
|
7
|
+
*
|
|
8
|
+
* @module economy
|
|
9
|
+
*/
|
|
10
|
+
export class EconomyManager {
|
|
11
|
+
connection;
|
|
12
|
+
constructor(connection) {
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
}
|
|
15
|
+
// ============================================================
|
|
16
|
+
// Credits
|
|
17
|
+
// ============================================================
|
|
18
|
+
/**
|
|
19
|
+
* Get the unified balance — credits + claimable revenue.
|
|
20
|
+
*/
|
|
21
|
+
async getBalance() {
|
|
22
|
+
const [credits, revenue] = await Promise.all([
|
|
23
|
+
this.connection.request("GET", "/v1/credits/balance"),
|
|
24
|
+
this.connection.request("GET", "/v1/revenue/balance").catch(() => ({
|
|
25
|
+
claimable: 0, totalEarned: 0,
|
|
26
|
+
})),
|
|
27
|
+
]);
|
|
28
|
+
return { credits, revenue };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Add credits to the account.
|
|
32
|
+
*
|
|
33
|
+
* @param amount - Number of credits to add.
|
|
34
|
+
*/
|
|
35
|
+
async topUpCredits(amount) {
|
|
36
|
+
return this.connection.request("POST", "/v1/credits/top-up", { amount });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get usage summary for a time period.
|
|
40
|
+
*
|
|
41
|
+
* @param days - Number of days to look back (default: 30).
|
|
42
|
+
*/
|
|
43
|
+
async getUsage(days = 30) {
|
|
44
|
+
return this.connection.request("GET", `/v1/credits/usage?days=${days}`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get credit transaction history.
|
|
48
|
+
*
|
|
49
|
+
* @param limit - Max transactions to return.
|
|
50
|
+
* @param offset - Pagination offset.
|
|
51
|
+
*/
|
|
52
|
+
async getTransactions(limit = 50, offset = 0) {
|
|
53
|
+
return this.connection.request("GET", `/v1/credits/transactions?limit=${limit}&offset=${offset}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set auto-convert percentage (revenue → credits).
|
|
57
|
+
*
|
|
58
|
+
* @param percentage - Percentage of revenue to auto-convert (0-100).
|
|
59
|
+
*/
|
|
60
|
+
async setAutoConvert(percentage) {
|
|
61
|
+
return this.connection.request("POST", "/v1/credits/auto-convert", {
|
|
62
|
+
percentage,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// ============================================================
|
|
66
|
+
// Inference
|
|
67
|
+
// ============================================================
|
|
68
|
+
/**
|
|
69
|
+
* Make an LLM inference call using credits.
|
|
70
|
+
*
|
|
71
|
+
* @param messages - Conversation messages.
|
|
72
|
+
* @param options - Model, provider, temperature, etc.
|
|
73
|
+
*/
|
|
74
|
+
async inference(messages, options) {
|
|
75
|
+
return this.connection.request("POST", "/v1/inference/chat", {
|
|
76
|
+
messages,
|
|
77
|
+
...options,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Make a streaming LLM inference call (SSE).
|
|
82
|
+
*
|
|
83
|
+
* Returns the full response after streaming completes.
|
|
84
|
+
* For true streaming, use the connection's HTTP client directly.
|
|
85
|
+
*
|
|
86
|
+
* @param messages - Conversation messages.
|
|
87
|
+
* @param options - Model, provider, temperature, etc.
|
|
88
|
+
*/
|
|
89
|
+
async inferenceStream(messages, options) {
|
|
90
|
+
return this.connection.request("POST", "/v1/inference/stream", {
|
|
91
|
+
messages,
|
|
92
|
+
...options,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* List available inference models.
|
|
97
|
+
*/
|
|
98
|
+
async getModels() {
|
|
99
|
+
return this.connection.request("GET", "/v1/inference/models");
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get inference call history.
|
|
103
|
+
*
|
|
104
|
+
* @param limit - Max entries to return.
|
|
105
|
+
* @param offset - Pagination offset.
|
|
106
|
+
*/
|
|
107
|
+
async getInferenceHistory(limit = 20, offset = 0) {
|
|
108
|
+
return this.connection.request("GET", `/v1/inference/history?limit=${limit}&offset=${offset}`);
|
|
109
|
+
}
|
|
110
|
+
// ============================================================
|
|
111
|
+
// BYOK (Bring Your Own Key)
|
|
112
|
+
// ============================================================
|
|
113
|
+
/**
|
|
114
|
+
* Store a BYOK API key for a provider.
|
|
115
|
+
*
|
|
116
|
+
* @param provider - Provider name (e.g., "anthropic", "openai").
|
|
117
|
+
* @param apiKey - The API key to store (encrypted at rest).
|
|
118
|
+
*/
|
|
119
|
+
async storeApiKey(provider, apiKey) {
|
|
120
|
+
return this.connection.request("POST", "/v1/byok", { provider, apiKey });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Remove a stored BYOK API key.
|
|
124
|
+
*
|
|
125
|
+
* @param provider - Provider name to remove.
|
|
126
|
+
*/
|
|
127
|
+
async removeApiKey(provider) {
|
|
128
|
+
return this.connection.request("DELETE", `/v1/byok/${provider}`);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* List stored BYOK providers.
|
|
132
|
+
*/
|
|
133
|
+
async listApiKeys() {
|
|
134
|
+
return this.connection.request("GET", "/v1/byok");
|
|
135
|
+
}
|
|
136
|
+
// ============================================================
|
|
137
|
+
// Revenue
|
|
138
|
+
// ============================================================
|
|
139
|
+
/**
|
|
140
|
+
* Claim earned revenue.
|
|
141
|
+
*/
|
|
142
|
+
async claimEarnings() {
|
|
143
|
+
return this.connection.request("POST", "/v1/revenue/claim");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get earnings summary.
|
|
147
|
+
*/
|
|
148
|
+
async getEarnings() {
|
|
149
|
+
const address = this.connection.address;
|
|
150
|
+
if (!address) {
|
|
151
|
+
throw new Error("Not connected — cannot get earnings");
|
|
152
|
+
}
|
|
153
|
+
return this.connection.request("GET", `/v1/revenue/earnings/${address}`);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get revenue share configuration.
|
|
157
|
+
*/
|
|
158
|
+
async getRevenueConfig() {
|
|
159
|
+
const address = this.connection.address;
|
|
160
|
+
if (!address) {
|
|
161
|
+
throw new Error("Not connected — cannot get revenue config");
|
|
162
|
+
}
|
|
163
|
+
return this.connection.request("GET", `/v1/revenue/config/${address}`);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Set revenue share configuration.
|
|
167
|
+
*
|
|
168
|
+
* @param config - Revenue share percentages.
|
|
169
|
+
*/
|
|
170
|
+
async setRevenueConfig(config) {
|
|
171
|
+
return this.connection.request("POST", "/v1/revenue/config", config);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get distribution history.
|
|
175
|
+
*
|
|
176
|
+
* @param limit - Max entries to return.
|
|
177
|
+
*/
|
|
178
|
+
async getDistributionHistory(limit = 20) {
|
|
179
|
+
const address = this.connection.address;
|
|
180
|
+
if (!address) {
|
|
181
|
+
throw new Error("Not connected — cannot get distribution history");
|
|
182
|
+
}
|
|
183
|
+
return this.connection.request("GET", `/v1/revenue/history/${address}?limit=${limit}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=economy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"economy.js","sourceRoot":"","sources":["../src/economy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,MAAM,OAAO,cAAc;IACR,UAAU,CAAoB;IAE/C,YAAY,UAA6B;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,+DAA+D;IAC/D,WAAW;IACX,+DAA+D;IAE/D;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC3C,IAAI,CAAC,UAAU,CAAC,OAAO,CAGpB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event subscription interface on top of the
|
|
5
|
+
* ConnectionManager's WebSocket. Agents subscribe to event types
|
|
6
|
+
* and receive callbacks when matching events arrive.
|
|
7
|
+
*
|
|
8
|
+
* @module events
|
|
9
|
+
*/
|
|
10
|
+
import type { ConnectionManager } from "./connection.js";
|
|
11
|
+
import type { RuntimeEventType, RuntimeEvent, EventHandler } from "./types.js";
|
|
12
|
+
export declare class EventManager {
|
|
13
|
+
private readonly connection;
|
|
14
|
+
constructor(connection: ConnectionManager);
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to a specific event type.
|
|
17
|
+
*
|
|
18
|
+
* @param eventType - The event type to listen for.
|
|
19
|
+
* @param handler - Callback invoked when matching events arrive.
|
|
20
|
+
*/
|
|
21
|
+
subscribe(eventType: RuntimeEventType | "*", handler: EventHandler): void;
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from a specific event type.
|
|
24
|
+
*
|
|
25
|
+
* @param eventType - The event type to stop listening for.
|
|
26
|
+
* @param handler - The specific handler to remove. If omitted, removes all handlers for this type.
|
|
27
|
+
*/
|
|
28
|
+
unsubscribe(eventType: RuntimeEventType | "*", handler?: EventHandler): void;
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to all events (wildcard).
|
|
31
|
+
*
|
|
32
|
+
* @param handler - Callback invoked for every event.
|
|
33
|
+
*/
|
|
34
|
+
subscribeAll(handler: EventHandler): void;
|
|
35
|
+
/**
|
|
36
|
+
* Unsubscribe from the wildcard handler.
|
|
37
|
+
*
|
|
38
|
+
* @param handler - The specific wildcard handler to remove.
|
|
39
|
+
*/
|
|
40
|
+
unsubscribeAll(handler?: EventHandler): void;
|
|
41
|
+
/**
|
|
42
|
+
* Create a one-time event listener that auto-removes after firing.
|
|
43
|
+
*
|
|
44
|
+
* @param eventType - The event type to listen for.
|
|
45
|
+
* @param handler - Callback invoked once when the event fires.
|
|
46
|
+
*/
|
|
47
|
+
once(eventType: RuntimeEventType, handler: EventHandler): void;
|
|
48
|
+
/**
|
|
49
|
+
* Wait for a specific event type with a timeout.
|
|
50
|
+
*
|
|
51
|
+
* @param eventType - The event type to wait for.
|
|
52
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 30000).
|
|
53
|
+
* @returns The event that was received.
|
|
54
|
+
* @throws If the timeout is reached before an event arrives.
|
|
55
|
+
*/
|
|
56
|
+
waitFor(eventType: RuntimeEventType, timeoutMs?: number): Promise<RuntimeEvent>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/E,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,UAAU,EAAE,iBAAiB;IAIzC;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,gBAAgB,GAAG,GAAG,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIzE;;;;;OAKG;IACH,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI;IAI5E;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIzC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI;IAI5C;;;;;OAKG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAQ9D;;;;;;;OAOG;IACH,OAAO,CAAC,SAAS,EAAE,gBAAgB,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;CAiB/E"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed event subscription interface on top of the
|
|
5
|
+
* ConnectionManager's WebSocket. Agents subscribe to event types
|
|
6
|
+
* and receive callbacks when matching events arrive.
|
|
7
|
+
*
|
|
8
|
+
* @module events
|
|
9
|
+
*/
|
|
10
|
+
export class EventManager {
|
|
11
|
+
connection;
|
|
12
|
+
constructor(connection) {
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to a specific event type.
|
|
17
|
+
*
|
|
18
|
+
* @param eventType - The event type to listen for.
|
|
19
|
+
* @param handler - Callback invoked when matching events arrive.
|
|
20
|
+
*/
|
|
21
|
+
subscribe(eventType, handler) {
|
|
22
|
+
this.connection.on(eventType, handler);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unsubscribe from a specific event type.
|
|
26
|
+
*
|
|
27
|
+
* @param eventType - The event type to stop listening for.
|
|
28
|
+
* @param handler - The specific handler to remove. If omitted, removes all handlers for this type.
|
|
29
|
+
*/
|
|
30
|
+
unsubscribe(eventType, handler) {
|
|
31
|
+
this.connection.off(eventType, handler);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to all events (wildcard).
|
|
35
|
+
*
|
|
36
|
+
* @param handler - Callback invoked for every event.
|
|
37
|
+
*/
|
|
38
|
+
subscribeAll(handler) {
|
|
39
|
+
this.connection.on("*", handler);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Unsubscribe from the wildcard handler.
|
|
43
|
+
*
|
|
44
|
+
* @param handler - The specific wildcard handler to remove.
|
|
45
|
+
*/
|
|
46
|
+
unsubscribeAll(handler) {
|
|
47
|
+
this.connection.off("*", handler);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a one-time event listener that auto-removes after firing.
|
|
51
|
+
*
|
|
52
|
+
* @param eventType - The event type to listen for.
|
|
53
|
+
* @param handler - Callback invoked once when the event fires.
|
|
54
|
+
*/
|
|
55
|
+
once(eventType, handler) {
|
|
56
|
+
const wrapper = (event) => {
|
|
57
|
+
this.connection.off(eventType, wrapper);
|
|
58
|
+
return handler(event);
|
|
59
|
+
};
|
|
60
|
+
this.connection.on(eventType, wrapper);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Wait for a specific event type with a timeout.
|
|
64
|
+
*
|
|
65
|
+
* @param eventType - The event type to wait for.
|
|
66
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 30000).
|
|
67
|
+
* @returns The event that was received.
|
|
68
|
+
* @throws If the timeout is reached before an event arrives.
|
|
69
|
+
*/
|
|
70
|
+
waitFor(eventType, timeoutMs = 30000) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const timer = setTimeout(() => {
|
|
73
|
+
this.connection.off(eventType, handler);
|
|
74
|
+
// MEDIUM-9: Don't leak event type names in unhandled rejections
|
|
75
|
+
reject(new Error("Timeout waiting for runtime event"));
|
|
76
|
+
}, timeoutMs);
|
|
77
|
+
const handler = (event) => {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
this.connection.off(eventType, handler);
|
|
80
|
+
resolve(event);
|
|
81
|
+
};
|
|
82
|
+
this.connection.on(eventType, handler);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,OAAO,YAAY;IACN,UAAU,CAAoB;IAE/C,YAAY,UAA6B;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,SAAiC,EAAE,OAAqB;QAChE,IAAI,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;gBACpB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBACxC,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC;YAEF,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heartbeat manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Monitors the connection state and provides convenience methods
|
|
5
|
+
* for tracking connection health. The actual heartbeat sending
|
|
6
|
+
* is handled by ConnectionManager — this module provides
|
|
7
|
+
* higher-level health monitoring.
|
|
8
|
+
*
|
|
9
|
+
* @module heartbeat
|
|
10
|
+
*/
|
|
11
|
+
import type { ConnectionManager } from "./connection.js";
|
|
12
|
+
import type { ConnectionState } from "./types.js";
|
|
13
|
+
export declare class HeartbeatManager {
|
|
14
|
+
private readonly connection;
|
|
15
|
+
private onHealthChange;
|
|
16
|
+
private lastHealthy;
|
|
17
|
+
constructor(connection: ConnectionManager);
|
|
18
|
+
/**
|
|
19
|
+
* Whether the connection is currently healthy (connected).
|
|
20
|
+
*/
|
|
21
|
+
get isHealthy(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Current connection state.
|
|
24
|
+
*/
|
|
25
|
+
get state(): ConnectionState;
|
|
26
|
+
/**
|
|
27
|
+
* The current session ID (null if not connected).
|
|
28
|
+
*/
|
|
29
|
+
get sessionId(): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Register a callback for health state changes.
|
|
32
|
+
*
|
|
33
|
+
* @param callback - Called with `true` when connection becomes healthy,
|
|
34
|
+
* `false` when it becomes unhealthy.
|
|
35
|
+
*/
|
|
36
|
+
onHealthChanged(callback: (healthy: boolean) => void): void;
|
|
37
|
+
/**
|
|
38
|
+
* Send a manual heartbeat via HTTP (backup for WebSocket heartbeat).
|
|
39
|
+
* Useful if the WebSocket is temporarily down but HTTP still works.
|
|
40
|
+
*/
|
|
41
|
+
manualHeartbeat(): Promise<boolean>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../src/heartbeat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,WAAW,CAAS;gBAEhB,UAAU,EAAE,iBAAiB;IAezC;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,eAAe,CAE3B;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED;;;;;OAKG;IACH,eAAe,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAI3D;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAW1C"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heartbeat manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Monitors the connection state and provides convenience methods
|
|
5
|
+
* for tracking connection health. The actual heartbeat sending
|
|
6
|
+
* is handled by ConnectionManager — this module provides
|
|
7
|
+
* higher-level health monitoring.
|
|
8
|
+
*
|
|
9
|
+
* @module heartbeat
|
|
10
|
+
*/
|
|
11
|
+
export class HeartbeatManager {
|
|
12
|
+
connection;
|
|
13
|
+
onHealthChange = null;
|
|
14
|
+
lastHealthy = false;
|
|
15
|
+
constructor(connection) {
|
|
16
|
+
this.connection = connection;
|
|
17
|
+
// Monitor state changes for health tracking
|
|
18
|
+
this.connection.onStateChange((state) => {
|
|
19
|
+
const healthy = state === "connected";
|
|
20
|
+
if (healthy !== this.lastHealthy) {
|
|
21
|
+
this.lastHealthy = healthy;
|
|
22
|
+
if (this.onHealthChange) {
|
|
23
|
+
try {
|
|
24
|
+
this.onHealthChange(healthy);
|
|
25
|
+
}
|
|
26
|
+
catch { /* swallow */ }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether the connection is currently healthy (connected).
|
|
33
|
+
*/
|
|
34
|
+
get isHealthy() {
|
|
35
|
+
return this.connection.state === "connected";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Current connection state.
|
|
39
|
+
*/
|
|
40
|
+
get state() {
|
|
41
|
+
return this.connection.state;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The current session ID (null if not connected).
|
|
45
|
+
*/
|
|
46
|
+
get sessionId() {
|
|
47
|
+
return this.connection.sessionId;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Register a callback for health state changes.
|
|
51
|
+
*
|
|
52
|
+
* @param callback - Called with `true` when connection becomes healthy,
|
|
53
|
+
* `false` when it becomes unhealthy.
|
|
54
|
+
*/
|
|
55
|
+
onHealthChanged(callback) {
|
|
56
|
+
this.onHealthChange = callback;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Send a manual heartbeat via HTTP (backup for WebSocket heartbeat).
|
|
60
|
+
* Useful if the WebSocket is temporarily down but HTTP still works.
|
|
61
|
+
*/
|
|
62
|
+
async manualHeartbeat() {
|
|
63
|
+
try {
|
|
64
|
+
await this.connection.request("POST", "/v1/runtime/heartbeat");
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=heartbeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../src/heartbeat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,MAAM,OAAO,gBAAgB;IACV,UAAU,CAAoB;IACvC,cAAc,GAAwC,IAAI,CAAC;IAC3D,WAAW,GAAG,KAAK,CAAC;IAE5B,YAAY,UAA6B;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,4CAA4C;QAC5C,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,KAAK,EAAE,EAAE;YACtC,MAAM,OAAO,GAAG,KAAK,KAAK,WAAW,CAAC;YACtC,IAAI,OAAO,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;gBAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;oBACxB,IAAI,CAAC;wBAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;oBAAC,CAAC;oBAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;gBAC/D,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,KAAK,WAAW,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,QAAoC;QAClD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAC3B,MAAM,EACN,uBAAuB,CACxB,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Handles agent registration, profile management, and soul.md
|
|
5
|
+
* document lifecycle via the gateway API.
|
|
6
|
+
*
|
|
7
|
+
* @module identity
|
|
8
|
+
*/
|
|
9
|
+
import type { ConnectionManager } from "./connection.js";
|
|
10
|
+
import type { AgentProfileInput, AgentInfo, SoulUpdateInput } from "./types.js";
|
|
11
|
+
export declare class IdentityManager {
|
|
12
|
+
private readonly connection;
|
|
13
|
+
constructor(connection: ConnectionManager);
|
|
14
|
+
/**
|
|
15
|
+
* Get the current agent's profile.
|
|
16
|
+
*/
|
|
17
|
+
getProfile(): Promise<AgentInfo>;
|
|
18
|
+
/**
|
|
19
|
+
* Look up another agent's profile by address.
|
|
20
|
+
*/
|
|
21
|
+
lookupAgent(address: string): Promise<AgentInfo>;
|
|
22
|
+
/**
|
|
23
|
+
* Register a new agent on the network.
|
|
24
|
+
* Note: Most agents will already be registered via the gateway
|
|
25
|
+
* before using the runtime SDK. This is for programmatic registration.
|
|
26
|
+
*/
|
|
27
|
+
register(profile?: AgentProfileInput): Promise<AgentInfo & {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Update the agent's soul CID (for agent launchpad deployments).
|
|
32
|
+
*/
|
|
33
|
+
updateSoul(input: SoulUpdateInput): Promise<{
|
|
34
|
+
success: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the current agent's address.
|
|
38
|
+
* Convenience method — returns null if not connected.
|
|
39
|
+
*/
|
|
40
|
+
getAddress(): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Get the current agent's ID.
|
|
43
|
+
* Convenience method — returns null if not connected.
|
|
44
|
+
*/
|
|
45
|
+
getAgentId(): string | null;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EACV,iBAAiB,EACjB,SAAS,EACT,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,UAAU,EAAE,iBAAiB;IAIzC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,SAAS,CAAC;IAItC;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAKtD;;;;OAIG;IACG,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAIpF;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAQvE;;;OAGG;IACH,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B;;;OAGG;IACH,UAAU,IAAI,MAAM,GAAG,IAAI;CAG5B"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Handles agent registration, profile management, and soul.md
|
|
5
|
+
* document lifecycle via the gateway API.
|
|
6
|
+
*
|
|
7
|
+
* @module identity
|
|
8
|
+
*/
|
|
9
|
+
export class IdentityManager {
|
|
10
|
+
connection;
|
|
11
|
+
constructor(connection) {
|
|
12
|
+
this.connection = connection;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the current agent's profile.
|
|
16
|
+
*/
|
|
17
|
+
async getProfile() {
|
|
18
|
+
return this.connection.request("GET", "/v1/agents/me");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Look up another agent's profile by address.
|
|
22
|
+
*/
|
|
23
|
+
async lookupAgent(address) {
|
|
24
|
+
// SECURITY: URL-encode path segment to prevent path traversal
|
|
25
|
+
return this.connection.request("GET", `/v1/agents/${encodeURIComponent(address)}`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Register a new agent on the network.
|
|
29
|
+
* Note: Most agents will already be registered via the gateway
|
|
30
|
+
* before using the runtime SDK. This is for programmatic registration.
|
|
31
|
+
*/
|
|
32
|
+
async register(profile) {
|
|
33
|
+
return this.connection.request("POST", "/v1/agents", profile ?? {});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Update the agent's soul CID (for agent launchpad deployments).
|
|
37
|
+
*/
|
|
38
|
+
async updateSoul(input) {
|
|
39
|
+
return this.connection.request("PUT", `/v1/deployments/${encodeURIComponent(input.deploymentId)}/soul`, { soulCid: input.soulCid });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the current agent's address.
|
|
43
|
+
* Convenience method — returns null if not connected.
|
|
44
|
+
*/
|
|
45
|
+
getAddress() {
|
|
46
|
+
return this.connection.address;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the current agent's ID.
|
|
50
|
+
* Convenience method — returns null if not connected.
|
|
51
|
+
*/
|
|
52
|
+
getAgentId() {
|
|
53
|
+
return this.connection.agentId;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,OAAO,eAAe;IACT,UAAU,CAAoB;IAE/C,YAAY,UAA6B;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAY,KAAK,EAAE,eAAe,CAAC,CAAC;IACpE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,8DAA8D;QAC9D,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAY,KAAK,EAAE,cAAc,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAQ,CAAC,OAA2B;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,KAAsB;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAC5B,KAAK,EACL,mBAAmB,kBAAkB,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAChE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAC3B,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;IACjC,CAAC;CACF"}
|
package/dist/inbox.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbox manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides direct messaging between agents. Messages are stored
|
|
5
|
+
* in the gateway's PostgreSQL database (not on-chain) for
|
|
6
|
+
* fast, cheap communication.
|
|
7
|
+
*
|
|
8
|
+
* Real-time delivery is handled via the EventManager — when
|
|
9
|
+
* a message is sent, the recipient receives a `message.received`
|
|
10
|
+
* event over their WebSocket connection.
|
|
11
|
+
*
|
|
12
|
+
* @module inbox
|
|
13
|
+
*/
|
|
14
|
+
import type { ConnectionManager } from "./connection.js";
|
|
15
|
+
import type { SendMessageInput, InboxMessage, InboxFilters, EventHandler } from "./types.js";
|
|
16
|
+
export declare class InboxManager {
|
|
17
|
+
private readonly connection;
|
|
18
|
+
constructor(connection: ConnectionManager);
|
|
19
|
+
/**
|
|
20
|
+
* Send a message to another agent.
|
|
21
|
+
*
|
|
22
|
+
* @param input - Message details (recipient address, content, optional type and metadata).
|
|
23
|
+
*/
|
|
24
|
+
send(input: SendMessageInput): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Get inbox messages with optional filters.
|
|
30
|
+
*
|
|
31
|
+
* @param filters - Optional filters (from, unreadOnly, messageType, pagination).
|
|
32
|
+
*/
|
|
33
|
+
getMessages(filters?: InboxFilters): Promise<{
|
|
34
|
+
messages: InboxMessage[];
|
|
35
|
+
limit: number;
|
|
36
|
+
offset: number;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Mark a message as read.
|
|
40
|
+
*
|
|
41
|
+
* @param messageId - The message ID.
|
|
42
|
+
*/
|
|
43
|
+
markRead(messageId: string): Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Get unread message count.
|
|
48
|
+
*/
|
|
49
|
+
getUnreadCount(): Promise<{
|
|
50
|
+
unreadCount: number;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Delete a message from inbox.
|
|
54
|
+
*
|
|
55
|
+
* @param messageId - The message ID.
|
|
56
|
+
*/
|
|
57
|
+
deleteMessage(messageId: string): Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Register a callback for incoming messages.
|
|
62
|
+
*
|
|
63
|
+
* This is a convenience wrapper around the ConnectionManager's
|
|
64
|
+
* event system. The handler fires when a `message.received`
|
|
65
|
+
* event arrives over WebSocket.
|
|
66
|
+
*
|
|
67
|
+
* @param handler - Callback invoked with the event data.
|
|
68
|
+
*/
|
|
69
|
+
onMessage(handler: EventHandler): void;
|
|
70
|
+
/**
|
|
71
|
+
* Remove a previously registered message handler.
|
|
72
|
+
*
|
|
73
|
+
* @param handler - The handler to remove.
|
|
74
|
+
*/
|
|
75
|
+
offMessage(handler: EventHandler): void;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=inbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox.d.ts","sourceRoot":"","sources":["../src/inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,UAAU,EAAE,iBAAiB;IAIzC;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAS/E;;;;OAIG;IACG,WAAW,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,M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