export enum ExtensionErrorCode { PermissionDenied = 4001, InvalidRequest = 4002, MethodNotFound = 4003, InternalError = 4004, Timeout = 4005, ExtensionNotFound = 4006, RateLimited = 4007, } export interface ThemeInfo { mode: 'light' | 'dark'; tokens: Record; fontFamily?: string; fontFamilyMono?: string; } export interface ExtensionRequest { source: 'xopc-extension'; extensionId: string; type: 'request'; requestId: string; method: string; params?: unknown; } export interface ExtensionEventMessage { source: 'xopc-extension'; extensionId: string; type: 'event'; event: string; data?: unknown; } export interface HostInit { source: 'xopc-host'; type: 'init'; extensionId: string; permissions: string[]; theme: ThemeInfo; locale: string; } export interface HostResponse { source: 'xopc-host'; type: 'response'; requestId: string; result?: unknown; error?: { code: number; message: string }; } export interface HostEventMessage { source: 'xopc-host'; type: 'event'; event: string; data?: unknown; } export type HostToExtensionMessage = HostInit | HostResponse | HostEventMessage; export type ExtensionToHostMessage = ExtensionRequest | ExtensionEventMessage; export type StreamHandler = (payload: unknown) => void; export interface ExtensionClient { whenReady(): Promise; theme: { getTheme(): Promise; onThemeChange(handler: (t: ThemeInfo) => void): () => void; }; agent: { sendMessage( message: string, options?: { sessionKey?: string; newSession?: boolean }, ): Promise<{ sessionKey: string }>; onStreamEvent(sessionKey: string, handler: StreamHandler): () => void; }; session: { listSessions(): Promise; navigateToSession(sessionKey: string): Promise; }; config: { getExtensionConfig>(): Promise; setExtensionConfig(patch: Record): Promise; }; storage: { get(key: string): Promise; set(key: string, value: unknown): Promise; remove(key: string): Promise; keys(): Promise; }; ui: { resize(height: number): void; showNotification(options: { type?: 'success' | 'error' | 'info'; title: string; message?: string; }): Promise; closePanel(): void; navigate(path: string): Promise; openProduct(reference: ProductReferenceLocator): Promise; /** Chat/tool widget iframe: host sends the tool result via `widget.data` after load. */ onWidgetResult(handler: (data: unknown) => void): () => void; }; events: { emit(event: string, data?: unknown): void; on(event: string, handler: (data: unknown) => void): () => void; }; onDispose(handler: () => void): () => void; onDidChangeVisibility(handler: (visible: boolean) => void): () => void; } import type { ProductReferenceLocator } from '@xopcai/gateway-contract';