@olane/o-client-limited 0.8.3 → 0.8.4

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 +152 -2
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,3 +1,153 @@
1
- # Limited Client
1
+ # @olane/o-client-limited
2
2
 
3
- Re-use connections + streams for libp2p.
3
+ A limited connection client for the Olane network. Provides a constrained connection variant of `oNodeTool` designed for bandwidth-limited, mobile, or resource-constrained environments where connection reuse and minimal network overhead are essential.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @olane/o-client-limited
9
+ ```
10
+
11
+ ## When to Use
12
+
13
+ Use `@olane/o-client-limited` instead of a regular `oNodeTool` when:
14
+
15
+ - **Bandwidth-limited environments** -- The client defaults `runOnLimitedConnection: true`, enabling connection and stream reuse to reduce overhead.
16
+ - **Mobile or edge devices** -- Network listeners are disabled by default (empty `listeners` array), so the node does not bind to ports or accept inbound connections.
17
+ - **Reusing existing connections** -- The limited connection manager is built to piggyback on already-established libp2p connections rather than opening new ones.
18
+ - **Lightweight participants** -- Nodes that only need to call out to the network (consume services) without advertising or serving requests to peers.
19
+
20
+ If your tool needs to listen for inbound connections, serve requests to other peers, or operate in a well-connected datacenter environment, use the standard `oNodeTool` from `@olane/o-node` instead.
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { oLimitedTool } from '@olane/o-client-limited';
26
+ import { oNodeAddress } from '@olane/o-node';
27
+
28
+ class MyLimitedTool extends oLimitedTool {
29
+ constructor(config) {
30
+ super({
31
+ ...config,
32
+ address: new oNodeAddress('o://my-limited-tool'),
33
+ description: 'A tool optimized for limited connections',
34
+ });
35
+ }
36
+
37
+ async _tool_ping(request) {
38
+ return { pong: true, timestamp: Date.now() };
39
+ }
40
+ }
41
+
42
+ // Usage
43
+ const tool = new MyLimitedTool({ leader: null, parent: null });
44
+ await tool.start();
45
+ ```
46
+
47
+ ## API Reference
48
+
49
+ ### oLimitedTool
50
+
51
+ ```typescript
52
+ import { oLimitedTool } from '@olane/o-client-limited';
53
+ ```
54
+
55
+ A subclass of `oNodeTool` that preconfigures the node for limited-connection operation.
56
+
57
+ **Constructor behavior:**
58
+
59
+ | Setting | Value | Purpose |
60
+ |---------|-------|---------|
61
+ | `runOnLimitedConnection` | `true` | Enables connection and stream reuse across requests |
62
+ | `network.listeners` | `[]` (empty) | Disables inbound network listeners by default |
63
+
64
+ You can still override `network.listeners` in the config you pass to the constructor if your use case requires listeners.
65
+
66
+ **Lifecycle hooks** -- The same hooks available on `oNodeTool` apply:
67
+
68
+ | Hook | When to use |
69
+ |------|-------------|
70
+ | `hookInitializeFinished()` | Initialize third-party services, API clients |
71
+ | `hookStartFinished()` | Start background tasks, create child nodes |
72
+ | `stop()` | Clean up resources, disconnect services |
73
+
74
+ **Method exposure** -- Prefix methods with `_tool_` to make them discoverable:
75
+
76
+ ```typescript
77
+ class MyTool extends oLimitedTool {
78
+ async _tool_fetch_data(request) {
79
+ const { query } = request.params;
80
+ if (!query) throw new Error('query is required');
81
+ return { results: await this.search(query) };
82
+ }
83
+ }
84
+ ```
85
+
86
+ ### oLimitedConnectionManager
87
+
88
+ ```typescript
89
+ import { oLimitedConnectionManager } from '@olane/o-client-limited';
90
+ ```
91
+
92
+ A subclass of `oNodeConnectionManager` tailored for limited-connection scenarios. This manager handles the low-level details of connection and stream reuse within the libp2p transport layer.
93
+
94
+ In most cases you do not need to interact with `oLimitedConnectionManager` directly -- `oLimitedTool` manages it internally.
95
+
96
+ ## Response Structure
97
+
98
+ When calling methods on an `oLimitedTool` instance via `node.use()`, responses follow the standard Olane response envelope:
99
+
100
+ ```typescript
101
+ const response = await tool.use(tool.address, {
102
+ method: 'fetch_data',
103
+ params: { query: 'example' },
104
+ });
105
+
106
+ // Check success
107
+ if (response.result.success) {
108
+ const data = response.result.data;
109
+ // { results: [...] }
110
+ } else {
111
+ const error = response.result.error;
112
+ // "query is required"
113
+ }
114
+ ```
115
+
116
+ **Response shape:**
117
+
118
+ ```typescript
119
+ {
120
+ jsonrpc: "2.0",
121
+ id: "request-id",
122
+ result: {
123
+ success: boolean, // Whether the call succeeded
124
+ data: any, // Return value on success
125
+ error?: string, // Error message on failure
126
+ }
127
+ }
128
+ ```
129
+
130
+ ## Comparison: oLimitedTool vs oNodeTool
131
+
132
+ | Aspect | oNodeTool | oLimitedTool |
133
+ |--------|-----------|--------------|
134
+ | **Package** | `@olane/o-node` | `@olane/o-client-limited` |
135
+ | **Network listeners** | Configured per environment | Disabled by default |
136
+ | **Connection reuse** | Optional (`runOnLimitedConnection: false` by default) | Always enabled (`runOnLimitedConnection: true`) |
137
+ | **Inbound requests** | Accepts connections from peers | Does not listen; outbound-only by default |
138
+ | **Best for** | Servers, full network participants | Mobile clients, edge devices, bandwidth-constrained nodes |
139
+ | **Overhead** | Standard libp2p resource usage | Minimal; reuses connections and streams |
140
+
141
+ ## Dependencies
142
+
143
+ | Package | Purpose |
144
+ |---------|---------|
145
+ | `@olane/o-core` | Core types and base classes |
146
+ | `@olane/o-node` | Node base class (`oNodeTool`) and connection primitives |
147
+ | `@olane/o-protocol` | Olane protocol definitions |
148
+ | `@olane/o-tool` | Tool interfaces |
149
+ | `@olane/o-config` | Configuration utilities |
150
+
151
+ ## License
152
+
153
+ MIT OR Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-client-limited",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -54,13 +54,13 @@
54
54
  "typescript": "5.4.5"
55
55
  },
56
56
  "dependencies": {
57
- "@olane/o-config": "0.8.3",
58
- "@olane/o-core": "0.8.3",
59
- "@olane/o-node": "0.8.3",
60
- "@olane/o-protocol": "0.8.3",
61
- "@olane/o-tool": "0.8.3",
57
+ "@olane/o-config": "0.8.4",
58
+ "@olane/o-core": "0.8.4",
59
+ "@olane/o-node": "0.8.4",
60
+ "@olane/o-protocol": "0.8.4",
61
+ "@olane/o-tool": "0.8.4",
62
62
  "debug": "^4.4.1",
63
63
  "dotenv": "^16.5.0"
64
64
  },
65
- "gitHead": "189c0cf7b6dd9d5d961f5424af21d37978092d9e"
65
+ "gitHead": "b53623b1ad4365133911722f80d5597a72b65bf2"
66
66
  }