@lidia.poet/sdk 0.2.1 → 0.3.1

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
@@ -5,7 +5,7 @@ A comprehensive TypeScript SDK for the Lidia API, providing type-safe access to
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @lidia/sdk
8
+ npm install @lidia.poet/sdk
9
9
  ```
10
10
 
11
11
  ## Quick Start
@@ -1,4 +1,5 @@
1
1
  import { LidiaClient } from './client/LidiaClient';
2
+ import { LidiaWebSocket, LidiaWebSocketConfig } from './client/LidiaWebSocket';
2
3
  import { LidiaConfig } from './types/config';
3
4
  import { LoginCredentials, AuthTokens } from './types/auth';
4
5
  import { AuthorizationService } from './services/AuthorizationService';
@@ -37,8 +38,11 @@ export declare class LidiaSDK {
37
38
  readonly users: UserService;
38
39
  readonly webSearches: WebSearchService;
39
40
  readonly workflows: WorkflowService;
41
+ /** WebSocket client for real-time events (available after connectWebSocket()) */
42
+ ws: LidiaWebSocket | null;
43
+ private mergedConfig;
40
44
  private authInitPromise?;
41
- constructor(config: LidiaConfig);
45
+ constructor(config?: LidiaConfig);
42
46
  private shouldInitializeAuth;
43
47
  private mergeConfigWithEnv;
44
48
  private initializeAuthentication;
@@ -58,5 +62,12 @@ export declare class LidiaSDK {
58
62
  updateConfig(config: Partial<LidiaConfig>): void;
59
63
  /** Get the underlying HTTP client for advanced usage */
60
64
  getClient(): LidiaClient;
65
+ /**
66
+ * Connect to Lidia WebSocket for real-time events (streaming messages, document updates, etc.).
67
+ * Requires authentication (call login() or waitForAuthentication() first).
68
+ */
69
+ connectWebSocket(options?: Partial<Pick<LidiaWebSocketConfig, 'pingInterval' | 'reconnectDelay' | 'maxReconnectAttempts'>>): LidiaWebSocket;
70
+ /** Disconnect WebSocket */
71
+ disconnectWebSocket(): void;
61
72
  }
62
73
  //# sourceMappingURL=LidiaSDK.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file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UAAU,GAAG,SAAS;IAIvC,+BAA+B;IAC/B,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAIhD,wDAAwD;IACxD,SAAS,IAAI,WAAW;IAIxB;;;OAGG;IACH,gBAAgB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,cAAc,GAAG,gBAAgB,GAAG,sBAAsB,CAAC,CAAC,GAAG,cAAc;IA8B3I,2BAA2B;IAC3B,mBAAmB,IAAI,IAAI;CAM5B"}
@@ -0,0 +1,62 @@
1
+ import { LidiaWsEvent, LidiaWsEventMap, LidiaWsAction } from '../types/ws';
2
+ type WsListener<T> = (event: T) => void;
3
+ type WsState = 'disconnected' | 'connecting' | 'connected';
4
+ export interface LidiaWebSocketConfig {
5
+ /** WebSocket endpoint URL (wss://ws.lidiatech.ai) */
6
+ wsUrl: string;
7
+ /** JWT access token for authentication */
8
+ accessToken: string;
9
+ /** Enable debug logging */
10
+ debug?: boolean | undefined;
11
+ /** Ping interval in ms (default: 30000) */
12
+ pingInterval?: number | undefined;
13
+ /** Reconnect delay in ms (default: 2000) */
14
+ reconnectDelay?: number | undefined;
15
+ /** Max reconnect attempts (default: 10, 0 = disabled) */
16
+ maxReconnectAttempts?: number | undefined;
17
+ }
18
+ export declare class LidiaWebSocket {
19
+ private ws;
20
+ private config;
21
+ private state;
22
+ private pingTimer;
23
+ private reconnectTimer;
24
+ private reconnectAttempts;
25
+ private intentionalClose;
26
+ private listeners;
27
+ private wildcardListeners;
28
+ constructor(config: LidiaWebSocketConfig);
29
+ /** Current connection state */
30
+ getState(): WsState;
31
+ /** Connect to the WebSocket server */
32
+ connect(): void;
33
+ /** Disconnect from the WebSocket server */
34
+ disconnect(): void;
35
+ /** Update the access token (e.g. after refresh) */
36
+ updateToken(accessToken: string): void;
37
+ /** Subscribe to a specific event type */
38
+ on<A extends LidiaWsAction>(action: A, listener: WsListener<LidiaWsEventMap[A]>): () => void;
39
+ /** Subscribe to all events */
40
+ onAny(listener: WsListener<LidiaWsEvent>): () => void;
41
+ /** Subscribe to internal lifecycle events */
42
+ onState(event: '_connected' | '_disconnected' | '_error', listener: () => void): () => void;
43
+ /**
44
+ * Wait for a specific event matching a filter.
45
+ * Resolves with the first matching event, or rejects on timeout.
46
+ */
47
+ waitFor<A extends LidiaWsAction>(action: A, filter?: (event: LidiaWsEventMap[A]) => boolean, timeoutMs?: number): Promise<LidiaWsEventMap[A]>;
48
+ /**
49
+ * Collect streaming delta events for a specific message into an AsyncGenerator.
50
+ * Yields each delta text chunk and returns the full accumulated text.
51
+ */
52
+ streamMessage(conversationId: string, messageId: string, timeoutMs?: number): AsyncGenerator<string, string, undefined>;
53
+ private handleMessage;
54
+ private emit;
55
+ private startPing;
56
+ private stopPing;
57
+ private cleanup;
58
+ private scheduleReconnect;
59
+ private log;
60
+ }
61
+ export {};
62
+ //# sourceMappingURL=LidiaWebSocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LidiaWebSocket.d.ts","sourceRoot":"","sources":["../../src/client/LidiaWebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3E,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACxC,KAAK,OAAO,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,yDAA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tB,SAAS,EAAE,MAAM,EACjB,SAAS,SAAU,GAClB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC;IA6F5C,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,GAAG;CAKZ"}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  export { LidiaSDK } from './LidiaSDK';
9
9
  export { LidiaClient } from './client/LidiaClient';
10
+ export { LidiaWebSocket } from './client/LidiaWebSocket';
11
+ export type { LidiaWebSocketConfig } from './client/LidiaWebSocket';
10
12
  export { LidiaConfig } from './types/config';
11
13
  export { AuthorizationService } from './services/AuthorizationService';
12
14
  export { CaseService } from './services/CaseService';
@@ -41,6 +43,7 @@ export * from './types/smartAnswer';
41
43
  export * from './types/user';
42
44
  export * from './types/webSearch';
43
45
  export * from './types/workflow';
46
+ export * from './types/ws';
44
47
  export { LidiaError } from './errors/LidiaError';
45
48
  export { NetworkError } from './errors/NetworkError';
46
49
  export { ValidationError } from './errors/ValidationError';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,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,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.esm.js CHANGED
@@ -282,6 +282,312 @@ var LidiaClient = class {
282
282
  }
283
283
  };
284
284
 
285
+ // src/client/LidiaWebSocket.ts
286
+ var LidiaWebSocket = class {
287
+ constructor(config) {
288
+ this.ws = null;
289
+ this.state = "disconnected";
290
+ this.pingTimer = null;
291
+ this.reconnectTimer = null;
292
+ this.reconnectAttempts = 0;
293
+ this.intentionalClose = false;
294
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
295
+ this.listeners = /* @__PURE__ */ new Map();
296
+ this.wildcardListeners = /* @__PURE__ */ new Set();
297
+ this.config = {
298
+ wsUrl: config.wsUrl,
299
+ accessToken: config.accessToken,
300
+ debug: config.debug ?? false,
301
+ pingInterval: config.pingInterval ?? 3e4,
302
+ reconnectDelay: config.reconnectDelay ?? 2e3,
303
+ maxReconnectAttempts: config.maxReconnectAttempts ?? 10
304
+ };
305
+ }
306
+ /** Current connection state */
307
+ getState() {
308
+ return this.state;
309
+ }
310
+ /** Connect to the WebSocket server */
311
+ connect() {
312
+ if (this.state !== "disconnected") return;
313
+ this.intentionalClose = false;
314
+ this.state = "connecting";
315
+ this.log("Connecting to", this.config.wsUrl);
316
+ this.ws = new WebSocket(this.config.wsUrl, [
317
+ "Authorization",
318
+ this.config.accessToken
319
+ ]);
320
+ this.ws.onopen = () => {
321
+ this.state = "connected";
322
+ this.reconnectAttempts = 0;
323
+ this.startPing();
324
+ this.log("Connected");
325
+ this.emit("_connected", {});
326
+ };
327
+ this.ws.onmessage = (event) => {
328
+ this.handleMessage(event);
329
+ };
330
+ this.ws.onclose = () => {
331
+ this.cleanup();
332
+ this.log("Disconnected");
333
+ this.emit("_disconnected", {});
334
+ if (!this.intentionalClose) {
335
+ this.scheduleReconnect();
336
+ }
337
+ };
338
+ this.ws.onerror = (error) => {
339
+ this.log("WebSocket error", error);
340
+ this.emit("_error", { error });
341
+ };
342
+ }
343
+ /** Disconnect from the WebSocket server */
344
+ disconnect() {
345
+ this.intentionalClose = true;
346
+ this.cleanup();
347
+ if (this.ws) {
348
+ this.ws.close();
349
+ this.ws = null;
350
+ }
351
+ this.state = "disconnected";
352
+ }
353
+ /** Update the access token (e.g. after refresh) */
354
+ updateToken(accessToken) {
355
+ this.config.accessToken = accessToken;
356
+ if (this.state === "connected") {
357
+ this.disconnect();
358
+ this.connect();
359
+ }
360
+ }
361
+ /** Subscribe to a specific event type */
362
+ on(action, listener) {
363
+ if (!this.listeners.has(action)) {
364
+ this.listeners.set(action, /* @__PURE__ */ new Set());
365
+ }
366
+ this.listeners.get(action).add(listener);
367
+ return () => {
368
+ var _a;
369
+ (_a = this.listeners.get(action)) == null ? void 0 : _a.delete(listener);
370
+ };
371
+ }
372
+ /** Subscribe to all events */
373
+ onAny(listener) {
374
+ this.wildcardListeners.add(listener);
375
+ return () => {
376
+ this.wildcardListeners.delete(listener);
377
+ };
378
+ }
379
+ /** Subscribe to internal lifecycle events */
380
+ onState(event, listener) {
381
+ const wrappedListener = listener;
382
+ if (!this.listeners.has(event)) {
383
+ this.listeners.set(event, /* @__PURE__ */ new Set());
384
+ }
385
+ this.listeners.get(event).add(wrappedListener);
386
+ return () => {
387
+ var _a;
388
+ (_a = this.listeners.get(event)) == null ? void 0 : _a.delete(wrappedListener);
389
+ };
390
+ }
391
+ /**
392
+ * Wait for a specific event matching a filter.
393
+ * Resolves with the first matching event, or rejects on timeout.
394
+ */
395
+ waitFor(action, filter, timeoutMs = 6e4) {
396
+ return new Promise((resolve, reject) => {
397
+ const timer = setTimeout(() => {
398
+ unsub();
399
+ reject(new Error(`Timeout waiting for event "${action}"`));
400
+ }, timeoutMs);
401
+ const unsub = this.on(action, (event) => {
402
+ if (!filter || filter(event)) {
403
+ clearTimeout(timer);
404
+ unsub();
405
+ resolve(event);
406
+ }
407
+ });
408
+ });
409
+ }
410
+ /**
411
+ * Collect streaming delta events for a specific message into an AsyncGenerator.
412
+ * Yields each delta text chunk and returns the full accumulated text.
413
+ */
414
+ async *streamMessage(conversationId, messageId, timeoutMs = 12e4) {
415
+ let accumulated = "";
416
+ let done = false;
417
+ let error = null;
418
+ const chunks = [];
419
+ let resolve = null;
420
+ const onChunk = () => {
421
+ if (resolve) {
422
+ resolve();
423
+ resolve = null;
424
+ }
425
+ };
426
+ const matchesMessage = (e) => e.conversationId === conversationId && e.messageId === messageId;
427
+ const unsubs = [
428
+ this.on("streaming.message.delta", (e) => {
429
+ if (matchesMessage(e)) {
430
+ chunks.push(e.eventText);
431
+ onChunk();
432
+ }
433
+ }),
434
+ this.on("streaming.message.stop", (e) => {
435
+ if (matchesMessage(e)) {
436
+ done = true;
437
+ onChunk();
438
+ }
439
+ }),
440
+ this.on("streaming.message.error", (e) => {
441
+ if (matchesMessage(e)) {
442
+ error = e.error;
443
+ done = true;
444
+ onChunk();
445
+ }
446
+ }),
447
+ this.on("streaming.smart_answer.delta", (e) => {
448
+ if (matchesMessage(e)) {
449
+ chunks.push(e.eventText);
450
+ onChunk();
451
+ }
452
+ }),
453
+ this.on("streaming.smart_answer.stop", (e) => {
454
+ if (matchesMessage(e)) {
455
+ done = true;
456
+ onChunk();
457
+ }
458
+ }),
459
+ this.on("streaming.smart_answer.error", (e) => {
460
+ if (matchesMessage(e)) {
461
+ error = e.eventText;
462
+ done = true;
463
+ onChunk();
464
+ }
465
+ }),
466
+ this.on("streaming.legal_search.message_delta", (e) => {
467
+ if (matchesMessage(e)) {
468
+ chunks.push(e.eventText);
469
+ onChunk();
470
+ }
471
+ }),
472
+ this.on("streaming.legal_search.stop", (e) => {
473
+ if (matchesMessage(e)) {
474
+ done = true;
475
+ onChunk();
476
+ }
477
+ }),
478
+ this.on("streaming.legal_search.error", (e) => {
479
+ if (matchesMessage(e)) {
480
+ done = true;
481
+ error = "Legal search error";
482
+ onChunk();
483
+ }
484
+ }),
485
+ this.on("conversation.message.new", (e) => {
486
+ if (matchesMessage(e)) {
487
+ done = true;
488
+ onChunk();
489
+ }
490
+ })
491
+ ];
492
+ const timeout = setTimeout(() => {
493
+ error = "Stream timeout";
494
+ done = true;
495
+ onChunk();
496
+ }, timeoutMs);
497
+ try {
498
+ while (!done) {
499
+ if (chunks.length === 0) {
500
+ await new Promise((r) => {
501
+ resolve = r;
502
+ });
503
+ }
504
+ while (chunks.length > 0) {
505
+ const chunk = chunks.shift();
506
+ accumulated += chunk;
507
+ yield chunk;
508
+ }
509
+ }
510
+ if (error) {
511
+ throw new Error(error);
512
+ }
513
+ return accumulated;
514
+ } finally {
515
+ clearTimeout(timeout);
516
+ unsubs.forEach((unsub) => unsub());
517
+ }
518
+ }
519
+ // ── Private ──────────────────────────────────────────────
520
+ handleMessage(event) {
521
+ let data;
522
+ try {
523
+ data = JSON.parse(String(event.data));
524
+ } catch {
525
+ this.log("Failed to parse WS message:", event.data);
526
+ return;
527
+ }
528
+ if (!data.action) return;
529
+ this.log("Event:", data.action);
530
+ const actionListeners = this.listeners.get(data.action);
531
+ if (actionListeners) {
532
+ for (const listener of actionListeners) {
533
+ listener(data);
534
+ }
535
+ }
536
+ for (const listener of this.wildcardListeners) {
537
+ listener(data);
538
+ }
539
+ }
540
+ emit(action, event) {
541
+ const actionListeners = this.listeners.get(action);
542
+ if (actionListeners) {
543
+ for (const listener of actionListeners) {
544
+ listener(event);
545
+ }
546
+ }
547
+ }
548
+ startPing() {
549
+ this.stopPing();
550
+ this.pingTimer = setInterval(() => {
551
+ var _a;
552
+ if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
553
+ this.ws.send(JSON.stringify({ action: "ping" }));
554
+ }
555
+ }, this.config.pingInterval);
556
+ }
557
+ stopPing() {
558
+ if (this.pingTimer) {
559
+ clearInterval(this.pingTimer);
560
+ this.pingTimer = null;
561
+ }
562
+ }
563
+ cleanup() {
564
+ this.stopPing();
565
+ if (this.reconnectTimer) {
566
+ clearTimeout(this.reconnectTimer);
567
+ this.reconnectTimer = null;
568
+ }
569
+ }
570
+ scheduleReconnect() {
571
+ if (this.config.maxReconnectAttempts === 0) return;
572
+ if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
573
+ this.log("Max reconnect attempts reached");
574
+ return;
575
+ }
576
+ this.reconnectAttempts++;
577
+ const delay = this.config.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
578
+ this.log(`Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`);
579
+ this.reconnectTimer = setTimeout(() => {
580
+ this.state = "disconnected";
581
+ this.connect();
582
+ }, delay);
583
+ }
584
+ log(...args) {
585
+ if (this.config.debug) {
586
+ console.log("[Lidia WS]", ...args);
587
+ }
588
+ }
589
+ };
590
+
285
591
  // src/services/AuthorizationService.ts
286
592
  var AuthorizationService = class {
287
593
  // Refresh 5 minutes before expiry
@@ -875,6 +1181,11 @@ var LegisratioService = class {
875
1181
  var MessageService = class {
876
1182
  constructor(client) {
877
1183
  this.client = client;
1184
+ this.ws = null;
1185
+ }
1186
+ /** Inject WebSocket reference (called by LidiaSDK) */
1187
+ setWebSocket(ws) {
1188
+ this.ws = ws;
878
1189
  }
879
1190
  /** List messages with pagination */
880
1191
  async find(params) {
@@ -909,10 +1220,45 @@ var MessageService = class {
909
1220
  async getUrlRegistry(id, urlRegistryKey) {
910
1221
  return this.client.get(`/messages/${id}/url-registry/${urlRegistryKey}`);
911
1222
  }
1223
+ /** Get message status (lightweight polling endpoint) */
1224
+ async getStatus(id) {
1225
+ return this.client.get(`/messages/${id}/status`);
1226
+ }
912
1227
  /** Export a specific message */
913
1228
  async export(id, exportType, exportMedium) {
914
1229
  return this.client.post(`/messages/${id}/export/${exportType}/${exportMedium}`);
915
1230
  }
1231
+ /**
1232
+ * Create a message and stream the response via WebSocket.
1233
+ * Yields each text chunk as it arrives. The return value is the full accumulated text.
1234
+ *
1235
+ * Requires an active WebSocket connection (sdk.connectWebSocket()).
1236
+ *
1237
+ * @example
1238
+ * ```ts
1239
+ * await sdk.connectWebSocket();
1240
+ * const stream = sdk.messages.createAndStream({
1241
+ * conversationId: 'conv-123',
1242
+ * conversationType: 'smartAnswer',
1243
+ * message: 'What are the key terms?',
1244
+ * relevantDocumentIds: ['doc-1'],
1245
+ * });
1246
+ *
1247
+ * for await (const chunk of stream) {
1248
+ * process.stdout.write(chunk);
1249
+ * }
1250
+ * ```
1251
+ */
1252
+ async *createAndStream(data, timeoutMs = 12e4) {
1253
+ if (!this.ws) {
1254
+ throw new Error(
1255
+ "WebSocket not connected. Call sdk.connectWebSocket() before using createAndStream()."
1256
+ );
1257
+ }
1258
+ const message = await this.create(data);
1259
+ yield* this.ws.streamMessage(data.conversationId, message.id, timeoutMs);
1260
+ return "";
1261
+ }
916
1262
  };
917
1263
 
918
1264
  // src/services/NotificationService.ts
@@ -1112,16 +1458,19 @@ var WorkflowService = class {
1112
1458
  var ENVIRONMENT_PRESETS = {
1113
1459
  ["Production" /* PRODUCTION */]: {
1114
1460
  baseUrl: "https://api.lidiatech.ai",
1461
+ wsUrl: "wss://ws.lidiatech.ai",
1115
1462
  region: "eu-central-1",
1116
1463
  clientId: "10lnfbvtu9lrg1ujeemf2uk0sa"
1117
1464
  },
1118
1465
  ["Development" /* DEVELOPMENT */]: {
1119
1466
  baseUrl: "https://api.dev.lidiatech.ai",
1467
+ wsUrl: "wss://ws.dev.lidiatech.ai",
1120
1468
  region: "eu-west-1",
1121
1469
  clientId: "4uep6n7bmk8o1b7hs7e5ts7u9"
1122
1470
  },
1123
1471
  ["Staging" /* STAGING */]: {
1124
1472
  baseUrl: "https://api.staging.lidiatech.ai",
1473
+ wsUrl: "wss://ws.staging.lidiatech.ai",
1125
1474
  region: "eu-west-1",
1126
1475
  clientId: "5og664h80v1tv1md0fsgtmln2u"
1127
1476
  }
@@ -1154,8 +1503,10 @@ function isNodeEnvironment() {
1154
1503
 
1155
1504
  // src/LidiaSDK.ts
1156
1505
  var LidiaSDK = class {
1157
- constructor(config) {
1158
- const mergedConfig = this.mergeConfigWithEnv(config);
1506
+ constructor(config = {}) {
1507
+ /** WebSocket client for real-time events (available after connectWebSocket()) */
1508
+ this.ws = null;
1509
+ const mergedConfig = this.mergedConfig = this.mergeConfigWithEnv(config);
1159
1510
  this.client = new LidiaClient(mergedConfig);
1160
1511
  this.cases = new CaseService(this.client);
1161
1512
  this.conversations = new ConversationService(this.client);
@@ -1218,6 +1569,13 @@ var LidiaSDK = class {
1218
1569
  }
1219
1570
  }
1220
1571
  }
1572
+ if (!mergedConfig.wsUrl) {
1573
+ if (isNodeEnvironment()) {
1574
+ mergedConfig.wsUrl = process.env["LIDIA_WS_URL"] ?? preset.wsUrl;
1575
+ } else {
1576
+ mergedConfig.wsUrl = preset.wsUrl;
1577
+ }
1578
+ }
1221
1579
  if (!mergedConfig.baseUrl) {
1222
1580
  mergedConfig.baseUrl = preset.baseUrl;
1223
1581
  }
@@ -1293,6 +1651,39 @@ var LidiaSDK = class {
1293
1651
  getClient() {
1294
1652
  return this.client;
1295
1653
  }
1654
+ /**
1655
+ * Connect to Lidia WebSocket for real-time events (streaming messages, document updates, etc.).
1656
+ * Requires authentication (call login() or waitForAuthentication() first).
1657
+ */
1658
+ connectWebSocket(options) {
1659
+ const tokens = this.getAuthTokens();
1660
+ if (!(tokens == null ? void 0 : tokens.accessToken)) {
1661
+ throw new Error("Cannot connect WebSocket: not authenticated. Call login() or waitForAuthentication() first.");
1662
+ }
1663
+ const wsUrl = this.mergedConfig.wsUrl;
1664
+ if (!wsUrl) {
1665
+ throw new Error("WebSocket URL not configured. Set wsUrl in config or LIDIA_WS_URL env var.");
1666
+ }
1667
+ if (this.ws) {
1668
+ this.ws.disconnect();
1669
+ }
1670
+ this.ws = new LidiaWebSocket({
1671
+ wsUrl,
1672
+ accessToken: tokens.accessToken,
1673
+ debug: this.mergedConfig.debug,
1674
+ ...options
1675
+ });
1676
+ this.messages.setWebSocket(this.ws);
1677
+ this.ws.connect();
1678
+ return this.ws;
1679
+ }
1680
+ /** Disconnect WebSocket */
1681
+ disconnectWebSocket() {
1682
+ if (this.ws) {
1683
+ this.ws.disconnect();
1684
+ this.ws = null;
1685
+ }
1686
+ }
1296
1687
  };
1297
1688
 
1298
1689
  // src/types/case.ts
@@ -1366,6 +1757,8 @@ var MessageSenderType = /* @__PURE__ */ ((MessageSenderType2) => {
1366
1757
  })(MessageSenderType || {});
1367
1758
  var MessageStatus = /* @__PURE__ */ ((MessageStatus2) => {
1368
1759
  MessageStatus2["PROCESSING"] = "PROCESSING";
1760
+ MessageStatus2["STREAMING"] = "STREAMING";
1761
+ MessageStatus2["LOADING_SOURCES"] = "LOADING_SOURCES";
1369
1762
  MessageStatus2["DONE"] = "DONE";
1370
1763
  MessageStatus2["FAILED"] = "FAILED";
1371
1764
  MessageStatus2["CANCELED"] = "CANCELED";
@@ -1446,6 +1839,7 @@ export {
1446
1839
  LidiaClient,
1447
1840
  LidiaError,
1448
1841
  LidiaSDK,
1842
+ LidiaWebSocket,
1449
1843
  MessageSenderType,
1450
1844
  MessageService,
1451
1845
  MessageStatus,