@azure/ai-voicelive 1.0.0-alpha.20251117.2

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 (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -0
  3. package/dist/browser/auth/credentialHandler.d.ts +43 -0
  4. package/dist/browser/auth/credentialHandler.js +147 -0
  5. package/dist/browser/auth/credentialHandler.js.map +1 -0
  6. package/dist/browser/errors/connectionErrors.d.ts +68 -0
  7. package/dist/browser/errors/connectionErrors.js +136 -0
  8. package/dist/browser/errors/connectionErrors.js.map +1 -0
  9. package/dist/browser/errors/index.d.ts +2 -0
  10. package/dist/browser/errors/index.js +4 -0
  11. package/dist/browser/errors/index.js.map +1 -0
  12. package/dist/browser/handlers/sessionHandlers.d.ts +250 -0
  13. package/dist/browser/handlers/sessionHandlers.js +4 -0
  14. package/dist/browser/handlers/sessionHandlers.js.map +1 -0
  15. package/dist/browser/handlers/subscriptionManager.d.ts +54 -0
  16. package/dist/browser/handlers/subscriptionManager.js +250 -0
  17. package/dist/browser/handlers/subscriptionManager.js.map +1 -0
  18. package/dist/browser/index.d.ts +7 -0
  19. package/dist/browser/index.js +12 -0
  20. package/dist/browser/index.js.map +1 -0
  21. package/dist/browser/logger.d.ts +2 -0
  22. package/dist/browser/logger.js +5 -0
  23. package/dist/browser/logger.js.map +1 -0
  24. package/dist/browser/models/index.d.ts +2 -0
  25. package/dist/browser/models/index.js +4 -0
  26. package/dist/browser/models/index.js.map +1 -0
  27. package/dist/browser/models/models.d.ts +2154 -0
  28. package/dist/browser/models/models.js +2251 -0
  29. package/dist/browser/models/models.js.map +1 -0
  30. package/dist/browser/package.json +3 -0
  31. package/dist/browser/protocol/messageParser.d.ts +42 -0
  32. package/dist/browser/protocol/messageParser.js +150 -0
  33. package/dist/browser/protocol/messageParser.js.map +1 -0
  34. package/dist/browser/voiceLiveClient.d.ts +65 -0
  35. package/dist/browser/voiceLiveClient.js +81 -0
  36. package/dist/browser/voiceLiveClient.js.map +1 -0
  37. package/dist/browser/voiceLiveSession.d.ts +138 -0
  38. package/dist/browser/voiceLiveSession.js +429 -0
  39. package/dist/browser/voiceLiveSession.js.map +1 -0
  40. package/dist/browser/websocket/connectionManager.d.ts +88 -0
  41. package/dist/browser/websocket/connectionManager.js +183 -0
  42. package/dist/browser/websocket/connectionManager.js.map +1 -0
  43. package/dist/browser/websocket/websocketBrowser.d.ts +26 -0
  44. package/dist/browser/websocket/websocketBrowser.js +175 -0
  45. package/dist/browser/websocket/websocketBrowser.js.map +1 -0
  46. package/dist/browser/websocket/websocketFactory.d.ts +23 -0
  47. package/dist/browser/websocket/websocketFactory.js +80 -0
  48. package/dist/browser/websocket/websocketFactory.js.map +1 -0
  49. package/dist/browser/websocket/websocketLike.d.ts +78 -0
  50. package/dist/browser/websocket/websocketLike.js +13 -0
  51. package/dist/browser/websocket/websocketLike.js.map +1 -0
  52. package/dist/browser/websocket/websocketNode.d.ts +26 -0
  53. package/dist/browser/websocket/websocketNode.js +180 -0
  54. package/dist/browser/websocket/websocketNode.js.map +1 -0
  55. package/dist/commonjs/auth/credentialHandler.d.ts +43 -0
  56. package/dist/commonjs/auth/credentialHandler.js +151 -0
  57. package/dist/commonjs/auth/credentialHandler.js.map +1 -0
  58. package/dist/commonjs/errors/connectionErrors.d.ts +68 -0
  59. package/dist/commonjs/errors/connectionErrors.js +146 -0
  60. package/dist/commonjs/errors/connectionErrors.js.map +1 -0
  61. package/dist/commonjs/errors/index.d.ts +2 -0
  62. package/dist/commonjs/errors/index.js +7 -0
  63. package/dist/commonjs/errors/index.js.map +1 -0
  64. package/dist/commonjs/handlers/sessionHandlers.d.ts +250 -0
  65. package/dist/commonjs/handlers/sessionHandlers.js +5 -0
  66. package/dist/commonjs/handlers/sessionHandlers.js.map +1 -0
  67. package/dist/commonjs/handlers/subscriptionManager.d.ts +54 -0
  68. package/dist/commonjs/handlers/subscriptionManager.js +255 -0
  69. package/dist/commonjs/handlers/subscriptionManager.js.map +1 -0
  70. package/dist/commonjs/index.d.ts +7 -0
  71. package/dist/commonjs/index.js +45 -0
  72. package/dist/commonjs/index.js.map +1 -0
  73. package/dist/commonjs/logger.d.ts +2 -0
  74. package/dist/commonjs/logger.js +8 -0
  75. package/dist/commonjs/logger.js.map +1 -0
  76. package/dist/commonjs/models/index.d.ts +2 -0
  77. package/dist/commonjs/models/index.js +27 -0
  78. package/dist/commonjs/models/index.js.map +1 -0
  79. package/dist/commonjs/models/models.d.ts +2154 -0
  80. package/dist/commonjs/models/models.js +2463 -0
  81. package/dist/commonjs/models/models.js.map +1 -0
  82. package/dist/commonjs/package.json +3 -0
  83. package/dist/commonjs/protocol/messageParser.d.ts +42 -0
  84. package/dist/commonjs/protocol/messageParser.js +154 -0
  85. package/dist/commonjs/protocol/messageParser.js.map +1 -0
  86. package/dist/commonjs/tsdoc-metadata.json +11 -0
  87. package/dist/commonjs/voiceLiveClient.d.ts +65 -0
  88. package/dist/commonjs/voiceLiveClient.js +85 -0
  89. package/dist/commonjs/voiceLiveClient.js.map +1 -0
  90. package/dist/commonjs/voiceLiveSession.d.ts +138 -0
  91. package/dist/commonjs/voiceLiveSession.js +433 -0
  92. package/dist/commonjs/voiceLiveSession.js.map +1 -0
  93. package/dist/commonjs/websocket/connectionManager.d.ts +88 -0
  94. package/dist/commonjs/websocket/connectionManager.js +187 -0
  95. package/dist/commonjs/websocket/connectionManager.js.map +1 -0
  96. package/dist/commonjs/websocket/websocketBrowser.d.ts +26 -0
  97. package/dist/commonjs/websocket/websocketBrowser.js +179 -0
  98. package/dist/commonjs/websocket/websocketBrowser.js.map +1 -0
  99. package/dist/commonjs/websocket/websocketFactory.d.ts +23 -0
  100. package/dist/commonjs/websocket/websocketFactory.js +86 -0
  101. package/dist/commonjs/websocket/websocketFactory.js.map +1 -0
  102. package/dist/commonjs/websocket/websocketLike.d.ts +78 -0
  103. package/dist/commonjs/websocket/websocketLike.js +16 -0
  104. package/dist/commonjs/websocket/websocketLike.js.map +1 -0
  105. package/dist/commonjs/websocket/websocketNode.d.ts +26 -0
  106. package/dist/commonjs/websocket/websocketNode.js +185 -0
  107. package/dist/commonjs/websocket/websocketNode.js.map +1 -0
  108. package/dist/esm/auth/credentialHandler.d.ts +43 -0
  109. package/dist/esm/auth/credentialHandler.js +147 -0
  110. package/dist/esm/auth/credentialHandler.js.map +1 -0
  111. package/dist/esm/errors/connectionErrors.d.ts +68 -0
  112. package/dist/esm/errors/connectionErrors.js +136 -0
  113. package/dist/esm/errors/connectionErrors.js.map +1 -0
  114. package/dist/esm/errors/index.d.ts +2 -0
  115. package/dist/esm/errors/index.js +4 -0
  116. package/dist/esm/errors/index.js.map +1 -0
  117. package/dist/esm/handlers/sessionHandlers.d.ts +250 -0
  118. package/dist/esm/handlers/sessionHandlers.js +4 -0
  119. package/dist/esm/handlers/sessionHandlers.js.map +1 -0
  120. package/dist/esm/handlers/subscriptionManager.d.ts +54 -0
  121. package/dist/esm/handlers/subscriptionManager.js +250 -0
  122. package/dist/esm/handlers/subscriptionManager.js.map +1 -0
  123. package/dist/esm/index.d.ts +7 -0
  124. package/dist/esm/index.js +12 -0
  125. package/dist/esm/index.js.map +1 -0
  126. package/dist/esm/logger.d.ts +2 -0
  127. package/dist/esm/logger.js +5 -0
  128. package/dist/esm/logger.js.map +1 -0
  129. package/dist/esm/models/index.d.ts +2 -0
  130. package/dist/esm/models/index.js +4 -0
  131. package/dist/esm/models/index.js.map +1 -0
  132. package/dist/esm/models/models.d.ts +2154 -0
  133. package/dist/esm/models/models.js +2251 -0
  134. package/dist/esm/models/models.js.map +1 -0
  135. package/dist/esm/package.json +3 -0
  136. package/dist/esm/protocol/messageParser.d.ts +42 -0
  137. package/dist/esm/protocol/messageParser.js +150 -0
  138. package/dist/esm/protocol/messageParser.js.map +1 -0
  139. package/dist/esm/voiceLiveClient.d.ts +65 -0
  140. package/dist/esm/voiceLiveClient.js +81 -0
  141. package/dist/esm/voiceLiveClient.js.map +1 -0
  142. package/dist/esm/voiceLiveSession.d.ts +138 -0
  143. package/dist/esm/voiceLiveSession.js +429 -0
  144. package/dist/esm/voiceLiveSession.js.map +1 -0
  145. package/dist/esm/websocket/connectionManager.d.ts +88 -0
  146. package/dist/esm/websocket/connectionManager.js +183 -0
  147. package/dist/esm/websocket/connectionManager.js.map +1 -0
  148. package/dist/esm/websocket/websocketBrowser.d.ts +26 -0
  149. package/dist/esm/websocket/websocketBrowser.js +175 -0
  150. package/dist/esm/websocket/websocketBrowser.js.map +1 -0
  151. package/dist/esm/websocket/websocketFactory.d.ts +23 -0
  152. package/dist/esm/websocket/websocketFactory.js +80 -0
  153. package/dist/esm/websocket/websocketFactory.js.map +1 -0
  154. package/dist/esm/websocket/websocketLike.d.ts +78 -0
  155. package/dist/esm/websocket/websocketLike.js +13 -0
  156. package/dist/esm/websocket/websocketLike.js.map +1 -0
  157. package/dist/esm/websocket/websocketNode.d.ts +26 -0
  158. package/dist/esm/websocket/websocketNode.js +180 -0
  159. package/dist/esm/websocket/websocketNode.js.map +1 -0
  160. package/dist/react-native/auth/credentialHandler.d.ts +43 -0
  161. package/dist/react-native/auth/credentialHandler.js +147 -0
  162. package/dist/react-native/auth/credentialHandler.js.map +1 -0
  163. package/dist/react-native/errors/connectionErrors.d.ts +68 -0
  164. package/dist/react-native/errors/connectionErrors.js +136 -0
  165. package/dist/react-native/errors/connectionErrors.js.map +1 -0
  166. package/dist/react-native/errors/index.d.ts +2 -0
  167. package/dist/react-native/errors/index.js +4 -0
  168. package/dist/react-native/errors/index.js.map +1 -0
  169. package/dist/react-native/handlers/sessionHandlers.d.ts +250 -0
  170. package/dist/react-native/handlers/sessionHandlers.js +4 -0
  171. package/dist/react-native/handlers/sessionHandlers.js.map +1 -0
  172. package/dist/react-native/handlers/subscriptionManager.d.ts +54 -0
  173. package/dist/react-native/handlers/subscriptionManager.js +250 -0
  174. package/dist/react-native/handlers/subscriptionManager.js.map +1 -0
  175. package/dist/react-native/index.d.ts +7 -0
  176. package/dist/react-native/index.js +12 -0
  177. package/dist/react-native/index.js.map +1 -0
  178. package/dist/react-native/logger.d.ts +2 -0
  179. package/dist/react-native/logger.js +5 -0
  180. package/dist/react-native/logger.js.map +1 -0
  181. package/dist/react-native/models/index.d.ts +2 -0
  182. package/dist/react-native/models/index.js +4 -0
  183. package/dist/react-native/models/index.js.map +1 -0
  184. package/dist/react-native/models/models.d.ts +2154 -0
  185. package/dist/react-native/models/models.js +2251 -0
  186. package/dist/react-native/models/models.js.map +1 -0
  187. package/dist/react-native/package.json +3 -0
  188. package/dist/react-native/protocol/messageParser.d.ts +42 -0
  189. package/dist/react-native/protocol/messageParser.js +150 -0
  190. package/dist/react-native/protocol/messageParser.js.map +1 -0
  191. package/dist/react-native/voiceLiveClient.d.ts +65 -0
  192. package/dist/react-native/voiceLiveClient.js +81 -0
  193. package/dist/react-native/voiceLiveClient.js.map +1 -0
  194. package/dist/react-native/voiceLiveSession.d.ts +138 -0
  195. package/dist/react-native/voiceLiveSession.js +429 -0
  196. package/dist/react-native/voiceLiveSession.js.map +1 -0
  197. package/dist/react-native/websocket/connectionManager.d.ts +88 -0
  198. package/dist/react-native/websocket/connectionManager.js +183 -0
  199. package/dist/react-native/websocket/connectionManager.js.map +1 -0
  200. package/dist/react-native/websocket/websocketBrowser.d.ts +26 -0
  201. package/dist/react-native/websocket/websocketBrowser.js +175 -0
  202. package/dist/react-native/websocket/websocketBrowser.js.map +1 -0
  203. package/dist/react-native/websocket/websocketFactory.d.ts +23 -0
  204. package/dist/react-native/websocket/websocketFactory.js +80 -0
  205. package/dist/react-native/websocket/websocketFactory.js.map +1 -0
  206. package/dist/react-native/websocket/websocketLike.d.ts +78 -0
  207. package/dist/react-native/websocket/websocketLike.js +13 -0
  208. package/dist/react-native/websocket/websocketLike.js.map +1 -0
  209. package/dist/react-native/websocket/websocketNode.d.ts +26 -0
  210. package/dist/react-native/websocket/websocketNode.js +180 -0
  211. package/dist/react-native/websocket/websocketNode.js.map +1 -0
  212. package/package.json +150 -0
@@ -0,0 +1,136 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Error codes for Voice Live WebSocket operations
5
+ */
6
+ export var VoiceLiveErrorCodes;
7
+ (function (VoiceLiveErrorCodes) {
8
+ // Connection errors
9
+ VoiceLiveErrorCodes["ConnectionFailed"] = "CONNECTION_FAILED";
10
+ VoiceLiveErrorCodes["ConnectionTimeout"] = "CONNECTION_TIMEOUT";
11
+ VoiceLiveErrorCodes["ConnectionLost"] = "CONNECTION_LOST";
12
+ VoiceLiveErrorCodes["AlreadyConnected"] = "ALREADY_CONNECTED";
13
+ VoiceLiveErrorCodes["NotConnected"] = "NOT_CONNECTED";
14
+ // WebSocket errors
15
+ VoiceLiveErrorCodes["WebSocketError"] = "WEBSOCKET_ERROR";
16
+ // Authentication errors
17
+ VoiceLiveErrorCodes["AuthenticationFailed"] = "AUTHENTICATION_FAILED";
18
+ VoiceLiveErrorCodes["InvalidCredentials"] = "INVALID_CREDENTIALS";
19
+ VoiceLiveErrorCodes["Unauthorized"] = "UNAUTHORIZED";
20
+ VoiceLiveErrorCodes["Forbidden"] = "FORBIDDEN";
21
+ // Protocol errors
22
+ VoiceLiveErrorCodes["InvalidMessage"] = "INVALID_MESSAGE";
23
+ VoiceLiveErrorCodes["MessageTooLarge"] = "MESSAGE_TOO_LARGE";
24
+ VoiceLiveErrorCodes["ProtocolError"] = "PROTOCOL_ERROR";
25
+ VoiceLiveErrorCodes["BufferOverflow"] = "BUFFER_OVERFLOW";
26
+ // General errors
27
+ VoiceLiveErrorCodes["OperationCancelled"] = "OPERATION_CANCELLED";
28
+ VoiceLiveErrorCodes["InvalidState"] = "INVALID_STATE";
29
+ })(VoiceLiveErrorCodes || (VoiceLiveErrorCodes = {}));
30
+ /**
31
+ * Base error class for Voice Live WebSocket operations
32
+ */
33
+ export class VoiceLiveConnectionError extends Error {
34
+ /** Error code identifying the specific error type */
35
+ code;
36
+ /** Context information about where the error occurred */
37
+ context;
38
+ /** Indicates whether this error is potentially recoverable */
39
+ recoverable;
40
+ /** The original error that caused this error, if any */
41
+ cause;
42
+ /** Timestamp when the error occurred */
43
+ timestamp;
44
+ constructor(message, code, context = "websocket", recoverable = false, cause) {
45
+ super(message);
46
+ this.name = "VoiceLiveConnectionError";
47
+ this.code = code;
48
+ this.context = context;
49
+ this.recoverable = recoverable;
50
+ this.cause = cause;
51
+ this.timestamp = new Date();
52
+ // Ensure proper stack trace in V8
53
+ if (Error.captureStackTrace) {
54
+ Error.captureStackTrace(this, VoiceLiveConnectionError);
55
+ }
56
+ // Make properties enumerable for JSON.stringify (following Azure SDK pattern)
57
+ Object.defineProperty(this, "message", { enumerable: true });
58
+ Object.defineProperty(this, "name", { enumerable: true });
59
+ Object.defineProperty(this, "stack", { enumerable: true });
60
+ }
61
+ }
62
+ /**
63
+ * Authentication error class for Voice Live operations
64
+ */
65
+ export class VoiceLiveAuthenticationError extends VoiceLiveConnectionError {
66
+ constructor(message, code, cause) {
67
+ super(message, code, "authentication", false, cause);
68
+ this.name = "VoiceLiveAuthenticationError";
69
+ }
70
+ }
71
+ /**
72
+ * Protocol error class for Voice Live message operations
73
+ */
74
+ export class VoiceLiveProtocolError extends VoiceLiveConnectionError {
75
+ constructor(message, code, cause) {
76
+ super(message, code, "protocol", false, cause);
77
+ this.name = "VoiceLiveProtocolError";
78
+ }
79
+ }
80
+ /**
81
+ * General Voice Live error class
82
+ */
83
+ export class VoiceLiveError extends VoiceLiveConnectionError {
84
+ constructor(message, code, context = "general", recoverable = false, cause) {
85
+ super(message, code, context, recoverable, cause);
86
+ this.name = "VoiceLiveError";
87
+ }
88
+ }
89
+ /**
90
+ * Classifies a WebSocket close event and returns appropriate error
91
+ */
92
+ export function classifyWebSocketClose(code, reason) {
93
+ switch (code) {
94
+ case 1000: // Normal closure
95
+ return new VoiceLiveConnectionError("WebSocket connection closed normally", VoiceLiveErrorCodes.ConnectionLost, "websocket_close", false);
96
+ case 1001: // Going away
97
+ case 1006: // Abnormal closure
98
+ return new VoiceLiveConnectionError(`WebSocket connection lost: ${reason || "Abnormal closure"}`, VoiceLiveErrorCodes.ConnectionLost, "websocket_close", true);
99
+ case 1008: // Policy violation
100
+ return new VoiceLiveConnectionError(`WebSocket policy violation: ${reason}`, VoiceLiveErrorCodes.WebSocketError, "websocket_close", false);
101
+ case 1011: // Server error
102
+ return new VoiceLiveConnectionError(`WebSocket server error: ${reason}`, VoiceLiveErrorCodes.WebSocketError, "websocket_close", true);
103
+ default:
104
+ return new VoiceLiveConnectionError(`WebSocket closed with code ${code}: ${reason}`, VoiceLiveErrorCodes.ConnectionLost, "websocket_close", true);
105
+ }
106
+ }
107
+ /**
108
+ * Classifies connection errors
109
+ */
110
+ export function classifyConnectionError(error) {
111
+ if (error instanceof VoiceLiveConnectionError) {
112
+ return error;
113
+ }
114
+ if (error instanceof Error) {
115
+ if (error.message.includes("timeout")) {
116
+ return new VoiceLiveConnectionError(`Connection timeout: ${error.message}`, VoiceLiveErrorCodes.ConnectionTimeout, "connection", true, error);
117
+ }
118
+ if (error.message.includes("ECONNREFUSED") || error.message.includes("ENOTFOUND")) {
119
+ return new VoiceLiveConnectionError(`Connection failed: ${error.message}`, VoiceLiveErrorCodes.ConnectionFailed, "connection", true, error);
120
+ }
121
+ }
122
+ return new VoiceLiveConnectionError(`Unknown connection error: ${error instanceof Error ? error.message : String(error)}`, VoiceLiveErrorCodes.ConnectionFailed, "connection", true, error instanceof Error ? error : new Error(String(error)));
123
+ }
124
+ /**
125
+ * Classifies protocol errors
126
+ */
127
+ export function classifyProtocolError(error, messageType) {
128
+ if (error.message.includes("JSON")) {
129
+ return new VoiceLiveProtocolError(`Invalid JSON message: ${error.message}`, VoiceLiveErrorCodes.InvalidMessage, error);
130
+ }
131
+ if (error.message.includes("size") || error.message.includes("large")) {
132
+ return new VoiceLiveProtocolError(`Message too large: ${error.message}`, VoiceLiveErrorCodes.MessageTooLarge, error);
133
+ }
134
+ return new VoiceLiveProtocolError(`Protocol error in ${messageType}: ${error.message}`, VoiceLiveErrorCodes.ProtocolError, error);
135
+ }
136
+ //# sourceMappingURL=connectionErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectionErrors.js","sourceRoot":"","sources":["../../../src/errors/connectionErrors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAN,IAAY,mBA0BX;AA1BD,WAAY,mBAAmB;IAC7B,oBAAoB;IACpB,6DAAsC,CAAA;IACtC,+DAAwC,CAAA;IACxC,yDAAkC,CAAA;IAClC,6DAAsC,CAAA;IACtC,qDAA8B,CAAA;IAE9B,mBAAmB;IACnB,yDAAkC,CAAA;IAElC,wBAAwB;IACxB,qEAA8C,CAAA;IAC9C,iEAA0C,CAAA;IAC1C,oDAA6B,CAAA;IAC7B,8CAAuB,CAAA;IAEvB,kBAAkB;IAClB,yDAAkC,CAAA;IAClC,4DAAqC,CAAA;IACrC,uDAAgC,CAAA;IAChC,yDAAkC,CAAA;IAElC,iBAAiB;IACjB,iEAA0C,CAAA;IAC1C,qDAA8B,CAAA;AAChC,CAAC,EA1BW,mBAAmB,KAAnB,mBAAmB,QA0B9B;AAED;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,qDAAqD;IACrC,IAAI,CAAS;IAE7B,yDAAyD;IACzC,OAAO,CAAS;IAEhC,8DAA8D;IAC9C,WAAW,CAAU;IAErC,wDAAwD;IACxC,KAAK,CAAS;IAE9B,wCAAwC;IACxB,SAAS,CAAO;IAEhC,YACE,OAAe,EACf,IAAY,EACZ,UAAkB,WAAW,EAC7B,cAAuB,KAAK,EAC5B,KAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW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AAO,EAAE,EACrC,mBAAmB,CAAC,eAAe,EACnC,KAAK,CACN,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,sBAAsB,CAC/B,qBAAqB,WAAW,KAAK,KAAK,CAAC,OAAO,EAAE,EACpD,mBAAmB,CAAC,aAAa,EACjC,KAAK,CACN,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Error codes for Voice Live WebSocket operations\n */\nexport enum VoiceLiveErrorCodes {\n // Connection errors\n ConnectionFailed = \"CONNECTION_FAILED\",\n ConnectionTimeout = \"CONNECTION_TIMEOUT\",\n ConnectionLost = \"CONNECTION_LOST\",\n AlreadyConnected = \"ALREADY_CONNECTED\",\n NotConnected = \"NOT_CONNECTED\",\n\n // WebSocket errors\n WebSocketError = \"WEBSOCKET_ERROR\",\n\n // Authentication errors\n AuthenticationFailed = \"AUTHENTICATION_FAILED\",\n InvalidCredentials = \"INVALID_CREDENTIALS\",\n Unauthorized = \"UNAUTHORIZED\",\n Forbidden = \"FORBIDDEN\",\n\n // Protocol errors\n InvalidMessage = \"INVALID_MESSAGE\",\n MessageTooLarge = \"MESSAGE_TOO_LARGE\",\n ProtocolError = \"PROTOCOL_ERROR\",\n BufferOverflow = \"BUFFER_OVERFLOW\",\n\n // General errors\n OperationCancelled = \"OPERATION_CANCELLED\",\n InvalidState = \"INVALID_STATE\",\n}\n\n/**\n * Base error class for Voice Live WebSocket operations\n */\nexport class VoiceLiveConnectionError extends Error {\n /** Error code identifying the specific error type */\n public readonly code: string;\n\n /** Context information about where the error occurred */\n public readonly context: string;\n\n /** Indicates whether this error is potentially recoverable */\n public readonly recoverable: boolean;\n\n /** The original error that caused this error, if any */\n public readonly cause?: Error;\n\n /** Timestamp when the error occurred */\n public readonly timestamp: Date;\n\n constructor(\n message: string,\n code: string,\n context: string = \"websocket\",\n recoverable: boolean = false,\n cause?: Error,\n ) {\n super(message);\n this.name = \"VoiceLiveConnectionError\";\n this.code = code;\n this.context = context;\n this.recoverable = recoverable;\n this.cause = cause;\n this.timestamp = new Date();\n\n // Ensure proper stack trace in V8\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, VoiceLiveConnectionError);\n }\n\n // Make properties enumerable for JSON.stringify (following Azure SDK pattern)\n Object.defineProperty(this, \"message\", { enumerable: true });\n Object.defineProperty(this, \"name\", { enumerable: true });\n Object.defineProperty(this, \"stack\", { enumerable: true });\n }\n}\n\n/**\n * Authentication error class for Voice Live operations\n */\nexport class VoiceLiveAuthenticationError extends VoiceLiveConnectionError {\n constructor(message: string, code: string, cause?: Error) {\n super(message, code, \"authentication\", false, cause);\n this.name = \"VoiceLiveAuthenticationError\";\n }\n}\n\n/**\n * Protocol error class for Voice Live message operations\n */\nexport class VoiceLiveProtocolError extends VoiceLiveConnectionError {\n constructor(message: string, code: string, cause?: Error) {\n super(message, code, \"protocol\", false, cause);\n this.name = \"VoiceLiveProtocolError\";\n }\n}\n\n/**\n * General Voice Live error class\n */\nexport class VoiceLiveError extends VoiceLiveConnectionError {\n constructor(\n message: string,\n code: string,\n context: string = \"general\",\n recoverable: boolean = false,\n cause?: Error,\n ) {\n super(message, code, context, recoverable, cause);\n this.name = \"VoiceLiveError\";\n }\n}\n\n/**\n * Classifies a WebSocket close event and returns appropriate error\n */\nexport function classifyWebSocketClose(code: number, reason: string): VoiceLiveConnectionError {\n switch (code) {\n case 1000: // Normal closure\n return new VoiceLiveConnectionError(\n \"WebSocket connection closed normally\",\n VoiceLiveErrorCodes.ConnectionLost,\n \"websocket_close\",\n false,\n );\n\n case 1001: // Going away\n case 1006: // Abnormal closure\n return new VoiceLiveConnectionError(\n `WebSocket connection lost: ${reason || \"Abnormal closure\"}`,\n VoiceLiveErrorCodes.ConnectionLost,\n \"websocket_close\",\n true, // Recoverable\n );\n\n case 1008: // Policy violation\n return new VoiceLiveConnectionError(\n `WebSocket policy violation: ${reason}`,\n VoiceLiveErrorCodes.WebSocketError,\n \"websocket_close\",\n false, // Not recoverable\n );\n\n case 1011: // Server error\n return new VoiceLiveConnectionError(\n `WebSocket server error: ${reason}`,\n VoiceLiveErrorCodes.WebSocketError,\n \"websocket_close\",\n true, // Recoverable\n );\n\n default:\n return new VoiceLiveConnectionError(\n `WebSocket closed with code ${code}: ${reason}`,\n VoiceLiveErrorCodes.ConnectionLost,\n \"websocket_close\",\n true, // Default to recoverable\n );\n }\n}\n\n/**\n * Classifies connection errors\n */\nexport function classifyConnectionError(\n error: VoiceLiveConnectionError | Error | unknown,\n): VoiceLiveConnectionError {\n if (error instanceof VoiceLiveConnectionError) {\n return error;\n }\n\n if (error instanceof Error) {\n if (error.message.includes(\"timeout\")) {\n return new VoiceLiveConnectionError(\n `Connection timeout: ${error.message}`,\n VoiceLiveErrorCodes.ConnectionTimeout,\n \"connection\",\n true,\n error,\n );\n }\n\n if (error.message.includes(\"ECONNREFUSED\") || error.message.includes(\"ENOTFOUND\")) {\n return new VoiceLiveConnectionError(\n `Connection failed: ${error.message}`,\n VoiceLiveErrorCodes.ConnectionFailed,\n \"connection\",\n true,\n error,\n );\n }\n }\n\n return new VoiceLiveConnectionError(\n `Unknown connection error: ${error instanceof Error ? error.message : String(error)}`,\n VoiceLiveErrorCodes.ConnectionFailed,\n \"connection\",\n true,\n error instanceof Error ? error : new Error(String(error)),\n );\n}\n\n/**\n * Classifies protocol errors\n */\nexport function classifyProtocolError(error: Error, messageType: string): VoiceLiveProtocolError {\n if (error.message.includes(\"JSON\")) {\n return new VoiceLiveProtocolError(\n `Invalid JSON message: ${error.message}`,\n VoiceLiveErrorCodes.InvalidMessage,\n error,\n );\n }\n\n if (error.message.includes(\"size\") || error.message.includes(\"large\")) {\n return new VoiceLiveProtocolError(\n `Message too large: ${error.message}`,\n VoiceLiveErrorCodes.MessageTooLarge,\n error,\n );\n }\n\n return new VoiceLiveProtocolError(\n `Protocol error in ${messageType}: ${error.message}`,\n VoiceLiveErrorCodes.ProtocolError,\n error,\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./connectionErrors.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export * from "./connectionErrors.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport * from \"./connectionErrors.js\";\n"]}
@@ -0,0 +1,250 @@
1
+ import type { ServerEventUnion, ServerEventError, ServerEventSessionCreated, ServerEventSessionUpdated, ServerEventSessionAvatarConnecting, ServerEventInputAudioBufferCommitted, ServerEventInputAudioBufferCleared, ServerEventInputAudioBufferSpeechStarted, ServerEventInputAudioBufferSpeechStopped, ServerEventConversationItemCreated, ServerEventConversationItemInputAudioTranscriptionCompleted, ServerEventConversationItemInputAudioTranscriptionFailed, ServerEventConversationItemInputAudioTranscriptionDelta, ServerEventConversationItemTruncated, ServerEventConversationItemDeleted, ServerEventConversationItemRetrieved, ServerEventResponseCreated, ServerEventResponseDone, ServerEventResponseOutputItemAdded, ServerEventResponseOutputItemDone, ServerEventResponseContentPartAdded, ServerEventResponseContentPartDone, ServerEventResponseTextDelta, ServerEventResponseTextDone, ServerEventResponseAudioDelta, ServerEventResponseAudioDone, ServerEventResponseAudioTranscriptDelta, ServerEventResponseAudioTranscriptDone, ServerEventResponseAnimationBlendshapeDelta, ServerEventResponseAnimationBlendshapeDone, ServerEventResponseAnimationVisemeDelta, ServerEventResponseAnimationVisemeDone, ServerEventResponseAudioTimestampDelta, ServerEventResponseAudioTimestampDone, ServerEventResponseFunctionCallArgumentsDelta, ServerEventResponseFunctionCallArgumentsDone } from "../models/index.js";
2
+ /**
3
+ * Context information provided to connection-related handlers
4
+ */
5
+ export interface ConnectionContext {
6
+ /** The session endpoint URL */
7
+ readonly endpoint: string;
8
+ /** The session ID (if available) */
9
+ readonly sessionId?: string;
10
+ /** When the event occurred */
11
+ readonly timestamp: Date;
12
+ /** The model being used for this session */
13
+ readonly model: string;
14
+ }
15
+ /**
16
+ * Context information provided to session-related handlers
17
+ */
18
+ export interface SessionContext extends ConnectionContext {
19
+ /** The session ID (guaranteed to be available for session events) */
20
+ readonly sessionId: string;
21
+ /** The current conversation ID (if available) */
22
+ readonly conversationId?: string;
23
+ }
24
+ /**
25
+ * Arguments provided when a connection is established
26
+ */
27
+ export interface ConnectedEventArgs {
28
+ /** Connection identifier */
29
+ connectionId: string;
30
+ /** When the connection was established */
31
+ timestamp: Date;
32
+ }
33
+ /**
34
+ * Arguments provided when a connection is lost
35
+ */
36
+ export interface DisconnectedEventArgs {
37
+ /** WebSocket close code */
38
+ code: number;
39
+ /** Close reason */
40
+ reason: string;
41
+ /** Whether the close was clean */
42
+ wasClean: boolean;
43
+ /** When the disconnection occurred */
44
+ timestamp: Date;
45
+ }
46
+ /**
47
+ * Arguments provided when an error occurs
48
+ */
49
+ export interface ErrorEventArgs {
50
+ /** The error that occurred */
51
+ error: Error;
52
+ /** Additional context about where the error occurred */
53
+ context: string;
54
+ /** Whether the error is recoverable (always false in fail-fast model) */
55
+ recoverable: boolean;
56
+ /** When the error occurred */
57
+ timestamp: Date;
58
+ }
59
+ /**
60
+ * Handler functions for VoiceLive session events following Azure SDK patterns.
61
+ *
62
+ * ALL handlers are optional - implement only the events you care about!
63
+ * Each handler receives strongly-typed event data and context information.
64
+ */
65
+ export interface VoiceLiveSessionHandlers {
66
+ /**
67
+ * Called when the session connects successfully to the VoiceLive service
68
+ */
69
+ onConnected?: (args: ConnectedEventArgs, context: ConnectionContext) => Promise<void>;
70
+ /**
71
+ * Called when the session disconnects from the VoiceLive service
72
+ * In fail-fast mode, this indicates the session is permanently dead
73
+ */
74
+ onDisconnected?: (args: DisconnectedEventArgs, context: ConnectionContext) => Promise<void>;
75
+ /**
76
+ * Called when an error occurs that makes the session unusable
77
+ * In fail-fast mode, this indicates the session is permanently dead
78
+ */
79
+ onError?: (args: ErrorEventArgs, context: ConnectionContext) => Promise<void>;
80
+ /**
81
+ * Called when an error event is received from the server
82
+ */
83
+ onServerError?: (event: ServerEventError, context: SessionContext) => Promise<void>;
84
+ /**
85
+ * Called when the session is created on the server
86
+ */
87
+ onSessionCreated?: (event: ServerEventSessionCreated, context: SessionContext) => Promise<void>;
88
+ /**
89
+ * Called when the session configuration is updated
90
+ */
91
+ onSessionUpdated?: (event: ServerEventSessionUpdated, context: SessionContext) => Promise<void>;
92
+ /**
93
+ * Called when the server is establishing an avatar media connection
94
+ */
95
+ onSessionAvatarConnecting?: (event: ServerEventSessionAvatarConnecting, context: SessionContext) => Promise<void>;
96
+ /**
97
+ * Called when the input audio buffer is committed
98
+ */
99
+ onInputAudioBufferCommitted?: (event: ServerEventInputAudioBufferCommitted, context: SessionContext) => Promise<void>;
100
+ /**
101
+ * Called when the input audio buffer is cleared
102
+ */
103
+ onInputAudioBufferCleared?: (event: ServerEventInputAudioBufferCleared, context: SessionContext) => Promise<void>;
104
+ /**
105
+ * Called when speech is detected in the user's audio input
106
+ */
107
+ onInputAudioBufferSpeechStarted?: (event: ServerEventInputAudioBufferSpeechStarted, context: SessionContext) => Promise<void>;
108
+ /**
109
+ * Called when speech stops being detected in the user's audio input
110
+ */
111
+ onInputAudioBufferSpeechStopped?: (event: ServerEventInputAudioBufferSpeechStopped, context: SessionContext) => Promise<void>;
112
+ /**
113
+ * Called when a conversation item is created
114
+ */
115
+ onConversationItemCreated?: (event: ServerEventConversationItemCreated, context: SessionContext) => Promise<void>;
116
+ /**
117
+ * Called when input audio transcription is completed
118
+ */
119
+ onConversationItemInputAudioTranscriptionCompleted?: (event: ServerEventConversationItemInputAudioTranscriptionCompleted, context: SessionContext) => Promise<void>;
120
+ /**
121
+ * Called when input audio transcription fails
122
+ */
123
+ onConversationItemInputAudioTranscriptionFailed?: (event: ServerEventConversationItemInputAudioTranscriptionFailed, context: SessionContext) => Promise<void>;
124
+ /**
125
+ * Called when input audio transcription delta is received
126
+ */
127
+ onConversationItemInputAudioTranscriptionDelta?: (event: ServerEventConversationItemInputAudioTranscriptionDelta, context: SessionContext) => Promise<void>;
128
+ /**
129
+ * Called when a conversation item is truncated
130
+ */
131
+ onConversationItemTruncated?: (event: ServerEventConversationItemTruncated, context: SessionContext) => Promise<void>;
132
+ /**
133
+ * Called when a conversation item is deleted
134
+ */
135
+ onConversationItemDeleted?: (event: ServerEventConversationItemDeleted, context: SessionContext) => Promise<void>;
136
+ /**
137
+ * Called when a conversation item is retrieved
138
+ */
139
+ onConversationItemRetrieved?: (event: ServerEventConversationItemRetrieved, context: SessionContext) => Promise<void>;
140
+ /**
141
+ * Called when a response is created by the assistant
142
+ */
143
+ onResponseCreated?: (event: ServerEventResponseCreated, context: SessionContext) => Promise<void>;
144
+ /**
145
+ * Called when a response is completed by the assistant
146
+ */
147
+ onResponseDone?: (event: ServerEventResponseDone, context: SessionContext) => Promise<void>;
148
+ /**
149
+ * Called when a new output item is added to a response
150
+ */
151
+ onResponseOutputItemAdded?: (event: ServerEventResponseOutputItemAdded, context: SessionContext) => Promise<void>;
152
+ /**
153
+ * Called when an output item is completed
154
+ */
155
+ onResponseOutputItemDone?: (event: ServerEventResponseOutputItemDone, context: SessionContext) => Promise<void>;
156
+ /**
157
+ * Called when a new content part is added to a response
158
+ */
159
+ onResponseContentPartAdded?: (event: ServerEventResponseContentPartAdded, context: SessionContext) => Promise<void>;
160
+ /**
161
+ * Called when a content part is completed
162
+ */
163
+ onResponseContentPartDone?: (event: ServerEventResponseContentPartDone, context: SessionContext) => Promise<void>;
164
+ /**
165
+ * Called when text data is received from the assistant (streaming text response)
166
+ */
167
+ onResponseTextDelta?: (event: ServerEventResponseTextDelta, context: SessionContext) => Promise<void>;
168
+ /**
169
+ * Called when text response is completed
170
+ */
171
+ onResponseTextDone?: (event: ServerEventResponseTextDone, context: SessionContext) => Promise<void>;
172
+ /**
173
+ * Called when audio data is received from the assistant (streaming audio response)
174
+ */
175
+ onResponseAudioDelta?: (event: ServerEventResponseAudioDelta, context: SessionContext) => Promise<void>;
176
+ /**
177
+ * Called when audio response is completed
178
+ */
179
+ onResponseAudioDone?: (event: ServerEventResponseAudioDone, context: SessionContext) => Promise<void>;
180
+ /**
181
+ * Called when audio transcript data is received (what the assistant said as text)
182
+ */
183
+ onResponseAudioTranscriptDelta?: (event: ServerEventResponseAudioTranscriptDelta, context: SessionContext) => Promise<void>;
184
+ /**
185
+ * Called when audio transcript is completed
186
+ */
187
+ onResponseAudioTranscriptDone?: (event: ServerEventResponseAudioTranscriptDone, context: SessionContext) => Promise<void>;
188
+ /**
189
+ * Called when animation blendshape data is received
190
+ */
191
+ onResponseAnimationBlendshapeDelta?: (event: ServerEventResponseAnimationBlendshapeDelta, context: SessionContext) => Promise<void>;
192
+ /**
193
+ * Called when animation blendshape data is completed
194
+ */
195
+ onResponseAnimationBlendshapeDone?: (event: ServerEventResponseAnimationBlendshapeDone, context: SessionContext) => Promise<void>;
196
+ /**
197
+ * Called when animation viseme data is received
198
+ */
199
+ onResponseAnimationVisemeDelta?: (event: ServerEventResponseAnimationVisemeDelta, context: SessionContext) => Promise<void>;
200
+ /**
201
+ * Called when animation viseme data is completed
202
+ */
203
+ onResponseAnimationVisemeDone?: (event: ServerEventResponseAnimationVisemeDone, context: SessionContext) => Promise<void>;
204
+ /**
205
+ * Called when audio timestamp data is received
206
+ */
207
+ onResponseAudioTimestampDelta?: (event: ServerEventResponseAudioTimestampDelta, context: SessionContext) => Promise<void>;
208
+ /**
209
+ * Called when audio timestamp data is completed
210
+ */
211
+ onResponseAudioTimestampDone?: (event: ServerEventResponseAudioTimestampDone, context: SessionContext) => Promise<void>;
212
+ /**
213
+ * Called when function call arguments are received (streaming)
214
+ */
215
+ onResponseFunctionCallArgumentsDelta?: (event: ServerEventResponseFunctionCallArgumentsDelta, context: SessionContext) => Promise<void>;
216
+ /**
217
+ * Called when function call arguments are completed
218
+ */
219
+ onResponseFunctionCallArgumentsDone?: (event: ServerEventResponseFunctionCallArgumentsDone, context: SessionContext) => Promise<void>;
220
+ /**
221
+ * Called for all server events from the VoiceLive service.
222
+ * This is a catch-all handler that receives every server protocol message.
223
+ *
224
+ * Use this for:
225
+ * - Custom logging/monitoring of all events
226
+ * - Handling future events not yet covered by specific handlers
227
+ * - Debugging and development
228
+ *
229
+ * Note: This is called IN ADDITION TO any specific handlers above.
230
+ */
231
+ onServerEvent?: (event: ServerEventUnion, context: SessionContext) => Promise<void>;
232
+ }
233
+ /**
234
+ * Represents an active subscription to VoiceLive session events
235
+ */
236
+ export interface VoiceLiveSubscription {
237
+ /**
238
+ * Stops the subscription and cleans up resources
239
+ */
240
+ close(): Promise<void>;
241
+ /**
242
+ * Whether the subscription is currently active
243
+ */
244
+ readonly isActive: boolean;
245
+ /**
246
+ * The subscription ID for tracking
247
+ */
248
+ readonly subscriptionId: string;
249
+ }
250
+ //# sourceMappingURL=sessionHandlers.d.ts.map
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export {};
4
+ //# sourceMappingURL=sessionHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionHandlers.js","sourceRoot":"","sources":["../../../src/handlers/sessionHandlers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n ServerEventUnion,\n ServerEventError,\n ServerEventSessionCreated,\n ServerEventSessionUpdated,\n ServerEventSessionAvatarConnecting,\n ServerEventInputAudioBufferCommitted,\n ServerEventInputAudioBufferCleared,\n ServerEventInputAudioBufferSpeechStarted,\n ServerEventInputAudioBufferSpeechStopped,\n ServerEventConversationItemCreated,\n ServerEventConversationItemInputAudioTranscriptionCompleted,\n ServerEventConversationItemInputAudioTranscriptionFailed,\n ServerEventConversationItemInputAudioTranscriptionDelta,\n ServerEventConversationItemTruncated,\n ServerEventConversationItemDeleted,\n ServerEventConversationItemRetrieved,\n ServerEventResponseCreated,\n ServerEventResponseDone,\n ServerEventResponseOutputItemAdded,\n ServerEventResponseOutputItemDone,\n ServerEventResponseContentPartAdded,\n ServerEventResponseContentPartDone,\n ServerEventResponseTextDelta,\n ServerEventResponseTextDone,\n ServerEventResponseAudioDelta,\n ServerEventResponseAudioDone,\n ServerEventResponseAudioTranscriptDelta,\n ServerEventResponseAudioTranscriptDone,\n ServerEventResponseAnimationBlendshapeDelta,\n ServerEventResponseAnimationBlendshapeDone,\n ServerEventResponseAnimationVisemeDelta,\n ServerEventResponseAnimationVisemeDone,\n ServerEventResponseAudioTimestampDelta,\n ServerEventResponseAudioTimestampDone,\n ServerEventResponseFunctionCallArgumentsDelta,\n ServerEventResponseFunctionCallArgumentsDone,\n} from \"../models/index.js\";\n\n/**\n * Context information provided to connection-related handlers\n */\nexport interface ConnectionContext {\n /** The session endpoint URL */\n readonly endpoint: string;\n /** The session ID (if available) */\n readonly sessionId?: string;\n /** When the event occurred */\n readonly timestamp: Date;\n /** The model being used for this session */\n readonly model: string;\n}\n\n/**\n * Context information provided to session-related handlers\n */\nexport interface SessionContext extends ConnectionContext {\n /** The session ID (guaranteed to be available for session events) */\n readonly sessionId: string;\n /** The current conversation ID (if available) */\n readonly conversationId?: string;\n}\n\n/**\n * Arguments provided when a connection is established\n */\nexport interface ConnectedEventArgs {\n /** Connection identifier */\n connectionId: string;\n /** When the connection was established */\n timestamp: Date;\n}\n\n/**\n * Arguments provided when a connection is lost\n */\nexport interface DisconnectedEventArgs {\n /** WebSocket close code */\n code: number;\n /** Close reason */\n reason: string;\n /** Whether the close was clean */\n wasClean: boolean;\n /** When the disconnection occurred */\n timestamp: Date;\n}\n\n/**\n * Arguments provided when an error occurs\n */\nexport interface ErrorEventArgs {\n /** The error that occurred */\n error: Error;\n /** Additional context about where the error occurred */\n context: string;\n /** Whether the error is recoverable (always false in fail-fast model) */\n recoverable: boolean;\n /** When the error occurred */\n timestamp: Date;\n}\n\n/**\n * Handler functions for VoiceLive session events following Azure SDK patterns.\n *\n * ALL handlers are optional - implement only the events you care about!\n * Each handler receives strongly-typed event data and context information.\n */\nexport interface VoiceLiveSessionHandlers {\n // ========================================\n // CONNECTION LIFECYCLE EVENTS\n // ========================================\n\n /**\n * Called when the session connects successfully to the VoiceLive service\n */\n onConnected?: (args: ConnectedEventArgs, context: ConnectionContext) => Promise<void>;\n\n /**\n * Called when the session disconnects from the VoiceLive service\n * In fail-fast mode, this indicates the session is permanently dead\n */\n onDisconnected?: (args: DisconnectedEventArgs, context: ConnectionContext) => Promise<void>;\n\n /**\n * Called when an error occurs that makes the session unusable\n * In fail-fast mode, this indicates the session is permanently dead\n */\n onError?: (args: ErrorEventArgs, context: ConnectionContext) => Promise<void>;\n\n /**\n * Called when an error event is received from the server\n */\n onServerError?: (event: ServerEventError, context: SessionContext) => Promise<void>;\n\n /**\n * Called when the session is created on the server\n */\n onSessionCreated?: (event: ServerEventSessionCreated, context: SessionContext) => Promise<void>;\n\n /**\n * Called when the session configuration is updated\n */\n onSessionUpdated?: (event: ServerEventSessionUpdated, context: SessionContext) => Promise<void>;\n\n /**\n * Called when the server is establishing an avatar media connection\n */\n onSessionAvatarConnecting?: (\n event: ServerEventSessionAvatarConnecting,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // INPUT AUDIO BUFFER EVENTS\n // ========================================\n\n /**\n * Called when the input audio buffer is committed\n */\n onInputAudioBufferCommitted?: (\n event: ServerEventInputAudioBufferCommitted,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when the input audio buffer is cleared\n */\n onInputAudioBufferCleared?: (\n event: ServerEventInputAudioBufferCleared,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when speech is detected in the user's audio input\n */\n onInputAudioBufferSpeechStarted?: (\n event: ServerEventInputAudioBufferSpeechStarted,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when speech stops being detected in the user's audio input\n */\n onInputAudioBufferSpeechStopped?: (\n event: ServerEventInputAudioBufferSpeechStopped,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // CONVERSATION ITEM EVENTS\n // ========================================\n\n /**\n * Called when a conversation item is created\n */\n onConversationItemCreated?: (\n event: ServerEventConversationItemCreated,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when input audio transcription is completed\n */\n onConversationItemInputAudioTranscriptionCompleted?: (\n event: ServerEventConversationItemInputAudioTranscriptionCompleted,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when input audio transcription fails\n */\n onConversationItemInputAudioTranscriptionFailed?: (\n event: ServerEventConversationItemInputAudioTranscriptionFailed,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when input audio transcription delta is received\n */\n onConversationItemInputAudioTranscriptionDelta?: (\n event: ServerEventConversationItemInputAudioTranscriptionDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when a conversation item is truncated\n */\n onConversationItemTruncated?: (\n event: ServerEventConversationItemTruncated,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when a conversation item is deleted\n */\n onConversationItemDeleted?: (\n event: ServerEventConversationItemDeleted,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when a conversation item is retrieved\n */\n onConversationItemRetrieved?: (\n event: ServerEventConversationItemRetrieved,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // RESPONSE LIFECYCLE EVENTS\n // ========================================\n\n /**\n * Called when a response is created by the assistant\n */\n onResponseCreated?: (event: ServerEventResponseCreated, context: SessionContext) => Promise<void>;\n\n /**\n * Called when a response is completed by the assistant\n */\n onResponseDone?: (event: ServerEventResponseDone, context: SessionContext) => Promise<void>;\n\n /**\n * Called when a new output item is added to a response\n */\n onResponseOutputItemAdded?: (\n event: ServerEventResponseOutputItemAdded,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when an output item is completed\n */\n onResponseOutputItemDone?: (\n event: ServerEventResponseOutputItemDone,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when a new content part is added to a response\n */\n onResponseContentPartAdded?: (\n event: ServerEventResponseContentPartAdded,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when a content part is completed\n */\n onResponseContentPartDone?: (\n event: ServerEventResponseContentPartDone,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // RESPONSE TEXT EVENTS\n // ========================================\n\n /**\n * Called when text data is received from the assistant (streaming text response)\n */\n onResponseTextDelta?: (\n event: ServerEventResponseTextDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when text response is completed\n */\n onResponseTextDone?: (\n event: ServerEventResponseTextDone,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // RESPONSE AUDIO EVENTS\n // ========================================\n\n /**\n * Called when audio data is received from the assistant (streaming audio response)\n */\n onResponseAudioDelta?: (\n event: ServerEventResponseAudioDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when audio response is completed\n */\n onResponseAudioDone?: (\n event: ServerEventResponseAudioDone,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when audio transcript data is received (what the assistant said as text)\n */\n onResponseAudioTranscriptDelta?: (\n event: ServerEventResponseAudioTranscriptDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when audio transcript is completed\n */\n onResponseAudioTranscriptDone?: (\n event: ServerEventResponseAudioTranscriptDone,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // RESPONSE ANIMATION EVENTS\n // ========================================\n\n /**\n * Called when animation blendshape data is received\n */\n onResponseAnimationBlendshapeDelta?: (\n event: ServerEventResponseAnimationBlendshapeDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when animation blendshape data is completed\n */\n onResponseAnimationBlendshapeDone?: (\n event: ServerEventResponseAnimationBlendshapeDone,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when animation viseme data is received\n */\n onResponseAnimationVisemeDelta?: (\n event: ServerEventResponseAnimationVisemeDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when animation viseme data is completed\n */\n onResponseAnimationVisemeDone?: (\n event: ServerEventResponseAnimationVisemeDone,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // RESPONSE TIMING EVENTS\n // ========================================\n\n /**\n * Called when audio timestamp data is received\n */\n onResponseAudioTimestampDelta?: (\n event: ServerEventResponseAudioTimestampDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when audio timestamp data is completed\n */\n onResponseAudioTimestampDone?: (\n event: ServerEventResponseAudioTimestampDone,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // FUNCTION CALL EVENTS\n // ========================================\n\n /**\n * Called when function call arguments are received (streaming)\n */\n onResponseFunctionCallArgumentsDelta?: (\n event: ServerEventResponseFunctionCallArgumentsDelta,\n context: SessionContext,\n ) => Promise<void>;\n\n /**\n * Called when function call arguments are completed\n */\n onResponseFunctionCallArgumentsDone?: (\n event: ServerEventResponseFunctionCallArgumentsDone,\n context: SessionContext,\n ) => Promise<void>;\n\n // ========================================\n // CATCH-ALL HANDLER (OPTIONAL)\n // ========================================\n\n /**\n * Called for all server events from the VoiceLive service.\n * This is a catch-all handler that receives every server protocol message.\n *\n * Use this for:\n * - Custom logging/monitoring of all events\n * - Handling future events not yet covered by specific handlers\n * - Debugging and development\n *\n * Note: This is called IN ADDITION TO any specific handlers above.\n */\n onServerEvent?: (event: ServerEventUnion, context: SessionContext) => Promise<void>;\n}\n\n/**\n * Represents an active subscription to VoiceLive session events\n */\nexport interface VoiceLiveSubscription {\n /**\n * Stops the subscription and cleans up resources\n */\n close(): Promise<void>;\n\n /**\n * Whether the subscription is currently active\n */\n readonly isActive: boolean;\n\n /**\n * The subscription ID for tracking\n */\n readonly subscriptionId: string;\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import type { VoiceLiveSessionHandlers, VoiceLiveSubscription, ConnectionContext, SessionContext, ConnectedEventArgs, DisconnectedEventArgs, ErrorEventArgs } from "./sessionHandlers.js";
2
+ import type { ServerEventUnion } from "../models/index.js";
3
+ /**
4
+ * Internal implementation of VoiceLiveSubscription
5
+ */
6
+ export declare class VoiceLiveSubscriptionImpl implements VoiceLiveSubscription {
7
+ private _isActive;
8
+ private _handlers;
9
+ private _subscriptionId;
10
+ constructor(handlers: VoiceLiveSessionHandlers, subscriptionId: string);
11
+ get isActive(): boolean;
12
+ get subscriptionId(): string;
13
+ close(): Promise<void>;
14
+ /**
15
+ * Process a connection event
16
+ */
17
+ processConnectionEvent(eventType: "connected" | "disconnected" | "error", args: ConnectedEventArgs | DisconnectedEventArgs | ErrorEventArgs, context: ConnectionContext): Promise<void>;
18
+ /**
19
+ * Process a server event
20
+ */
21
+ processServerEvent(event: ServerEventUnion, context: SessionContext): Promise<void>;
22
+ }
23
+ /**
24
+ * Manages multiple subscriptions for a VoiceLive session
25
+ */
26
+ export declare class SubscriptionManager {
27
+ private _subscriptions;
28
+ private _nextSubscriptionId;
29
+ /**
30
+ * Create a new subscription
31
+ */
32
+ createSubscription(handlers: VoiceLiveSessionHandlers): VoiceLiveSubscription;
33
+ /**
34
+ * Remove a subscription
35
+ */
36
+ removeSubscription(subscriptionId: string): void;
37
+ /**
38
+ * Process a connection event for all active subscriptions
39
+ */
40
+ processConnectionEvent(eventType: "connected" | "disconnected" | "error", args: ConnectedEventArgs | DisconnectedEventArgs | ErrorEventArgs, context: ConnectionContext): Promise<void>;
41
+ /**
42
+ * Process a server event for all active subscriptions
43
+ */
44
+ processServerEvent(event: ServerEventUnion, context: SessionContext): Promise<void>;
45
+ /**
46
+ * Close all subscriptions
47
+ */
48
+ closeAll(): Promise<void>;
49
+ /**
50
+ * Get count of active subscriptions
51
+ */
52
+ get activeCount(): number;
53
+ }
54
+ //# sourceMappingURL=subscriptionManager.d.ts.map