@csntgao/ai-employee-client 0.15.6 → 0.16.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 +169 -2
- package/dist/index.js +672 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -466,6 +466,12 @@ declare class CustomerSupportClient {
|
|
|
466
466
|
|
|
467
467
|
type NotificationReadStatus = 'unread' | 'read';
|
|
468
468
|
type NotificationContentType = 'text' | 'markdown';
|
|
469
|
+
type ConversationNotificationChannel = 'ai_employee' | 'customer_support';
|
|
470
|
+
interface NotificationConversationReference {
|
|
471
|
+
channel: ConversationNotificationChannel;
|
|
472
|
+
messageId: string;
|
|
473
|
+
messageSequence?: string;
|
|
474
|
+
}
|
|
469
475
|
interface NotificationSource {
|
|
470
476
|
type: string;
|
|
471
477
|
code: string;
|
|
@@ -488,6 +494,8 @@ interface NotificationAttachment {
|
|
|
488
494
|
}
|
|
489
495
|
interface NotificationDto {
|
|
490
496
|
id: string;
|
|
497
|
+
/** Authoritative application that owns and can open this notification. */
|
|
498
|
+
applicationName: string;
|
|
491
499
|
type: string;
|
|
492
500
|
typeName: string;
|
|
493
501
|
title: string;
|
|
@@ -496,6 +504,8 @@ interface NotificationDto {
|
|
|
496
504
|
contentType: NotificationContentType;
|
|
497
505
|
priority: string;
|
|
498
506
|
source: NotificationSource | null;
|
|
507
|
+
/** Valid conversation_message or customer_support_message payload with a matching channel. */
|
|
508
|
+
conversation?: NotificationConversationReference;
|
|
499
509
|
resources: readonly NotificationResource[];
|
|
500
510
|
attachments: readonly NotificationAttachment[];
|
|
501
511
|
readStatus: NotificationReadStatus;
|
|
@@ -548,6 +558,9 @@ type NotificationRealtimeChange = {
|
|
|
548
558
|
};
|
|
549
559
|
interface NotificationCenterTransport {
|
|
550
560
|
listInbox(query: NotificationInboxQuery): Promise<NotificationInboxResult>;
|
|
561
|
+
getNotification(params: {
|
|
562
|
+
notificationId: string;
|
|
563
|
+
}): Promise<NotificationDto>;
|
|
551
564
|
getUnreadCount(params: {
|
|
552
565
|
applicationName: string;
|
|
553
566
|
}): Promise<{
|
|
@@ -581,7 +594,7 @@ interface NotificationCenterClientOptions {
|
|
|
581
594
|
readStatus?: 'all' | 'unread' | 'read';
|
|
582
595
|
preferredTypeOrder?: readonly string[];
|
|
583
596
|
}
|
|
584
|
-
type NotificationCenterErrorCode = 'INVALID_CONFIGURATION' | 'INBOX_LOAD_FAILED' | 'MARK_READ_FAILED' | 'DOWNLOAD_FAILED' | 'CLIENT_DESTROYED';
|
|
597
|
+
type NotificationCenterErrorCode = 'INVALID_CONFIGURATION' | 'NAVIGATION_NOT_CONFIGURED' | 'INBOX_LOAD_FAILED' | 'MARK_READ_FAILED' | 'DOWNLOAD_FAILED' | 'CLIENT_DESTROYED' | 'NOTIFICATION_FRAGMENT_INVALID' | 'NOTIFICATION_NOT_FOUND' | 'NOTIFICATION_APPLICATION_MISSING' | 'NOTIFICATION_APPLICATION_MISMATCH' | 'NOTIFICATION_APPLICATION_UNAVAILABLE' | 'NOTIFICATION_HANDLER_UNAVAILABLE' | 'NOTIFICATION_RESOURCE_INVALID' | 'NOTIFICATION_LAUNCH_BLOCKED' | 'NOTIFICATION_LAUNCH_FAILED' | 'NOTIFICATION_OPEN_FAILED';
|
|
585
598
|
interface NotificationCenterErrorDetail {
|
|
586
599
|
code: NotificationCenterErrorCode;
|
|
587
600
|
message: string;
|
|
@@ -672,6 +685,7 @@ declare class NotificationCenterClient {
|
|
|
672
685
|
private setAvailableTypes;
|
|
673
686
|
private refreshUnreadCount;
|
|
674
687
|
private applyRealtimeChange;
|
|
688
|
+
private resyncUnreadInbox;
|
|
675
689
|
private syncRealtimeUnreadCount;
|
|
676
690
|
private applyRead;
|
|
677
691
|
private refreshFromRealtime;
|
|
@@ -682,6 +696,159 @@ declare class NotificationCenterClient {
|
|
|
682
696
|
private assertUsable;
|
|
683
697
|
}
|
|
684
698
|
|
|
699
|
+
type UserRealtimeConnectionState = 'idle' | 'connecting' | 'authenticating' | 'connected' | 'reconnecting' | 'stopped' | 'destroyed';
|
|
700
|
+
interface UserRealtimeReconnectOptions {
|
|
701
|
+
initialDelayMs: number;
|
|
702
|
+
maximumDelayMs: number;
|
|
703
|
+
factor: number;
|
|
704
|
+
jitter: number;
|
|
705
|
+
}
|
|
706
|
+
interface UserRealtimeCursorStore {
|
|
707
|
+
load(channel: string): string | null | undefined | Promise<string | null | undefined>;
|
|
708
|
+
save(channel: string, cursor: string): void | Promise<void>;
|
|
709
|
+
clear(channel: string): void | Promise<void>;
|
|
710
|
+
}
|
|
711
|
+
type UserRealtimeWebSocketFactory = (url: string) => WebSocket;
|
|
712
|
+
interface UserRealtimeClientOptions {
|
|
713
|
+
realtimeUrl: string;
|
|
714
|
+
getAccessToken(): string | Promise<string>;
|
|
715
|
+
requestedChannels: readonly string[];
|
|
716
|
+
cursorStore?: UserRealtimeCursorStore | null;
|
|
717
|
+
reconnect?: Partial<UserRealtimeReconnectOptions>;
|
|
718
|
+
webSocketFactory?: UserRealtimeWebSocketFactory;
|
|
719
|
+
/** Primarily useful for deterministic tests. Production heartbeats are never faster than 5s. */
|
|
720
|
+
minimumHeartbeatMs?: number;
|
|
721
|
+
/** Per-channel in-memory event ID bound. */
|
|
722
|
+
maximumSeenEventIds?: number;
|
|
723
|
+
}
|
|
724
|
+
type UserRealtimeErrorCode = 'INVALID_CONFIGURATION' | 'TOKEN_UNAVAILABLE' | 'WEBSOCKET_UNAVAILABLE' | 'WEBSOCKET_ERROR' | 'AUTHENTICATION_FAILED' | 'REALTIME_UNAVAILABLE' | 'CHANNEL_UNAVAILABLE' | 'PROTOCOL_ERROR' | 'CURSOR_STORE_FAILED' | 'EVENT_HANDLER_FAILED' | 'CLIENT_DESTROYED';
|
|
725
|
+
interface UserRealtimeErrorDetail {
|
|
726
|
+
code: UserRealtimeErrorCode;
|
|
727
|
+
message: string;
|
|
728
|
+
recoverable: boolean;
|
|
729
|
+
channel?: string;
|
|
730
|
+
}
|
|
731
|
+
interface UserRealtimeChannelEventDetail {
|
|
732
|
+
channel: string;
|
|
733
|
+
/** Raw `realtime_event.event` payload. The client does not parse business DTOs. */
|
|
734
|
+
event: unknown;
|
|
735
|
+
eventId: string;
|
|
736
|
+
cursor: string;
|
|
737
|
+
/** Monotonically increases for every newly delivered event within this channel. */
|
|
738
|
+
sequence: number;
|
|
739
|
+
}
|
|
740
|
+
interface UserRealtimeResyncRequiredDetail {
|
|
741
|
+
channel: string;
|
|
742
|
+
reason: string;
|
|
743
|
+
latestEventId: string;
|
|
744
|
+
/** Channel event sequence observed when the resync signal arrived. */
|
|
745
|
+
sequence: number;
|
|
746
|
+
/** Per-channel generation used to reject stale resync acknowledgements. */
|
|
747
|
+
generation: number;
|
|
748
|
+
}
|
|
749
|
+
interface UserRealtimeClientEventMap {
|
|
750
|
+
ready: {
|
|
751
|
+
channels: readonly string[];
|
|
752
|
+
};
|
|
753
|
+
'channel-event': UserRealtimeChannelEventDetail;
|
|
754
|
+
'resync-required': UserRealtimeResyncRequiredDetail;
|
|
755
|
+
'state-change': {
|
|
756
|
+
previous: UserRealtimeConnectionState;
|
|
757
|
+
current: UserRealtimeConnectionState;
|
|
758
|
+
};
|
|
759
|
+
error: UserRealtimeErrorDetail;
|
|
760
|
+
}
|
|
761
|
+
type UserRealtimeClientListener<K extends keyof UserRealtimeClientEventMap> = (detail: UserRealtimeClientEventMap[K]) => void;
|
|
762
|
+
interface UserRealtimeRestartOptions {
|
|
763
|
+
clearCursors?: boolean;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
declare class UserRealtimeClientError extends Error {
|
|
767
|
+
readonly code: UserRealtimeErrorCode;
|
|
768
|
+
constructor(code: UserRealtimeErrorCode, message: string);
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Framework-independent owner of one authenticated `/api/user-realtime/ws` connection.
|
|
772
|
+
*
|
|
773
|
+
* Business payloads remain opaque. Hosts decide which components or stores receive each
|
|
774
|
+
* channel event and own all HTTP resynchronization work.
|
|
775
|
+
*/
|
|
776
|
+
declare class UserRealtimeClient {
|
|
777
|
+
readonly requestedChannels: readonly string[];
|
|
778
|
+
private readonly realtimeUrl;
|
|
779
|
+
private readonly getAccessToken;
|
|
780
|
+
private readonly cursorStore;
|
|
781
|
+
private readonly reconnectOptions;
|
|
782
|
+
private readonly webSocketFactory;
|
|
783
|
+
private readonly minimumHeartbeatMs;
|
|
784
|
+
private readonly maximumSeenEventIds;
|
|
785
|
+
private readonly listeners;
|
|
786
|
+
private readonly cursors;
|
|
787
|
+
private readonly cursorWriteChains;
|
|
788
|
+
private readonly seenEventIds;
|
|
789
|
+
private readonly channelSequences;
|
|
790
|
+
private readonly pendingResyncs;
|
|
791
|
+
private readonly resyncGenerations;
|
|
792
|
+
private socket;
|
|
793
|
+
private messageChain;
|
|
794
|
+
private reconnectTimer;
|
|
795
|
+
private heartbeatTimer;
|
|
796
|
+
private startPromise;
|
|
797
|
+
private currentState;
|
|
798
|
+
private socketGeneration;
|
|
799
|
+
private lifecycleGeneration;
|
|
800
|
+
private reconnectAttempt;
|
|
801
|
+
private deliverySequence;
|
|
802
|
+
private shouldReconnect;
|
|
803
|
+
private destroyed;
|
|
804
|
+
private socketAuthenticationFailure;
|
|
805
|
+
constructor(options: UserRealtimeClientOptions);
|
|
806
|
+
get connectionState(): UserRealtimeConnectionState;
|
|
807
|
+
get eventSequence(): number;
|
|
808
|
+
get isDestroyed(): boolean;
|
|
809
|
+
on<K extends keyof UserRealtimeClientEventMap>(type: K, listener: UserRealtimeClientListener<K>): () => void;
|
|
810
|
+
start(): Promise<void>;
|
|
811
|
+
stop(): void;
|
|
812
|
+
restart(options?: UserRealtimeRestartOptions): Promise<void>;
|
|
813
|
+
clearCursors(): Promise<void>;
|
|
814
|
+
/**
|
|
815
|
+
* Confirm that Host HTTP state was restored for a previously emitted resync signal.
|
|
816
|
+
* Stale confirmations never overwrite a cursor advanced by a newer realtime event.
|
|
817
|
+
*/
|
|
818
|
+
confirmResync(detail: UserRealtimeResyncRequiredDetail): Promise<boolean>;
|
|
819
|
+
destroy(): void;
|
|
820
|
+
private loadCursors;
|
|
821
|
+
private openSocket;
|
|
822
|
+
private authenticate;
|
|
823
|
+
private handleSocketData;
|
|
824
|
+
private handleServerMessage;
|
|
825
|
+
private handleReady;
|
|
826
|
+
private handleRealtimeEvent;
|
|
827
|
+
private handleResyncRequired;
|
|
828
|
+
private handleChannelError;
|
|
829
|
+
private handleAuthenticationError;
|
|
830
|
+
private startHeartbeat;
|
|
831
|
+
private handleSocketClose;
|
|
832
|
+
private scheduleReconnect;
|
|
833
|
+
private rememberEventId;
|
|
834
|
+
private hasSeenEvent;
|
|
835
|
+
private rememberCursor;
|
|
836
|
+
private flushCursorWrite;
|
|
837
|
+
private clearStoredCursor;
|
|
838
|
+
private stopConnection;
|
|
839
|
+
private closeCurrentSocket;
|
|
840
|
+
private clearReconnectTimer;
|
|
841
|
+
private clearHeartbeatTimer;
|
|
842
|
+
private clearDeliveryState;
|
|
843
|
+
private isCurrentSocket;
|
|
844
|
+
private isCurrentLifecycle;
|
|
845
|
+
private setState;
|
|
846
|
+
private emitError;
|
|
847
|
+
private emit;
|
|
848
|
+
private emitSafely;
|
|
849
|
+
private assertUsable;
|
|
850
|
+
}
|
|
851
|
+
|
|
685
852
|
type JsonRecord = Record<string, unknown>;
|
|
686
853
|
interface AuthenticateFrame {
|
|
687
854
|
type: 'authenticate';
|
|
@@ -738,4 +905,4 @@ declare function parseJsonRecord(raw: string): JsonRecord | null;
|
|
|
738
905
|
declare function parseAiEmployeeEvent(raw: unknown): ParsedAiEmployeeEvent;
|
|
739
906
|
declare function hashText(value: string): string;
|
|
740
907
|
|
|
741
|
-
export { type AiEmployeeAssistantAction, type AiEmployeeAttachmentReference, AiEmployeeClient, AiEmployeeClientError, type AiEmployeeClientErrorDetail, type AiEmployeeClientEventMap, type AiEmployeeClientListener, type AiEmployeeClientOptions, type AiEmployeeClientStartResult, type AiEmployeeConnectionState, type AiEmployeeErrorCode, type AiEmployeeFirstMessageOptions, type AiEmployeeFirstMessageRequest, type AiEmployeeFirstMessageRequestState, type AiEmployeeFirstMessageRequestStore, type AiEmployeeFirstMessageResult, type AiEmployeeMessage, type AiEmployeeMessageRole, type AiEmployeeReconnectOptions, type AiEmployeeSessionSummary, type AiEmployeeTransport, AiEmployeeTransportError, type AiEmployeeTransportErrorCode, type AiEmployeeWebSocketFactory, type AuthenticateFrame, type CustomerSupportAgent, type CustomerSupportAttachment, type CustomerSupportAttachmentDownloadRequest, CustomerSupportClient, CustomerSupportClientError, type CustomerSupportClientEventMap, type CustomerSupportClientListener, type CustomerSupportClientOptions, type CustomerSupportCreateSessionRequest, type CustomerSupportCreateSessionResult, type CustomerSupportErrorCode, type CustomerSupportErrorDetail, type CustomerSupportHandoffRequest, type CustomerSupportHandoffResult, type CustomerSupportMessage, type CustomerSupportMessagePage, type CustomerSupportSenderType, type CustomerSupportSession, type CustomerSupportSessionStatus, type CustomerSupportTransport, type NotificationAttachment, NotificationCenterClient, NotificationCenterClientError, type NotificationCenterClientEventMap, type NotificationCenterClientListener, type NotificationCenterClientOptions, type NotificationCenterErrorCode, type NotificationCenterErrorDetail, type NotificationCenterTransport, type NotificationContentType, type NotificationDto, type NotificationInboxQuery, type NotificationInboxResult, type NotificationMarkAllReadResult, type NotificationMarkReadResult, type NotificationReadStatus, type NotificationRealtimeChange, type NotificationResource, type NotificationSource, type NotificationTypeSummary, type OpenCustomerSupportAssistantAction, type OpenFileAssistantAction, type ParsedAiEmployeeAssistantContent, type ParsedAiEmployeeEvent, type ParsedAssistantMessageStreamReference, type ParsedAssistantStreamEvent, type ParsedSessionMessage, type PingFrame, type SessionSubscriptionFrame, createAuthenticateFrame, createPingFrame, createSubscriptionFrame, hashText, isUuidV4, parseAiEmployeeAssistantContent, parseAiEmployeeEvent, parseJsonRecord };
|
|
908
|
+
export { type AiEmployeeAssistantAction, type AiEmployeeAttachmentReference, AiEmployeeClient, AiEmployeeClientError, type AiEmployeeClientErrorDetail, type AiEmployeeClientEventMap, type AiEmployeeClientListener, type AiEmployeeClientOptions, type AiEmployeeClientStartResult, type AiEmployeeConnectionState, type AiEmployeeErrorCode, type AiEmployeeFirstMessageOptions, type AiEmployeeFirstMessageRequest, type AiEmployeeFirstMessageRequestState, type AiEmployeeFirstMessageRequestStore, type AiEmployeeFirstMessageResult, type AiEmployeeMessage, type AiEmployeeMessageRole, type AiEmployeeReconnectOptions, type AiEmployeeSessionSummary, type AiEmployeeTransport, AiEmployeeTransportError, type AiEmployeeTransportErrorCode, type AiEmployeeWebSocketFactory, type AuthenticateFrame, type ConversationNotificationChannel, type CustomerSupportAgent, type CustomerSupportAttachment, type CustomerSupportAttachmentDownloadRequest, CustomerSupportClient, CustomerSupportClientError, type CustomerSupportClientEventMap, type CustomerSupportClientListener, type CustomerSupportClientOptions, type CustomerSupportCreateSessionRequest, type CustomerSupportCreateSessionResult, type CustomerSupportErrorCode, type CustomerSupportErrorDetail, type CustomerSupportHandoffRequest, type CustomerSupportHandoffResult, type CustomerSupportMessage, type CustomerSupportMessagePage, type CustomerSupportSenderType, type CustomerSupportSession, type CustomerSupportSessionStatus, type CustomerSupportTransport, type NotificationAttachment, NotificationCenterClient, NotificationCenterClientError, type NotificationCenterClientEventMap, type NotificationCenterClientListener, type NotificationCenterClientOptions, type NotificationCenterErrorCode, type NotificationCenterErrorDetail, type NotificationCenterTransport, type NotificationContentType, type NotificationConversationReference, type NotificationDto, type NotificationInboxQuery, type NotificationInboxResult, type NotificationMarkAllReadResult, type NotificationMarkReadResult, type NotificationReadStatus, type NotificationRealtimeChange, type NotificationResource, type NotificationSource, type NotificationTypeSummary, type OpenCustomerSupportAssistantAction, type OpenFileAssistantAction, type ParsedAiEmployeeAssistantContent, type ParsedAiEmployeeEvent, type ParsedAssistantMessageStreamReference, type ParsedAssistantStreamEvent, type ParsedSessionMessage, type PingFrame, type SessionSubscriptionFrame, type UserRealtimeChannelEventDetail, UserRealtimeClient, UserRealtimeClientError, type UserRealtimeClientEventMap, type UserRealtimeClientListener, type UserRealtimeClientOptions, type UserRealtimeConnectionState, type UserRealtimeCursorStore, type UserRealtimeErrorCode, type UserRealtimeErrorDetail, type UserRealtimeReconnectOptions, type UserRealtimeRestartOptions, type UserRealtimeResyncRequiredDetail, type UserRealtimeWebSocketFactory, createAuthenticateFrame, createPingFrame, createSubscriptionFrame, hashText, isUuidV4, parseAiEmployeeAssistantContent, parseAiEmployeeEvent, parseJsonRecord };
|