@gravity-rail/sdk 8.1.0 → 9.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 +2 -3
  2. package/dist/{agent_standing_job-CaD7wjGr.d.cts → agent_team-CeErHy0t.d.ts} +846 -110
  3. package/dist/{agent_standing_job-DMLbDOjP.d.ts → agent_team-J0TyZPkg.d.cts} +846 -110
  4. package/dist/{chunk-MVWCWWRQ.js → chunk-AMJ2MMBM.js} +504 -477
  5. package/dist/chunk-AMJ2MMBM.js.map +1 -0
  6. package/dist/{chunk-IIIRXFKG.js → chunk-MWTQXZGB.js} +1 -1
  7. package/dist/chunk-MWTQXZGB.js.map +1 -0
  8. package/dist/{chunk-6KPGCPGW.js → chunk-ZJJDZUAK.js} +40 -1
  9. package/dist/chunk-ZJJDZUAK.js.map +1 -0
  10. package/dist/{chat-interaction-_mKOHRYc.d.cts → client-CO1hYs43.d.cts} +2732 -1354
  11. package/dist/{chat-interaction-exmrd2jl.d.ts → client-xtsG-YOi.d.ts} +2732 -1354
  12. package/dist/helpers.cjs +41 -0
  13. package/dist/helpers.cjs.map +1 -1
  14. package/dist/helpers.d.cts +2 -2
  15. package/dist/helpers.d.ts +2 -2
  16. package/dist/helpers.js +5 -1
  17. package/dist/helpers.js.map +1 -1
  18. package/dist/index.cjs +548 -555
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +7 -23
  21. package/dist/index.d.ts +7 -23
  22. package/dist/index.js +14 -84
  23. package/dist/index.js.map +1 -1
  24. package/dist/internal.cjs +512 -482
  25. package/dist/internal.cjs.map +1 -1
  26. package/dist/internal.d.cts +775 -927
  27. package/dist/internal.d.ts +775 -927
  28. package/dist/internal.js +14 -11
  29. package/dist/internal.js.map +1 -1
  30. package/dist/member-import-CzGVMtgv.d.cts +92 -0
  31. package/dist/member-import-q5-fCvfV.d.ts +92 -0
  32. package/dist/realtime.cjs +109 -54
  33. package/dist/realtime.cjs.map +1 -1
  34. package/dist/realtime.d.cts +7 -2
  35. package/dist/realtime.d.ts +7 -2
  36. package/dist/realtime.js +109 -54
  37. package/dist/realtime.js.map +1 -1
  38. package/dist/schemas.cjs +24 -6
  39. package/dist/schemas.cjs.map +1 -1
  40. package/dist/schemas.d.cts +54 -40
  41. package/dist/schemas.d.ts +54 -40
  42. package/dist/schemas.js +24 -7
  43. package/dist/schemas.js.map +1 -1
  44. package/dist/{tasks-BTURuIlD.d.cts → tasks-BM3pb5W6.d.cts} +67 -904
  45. package/dist/{tasks-2LhXIwL8.d.ts → tasks-Dc89D2Gu.d.ts} +67 -904
  46. package/package.json +3 -3
  47. package/dist/chunk-6KPGCPGW.js.map +0 -1
  48. package/dist/chunk-IIIRXFKG.js.map +0 -1
  49. package/dist/chunk-MVWCWWRQ.js.map +0 -1
  50. package/dist/member-import-4VSE3yYo.d.cts +0 -46
  51. package/dist/member-import-BQDFoSyf.d.ts +0 -46
@@ -0,0 +1,92 @@
1
+ import { cW as BusinessImportPreviewResponse, cZ as BusinessImportPreviewSummary, cU as BusinessImportIssueCode, c_ as BusinessImportResponse } from './client-CO1hYs43.cjs';
2
+ import { c1 as MemberImportPreviewResponse, c4 as MemberImportPreviewSummary, c3 as MemberImportPreviewRowAction, b$ as MemberImportMatchInfoMatchType, cd as MemberImportStreamEvent } from './tasks-BM3pb5W6.cjs';
3
+
4
+ /** Counts, row numbers, codes, column keys, changed field names and business ids; no prose. */
5
+ declare function toSafeBusinessImportPreview(preview: BusinessImportPreviewResponse): {
6
+ previewPlanToken: string | null | undefined;
7
+ totalRows: number;
8
+ summary: BusinessImportPreviewSummary;
9
+ rows: {
10
+ row: number;
11
+ action: "create" | "update" | "unchanged" | "error";
12
+ legalEntityUuid: string | undefined;
13
+ proposedChanges: string[] | undefined;
14
+ reason: "submitted_business_not_changed" | undefined;
15
+ error: string | undefined;
16
+ }[];
17
+ ignoredColumnPositions: number[] | undefined;
18
+ issues: {
19
+ row: number;
20
+ column: string | null | undefined;
21
+ columnPosition: number | null | undefined;
22
+ code: BusinessImportIssueCode;
23
+ }[] | undefined;
24
+ issueCount: number | undefined;
25
+ };
26
+ /** The same allowlist for a finished import; a row's business id is the one it wrote. */
27
+ declare function toSafeBusinessImportResult(result: BusinessImportResponse): {
28
+ importId: string;
29
+ totalRows: number;
30
+ summary: BusinessImportPreviewSummary;
31
+ rows: {
32
+ row: number;
33
+ action: "create" | "update" | "unchanged" | "error";
34
+ legalEntityUuid: string | undefined;
35
+ proposedChanges: string[] | undefined;
36
+ reason: "submitted_business_not_changed" | undefined;
37
+ error: string | undefined;
38
+ }[];
39
+ ignoredColumnPositions: number[] | undefined;
40
+ issues: {
41
+ row: number;
42
+ column: string | null | undefined;
43
+ columnPosition: number | null | undefined;
44
+ code: BusinessImportIssueCode;
45
+ }[] | undefined;
46
+ issueCount: number | undefined;
47
+ };
48
+
49
+ /** Counts and row references for logs/CLI/chat. Drops identity, contacts and free text. */
50
+ declare function toSafeMemberImportPreview(preview: MemberImportPreviewResponse): {
51
+ previewPlanToken: string | null | undefined;
52
+ totalRows: number;
53
+ summary: MemberImportPreviewSummary;
54
+ rows: {
55
+ row: number;
56
+ action: MemberImportPreviewRowAction;
57
+ memberId: number | undefined;
58
+ matchType: MemberImportMatchInfoMatchType | undefined;
59
+ conflict: {
60
+ code: string;
61
+ fields: string[];
62
+ } | undefined;
63
+ proposedChanges: string[] | undefined;
64
+ sharedContacts: string[] | undefined;
65
+ }[];
66
+ };
67
+ /** Deliberate allowlist: stream conflicts can contain global Account contact values. */
68
+ declare function toSafeMemberImportSummary(event: MemberImportStreamEvent): {
69
+ total: number | undefined;
70
+ created: number | undefined;
71
+ updated: number | undefined;
72
+ unchanged: number | undefined;
73
+ failed: number | undefined;
74
+ conflicted: number | undefined;
75
+ skipped: number | undefined;
76
+ failedRows: number[] | undefined;
77
+ conflictRows: number[] | undefined;
78
+ skippedRows: number[] | undefined;
79
+ conflicts: {
80
+ row: number;
81
+ code: string;
82
+ fields: string[];
83
+ memberId: number;
84
+ }[] | undefined;
85
+ updatedMembers: {
86
+ row: number;
87
+ memberId: number;
88
+ changes: string[];
89
+ }[] | undefined;
90
+ };
91
+
92
+ export { toSafeBusinessImportResult as a, toSafeMemberImportPreview as b, toSafeMemberImportSummary as c, toSafeBusinessImportPreview as t };
@@ -0,0 +1,92 @@
1
+ import { cW as BusinessImportPreviewResponse, cZ as BusinessImportPreviewSummary, cU as BusinessImportIssueCode, c_ as BusinessImportResponse } from './client-xtsG-YOi.js';
2
+ import { c1 as MemberImportPreviewResponse, c4 as MemberImportPreviewSummary, c3 as MemberImportPreviewRowAction, b$ as MemberImportMatchInfoMatchType, cd as MemberImportStreamEvent } from './tasks-Dc89D2Gu.js';
3
+
4
+ /** Counts, row numbers, codes, column keys, changed field names and business ids; no prose. */
5
+ declare function toSafeBusinessImportPreview(preview: BusinessImportPreviewResponse): {
6
+ previewPlanToken: string | null | undefined;
7
+ totalRows: number;
8
+ summary: BusinessImportPreviewSummary;
9
+ rows: {
10
+ row: number;
11
+ action: "create" | "update" | "unchanged" | "error";
12
+ legalEntityUuid: string | undefined;
13
+ proposedChanges: string[] | undefined;
14
+ reason: "submitted_business_not_changed" | undefined;
15
+ error: string | undefined;
16
+ }[];
17
+ ignoredColumnPositions: number[] | undefined;
18
+ issues: {
19
+ row: number;
20
+ column: string | null | undefined;
21
+ columnPosition: number | null | undefined;
22
+ code: BusinessImportIssueCode;
23
+ }[] | undefined;
24
+ issueCount: number | undefined;
25
+ };
26
+ /** The same allowlist for a finished import; a row's business id is the one it wrote. */
27
+ declare function toSafeBusinessImportResult(result: BusinessImportResponse): {
28
+ importId: string;
29
+ totalRows: number;
30
+ summary: BusinessImportPreviewSummary;
31
+ rows: {
32
+ row: number;
33
+ action: "create" | "update" | "unchanged" | "error";
34
+ legalEntityUuid: string | undefined;
35
+ proposedChanges: string[] | undefined;
36
+ reason: "submitted_business_not_changed" | undefined;
37
+ error: string | undefined;
38
+ }[];
39
+ ignoredColumnPositions: number[] | undefined;
40
+ issues: {
41
+ row: number;
42
+ column: string | null | undefined;
43
+ columnPosition: number | null | undefined;
44
+ code: BusinessImportIssueCode;
45
+ }[] | undefined;
46
+ issueCount: number | undefined;
47
+ };
48
+
49
+ /** Counts and row references for logs/CLI/chat. Drops identity, contacts and free text. */
50
+ declare function toSafeMemberImportPreview(preview: MemberImportPreviewResponse): {
51
+ previewPlanToken: string | null | undefined;
52
+ totalRows: number;
53
+ summary: MemberImportPreviewSummary;
54
+ rows: {
55
+ row: number;
56
+ action: MemberImportPreviewRowAction;
57
+ memberId: number | undefined;
58
+ matchType: MemberImportMatchInfoMatchType | undefined;
59
+ conflict: {
60
+ code: string;
61
+ fields: string[];
62
+ } | undefined;
63
+ proposedChanges: string[] | undefined;
64
+ sharedContacts: string[] | undefined;
65
+ }[];
66
+ };
67
+ /** Deliberate allowlist: stream conflicts can contain global Account contact values. */
68
+ declare function toSafeMemberImportSummary(event: MemberImportStreamEvent): {
69
+ total: number | undefined;
70
+ created: number | undefined;
71
+ updated: number | undefined;
72
+ unchanged: number | undefined;
73
+ failed: number | undefined;
74
+ conflicted: number | undefined;
75
+ skipped: number | undefined;
76
+ failedRows: number[] | undefined;
77
+ conflictRows: number[] | undefined;
78
+ skippedRows: number[] | undefined;
79
+ conflicts: {
80
+ row: number;
81
+ code: string;
82
+ fields: string[];
83
+ memberId: number;
84
+ }[] | undefined;
85
+ updatedMembers: {
86
+ row: number;
87
+ memberId: number;
88
+ changes: string[];
89
+ }[] | undefined;
90
+ };
91
+
92
+ export { toSafeBusinessImportResult as a, toSafeMemberImportPreview as b, toSafeMemberImportSummary as c, toSafeBusinessImportPreview as t };
package/dist/realtime.cjs CHANGED
@@ -835,6 +835,7 @@ function base64ToFloat32Array(base64) {
835
835
  }
836
836
 
837
837
  // src/realtime/operator-session-client.ts
838
+ var CONNECT_SUPERSEDED = "Operator session connect superseded";
838
839
  var OperatorSessionClient = class {
839
840
  constructor(handlers = {}) {
840
841
  this.handlers = handlers;
@@ -854,7 +855,7 @@ var OperatorSessionClient = class {
854
855
  receivedRemoteAudio = false;
855
856
  heartbeatTimer = null;
856
857
  sessionCloseNotified = false;
857
- intentionalDisconnect = false;
858
+ cancelPendingLogin = null;
858
859
  /** Bumped by every connect and disconnect; a stale connect stops at its next await. */
859
860
  connectGeneration = 0;
860
861
  getSessionState() {
@@ -880,8 +881,11 @@ var OperatorSessionClient = class {
880
881
  if (typeof window === "undefined" || typeof WebSocket === "undefined") {
881
882
  throw new Error("Operator session WebSocket is not available in this environment");
882
883
  }
883
- await this.disconnect();
884
884
  const generation = ++this.connectGeneration;
885
+ await this.closeSession();
886
+ if (generation !== this.connectGeneration) {
887
+ throw new Error(CONNECT_SUPERSEDED);
888
+ }
885
889
  this.sessionCloseNotified = false;
886
890
  this.setSessionState("connecting");
887
891
  this.setCallPhase("connecting");
@@ -890,7 +894,7 @@ var OperatorSessionClient = class {
890
894
  const wsUrl = `${isSsl ? "wss" : "ws"}://${host}/api/v2/w/${session.workspaceUuid}/operator/chats/${chatId}/session-ws`;
891
895
  const token = await mintLoginToken(session.getLoginToken);
892
896
  if (generation !== this.connectGeneration) {
893
- throw new Error("Operator session connect superseded");
897
+ throw new Error(CONNECT_SUPERSEDED);
894
898
  }
895
899
  if (!token) {
896
900
  this.setSessionState("error");
@@ -900,39 +904,62 @@ var OperatorSessionClient = class {
900
904
  await new Promise((resolve, reject) => {
901
905
  const ws = new WebSocket(wsUrl);
902
906
  this.ws = ws;
907
+ let loginSettled = false;
908
+ let loggedIn = false;
909
+ const settleLogin = (error) => {
910
+ if (loginSettled) return;
911
+ loginSettled = true;
912
+ if (this.cancelPendingLogin === cancelLogin) this.cancelPendingLogin = null;
913
+ if (error) {
914
+ reject(error);
915
+ } else {
916
+ loggedIn = true;
917
+ resolve();
918
+ }
919
+ };
920
+ const cancelLogin = () => settleLogin(new Error(CONNECT_SUPERSEDED));
921
+ this.cancelPendingLogin = cancelLogin;
903
922
  ws.onopen = () => {
923
+ if (this.ws !== ws) return;
904
924
  ws.send(JSON.stringify({ type: "login", token }));
905
925
  };
906
926
  ws.onmessage = (event) => {
927
+ if (this.ws !== ws) return;
907
928
  try {
908
929
  const msg = JSON.parse(String(event.data));
909
- this.handleMessage(msg, resolve, reject);
930
+ this.handleMessage(msg, () => settleLogin(), settleLogin);
910
931
  } catch {
911
932
  }
912
933
  };
913
934
  ws.onerror = () => {
935
+ if (this.ws !== ws) return;
914
936
  const message = "Operator session WebSocket error";
915
937
  const wasConnecting = this.sessionState === "connecting";
916
938
  this.setSessionState("error");
917
939
  if (wasConnecting) {
918
940
  this.setCallPhase("idle");
919
- reject(new Error(message));
941
+ settleLogin(new Error(message));
920
942
  } else {
921
943
  this.setCallPhase("failed");
922
944
  this.handlers.onError?.(message);
923
945
  }
924
946
  };
925
947
  ws.onclose = () => {
948
+ if (this.ws !== ws) {
949
+ settleLogin(new Error(CONNECT_SUPERSEDED));
950
+ return;
951
+ }
952
+ this.ws = null;
926
953
  this.clearHeartbeat();
927
954
  this.stopMicrophone();
928
955
  this.stopPlayback();
929
- const wasConnected = this.sessionState === "connected";
930
956
  this.setSessionState("idle");
931
957
  this.setCallPhase("idle");
932
- if (wasConnected && !this.intentionalDisconnect) {
958
+ if (loggedIn) {
933
959
  this.notifySessionClosed("disconnect");
960
+ } else {
961
+ settleLogin(new Error("Operator session closed before login"));
934
962
  }
935
- this.intentionalDisconnect = false;
936
963
  };
937
964
  });
938
965
  }
@@ -1140,57 +1167,81 @@ var OperatorSessionClient = class {
1140
1167
  throw new Error("Microphone not available in this browser");
1141
1168
  }
1142
1169
  if (this.micActive) return;
1143
- this.mediaStream = await navigator.mediaDevices.getUserMedia({
1170
+ const ws = this.ws;
1171
+ const mediaStream = await navigator.mediaDevices.getUserMedia({
1144
1172
  audio: {
1145
1173
  echoCancellation: true,
1146
1174
  noiseSuppression: true,
1147
1175
  autoGainControl: true
1148
1176
  }
1149
1177
  });
1150
- const Ctx = window.AudioContext ?? window.webkitAudioContext;
1151
- if (!Ctx) throw new Error("Web Audio not supported");
1152
- this.audioContext = new Ctx();
1153
- if (this.audioContext.state === "suspended") {
1154
- await this.audioContext.resume();
1178
+ if (this.ws !== ws) {
1179
+ for (const track of mediaStream.getTracks()) track.stop();
1180
+ throw new Error("Operator session WebSocket is not connected");
1155
1181
  }
1156
- const source = this.audioContext.createMediaStreamSource(this.mediaStream);
1157
- const processor = this.audioContext.createScriptProcessor(4096, 1, 1);
1158
- this.processor = processor;
1159
- processor.onaudioprocess = (event) => {
1160
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
1161
- if (this.onHold) return;
1162
- if (this.muted) return;
1163
- if (this.callPhase !== "dialing" && this.callPhase !== "live" && this.callPhase !== "onHold") {
1164
- return;
1182
+ this.mediaStream = mediaStream;
1183
+ let audioContext = null;
1184
+ let processor = null;
1185
+ try {
1186
+ const Ctx = window.AudioContext ?? window.webkitAudioContext;
1187
+ if (!Ctx) throw new Error("Web Audio not supported");
1188
+ audioContext = new Ctx();
1189
+ this.audioContext = audioContext;
1190
+ if (audioContext.state === "suspended") {
1191
+ await audioContext.resume();
1165
1192
  }
1166
- const input = event.inputBuffer.getChannelData(0);
1167
- const copy = new Float32Array(input.length);
1168
- copy.set(input);
1169
- const sampleRate = this.audioContext?.sampleRate ?? TARGET_SAMPLE_RATE;
1170
- let pcm = copy;
1171
- if (sampleRate !== TARGET_SAMPLE_RATE) {
1172
- const ratio = sampleRate / TARGET_SAMPLE_RATE;
1173
- const newLen = Math.floor(copy.length / ratio);
1174
- const down = new Float32Array(newLen);
1175
- for (let i = 0; i < newLen; i += 1) {
1176
- down[i] = copy[Math.floor(i * ratio)];
1193
+ if (this.ws !== ws) throw new Error("Operator session WebSocket is not connected");
1194
+ const source = audioContext.createMediaStreamSource(mediaStream);
1195
+ processor = audioContext.createScriptProcessor(4096, 1, 1);
1196
+ this.processor = processor;
1197
+ processor.onaudioprocess = (event) => {
1198
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
1199
+ if (this.onHold) return;
1200
+ if (this.muted) return;
1201
+ if (this.callPhase !== "dialing" && this.callPhase !== "live" && this.callPhase !== "onHold") {
1202
+ return;
1177
1203
  }
1178
- pcm = down;
1179
- }
1180
- this.ws.send(
1181
- JSON.stringify({
1182
- type: "CUSTOM",
1183
- name: "voice.audio",
1184
- value: {
1185
- data: float32ArrayToBase64(pcm),
1186
- format: "pcm16",
1187
- sample_rate: TARGET_SAMPLE_RATE
1204
+ const input = event.inputBuffer.getChannelData(0);
1205
+ const copy = new Float32Array(input.length);
1206
+ copy.set(input);
1207
+ const sampleRate = this.audioContext?.sampleRate ?? TARGET_SAMPLE_RATE;
1208
+ let pcm = copy;
1209
+ if (sampleRate !== TARGET_SAMPLE_RATE) {
1210
+ const ratio = sampleRate / TARGET_SAMPLE_RATE;
1211
+ const newLen = Math.floor(copy.length / ratio);
1212
+ const down = new Float32Array(newLen);
1213
+ for (let i = 0; i < newLen; i += 1) {
1214
+ down[i] = copy[Math.floor(i * ratio)];
1188
1215
  }
1189
- })
1190
- );
1191
- };
1192
- source.connect(processor);
1193
- processor.connect(this.audioContext.destination);
1216
+ pcm = down;
1217
+ }
1218
+ this.ws.send(
1219
+ JSON.stringify({
1220
+ type: "CUSTOM",
1221
+ name: "voice.audio",
1222
+ value: {
1223
+ data: float32ArrayToBase64(pcm),
1224
+ format: "pcm16",
1225
+ sample_rate: TARGET_SAMPLE_RATE
1226
+ }
1227
+ })
1228
+ );
1229
+ };
1230
+ source.connect(processor);
1231
+ processor.connect(audioContext.destination);
1232
+ } catch (err) {
1233
+ if (processor && this.processor === processor) {
1234
+ processor.disconnect();
1235
+ this.processor = null;
1236
+ }
1237
+ for (const track of mediaStream.getTracks()) track.stop();
1238
+ if (this.mediaStream === mediaStream) this.mediaStream = null;
1239
+ if (audioContext && this.audioContext === audioContext) {
1240
+ this.audioContext = null;
1241
+ void audioContext.close().catch(() => void 0);
1242
+ }
1243
+ throw err;
1244
+ }
1194
1245
  this.micActive = true;
1195
1246
  }
1196
1247
  stopMicrophone() {
@@ -1239,17 +1290,21 @@ var OperatorSessionClient = class {
1239
1290
  }
1240
1291
  async disconnect() {
1241
1292
  this.connectGeneration += 1;
1242
- this.intentionalDisconnect = true;
1293
+ await this.closeSession();
1294
+ }
1295
+ async closeSession() {
1296
+ const cancelLogin = this.cancelPendingLogin;
1297
+ this.cancelPendingLogin = null;
1298
+ cancelLogin?.();
1243
1299
  if (this.callPhase === "dialing" || this.callPhase === "live" || this.callPhase === "onHold") {
1244
1300
  this.hangUp();
1245
1301
  }
1246
1302
  this.clearHeartbeat();
1247
1303
  this.stopMicrophone();
1248
1304
  this.stopPlayback();
1249
- if (this.ws) {
1250
- this.ws.close();
1251
- this.ws = null;
1252
- }
1305
+ const ws = this.ws;
1306
+ this.ws = null;
1307
+ ws?.close();
1253
1308
  if (this.audioContext && this.audioContext.state !== "closed") {
1254
1309
  await this.audioContext.close().catch(() => void 0);
1255
1310
  }