@openagentmarket/nodejs 1.2.0 → 1.3.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/README.md +118 -119
- package/dist/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +31 -0
- package/my-hirer/README.md +40 -0
- package/my-hirer/index.ts +142 -0
- package/my-hirer/package-lock.json +2527 -0
- package/my-hirer/package.json +20 -0
- package/my-hirer/tsconfig.json +11 -0
- package/my-hirer/xmtp-production-1bdefa5540ad018555ed3798dc2973a4783fc35113e2e624646e26c1e546b826.db3 +0 -0
- package/my-hirer/xmtp-production-1bdefa5540ad018555ed3798dc2973a4783fc35113e2e624646e26c1e546b826.db3-shm +0 -0
- package/my-hirer/xmtp-production-1bdefa5540ad018555ed3798dc2973a4783fc35113e2e624646e26c1e546b826.db3-wal +0 -0
- package/package.json +1 -1
- package/src/client.ts +37 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-hirer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Hire agents on OpenAgent Market",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "tsx index.ts",
|
|
8
|
+
"dev": "tsx watch index.ts"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@openagentmarket/nodejs": "^1.0.0",
|
|
12
|
+
"ethers": "^6.10.0",
|
|
13
|
+
"dotenv": "^16.4.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"tsx": "^4.7.0",
|
|
17
|
+
"typescript": "^5.3.3",
|
|
18
|
+
"@types/node": "^20.11.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client } from '@xmtp/node-sdk';
|
|
1
|
+
import { Client, ConsentState } from '@xmtp/node-sdk';
|
|
2
2
|
import { type Signer, Wallet, HDNodeWallet, getBytes } from 'ethers';
|
|
3
3
|
|
|
4
4
|
export interface OpenAgentClientConfig {
|
|
@@ -243,4 +243,40 @@ export class OpenAgentClient {
|
|
|
243
243
|
}
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Stream all incoming messages across all conversations.
|
|
249
|
+
* Calls the callback for each incoming message (skips own messages).
|
|
250
|
+
* Runs in the background — returns immediately.
|
|
251
|
+
*
|
|
252
|
+
* @param onMessage - Callback receiving (senderAddress, content, conversationId)
|
|
253
|
+
*/
|
|
254
|
+
public async streamAllMessages(
|
|
255
|
+
onMessage: (senderAddress: string, content: string, conversationId: string) => void
|
|
256
|
+
): Promise<void> {
|
|
257
|
+
// Sync all conversations and messages first
|
|
258
|
+
await this.client.conversations.syncAll();
|
|
259
|
+
|
|
260
|
+
const stream = await this.client.conversations.streamAllMessages({
|
|
261
|
+
consentStates: [ConsentState.Allowed, ConsentState.Unknown, ConsentState.Denied]
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Run in background (don't await)
|
|
265
|
+
(async () => {
|
|
266
|
+
try {
|
|
267
|
+
for await (const message of stream) {
|
|
268
|
+
// Skip our own messages
|
|
269
|
+
if ((message as any).senderInboxId === this.client.inboxId) continue;
|
|
270
|
+
|
|
271
|
+
const content = (message as any).content;
|
|
272
|
+
const conversationId = (message as any).conversationId || '';
|
|
273
|
+
const senderAddress = (message as any).senderInboxId || 'unknown';
|
|
274
|
+
|
|
275
|
+
onMessage(senderAddress, String(content), conversationId);
|
|
276
|
+
}
|
|
277
|
+
} catch (err: any) {
|
|
278
|
+
console.error('[OpenAgentClient] Stream error:', err.message);
|
|
279
|
+
}
|
|
280
|
+
})();
|
|
281
|
+
}
|
|
246
282
|
}
|