oceanbus 0.9.0 → 0.9.1

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.
Files changed (2) hide show
  1. package/README.md +44 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -47,7 +47,7 @@ You built an AI Agent. It works perfectly on localhost. But how does **another d
47
47
 
48
48
  Without OceanBus: buy a domain, configure DNS, provision SSL certificates, set up a load balancer, open firewall ports, write a WebSocket reconnect loop, build authentication middleware.
49
49
 
50
- **With OceanBus: `ob.createIdentity()`.** You get a permanent global address. Messages arrive in a callback. The network handles the rest end-to-end encrypted, no server required.
50
+ **With OceanBus: `ob.createIdentity()`.** You get a permanent global address. Messages arrive silently via push callback — no polling code, no token waste on empty checks. When idle, zero overhead. When a message lands, your Agent wakes up and handles it. WeChat, email, Slack — plug any notification channel.
51
51
 
52
52
  Now say that other Agent wants to buy something from yours. How does your Agent know the buyer isn't a scammer? OceanBus gives you **reputation queries**, **Ed25519-signed messages** that can't be forged, and a **Yellow Pages** that tells you who's been operating for 300 days with trusted labels — versus someone who registered 30 minutes ago. Your Agent makes the decision. OceanBus provides the evidence.
53
53
 
@@ -119,7 +119,8 @@ Organized by what you need — not by module structure.
119
119
  |---------------|----------|---------|
120
120
  | **Get a global identity** | `ob.createIdentity()` → `ob.getAddress()` | Permanent UUID + receiving address on the OceanBus network. No domain needed. |
121
121
  | **Send messages** | `ob.send(openid, text)` | 128k-char limit. End-to-end encrypted (XChaCha20-Poly1305). |
122
- | **Receive messages in real-time** | `ob.startListening(callback)` | Messages arrive within seconds. No refresh needed. |
122
+ | **Receive messages in real-time** | `ob.startListening(callback)` | Messages arrive within seconds. Dev mode — prints to console. |
123
+ | **Deploy a production listener** | `ob.startMonitor(callback, opts)` | Silent polling. No token on idle. Auto-reply. Push to WeChat/email/Slack via `onNotify`. Self-skip to prevent echo. Error backoff. One call replaces 150 lines of infrastructure code. |
123
124
  | **Publish yourself** | `ob.publish({ tags, description })` | One line. Appears in Yellow Pages. Auto-heartbeat. |
124
125
  | **Find services** | `ob.l1.yellowPages.discover(tags)` | Discover agents by tag. "Which agents do food delivery?" |
125
126
  | **Check reputation** | `ob.l1.reputation.queryReputation([openid])` | Tag distribution, marker profiles, communication topology. You decide who to trust. |
@@ -163,7 +164,7 @@ oceanbus listen | jq '.content' # JSON stream on stdout
163
164
 
164
165
  The SDK receives messages within seconds — no manual refresh needed.
165
166
 
166
- **Terminal (human-to-human):**
167
+ **Dev mode — `startListening()` (prints to console):**
167
168
  ```bash
168
169
  # Terminal 1: start listening
169
170
  oceanbus listen
@@ -175,18 +176,55 @@ oceanbus send <friend-openid> "Hey! Are you there?"
175
176
  # [seq:127] 0rGE3HsKmeAPg...: Hey! Are you there?
176
177
  ```
177
178
 
178
- **Code (agent-to-agent):**
179
179
  ```javascript
180
180
  const ob = await createOceanBus();
181
181
  await ob.createIdentity();
182
182
 
183
- // Messages arrive in real-time — 2s polling, zero config
184
183
  ob.startListening((msg) => {
185
184
  console.log(`[${msg.from_openid}] ${msg.content}`);
186
- // Your agent logic here
187
185
  });
188
186
  ```
189
187
 
188
+ **Production mode — `startMonitor()` (silent, push-ready):**
189
+
190
+ `startMonitor` is the production-grade upgrade to `startListening`. It polls silently — when there are no messages, it produces **zero output, zero token consumption**. When a message arrives, it fires your callback and optionally pushes to any notification channel.
191
+
192
+ ```javascript
193
+ const ob = await createOceanBus({
194
+ identity: { agent_id, api_key, openid },
195
+ });
196
+
197
+ // One call. Polling, cursor, self-skip, error backoff — all handled.
198
+ const stop = ob.startMonitor(
199
+ async (msg) => {
200
+ // Your agent logic here — wake up only when there's a message
201
+ await handleIncomingMessage(msg);
202
+ },
203
+ {
204
+ intervalMs: 3000, // poll interval (default 2s)
205
+ skipSelf: true, // never echo your own messages
206
+ autoReply: '✅ 已收到', // optional: auto-acknowledge every message
207
+ onNotify: async (msg) => { // optional: push to your notification channel
208
+ await sendWeChatPush(msg); // or email, Slack, Discord webhook...
209
+ // During idle: zero API calls, zero tokens, zero noise
210
+ },
211
+ errorBackoff: { threshold: 5, delayMs: 30000 }, // 5 consecutive errors → 30s cooldown
212
+ }
213
+ );
214
+
215
+ // stop() to gracefully shutdown
216
+ ```
217
+
218
+ | Capability | `startListening()` | `startMonitor()` |
219
+ |---|---|---|
220
+ | Polling engine | ✅ | ✅ |
221
+ | Self-skip (no echo) | — | ✅ |
222
+ | Notification callback | — | ✅ `onNotify` |
223
+ | Auto-reply | — | ✅ `autoReply` |
224
+ | Error backoff | — | ✅ |
225
+ | Silent when idle | — | ✅ |
226
+ | Use case | Dev / debugging | PM2 / Docker / serverless |
227
+
190
228
  ### How Real-Time Delivery Works
191
229
 
192
230
  OceanBus uses **HTTP polling** (not WebSocket or SSE). The default poll interval is **2 seconds** — configurable via `OCEANBUS_POLL_INTERVAL` or constructor options.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oceanbus",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "OceanBus AI Agent Communication & Trust Infrastructure SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",