@origonai/web-sdk 0.1.3 → 0.1.5

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 CHANGED
@@ -59,13 +59,23 @@ await client.endSession(sessionId)
59
59
  ### Sessions
60
60
  - `startSession({ channel, sessionId?, data? })` — originate a chat or voice session (issues `POST /session/start`)
61
61
  - `joinSession({ channel, sessionId, url, token, chat?, voice? })` — attach to a session provisioned out of band, skipping `POST /session/start`; `chat.recovery` opts into caller-authorized server-replay recovery, while `voice.receiveOnly` starts playout with no microphone and awaits server uplink mute before connecting (see [Joining a provisioned session](#joining-a-provisioned-session))
62
- - `endSession(sessionId)` — close a session
62
+ - `endChat(sessionId)` — end an owned customer chat, retaining its transcript; duplicate requests coalesce.
63
+ - `endSession(sessionId)` — close the local session; customer chat cleanup detaches without ending the conversation
63
64
  - `endAllSessions()` — close every active session
64
65
  - `migrateSessionId(oldId, newId)` — re-key a live session whose id the control plane reassigned mid-call, without a media re-dial
65
66
  - `activeSessionIds()` — list active sessions
66
67
  - `getSessions()` — GET `/sessions` (prior sessions; every `SessionSummary`
67
68
  includes required live-owner `active: boolean`)
68
69
  - `getSession(sessionId)` — GET `/session/{id}` (transcript + control)
70
+ - `getSessionsPage({ pageSize?, cursor?, search?, signal? })` — fetch a strict
71
+ directory page (50 by default, 100 maximum); `search` matches subject,
72
+ contact name, latest visible message text, and attachment names
73
+ - `getSessionPage(sessionId, { pageSize?, cursor?, signal? })` — fetch a strict
74
+ chronological history page (100 by default, 250 maximum)
75
+ - `SessionDirectoryPager` / `SessionHistoryPager` — generation-fenced page
76
+ reducers for dedupe, live-event reconciliation, prepend accumulation, and
77
+ bounded empty-page continuation; keep search state separate from the default
78
+ cached directory
69
79
 
70
80
  ### Chat
71
81
  - `sendMessage(sessionId, payload)` — post a message with optional `metadata: {audience}`; ordinary participant sends omit it and the server resolves the audience to `all`. The SDK fires `onMessageAdded` immediately with `status: 'sending'`, then `onMessageUpdated` with `'delivered'` or `'failed'` after the server acks
package/dist/index.d.ts CHANGED
@@ -54,6 +54,8 @@ export declare class ClientError extends Error {
54
54
  static serverUnavailable(status: number): ClientError;
55
55
  static http(status: number, code: string, message: string): ClientError;
56
56
  static attachment(code: AttachmentErrorCode, message: string): ClientError;
57
+ static chatEndPending(): ClientError;
58
+ static chatEndUnconfirmed(): ClientError;
57
59
  static cancelled(): ClientError;
58
60
  static other(message: string): ClientError;
59
61
  static session(message: string): ClientError;
@@ -66,7 +68,7 @@ export declare interface ClientErrorJSON {
66
68
  message: string;
67
69
  }
68
70
 
69
- export declare type ClientErrorKind = 'notInitialized' | 'noSession' | 'session' | 'missingField' | 'serverUnavailable' | 'http' | 'attachment' | 'cancelled' | 'other';
71
+ export declare type ClientErrorKind = 'notInitialized' | 'noSession' | 'session' | 'missingField' | 'serverUnavailable' | 'http' | 'attachment' | 'cancelled' | 'chatEndPending' | 'chatEndUnconfirmed' | 'other';
70
72
 
71
73
  /**
72
74
  * Cached response of `POST /config`. Shape matches the backend wire
@@ -174,6 +176,8 @@ export declare interface JoinSessionOptions {
174
176
  chat?: ProvisionedChatJoinOptions;
175
177
  }
176
178
 
179
+ export declare const MAX_EMPTY_PAGE_CONTINUATIONS = 8;
180
+
177
181
  export declare interface Message {
178
182
  role: MessageRole;
179
183
  id: string;
@@ -259,6 +263,8 @@ export declare type MessageStatus = 'sending' | 'delivered' | 'failed';
259
263
  /** Mirrors `media-server::MuteScope`. */
260
264
  export declare type MuteScope = 'none' | 'uplink' | 'downlink' | 'both';
261
265
 
266
+ export declare function normalizeSearchField(value: string): string;
267
+
262
268
  /**
263
269
  * A non-OK orpc reply (an ERROR frame). `code` is the wire status — a base code
264
270
  * (§5) or a `0x1000+` auth code; `reason` is the server's UTF-8 message.
@@ -382,11 +388,77 @@ export declare interface SendMessagePayload {
382
388
 
383
389
  export declare type SessionControl = 'ai' | 'user';
384
390
 
391
+ export declare interface SessionDirectoryPage {
392
+ sessions: SessionSummary[];
393
+ nextCursor: string | null;
394
+ }
395
+
396
+ export declare interface SessionDirectoryPageOptions {
397
+ /** Defaults to 50; server maximum is 100. */
398
+ pageSize?: number;
399
+ cursor?: string;
400
+ search?: string;
401
+ signal?: AbortSignal;
402
+ }
403
+
404
+ export declare class SessionDirectoryPager {
405
+ private generationValue;
406
+ private query;
407
+ private live;
408
+ private value;
409
+ get generation(): number;
410
+ get search(): string | null;
411
+ get state(): Readonly<SessionDirectoryPageState>;
412
+ begin(search?: string, cached?: SessionSummary[]): number;
413
+ applyLive(summary: SessionSummary): void;
414
+ merge(generation: number, page: SessionDirectoryPage, firstPage: boolean): boolean;
415
+ canLoadMore(): boolean;
416
+ }
417
+
418
+ export declare interface SessionDirectoryPageState {
419
+ sessions: SessionSummary[];
420
+ nextCursor: string | null;
421
+ emptyContinuations: number;
422
+ }
423
+
385
424
  export declare interface SessionHistory {
386
425
  history: Message[];
387
426
  control: SessionControl;
388
427
  }
389
428
 
429
+ export declare interface SessionHistoryPage {
430
+ history: Message[];
431
+ control: SessionControl;
432
+ nextCursor: string | null;
433
+ }
434
+
435
+ export declare interface SessionHistoryPageOptions {
436
+ /** Defaults to 100; server maximum is 250. */
437
+ pageSize?: number;
438
+ cursor?: string;
439
+ signal?: AbortSignal;
440
+ }
441
+
442
+ export declare class SessionHistoryPager {
443
+ private generationValue;
444
+ private live;
445
+ private value;
446
+ get generation(): number;
447
+ get state(): Readonly<SessionHistoryPageState>;
448
+ begin(cached?: SessionHistory): number;
449
+ applyLive(message: Message): void;
450
+ removeLive(identity: Pick<Message, 'id' | 'localId'>): void;
451
+ merge(generation: number, page: SessionHistoryPage, firstPage: boolean): boolean;
452
+ canLoadMore(): boolean;
453
+ }
454
+
455
+ export declare interface SessionHistoryPageState {
456
+ history: Message[];
457
+ control: SessionControl;
458
+ nextCursor: string | null;
459
+ emptyContinuations: number;
460
+ }
461
+
390
462
  /**
391
463
  * Top-level entry point. One instance per app — see `getSessionManager()`
392
464
  * for the singleton accessor.
@@ -405,6 +477,8 @@ export declare class SessionManager {
405
477
  private attachmentBearer;
406
478
  private readonly dispatcher;
407
479
  private readonly sessions;
480
+ private readonly chatOwners;
481
+ private readonly endingChats;
408
482
  private readonly pendingUploads;
409
483
  initialize(credentials: Credentials): void;
410
484
  authenticate(): Promise<ConfigData>;
@@ -418,6 +492,8 @@ export declare class SessionManager {
418
492
  }>;
419
493
  getSessions(): Promise<SessionSummary[]>;
420
494
  getSession(sessionId: string): Promise<SessionHistory>;
495
+ getSessionsPage(options?: SessionDirectoryPageOptions): Promise<SessionDirectoryPage>;
496
+ getSessionPage(sessionId: string, options?: SessionHistoryPageOptions): Promise<SessionHistoryPage>;
421
497
  startSession(opts: StartSessionOptions): Promise<{
422
498
  sessionId: string;
423
499
  }>;
@@ -443,6 +519,9 @@ export declare class SessionManager {
443
519
  * the MoQ `ConnectOk` lands — so this method must NOT fire it for voice.
444
520
  */
445
521
  private attachSession;
522
+ private prepareChatOpen;
523
+ /** End the customer conversation; endSession remains local cleanup/Leave. */
524
+ endChat(sessionId: string): Promise<void>;
446
525
  endSession(sessionId: string): Promise<void>;
447
526
  endAllSessions(): Promise<void>;
448
527
  /**
@@ -493,6 +572,8 @@ export declare class SessionManager {
493
572
  private requireHttp;
494
573
  }
495
574
 
575
+ export declare function sessionMatchesSearch(summary: SessionSummary, normalizedSearch: string): boolean;
576
+
496
577
  export declare interface SessionSummary {
497
578
  sessionId: string;
498
579
  subject: string;