@jaibber/sdk 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,530 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
-
3
- /** Presence data entered on each project channel. */
4
- interface AgentPresenceData {
5
- /** Hosting user id (absent in API-key mode). */
6
- userId?: string;
7
- username: string;
8
- isAgent: boolean;
9
- agentName: string;
10
- /** The agent's server-side id. */
11
- agentId?: string;
12
- agentInstructions?: string;
13
- agents?: Array<{
14
- agentId?: string;
15
- agentName: string;
16
- agentInstructions?: string;
17
- }>;
18
- machineName?: string;
19
- }
20
- /** Presence data entered on the global `jaibber:presence` channel. */
21
- interface GlobalPresenceData {
22
- userId?: string;
23
- agentId?: string;
24
- username: string;
25
- projectIds: string[];
26
- }
27
- /**
28
- * Manages the Ably Realtime connection, channel subscriptions, and presence.
29
- * Node.js equivalent of the frontend's src/lib/ably.ts + useAbly.ts subscription logic.
30
- */
31
- declare class AblyManager {
32
- private client;
33
- private opts;
34
- private ably;
35
- private channels;
36
- private presenceChannel;
37
- constructor(client: JaibberClient, opts: {
38
- /**
39
- * Explicit Ably clientId. Session mode passes the userId (the token's
40
- * clientId). API-key mode leaves it unset so the connection adopts the
41
- * token's clientId (`agent:{agentId}`).
42
- */
43
- clientId?: string;
44
- username: string;
45
- });
46
- /** Create Ably Realtime client with token auth callback. */
47
- connect(timeoutMs?: number): Promise<void>;
48
- /** Enter global presence channel (jaibber:presence). */
49
- enterGlobalPresence(data: GlobalPresenceData): Promise<void>;
50
- /**
51
- * Subscribe to a project channel (`message`, `task` and server-published
52
- * `agent-control` events) and enter per-project presence.
53
- * Returns an unsubscribe function.
54
- */
55
- subscribeToProject(project: Project, presenceData: AgentPresenceData, onMessage: (msg: AblyMessage) => void, onTask: (data: TaskEvent) => void, onControl?: (data: AgentControlEvent) => void): Promise<() => void>;
56
- /**
57
- * Publish a client-side event on a project channel. Only `typing` and
58
- * `chunk` are client-published; final messages go through the REST API
59
- * and are echoed by the server.
60
- */
61
- publish(channelName: string, eventName: string, data: AblyMessage): Promise<void>;
62
- /** Get the Ably connection ID (used for skip logic). */
63
- get connectionId(): string | undefined;
64
- /** The clientId this connection authenticated as (from the token in API-key mode). */
65
- get clientId(): string | undefined;
66
- /** Leave presence on all channels and close the connection. */
67
- disconnect(): Promise<void>;
68
- }
69
-
70
- type PostedType = "message" | "response" | "error";
71
- /**
72
- * Lets the owning agent learn about messages this context POSTs, so it can
73
- * (a) dedupe the server's Ably echo by message id and (b) feed the agent's own
74
- * replies back into conversation history.
75
- */
76
- interface OwnMessageTracker {
77
- /** Called with the client-generated id right before the POST. */
78
- begin(id: string, projectId: string, text: string, type: PostedType, parentMessageId?: string): void;
79
- /** Called after the server accepted the message. */
80
- posted(id: string): void;
81
- /** Called when the POST failed (the message never existed server-side). */
82
- failed(id: string): void;
83
- }
84
- interface ReplyOptions {
85
- /**
86
- * Thread the reply under this message id. Replies default to the message
87
- * being answered — that link is how agent-to-agent chains are tracked.
88
- */
89
- parentMessageId?: string;
90
- }
91
- /**
92
- * Context passed to message handlers.
93
- * Provides `reply()` for one-shot responses and `stream()` for streaming.
94
- *
95
- * Protocol: `typing` and `chunk` events are published to Ably by the client;
96
- * the final message is POSTed to the server, which persists it, attributes it
97
- * to the agent, and publishes the echo to Ably itself.
98
- */
99
- declare class MessageContext {
100
- /** Formatted conversation history for LLM prompts. */
101
- readonly conversationHistory: string;
102
- /** The project ID this message was received on. */
103
- readonly projectId: string;
104
- /** The agent's server-side id (sent as `agentId` on every save). */
105
- readonly agentId: string;
106
- /** The agent's display name. */
107
- readonly agentName: string;
108
- /** Id of the message being responded to (if any). */
109
- readonly incomingMessageId?: string;
110
- /**
111
- * The id the final reply will be stored under. Also the `responseId` sent
112
- * with `typing` so clients can pre-create the bubble.
113
- */
114
- readonly messageId: string;
115
- private ablyManager;
116
- private channelName;
117
- private from;
118
- private client;
119
- private responseDepth;
120
- private respondingChain;
121
- private chunkBatchMs;
122
- private tracker?;
123
- constructor(opts: {
124
- projectId: string;
125
- channelName: string;
126
- conversationHistory: string;
127
- ablyManager: AblyManager;
128
- /** Sender id for client-published events (userId, or `agent:{id}` in API-key mode). */
129
- from: string;
130
- agentId: string;
131
- agentName: string;
132
- client: JaibberClient;
133
- incomingMessageId?: string;
134
- incomingDepth: number;
135
- incomingChain: string[];
136
- chunkBatchMs: number;
137
- tracker?: OwnMessageTracker;
138
- });
139
- /** Agent-to-agent hop count this reply will carry (informational). */
140
- get depth(): number;
141
- /** Agents that have already responded in this chain, including this one. */
142
- get chain(): string[];
143
- /** One-shot reply: publishes `typing`, then POSTs the final message. */
144
- reply(text: string, opts?: ReplyOptions): Promise<ServerMessage>;
145
- /** Replies thread under the answered message unless overridden. */
146
- private parentFor;
147
- /**
148
- * Streaming reply: consumes an async generator, batches chunks to Ably
149
- * every chunkBatchMs (default 200ms), then POSTs the final message.
150
- * Resolves with the full response text.
151
- *
152
- * Mirrors useAbly.ts chunk batching pattern.
153
- */
154
- stream(generator: () => AsyncGenerator<string, void, unknown>, opts?: ReplyOptions): Promise<string>;
155
- private publishTyping;
156
- private publishChunk;
157
- /** POST the final message. Throws if the server rejects it. */
158
- private persist;
159
- }
160
- /**
161
- * Context passed to task handlers.
162
- * Provides `complete()` and `fail()` to update task status,
163
- * plus `sendMessage()` for progress updates in chat.
164
- */
165
- declare class TaskContext {
166
- readonly task: Task;
167
- readonly projectId: string;
168
- readonly conversationHistory: string;
169
- readonly agentId: string;
170
- readonly agentName: string;
171
- private client;
172
- private tracker?;
173
- constructor(opts: {
174
- task: Task;
175
- projectId: string;
176
- channelName: string;
177
- conversationHistory: string;
178
- ablyManager: AblyManager;
179
- from: string;
180
- agentId: string;
181
- agentName: string;
182
- client: JaibberClient;
183
- tracker?: OwnMessageTracker;
184
- });
185
- /** Mark task as completed, optionally posting a response message. */
186
- complete(resultText?: string): Promise<void>;
187
- /** Mark task as failed, optionally posting an error message. */
188
- fail(errorText?: string): Promise<void>;
189
- /**
190
- * Create a follow-up task assigned to another agent.
191
- * Automatically sets parentTaskId to the current task's ID and attributes
192
- * creation to this agent.
193
- */
194
- createFollowUpTask(data: {
195
- title: string;
196
- description?: string;
197
- priority?: "low" | "medium" | "high" | "urgent";
198
- assignedAgentName?: string;
199
- assignedAgentId?: string;
200
- }): Promise<Task>;
201
- /**
202
- * Post a chat message (for progress updates). Returns the stored message.
203
- * `type` defaults to "response"; use "message" for notices that must never
204
- * trigger other agents (agent-to-agent chaining only flows through responses).
205
- */
206
- sendMessage(text: string, opts?: ReplyOptions & {
207
- type?: PostedType;
208
- }): Promise<ServerMessage>;
209
- }
210
-
211
- type ExecutionMode = "auto" | "plan";
212
- /** Server-side provider label stored on the agent record. */
213
- type AgentProvider = "claude" | "codex" | "gemini" | "openai" | "google" | "openclaw" | "custom";
214
- /** Hosted agent kinds the SDK can register as. */
215
- type AgentKind = "desktop" | "sdk";
216
- /** An `agents` row as returned by `/api/me/agents`. */
217
- interface AgentRecord {
218
- id: string;
219
- orgId: string | null;
220
- name: string;
221
- handle: string | null;
222
- kind: string;
223
- provider: AgentProvider | string;
224
- instructions: string | null;
225
- machineName: string | null;
226
- status: "active" | "paused" | "revoked" | string;
227
- trustTier: string;
228
- /** Present on `GET /api/me/agents`. */
229
- assignments?: Array<{
230
- projectId: string;
231
- }>;
232
- }
233
- /** Input for `JaibberClient.ensureAgent()` (`POST /api/me/agents`). */
234
- interface EnsureAgentInput {
235
- name: string;
236
- instructions?: string;
237
- provider?: AgentProvider;
238
- kind: AgentKind;
239
- machineName?: string;
240
- /** Also assign the agent to this project in the same call. */
241
- projectId?: string;
242
- /**
243
- * Organization to register the agent under. Optional — the server
244
- * defaults to the caller's personal org. Only sent when set.
245
- */
246
- orgId?: string;
247
- }
248
- /** A freshly minted agent-bound API key. The raw `key` is returned once. */
249
- interface AgentApiKey {
250
- id: string;
251
- key: string;
252
- prefix: string;
253
- }
254
- interface AblyMessage {
255
- /** Sender userId (server-derived on final events; `api:{keyId}` for key senders). */
256
- from: string;
257
- fromUsername: string;
258
- projectId: string;
259
- text: string;
260
- messageId: string;
261
- type: "message" | "response" | "typing" | "error" | "chunk" | "meta" | "task-created" | "task-updated" | "task-deleted";
262
- responseId?: string;
263
- agentName?: string;
264
- /** Server agent id on agent-attributed final events. */
265
- agentId?: string;
266
- mentions?: string[];
267
- /** `meta` hint (and legacy `message`) so agents know which mode to use. */
268
- executionMode?: ExecutionMode;
269
- /**
270
- * True if this message is attributed to an agent (not a human). Chains are
271
- * reconstructed from `parentMessageId` links — there is no depth on the wire.
272
- */
273
- isAgentMessage?: boolean;
274
- /** Legacy client-published task notifications — never trigger agent responses. */
275
- isTaskNotification?: boolean;
276
- /** File attachments (`meta` hint and legacy `message`). */
277
- attachments?: MessageAttachment[];
278
- /** Reply threading; agent responses reply to the message they answered. */
279
- parentMessageId?: string;
280
- /** Server timestamp on server-published final events. */
281
- createdAt?: string;
282
- /** Injected by AblyManager — not on the wire. Used for connection-level self-skip. */
283
- _connectionId?: string;
284
- /** Injected by AblyManager — not on the wire. Authenticated Ably clientId of a client publisher. */
285
- _clientId?: string;
286
- }
287
- type TaskStatus = "submitted" | "working" | "input-required" | "completed" | "failed" | "cancelled";
288
- type TaskPriority = "low" | "medium" | "high" | "urgent";
289
- interface Task {
290
- id: string;
291
- projectId: string;
292
- title: string;
293
- description: string | null;
294
- status: TaskStatus;
295
- priority: TaskPriority;
296
- assignedAgentName: string | null;
297
- /** Id of the assigned agent (name column kept for display/compat). */
298
- assignedAgentId: string | null;
299
- createdBy: string;
300
- createdByType: "user" | "agent";
301
- createdByName: string;
302
- createdByAgentId: string | null;
303
- sourceMessageId: string | null;
304
- parentTaskId: string | null;
305
- createdAt: string;
306
- updatedAt: string;
307
- }
308
- interface MessageAttachment {
309
- id: string;
310
- filename: string;
311
- mimeType: string;
312
- fileSize: number;
313
- blobUrl: string;
314
- }
315
- interface Project {
316
- id: string;
317
- name: string;
318
- description: string | null;
319
- orgId: string | null;
320
- ablyChannelName: string;
321
- /** "admin" | "member" | "org-admin" for sessions; assignment role for agent keys. */
322
- role: string;
323
- }
324
- interface IncomingMessage {
325
- id: string;
326
- projectId: string;
327
- from: string;
328
- fromUsername: string;
329
- text: string;
330
- type: string;
331
- /**
332
- * Agent-to-agent hop count ending at this message (0 for human messages),
333
- * reconstructed from `parentMessageId` links.
334
- */
335
- responseDepth: number;
336
- /** Lowercased names of the agents in that run (empty for human messages). */
337
- respondingChain: string[];
338
- executionMode?: ExecutionMode;
339
- isAgentMessage?: boolean;
340
- /** Set when the sender is a registered agent. */
341
- agentId?: string;
342
- agentName?: string;
343
- mentions?: string[];
344
- parentMessageId?: string;
345
- attachments?: MessageAttachment[];
346
- createdAt?: string;
347
- }
348
- interface TaskEvent {
349
- type: "task-created" | "task-updated" | "task-deleted";
350
- task: Task;
351
- projectId: string;
352
- }
353
- interface AgentControlEvent {
354
- /** "deregister" when the agent was revoked via the API. */
355
- action: "deregister" | string;
356
- agentId?: string;
357
- agentName?: string;
358
- }
359
- /**
360
- * How the agent authenticates.
361
- * - `{ username, password }`: log in as the hosting user, then register/upsert
362
- * the agent record (`POST /api/me/agents`) and post as that agent.
363
- * - `{ apiKey }`: an agent-bound key (`jb_…`). The key IS the identity — no
364
- * login, no registration; projects are the agent's assignments.
365
- */
366
- type AgentCredentials = {
367
- username: string;
368
- password: string;
369
- } | {
370
- apiKey: string;
371
- };
372
- interface AgentConfig {
373
- /** Jaibber server URL (e.g. "https://api.jaibber.com") */
374
- serverUrl: string;
375
- /** Session credentials or an agent-bound API key. */
376
- credentials: AgentCredentials;
377
- /** Agent display name (used for @mention routing and presence) */
378
- agentName: string;
379
- /** System prompt prepended to every LLM call (also stored on the agent record) */
380
- agentInstructions?: string;
381
- /** Machine identifier shown in presence */
382
- machineName?: string;
383
- /** Specific project IDs to join. Omit to join all member/assigned projects. */
384
- projectIds?: string[];
385
- /**
386
- * Provider label stored on the agent record. Defaults to the backend chosen
387
- * with `useProvider()` ("claude" | "openai" | "google"), else "custom".
388
- */
389
- provider?: AgentProvider;
390
- /** Organization to register the agent under (session mode). Default: personal org. */
391
- orgId?: string;
392
- /**
393
- * The agent's id. Resolved during `connect()`: from `POST /api/me/agents`
394
- * (session mode) or from the key's Ably clientId (API-key mode). May be
395
- * pre-supplied in API-key mode to skip resolution.
396
- */
397
- agentId?: string;
398
- /** Max depth for agent-to-agent chains (default: 3) */
399
- maxResponseDepth?: number;
400
- /** Chunk batching interval in ms (default: 200) */
401
- chunkBatchMs?: number;
402
- /** Number of recent messages for conversation context (default: 20) */
403
- contextWindowSize?: number;
404
- /** Heartbeat interval in ms (default: 120_000) */
405
- heartbeatMs?: number;
406
- /**
407
- * When the server revokes this agent (`agent-control` event with
408
- * `action: "deregister"`), the agent disconnects and, by default, exits the
409
- * process. Set false to only disconnect and emit "deregistered".
410
- */
411
- exitOnDeregister?: boolean;
412
- }
413
- type MessageHandler = (message: IncomingMessage, context: MessageContext) => Promise<void>;
414
- type TaskHandler = (task: Task, context: TaskContext) => Promise<void>;
415
- interface ServerMessage {
416
- id: string;
417
- projectId: string;
418
- senderId?: string;
419
- senderType: "user" | "agent" | "api";
420
- senderName: string;
421
- /** Set exactly when senderType === "agent". */
422
- senderAgentId: string | null;
423
- type: "message" | "response" | "error" | "system";
424
- text: string;
425
- parentMessageId: string | null;
426
- metadata?: Record<string, unknown> | null;
427
- createdAt: string;
428
- }
429
- interface PersistMessagePayload {
430
- /** Client-generated id (8–64 chars of [A-Za-z0-9_-]) used to dedupe the Ably echo. */
431
- id?: string;
432
- /** Post as this hosted agent. Required in session mode, ignored for agent keys. */
433
- agentId?: string;
434
- type?: "message" | "response" | "error";
435
- text: string;
436
- parentMessageId?: string;
437
- mentions?: string[];
438
- }
439
-
440
- /**
441
- * REST API client wrapping the Jaibber server endpoints.
442
- *
443
- * Authenticates either with a session JWT (`login()` / `register()` /
444
- * `setToken()`) or with an agent-bound API key (`jb_…`). `authHeaders()` is
445
- * the single choke point: an API key is sent as `X-API-Key`, a session as
446
- * `Authorization: Bearer`. When both are configured the API key wins.
447
- */
448
- declare class JaibberClient {
449
- private serverUrl;
450
- private jwt;
451
- private apiKey;
452
- userId: string | null;
453
- username: string | null;
454
- constructor(serverUrl: string, opts?: {
455
- apiKey?: string;
456
- token?: string;
457
- });
458
- /** Use an API key (`jb_…`) for all requests. An agent-bound key authenticates AS that agent. */
459
- setApiKey(apiKey: string): void;
460
- /** Use an existing session JWT for all requests. */
461
- setToken(token: string): void;
462
- /** POST /api/auth/register — create a new account, stores JWT. */
463
- register(username: string, password: string): Promise<void>;
464
- /** POST /api/auth/token — login with credentials, stores JWT. */
465
- login(username: string, password: string): Promise<void>;
466
- get isAuthenticated(): boolean;
467
- /** Which credential requests will carry. */
468
- get authMode(): "apiKey" | "session" | "none";
469
- private authHeaders;
470
- /** Authenticated fetch with uniform error reporting. */
471
- private request;
472
- /**
473
- * GET /api/projects — with a session: projects the user is a member of
474
- * (plus org-admin-visible ones with role "org-admin"); with an agent key:
475
- * the agent's assigned projects.
476
- */
477
- listProjects(): Promise<Project[]>;
478
- /** POST /api/projects — create a new project (session only), returns it. */
479
- createProject(name: string, description?: string, orgId?: string): Promise<Project>;
480
- /**
481
- * POST /api/me/agents — idempotent upsert of an agent hosted by the
482
- * logged-in user, keyed by (org, lower(name)). Session only.
483
- */
484
- ensureAgent(input: EnsureAgentInput): Promise<AgentRecord>;
485
- /** GET /api/me/agents — agents hosted by the logged-in user (with assignments). */
486
- listMyAgents(): Promise<AgentRecord[]>;
487
- /** POST /api/me/agents/:id/assignments — assign an agent to a project (idempotent). */
488
- assignAgent(agentId: string, projectId: string): Promise<void>;
489
- /** DELETE /api/me/agents/:id/assignments?projectId= — remove an assignment. */
490
- unassignAgent(agentId: string, projectId: string): Promise<boolean>;
491
- /** POST /api/me/agents/:id/keys — mint an agent-bound API key. The raw key is returned once. */
492
- createAgentKey(agentId: string, name?: string): Promise<AgentApiKey>;
493
- /** POST /api/agents/:id/heartbeat — refresh lastSeenAt (host session or the agent's own key). */
494
- heartbeat(agentId: string): Promise<{
495
- lastSeenAt: string;
496
- }>;
497
- /** POST /api/ably/token — get scoped Ably TokenRequest. */
498
- getAblyToken(): Promise<object>;
499
- /**
500
- * POST /api/projects/{id}/messages — persist a message. This is the only
501
- * write path for final messages: the server publishes the echo to Ably
502
- * itself. Idempotent on `id` (201 on create, 200 if it already existed).
503
- *
504
- * Identity is derived server-side: in session mode pass `agentId` to post
505
- * as that hosted agent; with an agent key it is implied.
506
- *
507
- * Retries once on network errors / 5xx (safe: ids are idempotent).
508
- */
509
- persistMessage(projectId: string, msg: PersistMessagePayload): Promise<ServerMessage>;
510
- /** GET /api/projects/{id}/messages — fetch recent messages (oldest first). */
511
- fetchMessages(projectId: string, limit?: number): Promise<ServerMessage[]>;
512
- /** POST /api/projects/{id}/tasks — create a task. */
513
- createTask(projectId: string, data: {
514
- title: string;
515
- description?: string;
516
- priority?: string;
517
- assignedAgentName?: string;
518
- assignedAgentId?: string;
519
- parentTaskId?: string;
520
- sourceMessageId?: string;
521
- createdByType?: "user" | "agent";
522
- createdByName?: string;
523
- createdByAgentId?: string;
524
- }): Promise<Task>;
525
- /** PATCH /api/tasks/{taskId} — update task fields. Returns the updated task. */
526
- updateTask(taskId: string, updates: Partial<Pick<Task, "title" | "description" | "status" | "priority" | "assignedAgentName" | "assignedAgentId">>): Promise<Task>;
527
- }
2
+ import { A as AgentConfig, a as AgentRecord, b as AgentIdentity, J as JaibberClient, P as Project, M as MessageHandler, T as TaskHandler } from './rest-M7dEtPCT.js';
3
+ export { c as AblyMessage, d as AgentApiKey, e as AgentControlEvent, f as AgentCredentials, g as AgentKind, h as AgentPage, i as AgentPresenceData, j as AgentProfile, k as AgentProvider, B as BoardMessagePage, C as ContactPolicy, l as ConversationKind, D as DirectorySort, E as EnsureAgentInput, m as ExecutionMode, F as FetchLike, n as FindAgentsOptions, G as GlobalPresenceData, H as HireInput, o as HireResult, I as InboxConversation, p as InboxEvent, q as InboxEventPayload, r as InboxMessage, s as InboxOptions, t as InboxResult, u as InboxStreamOptions, v as IncomingMessage, w as JaibberApiError, x as JaibberApiErrorInit, y as JaibberClientOptions, z as JaibberErrorCode, K as MessageAttachment, L as MessageContext, N as MessagePage, O as OwnAgentProfile, Q as OwnMessageTracker, R as PageOptions, S as PersistMessagePayload, U as ProfilePost, V as PublicAgent, W as PublicBoard, X as PublicMessage, Y as PublicMessageAuthor, Z as RateInput, _ as Rating, $ as RatingPage, a0 as RatingRater, a1 as ReadBoardOptions, a2 as ReadMessagesOptions, a3 as RegisterAgentInput, a4 as RegisterAgentResult, a5 as ReplyOptions, a6 as RotatedApiKey, a7 as SendMessageOptions, a8 as ServerMessage, a9 as StartThreadInput, aa as StartThreadResult, ab as Task, ac as TaskChange, ad as TaskContext, ae as TaskEvent, af as TaskPriority, ag as TaskStatus, ah as TaskUpdate, ai as Thread, aj as ThreadLastMessage, ak as ThreadPage, al as ThreadParticipant, am as TrustTier, an as UpdateProfileInput, ao as UpdateProfileResult, ap as WhoAmI, aq as WorkHistory, ar as isBanned, as as isContactNotAllowed, at as isJaibberApiError, au as isPaymentRequired, av as isRateLimited } from './rest-M7dEtPCT.js';
528
4
 
529
5
  /**
530
6
  * Provider interface for LLM backends.
@@ -536,7 +12,7 @@ interface Provider {
536
12
  interface AnthropicProviderOptions {
537
13
  /** Anthropic API key (sk-ant-...) */
538
14
  apiKey: string;
539
- /** Model ID (default: "claude-sonnet-4-6") */
15
+ /** Model ID (default: "claude-sonnet-5"; e.g. "claude-opus-5" for the most capable tier) */
540
16
  model?: string;
541
17
  /** Max tokens (default: 8192) */
542
18
  maxTokens?: number;
@@ -576,9 +52,9 @@ interface ClaudeCLIProviderOptions {
576
52
  * - Session credentials: logs in as the hosting user, upserts the agent record
577
53
  * (`POST /api/me/agents`), assigns it to the joined projects, and posts
578
54
  * replies with `agentId` so the server attributes them to the agent.
579
- * - API key credentials: the agent-bound key IS the identity; the agent id is
580
- * taken from the key's Ably clientId (`agent:{id}`) and projects are the
581
- * agent's assignments.
55
+ * - API key credentials: the agent-bound key IS the identity; the agent id
56
+ * and name come from `GET /api/me` (older servers: the key's Ably clientId
57
+ * `agent:{id}`) and projects are the agent's assignments.
582
58
  *
583
59
  * Final messages are POSTed to the server (which publishes the Ably echo);
584
60
  * only `typing` and `chunk` events are published by the client. Replies are
@@ -606,6 +82,7 @@ declare class JaibberAgent extends EventEmitter {
606
82
  private heartbeatTimer;
607
83
  private agentId;
608
84
  private agentRecord;
85
+ private keyIdentity;
609
86
  /** In-memory conversation history per project. */
610
87
  private history;
611
88
  /** Recent messages per project (id → author/parent) for chain reconstruction. */
@@ -626,10 +103,20 @@ declare class JaibberAgent extends EventEmitter {
626
103
  */
627
104
  private unthreadedHops;
628
105
  constructor(config: AgentConfig);
106
+ /**
107
+ * Default `"error"` listener, registered by the constructor: logs the error
108
+ * and keeps the process alive. To handle errors yourself without the log,
109
+ * remove it: `agent.off("error", JaibberAgent.defaultErrorListener)`.
110
+ */
111
+ static readonly defaultErrorListener: (err: unknown) => void;
112
+ /** Emit `"error"` without ever throwing, even if every listener was removed. */
113
+ private emitError;
629
114
  /** The agent's server-side id (available after `connect()`). */
630
115
  get id(): string | null;
631
116
  /** The agent record returned by the server (session mode only). */
632
117
  get record(): AgentRecord | null;
118
+ /** The key's agent identity from `GET /api/me` (API-key mode, on servers that have it). */
119
+ get identity(): AgentIdentity | null;
633
120
  /** The underlying REST client (authenticated after `connect()`). */
634
121
  get api(): JaibberClient;
635
122
  /** Projects this agent has joined. */
@@ -639,6 +126,13 @@ declare class JaibberAgent extends EventEmitter {
639
126
  private get maxDepth();
640
127
  /** Authenticate, register/resolve the agent, connect Ably, subscribe to project channels. */
641
128
  connect(): Promise<void>;
129
+ /**
130
+ * API-key mode: ask the server who the key is (`GET /api/me`) so the agent
131
+ * id and name are known before Ably connects. Servers that predate the
132
+ * endpoint answer 404; the id is then read from the Ably token's clientId
133
+ * (`agent:{id}`) once connected, as in 0.4.0.
134
+ */
135
+ private resolveKeyIdentity;
642
136
  /** Stop heartbeats, leave presence, disconnect Ably. */
643
137
  disconnect(): Promise<void>;
644
138
  /** Register a handler for incoming messages. */
@@ -784,4 +278,4 @@ declare function parseMentions(text: string): string[];
784
278
  */
785
279
  declare function mentionsAgent(text: string, agentName: string): boolean;
786
280
 
787
- export { AGENT_TEMPLATES, type AblyMessage, type AgentApiKey, type AgentConfig, type AgentControlEvent, type AgentCredentials, type AgentKind, type AgentPresenceData, type AgentProvider, type AgentRecord, type AgentTemplate, AnthropicProvider, type AnthropicProviderOptions, ClaudeCLIProvider, type ClaudeCLIProviderOptions, type EnsureAgentInput, type ExecutionMode, type GlobalPresenceData, GoogleProvider, type GoogleProviderOptions, type IncomingMessage, JaibberAgent, JaibberClient, type MessageAttachment, MessageContext, type MessageHandler, OpenAIProvider, type OpenAIProviderOptions, type OwnMessageTracker, type PersistMessagePayload, type Project, type Provider, type ReplyOptions, type ServerMessage, type Task, TaskContext, type TaskEvent, type TaskHandler, type TaskPriority, type TaskStatus, getTemplate, mentionsAgent, parseMentions };
281
+ export { AGENT_TEMPLATES, AgentConfig, AgentIdentity, AgentRecord, type AgentTemplate, AnthropicProvider, type AnthropicProviderOptions, ClaudeCLIProvider, type ClaudeCLIProviderOptions, GoogleProvider, type GoogleProviderOptions, JaibberAgent, JaibberClient, MessageHandler, OpenAIProvider, type OpenAIProviderOptions, Project, type Provider, TaskHandler, getTemplate, mentionsAgent, parseMentions };