@scitrera/aether-client 0.1.58
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 +679 -0
- package/dist/index.cjs +5325 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4063 -0
- package/dist/index.d.ts +4063 -0
- package/dist/index.js +5215 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4063 @@
|
|
|
1
|
+
import { Long } from '@grpc/proto-loader';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SubmitAuditEventResponse acknowledges a SubmitAuditEventRequest. success=false
|
|
5
|
+
* indicates the event was rejected before persistence (event type forbidden,
|
|
6
|
+
* rate-limited, ACL denial, audit disabled, etc.).
|
|
7
|
+
*/
|
|
8
|
+
interface SubmitAuditEventResponse__Output {
|
|
9
|
+
/**
|
|
10
|
+
* Echoes the request's correlation ID
|
|
11
|
+
*/
|
|
12
|
+
'clientRequestId': (string);
|
|
13
|
+
/**
|
|
14
|
+
* True iff the event was enqueued for persistence
|
|
15
|
+
*/
|
|
16
|
+
'success': (boolean);
|
|
17
|
+
/**
|
|
18
|
+
* ERR_AUDIT_TYPE_FORBIDDEN / ERR_PERMISSION_DENIED / ERR_AUDIT_RATE_LIMITED / ERR_AUDIT_DISABLED
|
|
19
|
+
*/
|
|
20
|
+
'errorCode': (string);
|
|
21
|
+
/**
|
|
22
|
+
* Human-readable rejection reason
|
|
23
|
+
*/
|
|
24
|
+
'errorMessage': (string);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Type definitions for the Aether TypeScript SDK.
|
|
29
|
+
*
|
|
30
|
+
* This module provides comprehensive type definitions for principal types,
|
|
31
|
+
* message types, KV scopes, topic construction, and callback handlers.
|
|
32
|
+
* These types mirror the protobuf definitions in api/proto/aether.proto
|
|
33
|
+
* and match the patterns established by the Go and Python SDKs.
|
|
34
|
+
*
|
|
35
|
+
* @module types
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Principal types supported by the Aether gateway.
|
|
39
|
+
*
|
|
40
|
+
* Each principal type has different routing rules and permissions:
|
|
41
|
+
* - Agent: Persistent entity with workspace/impl/spec identity
|
|
42
|
+
* - UniqueTask: Named task with persistent identity
|
|
43
|
+
* - NonUniqueTask: Ephemeral task with server-assigned ID
|
|
44
|
+
* - User: Browser/session-based identity with userId/windowId
|
|
45
|
+
* - WorkflowEngine: Event processor (singleton per gateway)
|
|
46
|
+
* - MetricsBridge: Telemetry collector (singleton per gateway)
|
|
47
|
+
* - Orchestrator: Compute provisioner for lazy-loading agents/tasks
|
|
48
|
+
*/
|
|
49
|
+
declare enum PrincipalType {
|
|
50
|
+
Agent = "agent",
|
|
51
|
+
UniqueTask = "unique_task",
|
|
52
|
+
NonUniqueTask = "non_unique_task",
|
|
53
|
+
User = "user",
|
|
54
|
+
WorkflowEngine = "workflow_engine",
|
|
55
|
+
MetricsBridge = "metrics_bridge",
|
|
56
|
+
Orchestrator = "orchestrator",
|
|
57
|
+
Service = "service"
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Message types for the Aether messaging protocol.
|
|
61
|
+
*
|
|
62
|
+
* - Chat: Conversational messages between principals
|
|
63
|
+
* - Control: Control/command messages for state changes
|
|
64
|
+
* - ToolCall: Tool invocation messages
|
|
65
|
+
* - Event: Broadcast events processed by WorkflowEngine
|
|
66
|
+
* - Metric: Telemetry data collected by MetricsBridge
|
|
67
|
+
*/
|
|
68
|
+
declare enum MessageType {
|
|
69
|
+
Unspecified = 0,
|
|
70
|
+
Chat = 1,
|
|
71
|
+
Control = 2,
|
|
72
|
+
ToolCall = 3,
|
|
73
|
+
Event = 4,
|
|
74
|
+
Metric = 5,
|
|
75
|
+
Opaque = 6
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Scopes for KV store operations.
|
|
79
|
+
*
|
|
80
|
+
* - Global: Accessible to all entities across all workspaces
|
|
81
|
+
* - Workspace: Accessible within a specific workspace
|
|
82
|
+
* - User: Accessible to a specific user across all workspaces
|
|
83
|
+
* - UserWorkspace: Accessible to a specific user within a specific workspace
|
|
84
|
+
* - GlobalExclusive: Global scope with exclusive (single-owner) write semantics
|
|
85
|
+
* - WorkspaceExclusive: Workspace scope with exclusive (single-owner) write semantics
|
|
86
|
+
* - UserShared: User scope shared across all agent implementations
|
|
87
|
+
* - UserWorkspaceShared: User-workspace scope shared across all agent implementations
|
|
88
|
+
*/
|
|
89
|
+
declare enum KVScope {
|
|
90
|
+
Unspecified = 0,
|
|
91
|
+
Global = 1,
|
|
92
|
+
Workspace = 2,
|
|
93
|
+
User = 3,
|
|
94
|
+
UserWorkspace = 4,
|
|
95
|
+
GlobalExclusive = 5,
|
|
96
|
+
WorkspaceExclusive = 6,
|
|
97
|
+
UserShared = 7,
|
|
98
|
+
UserWorkspaceShared = 8
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Modes for task assignment.
|
|
102
|
+
*
|
|
103
|
+
* - SelfAssign: Caller self-assigns the task (default)
|
|
104
|
+
* - Targeted: Task is assigned to a specific agent (may trigger orchestration)
|
|
105
|
+
* - Pool: Any matching worker can claim the task
|
|
106
|
+
*/
|
|
107
|
+
declare enum TaskAssignmentMode {
|
|
108
|
+
SelfAssign = 0,
|
|
109
|
+
Targeted = 1,
|
|
110
|
+
Pool = 2
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Signal types from the gateway.
|
|
114
|
+
*/
|
|
115
|
+
declare enum SignalType {
|
|
116
|
+
ForceDisconnect = 0,
|
|
117
|
+
GracefulDisconnect = 1
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* An incoming message received from the Aether gateway.
|
|
121
|
+
*/
|
|
122
|
+
interface IncomingMessage {
|
|
123
|
+
/** The topic from which the message originated (identifies the sender). */
|
|
124
|
+
readonly sourceTopic: string;
|
|
125
|
+
/** The raw message payload. */
|
|
126
|
+
readonly payload: Uint8Array;
|
|
127
|
+
/** The type of the message (Chat, Control, ToolCall, Event, Metric). */
|
|
128
|
+
readonly messageType?: number;
|
|
129
|
+
/** Local timestamp when the message was received. */
|
|
130
|
+
readonly receivedAt: Date;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* An outgoing message to send through the Aether gateway.
|
|
134
|
+
*/
|
|
135
|
+
interface OutgoingMessage {
|
|
136
|
+
/** The destination topic string. */
|
|
137
|
+
targetTopic: string;
|
|
138
|
+
/** The message payload (bytes). */
|
|
139
|
+
payload: Uint8Array;
|
|
140
|
+
/** The type of message. Defaults to Chat. */
|
|
141
|
+
messageType?: MessageType;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* A configuration snapshot received upon connection.
|
|
145
|
+
* Contains KV store data for the client's workspace.
|
|
146
|
+
*/
|
|
147
|
+
interface ConfigSnapshot {
|
|
148
|
+
/** Workspace-scoped key-value pairs (opaque bytes; decode with msgpack/TextDecoder as needed). */
|
|
149
|
+
readonly kv: Record<string, Uint8Array>;
|
|
150
|
+
/** Global-scoped key-value pairs (opaque bytes; decode with msgpack/TextDecoder as needed). */
|
|
151
|
+
readonly globalKv: Record<string, Uint8Array>;
|
|
152
|
+
/** Workspace-exclusive-scoped key-value pairs (opaque bytes). */
|
|
153
|
+
readonly workspaceExclusiveKv: Record<string, Uint8Array>;
|
|
154
|
+
/** Global-exclusive-scoped key-value pairs (opaque bytes). */
|
|
155
|
+
readonly globalExclusiveKv: Record<string, Uint8Array>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A signal from the gateway (e.g., force disconnect).
|
|
159
|
+
*/
|
|
160
|
+
interface Signal {
|
|
161
|
+
/** The signal type. */
|
|
162
|
+
readonly type: SignalType;
|
|
163
|
+
/** Additional context for the signal. */
|
|
164
|
+
readonly reason: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* An error response from the gateway.
|
|
168
|
+
*/
|
|
169
|
+
interface ErrorResponse {
|
|
170
|
+
/** Error code string. */
|
|
171
|
+
readonly code: string;
|
|
172
|
+
/** Human-readable error message. */
|
|
173
|
+
readonly message: string;
|
|
174
|
+
/** Whether the client should retry this request. */
|
|
175
|
+
readonly retryable: boolean;
|
|
176
|
+
/** Suggested retry delay in milliseconds (0 = use default backoff). */
|
|
177
|
+
readonly retryAfterMs: number;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Connection acknowledgment received after successful connection.
|
|
181
|
+
*/
|
|
182
|
+
interface ConnectionAck {
|
|
183
|
+
/** Server-assigned session identifier. Store for session resumption. */
|
|
184
|
+
readonly sessionId: string;
|
|
185
|
+
/** Whether this was a resumed session. */
|
|
186
|
+
readonly resumed: boolean;
|
|
187
|
+
/** For non-unique tasks: the server-assigned task instance ID. Empty otherwise. */
|
|
188
|
+
readonly assignedId: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A task assignment received by orchestrators.
|
|
192
|
+
*/
|
|
193
|
+
interface TaskAssignment {
|
|
194
|
+
readonly taskId: string;
|
|
195
|
+
readonly taskType: string;
|
|
196
|
+
readonly assignedTo: string;
|
|
197
|
+
readonly metadata: Record<string, string>;
|
|
198
|
+
readonly assignedAt: number;
|
|
199
|
+
readonly profile: string;
|
|
200
|
+
readonly launchParams: Record<string, string>;
|
|
201
|
+
readonly targetImplementation: string;
|
|
202
|
+
readonly workspace: string;
|
|
203
|
+
readonly specifier: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Response from a KV store operation.
|
|
207
|
+
*/
|
|
208
|
+
interface KVResponse {
|
|
209
|
+
readonly success: boolean;
|
|
210
|
+
/** Retrieved value (for GET operations). */
|
|
211
|
+
readonly value: Uint8Array;
|
|
212
|
+
/** List of keys (for LIST operations). */
|
|
213
|
+
readonly keys: string[];
|
|
214
|
+
/** Key-value pairs (for LIST with values). */
|
|
215
|
+
readonly kvMap: Record<string, string>;
|
|
216
|
+
/** Correlation ID echoed from the request. */
|
|
217
|
+
readonly requestId: string;
|
|
218
|
+
/** Result of INCREMENT/DECREMENT operations. */
|
|
219
|
+
readonly counterValue?: number;
|
|
220
|
+
/** Whether the guarded increment/decrement was applied (INCREMENT_IF/DECREMENT_IF). */
|
|
221
|
+
readonly applied?: boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Parameters for a KV GET operation.
|
|
225
|
+
*/
|
|
226
|
+
interface KVGetOptions {
|
|
227
|
+
key: string;
|
|
228
|
+
scope?: KVScope;
|
|
229
|
+
userId?: string;
|
|
230
|
+
workspace?: string;
|
|
231
|
+
/** Timeout in milliseconds for sync operations. */
|
|
232
|
+
timeout?: number;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Parameters for a KV PUT operation.
|
|
236
|
+
*/
|
|
237
|
+
interface KVPutOptions {
|
|
238
|
+
key: string;
|
|
239
|
+
value: Uint8Array;
|
|
240
|
+
scope?: KVScope;
|
|
241
|
+
userId?: string;
|
|
242
|
+
workspace?: string;
|
|
243
|
+
/** TTL in seconds (0 = no expiration). */
|
|
244
|
+
ttl?: number;
|
|
245
|
+
/** Timeout in milliseconds for sync operations. */
|
|
246
|
+
timeout?: number;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Parameters for a KV LIST operation.
|
|
250
|
+
*/
|
|
251
|
+
interface KVListOptions {
|
|
252
|
+
keyPrefix?: string;
|
|
253
|
+
scope?: KVScope;
|
|
254
|
+
userId?: string;
|
|
255
|
+
workspace?: string;
|
|
256
|
+
/** Timeout in milliseconds for sync operations. */
|
|
257
|
+
timeout?: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Parameters for a KV DELETE operation.
|
|
261
|
+
*/
|
|
262
|
+
interface KVDeleteOptions {
|
|
263
|
+
key: string;
|
|
264
|
+
scope?: KVScope;
|
|
265
|
+
userId?: string;
|
|
266
|
+
workspace?: string;
|
|
267
|
+
/** Timeout in milliseconds for sync operations. */
|
|
268
|
+
timeout?: number;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Parameters for a KV INCREMENT operation.
|
|
272
|
+
*/
|
|
273
|
+
interface KVIncrementOptions {
|
|
274
|
+
key: string;
|
|
275
|
+
scope?: KVScope;
|
|
276
|
+
userId?: string;
|
|
277
|
+
workspace?: string;
|
|
278
|
+
/** Timeout in milliseconds for sync operations. */
|
|
279
|
+
timeout?: number;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Parameters for a KV DECREMENT operation.
|
|
283
|
+
*/
|
|
284
|
+
interface KVDecrementOptions {
|
|
285
|
+
key: string;
|
|
286
|
+
scope?: KVScope;
|
|
287
|
+
userId?: string;
|
|
288
|
+
workspace?: string;
|
|
289
|
+
/** Timeout in milliseconds for sync operations. */
|
|
290
|
+
timeout?: number;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Parameters for a KV INCREMENT_IF operation (increment only if counter is below ceiling).
|
|
294
|
+
*/
|
|
295
|
+
interface KVIncrementIfOptions {
|
|
296
|
+
key: string;
|
|
297
|
+
/** Amount to increment. Default: 1. */
|
|
298
|
+
delta?: bigint | number;
|
|
299
|
+
/** Ceiling guard: increment only if the current value is strictly below this. */
|
|
300
|
+
ceiling: bigint | number;
|
|
301
|
+
scope?: KVScope;
|
|
302
|
+
userId?: string;
|
|
303
|
+
workspace?: string;
|
|
304
|
+
/** Timeout in milliseconds for sync operations. */
|
|
305
|
+
timeout?: number;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Parameters for a KV DECREMENT_IF operation (decrement only if counter is above floor).
|
|
309
|
+
*/
|
|
310
|
+
interface KVDecrementIfOptions {
|
|
311
|
+
key: string;
|
|
312
|
+
/** Amount to decrement. Default: 1. */
|
|
313
|
+
delta?: bigint | number;
|
|
314
|
+
/** Floor guard: decrement only if the current value is strictly above this. */
|
|
315
|
+
floor: bigint | number;
|
|
316
|
+
scope?: KVScope;
|
|
317
|
+
userId?: string;
|
|
318
|
+
workspace?: string;
|
|
319
|
+
/** Timeout in milliseconds for sync operations. */
|
|
320
|
+
timeout?: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* A progress update received from an agent or task.
|
|
324
|
+
* Delivered via the pg.{workspace} RabbitMQ stream with server-side filtering.
|
|
325
|
+
*/
|
|
326
|
+
interface ProgressUpdate {
|
|
327
|
+
/** The identity of the reporting agent/task (topic format). */
|
|
328
|
+
readonly source: string;
|
|
329
|
+
/** Task or correlation ID this progress relates to. */
|
|
330
|
+
readonly taskId: string;
|
|
331
|
+
/** Current state (e.g., "running", "finishing", "idle"). */
|
|
332
|
+
readonly state: string;
|
|
333
|
+
/** Completion fraction 0.0-1.0, or -1 for indeterminate. */
|
|
334
|
+
readonly completion: number;
|
|
335
|
+
/** Human-readable summary of current activity. */
|
|
336
|
+
readonly summary: string;
|
|
337
|
+
/** Structured step information for multi-step operations. */
|
|
338
|
+
readonly step?: ProgressStep;
|
|
339
|
+
/** Server timestamp when progress was received (Unix milliseconds). */
|
|
340
|
+
readonly timestampMs: number;
|
|
341
|
+
/** Workspace the progress originated from. */
|
|
342
|
+
readonly workspace: string;
|
|
343
|
+
/** Correlation ID from the originating request. */
|
|
344
|
+
readonly requestId: string;
|
|
345
|
+
/** Arbitrary metadata from the reporter. */
|
|
346
|
+
readonly metadata: Record<string, string>;
|
|
347
|
+
/** Target recipient identity topic (empty = broadcast). */
|
|
348
|
+
readonly recipient: string;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* A discrete step within a multi-step progress operation.
|
|
352
|
+
*/
|
|
353
|
+
interface ProgressStep {
|
|
354
|
+
/** Step name/title. */
|
|
355
|
+
readonly name: string;
|
|
356
|
+
/** Detailed description of what this step is doing. */
|
|
357
|
+
readonly detail: string;
|
|
358
|
+
/** Step sequence number (1-based). */
|
|
359
|
+
readonly sequence: number;
|
|
360
|
+
/** Total number of steps (0 = unknown). */
|
|
361
|
+
readonly totalSteps: number;
|
|
362
|
+
/** Step type hint for UI rendering (e.g., "llm_call", "tool_use"). */
|
|
363
|
+
readonly stepType: string;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Options for reporting progress from an agent or task.
|
|
367
|
+
*/
|
|
368
|
+
interface ReportProgressOptions {
|
|
369
|
+
/** Task or correlation ID this progress relates to. Required. */
|
|
370
|
+
taskId: string;
|
|
371
|
+
/** Current state (e.g., "running", "finishing", "idle"). */
|
|
372
|
+
state?: string;
|
|
373
|
+
/** Completion fraction 0.0-1.0, or -1 for indeterminate. Default: -1. */
|
|
374
|
+
completion?: number;
|
|
375
|
+
/** Human-readable summary of current activity. */
|
|
376
|
+
summary?: string;
|
|
377
|
+
/** Step name for multi-step progress. */
|
|
378
|
+
stepName?: string;
|
|
379
|
+
/** Step detail description. */
|
|
380
|
+
stepDetail?: string;
|
|
381
|
+
/** Step sequence number (1-based). */
|
|
382
|
+
stepSequence?: number;
|
|
383
|
+
/** Total number of steps (0 = unknown). */
|
|
384
|
+
stepTotal?: number;
|
|
385
|
+
/** Step type hint for UI rendering. */
|
|
386
|
+
stepType?: string;
|
|
387
|
+
/** Target identity topic to receive updates (empty = broadcast). */
|
|
388
|
+
recipient?: string;
|
|
389
|
+
/** Correlation ID for the originating request. */
|
|
390
|
+
requestId?: string;
|
|
391
|
+
/** Arbitrary key-value metadata. */
|
|
392
|
+
metadata?: Record<string, string>;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Response from a checkpoint operation.
|
|
396
|
+
*/
|
|
397
|
+
interface CheckpointResponse {
|
|
398
|
+
readonly success: boolean;
|
|
399
|
+
readonly data: Uint8Array;
|
|
400
|
+
readonly keys: string[];
|
|
401
|
+
readonly error: string;
|
|
402
|
+
readonly savedAt: number;
|
|
403
|
+
readonly requestId: string;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Represents a task's information from the server.
|
|
407
|
+
*/
|
|
408
|
+
interface TaskInfo {
|
|
409
|
+
taskId: string;
|
|
410
|
+
taskType: string;
|
|
411
|
+
status: string;
|
|
412
|
+
workspace: string;
|
|
413
|
+
targetTopic: string;
|
|
414
|
+
assignedTo: string;
|
|
415
|
+
createdAt: number;
|
|
416
|
+
startedAt: number;
|
|
417
|
+
completedAt: number;
|
|
418
|
+
attempt: number;
|
|
419
|
+
maxAttempts: number;
|
|
420
|
+
error: string;
|
|
421
|
+
metadata: Record<string, string>;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Response to a task query (list or get).
|
|
425
|
+
*/
|
|
426
|
+
interface TaskQueryResponse {
|
|
427
|
+
success: boolean;
|
|
428
|
+
error: string;
|
|
429
|
+
task?: TaskInfo;
|
|
430
|
+
tasks: TaskInfo[];
|
|
431
|
+
totalCount: number;
|
|
432
|
+
/** Correlation ID echoed from the request. */
|
|
433
|
+
requestId?: string;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Response to a task operation (cancel or retry).
|
|
437
|
+
*/
|
|
438
|
+
interface TaskOperationResponse {
|
|
439
|
+
success: boolean;
|
|
440
|
+
message: string;
|
|
441
|
+
error: string;
|
|
442
|
+
task?: TaskInfo;
|
|
443
|
+
/** Correlation ID echoed from the request. */
|
|
444
|
+
requestId?: string;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Response to a CreateTaskRequest that carried a non-empty request_id.
|
|
448
|
+
* Gives the creator the server-assigned task_id for later COMPLETE/FAIL/CANCEL.
|
|
449
|
+
*/
|
|
450
|
+
interface CreateTaskResponse {
|
|
451
|
+
/** Whether the task was created successfully. */
|
|
452
|
+
success: boolean;
|
|
453
|
+
/** Server-assigned task ID on success. */
|
|
454
|
+
taskId: string;
|
|
455
|
+
/** Initial task status, e.g., "pending", "assigned", "pending_pool". */
|
|
456
|
+
status: string;
|
|
457
|
+
/** Error code on failure, e.g., "ERR_PERMISSION_DENIED". */
|
|
458
|
+
errorCode: string;
|
|
459
|
+
/** Human-readable error description. */
|
|
460
|
+
errorMessage: string;
|
|
461
|
+
/** Echoed from the originating CreateTaskRequest for correlation. */
|
|
462
|
+
requestId: string;
|
|
463
|
+
/** For TARGETED tasks successfully delivered: the receiving identity string. */
|
|
464
|
+
assignedTo: string;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Generic workspace operation response.
|
|
468
|
+
*/
|
|
469
|
+
interface WorkspaceResponse {
|
|
470
|
+
readonly success: boolean;
|
|
471
|
+
readonly error: string;
|
|
472
|
+
readonly message: string;
|
|
473
|
+
readonly totalCount: number;
|
|
474
|
+
readonly requestId?: string;
|
|
475
|
+
readonly [key: string]: unknown;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Generic agent operation response.
|
|
479
|
+
*/
|
|
480
|
+
interface AgentResponse {
|
|
481
|
+
readonly success: boolean;
|
|
482
|
+
readonly error: string;
|
|
483
|
+
readonly message: string;
|
|
484
|
+
readonly totalCount: number;
|
|
485
|
+
readonly requestId?: string;
|
|
486
|
+
readonly [key: string]: unknown;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Generic ACL operation response.
|
|
490
|
+
*/
|
|
491
|
+
interface ACLResponse {
|
|
492
|
+
readonly success: boolean;
|
|
493
|
+
readonly error: string;
|
|
494
|
+
readonly message: string;
|
|
495
|
+
readonly requestId?: string;
|
|
496
|
+
readonly [key: string]: unknown;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Stable principal reference attached to an authority grant.
|
|
500
|
+
*/
|
|
501
|
+
interface AuthorityGrantPrincipalRef {
|
|
502
|
+
readonly principalType: string;
|
|
503
|
+
readonly principalId: string;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Resource-specific scope entry attached to an authority grant.
|
|
507
|
+
*/
|
|
508
|
+
interface AuthorityGrantResourceScope {
|
|
509
|
+
readonly resourceType: string;
|
|
510
|
+
readonly patterns: string[];
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Authority grant details returned by runtime or admin grant APIs.
|
|
514
|
+
*/
|
|
515
|
+
interface AuthorityGrantInfo {
|
|
516
|
+
readonly grantId: string;
|
|
517
|
+
readonly rootGrantId: string;
|
|
518
|
+
readonly subject?: AuthorityGrantPrincipalRef;
|
|
519
|
+
readonly delegate?: AuthorityGrantPrincipalRef;
|
|
520
|
+
readonly issuedBy?: AuthorityGrantPrincipalRef;
|
|
521
|
+
readonly rootSubject?: AuthorityGrantPrincipalRef;
|
|
522
|
+
readonly parentGrantId: string;
|
|
523
|
+
readonly mayDelegate: boolean;
|
|
524
|
+
readonly remainingHops: number;
|
|
525
|
+
readonly workspaceScope: string[];
|
|
526
|
+
readonly resourceScope: AuthorityGrantResourceScope[];
|
|
527
|
+
readonly operationScope: string[];
|
|
528
|
+
readonly maxAccessLevel: number;
|
|
529
|
+
readonly accessLevelName: string;
|
|
530
|
+
readonly audienceType: string;
|
|
531
|
+
readonly audienceId: string;
|
|
532
|
+
readonly validWhileAudienceActive: boolean;
|
|
533
|
+
readonly expiresAt: number;
|
|
534
|
+
readonly renewableUntil: number;
|
|
535
|
+
readonly renewedAt: number;
|
|
536
|
+
readonly revoked: boolean;
|
|
537
|
+
readonly revokedAt: number;
|
|
538
|
+
readonly reason: string;
|
|
539
|
+
readonly metadata: Record<string, string>;
|
|
540
|
+
readonly createdAt: number;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Runtime authority-grant operation response.
|
|
544
|
+
*/
|
|
545
|
+
interface AuthorityGrantResponse {
|
|
546
|
+
readonly success: boolean;
|
|
547
|
+
readonly error: string;
|
|
548
|
+
readonly message: string;
|
|
549
|
+
readonly grant?: AuthorityGrantInfo;
|
|
550
|
+
readonly requestId: string;
|
|
551
|
+
/**
|
|
552
|
+
* For LIST_MY_GRANTS / LIST_GRANTS_ON_ME / BATCH_EXCHANGE results.
|
|
553
|
+
*/
|
|
554
|
+
readonly grants?: AuthorityGrantInfo[];
|
|
555
|
+
/**
|
|
556
|
+
* Total matching rows ignoring pagination (LIST_*) or count of returned
|
|
557
|
+
* grants (BATCH_EXCHANGE).
|
|
558
|
+
*/
|
|
559
|
+
readonly total?: number;
|
|
560
|
+
/**
|
|
561
|
+
* Server's hint to clients on how often to revalidate cached grants
|
|
562
|
+
* (seconds). Zero means "no hint" — clients fall back to their own policy.
|
|
563
|
+
*/
|
|
564
|
+
readonly cacheHintTtlSeconds?: number;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Server-pushed AuthorityGrantRevocation event. Sent on the downstream
|
|
568
|
+
* stream when a grant the connected client holds is revoked, directly or
|
|
569
|
+
* via cascade from a parent revocation.
|
|
570
|
+
*/
|
|
571
|
+
interface AuthorityGrantRevocation {
|
|
572
|
+
readonly grantId: string;
|
|
573
|
+
readonly rootGrantId: string;
|
|
574
|
+
readonly reason: string;
|
|
575
|
+
readonly revokedAt: number;
|
|
576
|
+
readonly cascade: boolean;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Workflow operation response.
|
|
580
|
+
*/
|
|
581
|
+
interface WorkflowResponse {
|
|
582
|
+
readonly success: boolean;
|
|
583
|
+
readonly error: string;
|
|
584
|
+
readonly message: string;
|
|
585
|
+
readonly data?: Uint8Array;
|
|
586
|
+
readonly totalCount: number;
|
|
587
|
+
readonly requestId?: string;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Options for querying tasks.
|
|
591
|
+
*/
|
|
592
|
+
interface TaskQueryOptions {
|
|
593
|
+
workspace?: string;
|
|
594
|
+
status?: string;
|
|
595
|
+
taskType?: string;
|
|
596
|
+
limit?: number;
|
|
597
|
+
offset?: number;
|
|
598
|
+
timeout?: number;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Information about an API token.
|
|
602
|
+
*/
|
|
603
|
+
interface TokenInfo {
|
|
604
|
+
readonly id: string;
|
|
605
|
+
readonly name: string;
|
|
606
|
+
readonly principalType: string;
|
|
607
|
+
readonly workspacePatterns: string[];
|
|
608
|
+
readonly scopes: string[];
|
|
609
|
+
readonly createdBy: string;
|
|
610
|
+
readonly expiresAt: number;
|
|
611
|
+
readonly lastUsedAt: number;
|
|
612
|
+
readonly revoked: boolean;
|
|
613
|
+
readonly revokedAt: number;
|
|
614
|
+
readonly createdAt: number;
|
|
615
|
+
readonly updatedAt: number;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Response to a token operation.
|
|
619
|
+
*/
|
|
620
|
+
interface TokenResponse {
|
|
621
|
+
readonly success: boolean;
|
|
622
|
+
readonly error: string;
|
|
623
|
+
readonly message: string;
|
|
624
|
+
readonly token?: TokenInfo;
|
|
625
|
+
readonly tokens: TokenInfo[];
|
|
626
|
+
readonly totalCount: number;
|
|
627
|
+
readonly plaintextToken: string;
|
|
628
|
+
readonly createdToken?: TokenInfo;
|
|
629
|
+
readonly requestId: string;
|
|
630
|
+
}
|
|
631
|
+
/** Handler for incoming messages. */
|
|
632
|
+
type MessageHandler = (message: IncomingMessage) => void | Promise<void>;
|
|
633
|
+
/** Handler for configuration snapshots. */
|
|
634
|
+
type ConfigHandler = (config: ConfigSnapshot) => void | Promise<void>;
|
|
635
|
+
/** Handler for signals from the gateway. */
|
|
636
|
+
type SignalHandler = (signal: Signal) => void | Promise<void>;
|
|
637
|
+
/** Handler for error responses from the gateway. */
|
|
638
|
+
type ErrorHandler = (error: ErrorResponse) => void | Promise<void>;
|
|
639
|
+
/** Handler for KV operation responses. */
|
|
640
|
+
type KVResponseHandler = (response: KVResponse) => void | Promise<void>;
|
|
641
|
+
/** Handler for task assignments (used by orchestrators). */
|
|
642
|
+
type TaskAssignmentHandler = (assignment: TaskAssignment) => void | Promise<void>;
|
|
643
|
+
/** Handler for checkpoint responses. */
|
|
644
|
+
type CheckpointResponseHandler = (response: CheckpointResponse) => void | Promise<void>;
|
|
645
|
+
/** Handler for create task responses. */
|
|
646
|
+
type CreateTaskResponseHandler = (response: CreateTaskResponse) => void | Promise<void>;
|
|
647
|
+
/** Handler for task query responses. */
|
|
648
|
+
type TaskQueryResponseHandler = (response: TaskQueryResponse) => void;
|
|
649
|
+
/** Handler for task operation responses. */
|
|
650
|
+
type TaskOperationResponseHandler = (response: TaskOperationResponse) => void;
|
|
651
|
+
/** Handler for workspace operation responses. */
|
|
652
|
+
type WorkspaceResponseHandler = (response: WorkspaceResponse) => void | Promise<void>;
|
|
653
|
+
/** Handler for agent operation responses. */
|
|
654
|
+
type AgentResponseHandler = (response: AgentResponse) => void | Promise<void>;
|
|
655
|
+
/** Handler for ACL operation responses. */
|
|
656
|
+
type ACLResponseHandler = (response: ACLResponse) => void | Promise<void>;
|
|
657
|
+
/** Handler for runtime authority-grant responses. */
|
|
658
|
+
type AuthorityGrantResponseHandler = (response: AuthorityGrantResponse) => void | Promise<void>;
|
|
659
|
+
/** Handler for server-pushed authority-grant revocation events. */
|
|
660
|
+
type AuthorityGrantRevocationHandler = (event: AuthorityGrantRevocation) => void | Promise<void>;
|
|
661
|
+
/** Handler for workflow operation responses. */
|
|
662
|
+
type WorkflowResponseHandler = (response: WorkflowResponse) => void | Promise<void>;
|
|
663
|
+
/** Handler for token operation responses. */
|
|
664
|
+
type TokenResponseHandler = (response: TokenResponse) => void;
|
|
665
|
+
/** Response type for submitAuditEvent requests. */
|
|
666
|
+
type AuditSubmitResponse = SubmitAuditEventResponse__Output;
|
|
667
|
+
/** Handler for audit-submit responses. */
|
|
668
|
+
type AuditSubmitResponseHandler = (response: AuditSubmitResponse) => void;
|
|
669
|
+
/** Handler for progress updates from agents/tasks. */
|
|
670
|
+
type ProgressHandler = (update: ProgressUpdate) => void | Promise<void>;
|
|
671
|
+
/** Handler for successful connection. */
|
|
672
|
+
type ConnectHandler = (ack: ConnectionAck) => void | Promise<void>;
|
|
673
|
+
/** Handler for disconnection events. */
|
|
674
|
+
type DisconnectHandler = (reason: string) => void | Promise<void>;
|
|
675
|
+
/** Handler for reconnection attempts. */
|
|
676
|
+
type ReconnectingHandler = (attempt: number) => void | Promise<void>;
|
|
677
|
+
/**
|
|
678
|
+
* TLS configuration for secure connections.
|
|
679
|
+
*/
|
|
680
|
+
interface TLSOptions {
|
|
681
|
+
/** PEM-encoded root CA certificates for server verification. */
|
|
682
|
+
rootCerts?: Buffer;
|
|
683
|
+
/** PEM-encoded client private key (for mTLS). */
|
|
684
|
+
privateKey?: Buffer;
|
|
685
|
+
/** PEM-encoded client certificate chain (for mTLS). */
|
|
686
|
+
certChain?: Buffer;
|
|
687
|
+
/** Override server hostname for certificate validation. */
|
|
688
|
+
serverNameOverride?: string;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Connection behavior configuration.
|
|
692
|
+
*/
|
|
693
|
+
interface ConnectionOptions {
|
|
694
|
+
/** Maximum number of connection attempts (0 = infinite for reconnection). Default: 5. */
|
|
695
|
+
maxRetries?: number;
|
|
696
|
+
/** Initial backoff delay in milliseconds. Default: 1000. */
|
|
697
|
+
initialBackoff?: number;
|
|
698
|
+
/** Maximum backoff delay in milliseconds. Default: 30000. */
|
|
699
|
+
maxBackoff?: number;
|
|
700
|
+
/** Multiplier for exponential backoff. Default: 2.0. */
|
|
701
|
+
backoffMultiplier?: number;
|
|
702
|
+
/** Whether to automatically reconnect on connection loss. Default: true. */
|
|
703
|
+
autoReconnect?: boolean;
|
|
704
|
+
/** Timeout for establishing a connection in milliseconds. Default: 30000. */
|
|
705
|
+
connectTimeout?: number;
|
|
706
|
+
/**
|
|
707
|
+
* When true, if the gateway returns a DuplicateIdentityError (ALREADY_EXISTS)
|
|
708
|
+
* during connection, the client will wait briefly and retry. Useful when a
|
|
709
|
+
* previous instance may still be releasing its distributed lock.
|
|
710
|
+
* Default: false.
|
|
711
|
+
*/
|
|
712
|
+
retryOnDuplicate?: boolean;
|
|
713
|
+
/**
|
|
714
|
+
* How long to wait (ms) before retrying after a DuplicateIdentityError.
|
|
715
|
+
* Only used when retryOnDuplicate is true. Default: 5000.
|
|
716
|
+
*/
|
|
717
|
+
retryOnDuplicateDelay?: number;
|
|
718
|
+
/**
|
|
719
|
+
* Maximum number of duplicate-identity retries before giving up.
|
|
720
|
+
* Only used when retryOnDuplicate is true. Default: 5.
|
|
721
|
+
*/
|
|
722
|
+
retryOnDuplicateMaxAttempts?: number;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Authentication credentials passed to the gateway.
|
|
726
|
+
*/
|
|
727
|
+
interface Credentials {
|
|
728
|
+
[key: string]: string;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Creates a credentials object with an API key.
|
|
732
|
+
*
|
|
733
|
+
* @param key - The long-lived API key for authentication
|
|
734
|
+
* @returns Credentials map with the API key header
|
|
735
|
+
*/
|
|
736
|
+
declare function withAPIKey(key: string): Credentials;
|
|
737
|
+
/**
|
|
738
|
+
* Creates a credentials object with a bearer token.
|
|
739
|
+
*
|
|
740
|
+
* @param token - The OAuth/JWT bearer token
|
|
741
|
+
* @returns Credentials map with the authorization header
|
|
742
|
+
*/
|
|
743
|
+
declare function withToken(token: string): Credentials;
|
|
744
|
+
/**
|
|
745
|
+
* Creates a credentials object with a task token.
|
|
746
|
+
*
|
|
747
|
+
* @param token - The short-lived task authentication token
|
|
748
|
+
* @returns Credentials map with the token header
|
|
749
|
+
*/
|
|
750
|
+
declare function withTaskToken(token: string): Credentials;
|
|
751
|
+
/**
|
|
752
|
+
* Creates a credentials object with a tenant ID.
|
|
753
|
+
*
|
|
754
|
+
* @param tenantId - The tenant identifier
|
|
755
|
+
* @returns Credentials map with the tenant ID header
|
|
756
|
+
*/
|
|
757
|
+
declare function withTenant(tenantId: string): Credentials;
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* KV (key-value) store operations for the Aether TypeScript SDK.
|
|
761
|
+
*
|
|
762
|
+
* This module provides the KVClient class for interacting with the
|
|
763
|
+
* hierarchical KV store through the Aether gateway connection.
|
|
764
|
+
*
|
|
765
|
+
* KV operations support four scopes:
|
|
766
|
+
* - Global: Accessible to all entities across all workspaces
|
|
767
|
+
* - Workspace: Accessible within a specific workspace
|
|
768
|
+
* - User: Accessible to a specific user across all workspaces
|
|
769
|
+
* - UserWorkspace: Accessible to a specific user within a specific workspace
|
|
770
|
+
*
|
|
771
|
+
* @module kv
|
|
772
|
+
*/
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* KVClient provides KV store operations over an Aether connection.
|
|
776
|
+
*
|
|
777
|
+
* Access this through `client.kv()` rather than constructing directly.
|
|
778
|
+
*
|
|
779
|
+
* Supports both async (fire-and-forget with callback) and sync (Promise-based)
|
|
780
|
+
* operation modes.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* const kv = client.kv();
|
|
785
|
+
*
|
|
786
|
+
* // Async put (fire-and-forget)
|
|
787
|
+
* kv.put({ key: "my-key", value: encode("my-value"), scope: KVScope.Global });
|
|
788
|
+
*
|
|
789
|
+
* // Sync get (returns a Promise)
|
|
790
|
+
* const response = await kv.getSync({ key: "my-key", scope: KVScope.Global });
|
|
791
|
+
* if (response.success) {
|
|
792
|
+
* console.log("Value:", response.value);
|
|
793
|
+
* }
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
declare class KVClient {
|
|
797
|
+
private _client;
|
|
798
|
+
/** @internal */
|
|
799
|
+
constructor(client: AetherClient);
|
|
800
|
+
/**
|
|
801
|
+
* Retrieves a value from the KV store (async).
|
|
802
|
+
*
|
|
803
|
+
* The response is delivered via the onKVResponse handler callback.
|
|
804
|
+
* For synchronous operation, use {@link getSync}.
|
|
805
|
+
*
|
|
806
|
+
* @param opts - Get operation options
|
|
807
|
+
*/
|
|
808
|
+
get(opts: KVGetOptions): void;
|
|
809
|
+
/**
|
|
810
|
+
* Stores a value in the KV store (async).
|
|
811
|
+
*
|
|
812
|
+
* The response is delivered via the onKVResponse handler callback.
|
|
813
|
+
* For synchronous operation, use {@link putSync}.
|
|
814
|
+
*
|
|
815
|
+
* @param opts - Put operation options
|
|
816
|
+
*/
|
|
817
|
+
put(opts: KVPutOptions): void;
|
|
818
|
+
/**
|
|
819
|
+
* Removes a key from the KV store (async).
|
|
820
|
+
*
|
|
821
|
+
* The response is delivered via the onKVResponse handler callback.
|
|
822
|
+
* For synchronous operation, use {@link deleteSync}.
|
|
823
|
+
*
|
|
824
|
+
* @param opts - Delete operation options
|
|
825
|
+
*/
|
|
826
|
+
delete(opts: KVDeleteOptions): void;
|
|
827
|
+
/**
|
|
828
|
+
* Lists keys from the KV store (async).
|
|
829
|
+
*
|
|
830
|
+
* The response is delivered via the onKVResponse handler callback.
|
|
831
|
+
* For synchronous operation, use {@link listSync}.
|
|
832
|
+
*
|
|
833
|
+
* @param opts - List operation options
|
|
834
|
+
*/
|
|
835
|
+
list(opts?: KVListOptions): void;
|
|
836
|
+
/**
|
|
837
|
+
* Retrieves a value from the KV store and waits for the response.
|
|
838
|
+
*
|
|
839
|
+
* @param opts - Get operation options (includes optional timeout)
|
|
840
|
+
* @returns Promise resolving to the KV response
|
|
841
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
842
|
+
*/
|
|
843
|
+
getSync(opts: KVGetOptions): Promise<KVResponse>;
|
|
844
|
+
/**
|
|
845
|
+
* Stores a value in the KV store and waits for the response.
|
|
846
|
+
*
|
|
847
|
+
* @param opts - Put operation options (includes optional timeout)
|
|
848
|
+
* @returns Promise resolving to the KV response
|
|
849
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
850
|
+
*/
|
|
851
|
+
putSync(opts: KVPutOptions): Promise<KVResponse>;
|
|
852
|
+
/**
|
|
853
|
+
* Removes a key from the KV store and waits for the response.
|
|
854
|
+
*
|
|
855
|
+
* @param opts - Delete operation options (includes optional timeout)
|
|
856
|
+
* @returns Promise resolving to the KV response
|
|
857
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
858
|
+
*/
|
|
859
|
+
deleteSync(opts: KVDeleteOptions): Promise<KVResponse>;
|
|
860
|
+
/**
|
|
861
|
+
* Lists keys from the KV store and waits for the response.
|
|
862
|
+
*
|
|
863
|
+
* @param opts - List operation options (includes optional timeout)
|
|
864
|
+
* @returns Promise resolving to the KV response
|
|
865
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
866
|
+
*/
|
|
867
|
+
listSync(opts?: KVListOptions): Promise<KVResponse>;
|
|
868
|
+
/**
|
|
869
|
+
* Increments a counter in the KV store (async).
|
|
870
|
+
*
|
|
871
|
+
* The response is delivered via the onKVResponse handler callback.
|
|
872
|
+
* For synchronous operation, use {@link incrementSync}.
|
|
873
|
+
*
|
|
874
|
+
* @param opts - Increment operation options
|
|
875
|
+
*/
|
|
876
|
+
increment(opts: KVIncrementOptions): void;
|
|
877
|
+
/**
|
|
878
|
+
* Decrements a counter in the KV store (async).
|
|
879
|
+
*
|
|
880
|
+
* The response is delivered via the onKVResponse handler callback.
|
|
881
|
+
* For synchronous operation, use {@link decrementSync}.
|
|
882
|
+
*
|
|
883
|
+
* @param opts - Decrement operation options
|
|
884
|
+
*/
|
|
885
|
+
decrement(opts: KVDecrementOptions): void;
|
|
886
|
+
/**
|
|
887
|
+
* Increments a counter in the KV store and waits for the response.
|
|
888
|
+
*
|
|
889
|
+
* @param opts - Increment operation options (includes optional timeout)
|
|
890
|
+
* @returns Promise resolving to the KV response with counterValue set
|
|
891
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
892
|
+
*/
|
|
893
|
+
incrementSync(opts: KVIncrementOptions): Promise<KVResponse>;
|
|
894
|
+
/**
|
|
895
|
+
* Decrements a counter in the KV store and waits for the response.
|
|
896
|
+
*
|
|
897
|
+
* @param opts - Decrement operation options (includes optional timeout)
|
|
898
|
+
* @returns Promise resolving to the KV response with counterValue set
|
|
899
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
900
|
+
*/
|
|
901
|
+
decrementSync(opts: KVDecrementOptions): Promise<KVResponse>;
|
|
902
|
+
/**
|
|
903
|
+
* Increments a counter only if it is strictly below `ceiling` (async).
|
|
904
|
+
*
|
|
905
|
+
* The response (with `applied` and `counterValue`) is delivered via the onKVResponse callback.
|
|
906
|
+
* For synchronous operation, use {@link incrementIfSync}.
|
|
907
|
+
*
|
|
908
|
+
* @param opts - IncrementIf operation options
|
|
909
|
+
*/
|
|
910
|
+
incrementIf(opts: KVIncrementIfOptions): void;
|
|
911
|
+
/**
|
|
912
|
+
* Decrements a counter only if it is strictly above `floor` (async).
|
|
913
|
+
*
|
|
914
|
+
* The response (with `applied` and `counterValue`) is delivered via the onKVResponse callback.
|
|
915
|
+
* For synchronous operation, use {@link decrementIfSync}.
|
|
916
|
+
*
|
|
917
|
+
* @param opts - DecrementIf operation options
|
|
918
|
+
*/
|
|
919
|
+
decrementIf(opts: KVDecrementIfOptions): void;
|
|
920
|
+
/**
|
|
921
|
+
* Increments a counter only if it is strictly below `ceiling`, and waits for the response.
|
|
922
|
+
*
|
|
923
|
+
* @param opts - IncrementIf operation options (includes optional timeout)
|
|
924
|
+
* @returns Promise resolving to the KV response with `counterValue` and `applied` set
|
|
925
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
926
|
+
*/
|
|
927
|
+
incrementIfSync(opts: KVIncrementIfOptions): Promise<KVResponse>;
|
|
928
|
+
/**
|
|
929
|
+
* Decrements a counter only if it is strictly above `floor`, and waits for the response.
|
|
930
|
+
*
|
|
931
|
+
* @param opts - DecrementIf operation options (includes optional timeout)
|
|
932
|
+
* @returns Promise resolving to the KV response with `counterValue` and `applied` set
|
|
933
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
934
|
+
*/
|
|
935
|
+
decrementIfSync(opts: KVDecrementIfOptions): Promise<KVResponse>;
|
|
936
|
+
/**
|
|
937
|
+
* Retrieves a value from the global scope (async).
|
|
938
|
+
*
|
|
939
|
+
* @param key - The key to retrieve
|
|
940
|
+
*/
|
|
941
|
+
getGlobal(key: string): void;
|
|
942
|
+
/**
|
|
943
|
+
* Stores a value in the global scope (async).
|
|
944
|
+
*
|
|
945
|
+
* @param key - The key to store
|
|
946
|
+
* @param value - The value to store
|
|
947
|
+
*/
|
|
948
|
+
putGlobal(key: string, value: Uint8Array): void;
|
|
949
|
+
/**
|
|
950
|
+
* Removes a key from the global scope (async).
|
|
951
|
+
*
|
|
952
|
+
* @param key - The key to delete
|
|
953
|
+
*/
|
|
954
|
+
deleteGlobal(key: string): void;
|
|
955
|
+
/**
|
|
956
|
+
* Lists keys from the global scope (async).
|
|
957
|
+
*
|
|
958
|
+
* @param keyPrefix - Prefix to filter keys (empty for all)
|
|
959
|
+
*/
|
|
960
|
+
listGlobal(keyPrefix?: string): void;
|
|
961
|
+
/**
|
|
962
|
+
* Waits for a correlated KV response with timeout.
|
|
963
|
+
* @internal
|
|
964
|
+
*/
|
|
965
|
+
private _waitForResponse;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Checkpoint operations for the Aether TypeScript SDK.
|
|
970
|
+
*
|
|
971
|
+
* Checkpoints allow agents/tasks to persist arbitrary state that survives
|
|
972
|
+
* restarts. This is separate from message offset tracking (handled
|
|
973
|
+
* automatically by RabbitMQ Streams).
|
|
974
|
+
*
|
|
975
|
+
* @module checkpoint
|
|
976
|
+
*/
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Options for a checkpoint save operation.
|
|
980
|
+
*/
|
|
981
|
+
interface CheckpointSaveOptions {
|
|
982
|
+
/** The checkpoint data to save. */
|
|
983
|
+
data: Uint8Array;
|
|
984
|
+
/** Checkpoint key. Allows multiple named checkpoints per identity. Default: "default". */
|
|
985
|
+
key?: string;
|
|
986
|
+
/** TTL in seconds (-1 = server default, 0 = no expiration). */
|
|
987
|
+
ttl?: number;
|
|
988
|
+
/** Timeout in milliseconds for sync operations. */
|
|
989
|
+
timeout?: number;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Options for a checkpoint load operation.
|
|
993
|
+
*/
|
|
994
|
+
interface CheckpointLoadOptions {
|
|
995
|
+
/** Checkpoint key to load. Default: "default". */
|
|
996
|
+
key?: string;
|
|
997
|
+
/** Timeout in milliseconds for sync operations. */
|
|
998
|
+
timeout?: number;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Options for a checkpoint delete operation.
|
|
1002
|
+
*/
|
|
1003
|
+
interface CheckpointDeleteOptions {
|
|
1004
|
+
/** Checkpoint key to delete. Default: "default". */
|
|
1005
|
+
key?: string;
|
|
1006
|
+
/** Timeout in milliseconds for sync operations. */
|
|
1007
|
+
timeout?: number;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Options for a checkpoint list operation.
|
|
1011
|
+
*/
|
|
1012
|
+
interface CheckpointListOptions {
|
|
1013
|
+
/** Timeout in milliseconds for sync operations. */
|
|
1014
|
+
timeout?: number;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* CheckpointClient provides checkpoint operations over an Aether connection.
|
|
1018
|
+
*
|
|
1019
|
+
* Access this through `client.checkpoint()` rather than constructing directly.
|
|
1020
|
+
*
|
|
1021
|
+
* Supports both async (fire-and-forget with callback) and sync (Promise-based)
|
|
1022
|
+
* operation modes.
|
|
1023
|
+
*
|
|
1024
|
+
* @example
|
|
1025
|
+
* ```typescript
|
|
1026
|
+
* const cp = client.checkpoint();
|
|
1027
|
+
*
|
|
1028
|
+
* // Save state
|
|
1029
|
+
* const encoder = new TextEncoder();
|
|
1030
|
+
* await cp.saveSync({ data: encoder.encode(JSON.stringify(myState)) });
|
|
1031
|
+
*
|
|
1032
|
+
* // Load state
|
|
1033
|
+
* const response = await cp.loadSync({});
|
|
1034
|
+
* if (response.success && response.data.length > 0) {
|
|
1035
|
+
* const state = JSON.parse(new TextDecoder().decode(response.data));
|
|
1036
|
+
* }
|
|
1037
|
+
*
|
|
1038
|
+
* // List checkpoints
|
|
1039
|
+
* const listResponse = await cp.listSync({});
|
|
1040
|
+
* console.log("Checkpoint keys:", listResponse.keys);
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
declare class CheckpointClient {
|
|
1044
|
+
private _client;
|
|
1045
|
+
/** @internal */
|
|
1046
|
+
constructor(client: AetherClient);
|
|
1047
|
+
/**
|
|
1048
|
+
* Saves checkpoint data (async).
|
|
1049
|
+
* The response is delivered via the onCheckpointResponse handler.
|
|
1050
|
+
*/
|
|
1051
|
+
save(opts: CheckpointSaveOptions): void;
|
|
1052
|
+
/**
|
|
1053
|
+
* Loads checkpoint data (async).
|
|
1054
|
+
* The response is delivered via the onCheckpointResponse handler.
|
|
1055
|
+
*/
|
|
1056
|
+
load(opts?: CheckpointLoadOptions): void;
|
|
1057
|
+
/**
|
|
1058
|
+
* Deletes a checkpoint (async).
|
|
1059
|
+
* The response is delivered via the onCheckpointResponse handler.
|
|
1060
|
+
*/
|
|
1061
|
+
delete(opts?: CheckpointDeleteOptions): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* Lists checkpoint keys (async).
|
|
1064
|
+
* The response is delivered via the onCheckpointResponse handler.
|
|
1065
|
+
*/
|
|
1066
|
+
list(): void;
|
|
1067
|
+
/**
|
|
1068
|
+
* Saves checkpoint data and waits for the response.
|
|
1069
|
+
*
|
|
1070
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
1071
|
+
*/
|
|
1072
|
+
saveSync(opts: CheckpointSaveOptions): Promise<CheckpointResponse>;
|
|
1073
|
+
/**
|
|
1074
|
+
* Loads checkpoint data and waits for the response.
|
|
1075
|
+
*
|
|
1076
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
1077
|
+
*/
|
|
1078
|
+
loadSync(opts?: CheckpointLoadOptions): Promise<CheckpointResponse>;
|
|
1079
|
+
/**
|
|
1080
|
+
* Deletes a checkpoint and waits for the response.
|
|
1081
|
+
*
|
|
1082
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
1083
|
+
*/
|
|
1084
|
+
deleteSync(opts?: CheckpointDeleteOptions): Promise<CheckpointResponse>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Lists checkpoint keys and waits for the response.
|
|
1087
|
+
*
|
|
1088
|
+
* @throws {@link TimeoutError} if the operation times out
|
|
1089
|
+
*/
|
|
1090
|
+
listSync(opts?: CheckpointListOptions): Promise<CheckpointResponse>;
|
|
1091
|
+
private _waitForResponse;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* Tunnel (tunnelDial) support for the Aether TypeScript SDK.
|
|
1096
|
+
*
|
|
1097
|
+
* Provides `tunnelDial()` on AetherClient for opening a bidirectional byte-stream
|
|
1098
|
+
* tunnel through the Aether gRPC connection to a remote service.
|
|
1099
|
+
*
|
|
1100
|
+
* Uses the Web Streams API (ReadableStream / WritableStream) so callers work
|
|
1101
|
+
* in both Node ≥18 and browser environments.
|
|
1102
|
+
*
|
|
1103
|
+
* @module tunnel
|
|
1104
|
+
*/
|
|
1105
|
+
|
|
1106
|
+
/** Wire protocol for the tunnel. */
|
|
1107
|
+
type TunnelProtocol = "tcp" | "udp" | "ws" | "websocket";
|
|
1108
|
+
/** Options for tunnelDial(). */
|
|
1109
|
+
interface TunnelDialOptions {
|
|
1110
|
+
/** Hint passed to the remote sidecar (e.g. "host:port"). */
|
|
1111
|
+
remoteHint?: string;
|
|
1112
|
+
/** Idle timeout in ms (server-side enforcement). */
|
|
1113
|
+
idleTimeoutMs?: number;
|
|
1114
|
+
/** Byte quota (server-side enforcement). */
|
|
1115
|
+
maxBytes?: number;
|
|
1116
|
+
/** Arbitrary metadata forwarded in TunnelOpen (e.g. WS sub-protocols). */
|
|
1117
|
+
metadata?: Record<string, string>;
|
|
1118
|
+
/** Reserved for v2 reconnect/resume; ignored in v1. */
|
|
1119
|
+
sessionToken?: string;
|
|
1120
|
+
/** Initial outbound credit window (default: 16). */
|
|
1121
|
+
initialCredits?: number;
|
|
1122
|
+
/**
|
|
1123
|
+
* Pin the tunnel to a named terminator backend. The backend's allow-list
|
|
1124
|
+
* still applies — explicit naming selects which backend's ACL is consulted,
|
|
1125
|
+
* not whether the tunnel is allowed.
|
|
1126
|
+
*/
|
|
1127
|
+
backend?: string;
|
|
1128
|
+
}
|
|
1129
|
+
/** Reason string from a remote TunnelClose frame. */
|
|
1130
|
+
type TunnelCloseReason = "NORMAL" | "PEER_RESET" | "IDLE_TIMEOUT" | "QUOTA" | "ERROR" | string;
|
|
1131
|
+
/** Error thrown when the remote side sends a TunnelClose frame. */
|
|
1132
|
+
declare class TunnelClosedError extends Error {
|
|
1133
|
+
readonly reason: TunnelCloseReason;
|
|
1134
|
+
readonly detail: string;
|
|
1135
|
+
constructor(reason: TunnelCloseReason, detail: string);
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Duplex tunnel object returned by tunnelDial().
|
|
1139
|
+
*
|
|
1140
|
+
* - `readable`: incoming bytes from the remote end.
|
|
1141
|
+
* - `writable`: outgoing bytes to the remote end.
|
|
1142
|
+
* - `close()`: send a NORMAL TunnelClose and clean up.
|
|
1143
|
+
*/
|
|
1144
|
+
interface TunnelStream {
|
|
1145
|
+
/** Readable stream of inbound Uint8Array chunks from the remote end. */
|
|
1146
|
+
readonly readable: ReadableStream<Uint8Array>;
|
|
1147
|
+
/** Writable stream; write Uint8Array chunks to send to the remote end. */
|
|
1148
|
+
readonly writable: WritableStream<Uint8Array>;
|
|
1149
|
+
/** Sends TunnelClose{NORMAL} and tears down both streams. */
|
|
1150
|
+
close(): void;
|
|
1151
|
+
/** Resolves when the tunnel is fully closed (either side). */
|
|
1152
|
+
readonly closed: Promise<void>;
|
|
1153
|
+
}
|
|
1154
|
+
/** @internal */
|
|
1155
|
+
interface TunnelInflight {
|
|
1156
|
+
/** Push inbound data (from downstream TunnelData) into the readable side. */
|
|
1157
|
+
pushData(data: Uint8Array, fin: boolean): void;
|
|
1158
|
+
/** Replenish outbound credits (from downstream TunnelAck). */
|
|
1159
|
+
addCredits(n: number): void;
|
|
1160
|
+
/** Signal that the remote closed the tunnel. */
|
|
1161
|
+
closeWithError(err: TunnelClosedError): void;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Opens a byte-stream tunnel through the Aether connection.
|
|
1165
|
+
*
|
|
1166
|
+
* @param client - Connected AetherClient instance.
|
|
1167
|
+
* @param target - Target topic (e.g. "sv::proxy::default").
|
|
1168
|
+
* @param protocol - Wire protocol: "tcp", "udp", "ws", or "websocket".
|
|
1169
|
+
* @param options - Optional dial parameters.
|
|
1170
|
+
* @returns A TunnelStream with readable/writable Web Streams and a close() method.
|
|
1171
|
+
* @throws {@link ConnectionError} if not connected.
|
|
1172
|
+
*/
|
|
1173
|
+
declare function tunnelDial(client: AetherClient, target: string, protocol: TunnelProtocol, options?: TunnelDialOptions): TunnelStream;
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* Authority grant cache for the Aether TypeScript client.
|
|
1177
|
+
*
|
|
1178
|
+
* Mirrors the Python `AuthorityGrantCache` (see
|
|
1179
|
+
* `sdk/python-client/scitrera_aether_client/authority_cache.py`):
|
|
1180
|
+
*
|
|
1181
|
+
* - Caches grants per `(sourceSessionId, audienceType, audienceId)`.
|
|
1182
|
+
* - Soft-renews at `expiresAt - softRenewSkewMs` (configurable).
|
|
1183
|
+
* - Honors server `cacheHintTtlSeconds` from `AuthorityGrantResponse` as
|
|
1184
|
+
* an upper bound on the cached lifetime.
|
|
1185
|
+
* - Listens for `AuthorityGrantRevocation` push events and invalidates
|
|
1186
|
+
* matching entries by `grantId` OR `rootGrantId` (cascade).
|
|
1187
|
+
* - `deriveForTask(...)` uses the idempotent `DERIVE_FOR_TARGET` op so
|
|
1188
|
+
* repeated calls return the same grant rather than minting new ones.
|
|
1189
|
+
*
|
|
1190
|
+
* Concurrency: per-key in-flight Promise dedupe collapses concurrent
|
|
1191
|
+
* `getOrExchange` / `deriveForTask` calls so only one network round-trip
|
|
1192
|
+
* happens per cache key at a time.
|
|
1193
|
+
*
|
|
1194
|
+
* @module authority-cache
|
|
1195
|
+
*/
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Configuration for {@link AuthorityGrantCache}.
|
|
1199
|
+
*/
|
|
1200
|
+
interface AuthorityGrantCacheOptions {
|
|
1201
|
+
/**
|
|
1202
|
+
* Soft-renew skew, in milliseconds. Re-exchange a grant this long
|
|
1203
|
+
* before its server-side `expiresAt`. Default: 30000 (30 s) to match
|
|
1204
|
+
* the connection-lock heartbeat cadence.
|
|
1205
|
+
*/
|
|
1206
|
+
softRenewSkewMs?: number;
|
|
1207
|
+
/**
|
|
1208
|
+
* Default per-op timeout (ms) passed through to the underlying client
|
|
1209
|
+
* when the cache issues exchange / derive / revoke calls. Default:
|
|
1210
|
+
* 10000.
|
|
1211
|
+
*/
|
|
1212
|
+
opTimeoutMs?: number;
|
|
1213
|
+
/**
|
|
1214
|
+
* Wall-clock provider, returning unix-ms. Pluggable for tests.
|
|
1215
|
+
* Default: `Date.now`.
|
|
1216
|
+
*/
|
|
1217
|
+
clock?: () => number;
|
|
1218
|
+
/**
|
|
1219
|
+
* When true the cache treats `AuthorityGrantInfo.expiresAt` as
|
|
1220
|
+
* unix-MILLISECONDS rather than unix-seconds. The proto comment on
|
|
1221
|
+
* `AuthorityGrantInfo` says "Unix seconds" but the runtime
|
|
1222
|
+
* `ACLAuthorityGrantInfo` uses milliseconds in practice — pick the
|
|
1223
|
+
* unit your gateway emits. Default: `false` (seconds).
|
|
1224
|
+
*/
|
|
1225
|
+
expiresAtInMillis?: boolean;
|
|
1226
|
+
}
|
|
1227
|
+
/** Subset of {@link AetherClient} the cache depends on. */
|
|
1228
|
+
interface AuthorityCacheClient {
|
|
1229
|
+
exchangeAuthorityGrant(opts: Record<string, unknown>): Promise<AuthorityGrantResponse>;
|
|
1230
|
+
deriveAuthorityGrantForTarget(opts: Record<string, unknown>): Promise<AuthorityGrantResponse>;
|
|
1231
|
+
revokeAuthorityGrant(grantId: string, timeout?: number): Promise<AuthorityGrantResponse>;
|
|
1232
|
+
_removeAuthorityCache?(cache: AuthorityGrantCache): void;
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Per-actor cache of runtime authority grants. See module docstring for
|
|
1236
|
+
* the behavioural contract.
|
|
1237
|
+
*/
|
|
1238
|
+
declare class AuthorityGrantCache {
|
|
1239
|
+
private readonly _client;
|
|
1240
|
+
private readonly _softRenewSkewMs;
|
|
1241
|
+
private readonly _opTimeoutMs;
|
|
1242
|
+
private readonly _clock;
|
|
1243
|
+
private readonly _expiresAtInMillis;
|
|
1244
|
+
private readonly _entries;
|
|
1245
|
+
/** grantId -> set of cache keys, for fast revocation lookup. */
|
|
1246
|
+
private readonly _grantIdIndex;
|
|
1247
|
+
/** rootGrantId -> set of cache keys, for cascade invalidation. */
|
|
1248
|
+
private readonly _rootGrantIdIndex;
|
|
1249
|
+
/** In-flight per-key fetch promises, for single-flight de-dupe. */
|
|
1250
|
+
private readonly _inflight;
|
|
1251
|
+
private _closed;
|
|
1252
|
+
constructor(client: AuthorityCacheClient, opts?: AuthorityGrantCacheOptions);
|
|
1253
|
+
/**
|
|
1254
|
+
* Return a cached grant for the (sourceSessionId, audienceType,
|
|
1255
|
+
* audienceId) triplet, or exchange a fresh one. Callers MUST keep the
|
|
1256
|
+
* rest of the request shape stable for a given key.
|
|
1257
|
+
*
|
|
1258
|
+
* Returns `null` when the gateway response is missing, has
|
|
1259
|
+
* `success === false`, or carries no grant — callers should fall back
|
|
1260
|
+
* to direct invocation or surface the error.
|
|
1261
|
+
*/
|
|
1262
|
+
getOrExchange(opts: {
|
|
1263
|
+
sourceSessionId: string;
|
|
1264
|
+
audienceType?: string;
|
|
1265
|
+
audienceId?: string;
|
|
1266
|
+
workspaceScope?: string[];
|
|
1267
|
+
resourceScope?: {
|
|
1268
|
+
resourceType: string;
|
|
1269
|
+
patterns: string[];
|
|
1270
|
+
}[];
|
|
1271
|
+
operationScope?: string[];
|
|
1272
|
+
maxAccessLevel?: number;
|
|
1273
|
+
validWhileAudienceActive?: boolean;
|
|
1274
|
+
expiresAt?: number;
|
|
1275
|
+
renewableUntil?: number;
|
|
1276
|
+
mayDelegate?: boolean;
|
|
1277
|
+
remainingHops?: number;
|
|
1278
|
+
reason?: string;
|
|
1279
|
+
metadata?: Record<string, string>;
|
|
1280
|
+
timeout?: number;
|
|
1281
|
+
}): Promise<AuthorityGrantInfo | null>;
|
|
1282
|
+
/**
|
|
1283
|
+
* Idempotent derive for a target task: returns an existing visible
|
|
1284
|
+
* grant matching (parentGrantId, taskId, audience) when one is in
|
|
1285
|
+
* place, otherwise mints a new one via `DERIVE_FOR_TARGET`. Safe to
|
|
1286
|
+
* call repeatedly without leaking grants.
|
|
1287
|
+
*/
|
|
1288
|
+
deriveForTask(opts: {
|
|
1289
|
+
parentGrantId: string;
|
|
1290
|
+
taskId: string;
|
|
1291
|
+
audienceType?: string;
|
|
1292
|
+
audienceId?: string;
|
|
1293
|
+
operationScope?: string[];
|
|
1294
|
+
maxAccessLevel?: number;
|
|
1295
|
+
expiresAt?: number;
|
|
1296
|
+
renewableUntil?: number;
|
|
1297
|
+
mayDelegate?: boolean;
|
|
1298
|
+
remainingHops?: number;
|
|
1299
|
+
reason?: string;
|
|
1300
|
+
timeout?: number;
|
|
1301
|
+
}): Promise<AuthorityGrantInfo | null>;
|
|
1302
|
+
/** General form of {@link deriveForTask} for arbitrary target principals. */
|
|
1303
|
+
deriveForTarget(opts: {
|
|
1304
|
+
parentGrantId: string;
|
|
1305
|
+
targetType: string;
|
|
1306
|
+
targetId: string;
|
|
1307
|
+
audienceType?: string;
|
|
1308
|
+
audienceId?: string;
|
|
1309
|
+
operationScope?: string[];
|
|
1310
|
+
maxAccessLevel?: number;
|
|
1311
|
+
expiresAt?: number;
|
|
1312
|
+
renewableUntil?: number;
|
|
1313
|
+
mayDelegate?: boolean;
|
|
1314
|
+
remainingHops?: number;
|
|
1315
|
+
reason?: string;
|
|
1316
|
+
timeout?: number;
|
|
1317
|
+
}): Promise<AuthorityGrantInfo | null>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Drop every cache entry whose grant ID OR root grant ID matches.
|
|
1320
|
+
* Returns the number of entries dropped. Safe to call from any
|
|
1321
|
+
* context.
|
|
1322
|
+
*/
|
|
1323
|
+
invalidate(grantIdOrRoot: string): number;
|
|
1324
|
+
/**
|
|
1325
|
+
* Best-effort revoke every cached grant on the gateway, then clear.
|
|
1326
|
+
* Per-grant errors are caught and logged via `console.warn`.
|
|
1327
|
+
*/
|
|
1328
|
+
revokeAll(): Promise<void>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Invalidate cache entries matching a server-pushed revocation event.
|
|
1331
|
+
* Returns the number of entries dropped. Wired into the client
|
|
1332
|
+
* dispatch loop by {@link AetherClient.makeAuthorityCache}; tests may
|
|
1333
|
+
* also call this directly.
|
|
1334
|
+
*/
|
|
1335
|
+
handleRevocationEvent(evt: AuthorityGrantRevocation): number;
|
|
1336
|
+
/** Cache stats for observability tests. */
|
|
1337
|
+
stats(): {
|
|
1338
|
+
size: number;
|
|
1339
|
+
grantIdsIndexed: number;
|
|
1340
|
+
rootGrantIdsIndexed: number;
|
|
1341
|
+
};
|
|
1342
|
+
/**
|
|
1343
|
+
* Report whether `grantId` is currently cached and fresh (not revoked,
|
|
1344
|
+
* not past its soft-renew deadline). Cache-only — never round-trips to
|
|
1345
|
+
* the gateway. Stale/revoked entries observed here are evicted as a
|
|
1346
|
+
* side-effect.
|
|
1347
|
+
*/
|
|
1348
|
+
isValid(grantId: string): boolean;
|
|
1349
|
+
/**
|
|
1350
|
+
* Return a snapshot of every cached grant that is currently fresh,
|
|
1351
|
+
* de-duplicated by `grantId`. Stale/revoked entries observed during
|
|
1352
|
+
* the snapshot are evicted as a side-effect.
|
|
1353
|
+
*/
|
|
1354
|
+
listActive(): AuthorityGrantInfo[];
|
|
1355
|
+
/**
|
|
1356
|
+
* Drop `grantId` from the cache without calling the gateway. Alias of
|
|
1357
|
+
* {@link invalidate} with a name that telegraphs the local-only
|
|
1358
|
+
* semantics; the matching server-side revoke is
|
|
1359
|
+
* {@link AetherClient.revokeAuthorityGrant}. Returns the number of
|
|
1360
|
+
* entries dropped.
|
|
1361
|
+
*/
|
|
1362
|
+
revokeLocal(grantId: string): number;
|
|
1363
|
+
/**
|
|
1364
|
+
* Force-drop a cached grant and re-exchange it.
|
|
1365
|
+
*
|
|
1366
|
+
* Returns `null` when the cache does not know `grantId`, the matching
|
|
1367
|
+
* entry was originally derived (those cannot be refreshed via
|
|
1368
|
+
* exchange — re-derive explicitly), or the underlying exchange fails.
|
|
1369
|
+
*/
|
|
1370
|
+
refresh(grantId: string, opts?: {
|
|
1371
|
+
workspaceScope?: string[];
|
|
1372
|
+
resourceScope?: {
|
|
1373
|
+
resourceType: string;
|
|
1374
|
+
patterns: string[];
|
|
1375
|
+
}[];
|
|
1376
|
+
operationScope?: string[];
|
|
1377
|
+
maxAccessLevel?: number;
|
|
1378
|
+
validWhileAudienceActive?: boolean;
|
|
1379
|
+
expiresAt?: number;
|
|
1380
|
+
renewableUntil?: number;
|
|
1381
|
+
mayDelegate?: boolean;
|
|
1382
|
+
remainingHops?: number;
|
|
1383
|
+
reason?: string;
|
|
1384
|
+
metadata?: Record<string, string>;
|
|
1385
|
+
timeout?: number;
|
|
1386
|
+
}): Promise<AuthorityGrantInfo | null>;
|
|
1387
|
+
/**
|
|
1388
|
+
* Deregister this cache from its parent client so it stops receiving
|
|
1389
|
+
* AuthorityGrantRevocation events. Idempotent.
|
|
1390
|
+
*/
|
|
1391
|
+
close(): void;
|
|
1392
|
+
private _getUnexpired;
|
|
1393
|
+
private _store;
|
|
1394
|
+
private _drop;
|
|
1395
|
+
private _index;
|
|
1396
|
+
private _unindex;
|
|
1397
|
+
private _withInflight;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* Proxy HTTP support for the Aether TypeScript SDK.
|
|
1402
|
+
*
|
|
1403
|
+
* Provides `proxyHttp()` on AetherClient for tunneling HTTP requests through
|
|
1404
|
+
* the Aether gRPC stream, and `AetherFetchTransport` as a drop-in replacement
|
|
1405
|
+
* for the Web Fetch API transport layer.
|
|
1406
|
+
*
|
|
1407
|
+
* Bodies larger than CHUNK_THRESHOLD (256 KB) are split into
|
|
1408
|
+
* ProxyHttpBodyChunk frames and reassembled on the response side.
|
|
1409
|
+
*
|
|
1410
|
+
* @module proxy
|
|
1411
|
+
*/
|
|
1412
|
+
|
|
1413
|
+
/** Transport-layer error kinds from the gateway. */
|
|
1414
|
+
declare enum ProxyErrorKind {
|
|
1415
|
+
Unknown = 0,
|
|
1416
|
+
DialFailed = 1,
|
|
1417
|
+
Timeout = 2,
|
|
1418
|
+
UpstreamReset = 3,
|
|
1419
|
+
AclDenied = 4,
|
|
1420
|
+
SidecarUnavailable = 5,
|
|
1421
|
+
PayloadTooLarge = 6,
|
|
1422
|
+
DecodeFailed = 7
|
|
1423
|
+
}
|
|
1424
|
+
/** Transport-layer error from the gateway (not an HTTP error). */
|
|
1425
|
+
interface ProxyError {
|
|
1426
|
+
readonly kind: ProxyErrorKind;
|
|
1427
|
+
readonly message: string;
|
|
1428
|
+
}
|
|
1429
|
+
/** Structured response from a proxied HTTP request. */
|
|
1430
|
+
interface ProxyHttpResponse {
|
|
1431
|
+
readonly requestId: string;
|
|
1432
|
+
readonly statusCode: number;
|
|
1433
|
+
readonly headers: Record<string, string>;
|
|
1434
|
+
readonly body: Uint8Array;
|
|
1435
|
+
readonly bodyChunked: boolean;
|
|
1436
|
+
readonly error?: ProxyError;
|
|
1437
|
+
}
|
|
1438
|
+
/** Options for proxyHttp(). */
|
|
1439
|
+
interface ProxyHttpOptions {
|
|
1440
|
+
/** Request headers to send. */
|
|
1441
|
+
headers?: Record<string, string>;
|
|
1442
|
+
/** Request body (raw bytes). */
|
|
1443
|
+
body?: Uint8Array;
|
|
1444
|
+
/** Timeout in milliseconds (default: 30 000). */
|
|
1445
|
+
timeoutMs?: number;
|
|
1446
|
+
/** Whether to follow HTTP redirects (default: true). */
|
|
1447
|
+
followRedirects?: boolean;
|
|
1448
|
+
/**
|
|
1449
|
+
* Pin the request to a named terminator backend. The backend's allow-list
|
|
1450
|
+
* still applies — explicit naming selects which backend's ACL is consulted,
|
|
1451
|
+
* not whether the request is allowed.
|
|
1452
|
+
*/
|
|
1453
|
+
backend?: string;
|
|
1454
|
+
/**
|
|
1455
|
+
* Opt into unbounded response streaming (SSE / log tails / model token
|
|
1456
|
+
* streams). When true, ``timeoutMs`` becomes the time-to-first-byte
|
|
1457
|
+
* deadline only; subsequent body bytes are governed by
|
|
1458
|
+
* ``streamIdleTimeoutMs``. The response body is delivered as a real
|
|
1459
|
+
* ``ReadableStream<Uint8Array>`` so consumers can iterate chunks as they
|
|
1460
|
+
* arrive without buffering the whole response.
|
|
1461
|
+
*/
|
|
1462
|
+
streamResponse?: boolean;
|
|
1463
|
+
/**
|
|
1464
|
+
* Idle deadline (ms) between body bytes when ``streamResponse=true``.
|
|
1465
|
+
* Default 30 000 (30s) when unset. Exceeding closes the stream with
|
|
1466
|
+
* ``ProxyError{TIMEOUT}``.
|
|
1467
|
+
*/
|
|
1468
|
+
streamIdleTimeoutMs?: number;
|
|
1469
|
+
/**
|
|
1470
|
+
* Maximum total response body bytes when ``streamResponse=true``. 0 (the
|
|
1471
|
+
* default) means "use the per-backend cap". Exceeding closes the stream
|
|
1472
|
+
* with ``ProxyError{PAYLOAD_TOO_LARGE}``.
|
|
1473
|
+
*/
|
|
1474
|
+
maxResponseBodyBytes?: number;
|
|
1475
|
+
}
|
|
1476
|
+
/** Error thrown when the proxy transport layer fails. */
|
|
1477
|
+
declare class ProxyHttpError extends Error {
|
|
1478
|
+
readonly proxyError: ProxyError;
|
|
1479
|
+
constructor(err: ProxyError);
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Sends an HTTP request through the Aether gRPC stream to a service principal
|
|
1483
|
+
* and returns a fetch-compatible `Response` object.
|
|
1484
|
+
*
|
|
1485
|
+
* @param client - Connected AetherClient instance
|
|
1486
|
+
* @param target - Target topic, e.g. `"sv::memorylayer::default"` or wildcard `"sv::memorylayer"`
|
|
1487
|
+
* @param method - HTTP method, e.g. `"GET"`, `"POST"`
|
|
1488
|
+
* @param path - Path including query string, e.g. `"/v1/memories/abc"`
|
|
1489
|
+
* @param opts - Optional headers, body, timeout, followRedirects
|
|
1490
|
+
* @returns A `Response`-compatible object (standard Web API Response)
|
|
1491
|
+
* @throws {@link ProxyHttpError} on transport-layer failure
|
|
1492
|
+
* @throws {@link TimeoutError} if the request times out
|
|
1493
|
+
* @throws {@link ConnectionError} if not connected
|
|
1494
|
+
*/
|
|
1495
|
+
declare function proxyHttp(client: AetherClient, target: string, method: string, path: string, opts?: ProxyHttpOptions): Promise<Response>;
|
|
1496
|
+
/**
|
|
1497
|
+
* A drop-in transport for the Web Fetch API that routes requests through
|
|
1498
|
+
* an Aether gRPC connection to a service principal.
|
|
1499
|
+
*
|
|
1500
|
+
* @example
|
|
1501
|
+
* ```typescript
|
|
1502
|
+
* const transport = new AetherFetchTransport(agentClient, "sv::memorylayer::default");
|
|
1503
|
+
* const response = await transport.fetch("/v1/memories/abc");
|
|
1504
|
+
* ```
|
|
1505
|
+
*/
|
|
1506
|
+
declare class AetherFetchTransport {
|
|
1507
|
+
private readonly _client;
|
|
1508
|
+
private readonly _target;
|
|
1509
|
+
private readonly _defaultTimeoutMs;
|
|
1510
|
+
private readonly _defaultBackend;
|
|
1511
|
+
/**
|
|
1512
|
+
* @param client - Connected AetherClient
|
|
1513
|
+
* @param target - Default target topic (e.g. `"sv::memorylayer::default"`)
|
|
1514
|
+
* @param timeoutMs - Default request timeout in ms (default: 30 000)
|
|
1515
|
+
* @param backend - Optional default terminator backend name applied to
|
|
1516
|
+
* every request. The backend's allow-list still applies — explicit
|
|
1517
|
+
* naming selects which backend's ACL is consulted.
|
|
1518
|
+
*/
|
|
1519
|
+
constructor(client: AetherClient, target: string, timeoutMs?: number, backend?: string);
|
|
1520
|
+
/**
|
|
1521
|
+
* Fetch-compatible method. Accepts a URL string or Request object plus
|
|
1522
|
+
* optional RequestInit overrides.
|
|
1523
|
+
*
|
|
1524
|
+
* The URL hostname/protocol is ignored — requests are routed to the
|
|
1525
|
+
* configured target topic. Only the pathname + search are used as the path.
|
|
1526
|
+
*
|
|
1527
|
+
* @returns Web API `Response`
|
|
1528
|
+
*/
|
|
1529
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
/**
|
|
1533
|
+
* Base client implementation for the Aether TypeScript SDK.
|
|
1534
|
+
*
|
|
1535
|
+
* This module provides the AetherClient class that handles gRPC connection
|
|
1536
|
+
* management, TLS configuration, message queue infrastructure, and automatic
|
|
1537
|
+
* reconnection with exponential backoff. Specific client types (AgentClient,
|
|
1538
|
+
* UserClient, etc.) extend this base client.
|
|
1539
|
+
*
|
|
1540
|
+
* Key architectural principle: The connection itself IS the distributed lock
|
|
1541
|
+
* AND the heartbeat. When the gRPC stream closes, the identity lock is
|
|
1542
|
+
* immediately released. No separate heartbeat API exists.
|
|
1543
|
+
*
|
|
1544
|
+
* @module client
|
|
1545
|
+
*/
|
|
1546
|
+
|
|
1547
|
+
/**
|
|
1548
|
+
* Configuration options for the base Aether client.
|
|
1549
|
+
*/
|
|
1550
|
+
interface AetherClientOptions {
|
|
1551
|
+
/** Gateway address in host:port format. Required. */
|
|
1552
|
+
address: string;
|
|
1553
|
+
/** Optional TLS configuration for secure connections. */
|
|
1554
|
+
tls?: TLSOptions;
|
|
1555
|
+
/** Connection behavior configuration. */
|
|
1556
|
+
connection?: ConnectionOptions;
|
|
1557
|
+
/** Authentication credentials. */
|
|
1558
|
+
credentials?: Credentials;
|
|
1559
|
+
/** Whether to automatically reconnect on connection loss. Default: true. */
|
|
1560
|
+
reconnect?: boolean;
|
|
1561
|
+
/** Initial delay in ms between reconnect attempts. Default: 1000. */
|
|
1562
|
+
reconnectDelay?: number;
|
|
1563
|
+
/** Maximum delay in ms between reconnect attempts. Default: 30000. */
|
|
1564
|
+
maxReconnectDelay?: number;
|
|
1565
|
+
/**
|
|
1566
|
+
* When true, if the gateway returns a DuplicateIdentityError (ALREADY_EXISTS)
|
|
1567
|
+
* during connection, the client will wait and retry automatically.
|
|
1568
|
+
* Shorthand for connection.retryOnDuplicate. Default: false.
|
|
1569
|
+
*/
|
|
1570
|
+
retryOnDuplicate?: boolean;
|
|
1571
|
+
/**
|
|
1572
|
+
* How long to wait (ms) before retrying after a DuplicateIdentityError.
|
|
1573
|
+
* Shorthand for connection.retryOnDuplicateDelay. Default: 5000.
|
|
1574
|
+
*/
|
|
1575
|
+
retryOnDuplicateDelay?: number;
|
|
1576
|
+
}
|
|
1577
|
+
/** @internal */
|
|
1578
|
+
interface KVOperationParams {
|
|
1579
|
+
op: "GET" | "PUT" | "LIST" | "DELETE" | "INCREMENT" | "DECREMENT" | "INCREMENT_IF" | "DECREMENT_IF";
|
|
1580
|
+
scope: KVScope;
|
|
1581
|
+
key?: string;
|
|
1582
|
+
value?: Uint8Array;
|
|
1583
|
+
userId?: string;
|
|
1584
|
+
workspace?: string;
|
|
1585
|
+
ttl?: number;
|
|
1586
|
+
requestId?: string;
|
|
1587
|
+
/** Guard value for INCREMENT_IF (ceiling) and DECREMENT_IF (floor) operations. */
|
|
1588
|
+
guardValue?: bigint;
|
|
1589
|
+
/** Step size for INCREMENT_IF / DECREMENT_IF. When omitted the server defaults to 1. */
|
|
1590
|
+
deltaValue?: bigint;
|
|
1591
|
+
}
|
|
1592
|
+
/** @internal */
|
|
1593
|
+
interface CheckpointOperationParams {
|
|
1594
|
+
op: "SAVE" | "LOAD" | "DELETE" | "LIST";
|
|
1595
|
+
key?: string;
|
|
1596
|
+
data?: Uint8Array;
|
|
1597
|
+
ttl?: number;
|
|
1598
|
+
requestId?: string;
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Base client for connecting to the Aether distributed control plane.
|
|
1602
|
+
*
|
|
1603
|
+
* AetherClient manages the gRPC bidirectional streaming connection,
|
|
1604
|
+
* handles automatic reconnection with exponential backoff, and provides
|
|
1605
|
+
* the message send/receive infrastructure.
|
|
1606
|
+
*
|
|
1607
|
+
* This class is not typically used directly. Instead, use one of the
|
|
1608
|
+
* specialized client types:
|
|
1609
|
+
* - {@link AgentClient} for agent connections
|
|
1610
|
+
* - {@link UserClient} for user/browser connections
|
|
1611
|
+
*
|
|
1612
|
+
* @example
|
|
1613
|
+
* ```typescript
|
|
1614
|
+
* import { AetherClient } from "@scitrera/aether-client";
|
|
1615
|
+
*
|
|
1616
|
+
* const client = new AetherClient({ address: "localhost:50051" });
|
|
1617
|
+
*
|
|
1618
|
+
* client.onMessage((msg) => {
|
|
1619
|
+
* console.log(`Received from ${msg.sourceTopic}:`, msg.payload);
|
|
1620
|
+
* });
|
|
1621
|
+
*
|
|
1622
|
+
* await client.connect();
|
|
1623
|
+
* ```
|
|
1624
|
+
*/
|
|
1625
|
+
declare class AetherClient {
|
|
1626
|
+
protected readonly _address: string;
|
|
1627
|
+
protected readonly _tls: TLSOptions | undefined;
|
|
1628
|
+
protected readonly _connectionOpts: Required<ConnectionOptions>;
|
|
1629
|
+
protected readonly _credentials: Credentials;
|
|
1630
|
+
protected _connected: boolean;
|
|
1631
|
+
protected _connecting: boolean;
|
|
1632
|
+
protected _sessionId: string;
|
|
1633
|
+
protected _resumeSessionId: string;
|
|
1634
|
+
private _requestCounter;
|
|
1635
|
+
private _onMessage;
|
|
1636
|
+
private _onConfig;
|
|
1637
|
+
private _onSignal;
|
|
1638
|
+
private _onError;
|
|
1639
|
+
private _onKVResponse;
|
|
1640
|
+
private _onTaskAssignment;
|
|
1641
|
+
private _onCheckpointResponse;
|
|
1642
|
+
private _onProgress;
|
|
1643
|
+
private _onConnect;
|
|
1644
|
+
private _onDisconnect;
|
|
1645
|
+
private _onReconnecting;
|
|
1646
|
+
private _onTaskQueryResponse;
|
|
1647
|
+
private _onTaskOperationResponse;
|
|
1648
|
+
private _onCreateTaskResponse;
|
|
1649
|
+
private _onWorkspaceResponse;
|
|
1650
|
+
private _onAgentResponse;
|
|
1651
|
+
private _onACLResponse;
|
|
1652
|
+
private _onAuthorityGrantResponse;
|
|
1653
|
+
private _onAuthorityGrantRevocation;
|
|
1654
|
+
private _onAuditSubmitResponse;
|
|
1655
|
+
private _authorityGrantCaches;
|
|
1656
|
+
private _onWorkflowResponse;
|
|
1657
|
+
private _onTokenResponse;
|
|
1658
|
+
private _onChatMessage;
|
|
1659
|
+
private _onControlMessage;
|
|
1660
|
+
private _onToolCallMessage;
|
|
1661
|
+
private _onEventMessage;
|
|
1662
|
+
private _onMetricMessage;
|
|
1663
|
+
private _pendingKVRequests;
|
|
1664
|
+
private _pendingCheckpointRequests;
|
|
1665
|
+
private _pendingTaskQueryRequests;
|
|
1666
|
+
private _pendingTaskOpRequests;
|
|
1667
|
+
private _pendingCreateTaskRequests;
|
|
1668
|
+
private _pendingWorkspaceRequests;
|
|
1669
|
+
private _pendingAgentRequests;
|
|
1670
|
+
private _pendingACLRequests;
|
|
1671
|
+
private _pendingAuthorityGrantRequests;
|
|
1672
|
+
private _pendingWorkflowRequests;
|
|
1673
|
+
private _pendingAuditSubmitRequests;
|
|
1674
|
+
private _pendingTokenRequests;
|
|
1675
|
+
_pendingProxyHttpRequests: Map<string, (response: ProxyHttpResponse) => void>;
|
|
1676
|
+
_pendingProxyHttpChunks: Map<string, Uint8Array<ArrayBufferLike>[]>;
|
|
1677
|
+
_pendingProxyHttpStreams: Map<string, {
|
|
1678
|
+
controller: ReadableStreamDefaultController<Uint8Array>;
|
|
1679
|
+
headerResolved: boolean;
|
|
1680
|
+
}>;
|
|
1681
|
+
_pendingTunnels: Map<string, TunnelInflight>;
|
|
1682
|
+
private _kvClient;
|
|
1683
|
+
private _checkpointClient;
|
|
1684
|
+
private readonly _retryOnDuplicate;
|
|
1685
|
+
private readonly _retryOnDuplicateDelay;
|
|
1686
|
+
private readonly _retryOnDuplicateMaxAttempts;
|
|
1687
|
+
private _grpcClient;
|
|
1688
|
+
private _stream;
|
|
1689
|
+
private _disconnectRequested;
|
|
1690
|
+
private _reconnecting;
|
|
1691
|
+
private _packageDefinition;
|
|
1692
|
+
/**
|
|
1693
|
+
* Creates a new AetherClient.
|
|
1694
|
+
*
|
|
1695
|
+
* The client is created but not connected. Call {@link connect} to establish
|
|
1696
|
+
* the connection to the gateway.
|
|
1697
|
+
*
|
|
1698
|
+
* @param options - Client configuration options
|
|
1699
|
+
* @throws {@link InvalidArgumentError} if the address is not provided
|
|
1700
|
+
*/
|
|
1701
|
+
constructor(options: AetherClientOptions);
|
|
1702
|
+
/**
|
|
1703
|
+
* Establishes a connection to the Aether gateway.
|
|
1704
|
+
*
|
|
1705
|
+
* Opens a gRPC bidirectional stream and sends the InitConnection message.
|
|
1706
|
+
* If auto-reconnect is enabled, the client will automatically attempt to
|
|
1707
|
+
* reconnect on connection loss.
|
|
1708
|
+
*
|
|
1709
|
+
* If `retryOnDuplicate` is enabled and the gateway responds with a
|
|
1710
|
+
* DuplicateIdentityError (ALREADY_EXISTS), the client will wait briefly
|
|
1711
|
+
* and retry up to `retryOnDuplicateMaxAttempts` times. This handles the
|
|
1712
|
+
* race condition where a previous instance's lock has not yet expired.
|
|
1713
|
+
*
|
|
1714
|
+
* @throws {@link ConnectionError} if the connection cannot be established
|
|
1715
|
+
* @throws {@link DuplicateIdentityError} if identity is already connected
|
|
1716
|
+
* and retryOnDuplicate is disabled or exhausted
|
|
1717
|
+
*/
|
|
1718
|
+
connect(): Promise<void>;
|
|
1719
|
+
/**
|
|
1720
|
+
* Attempts connection, retrying on DuplicateIdentityError.
|
|
1721
|
+
* @internal
|
|
1722
|
+
*/
|
|
1723
|
+
private _connectWithDuplicateRetry;
|
|
1724
|
+
/**
|
|
1725
|
+
* Gracefully disconnects from the Aether gateway.
|
|
1726
|
+
*
|
|
1727
|
+
* Closes the gRPC stream and releases the identity lock on the server.
|
|
1728
|
+
* Automatic reconnection is suppressed for this disconnection.
|
|
1729
|
+
*/
|
|
1730
|
+
disconnect(): Promise<void>;
|
|
1731
|
+
/**
|
|
1732
|
+
* Returns whether the client is currently connected to the gateway.
|
|
1733
|
+
*/
|
|
1734
|
+
get connected(): boolean;
|
|
1735
|
+
/**
|
|
1736
|
+
* Returns the current session ID assigned by the gateway.
|
|
1737
|
+
* Empty string if not connected.
|
|
1738
|
+
*/
|
|
1739
|
+
get sessionId(): string;
|
|
1740
|
+
/**
|
|
1741
|
+
* Sends a message through the Aether gateway.
|
|
1742
|
+
*
|
|
1743
|
+
* @param message - The outgoing message to send
|
|
1744
|
+
* @throws {@link ConnectionError} if not connected
|
|
1745
|
+
*/
|
|
1746
|
+
send(message: OutgoingMessage): Promise<void>;
|
|
1747
|
+
/**
|
|
1748
|
+
* Sends a KV operation through the gateway.
|
|
1749
|
+
* @internal Used by KVClient.
|
|
1750
|
+
*/
|
|
1751
|
+
sendKVOperation(params: KVOperationParams): void;
|
|
1752
|
+
/**
|
|
1753
|
+
* Sends a checkpoint operation through the gateway.
|
|
1754
|
+
* @internal Used by CheckpointClient.
|
|
1755
|
+
*/
|
|
1756
|
+
sendCheckpointOperation(params: CheckpointOperationParams): void;
|
|
1757
|
+
/**
|
|
1758
|
+
* Registers a handler for incoming messages.
|
|
1759
|
+
*
|
|
1760
|
+
* @param handler - Function called when a message is received
|
|
1761
|
+
*
|
|
1762
|
+
* @example
|
|
1763
|
+
* ```typescript
|
|
1764
|
+
* client.onMessage((msg) => {
|
|
1765
|
+
* console.log(`From ${msg.sourceTopic}: ${new TextDecoder().decode(msg.payload)}`);
|
|
1766
|
+
* });
|
|
1767
|
+
* ```
|
|
1768
|
+
*/
|
|
1769
|
+
onMessage(handler: MessageHandler): void;
|
|
1770
|
+
/**
|
|
1771
|
+
* Registers a handler for configuration snapshots.
|
|
1772
|
+
*
|
|
1773
|
+
* Called once when the connection is established, providing the initial
|
|
1774
|
+
* KV store state for the workspace.
|
|
1775
|
+
*
|
|
1776
|
+
* @param handler - Function called when a config snapshot is received
|
|
1777
|
+
*/
|
|
1778
|
+
onConfig(handler: ConfigHandler): void;
|
|
1779
|
+
/**
|
|
1780
|
+
* Registers a handler for signals from the gateway.
|
|
1781
|
+
*
|
|
1782
|
+
* @param handler - Function called when a signal is received
|
|
1783
|
+
*/
|
|
1784
|
+
onSignal(handler: SignalHandler): void;
|
|
1785
|
+
/**
|
|
1786
|
+
* Registers a handler for error responses from the gateway.
|
|
1787
|
+
*
|
|
1788
|
+
* @param handler - Function called when an error response is received
|
|
1789
|
+
*/
|
|
1790
|
+
onError(handler: ErrorHandler): void;
|
|
1791
|
+
/**
|
|
1792
|
+
* Registers a handler for KV operation responses.
|
|
1793
|
+
*
|
|
1794
|
+
* @param handler - Function called when a KV response is received
|
|
1795
|
+
*/
|
|
1796
|
+
onKVResponse(handler: KVResponseHandler): void;
|
|
1797
|
+
/**
|
|
1798
|
+
* Registers a handler for task assignments.
|
|
1799
|
+
*
|
|
1800
|
+
* Used by orchestrators to receive task assignments that require
|
|
1801
|
+
* starting new agent or task instances.
|
|
1802
|
+
*
|
|
1803
|
+
* @param handler - Function called when a task assignment is received
|
|
1804
|
+
*/
|
|
1805
|
+
onTaskAssignment(handler: TaskAssignmentHandler): void;
|
|
1806
|
+
/**
|
|
1807
|
+
* Registers a handler for checkpoint operation responses.
|
|
1808
|
+
*
|
|
1809
|
+
* @param handler - Function called when a checkpoint response is received
|
|
1810
|
+
*/
|
|
1811
|
+
onCheckpointResponse(handler: CheckpointResponseHandler): void;
|
|
1812
|
+
/**
|
|
1813
|
+
* Registers a handler for progress updates from agents/tasks.
|
|
1814
|
+
*
|
|
1815
|
+
* Progress updates are delivered via the pg.{workspace} stream with
|
|
1816
|
+
* server-side recipient filtering.
|
|
1817
|
+
*
|
|
1818
|
+
* @param handler - Function called when a progress update is received
|
|
1819
|
+
*/
|
|
1820
|
+
onProgress(handler: ProgressHandler): void;
|
|
1821
|
+
/**
|
|
1822
|
+
* Registers a handler for successful connections.
|
|
1823
|
+
*
|
|
1824
|
+
* Called both for initial connection and reconnections.
|
|
1825
|
+
*
|
|
1826
|
+
* @param handler - Function called with the connection acknowledgment
|
|
1827
|
+
*/
|
|
1828
|
+
onConnect(handler: ConnectHandler): void;
|
|
1829
|
+
/**
|
|
1830
|
+
* Registers a handler for disconnection events.
|
|
1831
|
+
*
|
|
1832
|
+
* Called before any automatic reconnection attempt.
|
|
1833
|
+
*
|
|
1834
|
+
* @param handler - Function called with the disconnection reason
|
|
1835
|
+
*/
|
|
1836
|
+
onDisconnect(handler: DisconnectHandler): void;
|
|
1837
|
+
/**
|
|
1838
|
+
* Registers a handler for reconnection attempts.
|
|
1839
|
+
*
|
|
1840
|
+
* @param handler - Function called with the attempt number
|
|
1841
|
+
*/
|
|
1842
|
+
onReconnecting(handler: ReconnectingHandler): void;
|
|
1843
|
+
/**
|
|
1844
|
+
* Registers a handler for task query responses.
|
|
1845
|
+
*
|
|
1846
|
+
* @param handler - Function called when a task query response is received
|
|
1847
|
+
*/
|
|
1848
|
+
onTaskQueryResponse(handler: TaskQueryResponseHandler): void;
|
|
1849
|
+
/**
|
|
1850
|
+
* Registers a handler for task operation responses.
|
|
1851
|
+
*
|
|
1852
|
+
* @param handler - Function called when a task operation response is received
|
|
1853
|
+
*/
|
|
1854
|
+
onTaskOperationResponse(handler: TaskOperationResponseHandler): void;
|
|
1855
|
+
/**
|
|
1856
|
+
* Registers a handler for create-task responses (fire-and-forget path,
|
|
1857
|
+
* i.e. when no request_id is supplied or a response arrives without a
|
|
1858
|
+
* matching pending entry).
|
|
1859
|
+
*
|
|
1860
|
+
* @param handler - Function called when a create-task response is received
|
|
1861
|
+
*/
|
|
1862
|
+
onCreateTaskResponse(handler: CreateTaskResponseHandler): void;
|
|
1863
|
+
/**
|
|
1864
|
+
* Registers a handler for Chat messages.
|
|
1865
|
+
*
|
|
1866
|
+
* @param handler - Function called when a Chat message is received
|
|
1867
|
+
*/
|
|
1868
|
+
onChatMessage(handler: MessageHandler): void;
|
|
1869
|
+
/**
|
|
1870
|
+
* Registers a handler for Control messages.
|
|
1871
|
+
*
|
|
1872
|
+
* @param handler - Function called when a Control message is received
|
|
1873
|
+
*/
|
|
1874
|
+
onControlMessage(handler: MessageHandler): void;
|
|
1875
|
+
/**
|
|
1876
|
+
* Registers a handler for ToolCall messages.
|
|
1877
|
+
*
|
|
1878
|
+
* @param handler - Function called when a ToolCall message is received
|
|
1879
|
+
*/
|
|
1880
|
+
onToolCallMessage(handler: MessageHandler): void;
|
|
1881
|
+
/**
|
|
1882
|
+
* Registers a handler for Event messages.
|
|
1883
|
+
*
|
|
1884
|
+
* @param handler - Function called when an Event message is received
|
|
1885
|
+
*/
|
|
1886
|
+
onEventMessage(handler: MessageHandler): void;
|
|
1887
|
+
/**
|
|
1888
|
+
* Registers a handler for Metric messages.
|
|
1889
|
+
*
|
|
1890
|
+
* @param handler - Function called when a Metric message is received
|
|
1891
|
+
*/
|
|
1892
|
+
onMetricMessage(handler: MessageHandler): void;
|
|
1893
|
+
/**
|
|
1894
|
+
* Returns the KV operations client.
|
|
1895
|
+
*
|
|
1896
|
+
* @returns The KVClient instance for performing KV store operations
|
|
1897
|
+
*
|
|
1898
|
+
* @example
|
|
1899
|
+
* ```typescript
|
|
1900
|
+
* const kv = client.kv();
|
|
1901
|
+
* const response = await kv.getSync({ key: "my-key", scope: KVScope.Global });
|
|
1902
|
+
* ```
|
|
1903
|
+
*/
|
|
1904
|
+
kv(): KVClient;
|
|
1905
|
+
/**
|
|
1906
|
+
* Returns the checkpoint operations client.
|
|
1907
|
+
*
|
|
1908
|
+
* @returns The CheckpointClient instance for checkpoint save/load/delete/list
|
|
1909
|
+
*
|
|
1910
|
+
* @example
|
|
1911
|
+
* ```typescript
|
|
1912
|
+
* const cp = client.checkpoint();
|
|
1913
|
+
* const response = await cp.loadSync({ key: "my-state" });
|
|
1914
|
+
* ```
|
|
1915
|
+
*/
|
|
1916
|
+
checkpoint(): CheckpointClient;
|
|
1917
|
+
/**
|
|
1918
|
+
* Generates a unique request ID for correlating responses.
|
|
1919
|
+
* @internal
|
|
1920
|
+
*/
|
|
1921
|
+
nextRequestId(): string;
|
|
1922
|
+
/**
|
|
1923
|
+
* Registers a pending KV request for response correlation.
|
|
1924
|
+
* @internal
|
|
1925
|
+
*/
|
|
1926
|
+
registerPendingKVRequest(requestId: string, callback: (response: KVResponse) => void): void;
|
|
1927
|
+
/**
|
|
1928
|
+
* Registers a pending checkpoint request for response correlation.
|
|
1929
|
+
* @internal
|
|
1930
|
+
*/
|
|
1931
|
+
registerPendingCheckpointRequest(requestId: string, callback: (response: CheckpointResponse) => void): void;
|
|
1932
|
+
/**
|
|
1933
|
+
* Removes a pending request (used on timeout cleanup).
|
|
1934
|
+
* @internal
|
|
1935
|
+
*/
|
|
1936
|
+
removePendingRequest(requestId: string): void;
|
|
1937
|
+
/**
|
|
1938
|
+
* Builds the InitConnection message for the connection handshake.
|
|
1939
|
+
* Subclasses override this to provide their specific identity.
|
|
1940
|
+
* @internal
|
|
1941
|
+
*/
|
|
1942
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
1943
|
+
/**
|
|
1944
|
+
* Establishes the gRPC connection and starts the message loop.
|
|
1945
|
+
* @internal
|
|
1946
|
+
*/
|
|
1947
|
+
private _establishConnection;
|
|
1948
|
+
/**
|
|
1949
|
+
* Closes the gRPC connection.
|
|
1950
|
+
* @internal
|
|
1951
|
+
*/
|
|
1952
|
+
private _closeConnection;
|
|
1953
|
+
/**
|
|
1954
|
+
* Sends an upstream message on the gRPC stream.
|
|
1955
|
+
* @internal
|
|
1956
|
+
*/
|
|
1957
|
+
protected _sendUpstream(message: Record<string, unknown>): void;
|
|
1958
|
+
/**
|
|
1959
|
+
* Routes a downstream message to the appropriate handler.
|
|
1960
|
+
* @internal
|
|
1961
|
+
*/
|
|
1962
|
+
private _handleDownstreamMessage;
|
|
1963
|
+
/**
|
|
1964
|
+
* Handles gRPC stream errors.
|
|
1965
|
+
* @internal
|
|
1966
|
+
*/
|
|
1967
|
+
private _handleStreamError;
|
|
1968
|
+
/**
|
|
1969
|
+
* Handles gRPC stream end.
|
|
1970
|
+
* @internal
|
|
1971
|
+
*/
|
|
1972
|
+
private _handleStreamEnd;
|
|
1973
|
+
/**
|
|
1974
|
+
* Attempts automatic reconnection with exponential backoff.
|
|
1975
|
+
* @internal
|
|
1976
|
+
*/
|
|
1977
|
+
private _attemptReconnection;
|
|
1978
|
+
/**
|
|
1979
|
+
* Reports progress for a task through the Aether gateway.
|
|
1980
|
+
*
|
|
1981
|
+
* Progress updates are routed through RabbitMQ Streams via the pg.{workspace}
|
|
1982
|
+
* topic with server-side recipient filtering.
|
|
1983
|
+
*
|
|
1984
|
+
* @param opts - Progress report options
|
|
1985
|
+
* @throws {@link ConnectionError} if not connected
|
|
1986
|
+
*/
|
|
1987
|
+
reportProgress(opts: ReportProgressOptions): void;
|
|
1988
|
+
/**
|
|
1989
|
+
* Encodes a Metric object to protobuf bytes using the loaded proto descriptor.
|
|
1990
|
+
*
|
|
1991
|
+
* Uses the `aether.v1.Metric` type from the package definition stored at
|
|
1992
|
+
* connection time. Throws if the descriptor is not yet available — sending
|
|
1993
|
+
* JSON-encoded bytes here would silently fail on the gateway with
|
|
1994
|
+
* ERR_METRIC_INVALID, so we eagerly surface the misuse.
|
|
1995
|
+
*
|
|
1996
|
+
* @param metric - The metric object to encode
|
|
1997
|
+
* @returns Encoded bytes
|
|
1998
|
+
* @internal
|
|
1999
|
+
*/
|
|
2000
|
+
protected _encodeMetric(metric: Record<string, unknown>): Uint8Array;
|
|
2001
|
+
/**
|
|
2002
|
+
* Low-level message send helper used by subclasses.
|
|
2003
|
+
* @internal
|
|
2004
|
+
*/
|
|
2005
|
+
protected _sendMessage(targetTopic: string, payload: Uint8Array, messageType: MessageType): void;
|
|
2006
|
+
/**
|
|
2007
|
+
* Parses a raw task info object from the server into a TaskInfo.
|
|
2008
|
+
* @internal
|
|
2009
|
+
*/
|
|
2010
|
+
private _parseTaskInfo;
|
|
2011
|
+
/**
|
|
2012
|
+
* Parses a raw authority grant object from the server into an AuthorityGrantInfo.
|
|
2013
|
+
* @internal
|
|
2014
|
+
*/
|
|
2015
|
+
private _parseAuthorityGrantInfo;
|
|
2016
|
+
/**
|
|
2017
|
+
* Lists tasks with optional filters.
|
|
2018
|
+
*/
|
|
2019
|
+
queryTasks(opts?: TaskQueryOptions): Promise<TaskQueryResponse>;
|
|
2020
|
+
/**
|
|
2021
|
+
* Gets a specific task by ID.
|
|
2022
|
+
*/
|
|
2023
|
+
getTask(taskId: string, timeout?: number): Promise<TaskQueryResponse>;
|
|
2024
|
+
/**
|
|
2025
|
+
* Cancels a running or queued task.
|
|
2026
|
+
*/
|
|
2027
|
+
cancelTask(taskId: string, reason?: string, timeout?: number): Promise<TaskOperationResponse>;
|
|
2028
|
+
/**
|
|
2029
|
+
* Retries a failed task.
|
|
2030
|
+
*/
|
|
2031
|
+
retryTask(taskId: string, timeout?: number): Promise<TaskOperationResponse>;
|
|
2032
|
+
/**
|
|
2033
|
+
* Completes a task (for POOL workers).
|
|
2034
|
+
*/
|
|
2035
|
+
completeTask(taskId: string, timeout?: number): Promise<TaskOperationResponse>;
|
|
2036
|
+
/**
|
|
2037
|
+
* Marks a task as failed (for POOL workers).
|
|
2038
|
+
*/
|
|
2039
|
+
failTask(taskId: string, reason?: string, timeout?: number): Promise<TaskOperationResponse>;
|
|
2040
|
+
/**
|
|
2041
|
+
* Sends a CreateTaskRequest and waits for the server's CreateTaskResponse.
|
|
2042
|
+
*
|
|
2043
|
+
* A unique request_id is injected automatically so the response can be
|
|
2044
|
+
* correlated. Unlike the fire-and-forget `createTask` override in subclasses,
|
|
2045
|
+
* this method blocks until the gateway echoes back the assigned task_id.
|
|
2046
|
+
*
|
|
2047
|
+
* @param op - CreateTaskRequest fields (task_type, workspace, assignment_mode, etc.)
|
|
2048
|
+
* @param timeout - Timeout in ms (default 10 000)
|
|
2049
|
+
* @returns Promise resolving to the CreateTaskResponse
|
|
2050
|
+
*/
|
|
2051
|
+
createTaskBlocking(op: Record<string, unknown>, timeout?: number): Promise<CreateTaskResponse>;
|
|
2052
|
+
/**
|
|
2053
|
+
* Sends a workspace operation upstream.
|
|
2054
|
+
*
|
|
2055
|
+
* @param op - The workspace operation payload
|
|
2056
|
+
* @param timeout - Timeout in ms
|
|
2057
|
+
* @returns Promise resolving to the workspace response
|
|
2058
|
+
*/
|
|
2059
|
+
sendWorkspaceOperation(op: Record<string, unknown>, timeout?: number): Promise<WorkspaceResponse>;
|
|
2060
|
+
/**
|
|
2061
|
+
* Sends an agent operation upstream.
|
|
2062
|
+
*
|
|
2063
|
+
* @param op - The agent operation payload
|
|
2064
|
+
* @param timeout - Timeout in ms
|
|
2065
|
+
* @returns Promise resolving to the agent response
|
|
2066
|
+
*/
|
|
2067
|
+
sendAgentOperation(op: Record<string, unknown>, timeout?: number): Promise<AgentResponse>;
|
|
2068
|
+
/**
|
|
2069
|
+
* Sends an ACL operation upstream.
|
|
2070
|
+
*
|
|
2071
|
+
* @param op - The ACL operation payload
|
|
2072
|
+
* @param timeout - Timeout in ms
|
|
2073
|
+
* @returns Promise resolving to the ACL response
|
|
2074
|
+
*/
|
|
2075
|
+
sendACLOperation(op: Record<string, unknown>, timeout?: number): Promise<ACLResponse>;
|
|
2076
|
+
/**
|
|
2077
|
+
* Sends a runtime authority-grant operation upstream.
|
|
2078
|
+
*
|
|
2079
|
+
* @param op - The authority grant operation payload
|
|
2080
|
+
* @param timeout - Timeout in ms
|
|
2081
|
+
* @returns Promise resolving to the authority-grant response
|
|
2082
|
+
*/
|
|
2083
|
+
sendAuthorityGrantOperation(op: Record<string, unknown>, timeout?: number): Promise<AuthorityGrantResponse>;
|
|
2084
|
+
/**
|
|
2085
|
+
* Submits a foreign audit event to the gateway's audit pipeline.
|
|
2086
|
+
*
|
|
2087
|
+
* @param opts - Audit event fields
|
|
2088
|
+
* @param timeout - Timeout in ms (default 10 000)
|
|
2089
|
+
* @returns Promise resolving to the audit-submit response
|
|
2090
|
+
*/
|
|
2091
|
+
submitAuditEvent(opts: {
|
|
2092
|
+
eventType: string;
|
|
2093
|
+
operation?: string;
|
|
2094
|
+
resourceType?: string;
|
|
2095
|
+
resourceId?: string;
|
|
2096
|
+
workspace?: string;
|
|
2097
|
+
success?: boolean;
|
|
2098
|
+
errorMessage?: string;
|
|
2099
|
+
metadata?: Record<string, string>;
|
|
2100
|
+
}, timeout?: number): Promise<AuditSubmitResponse>;
|
|
2101
|
+
/**
|
|
2102
|
+
* Sends a workflow operation upstream.
|
|
2103
|
+
*
|
|
2104
|
+
* @param op - The workflow operation payload
|
|
2105
|
+
* @param timeout - Timeout in ms
|
|
2106
|
+
* @returns Promise resolving to the workflow response
|
|
2107
|
+
*/
|
|
2108
|
+
sendWorkflowOperation(op: Record<string, unknown>, timeout?: number): Promise<WorkflowResponse>;
|
|
2109
|
+
/**
|
|
2110
|
+
* Registers a handler for workspace operation responses.
|
|
2111
|
+
*
|
|
2112
|
+
* @param handler - Function called when a workspace response is received
|
|
2113
|
+
*/
|
|
2114
|
+
onWorkspaceResponse(handler: WorkspaceResponseHandler): void;
|
|
2115
|
+
/**
|
|
2116
|
+
* Registers a handler for agent operation responses.
|
|
2117
|
+
*
|
|
2118
|
+
* @param handler - Function called when an agent response is received
|
|
2119
|
+
*/
|
|
2120
|
+
onAgentResponse(handler: AgentResponseHandler): void;
|
|
2121
|
+
/**
|
|
2122
|
+
* Registers a handler for ACL operation responses.
|
|
2123
|
+
*
|
|
2124
|
+
* @param handler - Function called when an ACL response is received
|
|
2125
|
+
*/
|
|
2126
|
+
onACLResponse(handler: ACLResponseHandler): void;
|
|
2127
|
+
/**
|
|
2128
|
+
* Registers a handler for runtime authority-grant responses.
|
|
2129
|
+
*
|
|
2130
|
+
* @param handler - Function called when an authority-grant response is received
|
|
2131
|
+
*/
|
|
2132
|
+
onAuthorityGrantResponse(handler: AuthorityGrantResponseHandler): void;
|
|
2133
|
+
/**
|
|
2134
|
+
* Registers a handler for unsolicited audit-submit responses (i.e. responses
|
|
2135
|
+
* not correlated to a pending {@link submitAuditEvent} call).
|
|
2136
|
+
*
|
|
2137
|
+
* @param handler - Function called when an audit-submit response is received
|
|
2138
|
+
*/
|
|
2139
|
+
onAuditSubmitResponse(handler: AuditSubmitResponseHandler): void;
|
|
2140
|
+
/**
|
|
2141
|
+
* Registers a handler for server-pushed AuthorityGrantRevocation events.
|
|
2142
|
+
* Caches registered via {@link makeAuthorityCache} are invoked first; the
|
|
2143
|
+
* user handler runs after every cache has been notified.
|
|
2144
|
+
*/
|
|
2145
|
+
onAuthorityGrantRevocation(handler: AuthorityGrantRevocationHandler): void;
|
|
2146
|
+
/**
|
|
2147
|
+
* Bootstrap a runtime authority grant for the current actor.
|
|
2148
|
+
*
|
|
2149
|
+
* If `sourceSessionId` is empty, only a user may self-exchange. When it
|
|
2150
|
+
* is set, the caller must hold the `_perm:exchange_authority_grants`
|
|
2151
|
+
* permission and the referenced session must belong to an active user.
|
|
2152
|
+
*/
|
|
2153
|
+
exchangeAuthorityGrant(opts?: {
|
|
2154
|
+
sourceSessionId?: string;
|
|
2155
|
+
workspaceScope?: string[];
|
|
2156
|
+
resourceScope?: {
|
|
2157
|
+
resourceType: string;
|
|
2158
|
+
patterns: string[];
|
|
2159
|
+
}[];
|
|
2160
|
+
operationScope?: string[];
|
|
2161
|
+
maxAccessLevel?: number;
|
|
2162
|
+
audienceType?: string;
|
|
2163
|
+
audienceId?: string;
|
|
2164
|
+
validWhileAudienceActive?: boolean;
|
|
2165
|
+
expiresAt?: number;
|
|
2166
|
+
renewableUntil?: number;
|
|
2167
|
+
mayDelegate?: boolean;
|
|
2168
|
+
remainingHops?: number;
|
|
2169
|
+
reason?: string;
|
|
2170
|
+
metadata?: Record<string, string>;
|
|
2171
|
+
timeout?: number;
|
|
2172
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2173
|
+
/**
|
|
2174
|
+
* Derive a child runtime authority grant for a downstream delegate.
|
|
2175
|
+
*/
|
|
2176
|
+
deriveAuthorityGrant(opts: {
|
|
2177
|
+
parentGrantId: string;
|
|
2178
|
+
delegateType: string;
|
|
2179
|
+
delegateId: string;
|
|
2180
|
+
workspaceScope?: string[];
|
|
2181
|
+
resourceScope?: {
|
|
2182
|
+
resourceType: string;
|
|
2183
|
+
patterns: string[];
|
|
2184
|
+
}[];
|
|
2185
|
+
operationScope?: string[];
|
|
2186
|
+
maxAccessLevel?: number;
|
|
2187
|
+
audienceType?: string;
|
|
2188
|
+
audienceId?: string;
|
|
2189
|
+
validWhileAudienceActive?: boolean;
|
|
2190
|
+
expiresAt?: number;
|
|
2191
|
+
renewableUntil?: number;
|
|
2192
|
+
mayDelegate?: boolean;
|
|
2193
|
+
remainingHops?: number;
|
|
2194
|
+
reason?: string;
|
|
2195
|
+
metadata?: Record<string, string>;
|
|
2196
|
+
timeout?: number;
|
|
2197
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2198
|
+
/** Get a runtime authority grant by ID. */
|
|
2199
|
+
getAuthorityGrant(grantId: string, timeout?: number): Promise<AuthorityGrantResponse>;
|
|
2200
|
+
/**
|
|
2201
|
+
* Renew a runtime authority grant lease. `expiresAt` (proto units) takes
|
|
2202
|
+
* precedence; `extendSeconds` extends the current expiry by N seconds
|
|
2203
|
+
* server-side and is ignored when `expiresAt` is non-zero.
|
|
2204
|
+
*/
|
|
2205
|
+
renewAuthorityGrant(opts: {
|
|
2206
|
+
grantId: string;
|
|
2207
|
+
expiresAt?: number;
|
|
2208
|
+
extendSeconds?: number;
|
|
2209
|
+
timeout?: number;
|
|
2210
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2211
|
+
/** Revoke a runtime authority grant by ID. */
|
|
2212
|
+
revokeAuthorityGrant(grantId: string, timeout?: number): Promise<AuthorityGrantResponse>;
|
|
2213
|
+
/** List grants where the actor is delegate or subject. */
|
|
2214
|
+
listMyAuthorityGrants(opts?: {
|
|
2215
|
+
audienceType?: string;
|
|
2216
|
+
audienceId?: string;
|
|
2217
|
+
includeRevoked?: boolean;
|
|
2218
|
+
limit?: number;
|
|
2219
|
+
offset?: number;
|
|
2220
|
+
timeout?: number;
|
|
2221
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2222
|
+
/** List grants where the actor is the subject (i.e., grants OTHERS hold on me). */
|
|
2223
|
+
listAuthorityGrantsOnMe(opts?: {
|
|
2224
|
+
audienceType?: string;
|
|
2225
|
+
audienceId?: string;
|
|
2226
|
+
includeRevoked?: boolean;
|
|
2227
|
+
limit?: number;
|
|
2228
|
+
offset?: number;
|
|
2229
|
+
timeout?: number;
|
|
2230
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2231
|
+
/** Exchange multiple authority grants in a single round-trip. */
|
|
2232
|
+
batchExchangeAuthorityGrants(opts: {
|
|
2233
|
+
requests: Record<string, unknown>[];
|
|
2234
|
+
stopOnFirstError?: boolean;
|
|
2235
|
+
timeout?: number;
|
|
2236
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2237
|
+
/**
|
|
2238
|
+
* Idempotent derive: returns existing visible grant matching
|
|
2239
|
+
* (parentGrantId, target, audience) or mints a new one.
|
|
2240
|
+
*
|
|
2241
|
+
* Safe to call repeatedly without leaking grants.
|
|
2242
|
+
*/
|
|
2243
|
+
deriveAuthorityGrantForTarget(opts: {
|
|
2244
|
+
parentGrantId: string;
|
|
2245
|
+
targetType: string;
|
|
2246
|
+
targetId: string;
|
|
2247
|
+
audienceType?: string;
|
|
2248
|
+
audienceId?: string;
|
|
2249
|
+
operationScope?: string[];
|
|
2250
|
+
maxAccessLevel?: number;
|
|
2251
|
+
expiresAt?: number;
|
|
2252
|
+
renewableUntil?: number;
|
|
2253
|
+
mayDelegate?: boolean;
|
|
2254
|
+
remainingHops?: number;
|
|
2255
|
+
reason?: string;
|
|
2256
|
+
timeout?: number;
|
|
2257
|
+
}): Promise<AuthorityGrantResponse>;
|
|
2258
|
+
/**
|
|
2259
|
+
* Construct a new {@link AuthorityGrantCache} wired into this client.
|
|
2260
|
+
* AuthorityGrantRevocation push events on the downstream stream are
|
|
2261
|
+
* dispatched to the cache automatically. Call {@link AuthorityGrantCache.close}
|
|
2262
|
+
* to deregister it.
|
|
2263
|
+
*/
|
|
2264
|
+
makeAuthorityCache(opts?: AuthorityGrantCacheOptions): AuthorityGrantCache;
|
|
2265
|
+
/** @internal */
|
|
2266
|
+
_removeAuthorityCache(cache: AuthorityGrantCache): void;
|
|
2267
|
+
/**
|
|
2268
|
+
* Registers a handler for workflow operation responses.
|
|
2269
|
+
*
|
|
2270
|
+
* @param handler - Function called when a workflow response is received
|
|
2271
|
+
*/
|
|
2272
|
+
onWorkflowResponse(handler: WorkflowResponseHandler): void;
|
|
2273
|
+
/**
|
|
2274
|
+
* Sends a token management operation to the gateway.
|
|
2275
|
+
*
|
|
2276
|
+
* @param op - The token operation payload
|
|
2277
|
+
* @param timeout - Timeout in ms
|
|
2278
|
+
* @returns Promise resolving to the token response
|
|
2279
|
+
*/
|
|
2280
|
+
sendTokenOperation(op: Record<string, unknown>, timeout?: number): Promise<TokenResponse>;
|
|
2281
|
+
/**
|
|
2282
|
+
* Registers a handler for token operation responses.
|
|
2283
|
+
*
|
|
2284
|
+
* @param handler - Function called when a token response is received
|
|
2285
|
+
*/
|
|
2286
|
+
onTokenResponse(handler: TokenResponseHandler): void;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
/**
|
|
2290
|
+
* Admin client for the Aether TypeScript SDK.
|
|
2291
|
+
*
|
|
2292
|
+
* AdminClient wraps a connected AetherClient and provides named helper methods
|
|
2293
|
+
* for all administrative operations exposed through the gRPC streaming protocol:
|
|
2294
|
+
* token management, ACL rules, workspace CRUD, agent registry, and gateway
|
|
2295
|
+
* health / connection queries.
|
|
2296
|
+
*
|
|
2297
|
+
* The underlying AetherClient must already be connected before calling any
|
|
2298
|
+
* AdminClient method. All methods return Promises that resolve when the
|
|
2299
|
+
* gateway sends the correlated response, or reject on timeout.
|
|
2300
|
+
*
|
|
2301
|
+
* @module admin
|
|
2302
|
+
*/
|
|
2303
|
+
|
|
2304
|
+
/** Timeout option shared by all admin methods. */
|
|
2305
|
+
interface AdminTimeoutOptions {
|
|
2306
|
+
/** Operation timeout in milliseconds. Default: 10000. */
|
|
2307
|
+
timeout?: number;
|
|
2308
|
+
}
|
|
2309
|
+
/** Options for creating an API token. */
|
|
2310
|
+
interface CreateTokenOptions extends AdminTimeoutOptions {
|
|
2311
|
+
/** Human-readable name for the token. Required. */
|
|
2312
|
+
name: string;
|
|
2313
|
+
/** Principal type this token authenticates (e.g., "agent", "user"). */
|
|
2314
|
+
principalType?: string;
|
|
2315
|
+
/** Glob patterns for workspaces this token may access. */
|
|
2316
|
+
workspacePatterns?: string[];
|
|
2317
|
+
/** Permission scopes granted by this token. */
|
|
2318
|
+
scopes?: string[];
|
|
2319
|
+
/** Expiry duration in seconds from now (0 = no expiry). */
|
|
2320
|
+
expiresInSeconds?: number;
|
|
2321
|
+
}
|
|
2322
|
+
/** Options for revoking an API token. */
|
|
2323
|
+
interface RevokeTokenOptions extends AdminTimeoutOptions {
|
|
2324
|
+
/** Token ID to revoke. Required. */
|
|
2325
|
+
tokenId: string;
|
|
2326
|
+
}
|
|
2327
|
+
/** Options for listing API tokens. */
|
|
2328
|
+
interface ListTokensOptions extends AdminTimeoutOptions {
|
|
2329
|
+
/** Filter by principal type. */
|
|
2330
|
+
principalType?: string;
|
|
2331
|
+
/** If true, include revoked tokens in results. */
|
|
2332
|
+
includeRevoked?: boolean;
|
|
2333
|
+
/** Maximum number of results to return. */
|
|
2334
|
+
limit?: number;
|
|
2335
|
+
}
|
|
2336
|
+
/** Options for creating an ACL rule (granting access). */
|
|
2337
|
+
interface CreateACLRuleOptions extends AdminTimeoutOptions {
|
|
2338
|
+
/** Principal type being granted access (e.g., "agent", "user"). Required. */
|
|
2339
|
+
principalType: string;
|
|
2340
|
+
/** Principal ID being granted access. Required. */
|
|
2341
|
+
principalId: string;
|
|
2342
|
+
/** Resource type the access applies to (e.g., "workspace"). Required. */
|
|
2343
|
+
resourceType: string;
|
|
2344
|
+
/** Resource ID the access applies to. Required. */
|
|
2345
|
+
resourceId: string;
|
|
2346
|
+
/** Permission level (e.g., "read", "write", "admin"). Required. */
|
|
2347
|
+
permission: string;
|
|
2348
|
+
/** Optional expiry as Unix timestamp (seconds). 0 = no expiry. */
|
|
2349
|
+
expiresAt?: number;
|
|
2350
|
+
/** Arbitrary metadata to attach to the rule. */
|
|
2351
|
+
metadata?: Record<string, string>;
|
|
2352
|
+
}
|
|
2353
|
+
/** Options for deleting an ACL rule. */
|
|
2354
|
+
interface DeleteACLRuleOptions extends AdminTimeoutOptions {
|
|
2355
|
+
/** Rule ID to delete. Required. */
|
|
2356
|
+
ruleId: string;
|
|
2357
|
+
}
|
|
2358
|
+
/** Options for listing ACL rules. */
|
|
2359
|
+
interface ListACLRulesOptions extends AdminTimeoutOptions {
|
|
2360
|
+
/** Filter by principal type. */
|
|
2361
|
+
principalType?: string;
|
|
2362
|
+
/** Filter by principal ID. */
|
|
2363
|
+
principalId?: string;
|
|
2364
|
+
/** Filter by resource type. */
|
|
2365
|
+
resourceType?: string;
|
|
2366
|
+
/** Filter by resource ID. */
|
|
2367
|
+
resourceId?: string;
|
|
2368
|
+
}
|
|
2369
|
+
/** Options for reading a fallback policy by category. */
|
|
2370
|
+
interface GetFallbackPolicyOptions extends AdminTimeoutOptions {
|
|
2371
|
+
/**
|
|
2372
|
+
* Rule category, formatted as "{principal_type}_{resource_type}" (e.g.,
|
|
2373
|
+
* "user_workspace", "agent_kv_scope", "service_kv_scope").
|
|
2374
|
+
*/
|
|
2375
|
+
ruleCategory: string;
|
|
2376
|
+
}
|
|
2377
|
+
/** Options for upserting a fallback policy. */
|
|
2378
|
+
interface SetFallbackPolicyOptions extends AdminTimeoutOptions {
|
|
2379
|
+
/** Rule category to upsert. */
|
|
2380
|
+
ruleCategory: string;
|
|
2381
|
+
/**
|
|
2382
|
+
* Default access level when no explicit acl_rules row matches. Use the
|
|
2383
|
+
* numeric tiers from internal/acl/types.go: 0=NONE, 10=READ, 20=READWRITE,
|
|
2384
|
+
* 30=MANAGE, 40=ADMIN, 50=SUPERADMIN.
|
|
2385
|
+
*/
|
|
2386
|
+
fallbackAccessLevel: number;
|
|
2387
|
+
}
|
|
2388
|
+
/** Options for listing workspaces. */
|
|
2389
|
+
interface ListWorkspacesOptions extends AdminTimeoutOptions {
|
|
2390
|
+
/** Maximum number of results to return. */
|
|
2391
|
+
limit?: number;
|
|
2392
|
+
/** Offset for pagination. */
|
|
2393
|
+
offset?: number;
|
|
2394
|
+
}
|
|
2395
|
+
/** Data for creating a workspace. */
|
|
2396
|
+
interface CreateWorkspaceOptions extends AdminTimeoutOptions {
|
|
2397
|
+
/** Workspace ID (the string identifier). Required. */
|
|
2398
|
+
workspaceId: string;
|
|
2399
|
+
/** Human-readable display name. */
|
|
2400
|
+
displayName?: string;
|
|
2401
|
+
/** Arbitrary metadata. */
|
|
2402
|
+
metadata?: Record<string, string>;
|
|
2403
|
+
}
|
|
2404
|
+
/** Data for updating a workspace. */
|
|
2405
|
+
interface UpdateWorkspaceOptions extends AdminTimeoutOptions {
|
|
2406
|
+
/** Workspace ID to update. Required. */
|
|
2407
|
+
workspaceId: string;
|
|
2408
|
+
/** New display name. */
|
|
2409
|
+
displayName?: string;
|
|
2410
|
+
/** Updated metadata. */
|
|
2411
|
+
metadata?: Record<string, string>;
|
|
2412
|
+
}
|
|
2413
|
+
/** Options for deleting a workspace. */
|
|
2414
|
+
interface DeleteWorkspaceOptions extends AdminTimeoutOptions {
|
|
2415
|
+
/** Workspace ID to delete. Required. */
|
|
2416
|
+
workspaceId: string;
|
|
2417
|
+
}
|
|
2418
|
+
/** Options for listing registered agent types. */
|
|
2419
|
+
interface ListAgentsOptions extends AdminTimeoutOptions {
|
|
2420
|
+
/** Filter by workspace. */
|
|
2421
|
+
workspace?: string;
|
|
2422
|
+
/** Maximum number of results to return. */
|
|
2423
|
+
limit?: number;
|
|
2424
|
+
}
|
|
2425
|
+
/** Options for getting a specific agent registration. */
|
|
2426
|
+
interface GetAgentOptions extends AdminTimeoutOptions {
|
|
2427
|
+
/** The agent implementation name. Required. */
|
|
2428
|
+
implementation: string;
|
|
2429
|
+
}
|
|
2430
|
+
/** Response from admin queries. Loosely typed to accommodate the AdminResponse oneof. */
|
|
2431
|
+
interface AdminQueryResponse {
|
|
2432
|
+
readonly success: boolean;
|
|
2433
|
+
readonly error: string;
|
|
2434
|
+
readonly health?: Record<string, unknown>;
|
|
2435
|
+
readonly info?: Record<string, unknown>;
|
|
2436
|
+
readonly stats?: Record<string, unknown>;
|
|
2437
|
+
readonly connection?: Record<string, unknown>;
|
|
2438
|
+
readonly connections?: Record<string, unknown>[];
|
|
2439
|
+
readonly totalCount: number;
|
|
2440
|
+
}
|
|
2441
|
+
/** Handler type for admin query responses. */
|
|
2442
|
+
type AdminQueryResponseHandler = (response: AdminQueryResponse) => void | Promise<void>;
|
|
2443
|
+
/** Options for listing connections. */
|
|
2444
|
+
interface ListConnectionsOptions extends AdminTimeoutOptions {
|
|
2445
|
+
/** Filter by workspace. */
|
|
2446
|
+
workspace?: string;
|
|
2447
|
+
/** Filter by principal type. */
|
|
2448
|
+
principalType?: string;
|
|
2449
|
+
}
|
|
2450
|
+
/** Options for disconnecting a session. */
|
|
2451
|
+
interface DisconnectSessionOptions extends AdminTimeoutOptions {
|
|
2452
|
+
/** Session ID to disconnect. Required. */
|
|
2453
|
+
sessionId: string;
|
|
2454
|
+
/** Optional reason message sent to the disconnected client. */
|
|
2455
|
+
reason?: string;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Administrative client for managing an Aether gateway.
|
|
2459
|
+
*
|
|
2460
|
+
* AdminClient wraps any connected {@link AetherClient} (typically an
|
|
2461
|
+
* AgentClient or UserClient) and exposes named helper methods for the full
|
|
2462
|
+
* set of administrative operations that are available through the gRPC
|
|
2463
|
+
* streaming protocol.
|
|
2464
|
+
*
|
|
2465
|
+
* @example
|
|
2466
|
+
* ```typescript
|
|
2467
|
+
* import { AgentClient, AdminClient } from "@scitrera/aether-client";
|
|
2468
|
+
*
|
|
2469
|
+
* const agent = new AgentClient({
|
|
2470
|
+
* address: "localhost:50051",
|
|
2471
|
+
* workspace: "default",
|
|
2472
|
+
* implementation: "admin-agent",
|
|
2473
|
+
* specifier: "ops-1",
|
|
2474
|
+
* credentials: { "x-api-key": "my-admin-key" },
|
|
2475
|
+
* });
|
|
2476
|
+
* await agent.connect();
|
|
2477
|
+
*
|
|
2478
|
+
* const admin = new AdminClient(agent);
|
|
2479
|
+
*
|
|
2480
|
+
* // List workspaces
|
|
2481
|
+
* const wsr = await admin.listWorkspaces();
|
|
2482
|
+
* console.log(wsr);
|
|
2483
|
+
*
|
|
2484
|
+
* // Create a token
|
|
2485
|
+
* const tr = await admin.createToken({ name: "ci-token", principalType: "agent" });
|
|
2486
|
+
* console.log(tr.plaintextToken);
|
|
2487
|
+
* ```
|
|
2488
|
+
*/
|
|
2489
|
+
declare class AdminClient {
|
|
2490
|
+
private readonly _client;
|
|
2491
|
+
/**
|
|
2492
|
+
* Creates an AdminClient backed by the given AetherClient.
|
|
2493
|
+
*
|
|
2494
|
+
* The AetherClient must be connected before calling any method.
|
|
2495
|
+
*
|
|
2496
|
+
* @param client - A connected AetherClient instance
|
|
2497
|
+
*/
|
|
2498
|
+
constructor(client: AetherClient);
|
|
2499
|
+
/**
|
|
2500
|
+
* Creates a new API token.
|
|
2501
|
+
*
|
|
2502
|
+
* @param opts - Token creation parameters
|
|
2503
|
+
* @returns Promise resolving to the token response (includes plaintextToken)
|
|
2504
|
+
*/
|
|
2505
|
+
createToken(opts: CreateTokenOptions): Promise<TokenResponse>;
|
|
2506
|
+
/**
|
|
2507
|
+
* Revokes an API token by ID.
|
|
2508
|
+
*
|
|
2509
|
+
* @param opts - Revoke options containing the token ID
|
|
2510
|
+
* @returns Promise resolving to the token response
|
|
2511
|
+
*/
|
|
2512
|
+
revokeToken(opts: RevokeTokenOptions): Promise<TokenResponse>;
|
|
2513
|
+
/**
|
|
2514
|
+
* Lists API tokens with optional filters.
|
|
2515
|
+
*
|
|
2516
|
+
* @param opts - List options
|
|
2517
|
+
* @returns Promise resolving to the token response (tokens array)
|
|
2518
|
+
*/
|
|
2519
|
+
listTokens(opts?: ListTokensOptions): Promise<TokenResponse>;
|
|
2520
|
+
/**
|
|
2521
|
+
* Creates an ACL rule granting access.
|
|
2522
|
+
*
|
|
2523
|
+
* @param opts - ACL rule creation parameters
|
|
2524
|
+
* @returns Promise resolving to the ACL response
|
|
2525
|
+
*/
|
|
2526
|
+
createACLRule(opts: CreateACLRuleOptions): Promise<ACLResponse>;
|
|
2527
|
+
/**
|
|
2528
|
+
* Deletes an ACL rule by ID.
|
|
2529
|
+
*
|
|
2530
|
+
* @param opts - Delete options containing the rule ID
|
|
2531
|
+
* @returns Promise resolving to the ACL response
|
|
2532
|
+
*/
|
|
2533
|
+
deleteACLRule(opts: DeleteACLRuleOptions): Promise<ACLResponse>;
|
|
2534
|
+
/**
|
|
2535
|
+
* Lists ACL rules with optional filters.
|
|
2536
|
+
*
|
|
2537
|
+
* @param opts - List options
|
|
2538
|
+
* @returns Promise resolving to the ACL response (rules array in response)
|
|
2539
|
+
*/
|
|
2540
|
+
listACLRules(opts?: ListACLRulesOptions): Promise<ACLResponse>;
|
|
2541
|
+
/**
|
|
2542
|
+
* Reads the fallback policy for a rule category.
|
|
2543
|
+
*
|
|
2544
|
+
* Fallback policies decide the default ACL outcome when no explicit
|
|
2545
|
+
* `acl_rules` row matches the (principal_type, resource_type) pair.
|
|
2546
|
+
* The `ruleCategory` is the catonical
|
|
2547
|
+
* `{principal_type}_{resource_type}` slug — e.g., "agent_kv_scope".
|
|
2548
|
+
*/
|
|
2549
|
+
getFallbackPolicy(opts: GetFallbackPolicyOptions): Promise<ACLResponse>;
|
|
2550
|
+
/**
|
|
2551
|
+
* Upserts a fallback policy for a rule category.
|
|
2552
|
+
*
|
|
2553
|
+
* Use ``fallbackAccessLevel: 0`` to flip a category to default-deny.
|
|
2554
|
+
*/
|
|
2555
|
+
setFallbackPolicy(opts: SetFallbackPolicyOptions): Promise<ACLResponse>;
|
|
2556
|
+
/**
|
|
2557
|
+
* Lists workspaces.
|
|
2558
|
+
*
|
|
2559
|
+
* @param opts - List options
|
|
2560
|
+
* @returns Promise resolving to the workspace response
|
|
2561
|
+
*/
|
|
2562
|
+
listWorkspaces(opts?: ListWorkspacesOptions): Promise<WorkspaceResponse>;
|
|
2563
|
+
/**
|
|
2564
|
+
* Creates a new workspace.
|
|
2565
|
+
*
|
|
2566
|
+
* @param opts - Workspace creation parameters
|
|
2567
|
+
* @returns Promise resolving to the workspace response
|
|
2568
|
+
*/
|
|
2569
|
+
createWorkspace(opts: CreateWorkspaceOptions): Promise<WorkspaceResponse>;
|
|
2570
|
+
/**
|
|
2571
|
+
* Updates an existing workspace.
|
|
2572
|
+
*
|
|
2573
|
+
* @param opts - Workspace update parameters
|
|
2574
|
+
* @returns Promise resolving to the workspace response
|
|
2575
|
+
*/
|
|
2576
|
+
updateWorkspace(opts: UpdateWorkspaceOptions): Promise<WorkspaceResponse>;
|
|
2577
|
+
/**
|
|
2578
|
+
* Deletes a workspace by ID.
|
|
2579
|
+
*
|
|
2580
|
+
* @param opts - Delete options containing the workspace ID
|
|
2581
|
+
* @returns Promise resolving to the workspace response
|
|
2582
|
+
*/
|
|
2583
|
+
deleteWorkspace(opts: DeleteWorkspaceOptions): Promise<WorkspaceResponse>;
|
|
2584
|
+
/**
|
|
2585
|
+
* Lists registered agent types.
|
|
2586
|
+
*
|
|
2587
|
+
* @param opts - List options
|
|
2588
|
+
* @returns Promise resolving to the agent response
|
|
2589
|
+
*/
|
|
2590
|
+
listAgents(opts?: ListAgentsOptions): Promise<AgentResponse>;
|
|
2591
|
+
/**
|
|
2592
|
+
* Gets the registration details for a specific agent implementation.
|
|
2593
|
+
*
|
|
2594
|
+
* @param opts - Options including the implementation name
|
|
2595
|
+
* @returns Promise resolving to the agent response
|
|
2596
|
+
*/
|
|
2597
|
+
getAgent(opts: GetAgentOptions): Promise<AgentResponse>;
|
|
2598
|
+
/**
|
|
2599
|
+
* Queries gateway health, including component status for Redis, RabbitMQ,
|
|
2600
|
+
* and PostgreSQL.
|
|
2601
|
+
*
|
|
2602
|
+
* Note: This sends a GET_HEALTH admin query through the gRPC stream.
|
|
2603
|
+
* The gateway must have admin-over-stream enabled.
|
|
2604
|
+
*
|
|
2605
|
+
* @param timeout - Timeout in milliseconds (default: 10000)
|
|
2606
|
+
* @returns Promise resolving to the admin query response
|
|
2607
|
+
*/
|
|
2608
|
+
getHealth(timeout?: number): Promise<AdminQueryResponse>;
|
|
2609
|
+
/**
|
|
2610
|
+
* Lists active connections on the gateway.
|
|
2611
|
+
*
|
|
2612
|
+
* @param opts - Optional filter and timeout options
|
|
2613
|
+
* @returns Promise resolving to the admin query response (connections array)
|
|
2614
|
+
*/
|
|
2615
|
+
getConnections(opts?: ListConnectionsOptions): Promise<AdminQueryResponse>;
|
|
2616
|
+
/**
|
|
2617
|
+
* Forcibly disconnects a session by session ID.
|
|
2618
|
+
*
|
|
2619
|
+
* @param opts - Options containing the session ID and optional reason
|
|
2620
|
+
* @returns Promise resolving to the workspace response
|
|
2621
|
+
*/
|
|
2622
|
+
disconnectSession(opts: DisconnectSessionOptions): Promise<WorkspaceResponse>;
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
/**
|
|
2626
|
+
* MetricEntry is one additive delta within a Metric message.
|
|
2627
|
+
*/
|
|
2628
|
+
interface MetricEntry {
|
|
2629
|
+
/**
|
|
2630
|
+
* e.g. "tokens_in", "time_seconds", "pages_rendered"
|
|
2631
|
+
*/
|
|
2632
|
+
'name'?: (string);
|
|
2633
|
+
/**
|
|
2634
|
+
* sub-classifier, e.g. "modelA", "" (free-form, may be empty)
|
|
2635
|
+
*/
|
|
2636
|
+
'kind'?: (string);
|
|
2637
|
+
/**
|
|
2638
|
+
* additive delta; negative requires capability/metric_credit
|
|
2639
|
+
*/
|
|
2640
|
+
'qty'?: (number | string);
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
/**
|
|
2644
|
+
* Metric is the canonical payload for SendMessage when message_type == METRIC.
|
|
2645
|
+
* All entries are interpreted as additive deltas; negative qty requires the
|
|
2646
|
+
* `capability/metric_credit` ACL permission on the sender.
|
|
2647
|
+
*/
|
|
2648
|
+
interface Metric {
|
|
2649
|
+
/**
|
|
2650
|
+
* Optional correlation ID (request/trace) tying these entries to upstream work.
|
|
2651
|
+
*/
|
|
2652
|
+
'traceId'?: (string);
|
|
2653
|
+
/**
|
|
2654
|
+
* One or more counter deltas. At least one entry is required.
|
|
2655
|
+
*/
|
|
2656
|
+
'entries'?: (MetricEntry)[];
|
|
2657
|
+
/**
|
|
2658
|
+
* Free-form tags / hints. Documented well-known keys:
|
|
2659
|
+
* lifecycle = "startup" | "shutdown"
|
|
2660
|
+
* source.version, source.region, source.host, ...
|
|
2661
|
+
*/
|
|
2662
|
+
'metadata'?: ({
|
|
2663
|
+
[key: string]: string;
|
|
2664
|
+
});
|
|
2665
|
+
/**
|
|
2666
|
+
* Optional client-side timestamp (ms since epoch). The server always also
|
|
2667
|
+
* stamps MessageEnvelope.timestamp_ms; this is for client-side ordering hints.
|
|
2668
|
+
*/
|
|
2669
|
+
'clientTimestampMs'?: (number | string | Long);
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
/**
|
|
2673
|
+
* Fluent builder for constructing Metric payloads.
|
|
2674
|
+
*
|
|
2675
|
+
* Metric is the canonical payload for SendMessage when message_type == METRIC.
|
|
2676
|
+
* All entries are interpreted as additive deltas; negative qty values require
|
|
2677
|
+
* the `capability/metric_credit` ACL permission on the sender.
|
|
2678
|
+
*
|
|
2679
|
+
* @module metrics-builder
|
|
2680
|
+
*
|
|
2681
|
+
* @example
|
|
2682
|
+
* ```typescript
|
|
2683
|
+
* import { newMetric } from "@scitrera/aether-client";
|
|
2684
|
+
*
|
|
2685
|
+
* const metric = newMetric()
|
|
2686
|
+
* .trace("req-abc-123")
|
|
2687
|
+
* .add("tokens_in", "modelA", 512)
|
|
2688
|
+
* .add("tokens_out", "modelA", 128)
|
|
2689
|
+
* .tag("source.version", "1.0.0")
|
|
2690
|
+
* .clientTimestampMs(Date.now())
|
|
2691
|
+
* .build();
|
|
2692
|
+
*
|
|
2693
|
+
* agent.sendMetric(metric);
|
|
2694
|
+
* ```
|
|
2695
|
+
*/
|
|
2696
|
+
|
|
2697
|
+
/**
|
|
2698
|
+
* Fluent builder for constructing a {@link Metric}.
|
|
2699
|
+
*/
|
|
2700
|
+
declare class MetricBuilder {
|
|
2701
|
+
private m;
|
|
2702
|
+
constructor();
|
|
2703
|
+
/**
|
|
2704
|
+
* Sets the optional correlation/trace ID tying these entries to upstream work.
|
|
2705
|
+
*/
|
|
2706
|
+
trace(id: string): this;
|
|
2707
|
+
/**
|
|
2708
|
+
* Adds a metric entry (additive delta).
|
|
2709
|
+
*
|
|
2710
|
+
* @param name - Counter name, e.g. "tokens_in", "time_seconds"
|
|
2711
|
+
* @param kind - Sub-classifier, e.g. "modelA" (may be empty)
|
|
2712
|
+
* @param qty - Additive delta; negative requires `capability/metric_credit`
|
|
2713
|
+
*/
|
|
2714
|
+
add(name: string, kind: string, qty: number): this;
|
|
2715
|
+
/**
|
|
2716
|
+
* Adds a free-form metadata tag.
|
|
2717
|
+
*
|
|
2718
|
+
* Well-known keys: lifecycle ("startup" | "shutdown"),
|
|
2719
|
+
* source.version, source.region, source.host, ...
|
|
2720
|
+
*/
|
|
2721
|
+
tag(key: string, value: string): this;
|
|
2722
|
+
/**
|
|
2723
|
+
* Sets the optional client-side timestamp (ms since epoch).
|
|
2724
|
+
*
|
|
2725
|
+
* The server always stamps its own authoritative timestamp on the
|
|
2726
|
+
* MessageEnvelope; this field is an advisory ordering hint only.
|
|
2727
|
+
*
|
|
2728
|
+
* Accepts `number` or `string` to support int64 values that exceed
|
|
2729
|
+
* `Number.MAX_SAFE_INTEGER` (the generated proto type allows both,
|
|
2730
|
+
* driven by `--longs=String` in compile_protos.sh).
|
|
2731
|
+
*/
|
|
2732
|
+
clientTimestampMs(ts: number | string): this;
|
|
2733
|
+
/**
|
|
2734
|
+
* Returns the constructed Metric object.
|
|
2735
|
+
*/
|
|
2736
|
+
build(): Metric;
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Creates a new {@link MetricBuilder}.
|
|
2740
|
+
*
|
|
2741
|
+
* @example
|
|
2742
|
+
* ```typescript
|
|
2743
|
+
* const metric = newMetric()
|
|
2744
|
+
* .add("tokens_in", "gpt4", 512)
|
|
2745
|
+
* .build();
|
|
2746
|
+
* ```
|
|
2747
|
+
*/
|
|
2748
|
+
declare function newMetric(): MetricBuilder;
|
|
2749
|
+
|
|
2750
|
+
/**
|
|
2751
|
+
* Agent client implementation for the Aether TypeScript SDK.
|
|
2752
|
+
*
|
|
2753
|
+
* This module provides the AgentClient class for connecting to the Aether
|
|
2754
|
+
* gateway as an agent. Agents are persistent entities with
|
|
2755
|
+
* workspace/implementation/specifier identity that can send and receive
|
|
2756
|
+
* messages, manage state, and participate in task orchestration.
|
|
2757
|
+
*
|
|
2758
|
+
* @module agents
|
|
2759
|
+
*/
|
|
2760
|
+
|
|
2761
|
+
/**
|
|
2762
|
+
* Configuration options for the AgentClient.
|
|
2763
|
+
*/
|
|
2764
|
+
interface AgentClientOptions extends AetherClientOptions {
|
|
2765
|
+
/** The workspace to connect to. Required. */
|
|
2766
|
+
workspace: string;
|
|
2767
|
+
/** The agent implementation type. Required. */
|
|
2768
|
+
implementation: string;
|
|
2769
|
+
/** The unique specifier for this agent instance. Required. */
|
|
2770
|
+
specifier: string;
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Options for creating a task.
|
|
2774
|
+
*/
|
|
2775
|
+
interface CreateTaskOptions {
|
|
2776
|
+
/** The type of task to create. Required. */
|
|
2777
|
+
taskType: string;
|
|
2778
|
+
/** The workspace for the task. If empty, uses the agent's workspace. */
|
|
2779
|
+
workspace?: string;
|
|
2780
|
+
/** For TARGETED mode: the agent to assign to. */
|
|
2781
|
+
targetAgentId?: string;
|
|
2782
|
+
/** For POOL mode: the agent implementation type to match. */
|
|
2783
|
+
targetImplementation?: string;
|
|
2784
|
+
/** Optional parameter overrides for orchestration. */
|
|
2785
|
+
launchParamOverrides?: Record<string, string>;
|
|
2786
|
+
/** Optional task metadata. */
|
|
2787
|
+
metadata?: Record<string, string>;
|
|
2788
|
+
/** Assignment mode. Default: SelfAssign. */
|
|
2789
|
+
assignmentMode?: TaskAssignmentMode;
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* Client for connecting to the Aether gateway as an agent.
|
|
2793
|
+
*
|
|
2794
|
+
* Agents are persistent entities identified by workspace, implementation,
|
|
2795
|
+
* and specifier. Each agent identity can only have one active connection
|
|
2796
|
+
* at a time (Connection = Lock paradigm).
|
|
2797
|
+
*
|
|
2798
|
+
* AgentClient extends AetherClient and adds agent-specific functionality:
|
|
2799
|
+
* - Identity management (workspace, implementation, specifier)
|
|
2800
|
+
* - Messaging helpers (sendToAgent, sendToUser, sendToTask, broadcast)
|
|
2801
|
+
* - Event and metric publishing
|
|
2802
|
+
* - Workspace switching
|
|
2803
|
+
* - Task creation
|
|
2804
|
+
*
|
|
2805
|
+
* @example
|
|
2806
|
+
* ```typescript
|
|
2807
|
+
* import { AgentClient } from "@scitrera/aether-client";
|
|
2808
|
+
*
|
|
2809
|
+
* const agent = new AgentClient({
|
|
2810
|
+
* address: "localhost:50051",
|
|
2811
|
+
* workspace: "prod",
|
|
2812
|
+
* implementation: "data-processor",
|
|
2813
|
+
* specifier: "instance-1",
|
|
2814
|
+
* });
|
|
2815
|
+
*
|
|
2816
|
+
* agent.onMessage((msg) => {
|
|
2817
|
+
* console.log(`Received from ${msg.sourceTopic}:`, msg.payload);
|
|
2818
|
+
* });
|
|
2819
|
+
*
|
|
2820
|
+
* await agent.connect();
|
|
2821
|
+
* ```
|
|
2822
|
+
*/
|
|
2823
|
+
declare class AgentClient extends AetherClient {
|
|
2824
|
+
private _workspace;
|
|
2825
|
+
private readonly _implementation;
|
|
2826
|
+
private readonly _specifier;
|
|
2827
|
+
/**
|
|
2828
|
+
* Creates a new AgentClient.
|
|
2829
|
+
*
|
|
2830
|
+
* @param options - Agent client configuration
|
|
2831
|
+
* @throws {@link InvalidArgumentError} if required fields are missing
|
|
2832
|
+
*/
|
|
2833
|
+
constructor(options: AgentClientOptions);
|
|
2834
|
+
/** Returns the agent's current workspace. */
|
|
2835
|
+
get workspace(): string;
|
|
2836
|
+
/** Returns the agent's implementation type. */
|
|
2837
|
+
get implementation(): string;
|
|
2838
|
+
/** Returns the agent's specifier (instance identifier). */
|
|
2839
|
+
get specifier(): string;
|
|
2840
|
+
/**
|
|
2841
|
+
* Returns this agent's topic address.
|
|
2842
|
+
*
|
|
2843
|
+
* Format: ag.{workspace}.{implementation}.{specifier}
|
|
2844
|
+
*/
|
|
2845
|
+
get topic(): string;
|
|
2846
|
+
/** @internal */
|
|
2847
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
2848
|
+
/**
|
|
2849
|
+
* Switches the agent's workspace.
|
|
2850
|
+
*
|
|
2851
|
+
* Sends a SwitchWorkspace message to the gateway, which will update
|
|
2852
|
+
* the agent's topic subscription and optionally send a new ConfigSnapshot.
|
|
2853
|
+
*
|
|
2854
|
+
* @param newWorkspace - The new workspace to switch to
|
|
2855
|
+
* @throws {@link InvalidArgumentError} if the workspace is empty
|
|
2856
|
+
*/
|
|
2857
|
+
switchWorkspace(newWorkspace: string): void;
|
|
2858
|
+
/**
|
|
2859
|
+
* Sends a message to a specific agent.
|
|
2860
|
+
*
|
|
2861
|
+
* @param workspace - Target agent's workspace
|
|
2862
|
+
* @param implementation - Target agent's implementation type
|
|
2863
|
+
* @param specifier - Target agent's specifier
|
|
2864
|
+
* @param payload - Message payload (bytes)
|
|
2865
|
+
* @param messageType - Message type. Default: Chat
|
|
2866
|
+
*/
|
|
2867
|
+
sendToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
2868
|
+
/**
|
|
2869
|
+
* Sends a message to a specific task.
|
|
2870
|
+
*
|
|
2871
|
+
* For unique tasks (with specifier), uses tu.{workspace}.{impl}.{spec} topic.
|
|
2872
|
+
* For non-unique tasks (empty specifier), uses tb.{workspace}.{impl} broadcast topic.
|
|
2873
|
+
*
|
|
2874
|
+
* @param workspace - Target task's workspace
|
|
2875
|
+
* @param implementation - Target task's implementation type
|
|
2876
|
+
* @param specifier - Target task's specifier (empty for broadcast)
|
|
2877
|
+
* @param payload - Message payload (bytes)
|
|
2878
|
+
* @param messageType - Message type. Default: Chat
|
|
2879
|
+
*/
|
|
2880
|
+
sendToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
2881
|
+
/**
|
|
2882
|
+
* Sends a message to a specific user session.
|
|
2883
|
+
*
|
|
2884
|
+
* @param userId - Target user's ID
|
|
2885
|
+
* @param windowId - Target user's window/session ID
|
|
2886
|
+
* @param payload - Message payload (bytes)
|
|
2887
|
+
* @param messageType - Message type. Default: Chat
|
|
2888
|
+
*/
|
|
2889
|
+
sendToUser(userId: string, windowId: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
2890
|
+
/**
|
|
2891
|
+
* Sends a message to a user's workspace scope.
|
|
2892
|
+
*
|
|
2893
|
+
* This reaches the user regardless of which window/tab they are using.
|
|
2894
|
+
*
|
|
2895
|
+
* @param userId - Target user's ID
|
|
2896
|
+
* @param workspace - Target workspace
|
|
2897
|
+
* @param payload - Message payload (bytes)
|
|
2898
|
+
* @param messageType - Message type. Default: Chat
|
|
2899
|
+
*/
|
|
2900
|
+
sendToUserWorkspace(userId: string, workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
2901
|
+
/**
|
|
2902
|
+
* Sends a message to all agents in a workspace.
|
|
2903
|
+
*
|
|
2904
|
+
* @param workspace - Target workspace
|
|
2905
|
+
* @param payload - Message payload (bytes)
|
|
2906
|
+
* @param messageType - Message type. Default: Chat
|
|
2907
|
+
*/
|
|
2908
|
+
broadcastToAgents(workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
2909
|
+
/**
|
|
2910
|
+
* Sends a message to all users in a workspace.
|
|
2911
|
+
*
|
|
2912
|
+
* @param workspace - Target workspace
|
|
2913
|
+
* @param payload - Message payload (bytes)
|
|
2914
|
+
* @param messageType - Message type. Default: Chat
|
|
2915
|
+
*/
|
|
2916
|
+
broadcastToUsers(workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
2917
|
+
/**
|
|
2918
|
+
* Publishes an event to the workflow engine.
|
|
2919
|
+
*
|
|
2920
|
+
* @param payload - Event payload (bytes)
|
|
2921
|
+
*/
|
|
2922
|
+
sendEvent(payload: Uint8Array): void;
|
|
2923
|
+
/**
|
|
2924
|
+
* Publishes a metric to the metrics bridge.
|
|
2925
|
+
*
|
|
2926
|
+
* @param metric - Structured metric to publish. Use {@link newMetric} to construct one.
|
|
2927
|
+
*/
|
|
2928
|
+
sendMetric(metric: Metric): void;
|
|
2929
|
+
/**
|
|
2930
|
+
* Creates a new task with the specified parameters.
|
|
2931
|
+
*
|
|
2932
|
+
* @param opts - Task creation options
|
|
2933
|
+
* @throws {@link InvalidArgumentError} if task type is missing
|
|
2934
|
+
*/
|
|
2935
|
+
createTask(opts: CreateTaskOptions): void;
|
|
2936
|
+
/**
|
|
2937
|
+
* Registers a handler specifically for task-related messages.
|
|
2938
|
+
*
|
|
2939
|
+
* Filters incoming messages to only those from task topics (tu.* or ta.*).
|
|
2940
|
+
*
|
|
2941
|
+
* @param handler - Function called when a task message is received
|
|
2942
|
+
*/
|
|
2943
|
+
onTaskMessage(handler: MessageHandler): void;
|
|
2944
|
+
/**
|
|
2945
|
+
* Registers a handler specifically for control messages.
|
|
2946
|
+
*
|
|
2947
|
+
* Note: Since the base protocol delivers all messages through a single
|
|
2948
|
+
* stream, this filters based on source topic prefixes. For more granular
|
|
2949
|
+
* filtering, use onMessage directly and inspect the payload.
|
|
2950
|
+
*
|
|
2951
|
+
* @param handler - Function called when a control message is received
|
|
2952
|
+
*/
|
|
2953
|
+
onControlMessage(handler: MessageHandler): void;
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
/**
|
|
2957
|
+
* Task client implementation for the Aether TypeScript SDK.
|
|
2958
|
+
*
|
|
2959
|
+
* This module provides the TaskClient class for connecting to the Aether
|
|
2960
|
+
* gateway as a task. Tasks can be unique (named, with a specifier) or
|
|
2961
|
+
* non-unique (server-assigned ID, load-balanced via broadcast topic).
|
|
2962
|
+
*
|
|
2963
|
+
* @module tasks
|
|
2964
|
+
*/
|
|
2965
|
+
|
|
2966
|
+
/**
|
|
2967
|
+
* Configuration options for the TaskClient.
|
|
2968
|
+
*/
|
|
2969
|
+
interface TaskClientOptions extends AetherClientOptions {
|
|
2970
|
+
/** The workspace to connect to. Required. */
|
|
2971
|
+
workspace: string;
|
|
2972
|
+
/** The task implementation type. Required. */
|
|
2973
|
+
implementation: string;
|
|
2974
|
+
/** Unique specifier for this task. Empty for non-unique tasks. */
|
|
2975
|
+
uniqueSpecifier?: string;
|
|
2976
|
+
}
|
|
2977
|
+
/**
|
|
2978
|
+
* Client for connecting to the Aether gateway as a task.
|
|
2979
|
+
*
|
|
2980
|
+
* Tasks come in two flavors:
|
|
2981
|
+
* - **Unique tasks** (with specifier): Persistent identity like agents,
|
|
2982
|
+
* only one connection at a time. Topic: tu.{workspace}.{impl}.{spec}
|
|
2983
|
+
* - **Non-unique tasks** (empty specifier): Server-assigned ID, multiple
|
|
2984
|
+
* instances allowed. Subscribe to both ta.{workspace}.{impl}.{id} and
|
|
2985
|
+
* the shared tb.{workspace}.{impl} broadcast for work claiming.
|
|
2986
|
+
*
|
|
2987
|
+
* @example
|
|
2988
|
+
* ```typescript
|
|
2989
|
+
* // Unique task
|
|
2990
|
+
* const task = new TaskClient({
|
|
2991
|
+
* address: "localhost:50051",
|
|
2992
|
+
* workspace: "prod",
|
|
2993
|
+
* implementation: "report-gen",
|
|
2994
|
+
* uniqueSpecifier: "daily-report",
|
|
2995
|
+
* });
|
|
2996
|
+
*
|
|
2997
|
+
* // Non-unique task (worker pool)
|
|
2998
|
+
* const worker = new TaskClient({
|
|
2999
|
+
* address: "localhost:50051",
|
|
3000
|
+
* workspace: "prod",
|
|
3001
|
+
* implementation: "data-processor",
|
|
3002
|
+
* });
|
|
3003
|
+
* ```
|
|
3004
|
+
*/
|
|
3005
|
+
declare class TaskClient extends AetherClient {
|
|
3006
|
+
private _workspace;
|
|
3007
|
+
private readonly _implementation;
|
|
3008
|
+
private readonly _uniqueSpecifier;
|
|
3009
|
+
constructor(options: TaskClientOptions);
|
|
3010
|
+
get workspace(): string;
|
|
3011
|
+
get implementation(): string;
|
|
3012
|
+
get uniqueSpecifier(): string;
|
|
3013
|
+
/** Whether this is a unique (named) task. */
|
|
3014
|
+
get isUnique(): boolean;
|
|
3015
|
+
/**
|
|
3016
|
+
* Returns this task's topic address.
|
|
3017
|
+
* For unique tasks: tu.{workspace}.{impl}.{spec}
|
|
3018
|
+
* For non-unique tasks: returns the broadcast topic tb.{workspace}.{impl}
|
|
3019
|
+
* (the actual instance topic is assigned by the server).
|
|
3020
|
+
*/
|
|
3021
|
+
get topic(): string;
|
|
3022
|
+
/** @internal */
|
|
3023
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
3024
|
+
/**
|
|
3025
|
+
* Switches the task's workspace.
|
|
3026
|
+
*
|
|
3027
|
+
* @param newWorkspace - The new workspace to switch to
|
|
3028
|
+
* @throws {@link InvalidArgumentError} if the workspace is empty
|
|
3029
|
+
*/
|
|
3030
|
+
switchWorkspace(newWorkspace: string): void;
|
|
3031
|
+
/**
|
|
3032
|
+
* Sends a message to a specific agent.
|
|
3033
|
+
*/
|
|
3034
|
+
sendToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3035
|
+
/**
|
|
3036
|
+
* Sends a message to a specific task.
|
|
3037
|
+
* For unique tasks (with specifier), uses tu.* topic.
|
|
3038
|
+
* For non-unique tasks (empty specifier), uses tb.* broadcast topic.
|
|
3039
|
+
*/
|
|
3040
|
+
sendToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3041
|
+
/**
|
|
3042
|
+
* Sends a message to a specific user session.
|
|
3043
|
+
*/
|
|
3044
|
+
sendToUser(userId: string, windowId: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3045
|
+
/**
|
|
3046
|
+
* Publishes an event to the workflow engine.
|
|
3047
|
+
*/
|
|
3048
|
+
sendEvent(payload: Uint8Array): void;
|
|
3049
|
+
/**
|
|
3050
|
+
* Publishes a metric to the metrics bridge.
|
|
3051
|
+
*
|
|
3052
|
+
* @param metric - Structured metric to publish. Use {@link newMetric} to construct one.
|
|
3053
|
+
*/
|
|
3054
|
+
sendMetric(metric: Metric): void;
|
|
3055
|
+
/**
|
|
3056
|
+
* Creates a new task with the specified parameters.
|
|
3057
|
+
*
|
|
3058
|
+
* @param opts - Task creation options
|
|
3059
|
+
* @throws {@link InvalidArgumentError} if task type is missing
|
|
3060
|
+
*/
|
|
3061
|
+
createTask(opts: CreateTaskOptions): void;
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
/**
|
|
3065
|
+
* User client implementation for the Aether TypeScript SDK.
|
|
3066
|
+
*
|
|
3067
|
+
* This module provides the UserClient class for connecting to the Aether
|
|
3068
|
+
* gateway as a user. Users are identified by userId and windowId, allowing
|
|
3069
|
+
* multiple browser tabs or sessions per user.
|
|
3070
|
+
*
|
|
3071
|
+
* Per the Aether specification, users can only send direct messages.
|
|
3072
|
+
* They cannot publish events or metrics like agents and tasks can.
|
|
3073
|
+
*
|
|
3074
|
+
* @module users
|
|
3075
|
+
*/
|
|
3076
|
+
|
|
3077
|
+
/**
|
|
3078
|
+
* Configuration options for the UserClient.
|
|
3079
|
+
*/
|
|
3080
|
+
interface UserClientOptions extends AetherClientOptions {
|
|
3081
|
+
/** The user's unique identifier. Required. */
|
|
3082
|
+
userId: string;
|
|
3083
|
+
/** The window/session identifier. Required. */
|
|
3084
|
+
windowId: string;
|
|
3085
|
+
/** Optional initial workspace association. */
|
|
3086
|
+
workspace?: string;
|
|
3087
|
+
}
|
|
3088
|
+
/**
|
|
3089
|
+
* Client for connecting to the Aether gateway as a user.
|
|
3090
|
+
*
|
|
3091
|
+
* Users are identified by userId and windowId, allowing multiple browser
|
|
3092
|
+
* tabs or sessions per user. Each user session (userId + windowId combination)
|
|
3093
|
+
* is unique and can only have one active connection at a time.
|
|
3094
|
+
*
|
|
3095
|
+
* UserClient extends AetherClient and adds user-specific functionality:
|
|
3096
|
+
* - Identity management (userId, windowId)
|
|
3097
|
+
* - Messaging helpers (sendToAgent, sendToUser, sendToTask)
|
|
3098
|
+
* - Optional workspace association
|
|
3099
|
+
*
|
|
3100
|
+
* Note: Per the Aether specification, users can only send direct messages.
|
|
3101
|
+
* They cannot publish events or metrics.
|
|
3102
|
+
*
|
|
3103
|
+
* @example
|
|
3104
|
+
* ```typescript
|
|
3105
|
+
* import { UserClient } from "@scitrera/aether-client";
|
|
3106
|
+
*
|
|
3107
|
+
* const user = new UserClient({
|
|
3108
|
+
* address: "localhost:50051",
|
|
3109
|
+
* userId: "alice",
|
|
3110
|
+
* windowId: "tab-1",
|
|
3111
|
+
* });
|
|
3112
|
+
*
|
|
3113
|
+
* user.onIncomingMessage((msg) => {
|
|
3114
|
+
* console.log(`Received from ${msg.sourceTopic}:`, msg.payload);
|
|
3115
|
+
* });
|
|
3116
|
+
*
|
|
3117
|
+
* await user.connect();
|
|
3118
|
+
*
|
|
3119
|
+
* // Send a message to an agent
|
|
3120
|
+
* const encoder = new TextEncoder();
|
|
3121
|
+
* user.sendToAgent("prod", "data-processor", "instance-1",
|
|
3122
|
+
* encoder.encode(JSON.stringify({ action: "process" }))
|
|
3123
|
+
* );
|
|
3124
|
+
* ```
|
|
3125
|
+
*/
|
|
3126
|
+
declare class UserClient extends AetherClient {
|
|
3127
|
+
private readonly _userId;
|
|
3128
|
+
private readonly _windowId;
|
|
3129
|
+
private _workspace;
|
|
3130
|
+
/**
|
|
3131
|
+
* Creates a new UserClient.
|
|
3132
|
+
*
|
|
3133
|
+
* @param options - User client configuration
|
|
3134
|
+
* @throws {@link InvalidArgumentError} if required fields are missing
|
|
3135
|
+
*/
|
|
3136
|
+
constructor(options: UserClientOptions);
|
|
3137
|
+
/** Returns the user's unique identifier. */
|
|
3138
|
+
get userId(): string;
|
|
3139
|
+
/** Returns the user's window/session identifier. */
|
|
3140
|
+
get windowId(): string;
|
|
3141
|
+
/** Returns the user's current workspace (if set). */
|
|
3142
|
+
get workspace(): string;
|
|
3143
|
+
/**
|
|
3144
|
+
* Returns this user's topic address.
|
|
3145
|
+
*
|
|
3146
|
+
* Format: us.{userId}.{windowId}
|
|
3147
|
+
*/
|
|
3148
|
+
get topic(): string;
|
|
3149
|
+
/**
|
|
3150
|
+
* Returns this user's workspace-scoped topic address.
|
|
3151
|
+
*
|
|
3152
|
+
* Format: uw.{userId}.{workspace}
|
|
3153
|
+
*
|
|
3154
|
+
* Returns empty string if no workspace is set.
|
|
3155
|
+
*/
|
|
3156
|
+
get workspaceTopic(): string;
|
|
3157
|
+
/** @internal */
|
|
3158
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
3159
|
+
/**
|
|
3160
|
+
* Sets the user's current workspace for workspace-scoped operations.
|
|
3161
|
+
*
|
|
3162
|
+
* This is a local operation that does not notify the gateway.
|
|
3163
|
+
*
|
|
3164
|
+
* @param workspace - The workspace to associate with
|
|
3165
|
+
*/
|
|
3166
|
+
setWorkspace(workspace: string): void;
|
|
3167
|
+
/**
|
|
3168
|
+
* Switches the user's workspace on the gateway.
|
|
3169
|
+
*
|
|
3170
|
+
* Sends a SwitchWorkspace message to the gateway, which will update
|
|
3171
|
+
* topic subscriptions (including progress) and send a new ConfigSnapshot.
|
|
3172
|
+
*
|
|
3173
|
+
* @param newWorkspace - The new workspace to switch to
|
|
3174
|
+
* @throws {@link InvalidArgumentError} if the workspace is empty
|
|
3175
|
+
*/
|
|
3176
|
+
switchWorkspace(newWorkspace: string): void;
|
|
3177
|
+
/**
|
|
3178
|
+
* Sends a message to a specific agent.
|
|
3179
|
+
*
|
|
3180
|
+
* @param workspace - Target agent's workspace
|
|
3181
|
+
* @param implementation - Target agent's implementation type
|
|
3182
|
+
* @param specifier - Target agent's specifier
|
|
3183
|
+
* @param payload - Message payload (bytes)
|
|
3184
|
+
* @param messageType - Message type. Default: Chat
|
|
3185
|
+
*/
|
|
3186
|
+
sendToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3187
|
+
/**
|
|
3188
|
+
* Sends a message to a specific task.
|
|
3189
|
+
*
|
|
3190
|
+
* For unique tasks (with specifier), uses tu.{workspace}.{impl}.{spec} topic.
|
|
3191
|
+
* For non-unique tasks (empty specifier), uses tb.{workspace}.{impl} broadcast topic.
|
|
3192
|
+
*
|
|
3193
|
+
* @param workspace - Target task's workspace
|
|
3194
|
+
* @param implementation - Target task's implementation type
|
|
3195
|
+
* @param specifier - Target task's specifier (empty for broadcast)
|
|
3196
|
+
* @param payload - Message payload (bytes)
|
|
3197
|
+
* @param messageType - Message type. Default: Chat
|
|
3198
|
+
*/
|
|
3199
|
+
sendToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3200
|
+
/**
|
|
3201
|
+
* Sends a message to a specific user session.
|
|
3202
|
+
*
|
|
3203
|
+
* @param userId - Target user's ID
|
|
3204
|
+
* @param windowId - Target user's window/session ID
|
|
3205
|
+
* @param payload - Message payload (bytes)
|
|
3206
|
+
* @param messageType - Message type. Default: Chat
|
|
3207
|
+
*/
|
|
3208
|
+
sendToUser(userId: string, windowId: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3209
|
+
/**
|
|
3210
|
+
* Sends a message to a user's workspace scope.
|
|
3211
|
+
*
|
|
3212
|
+
* @param userId - Target user's ID
|
|
3213
|
+
* @param workspace - Target workspace
|
|
3214
|
+
* @param payload - Message payload (bytes)
|
|
3215
|
+
* @param messageType - Message type. Default: Chat
|
|
3216
|
+
*/
|
|
3217
|
+
sendToUserWorkspace(userId: string, workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3218
|
+
/**
|
|
3219
|
+
* Creates a new task with the specified parameters.
|
|
3220
|
+
*
|
|
3221
|
+
* Users can create tasks targeting agents or task pools.
|
|
3222
|
+
*
|
|
3223
|
+
* @param opts - Task creation options
|
|
3224
|
+
* @throws {@link InvalidArgumentError} if task type is missing
|
|
3225
|
+
*/
|
|
3226
|
+
createTask(opts: CreateTaskOptions): void;
|
|
3227
|
+
/**
|
|
3228
|
+
* Registers a handler for all incoming messages.
|
|
3229
|
+
*
|
|
3230
|
+
* This is an alias for onMessage, provided for API clarity in the
|
|
3231
|
+
* user context.
|
|
3232
|
+
*
|
|
3233
|
+
* @param handler - Function called when a message is received
|
|
3234
|
+
*/
|
|
3235
|
+
onIncomingMessage(handler: MessageHandler): void;
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
/**
|
|
3239
|
+
* Orchestrator client implementation for the Aether TypeScript SDK.
|
|
3240
|
+
*
|
|
3241
|
+
* Orchestrators manage agent/task lifecycle: receiving startup requests
|
|
3242
|
+
* when targeted agents are offline, launching compute resources, and
|
|
3243
|
+
* managing agent pools and scaling.
|
|
3244
|
+
*
|
|
3245
|
+
* @module orchestrator
|
|
3246
|
+
*/
|
|
3247
|
+
|
|
3248
|
+
/**
|
|
3249
|
+
* Configuration options for the OrchestratorClient.
|
|
3250
|
+
*/
|
|
3251
|
+
interface OrchestratorClientOptions extends AetherClientOptions {
|
|
3252
|
+
/** The orchestrator implementation type (e.g., "kubernetes-orchestrator"). Required. */
|
|
3253
|
+
implementation: string;
|
|
3254
|
+
/** Profiles this orchestrator supports (e.g., ["kubernetes", "docker"]). Required, at least one. */
|
|
3255
|
+
supportedProfiles: string[];
|
|
3256
|
+
/** Unique specifier for this instance. Auto-generated if not provided. */
|
|
3257
|
+
specifier?: string;
|
|
3258
|
+
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Client for connecting to the Aether gateway as an orchestrator.
|
|
3261
|
+
*
|
|
3262
|
+
* Orchestrators receive task assignments via the onTaskAssignment handler
|
|
3263
|
+
* and are responsible for launching the appropriate compute resources.
|
|
3264
|
+
*
|
|
3265
|
+
* @example
|
|
3266
|
+
* ```typescript
|
|
3267
|
+
* const orchestrator = new OrchestratorClient({
|
|
3268
|
+
* address: "localhost:50051",
|
|
3269
|
+
* implementation: "k8s-orchestrator",
|
|
3270
|
+
* supportedProfiles: ["kubernetes"],
|
|
3271
|
+
* });
|
|
3272
|
+
*
|
|
3273
|
+
* orchestrator.onTaskAssignment((assignment) => {
|
|
3274
|
+
* console.log(`Starting ${assignment.targetImplementation} for task ${assignment.taskId}`);
|
|
3275
|
+
* // Launch container based on assignment.launchParams
|
|
3276
|
+
* });
|
|
3277
|
+
*
|
|
3278
|
+
* await orchestrator.connect();
|
|
3279
|
+
* ```
|
|
3280
|
+
*/
|
|
3281
|
+
declare class OrchestratorClient extends AetherClient {
|
|
3282
|
+
private readonly _implementation;
|
|
3283
|
+
private readonly _specifier;
|
|
3284
|
+
private readonly _supportedProfiles;
|
|
3285
|
+
constructor(options: OrchestratorClientOptions);
|
|
3286
|
+
get implementation(): string;
|
|
3287
|
+
get specifier(): string;
|
|
3288
|
+
get supportedProfiles(): string[];
|
|
3289
|
+
/** @internal */
|
|
3290
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
3291
|
+
/**
|
|
3292
|
+
* Sends a status/control message to an agent.
|
|
3293
|
+
*/
|
|
3294
|
+
sendStatusToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3295
|
+
/**
|
|
3296
|
+
* Sends a status/control message to a task.
|
|
3297
|
+
* For unique tasks (with specifier), uses tu.* topic.
|
|
3298
|
+
* For non-unique tasks (empty specifier), uses tb.* broadcast topic.
|
|
3299
|
+
*/
|
|
3300
|
+
sendStatusToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3301
|
+
}
|
|
3302
|
+
/**
|
|
3303
|
+
* Configuration options for BaseOrchestrator subclasses.
|
|
3304
|
+
*/
|
|
3305
|
+
interface BaseOrchestratorOptions extends OrchestratorClientOptions {
|
|
3306
|
+
/**
|
|
3307
|
+
* Whether to log task assignment details to the console.
|
|
3308
|
+
* Default: false.
|
|
3309
|
+
*/
|
|
3310
|
+
logAssignments?: boolean;
|
|
3311
|
+
}
|
|
3312
|
+
/**
|
|
3313
|
+
* Abstract base class for building orchestrators.
|
|
3314
|
+
*
|
|
3315
|
+
* BaseOrchestrator wraps {@link OrchestratorClient} and provides a structured
|
|
3316
|
+
* framework for managing agent/task lifecycle. Subclasses implement the
|
|
3317
|
+
* abstract {@link launchTask} method to handle task assignments with their
|
|
3318
|
+
* specific compute backend (Docker, Kubernetes, subprocess, etc.).
|
|
3319
|
+
*
|
|
3320
|
+
* The class manages the full orchestrator lifecycle:
|
|
3321
|
+
* - Connecting to the Aether gateway as an Orchestrator principal
|
|
3322
|
+
* - Receiving {@link TaskAssignment} messages and dispatching to launchTask
|
|
3323
|
+
* - Error handling and logging hooks
|
|
3324
|
+
*
|
|
3325
|
+
* @example
|
|
3326
|
+
* ```typescript
|
|
3327
|
+
* import { BaseOrchestrator, TaskAssignment } from "@scitrera/aether-client";
|
|
3328
|
+
*
|
|
3329
|
+
* class MyOrchestrator extends BaseOrchestrator {
|
|
3330
|
+
* async launchTask(assignment: TaskAssignment): Promise<void> {
|
|
3331
|
+
* console.log(`Launching task ${assignment.taskId} (profile: ${assignment.profile})`);
|
|
3332
|
+
* // Start a subprocess, container, etc. using assignment.launchParams
|
|
3333
|
+
* }
|
|
3334
|
+
* }
|
|
3335
|
+
*
|
|
3336
|
+
* const orch = new MyOrchestrator({
|
|
3337
|
+
* address: "localhost:50051",
|
|
3338
|
+
* implementation: "my-orchestrator",
|
|
3339
|
+
* supportedProfiles: ["my-profile"],
|
|
3340
|
+
* });
|
|
3341
|
+
*
|
|
3342
|
+
* orch.onConnect((ack) => {
|
|
3343
|
+
* console.log(`Connected with session ${ack.sessionId}`);
|
|
3344
|
+
* });
|
|
3345
|
+
*
|
|
3346
|
+
* await orch.connect();
|
|
3347
|
+
* ```
|
|
3348
|
+
*/
|
|
3349
|
+
declare abstract class BaseOrchestrator {
|
|
3350
|
+
/** The underlying OrchestratorClient for direct gateway access. */
|
|
3351
|
+
readonly client: OrchestratorClient;
|
|
3352
|
+
private readonly _logAssignments;
|
|
3353
|
+
/**
|
|
3354
|
+
* Creates a new BaseOrchestrator.
|
|
3355
|
+
*
|
|
3356
|
+
* @param options - Orchestrator configuration options
|
|
3357
|
+
*/
|
|
3358
|
+
constructor(options: BaseOrchestratorOptions);
|
|
3359
|
+
/**
|
|
3360
|
+
* Called when the gateway assigns a task to this orchestrator.
|
|
3361
|
+
*
|
|
3362
|
+
* Subclasses must implement this method to launch the appropriate compute
|
|
3363
|
+
* resource (container, process, VM, etc.) based on the assignment details.
|
|
3364
|
+
*
|
|
3365
|
+
* The assignment includes:
|
|
3366
|
+
* - `taskId`: Unique task identifier
|
|
3367
|
+
* - `profile`: The profile that matched (from supportedProfiles)
|
|
3368
|
+
* - `targetImplementation`: The agent/task implementation to launch
|
|
3369
|
+
* - `workspace`: The workspace this task belongs to
|
|
3370
|
+
* - `specifier`: Optional unique specifier for the agent/task
|
|
3371
|
+
* - `launchParams`: Key-value launch parameters (image, command, env vars, etc.)
|
|
3372
|
+
* - `metadata`: Arbitrary task metadata
|
|
3373
|
+
*
|
|
3374
|
+
* @param assignment - The task assignment received from the gateway
|
|
3375
|
+
*/
|
|
3376
|
+
abstract launchTask(assignment: TaskAssignment): void | Promise<void>;
|
|
3377
|
+
/**
|
|
3378
|
+
* Connects to the Aether gateway.
|
|
3379
|
+
*
|
|
3380
|
+
* Must be called before the orchestrator can receive task assignments.
|
|
3381
|
+
*/
|
|
3382
|
+
connect(): Promise<void>;
|
|
3383
|
+
/**
|
|
3384
|
+
* Disconnects from the Aether gateway.
|
|
3385
|
+
*/
|
|
3386
|
+
disconnect(): Promise<void>;
|
|
3387
|
+
/**
|
|
3388
|
+
* Returns whether the orchestrator is currently connected.
|
|
3389
|
+
*/
|
|
3390
|
+
get connected(): boolean;
|
|
3391
|
+
/**
|
|
3392
|
+
* Returns the current session ID assigned by the gateway.
|
|
3393
|
+
* Empty string if not connected.
|
|
3394
|
+
*/
|
|
3395
|
+
get sessionId(): string;
|
|
3396
|
+
/**
|
|
3397
|
+
* Returns the orchestrator's implementation type.
|
|
3398
|
+
*/
|
|
3399
|
+
get implementation(): string;
|
|
3400
|
+
/**
|
|
3401
|
+
* Returns the orchestrator's specifier.
|
|
3402
|
+
*/
|
|
3403
|
+
get specifier(): string;
|
|
3404
|
+
/**
|
|
3405
|
+
* Returns the list of profiles this orchestrator supports.
|
|
3406
|
+
*/
|
|
3407
|
+
get supportedProfiles(): string[];
|
|
3408
|
+
/**
|
|
3409
|
+
* Registers a handler for successful connection events.
|
|
3410
|
+
*
|
|
3411
|
+
* @param handler - Called with the ConnectionAck when connected
|
|
3412
|
+
*/
|
|
3413
|
+
onConnect(handler: (ack: ConnectionAck) => void | Promise<void>): void;
|
|
3414
|
+
/**
|
|
3415
|
+
* Registers a handler for disconnection events.
|
|
3416
|
+
*
|
|
3417
|
+
* @param handler - Called with the reason string when disconnected
|
|
3418
|
+
*/
|
|
3419
|
+
onDisconnect(handler: (reason: string) => void | Promise<void>): void;
|
|
3420
|
+
/**
|
|
3421
|
+
* Registers a handler for reconnection attempts.
|
|
3422
|
+
*
|
|
3423
|
+
* @param handler - Called with the attempt number on each reconnect try
|
|
3424
|
+
*/
|
|
3425
|
+
onReconnecting(handler: (attempt: number) => void | Promise<void>): void;
|
|
3426
|
+
/**
|
|
3427
|
+
* Sends a status/control message to an agent.
|
|
3428
|
+
*
|
|
3429
|
+
* @param workspace - Target agent's workspace
|
|
3430
|
+
* @param implementation - Target agent's implementation type
|
|
3431
|
+
* @param specifier - Target agent's specifier
|
|
3432
|
+
* @param payload - Message payload
|
|
3433
|
+
* @param messageType - Message type. Default: Control
|
|
3434
|
+
*/
|
|
3435
|
+
sendStatusToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3436
|
+
/**
|
|
3437
|
+
* Sends a status/control message to a task.
|
|
3438
|
+
*
|
|
3439
|
+
* @param workspace - Target task's workspace
|
|
3440
|
+
* @param implementation - Target task's implementation type
|
|
3441
|
+
* @param specifier - Target task's specifier (empty for broadcast)
|
|
3442
|
+
* @param payload - Message payload
|
|
3443
|
+
* @param messageType - Message type. Default: Control
|
|
3444
|
+
*/
|
|
3445
|
+
sendStatusToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3446
|
+
/**
|
|
3447
|
+
* Internal handler that logs and dispatches to launchTask.
|
|
3448
|
+
* @internal
|
|
3449
|
+
*/
|
|
3450
|
+
private _handleAssignment;
|
|
3451
|
+
}
|
|
3452
|
+
|
|
3453
|
+
/**
|
|
3454
|
+
* Workflow engine client implementation for the Aether TypeScript SDK.
|
|
3455
|
+
*
|
|
3456
|
+
* The workflow engine is the sole subscriber to event.* topics and processes
|
|
3457
|
+
* broadcast events to trigger downstream actions by sending commands to
|
|
3458
|
+
* agents/tasks. It is a singleton per gateway deployment.
|
|
3459
|
+
*
|
|
3460
|
+
* @module workflow
|
|
3461
|
+
*/
|
|
3462
|
+
|
|
3463
|
+
/**
|
|
3464
|
+
* Configuration options for the WorkflowEngineClient.
|
|
3465
|
+
*
|
|
3466
|
+
* No additional identity fields are needed — the workflow engine is
|
|
3467
|
+
* identified by its principal type alone (singleton per gateway).
|
|
3468
|
+
*/
|
|
3469
|
+
type WorkflowEngineClientOptions = AetherClientOptions;
|
|
3470
|
+
/**
|
|
3471
|
+
* Client for connecting to the Aether gateway as a workflow engine.
|
|
3472
|
+
*
|
|
3473
|
+
* The workflow engine receives all events (event.*) and can send commands
|
|
3474
|
+
* to any principal type. It is the central event processor for the system.
|
|
3475
|
+
*
|
|
3476
|
+
* @example
|
|
3477
|
+
* ```typescript
|
|
3478
|
+
* const engine = new WorkflowEngineClient({
|
|
3479
|
+
* address: "localhost:50051",
|
|
3480
|
+
* });
|
|
3481
|
+
*
|
|
3482
|
+
* engine.onMessage((msg) => {
|
|
3483
|
+
* // Process incoming events
|
|
3484
|
+
* const event = JSON.parse(new TextDecoder().decode(msg.payload));
|
|
3485
|
+
* console.log(`Event from ${msg.sourceTopic}:`, event);
|
|
3486
|
+
* });
|
|
3487
|
+
*
|
|
3488
|
+
* await engine.connect();
|
|
3489
|
+
* ```
|
|
3490
|
+
*/
|
|
3491
|
+
declare class WorkflowEngineClient extends AetherClient {
|
|
3492
|
+
constructor(options: WorkflowEngineClientOptions);
|
|
3493
|
+
/** @internal */
|
|
3494
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
3495
|
+
/**
|
|
3496
|
+
* Sends a command to a specific agent.
|
|
3497
|
+
*/
|
|
3498
|
+
sendCommandToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3499
|
+
/**
|
|
3500
|
+
* Sends a command to a specific task.
|
|
3501
|
+
* For unique tasks (with specifier), uses tu.* topic.
|
|
3502
|
+
* For non-unique tasks (empty specifier), uses tb.* broadcast topic.
|
|
3503
|
+
*/
|
|
3504
|
+
sendCommandToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3505
|
+
/**
|
|
3506
|
+
* Sends a broadcast to all agents in a workspace.
|
|
3507
|
+
*/
|
|
3508
|
+
broadcastToAgents(workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3509
|
+
/**
|
|
3510
|
+
* Sends a broadcast to all users in a workspace.
|
|
3511
|
+
*/
|
|
3512
|
+
broadcastToUsers(workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3513
|
+
/**
|
|
3514
|
+
* Sends a message to a specific user session.
|
|
3515
|
+
*/
|
|
3516
|
+
sendToUser(userId: string, windowId: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3517
|
+
/**
|
|
3518
|
+
* Publishes a metric to the metrics bridge.
|
|
3519
|
+
*
|
|
3520
|
+
* @param metric - Structured metric to publish. Use {@link newMetric} to construct one.
|
|
3521
|
+
*/
|
|
3522
|
+
sendMetric(metric: Metric): void;
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
/**
|
|
3526
|
+
* Metrics bridge client implementation for the Aether TypeScript SDK.
|
|
3527
|
+
*
|
|
3528
|
+
* The metrics bridge is a receive-only client that subscribes to metric.*
|
|
3529
|
+
* topics to collect telemetry data from agents and tasks. It is a singleton
|
|
3530
|
+
* per gateway deployment.
|
|
3531
|
+
*
|
|
3532
|
+
* @module metrics
|
|
3533
|
+
*/
|
|
3534
|
+
|
|
3535
|
+
/**
|
|
3536
|
+
* Configuration options for the MetricsBridgeClient.
|
|
3537
|
+
*
|
|
3538
|
+
* No additional identity fields are needed — the metrics bridge is
|
|
3539
|
+
* identified by its principal type alone (singleton per gateway).
|
|
3540
|
+
*/
|
|
3541
|
+
type MetricsBridgeClientOptions = AetherClientOptions;
|
|
3542
|
+
/**
|
|
3543
|
+
* Client for connecting to the Aether gateway as a metrics bridge.
|
|
3544
|
+
*
|
|
3545
|
+
* The metrics bridge is receive-only: it subscribes to metric.* topics
|
|
3546
|
+
* to collect telemetry data published by agents and tasks. It does not
|
|
3547
|
+
* send messages to other principals.
|
|
3548
|
+
*
|
|
3549
|
+
* @example
|
|
3550
|
+
* ```typescript
|
|
3551
|
+
* const bridge = new MetricsBridgeClient({
|
|
3552
|
+
* address: "localhost:50051",
|
|
3553
|
+
* });
|
|
3554
|
+
*
|
|
3555
|
+
* bridge.onMessage((msg) => {
|
|
3556
|
+
* // Process incoming metrics
|
|
3557
|
+
* const metric = JSON.parse(new TextDecoder().decode(msg.payload));
|
|
3558
|
+
* console.log(`Metric from ${msg.sourceTopic}:`, metric);
|
|
3559
|
+
* });
|
|
3560
|
+
*
|
|
3561
|
+
* await bridge.connect();
|
|
3562
|
+
* ```
|
|
3563
|
+
*/
|
|
3564
|
+
declare class MetricsBridgeClient extends AetherClient {
|
|
3565
|
+
constructor(options: MetricsBridgeClientOptions);
|
|
3566
|
+
/** @internal */
|
|
3567
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
3568
|
+
/**
|
|
3569
|
+
* Sends an acknowledgment to a source topic.
|
|
3570
|
+
*
|
|
3571
|
+
* @param targetTopic - The topic to send the acknowledgment to
|
|
3572
|
+
* @param payload - The acknowledgment payload
|
|
3573
|
+
*/
|
|
3574
|
+
sendAcknowledgment(targetTopic: string, payload: Uint8Array): void;
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
/**
|
|
3578
|
+
* Bridge client implementation for the Aether TypeScript SDK.
|
|
3579
|
+
*
|
|
3580
|
+
* This module provides the BridgeClient class for connecting to the Aether
|
|
3581
|
+
* gateway as a cross-workspace message bridge. Bridges relay messages across
|
|
3582
|
+
* workspace boundaries and can send to any principal type in any workspace.
|
|
3583
|
+
*
|
|
3584
|
+
* Unlike workspace-scoped principals (agents, tasks, users), bridges have no
|
|
3585
|
+
* workspace field in their identity — allowing them to send to targets in any
|
|
3586
|
+
* workspace. Each bridge identity can only have one active connection at a time
|
|
3587
|
+
* (Connection = Lock paradigm).
|
|
3588
|
+
*
|
|
3589
|
+
* @module bridge
|
|
3590
|
+
*/
|
|
3591
|
+
|
|
3592
|
+
/**
|
|
3593
|
+
* Configuration options for the BridgeClient.
|
|
3594
|
+
*/
|
|
3595
|
+
interface BridgeClientOptions extends AetherClientOptions {
|
|
3596
|
+
/** The bridge implementation type (e.g., "aether-msgbridge", "webhook-bridge"). Required. */
|
|
3597
|
+
implementation: string;
|
|
3598
|
+
/** The unique specifier for this bridge instance (e.g., "default", "discord-1"). Required. */
|
|
3599
|
+
specifier: string;
|
|
3600
|
+
}
|
|
3601
|
+
/**
|
|
3602
|
+
* Client for connecting to the Aether gateway as a cross-workspace message bridge.
|
|
3603
|
+
*
|
|
3604
|
+
* Bridges are identified by implementation and specifier with no workspace field,
|
|
3605
|
+
* allowing them to operate across workspace boundaries. Each bridge identity can
|
|
3606
|
+
* only have one active connection at a time (Connection = Lock paradigm).
|
|
3607
|
+
*
|
|
3608
|
+
* BridgeClient extends AetherClient and adds bridge-specific functionality:
|
|
3609
|
+
* - Identity management (implementation, specifier)
|
|
3610
|
+
* - Messaging helpers to any workspace (sendToAgent, sendToUser, sendToTask, broadcast)
|
|
3611
|
+
*
|
|
3612
|
+
* Topic format: br.{implementation}.{specifier}
|
|
3613
|
+
*
|
|
3614
|
+
* @example
|
|
3615
|
+
* ```typescript
|
|
3616
|
+
* import { BridgeClient } from "@scitrera/aether-client";
|
|
3617
|
+
*
|
|
3618
|
+
* const bridge = new BridgeClient({
|
|
3619
|
+
* address: "localhost:50051",
|
|
3620
|
+
* implementation: "aether-msgbridge",
|
|
3621
|
+
* specifier: "discord-1",
|
|
3622
|
+
* });
|
|
3623
|
+
*
|
|
3624
|
+
* bridge.onMessage((msg) => {
|
|
3625
|
+
* console.log(`Received from ${msg.sourceTopic}:`, msg.payload);
|
|
3626
|
+
* });
|
|
3627
|
+
*
|
|
3628
|
+
* await bridge.connect();
|
|
3629
|
+
*
|
|
3630
|
+
* // Send to any workspace — bridges are cross-workspace
|
|
3631
|
+
* const encoder = new TextEncoder();
|
|
3632
|
+
* bridge.sendToAgent("prod", "my-agent", "instance-1", encoder.encode("Hello!"));
|
|
3633
|
+
* bridge.sendToUser("alice", "tab-1", encoder.encode("Notification from Discord"));
|
|
3634
|
+
* ```
|
|
3635
|
+
*/
|
|
3636
|
+
declare class BridgeClient extends AetherClient {
|
|
3637
|
+
private readonly _implementation;
|
|
3638
|
+
private readonly _specifier;
|
|
3639
|
+
/**
|
|
3640
|
+
* Creates a new BridgeClient.
|
|
3641
|
+
*
|
|
3642
|
+
* @param options - Bridge client configuration
|
|
3643
|
+
* @throws {@link InvalidArgumentError} if required fields are missing
|
|
3644
|
+
*/
|
|
3645
|
+
constructor(options: BridgeClientOptions);
|
|
3646
|
+
/** Returns the bridge's implementation type. */
|
|
3647
|
+
get implementation(): string;
|
|
3648
|
+
/** Returns the bridge's specifier (instance identifier). */
|
|
3649
|
+
get specifier(): string;
|
|
3650
|
+
/**
|
|
3651
|
+
* Returns this bridge's topic address.
|
|
3652
|
+
*
|
|
3653
|
+
* Format: br.{implementation}.{specifier}
|
|
3654
|
+
*/
|
|
3655
|
+
get topic(): string;
|
|
3656
|
+
/** @internal */
|
|
3657
|
+
protected _buildInitMessage(): Record<string, unknown>;
|
|
3658
|
+
/**
|
|
3659
|
+
* Sends a message to a specific agent in any workspace.
|
|
3660
|
+
*
|
|
3661
|
+
* @param workspace - Target agent's workspace
|
|
3662
|
+
* @param implementation - Target agent's implementation type
|
|
3663
|
+
* @param specifier - Target agent's specifier
|
|
3664
|
+
* @param payload - Message payload (bytes)
|
|
3665
|
+
* @param messageType - Message type. Default: Chat
|
|
3666
|
+
*/
|
|
3667
|
+
sendToAgent(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3668
|
+
/**
|
|
3669
|
+
* Sends a message to a specific task in any workspace.
|
|
3670
|
+
*
|
|
3671
|
+
* For unique tasks (with specifier), uses tu.{workspace}.{impl}.{spec} topic.
|
|
3672
|
+
* For non-unique tasks (empty specifier), uses tb.{workspace}.{impl} broadcast topic.
|
|
3673
|
+
*
|
|
3674
|
+
* @param workspace - Target task's workspace
|
|
3675
|
+
* @param implementation - Target task's implementation type
|
|
3676
|
+
* @param specifier - Target task's specifier (empty for broadcast)
|
|
3677
|
+
* @param payload - Message payload (bytes)
|
|
3678
|
+
* @param messageType - Message type. Default: Chat
|
|
3679
|
+
*/
|
|
3680
|
+
sendToTask(workspace: string, implementation: string, specifier: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3681
|
+
/**
|
|
3682
|
+
* Sends a message to a specific user session.
|
|
3683
|
+
*
|
|
3684
|
+
* @param userId - Target user's ID
|
|
3685
|
+
* @param windowId - Target user's window/session ID
|
|
3686
|
+
* @param payload - Message payload (bytes)
|
|
3687
|
+
* @param messageType - Message type. Default: Chat
|
|
3688
|
+
*/
|
|
3689
|
+
sendToUser(userId: string, windowId: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3690
|
+
/**
|
|
3691
|
+
* Sends a message to a user's workspace scope.
|
|
3692
|
+
*
|
|
3693
|
+
* This reaches the user regardless of which window/tab they are using.
|
|
3694
|
+
*
|
|
3695
|
+
* @param userId - Target user's ID
|
|
3696
|
+
* @param workspace - Target workspace
|
|
3697
|
+
* @param payload - Message payload (bytes)
|
|
3698
|
+
* @param messageType - Message type. Default: Chat
|
|
3699
|
+
*/
|
|
3700
|
+
sendToUserWorkspace(userId: string, workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3701
|
+
/**
|
|
3702
|
+
* Sends a message to all agents in a workspace.
|
|
3703
|
+
*
|
|
3704
|
+
* @param workspace - Target workspace
|
|
3705
|
+
* @param payload - Message payload (bytes)
|
|
3706
|
+
* @param messageType - Message type. Default: Chat
|
|
3707
|
+
*/
|
|
3708
|
+
broadcastToAgents(workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3709
|
+
/**
|
|
3710
|
+
* Sends a message to all users in a workspace.
|
|
3711
|
+
*
|
|
3712
|
+
* @param workspace - Target workspace
|
|
3713
|
+
* @param payload - Message payload (bytes)
|
|
3714
|
+
* @param messageType - Message type. Default: Chat
|
|
3715
|
+
*/
|
|
3716
|
+
broadcastToUsers(workspace: string, payload: Uint8Array, messageType?: MessageType): void;
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
/**
|
|
3720
|
+
* Error hierarchy for the Aether TypeScript SDK.
|
|
3721
|
+
*
|
|
3722
|
+
* This module provides a structured set of error classes that map to common
|
|
3723
|
+
* error scenarios in Aether client operations, mirroring the error hierarchies
|
|
3724
|
+
* in the Go SDK (errors.go) and Python SDK (exceptions.py).
|
|
3725
|
+
*
|
|
3726
|
+
* All errors extend the base AetherError class, making it easy to catch all
|
|
3727
|
+
* SDK-related errors with a single catch clause.
|
|
3728
|
+
*
|
|
3729
|
+
* @module errors
|
|
3730
|
+
*/
|
|
3731
|
+
/**
|
|
3732
|
+
* Base error class for all Aether SDK errors.
|
|
3733
|
+
*
|
|
3734
|
+
* All Aether-specific errors extend this class.
|
|
3735
|
+
*/
|
|
3736
|
+
declare class AetherError extends Error {
|
|
3737
|
+
/** Optional error code (e.g., gRPC status code name). */
|
|
3738
|
+
readonly code: string;
|
|
3739
|
+
/** Optional additional error details. */
|
|
3740
|
+
readonly details: string;
|
|
3741
|
+
/** The underlying cause, if any. */
|
|
3742
|
+
readonly cause?: Error;
|
|
3743
|
+
constructor(message: string, code?: string, details?: string, cause?: Error);
|
|
3744
|
+
}
|
|
3745
|
+
/**
|
|
3746
|
+
* Indicates a connection to the Aether gateway failed.
|
|
3747
|
+
*
|
|
3748
|
+
* This includes initial connection failures, network errors, and
|
|
3749
|
+
* disconnection events that cannot be automatically recovered.
|
|
3750
|
+
*/
|
|
3751
|
+
declare class ConnectionError extends AetherError {
|
|
3752
|
+
constructor(message?: string, code?: string, details?: string, cause?: Error);
|
|
3753
|
+
}
|
|
3754
|
+
/**
|
|
3755
|
+
* Indicates the connection was unexpectedly closed.
|
|
3756
|
+
*
|
|
3757
|
+
* This can happen due to network issues, server restarts, or
|
|
3758
|
+
* force disconnect signals from the server.
|
|
3759
|
+
*/
|
|
3760
|
+
declare class ConnectionClosedError extends AetherError {
|
|
3761
|
+
/** Reason for the disconnection. */
|
|
3762
|
+
readonly reason: string;
|
|
3763
|
+
constructor(reason?: string, code?: string, cause?: Error);
|
|
3764
|
+
}
|
|
3765
|
+
/**
|
|
3766
|
+
* Indicates automatic reconnection failed after exhausting all retries.
|
|
3767
|
+
*/
|
|
3768
|
+
declare class ReconnectionError extends AetherError {
|
|
3769
|
+
/** Number of reconnection attempts made. */
|
|
3770
|
+
readonly attempts: number;
|
|
3771
|
+
constructor(attempts: number, cause?: Error);
|
|
3772
|
+
}
|
|
3773
|
+
/**
|
|
3774
|
+
* Indicates authentication failed.
|
|
3775
|
+
*
|
|
3776
|
+
* Maps to gRPC UNAUTHENTICATED status code. Authentication errors
|
|
3777
|
+
* are non-recoverable and will not trigger automatic reconnection.
|
|
3778
|
+
*/
|
|
3779
|
+
declare class AuthenticationError extends AetherError {
|
|
3780
|
+
constructor(message?: string, details?: string, cause?: Error);
|
|
3781
|
+
}
|
|
3782
|
+
/**
|
|
3783
|
+
* Indicates the client lacks permission to perform an operation.
|
|
3784
|
+
*
|
|
3785
|
+
* Maps to gRPC PERMISSION_DENIED status code. Permission errors
|
|
3786
|
+
* are non-recoverable and will not trigger automatic reconnection.
|
|
3787
|
+
*/
|
|
3788
|
+
declare class PermissionDeniedError extends AetherError {
|
|
3789
|
+
constructor(message?: string, details?: string, cause?: Error);
|
|
3790
|
+
}
|
|
3791
|
+
/**
|
|
3792
|
+
* Indicates an identity is already in use.
|
|
3793
|
+
*
|
|
3794
|
+
* In Aether, each agent or unique task identity can only have one active
|
|
3795
|
+
* connection at a time (Connection = Lock paradigm). This error indicates
|
|
3796
|
+
* another client is already connected with the same identity.
|
|
3797
|
+
*
|
|
3798
|
+
* Maps to gRPC ALREADY_EXISTS status code.
|
|
3799
|
+
*/
|
|
3800
|
+
declare class DuplicateIdentityError extends AetherError {
|
|
3801
|
+
/** The conflicting identity string. */
|
|
3802
|
+
readonly identity: string;
|
|
3803
|
+
constructor(identity?: string, details?: string, cause?: Error);
|
|
3804
|
+
}
|
|
3805
|
+
/**
|
|
3806
|
+
* Indicates an operation timed out.
|
|
3807
|
+
*
|
|
3808
|
+
* This can occur during connection attempts, message sends, or
|
|
3809
|
+
* synchronous KV/checkpoint operations.
|
|
3810
|
+
*
|
|
3811
|
+
* Maps to gRPC DEADLINE_EXCEEDED status code.
|
|
3812
|
+
*/
|
|
3813
|
+
declare class TimeoutError extends AetherError {
|
|
3814
|
+
/** The operation that timed out. */
|
|
3815
|
+
readonly operation: string;
|
|
3816
|
+
/** The timeout duration that was exceeded, in seconds. */
|
|
3817
|
+
readonly timeoutSeconds: number;
|
|
3818
|
+
constructor(operation?: string, timeoutSeconds?: number, cause?: Error);
|
|
3819
|
+
}
|
|
3820
|
+
/**
|
|
3821
|
+
* Indicates an invalid argument was provided to an operation.
|
|
3822
|
+
*
|
|
3823
|
+
* Maps to gRPC INVALID_ARGUMENT status code.
|
|
3824
|
+
*/
|
|
3825
|
+
declare class InvalidArgumentError extends AetherError {
|
|
3826
|
+
/** The name of the invalid argument. */
|
|
3827
|
+
readonly argument: string;
|
|
3828
|
+
constructor(message?: string, argument?: string, cause?: Error);
|
|
3829
|
+
}
|
|
3830
|
+
/**
|
|
3831
|
+
* Indicates a requested resource was not found.
|
|
3832
|
+
*
|
|
3833
|
+
* Maps to gRPC NOT_FOUND status code.
|
|
3834
|
+
*/
|
|
3835
|
+
declare class NotFoundError extends AetherError {
|
|
3836
|
+
/** The resource that was not found. */
|
|
3837
|
+
readonly resource: string;
|
|
3838
|
+
constructor(resource?: string, cause?: Error);
|
|
3839
|
+
}
|
|
3840
|
+
/**
|
|
3841
|
+
* Indicates an operation is not implemented by the server.
|
|
3842
|
+
*
|
|
3843
|
+
* Maps to gRPC UNIMPLEMENTED status code.
|
|
3844
|
+
*/
|
|
3845
|
+
declare class UnimplementedError extends AetherError {
|
|
3846
|
+
/** The unimplemented operation name. */
|
|
3847
|
+
readonly operation: string;
|
|
3848
|
+
constructor(operation?: string, cause?: Error);
|
|
3849
|
+
}
|
|
3850
|
+
/**
|
|
3851
|
+
* Indicates an error with message handling.
|
|
3852
|
+
*
|
|
3853
|
+
* This includes serialization errors, invalid message formats,
|
|
3854
|
+
* or protocol violations.
|
|
3855
|
+
*/
|
|
3856
|
+
declare class MessageError extends AetherError {
|
|
3857
|
+
constructor(message?: string, cause?: Error);
|
|
3858
|
+
}
|
|
3859
|
+
/**
|
|
3860
|
+
* Indicates a KV store operation failed.
|
|
3861
|
+
*/
|
|
3862
|
+
declare class KVOperationError extends AetherError {
|
|
3863
|
+
/** The KV operation that failed. */
|
|
3864
|
+
readonly operation: string;
|
|
3865
|
+
/** The key involved in the failed operation. */
|
|
3866
|
+
readonly key: string;
|
|
3867
|
+
constructor(operation?: string, key?: string, cause?: Error);
|
|
3868
|
+
}
|
|
3869
|
+
/**
|
|
3870
|
+
* Indicates a checkpoint operation failed.
|
|
3871
|
+
*/
|
|
3872
|
+
declare class CheckpointError extends AetherError {
|
|
3873
|
+
/** The checkpoint operation that failed. */
|
|
3874
|
+
readonly operation: string;
|
|
3875
|
+
/** The checkpoint key involved. */
|
|
3876
|
+
readonly key: string;
|
|
3877
|
+
constructor(operation?: string, key?: string, cause?: Error);
|
|
3878
|
+
}
|
|
3879
|
+
/**
|
|
3880
|
+
* Checks if an error is recoverable (should trigger reconnection).
|
|
3881
|
+
*
|
|
3882
|
+
* Non-recoverable errors include authentication failures, permission denials,
|
|
3883
|
+
* and other terminal error conditions.
|
|
3884
|
+
*
|
|
3885
|
+
* @param error - The error to check
|
|
3886
|
+
* @returns true if the error is recoverable, false otherwise
|
|
3887
|
+
*/
|
|
3888
|
+
declare function isRecoverable(error: Error): boolean;
|
|
3889
|
+
/**
|
|
3890
|
+
* Checks if an error is a connection-related error.
|
|
3891
|
+
*
|
|
3892
|
+
* @param error - The error to check
|
|
3893
|
+
* @returns true if the error is connection-related
|
|
3894
|
+
*/
|
|
3895
|
+
declare function isConnectionError(error: Error): boolean;
|
|
3896
|
+
/**
|
|
3897
|
+
* Checks if an error is a timeout-related error.
|
|
3898
|
+
*
|
|
3899
|
+
* @param error - The error to check
|
|
3900
|
+
* @returns true if the error is timeout-related
|
|
3901
|
+
*/
|
|
3902
|
+
declare function isTimeoutError(error: Error): boolean;
|
|
3903
|
+
|
|
3904
|
+
/** Prefix for agent topics. */
|
|
3905
|
+
declare const TOPIC_PREFIX_AGENT = "ag";
|
|
3906
|
+
/** Prefix for unique task topics. */
|
|
3907
|
+
declare const TOPIC_PREFIX_UNIQUE_TASK = "tu";
|
|
3908
|
+
/** Prefix for non-unique task topics. */
|
|
3909
|
+
declare const TOPIC_PREFIX_TASK = "ta";
|
|
3910
|
+
/** Prefix for task broadcast topics. */
|
|
3911
|
+
declare const TOPIC_PREFIX_TASK_BROADCAST = "tb";
|
|
3912
|
+
/** Prefix for user session topics. */
|
|
3913
|
+
declare const TOPIC_PREFIX_USER = "us";
|
|
3914
|
+
/** Prefix for user workspace topics. */
|
|
3915
|
+
declare const TOPIC_PREFIX_USER_WORKSPACE = "uw";
|
|
3916
|
+
/** Prefix for global agent broadcast topics. */
|
|
3917
|
+
declare const TOPIC_PREFIX_GLOBAL_AGENTS = "ga";
|
|
3918
|
+
/** Prefix for global user broadcast topics. */
|
|
3919
|
+
declare const TOPIC_PREFIX_GLOBAL_USERS = "gu";
|
|
3920
|
+
/** Prefix for event topics (workflow engine). */
|
|
3921
|
+
declare const TOPIC_PREFIX_EVENT = "event";
|
|
3922
|
+
/** Prefix for metric topics (metrics bridge). */
|
|
3923
|
+
declare const TOPIC_PREFIX_METRIC = "metric";
|
|
3924
|
+
/** Prefix for progress stream topics. */
|
|
3925
|
+
declare const TOPIC_PREFIX_PROGRESS = "pg";
|
|
3926
|
+
/** Prefix for bridge topics. */
|
|
3927
|
+
declare const TOPIC_PREFIX_BRIDGE = "br";
|
|
3928
|
+
/**
|
|
3929
|
+
* Creates a topic string for a specific agent.
|
|
3930
|
+
*
|
|
3931
|
+
* @param workspace - The agent's workspace
|
|
3932
|
+
* @param implementation - The agent's implementation type
|
|
3933
|
+
* @param specifier - The agent's unique specifier
|
|
3934
|
+
* @returns Topic string in format: ag::{workspace}::{implementation}::{specifier}
|
|
3935
|
+
*
|
|
3936
|
+
* @example
|
|
3937
|
+
* ```typescript
|
|
3938
|
+
* const topic = agentTopic("prod", "data-processor", "instance-1");
|
|
3939
|
+
* // Returns: "ag::prod::data-processor::instance-1"
|
|
3940
|
+
* ```
|
|
3941
|
+
*/
|
|
3942
|
+
declare function agentTopic(workspace: string, implementation: string, specifier: string): string;
|
|
3943
|
+
/**
|
|
3944
|
+
* Creates a broadcast topic for all agents in a workspace.
|
|
3945
|
+
*
|
|
3946
|
+
* @param workspace - The workspace to broadcast to
|
|
3947
|
+
* @returns Topic string in format: ga::{workspace}
|
|
3948
|
+
*/
|
|
3949
|
+
declare function globalAgentsTopic(workspace: string): string;
|
|
3950
|
+
/**
|
|
3951
|
+
* Creates a topic string for a unique (named) task.
|
|
3952
|
+
*
|
|
3953
|
+
* @param workspace - The task's workspace
|
|
3954
|
+
* @param implementation - The task's implementation type
|
|
3955
|
+
* @param specifier - The task's unique specifier
|
|
3956
|
+
* @returns Topic string in format: tu::{workspace}::{implementation}::{specifier}
|
|
3957
|
+
*/
|
|
3958
|
+
declare function uniqueTaskTopic(workspace: string, implementation: string, specifier: string): string;
|
|
3959
|
+
/**
|
|
3960
|
+
* Creates a topic string for a non-unique task instance.
|
|
3961
|
+
*
|
|
3962
|
+
* @param workspace - The task's workspace
|
|
3963
|
+
* @param implementation - The task's implementation type
|
|
3964
|
+
* @param id - The server-assigned task instance ID
|
|
3965
|
+
* @returns Topic string in format: ta::{workspace}::{implementation}::{id}
|
|
3966
|
+
*/
|
|
3967
|
+
declare function taskTopic(workspace: string, implementation: string, id: string): string;
|
|
3968
|
+
/**
|
|
3969
|
+
* Creates a broadcast topic for task load balancing.
|
|
3970
|
+
*
|
|
3971
|
+
* Non-unique tasks subscribe to this topic to receive work items that can
|
|
3972
|
+
* be claimed by any available worker of that implementation type.
|
|
3973
|
+
*
|
|
3974
|
+
* @param workspace - The task's workspace
|
|
3975
|
+
* @param implementation - The task's implementation type
|
|
3976
|
+
* @returns Topic string in format: tb::{workspace}::{implementation}
|
|
3977
|
+
*/
|
|
3978
|
+
declare function taskBroadcastTopic(workspace: string, implementation: string): string;
|
|
3979
|
+
/**
|
|
3980
|
+
* Creates a topic string for a user session.
|
|
3981
|
+
*
|
|
3982
|
+
* @param userId - The user's unique identifier
|
|
3983
|
+
* @param windowId - The window/session identifier
|
|
3984
|
+
* @returns Topic string in format: us::{userId}::{windowId}
|
|
3985
|
+
*/
|
|
3986
|
+
declare function userTopic(userId: string, windowId: string): string;
|
|
3987
|
+
/**
|
|
3988
|
+
* Creates a topic string for user workspace messages.
|
|
3989
|
+
*
|
|
3990
|
+
* Messages sent to this topic reach a specific user regardless of which
|
|
3991
|
+
* window/tab they are using.
|
|
3992
|
+
*
|
|
3993
|
+
* @param userId - The user's unique identifier
|
|
3994
|
+
* @param workspace - The workspace
|
|
3995
|
+
* @returns Topic string in format: uw::{userId}::{workspace}
|
|
3996
|
+
*/
|
|
3997
|
+
declare function userWorkspaceTopic(userId: string, workspace: string): string;
|
|
3998
|
+
/**
|
|
3999
|
+
* Creates a broadcast topic for all users in a workspace.
|
|
4000
|
+
*
|
|
4001
|
+
* @param workspace - The workspace to broadcast to
|
|
4002
|
+
* @returns Topic string in format: gu::{workspace}
|
|
4003
|
+
*/
|
|
4004
|
+
declare function globalUsersTopic(workspace: string): string;
|
|
4005
|
+
/**
|
|
4006
|
+
* Creates a topic string for broadcast events.
|
|
4007
|
+
*
|
|
4008
|
+
* @param eventType - The event type identifier
|
|
4009
|
+
* @returns Topic string in format: event::{eventType}
|
|
4010
|
+
*/
|
|
4011
|
+
declare function eventTopic(eventType: string): string;
|
|
4012
|
+
/**
|
|
4013
|
+
* Returns the wildcard pattern for all events.
|
|
4014
|
+
*
|
|
4015
|
+
* This is the topic that Workflow Engines subscribe to.
|
|
4016
|
+
*
|
|
4017
|
+
* @returns "event::*"
|
|
4018
|
+
*/
|
|
4019
|
+
declare function eventWildcardTopic(): string;
|
|
4020
|
+
/**
|
|
4021
|
+
* Creates a topic string for telemetry/metrics.
|
|
4022
|
+
*
|
|
4023
|
+
* @param metricType - The metric type identifier
|
|
4024
|
+
* @returns Topic string in format: metric::{metricType}
|
|
4025
|
+
*/
|
|
4026
|
+
declare function metricTopic(metricType: string): string;
|
|
4027
|
+
/**
|
|
4028
|
+
* Returns the wildcard pattern for all metrics.
|
|
4029
|
+
*
|
|
4030
|
+
* This is the topic that Metrics Bridges subscribe to.
|
|
4031
|
+
*
|
|
4032
|
+
* @returns "metric::*"
|
|
4033
|
+
*/
|
|
4034
|
+
declare function metricWildcardTopic(): string;
|
|
4035
|
+
/**
|
|
4036
|
+
* Creates a topic string for workspace progress updates.
|
|
4037
|
+
*
|
|
4038
|
+
* Progress updates from agents and tasks in a workspace are published to this
|
|
4039
|
+
* topic. Users and agents subscribe to it with server-side recipient filtering.
|
|
4040
|
+
*
|
|
4041
|
+
* @param workspace - The workspace
|
|
4042
|
+
* @returns Topic string in format: pg::{workspace}
|
|
4043
|
+
*/
|
|
4044
|
+
declare function progressTopic(workspace: string): string;
|
|
4045
|
+
/**
|
|
4046
|
+
* Creates a topic string for a specific bridge instance.
|
|
4047
|
+
*
|
|
4048
|
+
* Bridges are cross-workspace principals identified only by implementation
|
|
4049
|
+
* and specifier (no workspace component).
|
|
4050
|
+
*
|
|
4051
|
+
* @param implementation - The bridge implementation type (e.g., "aether-msgbridge")
|
|
4052
|
+
* @param specifier - The bridge's unique specifier (e.g., "discord-1")
|
|
4053
|
+
* @returns Topic string in format: br::{implementation}::{specifier}
|
|
4054
|
+
*
|
|
4055
|
+
* @example
|
|
4056
|
+
* ```typescript
|
|
4057
|
+
* const topic = bridgeTopic("aether-msgbridge", "discord-1");
|
|
4058
|
+
* // Returns: "br::aether-msgbridge::discord-1"
|
|
4059
|
+
* ```
|
|
4060
|
+
*/
|
|
4061
|
+
declare function bridgeTopic(implementation: string, specifier: string): string;
|
|
4062
|
+
|
|
4063
|
+
export { type ACLResponse, type ACLResponseHandler, AdminClient, type AdminQueryResponse, type AdminQueryResponseHandler, type AdminTimeoutOptions, AetherClient, type AetherClientOptions, AetherError, AetherFetchTransport, AgentClient, type AgentClientOptions, type AgentResponse, type AgentResponseHandler, type AuditSubmitResponse, type AuditSubmitResponseHandler, AuthenticationError, type AuthorityCacheClient, AuthorityGrantCache, type AuthorityGrantCacheOptions, type AuthorityGrantInfo, type AuthorityGrantPrincipalRef, type AuthorityGrantResourceScope, type AuthorityGrantResponse, type AuthorityGrantResponseHandler, type AuthorityGrantRevocation, type AuthorityGrantRevocationHandler, BaseOrchestrator, type BaseOrchestratorOptions, BridgeClient, type BridgeClientOptions, CheckpointClient, type CheckpointDeleteOptions, CheckpointError, type CheckpointListOptions, type CheckpointLoadOptions, type CheckpointResponse, type CheckpointResponseHandler, type CheckpointSaveOptions, type ConfigHandler, type ConfigSnapshot, type ConnectHandler, type ConnectionAck, ConnectionClosedError, ConnectionError, type ConnectionOptions, type CreateACLRuleOptions, type CreateTaskOptions, type CreateTokenOptions, type CreateWorkspaceOptions, type Credentials, type DeleteACLRuleOptions, type DeleteWorkspaceOptions, type DisconnectHandler, type DisconnectSessionOptions, DuplicateIdentityError, type ErrorHandler, type ErrorResponse, type GetAgentOptions, type IncomingMessage, InvalidArgumentError, KVClient, type KVDecrementIfOptions, type KVDecrementOptions, type KVDeleteOptions, type KVGetOptions, type KVIncrementIfOptions, type KVIncrementOptions, type KVListOptions, KVOperationError, type KVPutOptions, type KVResponse, type KVResponseHandler, KVScope, type ListACLRulesOptions, type ListAgentsOptions, type ListConnectionsOptions, type ListTokensOptions, type ListWorkspacesOptions, MessageError, type MessageHandler, MessageType, type Metric, MetricBuilder, type MetricEntry, MetricsBridgeClient, type MetricsBridgeClientOptions, NotFoundError, OrchestratorClient, type OrchestratorClientOptions, type OutgoingMessage, PermissionDeniedError, PrincipalType, type ProgressHandler, type ProgressStep, type ProgressUpdate, type ProxyError, ProxyErrorKind, ProxyHttpError, type ProxyHttpOptions, type ProxyHttpResponse, type ReconnectingHandler, ReconnectionError, type ReportProgressOptions, type RevokeTokenOptions, type Signal, type SignalHandler, SignalType, type TLSOptions, TOPIC_PREFIX_AGENT, TOPIC_PREFIX_BRIDGE, TOPIC_PREFIX_EVENT, TOPIC_PREFIX_GLOBAL_AGENTS, TOPIC_PREFIX_GLOBAL_USERS, TOPIC_PREFIX_METRIC, TOPIC_PREFIX_PROGRESS, TOPIC_PREFIX_TASK, TOPIC_PREFIX_TASK_BROADCAST, TOPIC_PREFIX_UNIQUE_TASK, TOPIC_PREFIX_USER, TOPIC_PREFIX_USER_WORKSPACE, type TaskAssignment, type TaskAssignmentHandler, TaskAssignmentMode, TaskClient, type TaskClientOptions, type TaskInfo, type TaskOperationResponse, type TaskOperationResponseHandler, type TaskQueryOptions, type TaskQueryResponse, type TaskQueryResponseHandler, TimeoutError, type TokenInfo, type TokenResponse, type TokenResponseHandler, TunnelClosedError, type TunnelDialOptions, type TunnelProtocol, type TunnelStream, UnimplementedError, type UpdateWorkspaceOptions, UserClient, type UserClientOptions, WorkflowEngineClient, type WorkflowEngineClientOptions, type WorkflowResponse, type WorkflowResponseHandler, type WorkspaceResponse, type WorkspaceResponseHandler, agentTopic, bridgeTopic, eventTopic, eventWildcardTopic, globalAgentsTopic, globalUsersTopic, isConnectionError, isRecoverable, isTimeoutError, metricTopic, metricWildcardTopic, newMetric, progressTopic, proxyHttp, taskBroadcastTopic, taskTopic, tunnelDial, uniqueTaskTopic, userTopic, userWorkspaceTopic, withAPIKey, withTaskToken, withTenant, withToken };
|