@gravity-rail/sdk 4.0.0 → 6.0.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.
Files changed (51) hide show
  1. package/README.md +4 -2
  2. package/dist/account-CSJJbLIj.d.cts +459 -0
  3. package/dist/account-CSJJbLIj.d.ts +459 -0
  4. package/dist/{path-CUY-Iw70.d.ts → agent_standing_job-CqKpMoHO.d.cts} +1068 -140
  5. package/dist/{path-B3b3_El9.d.cts → agent_standing_job-yehTe972.d.ts} +1068 -140
  6. package/dist/{chat-interaction-DXgKjFqZ.d.cts → chat-interaction-BtUtVszg.d.ts} +13512 -9340
  7. package/dist/{chat-interaction-a7U-tHfQ.d.ts → chat-interaction-CAfwlYvv.d.cts} +13512 -9340
  8. package/dist/{chunk-WHRIIBJ4.js → chunk-L4XC6KDG.js} +1773 -475
  9. package/dist/chunk-L4XC6KDG.js.map +1 -0
  10. package/dist/{chunk-D5VNVTUQ.js → chunk-P2MSMMMJ.js} +120 -2
  11. package/dist/chunk-P2MSMMMJ.js.map +1 -0
  12. package/dist/{chunk-ZLF3N3ZD.js → chunk-P2X5TOYY.js} +31 -5
  13. package/dist/chunk-P2X5TOYY.js.map +1 -0
  14. package/dist/helpers.cjs.map +1 -1
  15. package/dist/helpers.d.cts +3 -2
  16. package/dist/helpers.d.ts +3 -2
  17. package/dist/helpers.js +1 -1
  18. package/dist/index.cjs +1961 -917
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +87 -249
  21. package/dist/index.d.ts +87 -249
  22. package/dist/index.js +171 -458
  23. package/dist/index.js.map +1 -1
  24. package/dist/internal.cjs +1928 -448
  25. package/dist/internal.cjs.map +1 -1
  26. package/dist/internal.d.cts +2428 -263
  27. package/dist/internal.d.ts +2428 -263
  28. package/dist/internal.js +146 -27
  29. package/dist/internal.js.map +1 -1
  30. package/dist/{member-import-VOLKR5dY.d.ts → member-import-C5nnoGvW.d.ts} +1 -1
  31. package/dist/{member-import-BHtOru8g.d.cts → member-import-DhaNVT7s.d.cts} +1 -1
  32. package/dist/realtime.cjs +250 -3
  33. package/dist/realtime.cjs.map +1 -1
  34. package/dist/realtime.d.cts +87 -4
  35. package/dist/realtime.d.ts +87 -4
  36. package/dist/realtime.js +245 -3
  37. package/dist/realtime.js.map +1 -1
  38. package/dist/schemas.cjs +154 -19
  39. package/dist/schemas.cjs.map +1 -1
  40. package/dist/schemas.d.cts +624 -72
  41. package/dist/schemas.d.ts +624 -72
  42. package/dist/schemas.js +72 -21
  43. package/dist/schemas.js.map +1 -1
  44. package/dist/{tasks-CgptqCsN.d.cts → tasks-A12E_RLa.d.cts} +2243 -1979
  45. package/dist/{tasks-CgptqCsN.d.ts → tasks-DrmyOlRh.d.ts} +2243 -1979
  46. package/dist/{types-BXaWYGHj.d.cts → types-Bv6GtLZ2.d.cts} +25 -2
  47. package/dist/{types-BXaWYGHj.d.ts → types-Bv6GtLZ2.d.ts} +25 -2
  48. package/package.json +4 -4
  49. package/dist/chunk-D5VNVTUQ.js.map +0 -1
  50. package/dist/chunk-WHRIIBJ4.js.map +0 -1
  51. package/dist/chunk-ZLF3N3ZD.js.map +0 -1
package/dist/realtime.cjs CHANGED
@@ -32,6 +32,8 @@ __export(realtime_exports, {
32
32
  WorkspaceRealtimeClient: () => WorkspaceRealtimeClient,
33
33
  buildAccountWsUrl: () => buildAccountWsUrl,
34
34
  buildWorkspaceWsUrl: () => buildWorkspaceWsUrl,
35
+ editorCollaborationChannel: () => editorCollaborationChannel,
36
+ editorCollaborationItemKey: () => editorCollaborationItemKey,
35
37
  initAccountSocket: () => initAccountSocket,
36
38
  initWorkspaceSocket: () => initWorkspaceSocket,
37
39
  isAccountSocketConnected: () => isAccountSocketConnected,
@@ -40,6 +42,9 @@ __export(realtime_exports, {
40
42
  isWorkspaceSocketConnected: () => isWorkspaceSocketConnected,
41
43
  onAccountSocketConnection: () => onAccountSocketConnection,
42
44
  onWorkspaceSocketConnection: () => onWorkspaceSocketConnection,
45
+ parseEditorCollaborationEvent: () => parseEditorCollaborationEvent,
46
+ parseOrgAuthRequirement: () => parseOrgAuthRequirement,
47
+ parseOrgAuthRequirements: () => parseOrgAuthRequirements,
43
48
  subscribeAccountChannel: () => subscribeAccountChannel,
44
49
  subscribeWorkspaceChannel: () => subscribeWorkspaceChannel,
45
50
  workspaceChannel: () => workspaceChannel
@@ -47,6 +52,32 @@ __export(realtime_exports, {
47
52
  module.exports = __toCommonJS(realtime_exports);
48
53
 
49
54
  // src/realtime/types.ts
55
+ function parseOrgAuthRequirement(value) {
56
+ if (typeof value !== "object" || value === null) return null;
57
+ const item = value;
58
+ const {
59
+ workspace_uuid: workspaceUuid,
60
+ org_uuid: orgUuid,
61
+ auth_url: authUrl,
62
+ requirement
63
+ } = item;
64
+ if (typeof workspaceUuid !== "string" || typeof orgUuid !== "string" || typeof authUrl !== "string" || !workspaceUuid || !orgUuid) {
65
+ return null;
66
+ }
67
+ return {
68
+ workspaceUuid,
69
+ orgUuid,
70
+ authUrl,
71
+ requirement: requirement === "mfa" ? "mfa" : "sso"
72
+ };
73
+ }
74
+ function parseOrgAuthRequirements(value) {
75
+ if (!Array.isArray(value)) return [];
76
+ return value.flatMap((item) => {
77
+ const parsed = parseOrgAuthRequirement(item);
78
+ return parsed ? [parsed] : [];
79
+ });
80
+ }
50
81
  function isActiveCallPhase(phase) {
51
82
  return phase === "dialing" || phase === "live" || phase === "onHold";
52
83
  }
@@ -88,6 +119,9 @@ var RECONNECT_DELAY_MS = 3e3;
88
119
  var MAX_RECONNECT_ATTEMPTS = 5;
89
120
  var CLOSE_DELAY_MS = 1e3;
90
121
  var MAX_SUBSCRIBE_RETRY_DELAY_MS = 3e4;
122
+ var CREDENTIAL_REVOKED_CLOSE_CODE = 4001;
123
+ var CREDENTIAL_REVOKED_CODE = "credential_revoked";
124
+ var CREDENTIAL_REVOKED_REASON = "Credential revoked";
91
125
  function createSocketState() {
92
126
  return {
93
127
  ws: null,
@@ -105,6 +139,8 @@ function createSocketState() {
105
139
  heartbeatTimer: null,
106
140
  closeTimer: null,
107
141
  intentionalClose: false,
142
+ orgAuthHalted: false,
143
+ credentialRevoked: false,
108
144
  connectGeneration: 0
109
145
  };
110
146
  }
@@ -113,6 +149,9 @@ var RealtimeSocketClient = class {
113
149
  getSessionFn;
114
150
  state = createSocketState();
115
151
  connectionListeners = /* @__PURE__ */ new Set();
152
+ orgAuthListeners = /* @__PURE__ */ new Set();
153
+ orgSessionsListeners = /* @__PURE__ */ new Set();
154
+ credentialRevokedListeners = /* @__PURE__ */ new Set();
116
155
  constructor(config) {
117
156
  if (typeof config === "function") {
118
157
  this.getSessionFn = config;
@@ -199,6 +238,7 @@ var RealtimeSocketClient = class {
199
238
  if (changed && (this.state.ws || this.state.connecting)) {
200
239
  this.closeConnection();
201
240
  }
241
+ if (changed) this.state.credentialRevoked = false;
202
242
  if (this.state.listeners.size > 0) {
203
243
  this.ensureConnection();
204
244
  }
@@ -235,6 +275,79 @@ var RealtimeSocketClient = class {
235
275
  }
236
276
  };
237
277
  }
278
+ /**
279
+ * Hear every workspace the server refused for want of an org session: a
280
+ * `subscribe_error` entry, an `error` frame with that code, a lapse notice,
281
+ * or the list in an `org_sessions_updated` reply.
282
+ */
283
+ onOrgAuthRequired(listener) {
284
+ this.orgAuthListeners.add(listener);
285
+ return () => {
286
+ this.orgAuthListeners.delete(listener);
287
+ };
288
+ }
289
+ /** Hear the server's reply to an `org_sessions` frame. */
290
+ onOrgSessionsUpdated(listener) {
291
+ this.orgSessionsListeners.add(listener);
292
+ return () => {
293
+ this.orgSessionsListeners.delete(listener);
294
+ };
295
+ }
296
+ /**
297
+ * Hear that the server ended this socket's login credential. The client
298
+ * does not reconnect afterwards; the consumer decides what the person sees
299
+ * (in the web app, the account check that leads to the login page).
300
+ */
301
+ onCredentialRevoked(listener) {
302
+ this.credentialRevokedListeners.add(listener);
303
+ return () => {
304
+ this.credentialRevokedListeners.delete(listener);
305
+ };
306
+ }
307
+ /** Whether the server ended this socket's login credential. */
308
+ isCredentialRevoked() {
309
+ return this.state.credentialRevoked;
310
+ }
311
+ markCredentialRevoked(message) {
312
+ if (this.state.credentialRevoked) return;
313
+ this.state.credentialRevoked = true;
314
+ this.state.lastError = message;
315
+ if (this.state.reconnectTimer) {
316
+ clearTimeout(this.state.reconnectTimer);
317
+ this.state.reconnectTimer = null;
318
+ }
319
+ this.notifyConnectionListeners();
320
+ for (const listener of this.credentialRevokedListeners) listener();
321
+ }
322
+ emitOrgAuthRequired(items) {
323
+ if (items.length === 0) return;
324
+ for (const listener of this.orgAuthListeners) listener(items);
325
+ }
326
+ /** Send a control frame (one that is not a channel message) on the open socket. */
327
+ sendFrame(frame) {
328
+ if (!this.state.connected || this.state.ws?.readyState !== WebSocket.OPEN) return false;
329
+ this.state.ws.send(JSON.stringify(frame));
330
+ return true;
331
+ }
332
+ /**
333
+ * Try again after the person completed org sign-in: reconnect a socket the
334
+ * server closed for it, or ask again for every channel it refused.
335
+ */
336
+ retryAfterOrgAuth() {
337
+ this.state.orgAuthHalted = false;
338
+ if (this.state.connected && this.state.ws?.readyState === WebSocket.OPEN) {
339
+ const pending = Array.from(this.state.listeners.keys()).filter(
340
+ (channel) => !this.state.subscribedChannels.has(channel)
341
+ );
342
+ if (pending.length > 0) {
343
+ this.state.ws.send(JSON.stringify({ type: "subscribe", channels: pending }));
344
+ }
345
+ return;
346
+ }
347
+ if (this.state.ws || this.state.connecting) return;
348
+ this.state.reconnectAttempts = 0;
349
+ this.ensureConnection();
350
+ }
238
351
  send(channel, data) {
239
352
  if (!this.state.connected || !this.state.ws) return;
240
353
  this.state.ws.send(JSON.stringify({ type: "message", channel, data }));
@@ -292,6 +405,7 @@ var RealtimeSocketClient = class {
292
405
  if (!session) return;
293
406
  if (typeof window === "undefined" || typeof WebSocket === "undefined") return;
294
407
  if (this.state.ws || this.state.connecting) return;
408
+ if (this.state.credentialRevoked) return;
295
409
  this.clearCloseTimer();
296
410
  this.state.connecting = true;
297
411
  this.state.intentionalClose = false;
@@ -361,10 +475,17 @@ var RealtimeSocketClient = class {
361
475
  }
362
476
  if (msg.type === "subscribe_error" && Array.isArray(msg.errors)) {
363
477
  const retryableChannels = [];
478
+ const orgRequired = [];
364
479
  for (const rawError of msg.errors) {
365
480
  if (!rawError || typeof rawError !== "object") continue;
366
481
  const error = rawError;
367
482
  if (typeof error.channel !== "string") continue;
483
+ if (error.code === "org_auth_required") {
484
+ this.clearSubscriptionRetry(error.channel);
485
+ const requirement = parseOrgAuthRequirement(rawError);
486
+ if (requirement) orgRequired.push(requirement);
487
+ continue;
488
+ }
368
489
  if (error.retryable === true) {
369
490
  retryableChannels.push(error.channel);
370
491
  } else {
@@ -372,6 +493,20 @@ var RealtimeSocketClient = class {
372
493
  }
373
494
  }
374
495
  this.scheduleSubscriptionRetry(retryableChannels);
496
+ this.emitOrgAuthRequired(orgRequired);
497
+ return;
498
+ }
499
+ if (msg.type === "org_auth_required") {
500
+ this.emitOrgAuthRequired(parseOrgAuthRequirements(msg.org_auth_required));
501
+ return;
502
+ }
503
+ if (msg.type === "org_sessions_updated") {
504
+ const orgAuthRequired = parseOrgAuthRequirements(msg.org_auth_required);
505
+ const orgUuids = Array.isArray(msg.org_uuids) ? msg.org_uuids.filter((value) => typeof value === "string") : [];
506
+ for (const listener of this.orgSessionsListeners) {
507
+ listener({ orgUuids, orgAuthRequired });
508
+ }
509
+ this.emitOrgAuthRequired(orgAuthRequired);
375
510
  return;
376
511
  }
377
512
  if (msg.type === "unsubscribed" && Array.isArray(msg.channels)) {
@@ -383,6 +518,19 @@ var RealtimeSocketClient = class {
383
518
  this.scheduleSubscriptionRetry(msg.channels);
384
519
  return;
385
520
  }
521
+ if (msg.type === "error" && msg.code === "org_auth_required") {
522
+ this.state.orgAuthHalted = true;
523
+ const requirement = parseOrgAuthRequirement(msg);
524
+ if (requirement) this.emitOrgAuthRequired([requirement]);
525
+ return;
526
+ }
527
+ if (msg.type === "error" && msg.code === CREDENTIAL_REVOKED_CODE) {
528
+ const message = msg.message;
529
+ this.markCredentialRevoked(
530
+ typeof message === "string" && message ? message : CREDENTIAL_REVOKED_REASON
531
+ );
532
+ return;
533
+ }
386
534
  if (msg.type === "error") {
387
535
  const message = msg.message;
388
536
  this.state.lastError = typeof message === "string" && message ? message : "Realtime error";
@@ -404,8 +552,11 @@ var RealtimeSocketClient = class {
404
552
  } catch {
405
553
  }
406
554
  };
407
- ws.onclose = () => {
555
+ ws.onclose = (event) => {
408
556
  if (this.state.ws !== null && this.state.ws !== ws) return;
557
+ if (event?.code === CREDENTIAL_REVOKED_CLOSE_CODE && event.reason === CREDENTIAL_REVOKED_REASON) {
558
+ this.markCredentialRevoked(CREDENTIAL_REVOKED_REASON);
559
+ }
409
560
  this.state.connected = false;
410
561
  this.state.connecting = false;
411
562
  this.state.ws = null;
@@ -431,8 +582,8 @@ var RealtimeSocketClient = class {
431
582
  }
432
583
  /** Decide whether a connection that just ended (or never opened) retries. */
433
584
  afterConnectionEnded() {
434
- const willRetry = !this.state.intentionalClose && this.state.listeners.size > 0 && this.state.reconnectAttempts < MAX_RECONNECT_ATTEMPTS;
435
- if (!willRetry && !this.state.intentionalClose && this.state.listeners.size > 0) {
585
+ const willRetry = !this.state.intentionalClose && !this.state.orgAuthHalted && !this.state.credentialRevoked && this.state.listeners.size > 0 && this.state.reconnectAttempts < MAX_RECONNECT_ATTEMPTS;
586
+ if (!willRetry && !this.state.intentionalClose && !this.state.credentialRevoked && this.state.listeners.size > 0) {
436
587
  this.state.lastError = "Realtime connection lost";
437
588
  }
438
589
  this.notifyConnectionListeners();
@@ -445,6 +596,8 @@ var RealtimeSocketClient = class {
445
596
  }
446
597
  closeConnection() {
447
598
  this.state.intentionalClose = true;
599
+ this.state.orgAuthHalted = false;
600
+ this.state.credentialRevoked = false;
448
601
  this.state.connectGeneration += 1;
449
602
  this.clearCloseTimer();
450
603
  if (this.state.reconnectTimer) {
@@ -566,6 +719,91 @@ function isAccountSocketConnected() {
566
719
  return defaultClient2.isConnected();
567
720
  }
568
721
 
722
+ // src/types/generated/account.ts
723
+ var AccountResponseAvatarColor = {
724
+ teal: "teal",
725
+ sky: "sky",
726
+ blue: "blue",
727
+ indigo: "indigo",
728
+ violet: "violet",
729
+ fuchsia: "fuchsia",
730
+ slate: "slate"
731
+ };
732
+ var AccountResponseAvatarIcon = {
733
+ user: "user",
734
+ stethoscope: "stethoscope",
735
+ heart: "heart",
736
+ shield: "shield",
737
+ sparkles: "sparkles",
738
+ star: "star"
739
+ };
740
+
741
+ // src/realtime/editor-collaboration.ts
742
+ function editorCollaborationChannel(resource, resourceId) {
743
+ return `collaboration:${resource}:${resourceId}`;
744
+ }
745
+ function editorCollaborationItemKey(item) {
746
+ return `${item.kind}:${String(item.id)}`;
747
+ }
748
+ function parseCollaborator(value) {
749
+ if (typeof value !== "object" || value === null) return null;
750
+ const record = value;
751
+ if (typeof record.memberId !== "number" || !Number.isInteger(record.memberId)) return null;
752
+ const name = record.name;
753
+ const avatarUrl = record.avatarUrl;
754
+ const avatarIcon = record.avatarIcon;
755
+ const avatarColor = record.avatarColor;
756
+ return {
757
+ kind: record.kind === "manager" ? "manager" : "member",
758
+ memberId: record.memberId,
759
+ name: typeof name === "string" ? name : null,
760
+ avatarUrl: typeof avatarUrl === "string" ? avatarUrl : null,
761
+ avatarIcon: typeof avatarIcon === "string" && avatarIcon in AccountResponseAvatarIcon ? avatarIcon : null,
762
+ avatarColor: typeof avatarColor === "string" && avatarColor in AccountResponseAvatarColor ? avatarColor : null
763
+ };
764
+ }
765
+ function parseItem(value) {
766
+ if (typeof value !== "object" || value === null) return null;
767
+ const item = value;
768
+ const kind = item.kind;
769
+ const id = item.id;
770
+ const validKind = kind === "workflow" || kind === "task" || kind === "note" || kind === "journey" || kind === "step" || kind === "route" || kind === "ending" || kind === "enrollment" || kind === "goal" || kind === "connection" || kind === "wait" || kind === "action";
771
+ if (!validKind) return null;
772
+ if (typeof id !== "number" && typeof id !== "string") return null;
773
+ if (!String(id)) return null;
774
+ return { kind, id };
775
+ }
776
+ function parseEditorCollaborationEvent(event) {
777
+ const data = event.data;
778
+ if (typeof data !== "object" || data === null) return null;
779
+ const record = data;
780
+ if (event.type === "collaborators.changed") {
781
+ if (!Array.isArray(record.collaborators)) return null;
782
+ const collaborators = record.collaborators.flatMap((value) => {
783
+ const parsed = parseCollaborator(value);
784
+ return parsed ? [parsed] : [];
785
+ });
786
+ return { type: event.type, collaborators };
787
+ }
788
+ if (event.type === "editor.updated") {
789
+ const editor = parseCollaborator(record.editor);
790
+ const rawItems = record.items;
791
+ if (!editor || !Array.isArray(rawItems) || rawItems.length === 0 || rawItems.length > 100 || typeof record.originId !== "string" || typeof record.updatedAt !== "string") {
792
+ return null;
793
+ }
794
+ const items = rawItems.map(parseItem);
795
+ if (items.some((item) => item === null)) return null;
796
+ return {
797
+ type: event.type,
798
+ editor,
799
+ items,
800
+ originId: record.originId,
801
+ updatedAt: record.updatedAt
802
+ };
803
+ }
804
+ return null;
805
+ }
806
+
569
807
  // src/audio/pcm.ts
570
808
  var SERVER_SAMPLE_RATE = 24e3;
571
809
  var TARGET_SAMPLE_RATE = 24e3;
@@ -701,6 +939,10 @@ var OperatorSessionClient = class {
701
939
  handleMessage(msg, resolveLogin, rejectLogin) {
702
940
  if (msg.type === "RUN_ERROR" || msg.type === "error") {
703
941
  const message = msg.message ?? "Operator session error";
942
+ if (msg.code === "org_auth_required") {
943
+ const requirement = parseOrgAuthRequirement(msg);
944
+ if (requirement) this.handlers.onOrgAuthRequired?.(requirement);
945
+ }
704
946
  if (this.sessionState === "connecting") {
705
947
  this.setSessionState("error");
706
948
  rejectLogin(new Error(message));
@@ -1027,6 +1269,8 @@ var OperatorSessionClient = class {
1027
1269
  WorkspaceRealtimeClient,
1028
1270
  buildAccountWsUrl,
1029
1271
  buildWorkspaceWsUrl,
1272
+ editorCollaborationChannel,
1273
+ editorCollaborationItemKey,
1030
1274
  initAccountSocket,
1031
1275
  initWorkspaceSocket,
1032
1276
  isAccountSocketConnected,
@@ -1035,6 +1279,9 @@ var OperatorSessionClient = class {
1035
1279
  isWorkspaceSocketConnected,
1036
1280
  onAccountSocketConnection,
1037
1281
  onWorkspaceSocketConnection,
1282
+ parseEditorCollaborationEvent,
1283
+ parseOrgAuthRequirement,
1284
+ parseOrgAuthRequirements,
1038
1285
  subscribeAccountChannel,
1039
1286
  subscribeWorkspaceChannel,
1040
1287
  workspaceChannel