openai 7.23.0 → 7.25.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 (240) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +4 -1
  3. package/client.d.mts +1 -1
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +1 -1
  6. package/client.d.ts.map +1 -1
  7. package/client.js +43 -5
  8. package/client.js.map +1 -1
  9. package/client.mjs +43 -5
  10. package/client.mjs.map +1 -1
  11. package/internal/responses/canonical-output-text.d.mts +8 -4
  12. package/internal/responses/canonical-output-text.d.mts.map +1 -1
  13. package/internal/responses/canonical-output-text.d.ts +8 -4
  14. package/internal/responses/canonical-output-text.d.ts.map +1 -1
  15. package/internal/responses/canonical-output-text.js +11 -0
  16. package/internal/responses/canonical-output-text.js.map +1 -1
  17. package/internal/responses/canonical-output-text.mjs +11 -0
  18. package/internal/responses/canonical-output-text.mjs.map +1 -1
  19. package/internal/responses/response-accumulator.d.mts +12 -1
  20. package/internal/responses/response-accumulator.d.mts.map +1 -1
  21. package/internal/responses/response-accumulator.d.ts +12 -1
  22. package/internal/responses/response-accumulator.d.ts.map +1 -1
  23. package/internal/responses/response-accumulator.js +99 -25
  24. package/internal/responses/response-accumulator.js.map +1 -1
  25. package/internal/responses/response-accumulator.mjs +97 -26
  26. package/internal/responses/response-accumulator.mjs.map +1 -1
  27. package/internal/ws.d.mts +6 -2
  28. package/internal/ws.d.mts.map +1 -1
  29. package/internal/ws.d.ts +6 -2
  30. package/internal/ws.d.ts.map +1 -1
  31. package/internal/ws.js +5 -3
  32. package/internal/ws.js.map +1 -1
  33. package/internal/ws.mjs +5 -3
  34. package/internal/ws.mjs.map +1 -1
  35. package/lib/live/transcript-grouping.d.mts.map +1 -1
  36. package/lib/live/transcript-grouping.d.ts.map +1 -1
  37. package/lib/live/transcript-grouping.js +6 -5
  38. package/lib/live/transcript-grouping.js.map +1 -1
  39. package/lib/live/transcript-grouping.mjs +6 -5
  40. package/lib/live/transcript-grouping.mjs.map +1 -1
  41. package/lib/responses/responses-websocket-accumulator.d.mts +72 -0
  42. package/lib/responses/responses-websocket-accumulator.d.mts.map +1 -0
  43. package/lib/responses/responses-websocket-accumulator.d.ts +72 -0
  44. package/lib/responses/responses-websocket-accumulator.d.ts.map +1 -0
  45. package/lib/responses/responses-websocket-accumulator.js +291 -0
  46. package/lib/responses/responses-websocket-accumulator.js.map +1 -0
  47. package/lib/responses/responses-websocket-accumulator.mjs +287 -0
  48. package/lib/responses/responses-websocket-accumulator.mjs.map +1 -0
  49. package/package.json +1 -1
  50. package/realtime/translations/ws.d.mts +84 -0
  51. package/realtime/translations/ws.d.mts.map +1 -0
  52. package/realtime/translations/ws.d.ts +84 -0
  53. package/realtime/translations/ws.d.ts.map +1 -0
  54. package/realtime/translations/ws.js +444 -0
  55. package/realtime/translations/ws.js.map +1 -0
  56. package/realtime/translations/ws.mjs +439 -0
  57. package/realtime/translations/ws.mjs.map +1 -0
  58. package/resources/audio/speech.d.mts +2 -2
  59. package/resources/audio/speech.d.mts.map +1 -1
  60. package/resources/audio/speech.d.ts +2 -2
  61. package/resources/audio/speech.d.ts.map +1 -1
  62. package/resources/audio/speech.js +1 -1
  63. package/resources/audio/speech.mjs +1 -1
  64. package/resources/audio/transcriptions.d.mts +2 -1
  65. package/resources/audio/transcriptions.d.mts.map +1 -1
  66. package/resources/audio/transcriptions.d.ts +2 -1
  67. package/resources/audio/transcriptions.d.ts.map +1 -1
  68. package/resources/audio/transcriptions.js.map +1 -1
  69. package/resources/audio/transcriptions.mjs.map +1 -1
  70. package/resources/beta/agents/agents.d.mts +577 -18
  71. package/resources/beta/agents/agents.d.mts.map +1 -1
  72. package/resources/beta/agents/agents.d.ts +577 -18
  73. package/resources/beta/agents/agents.d.ts.map +1 -1
  74. package/resources/beta/agents/agents.js.map +1 -1
  75. package/resources/beta/agents/agents.mjs.map +1 -1
  76. package/resources/beta/agents/environments/templates.d.mts +62 -9
  77. package/resources/beta/agents/environments/templates.d.mts.map +1 -1
  78. package/resources/beta/agents/environments/templates.d.ts +62 -9
  79. package/resources/beta/agents/environments/templates.d.ts.map +1 -1
  80. package/resources/beta/agents/index.d.mts +1 -1
  81. package/resources/beta/agents/index.d.mts.map +1 -1
  82. package/resources/beta/agents/index.d.ts +1 -1
  83. package/resources/beta/agents/index.d.ts.map +1 -1
  84. package/resources/beta/agents/index.js.map +1 -1
  85. package/resources/beta/agents/index.mjs.map +1 -1
  86. package/resources/beta/agents/sessions/events.d.mts +10 -7
  87. package/resources/beta/agents/sessions/events.d.mts.map +1 -1
  88. package/resources/beta/agents/sessions/events.d.ts +10 -7
  89. package/resources/beta/agents/sessions/events.d.ts.map +1 -1
  90. package/resources/beta/agents/sessions/events.js +10 -7
  91. package/resources/beta/agents/sessions/events.js.map +1 -1
  92. package/resources/beta/agents/sessions/events.mjs +10 -7
  93. package/resources/beta/agents/sessions/events.mjs.map +1 -1
  94. package/resources/beta/agents/sessions/sessions.d.mts +4 -2
  95. package/resources/beta/agents/sessions/sessions.d.mts.map +1 -1
  96. package/resources/beta/agents/sessions/sessions.d.ts +4 -2
  97. package/resources/beta/agents/sessions/sessions.d.ts.map +1 -1
  98. package/resources/beta/agents/sessions/sessions.js.map +1 -1
  99. package/resources/beta/agents/sessions/sessions.mjs.map +1 -1
  100. package/resources/beta/agents/vaults/credentials.d.mts +24 -7
  101. package/resources/beta/agents/vaults/credentials.d.mts.map +1 -1
  102. package/resources/beta/agents/vaults/credentials.d.ts +24 -7
  103. package/resources/beta/agents/vaults/credentials.d.ts.map +1 -1
  104. package/resources/beta/agents/vaults/credentials.js +2 -6
  105. package/resources/beta/agents/vaults/credentials.js.map +1 -1
  106. package/resources/beta/agents/vaults/credentials.mjs +2 -6
  107. package/resources/beta/agents/vaults/credentials.mjs.map +1 -1
  108. package/resources/beta/beta.d.mts +2 -2
  109. package/resources/beta/beta.d.mts.map +1 -1
  110. package/resources/beta/beta.d.ts +2 -2
  111. package/resources/beta/beta.d.ts.map +1 -1
  112. package/resources/beta/beta.js.map +1 -1
  113. package/resources/beta/beta.mjs.map +1 -1
  114. package/resources/beta/index.d.mts +1 -1
  115. package/resources/beta/index.d.mts.map +1 -1
  116. package/resources/beta/index.d.ts +1 -1
  117. package/resources/beta/index.d.ts.map +1 -1
  118. package/resources/beta/index.js.map +1 -1
  119. package/resources/beta/index.mjs.map +1 -1
  120. package/resources/beta/responses/responses.d.mts +69 -10
  121. package/resources/beta/responses/responses.d.mts.map +1 -1
  122. package/resources/beta/responses/responses.d.ts +69 -10
  123. package/resources/beta/responses/responses.d.ts.map +1 -1
  124. package/resources/beta/responses/responses.js.map +1 -1
  125. package/resources/beta/responses/responses.mjs.map +1 -1
  126. package/resources/files.d.mts +2 -2
  127. package/resources/files.d.mts.map +1 -1
  128. package/resources/files.d.ts +2 -2
  129. package/resources/files.d.ts.map +1 -1
  130. package/resources/index.d.mts +1 -1
  131. package/resources/index.d.mts.map +1 -1
  132. package/resources/index.d.ts +1 -1
  133. package/resources/index.d.ts.map +1 -1
  134. package/resources/live/forks/ws-base.js +1 -1
  135. package/resources/live/forks/ws-base.js.map +1 -1
  136. package/resources/live/forks/ws-base.mjs +1 -1
  137. package/resources/live/forks/ws-base.mjs.map +1 -1
  138. package/resources/live/sideband/ws-base.js +1 -1
  139. package/resources/live/sideband/ws-base.js.map +1 -1
  140. package/resources/live/sideband/ws-base.mjs +1 -1
  141. package/resources/live/sideband/ws-base.mjs.map +1 -1
  142. package/resources/live/ws-base.js +1 -1
  143. package/resources/live/ws-base.js.map +1 -1
  144. package/resources/live/ws-base.mjs +1 -1
  145. package/resources/live/ws-base.mjs.map +1 -1
  146. package/resources/realtime/index.d.mts +1 -0
  147. package/resources/realtime/index.d.mts.map +1 -1
  148. package/resources/realtime/index.d.ts +1 -0
  149. package/resources/realtime/index.d.ts.map +1 -1
  150. package/resources/realtime/index.js +3 -1
  151. package/resources/realtime/index.js.map +1 -1
  152. package/resources/realtime/index.mjs +1 -0
  153. package/resources/realtime/index.mjs.map +1 -1
  154. package/resources/realtime/realtime.d.mts +4 -0
  155. package/resources/realtime/realtime.d.mts.map +1 -1
  156. package/resources/realtime/realtime.d.ts +4 -0
  157. package/resources/realtime/realtime.d.ts.map +1 -1
  158. package/resources/realtime/realtime.js +4 -0
  159. package/resources/realtime/realtime.js.map +1 -1
  160. package/resources/realtime/realtime.mjs +4 -0
  161. package/resources/realtime/realtime.mjs.map +1 -1
  162. package/resources/realtime/translations/client-secrets.d.mts +67 -0
  163. package/resources/realtime/translations/client-secrets.d.mts.map +1 -0
  164. package/resources/realtime/translations/client-secrets.d.ts +67 -0
  165. package/resources/realtime/translations/client-secrets.d.ts.map +1 -0
  166. package/resources/realtime/translations/client-secrets.js +39 -0
  167. package/resources/realtime/translations/client-secrets.js.map +1 -0
  168. package/resources/realtime/translations/client-secrets.mjs +35 -0
  169. package/resources/realtime/translations/client-secrets.mjs.map +1 -0
  170. package/resources/realtime/translations/index.d.mts +3 -0
  171. package/resources/realtime/translations/index.d.mts.map +1 -0
  172. package/resources/realtime/translations/index.d.ts +3 -0
  173. package/resources/realtime/translations/index.d.ts.map +1 -0
  174. package/resources/realtime/translations/index.js +9 -0
  175. package/resources/realtime/translations/index.js.map +1 -0
  176. package/resources/realtime/translations/index.mjs +4 -0
  177. package/resources/realtime/translations/index.mjs.map +1 -0
  178. package/resources/realtime/translations/translations.d.mts +10 -0
  179. package/resources/realtime/translations/translations.d.mts.map +1 -0
  180. package/resources/realtime/translations/translations.d.ts +10 -0
  181. package/resources/realtime/translations/translations.d.ts.map +1 -0
  182. package/resources/realtime/translations/translations.js +17 -0
  183. package/resources/realtime/translations/translations.js.map +1 -0
  184. package/resources/realtime/translations/translations.mjs +12 -0
  185. package/resources/realtime/translations/translations.mjs.map +1 -0
  186. package/resources/realtime/translations.d.mts +2 -0
  187. package/resources/realtime/translations.d.mts.map +1 -0
  188. package/resources/realtime/translations.d.ts +2 -0
  189. package/resources/realtime/translations.d.ts.map +1 -0
  190. package/resources/realtime/translations.js +6 -0
  191. package/resources/realtime/translations.js.map +1 -0
  192. package/resources/realtime/translations.mjs +3 -0
  193. package/resources/realtime/translations.mjs.map +1 -0
  194. package/resources/responses/responses.d.mts +66 -7
  195. package/resources/responses/responses.d.mts.map +1 -1
  196. package/resources/responses/responses.d.ts +66 -7
  197. package/resources/responses/responses.d.ts.map +1 -1
  198. package/resources/responses/responses.js.map +1 -1
  199. package/resources/responses/responses.mjs.map +1 -1
  200. package/resources/shared.d.mts +1 -1
  201. package/resources/shared.d.mts.map +1 -1
  202. package/resources/shared.d.ts +1 -1
  203. package/resources/shared.d.ts.map +1 -1
  204. package/src/client.ts +42 -6
  205. package/src/internal/responses/canonical-output-text.ts +30 -5
  206. package/src/internal/responses/response-accumulator.ts +155 -56
  207. package/src/internal/ws.ts +5 -3
  208. package/src/lib/live/transcript-grouping.ts +6 -5
  209. package/src/lib/responses/responses-websocket-accumulator.ts +374 -0
  210. package/src/realtime/translations/ws.ts +539 -0
  211. package/src/resources/audio/speech.ts +4 -1
  212. package/src/resources/audio/transcriptions.ts +2 -1
  213. package/src/resources/beta/agents/agents.ts +699 -12
  214. package/src/resources/beta/agents/environments/templates.ts +70 -9
  215. package/src/resources/beta/agents/index.ts +3 -0
  216. package/src/resources/beta/agents/sessions/events.ts +10 -7
  217. package/src/resources/beta/agents/sessions/sessions.ts +4 -2
  218. package/src/resources/beta/agents/vaults/credentials.ts +21 -7
  219. package/src/resources/beta/beta.ts +6 -0
  220. package/src/resources/beta/index.ts +3 -0
  221. package/src/resources/beta/responses/responses.ts +75 -6
  222. package/src/resources/files.ts +3 -3
  223. package/src/resources/index.ts +1 -1
  224. package/src/resources/live/forks/ws-base.ts +1 -1
  225. package/src/resources/live/sideband/ws-base.ts +1 -1
  226. package/src/resources/live/ws-base.ts +1 -1
  227. package/src/resources/realtime/api.md +8 -0
  228. package/src/resources/realtime/index.ts +1 -0
  229. package/src/resources/realtime/realtime.ts +6 -0
  230. package/src/resources/realtime/translations/client-secrets.ts +93 -0
  231. package/src/resources/realtime/translations/index.ts +4 -0
  232. package/src/resources/realtime/translations/translations.ts +15 -0
  233. package/src/resources/realtime/translations.ts +3 -0
  234. package/src/resources/responses/responses.ts +72 -6
  235. package/src/resources/shared.ts +1 -0
  236. package/src/version.ts +1 -1
  237. package/version.d.mts +1 -1
  238. package/version.d.ts +1 -1
  239. package/version.js +1 -1
  240. package/version.mjs +1 -1
@@ -0,0 +1,287 @@
1
+ var _ResponsesWebSocketAccumulator_instances, _a, _ResponsesWebSocketAccumulator_context, _ResponsesWebSocketAccumulator_current, _ResponsesWebSocketAccumulator_at, _ResponsesWebSocketAccumulator_copyOutput, _ResponsesWebSocketAccumulator_validateOutputScaffold, _ResponsesWebSocketAccumulator_validateContentPart, _ResponsesWebSocketAccumulator_validateOutputEvent, _ResponsesWebSocketAccumulator_start;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "../../internal/tslib.mjs";
3
+ import { OpenAIError } from "../../core/error.mjs";
4
+ import { ensureCanonicalOutputText, getOutputText } from "../../internal/responses/canonical-output-text.mjs";
5
+ import { accumulateWebSocketOutput, cloneValidatedResponse, createResponseContext, isResponseOutputEvent, } from "../../internal/responses/response-accumulator.mjs";
6
+ import { hasOwn } from "../../internal/utils.mjs";
7
+ import { isObj } from "../../internal/utils/values.mjs";
8
+ // Keep the raw boundary aligned with the generated discriminants. Future wire
9
+ // items still belong to the raw lane and authoritative terminal event.
10
+ const outputItemTypes = {
11
+ message: true,
12
+ file_search_call: true,
13
+ function_call: true,
14
+ function_call_output: true,
15
+ web_search_call: true,
16
+ computer_call: true,
17
+ computer_call_output: true,
18
+ reasoning: true,
19
+ program: true,
20
+ program_output: true,
21
+ tool_search_call: true,
22
+ tool_search_output: true,
23
+ additional_tools: true,
24
+ compaction: true,
25
+ image_generation_call: true,
26
+ code_interpreter_call: true,
27
+ local_shell_call: true,
28
+ local_shell_call_output: true,
29
+ shell_call: true,
30
+ shell_call_output: true,
31
+ apply_patch_call: true,
32
+ apply_patch_call_output: true,
33
+ mcp_call: true,
34
+ mcp_list_tools: true,
35
+ mcp_approval_request: true,
36
+ mcp_approval_response: true,
37
+ custom_tool_call: true,
38
+ custom_tool_call_output: true,
39
+ };
40
+ /**
41
+ * Optional, caller-fed reconstruction of one lane's provisional output.
42
+ *
43
+ * Feed the raw events returned by lane.receive(). Use a separate instance per
44
+ * lane. This helper never reads, sends, closes, or registers a listener on a
45
+ * socket; raw events remain in the caller's hands. Tools remain output data.
46
+ * Provisional response metadata is preserved as received and is not yet schema
47
+ * validated. Narrow its unknown fields before use. Omitted fields remain absent.
48
+ * Raw deltas give per-event progress. Use outputAt(event.output_index) when an
49
+ * item finishes, or pass its content_index/summary_index to read only a changed
50
+ * part. For citations use content_index and annotation_index together. A full
51
+ * current, item, or part read materializes its entire nested contents, so
52
+ * reserve those reads for when that complete snapshot is needed.
53
+ *
54
+ * A socket stream can omit the item/content scaffolding required for deltas.
55
+ * Such a response is marked unavailable until the next creation or terminal
56
+ * event. Terminal events, including failures and errors, are retained exactly as
57
+ * delivered, without filling omitted output from provisional data.
58
+ */
59
+ export class ResponsesWebSocketAccumulator {
60
+ constructor() {
61
+ _ResponsesWebSocketAccumulator_instances.add(this);
62
+ _ResponsesWebSocketAccumulator_context.set(this, createResponseContext());
63
+ _ResponsesWebSocketAccumulator_current.set(this, void 0);
64
+ }
65
+ /** Materialize the full state. For per-item progress prefer outputAt(). */
66
+ get current() {
67
+ if (__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f")?.phase === 'provisional') {
68
+ if (__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f").outputTextDirty) {
69
+ __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f").snapshot.output_text = __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f").snapshot.output
70
+ .map((output) => getOutputText(__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f"), output))
71
+ .join('');
72
+ __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f").outputTextDirty = false;
73
+ }
74
+ return {
75
+ phase: 'provisional',
76
+ snapshot: __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f").snapshot),
77
+ };
78
+ }
79
+ return structuredClone(__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f"));
80
+ }
81
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- Only the generated output discriminator is validated; every raw nested value must remain unknown to callers.
82
+ outputAt(outputIndex, part) {
83
+ if (__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f")?.phase !== 'provisional') {
84
+ return undefined;
85
+ }
86
+ const output = __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_at).call(_a, __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f").snapshot.output, outputIndex);
87
+ if (!part) {
88
+ return __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, output);
89
+ }
90
+ if ('content_index' in part) {
91
+ if (output?.type === 'message' || output?.type === 'reasoning') {
92
+ const content = __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_at).call(_a, output.content, part.content_index);
93
+ if ('annotation_index' in part) {
94
+ return __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, content?.type === 'output_text'
95
+ ? __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_at).call(_a, content.annotations, part.annotation_index)
96
+ : undefined);
97
+ }
98
+ return __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, content);
99
+ }
100
+ }
101
+ else if (output?.type === 'reasoning') {
102
+ return __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_at).call(_a, output.summary, part.summary_index));
103
+ }
104
+ return undefined;
105
+ }
106
+ /** Drop retained provisional and terminal state without affecting any lane. */
107
+ reset() {
108
+ __classPrivateFieldSet(this, _ResponsesWebSocketAccumulator_context, createResponseContext(), "f");
109
+ __classPrivateFieldSet(this, _ResponsesWebSocketAccumulator_current, undefined, "f");
110
+ }
111
+ /** Record one raw lane event. Unknown event types leave the current state unchanged. */
112
+ add(event) {
113
+ if (event.type === 'response.completed' ||
114
+ event.type === 'response.failed' ||
115
+ event.type === 'response.incomplete' ||
116
+ event.type === 'error') {
117
+ __classPrivateFieldSet(this, _ResponsesWebSocketAccumulator_context, createResponseContext(), "f");
118
+ __classPrivateFieldSet(this, _ResponsesWebSocketAccumulator_current, { phase: 'terminal', event: structuredClone(event) }, "f");
119
+ return;
120
+ }
121
+ try {
122
+ if (event.type === 'response.created') {
123
+ __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_instances, "m", _ResponsesWebSocketAccumulator_start).call(this, { response: event.response });
124
+ return;
125
+ }
126
+ if (!isResponseOutputEvent(event) ||
127
+ __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f")?.phase === 'unavailable' ||
128
+ __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f")?.phase === 'terminal') {
129
+ return;
130
+ }
131
+ if (__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f")?.phase !== 'provisional') {
132
+ throw new OpenAIError("Cannot reconstruct WebSocket output before 'response.created'");
133
+ }
134
+ const outputEvent = structuredClone(event);
135
+ __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_validateOutputEvent).call(_a, outputEvent);
136
+ accumulateWebSocketOutput(outputEvent, __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_current, "f").snapshot, __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f"));
137
+ }
138
+ catch (error) {
139
+ __classPrivateFieldSet(this, _ResponsesWebSocketAccumulator_current, {
140
+ phase: 'unavailable',
141
+ error: error instanceof Error ? error : new OpenAIError('Invalid Responses WebSocket output event'),
142
+ }, "f");
143
+ }
144
+ }
145
+ }
146
+ _a = ResponsesWebSocketAccumulator, _ResponsesWebSocketAccumulator_context = new WeakMap(), _ResponsesWebSocketAccumulator_current = new WeakMap(), _ResponsesWebSocketAccumulator_instances = new WeakSet(), _ResponsesWebSocketAccumulator_at = function _ResponsesWebSocketAccumulator_at(collection, index) {
147
+ if (!Array.isArray(collection) || index === undefined || !Number.isSafeInteger(index) || index < 0) {
148
+ return undefined;
149
+ }
150
+ return collection[index];
151
+ }, _ResponsesWebSocketAccumulator_copyOutput = function _ResponsesWebSocketAccumulator_copyOutput(value) {
152
+ if (Array.isArray(value)) {
153
+ // SAFETY: Copying the array preserves every element's type and order.
154
+ return value.map((item) => __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, item));
155
+ }
156
+ if (isObj(value)) {
157
+ // SAFETY: Copying own data properties preserves the snapshot's JSON shape.
158
+ // fromEntries defines "__proto__" as an own property instead of invoking a setter.
159
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_copyOutput).call(_a, item)]));
160
+ }
161
+ return value;
162
+ }, _ResponsesWebSocketAccumulator_validateOutputScaffold = function _ResponsesWebSocketAccumulator_validateOutputScaffold(item) {
163
+ if (!isObj(item) ||
164
+ !hasOwn(item, 'type') ||
165
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- An unknown discriminator cannot satisfy the generated typed preview union.
166
+ typeof item['type'] !== 'string' ||
167
+ !hasOwn(outputItemTypes, item['type'])) {
168
+ throw new OpenAIError('Invalid Responses WebSocket output item');
169
+ }
170
+ if (item['type'] === 'message') {
171
+ if (!Array.isArray(item['content'])) {
172
+ throw new OpenAIError('Invalid Responses WebSocket message content');
173
+ }
174
+ for (const part of item['content']) {
175
+ __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_validateContentPart).call(_a, part);
176
+ }
177
+ }
178
+ if (item['type'] === 'function_call' ||
179
+ item['type'] === 'custom_tool_call' ||
180
+ item['type'] === 'mcp_call') {
181
+ const field = item['type'] === 'custom_tool_call' ? 'input' : 'arguments';
182
+ if (!hasOwn(item, 'name') ||
183
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- The caller feeds raw socket events; validate own required tool fields before exposing a typed snapshot.
184
+ typeof item['name'] !== 'string' ||
185
+ !hasOwn(item, field) ||
186
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Missing and numeric tool data cannot be extended as text.
187
+ typeof item[field] !== 'string') {
188
+ throw new OpenAIError('Invalid Responses WebSocket tool scaffold');
189
+ }
190
+ if (item['type'] === 'mcp_call' &&
191
+ (!hasOwn(item, 'server_label') ||
192
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- The server identity on an MCP scaffold is raw data, not a generated decoded string.
193
+ typeof item['server_label'] !== 'string')) {
194
+ throw new OpenAIError('Invalid Responses WebSocket MCP server label');
195
+ }
196
+ }
197
+ }, _ResponsesWebSocketAccumulator_validateContentPart = function _ResponsesWebSocketAccumulator_validateContentPart(part) {
198
+ if (!isObj(part) ||
199
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Raw output_text must not be silently coerced during a later provisional read.
200
+ (part['type'] === 'output_text' && typeof part['text'] !== 'string')) {
201
+ throw new OpenAIError('Invalid Responses WebSocket content part');
202
+ }
203
+ }, _ResponsesWebSocketAccumulator_validateOutputEvent = function _ResponsesWebSocketAccumulator_validateOutputEvent(event) {
204
+ switch (event.type) {
205
+ case 'response.output_item.added':
206
+ case 'response.output_item.done': {
207
+ __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_validateOutputScaffold).call(_a, event.item);
208
+ break;
209
+ }
210
+ case 'response.content_part.added':
211
+ case 'response.content_part.done': {
212
+ __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_validateContentPart).call(_a, event.part);
213
+ break;
214
+ }
215
+ case 'response.function_call_arguments.delta':
216
+ case 'response.mcp_call_arguments.delta':
217
+ case 'response.custom_tool_call_input.delta':
218
+ case 'response.output_text.delta':
219
+ case 'response.refusal.delta': {
220
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- The cloned raw event has not been schema-validated; do not coerce data into typed tool arguments.
221
+ if (typeof event.delta !== 'string') {
222
+ throw new OpenAIError('Invalid Responses WebSocket tool delta');
223
+ }
224
+ break;
225
+ }
226
+ case 'response.function_call_arguments.done':
227
+ case 'response.mcp_call_arguments.done': {
228
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- A final raw argument payload must satisfy the field exposed by the provisional snapshot.
229
+ if (typeof event.arguments !== 'string') {
230
+ throw new OpenAIError('Invalid Responses WebSocket tool arguments');
231
+ }
232
+ break;
233
+ }
234
+ case 'response.custom_tool_call_input.done': {
235
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Do not substitute omitted, null or object input for the typed text field.
236
+ if (typeof event.input !== 'string') {
237
+ throw new OpenAIError('Invalid Responses WebSocket custom tool input');
238
+ }
239
+ break;
240
+ }
241
+ case 'response.output_text.done': {
242
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Only actual wire text can replace the accumulated message text.
243
+ if (typeof event.text !== 'string') {
244
+ throw new OpenAIError('Invalid Responses WebSocket completed text');
245
+ }
246
+ break;
247
+ }
248
+ case 'response.refusal.done': {
249
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Refusals use their own finalized wire text field.
250
+ if (typeof event.refusal !== 'string') {
251
+ throw new OpenAIError('Invalid Responses WebSocket completed refusal');
252
+ }
253
+ break;
254
+ }
255
+ default: {
256
+ break;
257
+ }
258
+ }
259
+ }, _ResponsesWebSocketAccumulator_start = function _ResponsesWebSocketAccumulator_start(event) {
260
+ this.reset();
261
+ if (!isObj(event.response)) {
262
+ throw new OpenAIError('Responses WebSocket created event must contain a response');
263
+ }
264
+ // Only output fields are normalized; omitted response metadata is never invented.
265
+ const { output, output_text: outputText } = event.response;
266
+ if ((output !== undefined && !Array.isArray(output)) ||
267
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Validate optional text from an untyped WebSocket lifecycle before placing it in a typed provisional snapshot.
268
+ (outputText !== undefined && typeof outputText !== 'string')) {
269
+ throw new OpenAIError('Invalid Responses WebSocket initial output');
270
+ }
271
+ if (output !== undefined) {
272
+ for (const item of output) {
273
+ __classPrivateFieldGet(_a, _a, "m", _ResponsesWebSocketAccumulator_validateOutputScaffold).call(_a, item);
274
+ }
275
+ }
276
+ const snapshot = cloneValidatedResponse(__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f"), {
277
+ ...event.response,
278
+ output: output ?? [],
279
+ output_text: outputText ?? '',
280
+ });
281
+ if (outputText === undefined) {
282
+ ensureCanonicalOutputText(__classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f"), snapshot);
283
+ }
284
+ __classPrivateFieldGet(this, _ResponsesWebSocketAccumulator_context, "f").deferOutputText = true;
285
+ __classPrivateFieldSet(this, _ResponsesWebSocketAccumulator_current, { phase: 'provisional', snapshot }, "f");
286
+ };
287
+ //# sourceMappingURL=responses-websocket-accumulator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses-websocket-accumulator.mjs","sourceRoot":"","sources":["../../src/lib/responses/responses-websocket-accumulator.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAE/C,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,2DAAuD;AAC1G,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,0DAAsD;AACvD,OAAO,EAAE,MAAM,EAAE,iCAA6B;AAC9C,OAAO,EAAE,KAAK,EAAE,wCAAoC;AAapD,8EAA8E;AAC9E,uEAAuE;AACvE,MAAM,eAAe,GAAG;IACtB,OAAO,EAAE,IAAI;IACb,gBAAgB,EAAE,IAAI;IAC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0",
3
+ "version": "7.25.0",
4
4
  "description": "The official TypeScript library for the OpenAI API",
5
5
  "author": "OpenAI <support@openai.com>",
6
6
  "types": "./index.d.ts",
@@ -0,0 +1,84 @@
1
+ import * as WS from 'ws';
2
+ import type { OpenAI } from "../../client.mjs";
3
+ import { EventEmitter } from "../../lib/EventEmitter.mjs";
4
+ import { NodeWebSocket } from "../../internal/ws-adapter-node.mjs";
5
+ import type { RealtimeTranslationClientEvent, RealtimeTranslationServerEvent } from "../../resources/realtime/realtime.mjs";
6
+ import { OpenAIRealtimeError } from "../internal-base.mjs";
7
+ /** An event envelope, including event types added by the service in the future. */
8
+ export interface RealtimeTranslationEvent {
9
+ type: string;
10
+ [key: string]: unknown;
11
+ }
12
+ /** Options for a Node.js translation session. */
13
+ export interface RealtimeTranslationConnectOptions {
14
+ /** Translation model used to create the session. */
15
+ model: string;
16
+ /** Node `ws` options. Redirects are always disabled. */
17
+ options?: (Omit<WS.ClientOptions, 'headers'> & {
18
+ /** Case-insensitive overrides; null removes a default and undefined preserves it. */
19
+ headers?: Record<string, string | null | undefined> | undefined;
20
+ }) | undefined;
21
+ }
22
+ type TranslationEvents = {
23
+ event: (event: RealtimeTranslationServerEvent | RealtimeTranslationEvent) => void;
24
+ error: (error: OpenAIRealtimeError) => void;
25
+ } & {
26
+ [Type in Exclude<RealtimeTranslationServerEvent['type'], 'error'>]: (event: Extract<RealtimeTranslationServerEvent, {
27
+ type: Type;
28
+ }>) => void;
29
+ };
30
+ /**
31
+ * Node.js translation WebSocket. Install the optional `ws` peer dependency.
32
+ * Wait for `socket` to open before sending. Events are never buffered or replayed.
33
+ * Compression is off by default; set `options.perMessageDeflate` to opt in.
34
+ */
35
+ export declare class OpenAIRealtimeTranslationWS extends EventEmitter<TranslationEvents> {
36
+ /** Adapter exposing lifecycle events and the underlying Node socket as `platformSocket`. */
37
+ readonly socket: NodeWebSocket;
38
+ /** The configured endpoint and model for this connection. */
39
+ readonly url: URL;
40
+ /** Sends the protocol close once; use `finish` to await trailing output. */
41
+ readonly session: {
42
+ close: () => void;
43
+ };
44
+ private _inputClosed;
45
+ private _terminalReceived;
46
+ private _terminalDelivered;
47
+ private _transportClosed;
48
+ private _failure;
49
+ private _finishPromise;
50
+ private _resolveFinish;
51
+ private _rejectFinish;
52
+ private _finishTimer;
53
+ private _closeTimer;
54
+ private _signal;
55
+ private constructor();
56
+ /** Resolves the API key and starts connecting; resolves before the socket opens. */
57
+ static create(client: OpenAI, props: RealtimeTranslationConnectOptions): Promise<OpenAIRealtimeTranslationWS>;
58
+ /** Sends a typed event, future event envelope, or raw JSON envelope after the socket opens. */
59
+ send(event: RealtimeTranslationClientEvent | RealtimeTranslationEvent | string): void;
60
+ /**
61
+ * Stops input, sends `session.close` once, and delivers all events through `session.closed`.
62
+ * The first call owns the finite deadline and optional cancellation signal. Repeated calls
63
+ * share its result. API error events remain observable and do not end the drain.
64
+ * A timeout, abort, or transport failure rejects; no connection or input is replayed.
65
+ * Resolves after terminal delivery and transport closure. The deadline includes transport
66
+ * cleanup; a stalled close handshake is terminated and rejects the operation.
67
+ */
68
+ finish({ timeoutMs, signal }: {
69
+ timeoutMs: number;
70
+ signal?: AbortSignal | undefined;
71
+ }): Promise<void>;
72
+ /** Closes the transport without waiting for terminal output. Prefer `finish` for a complete session. */
73
+ close(): void;
74
+ private _onMessage;
75
+ private _onError;
76
+ private _reportError;
77
+ private _onClose;
78
+ private _onAbort;
79
+ private _fail;
80
+ private _settleFinish;
81
+ private _closeTransport;
82
+ }
83
+ export {};
84
+ //# sourceMappingURL=ws.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.d.mts","sourceRoot":"","sources":["../../src/realtime/translations/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAiB,MAAM,EAAE,yBAAqB;AAC1D,OAAO,EAAE,YAAY,EAAE,mCAA+B;AAOtD,OAAO,EAAE,aAAa,EAAE,2CAAuC;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,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,aAAa,CAAqD;IAC1E,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,WAAW,CAA4C;IAC/D,OAAO,CAAC,OAAO,CAA0B;IAEzC,OAAO;IASP,oFAAoF;WACvE,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,2BAA2B,CAAC;IA2CvC,+FAA+F;IAC/F,IAAI,CAAC,KAAK,EAAE,8BAA8B,GAAG,wBAAwB,GAAG,MAAM,GAAG,IAAI;IAuBrF;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA2CrG,wGAAwG;IACxG,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,UAAU,CAoDhB;IAEF,OAAO,CAAC,QAAQ,CAad;IAEF,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,QAAQ,CAqBd;IAEF,OAAO,CAAC,QAAQ,CAQd;IAEF,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,eAAe;CA4BxB"}
@@ -0,0 +1,84 @@
1
+ import * as WS from 'ws';
2
+ import type { OpenAI } from "../../client.js";
3
+ import { EventEmitter } from "../../lib/EventEmitter.js";
4
+ import { NodeWebSocket } from "../../internal/ws-adapter-node.js";
5
+ import type { RealtimeTranslationClientEvent, RealtimeTranslationServerEvent } from "../../resources/realtime/realtime.js";
6
+ import { OpenAIRealtimeError } from "../internal-base.js";
7
+ /** An event envelope, including event types added by the service in the future. */
8
+ export interface RealtimeTranslationEvent {
9
+ type: string;
10
+ [key: string]: unknown;
11
+ }
12
+ /** Options for a Node.js translation session. */
13
+ export interface RealtimeTranslationConnectOptions {
14
+ /** Translation model used to create the session. */
15
+ model: string;
16
+ /** Node `ws` options. Redirects are always disabled. */
17
+ options?: (Omit<WS.ClientOptions, 'headers'> & {
18
+ /** Case-insensitive overrides; null removes a default and undefined preserves it. */
19
+ headers?: Record<string, string | null | undefined> | undefined;
20
+ }) | undefined;
21
+ }
22
+ type TranslationEvents = {
23
+ event: (event: RealtimeTranslationServerEvent | RealtimeTranslationEvent) => void;
24
+ error: (error: OpenAIRealtimeError) => void;
25
+ } & {
26
+ [Type in Exclude<RealtimeTranslationServerEvent['type'], 'error'>]: (event: Extract<RealtimeTranslationServerEvent, {
27
+ type: Type;
28
+ }>) => void;
29
+ };
30
+ /**
31
+ * Node.js translation WebSocket. Install the optional `ws` peer dependency.
32
+ * Wait for `socket` to open before sending. Events are never buffered or replayed.
33
+ * Compression is off by default; set `options.perMessageDeflate` to opt in.
34
+ */
35
+ export declare class OpenAIRealtimeTranslationWS extends EventEmitter<TranslationEvents> {
36
+ /** Adapter exposing lifecycle events and the underlying Node socket as `platformSocket`. */
37
+ readonly socket: NodeWebSocket;
38
+ /** The configured endpoint and model for this connection. */
39
+ readonly url: URL;
40
+ /** Sends the protocol close once; use `finish` to await trailing output. */
41
+ readonly session: {
42
+ close: () => void;
43
+ };
44
+ private _inputClosed;
45
+ private _terminalReceived;
46
+ private _terminalDelivered;
47
+ private _transportClosed;
48
+ private _failure;
49
+ private _finishPromise;
50
+ private _resolveFinish;
51
+ private _rejectFinish;
52
+ private _finishTimer;
53
+ private _closeTimer;
54
+ private _signal;
55
+ private constructor();
56
+ /** Resolves the API key and starts connecting; resolves before the socket opens. */
57
+ static create(client: OpenAI, props: RealtimeTranslationConnectOptions): Promise<OpenAIRealtimeTranslationWS>;
58
+ /** Sends a typed event, future event envelope, or raw JSON envelope after the socket opens. */
59
+ send(event: RealtimeTranslationClientEvent | RealtimeTranslationEvent | string): void;
60
+ /**
61
+ * Stops input, sends `session.close` once, and delivers all events through `session.closed`.
62
+ * The first call owns the finite deadline and optional cancellation signal. Repeated calls
63
+ * share its result. API error events remain observable and do not end the drain.
64
+ * A timeout, abort, or transport failure rejects; no connection or input is replayed.
65
+ * Resolves after terminal delivery and transport closure. The deadline includes transport
66
+ * cleanup; a stalled close handshake is terminated and rejects the operation.
67
+ */
68
+ finish({ timeoutMs, signal }: {
69
+ timeoutMs: number;
70
+ signal?: AbortSignal | undefined;
71
+ }): Promise<void>;
72
+ /** Closes the transport without waiting for terminal output. Prefer `finish` for a complete session. */
73
+ close(): void;
74
+ private _onMessage;
75
+ private _onError;
76
+ private _reportError;
77
+ private _onClose;
78
+ private _onAbort;
79
+ private _fail;
80
+ private _settleFinish;
81
+ private _closeTransport;
82
+ }
83
+ export {};
84
+ //# sourceMappingURL=ws.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/realtime/translations/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAiB,MAAM,EAAE,wBAAqB;AAC1D,OAAO,EAAE,YAAY,EAAE,kCAA+B;AAOtD,OAAO,EAAE,aAAa,EAAE,0CAAuC;AAC/D,OAAO,KAAK,EAGV,8BAA8B,EAC9B,8BAA8B,EAE/B,6CAA0C;AAC3C,OAAO,EAAW,mBAAmB,EAAE,4BAAyB;AAEhE,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,iDAAiD;AACjD,MAAM,WAAW,iCAAiC;IAChD,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,CAAC,EACJ,CAA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