@agentick/client-multiplexer 0.2.0 → 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/README.md +26 -25
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -13,21 +13,21 @@ pnpm add @agentick/client-multiplexer
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import { createClient } from
|
|
17
|
-
import { createSharedTransport } from
|
|
16
|
+
import { createClient } from "@agentick/client";
|
|
17
|
+
import { createSharedTransport } from "@agentick/client-multiplexer";
|
|
18
18
|
|
|
19
19
|
// Create client with shared transport
|
|
20
20
|
const client = createClient({
|
|
21
|
-
baseUrl:
|
|
22
|
-
transport: createSharedTransport({ baseUrl:
|
|
21
|
+
baseUrl: "/api",
|
|
22
|
+
transport: createSharedTransport({ baseUrl: "/api", token: "your-token" }),
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
// Use exactly like a regular client
|
|
26
|
-
const session = client.session(
|
|
26
|
+
const session = client.session("main");
|
|
27
27
|
session.subscribe();
|
|
28
28
|
session.onEvent((event) => console.log(event));
|
|
29
29
|
|
|
30
|
-
const handle = session.send(
|
|
30
|
+
const handle = session.send("Hello!");
|
|
31
31
|
await handle.result;
|
|
32
32
|
```
|
|
33
33
|
|
|
@@ -56,22 +56,23 @@ The multiplexer uses browser tab leader election to ensure only one tab maintain
|
|
|
56
56
|
Creates a shared transport instance. Supports both SSE and WebSocket transports.
|
|
57
57
|
|
|
58
58
|
```typescript
|
|
59
|
-
import { createSharedTransport, type SharedTransportConfig } from
|
|
59
|
+
import { createSharedTransport, type SharedTransportConfig } from "@agentick/client-multiplexer";
|
|
60
60
|
|
|
61
61
|
// SSE transport (default for http:// URLs)
|
|
62
62
|
const sseTransport = createSharedTransport({
|
|
63
|
-
baseUrl:
|
|
64
|
-
token:
|
|
65
|
-
timeout: 30000,
|
|
66
|
-
withCredentials: true,
|
|
63
|
+
baseUrl: "https://api.example.com",
|
|
64
|
+
token: "your-auth-token", // Optional
|
|
65
|
+
timeout: 30000, // Optional
|
|
66
|
+
withCredentials: true, // Optional
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
// WebSocket transport (default for ws:// URLs)
|
|
70
70
|
const wsTransport = createSharedTransport({
|
|
71
|
-
baseUrl:
|
|
72
|
-
token:
|
|
73
|
-
clientId:
|
|
74
|
-
reconnect: {
|
|
71
|
+
baseUrl: "wss://api.example.com",
|
|
72
|
+
token: "your-auth-token",
|
|
73
|
+
clientId: "my-client", // Optional
|
|
74
|
+
reconnect: {
|
|
75
|
+
// Optional
|
|
75
76
|
enabled: true,
|
|
76
77
|
maxAttempts: 5,
|
|
77
78
|
delay: 1000,
|
|
@@ -80,8 +81,8 @@ const wsTransport = createSharedTransport({
|
|
|
80
81
|
|
|
81
82
|
// Explicit transport selection
|
|
82
83
|
const explicitTransport = createSharedTransport({
|
|
83
|
-
baseUrl:
|
|
84
|
-
transport:
|
|
84
|
+
baseUrl: "https://api.example.com",
|
|
85
|
+
transport: "websocket", // Force WebSocket even with http:// URL
|
|
85
86
|
});
|
|
86
87
|
```
|
|
87
88
|
|
|
@@ -91,31 +92,31 @@ The transport implements `ClientTransport` from `@agentick/client` plus addition
|
|
|
91
92
|
|
|
92
93
|
```typescript
|
|
93
94
|
// Check leadership status
|
|
94
|
-
transport.isLeader;
|
|
95
|
+
transport.isLeader; // boolean
|
|
95
96
|
|
|
96
97
|
// Get unique tab identifier
|
|
97
|
-
transport.tabId;
|
|
98
|
+
transport.tabId; // string
|
|
98
99
|
|
|
99
100
|
// Listen for leadership changes
|
|
100
101
|
transport.onLeadershipChange((isLeader) => {
|
|
101
|
-
console.log(isLeader ?
|
|
102
|
+
console.log(isLeader ? "This tab is now the leader" : "Leadership transferred");
|
|
102
103
|
});
|
|
103
104
|
```
|
|
104
105
|
|
|
105
106
|
### Accessing Transport from Client
|
|
106
107
|
|
|
107
108
|
```typescript
|
|
108
|
-
import { createClient, type ClientTransport } from
|
|
109
|
-
import { createSharedTransport, type SharedTransport } from
|
|
109
|
+
import { createClient, type ClientTransport } from "@agentick/client";
|
|
110
|
+
import { createSharedTransport, type SharedTransport } from "@agentick/client-multiplexer";
|
|
110
111
|
|
|
111
112
|
const client = createClient({
|
|
112
|
-
baseUrl:
|
|
113
|
-
transport: createSharedTransport({ baseUrl:
|
|
113
|
+
baseUrl: "/api",
|
|
114
|
+
transport: createSharedTransport({ baseUrl: "/api" }),
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
// Access the transport for leadership info
|
|
117
118
|
const transport = client.getTransport() as SharedTransport | undefined;
|
|
118
|
-
console.log(
|
|
119
|
+
console.log("Is leader:", transport?.isLeader);
|
|
119
120
|
```
|
|
120
121
|
|
|
121
122
|
## Architecture
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentick/client-multiplexer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Multi-tab connection multiplexer for Agentick client",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/agenticklabs/agentick.git",
|
|
8
|
+
"directory": "packages/client-multiplexer"
|
|
9
|
+
},
|
|
5
10
|
"files": [
|
|
6
11
|
"dist"
|
|
7
12
|
],
|
|
@@ -15,16 +20,11 @@
|
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"dependencies": {
|
|
18
|
-
"@agentick/client": "0.
|
|
23
|
+
"@agentick/client": "0.4.0"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
26
|
"typescript": "^5.8.3"
|
|
22
27
|
},
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/agenticklabs/agentick.git",
|
|
26
|
-
"directory": "packages/client-multiplexer"
|
|
27
|
-
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsc -p tsconfig.build.json",
|
|
30
30
|
"dev": "tsc -p tsconfig.build.json --watch",
|