@agentick/client 0.0.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.
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/client.d.ts +351 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1381 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/sse-transport.d.ts +73 -0
- package/dist/sse-transport.d.ts.map +1 -0
- package/dist/sse-transport.js +415 -0
- package/dist/sse-transport.js.map +1 -0
- package/dist/transport.d.ts +69 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +6 -0
- package/dist/transport.js.map +1 -0
- package/dist/transports/http.d.ts +213 -0
- package/dist/transports/http.d.ts.map +1 -0
- package/dist/transports/http.js +309 -0
- package/dist/transports/http.js.map +1 -0
- package/dist/transports/index.d.ts +16 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/transports/index.js +18 -0
- package/dist/transports/index.js.map +1 -0
- package/dist/transports/websocket.d.ts +114 -0
- package/dist/transports/websocket.d.ts.map +1 -0
- package/dist/transports/websocket.js +239 -0
- package/dist/transports/websocket.js.map +1 -0
- package/dist/types.d.ts +179 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/ws-transport.d.ts +67 -0
- package/dist/ws-transport.d.ts.map +1 -0
- package/dist/ws-transport.js +408 -0
- package/dist/ws-transport.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Agentick Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# @agentick/client
|
|
2
|
+
|
|
3
|
+
Client SDK for multiplexed session access to a Agentick server. One client per app, many sessions per client.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @agentick/client
|
|
9
|
+
# or
|
|
10
|
+
npm install @agentick/client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from "@agentick/client";
|
|
17
|
+
|
|
18
|
+
const client = createClient({ baseUrl: "https://api.example.com" });
|
|
19
|
+
|
|
20
|
+
// Subscribe to a session (hot)
|
|
21
|
+
const conv = client.subscribe("conv-123");
|
|
22
|
+
|
|
23
|
+
// Listen for all events from this session
|
|
24
|
+
conv.onEvent((event) => {
|
|
25
|
+
if (event.type === "content_delta") {
|
|
26
|
+
process.stdout.write(event.delta);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Send a message and await result
|
|
31
|
+
const handle = conv.send({
|
|
32
|
+
message: { role: "user", content: [{ type: "text", text: "Hello!" }] },
|
|
33
|
+
});
|
|
34
|
+
const result = await handle.result;
|
|
35
|
+
console.log(result.response);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API Reference
|
|
39
|
+
|
|
40
|
+
### `createClient(config)`
|
|
41
|
+
|
|
42
|
+
Creates a new AgentickClient instance.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const client = createClient({
|
|
46
|
+
baseUrl: "https://api.example.com",
|
|
47
|
+
token: "bearer_token",
|
|
48
|
+
headers: { "x-tenant": "acme" },
|
|
49
|
+
paths: {
|
|
50
|
+
events: "/events",
|
|
51
|
+
send: "/send",
|
|
52
|
+
subscribe: "/subscribe",
|
|
53
|
+
abort: "/abort",
|
|
54
|
+
close: "/close",
|
|
55
|
+
toolResponse: "/tool-response",
|
|
56
|
+
channel: "/channel",
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `client.session(sessionId)`
|
|
62
|
+
|
|
63
|
+
Returns a **cold** session accessor. No side effects until `subscribe()` or `send()` is called.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const conv = client.session("conv-123");
|
|
67
|
+
conv.subscribe(); // make hot
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### `client.subscribe(sessionId)`
|
|
71
|
+
|
|
72
|
+
Returns a **hot** session accessor. Subscribes immediately (auto-connects if needed).
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const conv = client.subscribe("conv-123");
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `client.send(input)`
|
|
79
|
+
|
|
80
|
+
Ephemeral send. Creates a session, executes, then closes.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const handle = client.send({
|
|
84
|
+
message: { role: "user", content: [{ type: "text", text: "Quick question" }] },
|
|
85
|
+
props: { mode: "fast" },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
for await (const event of handle) {
|
|
89
|
+
if (event.type === "content_delta") {
|
|
90
|
+
process.stdout.write(event.delta);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const result = await handle.result;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Session Accessor
|
|
98
|
+
|
|
99
|
+
### `accessor.subscribe()` / `accessor.unsubscribe()`
|
|
100
|
+
|
|
101
|
+
Turns a cold accessor hot, or turns it cold again. Subscriptions are scoped to the session.
|
|
102
|
+
|
|
103
|
+
### `accessor.send(input)`
|
|
104
|
+
|
|
105
|
+
Send to a session and return a `ClientExecutionHandle`.
|
|
106
|
+
|
|
107
|
+
### `accessor.onEvent(handler)`
|
|
108
|
+
|
|
109
|
+
Receives events for this session only.
|
|
110
|
+
|
|
111
|
+
### `accessor.onResult(handler)`
|
|
112
|
+
|
|
113
|
+
Receives final results for this session only (same as listening for `type: "result"`).
|
|
114
|
+
|
|
115
|
+
### `accessor.onToolConfirmation(handler)`
|
|
116
|
+
|
|
117
|
+
Receives tool confirmation requests for this session.
|
|
118
|
+
|
|
119
|
+
### `accessor.abort(reason?)` / `accessor.close()`
|
|
120
|
+
|
|
121
|
+
Abort the current execution or close the session server-side.
|
|
122
|
+
|
|
123
|
+
### `accessor.invoke(method, params?)`
|
|
124
|
+
|
|
125
|
+
Invoke a custom gateway method with auto-injected sessionId.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const session = client.subscribe("conv-123");
|
|
129
|
+
|
|
130
|
+
// Invoke custom methods defined in gateway
|
|
131
|
+
const tasks = await session.invoke("tasks:list");
|
|
132
|
+
const newTask = await session.invoke("tasks:create", {
|
|
133
|
+
title: "Buy groceries",
|
|
134
|
+
priority: "high"
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Nested namespaces
|
|
138
|
+
await session.invoke("tasks:admin:archive");
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `accessor.stream(method, params?)`
|
|
142
|
+
|
|
143
|
+
Invoke a streaming method with auto-injected sessionId. Returns an async generator.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const session = client.subscribe("conv-123");
|
|
147
|
+
|
|
148
|
+
// Stream updates from a custom method
|
|
149
|
+
for await (const change of session.stream("tasks:watch")) {
|
|
150
|
+
console.log("Task changed:", change);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### `accessor.channel(name)`
|
|
155
|
+
|
|
156
|
+
Session-scoped channel for app-defined pub/sub.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const conv = client.subscribe("conv-123");
|
|
160
|
+
const todos = conv.channel("todos");
|
|
161
|
+
|
|
162
|
+
todos.subscribe((payload) => {
|
|
163
|
+
console.log("Todo update:", payload);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
await todos.publish("add", { title: "Buy milk" });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Global Events
|
|
170
|
+
|
|
171
|
+
### `client.onEvent(handler)`
|
|
172
|
+
|
|
173
|
+
Receives events from **all subscribed sessions**. Events include `sessionId` for routing.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
client.onEvent((event) => {
|
|
177
|
+
console.log(event.sessionId, event.type);
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### `client.on(type, handler)`
|
|
182
|
+
|
|
183
|
+
Convenience subscription by event type (e.g., `"content_delta"`, `"tool_call"`).
|
|
184
|
+
|
|
185
|
+
## Streaming Text
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
client.onStreamingText((state) => {
|
|
189
|
+
console.log(state.text, state.isStreaming);
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Tool Confirmation UI
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const session = client.subscribe("conv-123");
|
|
197
|
+
|
|
198
|
+
session.onToolConfirmation((request, respond) => {
|
|
199
|
+
const approved = window.confirm(`Allow ${request.name}?`);
|
|
200
|
+
respond({
|
|
201
|
+
approved,
|
|
202
|
+
reason: approved ? undefined : "User denied",
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Error Handling
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
client.onConnectionChange((state) => {
|
|
211
|
+
if (state === "error") {
|
|
212
|
+
console.error("Connection error");
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Browser Support
|
|
218
|
+
|
|
219
|
+
- Chrome 89+
|
|
220
|
+
- Firefox 90+
|
|
221
|
+
- Safari 15+
|
|
222
|
+
- Edge 89+
|
|
223
|
+
|
|
224
|
+
## Cleanup
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
client.destroy();
|
|
228
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentickClient - Multiplexed session client
|
|
3
|
+
*
|
|
4
|
+
* Connects to a Agentick server with a single SSE connection
|
|
5
|
+
* that multiplexes events for multiple sessions.
|
|
6
|
+
*
|
|
7
|
+
* @module @agentick/client
|
|
8
|
+
*/
|
|
9
|
+
import type { ConnectionState, ChannelAccessor, GlobalEventHandler, SessionEventHandler, SessionResultHandler, SessionToolConfirmationHandler, ClientEventName, ClientEventHandlerMap, StreamingTextState, StreamingTextHandler, ChannelEvent, ToolConfirmationResponse, SendInput, ClientExecutionHandle } from "./types";
|
|
10
|
+
import type { ContentBlock, Message } from "@agentick/shared";
|
|
11
|
+
import type { ClientTransport } from "./transport.js";
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for AgentickClient.
|
|
14
|
+
*/
|
|
15
|
+
export interface AgentickClientConfig {
|
|
16
|
+
/** Base URL for the server (e.g., https://api.example.com or ws://localhost:18789) */
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
/**
|
|
19
|
+
* Transport to use for communication.
|
|
20
|
+
* - "sse": HTTP/SSE transport (default for http:// and https:// URLs)
|
|
21
|
+
* - "websocket": WebSocket transport (default for ws:// and wss:// URLs)
|
|
22
|
+
* - "auto": Auto-detect based on URL scheme (default)
|
|
23
|
+
* - ClientTransport instance: Use a custom transport (e.g., SharedTransport for multi-tab)
|
|
24
|
+
* @default "auto"
|
|
25
|
+
*/
|
|
26
|
+
transport?: "sse" | "websocket" | "auto" | ClientTransport;
|
|
27
|
+
/** Override default endpoint paths (SSE transport only) */
|
|
28
|
+
paths?: {
|
|
29
|
+
/** SSE stream endpoint (default: /events) */
|
|
30
|
+
events?: string;
|
|
31
|
+
/** Send endpoint (default: /send) */
|
|
32
|
+
send?: string;
|
|
33
|
+
/** Invoke endpoint for custom methods (default: /invoke) */
|
|
34
|
+
invoke?: string;
|
|
35
|
+
/** Subscribe endpoint (default: /subscribe) */
|
|
36
|
+
subscribe?: string;
|
|
37
|
+
/** Abort endpoint (default: /abort) */
|
|
38
|
+
abort?: string;
|
|
39
|
+
/** Close endpoint (default: /close) */
|
|
40
|
+
close?: string;
|
|
41
|
+
/** Tool response endpoint (default: /tool-response) */
|
|
42
|
+
toolResponse?: string;
|
|
43
|
+
/** Channel endpoint (default: /channel) */
|
|
44
|
+
channel?: string;
|
|
45
|
+
};
|
|
46
|
+
/** Authentication token (adds Authorization: Bearer header) */
|
|
47
|
+
token?: string;
|
|
48
|
+
/** Custom headers for all requests */
|
|
49
|
+
headers?: Record<string, string>;
|
|
50
|
+
/** Request timeout in ms (default: 30000) */
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/** Custom fetch implementation (SSE transport only) */
|
|
53
|
+
fetch?: typeof fetch;
|
|
54
|
+
/** Custom EventSource constructor (SSE transport only, for Node.js polyfills) */
|
|
55
|
+
EventSource?: typeof EventSource;
|
|
56
|
+
/** Custom WebSocket constructor (WebSocket transport only, for Node.js) */
|
|
57
|
+
WebSocket?: typeof WebSocket;
|
|
58
|
+
/** Send cookies with requests and SSE */
|
|
59
|
+
withCredentials?: boolean;
|
|
60
|
+
/** Client ID for WebSocket connections */
|
|
61
|
+
clientId?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Session accessor for interacting with a specific session.
|
|
65
|
+
*
|
|
66
|
+
* Cold accessor (from `client.session(id)`) - no server subscription
|
|
67
|
+
* Hot accessor (from `client.subscribe(id)`) - actively receiving events
|
|
68
|
+
*/
|
|
69
|
+
export interface SessionAccessor {
|
|
70
|
+
/** Session ID */
|
|
71
|
+
readonly sessionId: string;
|
|
72
|
+
/** Whether this accessor is subscribed (hot) */
|
|
73
|
+
readonly isSubscribed: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe to session events.
|
|
76
|
+
* Makes this a "hot" accessor.
|
|
77
|
+
*/
|
|
78
|
+
subscribe(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Unsubscribe from session events.
|
|
81
|
+
* Makes this a "cold" accessor.
|
|
82
|
+
*/
|
|
83
|
+
unsubscribe(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Send a message to this session.
|
|
86
|
+
*/
|
|
87
|
+
send(input: SendInput): ClientExecutionHandle;
|
|
88
|
+
/**
|
|
89
|
+
* Abort the current execution.
|
|
90
|
+
*/
|
|
91
|
+
abort(reason?: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Close the session.
|
|
94
|
+
*/
|
|
95
|
+
close(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Submit a tool confirmation response.
|
|
98
|
+
*/
|
|
99
|
+
submitToolResult(toolUseId: string, result: ToolConfirmationResponse): void;
|
|
100
|
+
/**
|
|
101
|
+
* Subscribe to events for this session only.
|
|
102
|
+
*/
|
|
103
|
+
onEvent(handler: SessionEventHandler): () => void;
|
|
104
|
+
/**
|
|
105
|
+
* Subscribe to results for this session only.
|
|
106
|
+
*/
|
|
107
|
+
onResult(handler: SessionResultHandler): () => void;
|
|
108
|
+
/**
|
|
109
|
+
* Subscribe to tool confirmation requests for this session.
|
|
110
|
+
*/
|
|
111
|
+
onToolConfirmation(handler: SessionToolConfirmationHandler): () => void;
|
|
112
|
+
/**
|
|
113
|
+
* Get a channel accessor scoped to this session.
|
|
114
|
+
* Allows pub/sub communication with the server for this session.
|
|
115
|
+
*/
|
|
116
|
+
channel(name: string): ChannelAccessor;
|
|
117
|
+
/**
|
|
118
|
+
* Invoke a custom method with auto-injected sessionId.
|
|
119
|
+
*/
|
|
120
|
+
invoke<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Invoke a streaming method with auto-injected sessionId.
|
|
123
|
+
*/
|
|
124
|
+
stream<T = unknown>(method: string, params?: Record<string, unknown>): AsyncGenerator<T>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* AgentickClient - Multiplexed session client.
|
|
128
|
+
*
|
|
129
|
+
* Connects to a Agentick server with a single SSE connection that
|
|
130
|
+
* can manage multiple session subscriptions.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const client = createClient({
|
|
135
|
+
* baseUrl: 'https://api.example.com',
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* // Get session accessor (cold - no subscription)
|
|
139
|
+
* const session = client.session('conv-123');
|
|
140
|
+
*
|
|
141
|
+
* // Subscribe to receive events (hot)
|
|
142
|
+
* session.subscribe();
|
|
143
|
+
*
|
|
144
|
+
* // Listen for events
|
|
145
|
+
* session.onEvent((event) => {
|
|
146
|
+
* console.log(event);
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* // Send a message
|
|
150
|
+
* const handle = session.send({ messages: [{ role: 'user', content: [...] }] });
|
|
151
|
+
* await handle.result;
|
|
152
|
+
*
|
|
153
|
+
* // Or use ephemeral send (creates session, executes, closes)
|
|
154
|
+
* const ephemeral = client.send({ messages: [{...}] });
|
|
155
|
+
* await ephemeral.result;
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare class AgentickClient {
|
|
159
|
+
private readonly config;
|
|
160
|
+
private readonly fetchFn;
|
|
161
|
+
private readonly EventSourceCtor;
|
|
162
|
+
private readonly requestHeaders;
|
|
163
|
+
private readonly customTransport;
|
|
164
|
+
private transportCleanup;
|
|
165
|
+
private _state;
|
|
166
|
+
private _connectionId?;
|
|
167
|
+
private eventSource?;
|
|
168
|
+
private connectionPromise?;
|
|
169
|
+
private stateHandlers;
|
|
170
|
+
private eventHandlers;
|
|
171
|
+
private streamingTextHandlers;
|
|
172
|
+
private _streamingText;
|
|
173
|
+
private sessions;
|
|
174
|
+
private subscriptions;
|
|
175
|
+
private seenEventIds;
|
|
176
|
+
private seenEventIdsOrder;
|
|
177
|
+
private readonly maxSeenEventIds;
|
|
178
|
+
constructor(config: AgentickClientConfig);
|
|
179
|
+
/**
|
|
180
|
+
* Setup handlers for custom transport events.
|
|
181
|
+
*/
|
|
182
|
+
private setupTransportHandlers;
|
|
183
|
+
/** Current connection state */
|
|
184
|
+
get state(): ConnectionState;
|
|
185
|
+
private setState;
|
|
186
|
+
/**
|
|
187
|
+
* Subscribe to connection state changes.
|
|
188
|
+
*/
|
|
189
|
+
onConnectionChange(handler: (state: ConnectionState) => void): () => void;
|
|
190
|
+
/**
|
|
191
|
+
* Ensure the connection is established.
|
|
192
|
+
* This is called lazily when subscribing to sessions.
|
|
193
|
+
*/
|
|
194
|
+
private ensureConnection;
|
|
195
|
+
private openEventSource;
|
|
196
|
+
private closeEventSource;
|
|
197
|
+
/**
|
|
198
|
+
* Get a session accessor (cold - no subscription).
|
|
199
|
+
*
|
|
200
|
+
* Call `accessor.subscribe()` to receive events.
|
|
201
|
+
*/
|
|
202
|
+
session(sessionId: string): SessionAccessor;
|
|
203
|
+
/**
|
|
204
|
+
* Subscribe to a session and get accessor (hot).
|
|
205
|
+
*/
|
|
206
|
+
subscribe(sessionId: string): SessionAccessor;
|
|
207
|
+
/** @internal - Called by SessionAccessor */
|
|
208
|
+
_subscribeToSession(sessionId: string): Promise<void>;
|
|
209
|
+
/** @internal - Called by SessionAccessor */
|
|
210
|
+
_unsubscribeFromSession(sessionId: string): Promise<void>;
|
|
211
|
+
/** @internal - Called by SessionAccessor to publish to a channel */
|
|
212
|
+
_publishToChannel(sessionId: string, channelName: string, event: ChannelEvent): Promise<void>;
|
|
213
|
+
/** @internal - Called by SessionAccessor to subscribe to a channel */
|
|
214
|
+
_subscribeToChannel(sessionId: string, channelName: string): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Send a message.
|
|
217
|
+
*
|
|
218
|
+
* @param input - Message input (message or messages)
|
|
219
|
+
* @param options - Options including optional sessionId
|
|
220
|
+
*/
|
|
221
|
+
send(input: string | ContentBlock | ContentBlock[] | Message | Message[] | SendInput, options?: {
|
|
222
|
+
sessionId?: string;
|
|
223
|
+
}): ClientExecutionHandle;
|
|
224
|
+
private performSend;
|
|
225
|
+
private normalizeSendInput;
|
|
226
|
+
/**
|
|
227
|
+
* Abort a session's current execution.
|
|
228
|
+
*/
|
|
229
|
+
abort(sessionId: string, reason?: string): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Close a session.
|
|
232
|
+
*/
|
|
233
|
+
closeSession(sessionId: string): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Submit a tool confirmation response.
|
|
236
|
+
*/
|
|
237
|
+
submitToolResult(sessionId: string, toolUseId: string, result: ToolConfirmationResponse): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* Subscribe to all stream events (from all sessions).
|
|
240
|
+
*/
|
|
241
|
+
onEvent(handler: GlobalEventHandler): () => void;
|
|
242
|
+
/**
|
|
243
|
+
* Ergonomic event subscription.
|
|
244
|
+
*/
|
|
245
|
+
on<T extends ClientEventName>(eventName: T, handler: ClientEventHandlerMap[T]): () => void;
|
|
246
|
+
private handleIncomingEvent;
|
|
247
|
+
/** Current streaming text state */
|
|
248
|
+
get streamingText(): StreamingTextState;
|
|
249
|
+
/**
|
|
250
|
+
* Subscribe to streaming text state changes.
|
|
251
|
+
*/
|
|
252
|
+
onStreamingText(handler: StreamingTextHandler): () => void;
|
|
253
|
+
/** Clear the accumulated streaming text */
|
|
254
|
+
clearStreamingText(): void;
|
|
255
|
+
private setStreamingText;
|
|
256
|
+
private updateStreamingText;
|
|
257
|
+
/**
|
|
258
|
+
* Invoke a custom Gateway method.
|
|
259
|
+
* For session-scoped methods, use session.invoke() instead.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* // Invoke a custom method
|
|
264
|
+
* const result = await client.invoke("tasks:list", { status: "active" });
|
|
265
|
+
*
|
|
266
|
+
* // Invoke with admin method
|
|
267
|
+
* const stats = await client.invoke("admin:stats");
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
invoke<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
271
|
+
/**
|
|
272
|
+
* Invoke a streaming method, returns async iterator.
|
|
273
|
+
* Yields values as they arrive from the server.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* // Stream task updates
|
|
278
|
+
* for await (const change of client.stream("tasks:watch")) {
|
|
279
|
+
* console.log("Task changed:", change);
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
stream<T = unknown>(method: string, params?: Record<string, unknown>): AsyncGenerator<T>;
|
|
284
|
+
/**
|
|
285
|
+
* Get authorization headers for use with fetch.
|
|
286
|
+
* Useful for making authenticated requests to custom routes.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* // Make authenticated request to custom API
|
|
291
|
+
* const response = await fetch("/api/custom", {
|
|
292
|
+
* headers: client.getAuthHeaders(),
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
getAuthHeaders(): Record<string, string>;
|
|
297
|
+
/**
|
|
298
|
+
* Cleanup and close the client.
|
|
299
|
+
*/
|
|
300
|
+
destroy(): void;
|
|
301
|
+
/**
|
|
302
|
+
* Get the underlying transport (if using custom transport).
|
|
303
|
+
* Useful for accessing transport-specific features like leadership status.
|
|
304
|
+
*/
|
|
305
|
+
getTransport(): ClientTransport | undefined;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Create a new AgentickClient.
|
|
309
|
+
*
|
|
310
|
+
* Transport is auto-detected from the URL scheme:
|
|
311
|
+
* - http:// or https:// -> SSE transport
|
|
312
|
+
* - ws:// or wss:// -> WebSocket transport
|
|
313
|
+
*
|
|
314
|
+
* You can also explicitly set the transport in the config, or provide
|
|
315
|
+
* a custom ClientTransport instance (e.g., SharedTransport for multi-tab).
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* // Auto-detect transport (SSE for http://)
|
|
320
|
+
* const client = createClient({
|
|
321
|
+
* baseUrl: 'https://api.example.com',
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* // Auto-detect transport (WebSocket for ws://)
|
|
325
|
+
* const wsClient = createClient({
|
|
326
|
+
* baseUrl: 'ws://localhost:18789',
|
|
327
|
+
* });
|
|
328
|
+
*
|
|
329
|
+
* // Force WebSocket transport
|
|
330
|
+
* const wsClient2 = createClient({
|
|
331
|
+
* baseUrl: 'http://localhost:3000',
|
|
332
|
+
* transport: 'websocket',
|
|
333
|
+
* });
|
|
334
|
+
*
|
|
335
|
+
* // Custom transport (e.g., SharedTransport for multi-tab)
|
|
336
|
+
* import { createSharedTransport } from '@agentick/client-multiplexer';
|
|
337
|
+
* const sharedClient = createClient({
|
|
338
|
+
* baseUrl: 'https://api.example.com',
|
|
339
|
+
* transport: createSharedTransport({ baseUrl: 'https://api.example.com' }),
|
|
340
|
+
* });
|
|
341
|
+
*
|
|
342
|
+
* // Subscribe to a session
|
|
343
|
+
* const session = client.subscribe('conv-123');
|
|
344
|
+
*
|
|
345
|
+
* // Send a message
|
|
346
|
+
* const handle = session.send({ messages: [{ role: 'user', content: [...] }] });
|
|
347
|
+
* await handle.result;
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export declare function createClient(config: AgentickClientConfig): AgentickClient;
|
|
351
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,8BAA8B,EAC9B,eAAe,EACf,qBAAqB,EAGrB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EAGZ,wBAAwB,EAGxB,SAAS,EACT,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAM9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,MAAM,GAAG,eAAe,CAAC;IAE3D,2DAA2D;IAC3D,KAAK,CAAC,EAAE;QACN,6CAA6C;QAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,qCAAqC;QACrC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,4DAA4D;QAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,+CAA+C;QAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,uCAA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