@starcite/sdk 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -182
- package/dist/index.cjs +1642 -615
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +594 -203
- package/dist/index.d.ts +594 -203
- package/dist/index.js +1620 -611
- package/dist/index.js.map +1 -1
- package/package.json +15 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,60 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
id: z.
|
|
8
|
-
|
|
9
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
10
|
-
creator_principal: z.ZodOptional<z.ZodObject<{
|
|
11
|
-
tenant_id: z.ZodString;
|
|
12
|
-
id: z.ZodString;
|
|
13
|
-
type: z.ZodUnion<[z.ZodLiteral<"user">, z.ZodLiteral<"agent">]>;
|
|
14
|
-
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
type: "user" | "agent";
|
|
16
|
-
tenant_id: string;
|
|
17
|
-
id: string;
|
|
18
|
-
}, {
|
|
19
|
-
type: "user" | "agent";
|
|
20
|
-
tenant_id: string;
|
|
21
|
-
id: string;
|
|
22
|
-
}>>;
|
|
3
|
+
declare const PrincipalTypeSchema: z.ZodEnum<["user", "agent"]>;
|
|
4
|
+
type PrincipalType = z.infer<typeof PrincipalTypeSchema>;
|
|
5
|
+
declare const SessionCreatorPrincipalSchema: z.ZodObject<{
|
|
6
|
+
tenant_id: z.ZodString;
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
type: z.ZodEnum<["user", "agent"]>;
|
|
23
9
|
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
creator_principal?: {
|
|
28
|
-
type: "user" | "agent";
|
|
29
|
-
tenant_id: string;
|
|
30
|
-
id: string;
|
|
31
|
-
} | undefined;
|
|
10
|
+
type: "user" | "agent";
|
|
11
|
+
tenant_id: string;
|
|
12
|
+
id: string;
|
|
32
13
|
}, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
creator_principal?: {
|
|
37
|
-
type: "user" | "agent";
|
|
38
|
-
tenant_id: string;
|
|
39
|
-
id: string;
|
|
40
|
-
} | undefined;
|
|
14
|
+
type: "user" | "agent";
|
|
15
|
+
tenant_id: string;
|
|
16
|
+
id: string;
|
|
41
17
|
}>;
|
|
18
|
+
type SessionCreatorPrincipal = z.infer<typeof SessionCreatorPrincipalSchema>;
|
|
19
|
+
declare const SessionTokenPrincipalSchema: z.ZodObject<{
|
|
20
|
+
type: z.ZodEnum<["user", "agent"]>;
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
type: "user" | "agent";
|
|
24
|
+
id: string;
|
|
25
|
+
}, {
|
|
26
|
+
type: "user" | "agent";
|
|
27
|
+
id: string;
|
|
28
|
+
}>;
|
|
29
|
+
type SessionTokenPrincipal = z.infer<typeof SessionTokenPrincipalSchema>;
|
|
42
30
|
/**
|
|
43
|
-
*
|
|
31
|
+
* Represents a resolved caller identity with tenant, principal id, and type.
|
|
44
32
|
*/
|
|
45
|
-
|
|
33
|
+
declare class StarciteIdentity {
|
|
34
|
+
readonly tenantId: string;
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly type: PrincipalType;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
tenantId: string;
|
|
39
|
+
id: string;
|
|
40
|
+
type: PrincipalType;
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Serializes to the `creator_principal` wire format expected by the API.
|
|
44
|
+
*/
|
|
45
|
+
toCreatorPrincipal(): SessionCreatorPrincipal;
|
|
46
|
+
/**
|
|
47
|
+
* Serializes to the `principal` wire format used in session token requests.
|
|
48
|
+
*/
|
|
49
|
+
toTokenPrincipal(): SessionTokenPrincipal;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the actor string derived from this identity (e.g. `agent:planner`, `user:alice`).
|
|
52
|
+
*/
|
|
53
|
+
toActor(): string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare const SessionTokenScopeSchema: z.ZodEnum<["session:read", "session:append"]>;
|
|
57
|
+
type SessionTokenScope = z.infer<typeof SessionTokenScopeSchema>;
|
|
46
58
|
/**
|
|
47
59
|
* Session record returned by the Starcite API.
|
|
48
60
|
*/
|
|
@@ -143,7 +155,7 @@ type SessionListPage = z.infer<typeof SessionListPageSchema>;
|
|
|
143
155
|
declare const AppendEventRequestSchema: z.ZodObject<{
|
|
144
156
|
type: z.ZodString;
|
|
145
157
|
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
146
|
-
actor: z.ZodString
|
|
158
|
+
actor: z.ZodOptional<z.ZodString>;
|
|
147
159
|
producer_id: z.ZodString;
|
|
148
160
|
producer_seq: z.ZodNumber;
|
|
149
161
|
source: z.ZodOptional<z.ZodString>;
|
|
@@ -154,10 +166,10 @@ declare const AppendEventRequestSchema: z.ZodObject<{
|
|
|
154
166
|
}, "strip", z.ZodTypeAny, {
|
|
155
167
|
type: string;
|
|
156
168
|
payload: Record<string, unknown>;
|
|
157
|
-
actor: string;
|
|
158
169
|
producer_id: string;
|
|
159
170
|
producer_seq: number;
|
|
160
171
|
metadata?: Record<string, unknown> | undefined;
|
|
172
|
+
actor?: string | undefined;
|
|
161
173
|
source?: string | undefined;
|
|
162
174
|
refs?: Record<string, unknown> | undefined;
|
|
163
175
|
idempotency_key?: string | undefined;
|
|
@@ -165,10 +177,10 @@ declare const AppendEventRequestSchema: z.ZodObject<{
|
|
|
165
177
|
}, {
|
|
166
178
|
type: string;
|
|
167
179
|
payload: Record<string, unknown>;
|
|
168
|
-
actor: string;
|
|
169
180
|
producer_id: string;
|
|
170
181
|
producer_seq: number;
|
|
171
182
|
metadata?: Record<string, unknown> | undefined;
|
|
183
|
+
actor?: string | undefined;
|
|
172
184
|
source?: string | undefined;
|
|
173
185
|
refs?: Record<string, unknown> | undefined;
|
|
174
186
|
idempotency_key?: string | undefined;
|
|
@@ -198,6 +210,13 @@ declare const AppendEventResponseSchema: z.ZodObject<{
|
|
|
198
210
|
* Inferred TypeScript type for {@link AppendEventResponseSchema}.
|
|
199
211
|
*/
|
|
200
212
|
type AppendEventResponse = z.infer<typeof AppendEventResponseSchema>;
|
|
213
|
+
/**
|
|
214
|
+
* High-level append result returned by `session.append()`.
|
|
215
|
+
*/
|
|
216
|
+
interface AppendResult {
|
|
217
|
+
seq: number;
|
|
218
|
+
deduped: boolean;
|
|
219
|
+
}
|
|
201
220
|
/**
|
|
202
221
|
* Raw event frame shape emitted by the Starcite tail stream.
|
|
203
222
|
*/
|
|
@@ -243,117 +262,113 @@ declare const TailEventSchema: z.ZodObject<{
|
|
|
243
262
|
*/
|
|
244
263
|
type TailEvent = z.infer<typeof TailEventSchema>;
|
|
245
264
|
/**
|
|
246
|
-
*
|
|
265
|
+
* Canonical session event surfaced by the SDK.
|
|
247
266
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
type: string;
|
|
265
|
-
payload: Record<string, unknown>;
|
|
266
|
-
actor: string;
|
|
267
|
-
producer_id: string;
|
|
268
|
-
producer_seq: number;
|
|
269
|
-
seq: number;
|
|
270
|
-
agent?: string | undefined;
|
|
271
|
-
metadata?: Record<string, unknown> | undefined;
|
|
272
|
-
source?: string | undefined;
|
|
273
|
-
refs?: Record<string, unknown> | undefined;
|
|
274
|
-
idempotency_key?: string | null | undefined;
|
|
275
|
-
inserted_at?: string | undefined;
|
|
276
|
-
text?: string | undefined;
|
|
277
|
-
}, {
|
|
278
|
-
type: string;
|
|
279
|
-
payload: Record<string, unknown>;
|
|
280
|
-
actor: string;
|
|
281
|
-
producer_id: string;
|
|
282
|
-
producer_seq: number;
|
|
283
|
-
seq: number;
|
|
284
|
-
agent?: string | undefined;
|
|
285
|
-
metadata?: Record<string, unknown> | undefined;
|
|
286
|
-
source?: string | undefined;
|
|
287
|
-
refs?: Record<string, unknown> | undefined;
|
|
288
|
-
idempotency_key?: string | null | undefined;
|
|
289
|
-
inserted_at?: string | undefined;
|
|
290
|
-
text?: string | undefined;
|
|
291
|
-
}>;
|
|
267
|
+
type SessionEvent = TailEvent;
|
|
268
|
+
/**
|
|
269
|
+
* Raw tail event batch grouped by a single WebSocket frame.
|
|
270
|
+
*/
|
|
271
|
+
type TailEventBatch = TailEvent[];
|
|
272
|
+
/**
|
|
273
|
+
* Retention options for a session's in-memory canonical log.
|
|
274
|
+
*/
|
|
275
|
+
interface SessionLogOptions {
|
|
276
|
+
/**
|
|
277
|
+
* Maximum number of events retained in memory.
|
|
278
|
+
*
|
|
279
|
+
* When omitted, the log keeps all applied events for the current runtime.
|
|
280
|
+
*/
|
|
281
|
+
maxEvents?: number;
|
|
282
|
+
}
|
|
292
283
|
/**
|
|
293
|
-
*
|
|
284
|
+
* Snapshot of a session's canonical in-memory log state.
|
|
294
285
|
*/
|
|
295
|
-
|
|
286
|
+
interface SessionSnapshot {
|
|
287
|
+
/**
|
|
288
|
+
* Ordered events currently retained in memory.
|
|
289
|
+
*/
|
|
290
|
+
events: TailEvent[];
|
|
291
|
+
/**
|
|
292
|
+
* Highest contiguous sequence applied to the log.
|
|
293
|
+
*/
|
|
294
|
+
lastSeq: number;
|
|
295
|
+
/**
|
|
296
|
+
* Indicates whether the session is actively streaming tail updates.
|
|
297
|
+
*/
|
|
298
|
+
syncing: boolean;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Serializable persisted state for one session log.
|
|
302
|
+
*/
|
|
303
|
+
interface SessionStoreState {
|
|
304
|
+
/**
|
|
305
|
+
* Highest contiguous sequence applied for this session.
|
|
306
|
+
*/
|
|
307
|
+
cursor: number;
|
|
308
|
+
/**
|
|
309
|
+
* Retained events snapshot used for immediate replay.
|
|
310
|
+
*/
|
|
311
|
+
events: TailEvent[];
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Persistence interface for session cursor + retained events.
|
|
315
|
+
*/
|
|
316
|
+
interface SessionStore {
|
|
317
|
+
load(sessionId: string): SessionStoreState | undefined;
|
|
318
|
+
save(sessionId: string, state: SessionStoreState): void;
|
|
319
|
+
clear?(sessionId: string): void;
|
|
320
|
+
}
|
|
296
321
|
/**
|
|
297
322
|
* High-level `session.append()` input.
|
|
298
323
|
*
|
|
299
|
-
*
|
|
300
|
-
* `text` or `payload`.
|
|
324
|
+
* The SDK manages `actor`, `producer_id`, and `producer_seq` automatically.
|
|
325
|
+
* Just provide `text` or `payload`.
|
|
301
326
|
*/
|
|
302
327
|
declare const SessionAppendInputSchema: z.ZodEffects<z.ZodObject<{
|
|
303
|
-
agent: z.ZodString;
|
|
304
|
-
producerId: z.ZodString;
|
|
305
|
-
producerSeq: z.ZodNumber;
|
|
306
328
|
text: z.ZodOptional<z.ZodString>;
|
|
307
329
|
payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
308
330
|
type: z.ZodOptional<z.ZodString>;
|
|
331
|
+
actor: z.ZodOptional<z.ZodString>;
|
|
309
332
|
source: z.ZodOptional<z.ZodString>;
|
|
310
333
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
311
334
|
refs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
312
335
|
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
313
336
|
expectedSeq: z.ZodOptional<z.ZodNumber>;
|
|
314
337
|
}, "strip", z.ZodTypeAny, {
|
|
315
|
-
agent: string;
|
|
316
|
-
producerId: string;
|
|
317
|
-
producerSeq: number;
|
|
318
338
|
type?: string | undefined;
|
|
319
339
|
metadata?: Record<string, unknown> | undefined;
|
|
320
340
|
payload?: Record<string, unknown> | undefined;
|
|
341
|
+
actor?: string | undefined;
|
|
321
342
|
source?: string | undefined;
|
|
322
343
|
refs?: Record<string, unknown> | undefined;
|
|
323
344
|
text?: string | undefined;
|
|
324
345
|
idempotencyKey?: string | undefined;
|
|
325
346
|
expectedSeq?: number | undefined;
|
|
326
347
|
}, {
|
|
327
|
-
agent: string;
|
|
328
|
-
producerId: string;
|
|
329
|
-
producerSeq: number;
|
|
330
348
|
type?: string | undefined;
|
|
331
349
|
metadata?: Record<string, unknown> | undefined;
|
|
332
350
|
payload?: Record<string, unknown> | undefined;
|
|
351
|
+
actor?: string | undefined;
|
|
333
352
|
source?: string | undefined;
|
|
334
353
|
refs?: Record<string, unknown> | undefined;
|
|
335
354
|
text?: string | undefined;
|
|
336
355
|
idempotencyKey?: string | undefined;
|
|
337
356
|
expectedSeq?: number | undefined;
|
|
338
357
|
}>, {
|
|
339
|
-
agent: string;
|
|
340
|
-
producerId: string;
|
|
341
|
-
producerSeq: number;
|
|
342
358
|
type?: string | undefined;
|
|
343
359
|
metadata?: Record<string, unknown> | undefined;
|
|
344
360
|
payload?: Record<string, unknown> | undefined;
|
|
361
|
+
actor?: string | undefined;
|
|
345
362
|
source?: string | undefined;
|
|
346
363
|
refs?: Record<string, unknown> | undefined;
|
|
347
364
|
text?: string | undefined;
|
|
348
365
|
idempotencyKey?: string | undefined;
|
|
349
366
|
expectedSeq?: number | undefined;
|
|
350
367
|
}, {
|
|
351
|
-
agent: string;
|
|
352
|
-
producerId: string;
|
|
353
|
-
producerSeq: number;
|
|
354
368
|
type?: string | undefined;
|
|
355
369
|
metadata?: Record<string, unknown> | undefined;
|
|
356
370
|
payload?: Record<string, unknown> | undefined;
|
|
371
|
+
actor?: string | undefined;
|
|
357
372
|
source?: string | undefined;
|
|
358
373
|
refs?: Record<string, unknown> | undefined;
|
|
359
374
|
text?: string | undefined;
|
|
@@ -372,10 +387,22 @@ interface SessionTailOptions {
|
|
|
372
387
|
* Starting cursor (inclusive) in the event stream.
|
|
373
388
|
*/
|
|
374
389
|
cursor?: number;
|
|
390
|
+
/**
|
|
391
|
+
* Tail frame batch size (`1..1000`).
|
|
392
|
+
*
|
|
393
|
+
* When greater than `1`, Starcite may emit batched WebSocket frames.
|
|
394
|
+
*/
|
|
395
|
+
batchSize?: number;
|
|
375
396
|
/**
|
|
376
397
|
* Optional filter for `agent:<name>` events.
|
|
377
398
|
*/
|
|
378
399
|
agent?: string;
|
|
400
|
+
/**
|
|
401
|
+
* Idle window in milliseconds used for replay-only tails (`follow=false`) before auto-close.
|
|
402
|
+
*
|
|
403
|
+
* Defaults to `1000`.
|
|
404
|
+
*/
|
|
405
|
+
catchUpIdleMs?: number;
|
|
379
406
|
/**
|
|
380
407
|
* Automatically reconnect on transport failures and continue from the last observed sequence.
|
|
381
408
|
*
|
|
@@ -383,58 +410,196 @@ interface SessionTailOptions {
|
|
|
383
410
|
*/
|
|
384
411
|
reconnect?: boolean;
|
|
385
412
|
/**
|
|
386
|
-
*
|
|
413
|
+
* Reconnect policy for transport failures.
|
|
414
|
+
*/
|
|
415
|
+
reconnectPolicy?: TailReconnectPolicy;
|
|
416
|
+
/**
|
|
417
|
+
* When `false`, exit after replaying stored events instead of streaming live.
|
|
387
418
|
*
|
|
388
|
-
* Defaults to `
|
|
419
|
+
* Defaults to `true`.
|
|
389
420
|
*/
|
|
390
|
-
|
|
421
|
+
follow?: boolean;
|
|
391
422
|
/**
|
|
392
423
|
* Optional abort signal to close the stream.
|
|
393
424
|
*/
|
|
394
425
|
signal?: AbortSignal;
|
|
426
|
+
/**
|
|
427
|
+
* Maximum number of tail batches buffered in-memory while the consumer is busy.
|
|
428
|
+
*
|
|
429
|
+
* Defaults to `1024`. When exceeded, the stream fails with `StarciteTailError`.
|
|
430
|
+
*/
|
|
431
|
+
maxBufferedBatches?: number;
|
|
432
|
+
/**
|
|
433
|
+
* Optional lifecycle callback invoked for reconnect/drop/terminal stream state changes.
|
|
434
|
+
*/
|
|
435
|
+
onLifecycleEvent?: (event: TailLifecycleEvent) => void;
|
|
436
|
+
/**
|
|
437
|
+
* Maximum time to wait for websocket handshake/open before reconnecting or failing.
|
|
438
|
+
*
|
|
439
|
+
* Defaults to `4000`.
|
|
440
|
+
*/
|
|
441
|
+
connectionTimeoutMs?: number;
|
|
442
|
+
/**
|
|
443
|
+
* Optional inactivity watchdog. When set, the stream reconnects when no messages
|
|
444
|
+
* arrive within this duration.
|
|
445
|
+
*/
|
|
446
|
+
inactivityTimeoutMs?: number;
|
|
395
447
|
}
|
|
396
448
|
/**
|
|
397
|
-
*
|
|
449
|
+
* Tail reconnect tuning knobs.
|
|
450
|
+
*/
|
|
451
|
+
interface TailReconnectPolicy {
|
|
452
|
+
/**
|
|
453
|
+
* Reconnect mode. `fixed` retries at the same delay, `exponential` increases delay after repeated failures.
|
|
454
|
+
*
|
|
455
|
+
* Defaults to `exponential`.
|
|
456
|
+
*/
|
|
457
|
+
mode?: "fixed" | "exponential";
|
|
458
|
+
/**
|
|
459
|
+
* Initial reconnect delay in milliseconds.
|
|
460
|
+
*
|
|
461
|
+
* Defaults to `500`.
|
|
462
|
+
*/
|
|
463
|
+
initialDelayMs?: number;
|
|
464
|
+
/**
|
|
465
|
+
* Maximum reconnect delay in milliseconds.
|
|
466
|
+
*
|
|
467
|
+
* Defaults to `15000`.
|
|
468
|
+
*/
|
|
469
|
+
maxDelayMs?: number;
|
|
470
|
+
/**
|
|
471
|
+
* Exponential growth factor applied after each failed reconnect attempt.
|
|
472
|
+
*
|
|
473
|
+
* Defaults to `2`.
|
|
474
|
+
*/
|
|
475
|
+
multiplier?: number;
|
|
476
|
+
/**
|
|
477
|
+
* Optional jitter ratio (`0..1`) applied around the computed delay.
|
|
478
|
+
*
|
|
479
|
+
* Defaults to `0.2`.
|
|
480
|
+
*/
|
|
481
|
+
jitterRatio?: number;
|
|
482
|
+
/**
|
|
483
|
+
* Maximum number of reconnect attempts before failing.
|
|
484
|
+
*
|
|
485
|
+
* Defaults to unlimited retries.
|
|
486
|
+
*/
|
|
487
|
+
maxAttempts?: number;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Stream lifecycle event emitted by `tail*()` APIs.
|
|
491
|
+
*/
|
|
492
|
+
type TailLifecycleEvent = {
|
|
493
|
+
type: "connect_attempt";
|
|
494
|
+
sessionId: string;
|
|
495
|
+
attempt: number;
|
|
496
|
+
cursor: number;
|
|
497
|
+
} | {
|
|
498
|
+
type: "reconnect_scheduled";
|
|
499
|
+
sessionId: string;
|
|
500
|
+
attempt: number;
|
|
501
|
+
delayMs: number;
|
|
502
|
+
trigger: "connect_failed" | "dropped";
|
|
503
|
+
closeCode?: number;
|
|
504
|
+
closeReason?: string;
|
|
505
|
+
} | {
|
|
506
|
+
type: "stream_dropped";
|
|
507
|
+
sessionId: string;
|
|
508
|
+
attempt: number;
|
|
509
|
+
closeCode?: number;
|
|
510
|
+
closeReason?: string;
|
|
511
|
+
} | {
|
|
512
|
+
type: "stream_ended";
|
|
513
|
+
sessionId: string;
|
|
514
|
+
reason: "aborted" | "caught_up" | "graceful";
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* Storage adapter used by `session.consume*()` to persist the last processed cursor.
|
|
518
|
+
*/
|
|
519
|
+
interface SessionCursorStore {
|
|
520
|
+
/**
|
|
521
|
+
* Loads the last processed cursor for a session.
|
|
522
|
+
*
|
|
523
|
+
* Return `undefined` when no cursor has been stored yet.
|
|
524
|
+
*/
|
|
525
|
+
load(sessionId: string): number | undefined | Promise<number | undefined>;
|
|
526
|
+
/**
|
|
527
|
+
* Persists the last processed cursor for a session.
|
|
528
|
+
*/
|
|
529
|
+
save(sessionId: string, cursor: number): void | Promise<void>;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Durable tail consumption options with automatic cursor checkpointing.
|
|
398
533
|
*/
|
|
399
|
-
interface
|
|
534
|
+
interface SessionConsumeOptions extends Omit<SessionTailOptions, "cursor"> {
|
|
400
535
|
/**
|
|
401
|
-
*
|
|
536
|
+
* Optional explicit starting cursor. When omitted, the SDK loads it from `cursorStore`.
|
|
402
537
|
*/
|
|
403
|
-
|
|
538
|
+
cursor?: number;
|
|
404
539
|
/**
|
|
405
|
-
*
|
|
540
|
+
* Cursor storage adapter used for resume-safe processing.
|
|
406
541
|
*/
|
|
407
|
-
|
|
542
|
+
cursorStore: SessionCursorStore;
|
|
408
543
|
/**
|
|
409
|
-
*
|
|
544
|
+
* Event handler. The cursor is checkpointed only after this handler succeeds.
|
|
410
545
|
*/
|
|
411
|
-
|
|
546
|
+
handler: (event: TailEvent) => void | Promise<void>;
|
|
412
547
|
}
|
|
548
|
+
/**
|
|
549
|
+
* Options for listing sessions.
|
|
550
|
+
*/
|
|
551
|
+
declare const SessionListOptionsSchema: z.ZodObject<{
|
|
552
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
553
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
554
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
555
|
+
}, "strip", z.ZodTypeAny, {
|
|
556
|
+
metadata?: Record<string, string> | undefined;
|
|
557
|
+
cursor?: string | undefined;
|
|
558
|
+
limit?: number | undefined;
|
|
559
|
+
}, {
|
|
560
|
+
metadata?: Record<string, string> | undefined;
|
|
561
|
+
cursor?: string | undefined;
|
|
562
|
+
limit?: number | undefined;
|
|
563
|
+
}>;
|
|
564
|
+
type SessionListOptions = z.input<typeof SessionListOptionsSchema>;
|
|
413
565
|
/**
|
|
414
566
|
* Minimal WebSocket contract required by the SDK.
|
|
415
567
|
*/
|
|
568
|
+
interface StarciteWebSocketMessageEvent {
|
|
569
|
+
data: unknown;
|
|
570
|
+
}
|
|
571
|
+
interface StarciteWebSocketCloseEvent {
|
|
572
|
+
code?: number;
|
|
573
|
+
reason?: string;
|
|
574
|
+
}
|
|
575
|
+
interface StarciteWebSocketEventMap {
|
|
576
|
+
open: unknown;
|
|
577
|
+
message: StarciteWebSocketMessageEvent;
|
|
578
|
+
error: unknown;
|
|
579
|
+
close: StarciteWebSocketCloseEvent;
|
|
580
|
+
}
|
|
416
581
|
interface StarciteWebSocket {
|
|
417
|
-
addEventListener(type:
|
|
418
|
-
removeEventListener(type:
|
|
582
|
+
addEventListener<TType extends keyof StarciteWebSocketEventMap>(type: TType, listener: (event: StarciteWebSocketEventMap[TType]) => void): void;
|
|
583
|
+
removeEventListener<TType extends keyof StarciteWebSocketEventMap>(type: TType, listener: (event: StarciteWebSocketEventMap[TType]) => void): void;
|
|
419
584
|
close(code?: number, reason?: string): void;
|
|
420
585
|
}
|
|
421
586
|
/**
|
|
422
587
|
* Factory used to create the WebSocket connection for `tail`.
|
|
423
588
|
*/
|
|
424
|
-
|
|
589
|
+
type StarciteWebSocketFactory = (url: string) => StarciteWebSocket;
|
|
590
|
+
/**
|
|
591
|
+
* Options forwarded to individual HTTP requests.
|
|
592
|
+
*/
|
|
593
|
+
interface RequestOptions {
|
|
425
594
|
/**
|
|
426
|
-
*
|
|
595
|
+
* Optional abort signal to cancel the request.
|
|
427
596
|
*/
|
|
428
|
-
|
|
597
|
+
signal?: AbortSignal;
|
|
429
598
|
}
|
|
430
|
-
/**
|
|
431
|
-
* Factory used to create the WebSocket connection for `tail`.
|
|
432
|
-
*/
|
|
433
|
-
type StarciteWebSocketFactory = (url: string, options?: StarciteWebSocketConnectOptions) => StarciteWebSocket;
|
|
434
599
|
/**
|
|
435
600
|
* Client construction options.
|
|
436
601
|
*/
|
|
437
|
-
interface
|
|
602
|
+
interface StarciteOptions {
|
|
438
603
|
/**
|
|
439
604
|
* Base API URL. Defaults to `process.env.STARCITE_BASE_URL` or `http://localhost:4000`.
|
|
440
605
|
*/
|
|
@@ -449,143 +614,369 @@ interface StarciteClientOptions {
|
|
|
449
614
|
headers?: HeadersInit;
|
|
450
615
|
/**
|
|
451
616
|
* Service key / JWT token. When set, the SDK automatically sends
|
|
452
|
-
* `Authorization: Bearer <token>` for HTTP requests
|
|
617
|
+
* `Authorization: Bearer <token>` for HTTP requests.
|
|
453
618
|
*/
|
|
454
619
|
apiKey?: string;
|
|
620
|
+
/**
|
|
621
|
+
* Auth issuer URL used to mint session tokens. When omitted, the SDK derives
|
|
622
|
+
* this from API key JWT `iss` (issuer authority) or `STARCITE_AUTH_URL`.
|
|
623
|
+
*/
|
|
624
|
+
authUrl?: string;
|
|
455
625
|
/**
|
|
456
626
|
* Custom WebSocket factory for non-browser runtimes.
|
|
457
627
|
*/
|
|
458
628
|
websocketFactory?: StarciteWebSocketFactory;
|
|
629
|
+
/**
|
|
630
|
+
* Session store used for cursor + retained event persistence.
|
|
631
|
+
*
|
|
632
|
+
* Defaults to an in-memory store.
|
|
633
|
+
*/
|
|
634
|
+
store?: SessionStore;
|
|
459
635
|
}
|
|
460
636
|
/**
|
|
461
637
|
* Error payload shape returned by non-2xx API responses.
|
|
462
638
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
639
|
+
type StarciteErrorPayload = Record<string, unknown>;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Base error type for SDK-level failures.
|
|
643
|
+
*/
|
|
644
|
+
declare class StarciteError extends Error {
|
|
645
|
+
constructor(message: string);
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Thrown when the Starcite API responds with a non-2xx status code.
|
|
649
|
+
*/
|
|
650
|
+
declare class StarciteApiError extends StarciteError {
|
|
651
|
+
/** HTTP status code returned by the API. */
|
|
652
|
+
readonly status: number;
|
|
653
|
+
/** Stable API error code (or synthesized `http_<status>` fallback). */
|
|
654
|
+
readonly code: string;
|
|
655
|
+
/** Parsed API error payload when available. */
|
|
656
|
+
readonly payload: StarciteErrorPayload | null;
|
|
657
|
+
constructor(message: string, status: number, code: string, payload: StarciteErrorPayload | null);
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Thrown when the SDK cannot reach Starcite or receives invalid transport payloads.
|
|
661
|
+
*/
|
|
662
|
+
declare class StarciteConnectionError extends StarciteError {
|
|
663
|
+
constructor(message: string);
|
|
664
|
+
}
|
|
665
|
+
type StarciteTailErrorStage = "connect" | "stream" | "retry_limit" | "consumer_backpressure";
|
|
666
|
+
/**
|
|
667
|
+
* Thrown for tail-stream failures with structured stage/context fields.
|
|
668
|
+
*/
|
|
669
|
+
declare class StarciteTailError extends StarciteConnectionError {
|
|
670
|
+
/** Session id tied to this tail stream. */
|
|
671
|
+
readonly sessionId: string;
|
|
672
|
+
/** Failure stage in the tail lifecycle. */
|
|
673
|
+
readonly stage: StarciteTailErrorStage;
|
|
674
|
+
/** Reconnect attempts observed before failing. */
|
|
675
|
+
readonly attempts: number;
|
|
676
|
+
/** WebSocket close code when available. */
|
|
677
|
+
readonly closeCode?: number;
|
|
678
|
+
/** WebSocket close reason when available. */
|
|
679
|
+
readonly closeReason?: string;
|
|
680
|
+
constructor(message: string, options: {
|
|
681
|
+
sessionId: string;
|
|
682
|
+
stage: StarciteTailErrorStage;
|
|
683
|
+
attempts?: number;
|
|
684
|
+
closeCode?: number;
|
|
685
|
+
closeReason?: string;
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Thrown when the tail WebSocket is closed with code 4001 (token expired).
|
|
690
|
+
*
|
|
691
|
+
* Callers should re-issue a session token and reconnect from the last cursor.
|
|
692
|
+
*/
|
|
693
|
+
declare class StarciteTokenExpiredError extends StarciteTailError {
|
|
694
|
+
constructor(message: string, options: {
|
|
695
|
+
sessionId: string;
|
|
696
|
+
attempts?: number;
|
|
697
|
+
closeCode?: number;
|
|
698
|
+
closeReason?: string;
|
|
699
|
+
});
|
|
700
|
+
}
|
|
473
701
|
/**
|
|
474
|
-
*
|
|
702
|
+
* Thrown when the tail consumer falls behind and exceeds the buffered batch limit.
|
|
475
703
|
*/
|
|
476
|
-
|
|
704
|
+
declare class StarciteBackpressureError extends StarciteTailError {
|
|
705
|
+
constructor(message: string, options: {
|
|
706
|
+
sessionId: string;
|
|
707
|
+
attempts?: number;
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Thrown when tail reconnect attempts exceed the configured limit.
|
|
712
|
+
*/
|
|
713
|
+
declare class StarciteRetryLimitError extends StarciteTailError {
|
|
714
|
+
constructor(message: string, options: {
|
|
715
|
+
sessionId: string;
|
|
716
|
+
attempts: number;
|
|
717
|
+
closeCode?: number;
|
|
718
|
+
closeReason?: string;
|
|
719
|
+
});
|
|
720
|
+
}
|
|
477
721
|
|
|
722
|
+
declare class SessionLogGapError extends StarciteError {
|
|
723
|
+
constructor(message: string);
|
|
724
|
+
}
|
|
725
|
+
declare class SessionLogConflictError extends StarciteError {
|
|
726
|
+
constructor(message: string);
|
|
727
|
+
}
|
|
478
728
|
/**
|
|
479
|
-
*
|
|
729
|
+
* Canonical in-memory log for one session.
|
|
730
|
+
*
|
|
731
|
+
* Invariants:
|
|
732
|
+
* - Applies events in strict contiguous `seq` order.
|
|
733
|
+
* - Treats repeated identical events as idempotent no-ops.
|
|
734
|
+
* - Rejects conflicting duplicates and sequence gaps.
|
|
735
|
+
*/
|
|
736
|
+
declare class SessionLog {
|
|
737
|
+
private readonly history;
|
|
738
|
+
private readonly emitter;
|
|
739
|
+
private readonly canonicalBySeq;
|
|
740
|
+
private maxEvents;
|
|
741
|
+
private appliedSeq;
|
|
742
|
+
constructor(options?: SessionLogOptions);
|
|
743
|
+
setMaxEvents(maxEvents: number | undefined): void;
|
|
744
|
+
applyBatch(batch: TailEvent[]): TailEvent[];
|
|
745
|
+
hydrate(state: SessionStoreState): void;
|
|
746
|
+
subscribe(listener: (event: TailEvent) => void, options?: {
|
|
747
|
+
replay?: boolean;
|
|
748
|
+
}): () => void;
|
|
749
|
+
private apply;
|
|
750
|
+
getSnapshot(syncing: boolean): SessionSnapshot;
|
|
751
|
+
get events(): readonly TailEvent[];
|
|
752
|
+
get cursor(): number;
|
|
753
|
+
get lastSeq(): number;
|
|
754
|
+
private enforceRetention;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Shared HTTP + WebSocket transport configuration.
|
|
759
|
+
*
|
|
760
|
+
* Both `Starcite` (API-key auth) and `StarciteSession` (session-token auth)
|
|
761
|
+
* hold their own `TransportConfig` and pass it to the free functions below.
|
|
480
762
|
*/
|
|
481
|
-
|
|
763
|
+
interface TransportConfig {
|
|
764
|
+
readonly baseUrl: string;
|
|
765
|
+
readonly websocketBaseUrl: string;
|
|
766
|
+
readonly authorization: string | null;
|
|
767
|
+
readonly fetchFn: typeof fetch;
|
|
768
|
+
readonly headers: Headers;
|
|
769
|
+
readonly websocketFactory: (url: string) => StarciteWebSocket;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Construction options for a `StarciteSession`.
|
|
774
|
+
*/
|
|
775
|
+
interface StarciteSessionOptions {
|
|
776
|
+
id: string;
|
|
777
|
+
token: string;
|
|
778
|
+
identity: StarciteIdentity;
|
|
779
|
+
transport: TransportConfig;
|
|
780
|
+
store: SessionStore;
|
|
781
|
+
record?: SessionRecord;
|
|
782
|
+
logOptions?: SessionLogOptions;
|
|
783
|
+
}
|
|
784
|
+
type SessionEventListener = (event: SessionEvent) => void;
|
|
482
785
|
/**
|
|
483
|
-
* Session-scoped
|
|
786
|
+
* Session-scoped client bound to a specific identity and session token.
|
|
787
|
+
*
|
|
788
|
+
* All operations use the session token for auth — not the parent client's API key.
|
|
484
789
|
*/
|
|
485
790
|
declare class StarciteSession {
|
|
486
791
|
/** Session identifier. */
|
|
487
792
|
readonly id: string;
|
|
793
|
+
/** The session JWT used for auth. Extract this for frontend handoff. */
|
|
794
|
+
readonly token: string;
|
|
795
|
+
/** Identity bound to this session. */
|
|
796
|
+
readonly identity: StarciteIdentity;
|
|
488
797
|
/** Optional session record captured at creation time. */
|
|
489
798
|
readonly record?: SessionRecord;
|
|
490
|
-
private readonly
|
|
491
|
-
|
|
799
|
+
private readonly transport;
|
|
800
|
+
private readonly producerId;
|
|
801
|
+
private producerSeq;
|
|
802
|
+
readonly log: SessionLog;
|
|
803
|
+
private readonly store;
|
|
804
|
+
private readonly lifecycle;
|
|
805
|
+
private readonly eventSubscriptions;
|
|
806
|
+
private liveSyncController;
|
|
807
|
+
private liveSyncTask;
|
|
808
|
+
constructor(options: StarciteSessionOptions);
|
|
492
809
|
/**
|
|
493
|
-
* Appends
|
|
810
|
+
* Appends an event to this session.
|
|
494
811
|
*
|
|
495
|
-
*
|
|
812
|
+
* The SDK manages `actor`, `producer_id`, and `producer_seq` automatically.
|
|
496
813
|
*/
|
|
497
|
-
append(input: SessionAppendInput): Promise<
|
|
814
|
+
append(input: SessionAppendInput, options?: RequestOptions): Promise<AppendResult>;
|
|
498
815
|
/**
|
|
499
|
-
* Appends a raw event payload as-is.
|
|
816
|
+
* Appends a raw event payload as-is. Caller manages all fields.
|
|
500
817
|
*/
|
|
501
|
-
appendRaw(input: AppendEventRequest): Promise<AppendEventResponse>;
|
|
818
|
+
appendRaw(input: AppendEventRequest, options?: RequestOptions): Promise<AppendEventResponse>;
|
|
502
819
|
/**
|
|
503
|
-
*
|
|
820
|
+
* Subscribes to canonical session events and lifecycle errors.
|
|
504
821
|
*/
|
|
505
|
-
|
|
822
|
+
on(eventName: "event", listener: SessionEventListener): () => void;
|
|
823
|
+
on(eventName: "error", listener: (error: Error) => void): () => void;
|
|
506
824
|
/**
|
|
507
|
-
*
|
|
825
|
+
* Removes a previously registered listener.
|
|
508
826
|
*/
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Starcite API client for HTTP and WebSocket session operations.
|
|
513
|
-
*/
|
|
514
|
-
declare class StarciteClient {
|
|
515
|
-
/** Normalized API base URL ending with `/v1`. */
|
|
516
|
-
readonly baseUrl: string;
|
|
517
|
-
private readonly inferredCreatorPrincipal?;
|
|
518
|
-
private readonly websocketBaseUrl;
|
|
519
|
-
private readonly fetchFn;
|
|
520
|
-
private readonly headers;
|
|
521
|
-
private readonly websocketFactory;
|
|
827
|
+
off(eventName: "event", listener: SessionEventListener): void;
|
|
828
|
+
off(eventName: "error", listener: (error: Error) => void): void;
|
|
522
829
|
/**
|
|
523
|
-
*
|
|
830
|
+
* Stops live syncing and removes listeners registered via `on()`.
|
|
524
831
|
*/
|
|
525
|
-
|
|
832
|
+
disconnect(): void;
|
|
526
833
|
/**
|
|
527
|
-
*
|
|
834
|
+
* Backwards-compatible alias for `disconnect()`.
|
|
528
835
|
*/
|
|
529
|
-
|
|
836
|
+
close(): void;
|
|
530
837
|
/**
|
|
531
|
-
*
|
|
838
|
+
* Updates in-memory session log retention.
|
|
532
839
|
*/
|
|
533
|
-
|
|
840
|
+
setLogOptions(options: SessionLogOptions): void;
|
|
534
841
|
/**
|
|
535
|
-
*
|
|
842
|
+
* Returns a stable snapshot of the current canonical in-memory log.
|
|
536
843
|
*/
|
|
537
|
-
|
|
844
|
+
getSnapshot(): SessionSnapshot;
|
|
538
845
|
/**
|
|
539
|
-
*
|
|
846
|
+
* Streams tail events one at a time via callback.
|
|
847
|
+
*/
|
|
848
|
+
tail(onEvent: (event: TailEvent) => void | Promise<void>, options?: SessionTailOptions): Promise<void>;
|
|
849
|
+
/**
|
|
850
|
+
* Streams tail event batches grouped by incoming frame via callback.
|
|
851
|
+
*/
|
|
852
|
+
tailBatches(onBatch: (batch: TailEvent[]) => void | Promise<void>, options?: SessionTailOptions): Promise<void>;
|
|
853
|
+
/**
|
|
854
|
+
* Durably consumes events and checkpoints `event.seq` after each successful handler invocation.
|
|
855
|
+
*/
|
|
856
|
+
consume(options: SessionConsumeOptions): Promise<void>;
|
|
857
|
+
private emitStreamError;
|
|
858
|
+
private ensureLiveSync;
|
|
859
|
+
private runLiveSync;
|
|
860
|
+
private persistLogState;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Tenant-scoped Starcite client.
|
|
865
|
+
*
|
|
866
|
+
* Create identities with {@link user} / {@link agent}, then bind them to
|
|
867
|
+
* sessions with {@link session}.
|
|
868
|
+
*/
|
|
869
|
+
declare class Starcite {
|
|
870
|
+
/** Normalized API base URL ending with `/v1`. */
|
|
871
|
+
readonly baseUrl: string;
|
|
872
|
+
private readonly transport;
|
|
873
|
+
private readonly authBaseUrl?;
|
|
874
|
+
private readonly inferredIdentity?;
|
|
875
|
+
private readonly store;
|
|
876
|
+
constructor(options?: StarciteOptions);
|
|
877
|
+
/**
|
|
878
|
+
* Creates a user identity bound to this client's tenant.
|
|
540
879
|
*/
|
|
541
|
-
|
|
880
|
+
user(options: {
|
|
881
|
+
id: string;
|
|
882
|
+
}): StarciteIdentity;
|
|
542
883
|
/**
|
|
543
|
-
*
|
|
884
|
+
* Creates an agent identity bound to this client's tenant.
|
|
544
885
|
*/
|
|
545
|
-
|
|
886
|
+
agent(options: {
|
|
887
|
+
id: string;
|
|
888
|
+
}): StarciteIdentity;
|
|
546
889
|
/**
|
|
547
|
-
*
|
|
890
|
+
* Creates or binds to a session.
|
|
891
|
+
*
|
|
892
|
+
* **With identity** (backend): creates a new session and/or mints a session
|
|
893
|
+
* token for the given identity. Pass `id` to bind to an existing session.
|
|
894
|
+
*
|
|
895
|
+
* **With token** (frontend): wraps an existing session token. The identity
|
|
896
|
+
* and session id are decoded from the JWT.
|
|
548
897
|
*/
|
|
549
|
-
|
|
898
|
+
session(input: {
|
|
899
|
+
token: string;
|
|
900
|
+
logOptions?: SessionLogOptions;
|
|
901
|
+
}): StarciteSession;
|
|
902
|
+
session(input: {
|
|
903
|
+
identity: StarciteIdentity;
|
|
904
|
+
id?: string;
|
|
905
|
+
title?: string;
|
|
906
|
+
metadata?: Record<string, unknown>;
|
|
907
|
+
logOptions?: SessionLogOptions;
|
|
908
|
+
}): Promise<StarciteSession>;
|
|
550
909
|
/**
|
|
551
|
-
*
|
|
910
|
+
* Lists sessions from the archive-backed catalog.
|
|
552
911
|
*/
|
|
553
|
-
|
|
554
|
-
private
|
|
912
|
+
listSessions(options?: SessionListOptions, requestOptions?: RequestOptions): Promise<SessionListPage>;
|
|
913
|
+
private sessionFromIdentity;
|
|
914
|
+
private sessionFromToken;
|
|
915
|
+
private buildSessionTransport;
|
|
916
|
+
private createSession;
|
|
917
|
+
private issueSessionToken;
|
|
918
|
+
private requireTenantId;
|
|
555
919
|
}
|
|
556
920
|
|
|
557
921
|
/**
|
|
558
|
-
*
|
|
922
|
+
* Minimal Web Storage contract used by {@link WebStorageCursorStore}.
|
|
559
923
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
924
|
+
interface StarciteWebStorage {
|
|
925
|
+
getItem(key: string): string | null;
|
|
926
|
+
setItem(key: string, value: string): void;
|
|
562
927
|
}
|
|
563
928
|
/**
|
|
564
|
-
*
|
|
929
|
+
* Key customization options for storage-backed cursor stores.
|
|
565
930
|
*/
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
931
|
+
interface CursorStoreOptions {
|
|
932
|
+
/**
|
|
933
|
+
* Prefix used when deriving storage keys.
|
|
934
|
+
*
|
|
935
|
+
* Defaults to `"starcite"`.
|
|
936
|
+
*/
|
|
937
|
+
keyPrefix?: string;
|
|
938
|
+
/**
|
|
939
|
+
* Custom key resolver. When provided it overrides `keyPrefix`.
|
|
940
|
+
*/
|
|
941
|
+
keyForSession?: (sessionId: string) => string;
|
|
574
942
|
}
|
|
575
943
|
/**
|
|
576
|
-
*
|
|
944
|
+
* In-memory cursor store (useful for workers/tests).
|
|
577
945
|
*/
|
|
578
|
-
declare class
|
|
579
|
-
|
|
946
|
+
declare class InMemoryCursorStore implements SessionCursorStore {
|
|
947
|
+
private readonly cursors;
|
|
948
|
+
constructor(initial?: Record<string, number>);
|
|
949
|
+
load(sessionId: string): number | undefined;
|
|
950
|
+
save(sessionId: string, cursor: number): void;
|
|
580
951
|
}
|
|
581
|
-
|
|
582
952
|
/**
|
|
583
|
-
*
|
|
953
|
+
* Cursor store backed by a Web Storage-compatible object.
|
|
584
954
|
*/
|
|
585
|
-
declare
|
|
955
|
+
declare class WebStorageCursorStore implements SessionCursorStore {
|
|
956
|
+
private readonly storage;
|
|
957
|
+
private readonly keyForSession;
|
|
958
|
+
constructor(storage: StarciteWebStorage, options?: CursorStoreOptions);
|
|
959
|
+
load(sessionId: string): number | undefined;
|
|
960
|
+
save(sessionId: string, cursor: number): void;
|
|
961
|
+
}
|
|
586
962
|
/**
|
|
587
|
-
*
|
|
963
|
+
* Cursor store backed by `globalThis.localStorage`.
|
|
588
964
|
*/
|
|
589
|
-
declare
|
|
965
|
+
declare class LocalStorageCursorStore extends WebStorageCursorStore {
|
|
966
|
+
constructor(options?: CursorStoreOptions);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Default in-memory session store.
|
|
971
|
+
*
|
|
972
|
+
* Persists both cursor and retained events for each session so late subscribers
|
|
973
|
+
* can replay immediately after process-local reconnect/rebind.
|
|
974
|
+
*/
|
|
975
|
+
declare class MemoryStore implements SessionStore {
|
|
976
|
+
private readonly sessions;
|
|
977
|
+
load(sessionId: string): SessionStoreState | undefined;
|
|
978
|
+
save(sessionId: string, state: SessionStoreState): void;
|
|
979
|
+
clear(sessionId: string): void;
|
|
980
|
+
}
|
|
590
981
|
|
|
591
|
-
export { type AppendEventRequest, type AppendEventResponse, type
|
|
982
|
+
export { type AppendEventRequest, type AppendEventResponse, type AppendResult, type CursorStoreOptions, InMemoryCursorStore, LocalStorageCursorStore, MemoryStore, type PrincipalType, type RequestOptions, type SessionAppendInput, type SessionConsumeOptions, type SessionCursorStore, type SessionEvent, type SessionListItem, type SessionListOptions, type SessionListPage, SessionLogConflictError, SessionLogGapError, type SessionLogOptions, type SessionRecord, type SessionSnapshot, type SessionStore, type SessionStoreState, type SessionTailOptions, type SessionTokenScope, Starcite, StarciteApiError, StarciteBackpressureError, StarciteConnectionError, StarciteError, StarciteIdentity, type StarciteOptions, StarciteRetryLimitError, StarciteSession, StarciteTailError, type StarciteTailErrorStage, StarciteTokenExpiredError, type StarciteWebSocket, type StarciteWebSocketCloseEvent, type StarciteWebSocketEventMap, type StarciteWebSocketFactory, type StarciteWebSocketMessageEvent, type StarciteWebStorage, type TailEvent, type TailEventBatch, type TailLifecycleEvent, type TailReconnectPolicy, WebStorageCursorStore };
|