openai 7.25.0 → 7.26.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 (308) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/client.d.mts +5 -6
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +5 -6
  5. package/client.d.ts.map +1 -1
  6. package/client.js +38 -10
  7. package/client.js.map +1 -1
  8. package/client.mjs +39 -11
  9. package/client.mjs.map +1 -1
  10. package/core/streaming.d.mts +4 -0
  11. package/core/streaming.d.mts.map +1 -1
  12. package/core/streaming.d.ts +4 -0
  13. package/core/streaming.d.ts.map +1 -1
  14. package/core/streaming.js +6 -0
  15. package/core/streaming.js.map +1 -1
  16. package/core/streaming.mjs +6 -0
  17. package/core/streaming.mjs.map +1 -1
  18. package/helpers/beta/agents/standard-schema.d.mts +7 -0
  19. package/helpers/beta/agents/standard-schema.d.mts.map +1 -0
  20. package/helpers/beta/agents/standard-schema.d.ts +7 -0
  21. package/helpers/beta/agents/standard-schema.d.ts.map +1 -0
  22. package/helpers/beta/agents/standard-schema.js +12 -0
  23. package/helpers/beta/agents/standard-schema.js.map +1 -0
  24. package/helpers/beta/agents/standard-schema.mjs +9 -0
  25. package/helpers/beta/agents/standard-schema.mjs.map +1 -0
  26. package/helpers/beta/agents/zod.d.mts +10 -0
  27. package/helpers/beta/agents/zod.d.mts.map +1 -0
  28. package/helpers/beta/agents/zod.d.ts +10 -0
  29. package/helpers/beta/agents/zod.d.ts.map +1 -0
  30. package/helpers/beta/agents/zod.js +12 -0
  31. package/helpers/beta/agents/zod.js.map +1 -0
  32. package/helpers/beta/agents/zod.mjs +9 -0
  33. package/helpers/beta/agents/zod.mjs.map +1 -0
  34. package/internal/realtime-credentials.d.mts +22 -1
  35. package/internal/realtime-credentials.d.mts.map +1 -1
  36. package/internal/realtime-credentials.d.ts +22 -1
  37. package/internal/realtime-credentials.d.ts.map +1 -1
  38. package/internal/realtime-credentials.js +48 -4
  39. package/internal/realtime-credentials.js.map +1 -1
  40. package/internal/realtime-credentials.mjs +45 -4
  41. package/internal/realtime-credentials.mjs.map +1 -1
  42. package/internal/responses-ws-credentials.d.mts +23 -0
  43. package/internal/responses-ws-credentials.d.mts.map +1 -0
  44. package/internal/responses-ws-credentials.d.ts +23 -0
  45. package/internal/responses-ws-credentials.d.ts.map +1 -0
  46. package/internal/responses-ws-credentials.js +108 -0
  47. package/internal/responses-ws-credentials.js.map +1 -0
  48. package/internal/responses-ws-credentials.mjs +104 -0
  49. package/internal/responses-ws-credentials.mjs.map +1 -0
  50. package/internal/ws-adapter-node.d.mts +4 -0
  51. package/internal/ws-adapter-node.d.mts.map +1 -1
  52. package/internal/ws-adapter-node.d.ts +4 -0
  53. package/internal/ws-adapter-node.d.ts.map +1 -1
  54. package/internal/ws-adapter-node.js +56 -0
  55. package/internal/ws-adapter-node.js.map +1 -1
  56. package/internal/ws-adapter-node.mjs +55 -0
  57. package/internal/ws-adapter-node.mjs.map +1 -1
  58. package/internal/ws.d.mts +27 -4
  59. package/internal/ws.d.mts.map +1 -1
  60. package/internal/ws.d.ts +27 -4
  61. package/internal/ws.d.ts.map +1 -1
  62. package/internal/ws.js +105 -5
  63. package/internal/ws.js.map +1 -1
  64. package/internal/ws.mjs +102 -4
  65. package/internal/ws.mjs.map +1 -1
  66. package/lib/agents/agent-session-stream.d.mts +13 -4
  67. package/lib/agents/agent-session-stream.d.mts.map +1 -1
  68. package/lib/agents/agent-session-stream.d.ts +13 -4
  69. package/lib/agents/agent-session-stream.d.ts.map +1 -1
  70. package/lib/agents/agent-session-stream.js +24 -21
  71. package/lib/agents/agent-session-stream.js.map +1 -1
  72. package/lib/agents/agent-session-stream.mjs +24 -21
  73. package/lib/agents/agent-session-stream.mjs.map +1 -1
  74. package/lib/beta/agents/agent-session-create-stream.d.mts +15 -0
  75. package/lib/beta/agents/agent-session-create-stream.d.mts.map +1 -0
  76. package/lib/beta/agents/agent-session-create-stream.d.ts +15 -0
  77. package/lib/beta/agents/agent-session-create-stream.d.ts.map +1 -0
  78. package/lib/beta/agents/agent-session-create-stream.js +25 -0
  79. package/lib/beta/agents/agent-session-create-stream.js.map +1 -0
  80. package/lib/beta/agents/agent-session-create-stream.mjs +22 -0
  81. package/lib/beta/agents/agent-session-create-stream.mjs.map +1 -0
  82. package/lib/beta/agents/agent-turn-result-collector.d.mts +17 -0
  83. package/lib/beta/agents/agent-turn-result-collector.d.mts.map +1 -0
  84. package/lib/beta/agents/agent-turn-result-collector.d.ts +17 -0
  85. package/lib/beta/agents/agent-turn-result-collector.d.ts.map +1 -0
  86. package/lib/beta/agents/agent-turn-result-collector.js +99 -0
  87. package/lib/beta/agents/agent-turn-result-collector.js.map +1 -0
  88. package/lib/beta/agents/agent-turn-result-collector.mjs +95 -0
  89. package/lib/beta/agents/agent-turn-result-collector.mjs.map +1 -0
  90. package/lib/beta/agents/agent-turn-result-error.d.mts +16 -0
  91. package/lib/beta/agents/agent-turn-result-error.d.mts.map +1 -0
  92. package/lib/beta/agents/agent-turn-result-error.d.ts +16 -0
  93. package/lib/beta/agents/agent-turn-result-error.d.ts.map +1 -0
  94. package/lib/beta/agents/agent-turn-result-error.js +22 -0
  95. package/lib/beta/agents/agent-turn-result-error.js.map +1 -0
  96. package/lib/beta/agents/agent-turn-result-error.mjs +18 -0
  97. package/lib/beta/agents/agent-turn-result-error.mjs.map +1 -0
  98. package/lib/beta/agents/agent-turn-result.d.mts +12 -0
  99. package/lib/beta/agents/agent-turn-result.d.mts.map +1 -0
  100. package/lib/beta/agents/agent-turn-result.d.ts +12 -0
  101. package/lib/beta/agents/agent-turn-result.d.ts.map +1 -0
  102. package/lib/beta/agents/agent-turn-result.js +22 -0
  103. package/lib/beta/agents/agent-turn-result.js.map +1 -0
  104. package/lib/beta/agents/agent-turn-result.mjs +18 -0
  105. package/lib/beta/agents/agent-turn-result.mjs.map +1 -0
  106. package/lib/beta/agents/function-tool.d.mts +27 -0
  107. package/lib/beta/agents/function-tool.d.mts.map +1 -0
  108. package/lib/beta/agents/function-tool.d.ts +27 -0
  109. package/lib/beta/agents/function-tool.d.ts.map +1 -0
  110. package/lib/beta/agents/function-tool.js +48 -0
  111. package/lib/beta/agents/function-tool.js.map +1 -0
  112. package/lib/beta/agents/function-tool.mjs +45 -0
  113. package/lib/beta/agents/function-tool.mjs.map +1 -0
  114. package/lib/beta/agents/output-format-types.d.mts +11 -0
  115. package/lib/beta/agents/output-format-types.d.mts.map +1 -0
  116. package/lib/beta/agents/output-format-types.d.ts +11 -0
  117. package/lib/beta/agents/output-format-types.d.ts.map +1 -0
  118. package/lib/beta/agents/output-format-types.js +3 -0
  119. package/lib/beta/agents/output-format-types.js.map +1 -0
  120. package/lib/beta/agents/output-format-types.mjs +2 -0
  121. package/lib/beta/agents/output-format-types.mjs.map +1 -0
  122. package/lib/beta/agents/output-format.d.mts +8 -0
  123. package/lib/beta/agents/output-format.d.mts.map +1 -0
  124. package/lib/beta/agents/output-format.d.ts +8 -0
  125. package/lib/beta/agents/output-format.d.ts.map +1 -0
  126. package/lib/beta/agents/output-format.js +20 -0
  127. package/lib/beta/agents/output-format.js.map +1 -0
  128. package/lib/beta/agents/output-format.mjs +14 -0
  129. package/lib/beta/agents/output-format.mjs.map +1 -0
  130. package/lib/beta/agents/output-parse-error.d.mts +11 -0
  131. package/lib/beta/agents/output-parse-error.d.mts.map +1 -0
  132. package/lib/beta/agents/output-parse-error.d.ts +11 -0
  133. package/lib/beta/agents/output-parse-error.d.ts.map +1 -0
  134. package/lib/beta/agents/output-parse-error.js +22 -0
  135. package/lib/beta/agents/output-parse-error.js.map +1 -0
  136. package/lib/beta/agents/output-parse-error.mjs +18 -0
  137. package/lib/beta/agents/output-parse-error.mjs.map +1 -0
  138. package/lib/beta/agents/parse-result.d.mts +95 -0
  139. package/lib/beta/agents/parse-result.d.mts.map +1 -0
  140. package/lib/beta/agents/parse-result.d.ts +95 -0
  141. package/lib/beta/agents/parse-result.d.ts.map +1 -0
  142. package/lib/beta/agents/parse-result.js +116 -0
  143. package/lib/beta/agents/parse-result.js.map +1 -0
  144. package/lib/beta/agents/parse-result.mjs +110 -0
  145. package/lib/beta/agents/parse-result.mjs.map +1 -0
  146. package/lib/beta/agents/parsed-agent-turn-result.d.mts +8 -0
  147. package/lib/beta/agents/parsed-agent-turn-result.d.mts.map +1 -0
  148. package/lib/beta/agents/parsed-agent-turn-result.d.ts +8 -0
  149. package/lib/beta/agents/parsed-agent-turn-result.d.ts.map +1 -0
  150. package/lib/beta/agents/parsed-agent-turn-result.js +14 -0
  151. package/lib/beta/agents/parsed-agent-turn-result.js.map +1 -0
  152. package/lib/beta/agents/parsed-agent-turn-result.mjs +10 -0
  153. package/lib/beta/agents/parsed-agent-turn-result.mjs.map +1 -0
  154. package/lib/beta/agents/result-collection.d.mts +15 -0
  155. package/lib/beta/agents/result-collection.d.mts.map +1 -0
  156. package/lib/beta/agents/result-collection.d.ts +15 -0
  157. package/lib/beta/agents/result-collection.d.ts.map +1 -0
  158. package/lib/beta/agents/result-collection.js +110 -0
  159. package/lib/beta/agents/result-collection.js.map +1 -0
  160. package/lib/beta/agents/result-collection.mjs +106 -0
  161. package/lib/beta/agents/result-collection.mjs.map +1 -0
  162. package/lib/beta/agents/tool-output.d.mts +7 -0
  163. package/lib/beta/agents/tool-output.d.mts.map +1 -0
  164. package/lib/beta/agents/tool-output.d.ts +7 -0
  165. package/lib/beta/agents/tool-output.d.ts.map +1 -0
  166. package/lib/beta/agents/tool-output.js +26 -0
  167. package/lib/beta/agents/tool-output.js.map +1 -0
  168. package/lib/beta/agents/tool-output.mjs +23 -0
  169. package/lib/beta/agents/tool-output.mjs.map +1 -0
  170. package/lib/responses/responses-websocket-session.d.mts +1 -1
  171. package/lib/responses/responses-websocket-session.d.mts.map +1 -1
  172. package/lib/responses/responses-websocket-session.d.ts +1 -1
  173. package/lib/responses/responses-websocket-session.d.ts.map +1 -1
  174. package/lib/responses/responses-websocket-session.js +12 -2
  175. package/lib/responses/responses-websocket-session.js.map +1 -1
  176. package/lib/responses/responses-websocket-session.mjs +12 -2
  177. package/lib/responses/responses-websocket-session.mjs.map +1 -1
  178. package/package.json +1 -1
  179. package/resources/beta/agents/agents.d.mts +9 -0
  180. package/resources/beta/agents/agents.d.mts.map +1 -1
  181. package/resources/beta/agents/agents.d.ts +9 -0
  182. package/resources/beta/agents/agents.d.ts.map +1 -1
  183. package/resources/beta/agents/agents.js.map +1 -1
  184. package/resources/beta/agents/agents.mjs.map +1 -1
  185. package/resources/beta/agents/sessions/events.d.mts +6 -5
  186. package/resources/beta/agents/sessions/events.d.mts.map +1 -1
  187. package/resources/beta/agents/sessions/events.d.ts +6 -5
  188. package/resources/beta/agents/sessions/events.d.ts.map +1 -1
  189. package/resources/beta/agents/sessions/events.js +6 -5
  190. package/resources/beta/agents/sessions/events.js.map +1 -1
  191. package/resources/beta/agents/sessions/events.mjs +6 -5
  192. package/resources/beta/agents/sessions/events.mjs.map +1 -1
  193. package/resources/beta/agents/sessions/index.d.mts +1 -0
  194. package/resources/beta/agents/sessions/index.d.mts.map +1 -1
  195. package/resources/beta/agents/sessions/index.d.ts +1 -0
  196. package/resources/beta/agents/sessions/index.d.ts.map +1 -1
  197. package/resources/beta/agents/sessions/index.js +3 -1
  198. package/resources/beta/agents/sessions/index.js.map +1 -1
  199. package/resources/beta/agents/sessions/index.mjs +1 -0
  200. package/resources/beta/agents/sessions/index.mjs.map +1 -1
  201. package/resources/beta/agents/sessions/sessions.d.mts +16 -4
  202. package/resources/beta/agents/sessions/sessions.d.mts.map +1 -1
  203. package/resources/beta/agents/sessions/sessions.d.ts +16 -4
  204. package/resources/beta/agents/sessions/sessions.d.ts.map +1 -1
  205. package/resources/beta/agents/sessions/sessions.js +17 -4
  206. package/resources/beta/agents/sessions/sessions.js.map +1 -1
  207. package/resources/beta/agents/sessions/sessions.mjs +17 -4
  208. package/resources/beta/agents/sessions/sessions.mjs.map +1 -1
  209. package/resources/beta/agents/sessions/traces.d.mts +68 -0
  210. package/resources/beta/agents/sessions/traces.d.mts.map +1 -0
  211. package/resources/beta/agents/sessions/traces.d.ts +68 -0
  212. package/resources/beta/agents/sessions/traces.d.ts.map +1 -0
  213. package/resources/beta/agents/sessions/traces.js +81 -0
  214. package/resources/beta/agents/sessions/traces.js.map +1 -0
  215. package/resources/beta/agents/sessions/traces.mjs +77 -0
  216. package/resources/beta/agents/sessions/traces.mjs.map +1 -0
  217. package/resources/beta/responses/ws-base.d.mts +3 -1
  218. package/resources/beta/responses/ws-base.d.mts.map +1 -1
  219. package/resources/beta/responses/ws-base.d.ts +3 -1
  220. package/resources/beta/responses/ws-base.d.ts.map +1 -1
  221. package/resources/beta/responses/ws-base.js +35 -6
  222. package/resources/beta/responses/ws-base.js.map +1 -1
  223. package/resources/beta/responses/ws-base.mjs +35 -6
  224. package/resources/beta/responses/ws-base.mjs.map +1 -1
  225. package/resources/beta/responses/ws.d.mts +10 -0
  226. package/resources/beta/responses/ws.d.mts.map +1 -1
  227. package/resources/beta/responses/ws.d.ts +10 -0
  228. package/resources/beta/responses/ws.d.ts.map +1 -1
  229. package/resources/beta/responses/ws.js +23 -22
  230. package/resources/beta/responses/ws.js.map +1 -1
  231. package/resources/beta/responses/ws.mjs +24 -23
  232. package/resources/beta/responses/ws.mjs.map +1 -1
  233. package/resources/chat/completions/completions.d.mts +1 -1
  234. package/resources/chat/completions/completions.d.mts.map +1 -1
  235. package/resources/chat/completions/completions.d.ts +1 -1
  236. package/resources/chat/completions/completions.d.ts.map +1 -1
  237. package/resources/evals/runs/runs.js +1 -1
  238. package/resources/evals/runs/runs.js.map +1 -1
  239. package/resources/evals/runs/runs.mjs +1 -1
  240. package/resources/evals/runs/runs.mjs.map +1 -1
  241. package/resources/live/forks/forks.d.mts +5 -1
  242. package/resources/live/forks/forks.d.mts.map +1 -1
  243. package/resources/live/forks/forks.d.ts +5 -1
  244. package/resources/live/forks/forks.d.ts.map +1 -1
  245. package/resources/live/live.d.mts +5 -1
  246. package/resources/live/live.d.mts.map +1 -1
  247. package/resources/live/live.d.ts +5 -1
  248. package/resources/live/live.d.ts.map +1 -1
  249. package/resources/live/live.js.map +1 -1
  250. package/resources/live/live.mjs.map +1 -1
  251. package/resources/responses/ws-base.d.mts +3 -1
  252. package/resources/responses/ws-base.d.mts.map +1 -1
  253. package/resources/responses/ws-base.d.ts +3 -1
  254. package/resources/responses/ws-base.d.ts.map +1 -1
  255. package/resources/responses/ws-base.js +35 -6
  256. package/resources/responses/ws-base.js.map +1 -1
  257. package/resources/responses/ws-base.mjs +35 -6
  258. package/resources/responses/ws-base.mjs.map +1 -1
  259. package/resources/responses/ws.d.mts +10 -0
  260. package/resources/responses/ws.d.mts.map +1 -1
  261. package/resources/responses/ws.d.ts +10 -0
  262. package/resources/responses/ws.d.ts.map +1 -1
  263. package/resources/responses/ws.js +23 -22
  264. package/resources/responses/ws.js.map +1 -1
  265. package/resources/responses/ws.mjs +24 -23
  266. package/resources/responses/ws.mjs.map +1 -1
  267. package/src/client.ts +55 -19
  268. package/src/core/streaming.ts +9 -0
  269. package/src/helpers/beta/agents/standard-schema.ts +13 -0
  270. package/src/helpers/beta/agents/zod.ts +10 -0
  271. package/src/internal/realtime-credentials.ts +70 -4
  272. package/src/internal/responses-ws-credentials.ts +160 -0
  273. package/src/internal/ws-adapter-node.ts +66 -0
  274. package/src/internal/ws.ts +139 -11
  275. package/src/lib/agents/agent-session-stream.ts +36 -24
  276. package/src/lib/beta/agents/agent-session-create-stream.ts +36 -0
  277. package/src/lib/beta/agents/agent-turn-result-collector.ts +122 -0
  278. package/src/lib/beta/agents/agent-turn-result-error.ts +33 -0
  279. package/src/lib/beta/agents/agent-turn-result.ts +22 -0
  280. package/src/lib/beta/agents/function-tool.ts +60 -0
  281. package/src/lib/beta/agents/output-format-types.ts +12 -0
  282. package/src/lib/beta/agents/output-format.ts +20 -0
  283. package/src/lib/beta/agents/output-parse-error.ts +16 -0
  284. package/src/lib/beta/agents/parse-result.ts +133 -0
  285. package/src/lib/beta/agents/parsed-agent-turn-result.ts +12 -0
  286. package/src/lib/beta/agents/result-collection.ts +115 -0
  287. package/src/lib/beta/agents/tool-output.ts +22 -0
  288. package/src/lib/responses/responses-websocket-session.ts +14 -3
  289. package/src/resources/beta/agents/agents.ts +11 -0
  290. package/src/resources/beta/agents/sessions/events.ts +6 -5
  291. package/src/resources/beta/agents/sessions/index.ts +1 -0
  292. package/src/resources/beta/agents/sessions/sessions.ts +48 -18
  293. package/src/resources/beta/agents/sessions/traces.ts +298 -0
  294. package/src/resources/beta/responses/ws-base.ts +40 -6
  295. package/src/resources/beta/responses/ws.ts +37 -27
  296. package/src/resources/chat/completions/completions.ts +1 -1
  297. package/src/resources/evals/runs/runs.ts +1 -1
  298. package/src/resources/live/forks/forks.ts +6 -1
  299. package/src/resources/live/live.ts +6 -1
  300. package/src/resources/responses/ws-base.ts +40 -6
  301. package/src/resources/responses/ws.ts +37 -27
  302. package/src/tsconfig.dist-src-node.d.ts +7 -0
  303. package/src/tsconfig.dist-src.d.ts +3 -1
  304. package/src/version.ts +1 -1
  305. package/version.d.mts +1 -1
  306. package/version.d.ts +1 -1
  307. package/version.js +1 -1
  308. package/version.mjs +1 -1
@@ -0,0 +1,133 @@
1
+ import type { RequestOptions } from '../../../internal/request-options';
2
+ import { OpenAIError } from '../../../core/error';
3
+ import type { SessionCreateParams } from '../../../resources/beta/agents/sessions/sessions';
4
+ import type { AgentTurnResult } from './agent-turn-result';
5
+ import type { TextFormatParam } from '../../../resources/beta/agents/agents';
6
+ import type { AgentOutputFormat, AgentResult } from './output-format-types';
7
+ import { ParsedAgentTurnResult } from './parsed-agent-turn-result';
8
+ import { AgentOutputParseError } from './output-parse-error';
9
+
10
+ /** @internal */
11
+ export function parseAgentResult<T>(result: AgentTurnResult, format?: AgentOutputFormat<T>): AgentResult<T> {
12
+ try {
13
+ if (!format) {
14
+ // SAFETY: Absent formats use the default never/raw overload.
15
+ return result as AgentResult<T>;
16
+ }
17
+ let first: { value: T } | undefined;
18
+ for (const message of result.messages) {
19
+ for (const content of message.content) {
20
+ if (content.type === 'output_text') {
21
+ const value = format.$parseRaw(content.text);
22
+ first ??= { value };
23
+ }
24
+ }
25
+ }
26
+ if (!first) {
27
+ throw new AgentOutputParseError(result);
28
+ }
29
+ // SAFETY: Callers preserve the format's inferred T.
30
+ return new ParsedAgentTurnResult(result, first.value) as AgentResult<T>;
31
+ } catch {
32
+ throw new AgentOutputParseError(result);
33
+ }
34
+ }
35
+
36
+ // Inspect only JSON-visible data fields; leave getters and inherited values to normal serialization.
37
+ function ownJSONValue<T extends object, K extends keyof T>(
38
+ object: T | null | undefined,
39
+ key: K,
40
+ ): T[K] | undefined {
41
+ const descriptor = object && Object.getOwnPropertyDescriptor(object, key);
42
+ // SAFETY: The own data descriptor corresponds to the requested property in T.
43
+ return descriptor?.enumerable && 'value' in descriptor ? (descriptor.value as T[K]) : undefined;
44
+ }
45
+
46
+ /** @internal */
47
+ export function agentFormatParser<T = unknown>(
48
+ format: TextFormatParam | null | undefined,
49
+ ): AgentOutputFormat<T> | undefined {
50
+ if (!format) {
51
+ return undefined;
52
+ }
53
+ const descriptor = Object.getOwnPropertyDescriptor(format, '$parseRaw');
54
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- An own parser data property is the explicit opt-in marker.
55
+ if (!descriptor || !('value' in descriptor) || typeof descriptor.value !== 'function') {
56
+ return undefined;
57
+ }
58
+ // SAFETY: Inspect the schema data descriptor without evaluating a caller getter; validate its discriminator below.
59
+ const schema = ownJSONValue(format as TextFormatParam.TextFormatParamJSONSchema, 'schema');
60
+ if (ownJSONValue(format, 'type') !== 'json_schema' || !schema) {
61
+ throw new OpenAIError('Typed agent formats require own enumerable type and schema data properties');
62
+ }
63
+ // SAFETY: The own descriptor was checked for a callable parser; retain its receiver and never reread the property.
64
+ const parse = descriptor.value as AgentOutputFormat<T>['$parseRaw'];
65
+ return { type: 'json_schema', schema, $parseRaw: (text) => parse.call(format, text) };
66
+ }
67
+
68
+ // Materialize JSON-visible envelope getters once without evaluating unrelated properties.
69
+ function snapshotJSONProperty<T extends object, K extends keyof T>(
70
+ object: T,
71
+ key: K,
72
+ capture: (value: T[K]) => T[K] = (value) => value,
73
+ ): T {
74
+ const descriptor = Object.getOwnPropertyDescriptor(object, key);
75
+ if (!descriptor?.enumerable) {
76
+ return object;
77
+ }
78
+ const value = capture(object[key]);
79
+ if ('value' in descriptor && value === descriptor.value) {
80
+ return object;
81
+ }
82
+ // SAFETY: Preserve the original properties/prototype, replacing only this captured property's value.
83
+ return Object.create(Object.getPrototypeOf(object), {
84
+ ...Object.getOwnPropertyDescriptors(object),
85
+ [key]: { value, enumerable: true, configurable: descriptor.configurable, writable: true },
86
+ }) as T;
87
+ }
88
+
89
+ /** @internal */
90
+ export function captureAgentOutput(input: SessionCreateParams, options?: RequestOptions) {
91
+ const body = snapshotJSONProperty(input, 'agent', (agent) =>
92
+ agent
93
+ ? snapshotJSONProperty(agent, 'text', (text) => (text ? snapshotJSONProperty(text, 'format') : text))
94
+ : agent,
95
+ );
96
+ const agent = ownJSONValue(body, 'agent');
97
+ const text = ownJSONValue(agent, 'text');
98
+ const format = agentFormatParser(ownJSONValue(text, 'format'));
99
+ if (!format) {
100
+ return { body, options };
101
+ }
102
+ const schema = structuredClone(format.schema);
103
+ for (const envelope of [body, agent, text]) {
104
+ if (envelope && 'toJSON' in envelope) {
105
+ throw new OpenAIError('Typed agent requests cannot customize body, agent, or text serialization');
106
+ }
107
+ }
108
+ // Snapshot options once, matching the own enumerable fields native request spreading uses.
109
+ const capturedOptions = { ...options };
110
+ if (ownJSONValue(capturedOptions, 'body') !== undefined) {
111
+ throw new OpenAIError('Typed agent requests cannot override the body in request options');
112
+ }
113
+ delete capturedOptions.body;
114
+ return {
115
+ options: capturedOptions,
116
+ body: {
117
+ ...body,
118
+ agent: {
119
+ ...agent,
120
+ text: { ...text, format: { type: 'json_schema', schema } },
121
+ },
122
+ },
123
+ format,
124
+ };
125
+ }
126
+
127
+ /** @internal */
128
+ export async function parseAgentResultPromise<T>(
129
+ result: Promise<AgentTurnResult>,
130
+ format?: AgentOutputFormat<T>,
131
+ ): Promise<AgentResult<T>> {
132
+ return parseAgentResult(await result, format);
133
+ }
@@ -0,0 +1,12 @@
1
+ import { AgentTurnResult } from './agent-turn-result';
2
+
3
+ /** Beta: a completed hosted turn whose output passed the local parser. */
4
+ export class ParsedAgentTurnResult<T> extends AgentTurnResult {
5
+ readonly output_parsed: T;
6
+ readonly raw_result: AgentTurnResult;
7
+ constructor(result: AgentTurnResult, parsed: T) {
8
+ super(result.turn, result.messages);
9
+ this.raw_result = result;
10
+ this.output_parsed = parsed;
11
+ }
12
+ }
@@ -0,0 +1,115 @@
1
+ import { OpenAIError } from '../../../core/error';
2
+ import type { AgentSessionEvent } from '../../../resources/beta/agents/agents';
3
+ import type { AgentTurnResult } from './agent-turn-result';
4
+ import { AgentTurnResultCollector } from './agent-turn-result-collector';
5
+ import { AgentTurnResultError } from './agent-turn-result-error';
6
+
7
+ /** Shares collection between a raw creation stream and the follow-up helper.
8
+ * @internal
9
+ */
10
+ export class ResultCollection {
11
+ #iterator: AsyncGenerator<AgentSessionEvent, void> | undefined;
12
+ #ended = false;
13
+ #enabled = false;
14
+ #uncollectedEvents = false;
15
+ #error: unknown;
16
+ #result: Promise<AgentTurnResult> | undefined;
17
+ readonly collector: AgentTurnResultCollector;
18
+
19
+ readonly #source: () => AsyncIterator<AgentSessionEvent>;
20
+ readonly #signal: AbortSignal | undefined;
21
+ readonly #canHandle: (name: string) => boolean;
22
+
23
+ constructor(
24
+ source: () => AsyncIterator<AgentSessionEvent>,
25
+ canHandle: (name: string) => boolean = () => false,
26
+ sessionID?: string,
27
+ signal?: AbortSignal,
28
+ ) {
29
+ this.#source = source;
30
+ this.#signal = signal;
31
+ this.#canHandle = canHandle;
32
+ this.collector = new AgentTurnResultCollector(sessionID);
33
+ }
34
+
35
+ enable(): void {
36
+ if (!this.#enabled && this.#uncollectedEvents) {
37
+ throw new OpenAIError(
38
+ 'Call withResultCollection() before consuming events, or call finalResult() on a fresh stream.',
39
+ );
40
+ }
41
+ this.#enabled = true;
42
+ }
43
+
44
+ iterate(): AsyncIterator<AgentSessionEvent> {
45
+ if (this.#iterator) {
46
+ throw new OpenAIError('An agent result stream can only be consumed once');
47
+ }
48
+ return (this.#iterator = this.#observe());
49
+ }
50
+
51
+ async *#observe(): AsyncGenerator<AgentSessionEvent, void> {
52
+ const iterator = this.#source();
53
+ let done = false;
54
+ try {
55
+ while (true) {
56
+ // oxlint-disable-next-line no-await-in-loop -- Pull the single-use stream sequentially.
57
+ const next = await iterator.next();
58
+ if (next.done) {
59
+ done = true;
60
+ return;
61
+ }
62
+ if (this.#enabled) {
63
+ this.collector.accept(next.value);
64
+ } else {
65
+ this.#uncollectedEvents = true;
66
+ }
67
+ yield next.value;
68
+ }
69
+ } catch (error) {
70
+ if (this.#enabled) {
71
+ this.#error = error;
72
+ }
73
+ throw error;
74
+ } finally {
75
+ this.#ended = true;
76
+ if (!done) {
77
+ await iterator.return?.();
78
+ }
79
+ }
80
+ }
81
+
82
+ finalResult(): Promise<AgentTurnResult> {
83
+ return (this.#result ??= this.#collect());
84
+ }
85
+
86
+ async #collect(): Promise<AgentTurnResult> {
87
+ this.enable();
88
+ try {
89
+ const iterator = this.#iterator ?? this.iterate();
90
+ while (!this.#ended && !this.collector.ready) {
91
+ this.collector.checkAction(this.#canHandle);
92
+ // oxlint-disable-next-line no-await-in-loop -- Each event can dispatch tools before the next pull.
93
+ const next = await iterator.next();
94
+ if (next.done) {
95
+ break;
96
+ }
97
+ }
98
+ if (this.#error !== undefined && !this.collector.ready) {
99
+ throw this.#error;
100
+ }
101
+ if (!this.collector.ready && this.#signal?.aborted) {
102
+ throw this.collector.error('observation', this.#signal.reason);
103
+ }
104
+ return this.collector.finish();
105
+ } catch (error) {
106
+ throw error instanceof AgentTurnResultError ? error : this.collector.error('observation', error);
107
+ } finally {
108
+ try {
109
+ await this.#iterator?.return();
110
+ } finally {
111
+ this.collector.release();
112
+ }
113
+ }
114
+ }
115
+ }
@@ -0,0 +1,22 @@
1
+ import { hasOwn, isObj } from '../../../internal/utils/values';
2
+ import type { InputContentParam } from '../../../resources/beta/agents/agents';
3
+
4
+ /**
5
+ * Recognizes supported content blocks without confusing JSON business data with content.
6
+ * @internal
7
+ */
8
+ export function isInputContent(value: unknown): value is InputContentParam {
9
+ if (!isObj(value)) {
10
+ return false;
11
+ }
12
+ const content = value;
13
+ let field: string;
14
+ if (content['type'] === 'input_text') {
15
+ field = 'text';
16
+ } else if (content['type'] === 'input_image') {
17
+ field = 'image_url';
18
+ } else {
19
+ return false;
20
+ }
21
+ return hasOwn(content, 'type') && hasOwn(content, field) && typeof content[field] === 'string';
22
+ }
@@ -22,9 +22,13 @@ interface LaneState {
22
22
  bytes: number;
23
23
  }
24
24
 
25
+ // A disposed helper cannot distinguish a delayed terminal from a later request
26
+ // on the same socket. Retain only IDs (never lane buffers) until that socket is gone.
27
+ const reservedLanes = new WeakMap<WebSocketLike, Set<string | undefined>>();
28
+
25
29
  /** Limits for this optional helper. They do not change the underlying socket's limits. */
26
30
  export interface ResponsesWebSocketSessionOptions {
27
- /** Maximum lane IDs registered until the next reconnect, including detached lanes. */
31
+ /** Maximum lane IDs registered on the socket until the next reconnect, including detached lanes. */
28
32
  maxLanes: number;
29
33
  /** Maximum queued events across all lanes. */
30
34
  maxBufferedEvents: number;
@@ -129,10 +133,16 @@ export class ResponsesWebSocketSession {
129
133
  ) {
130
134
  throw new OpenAIError('Invalid Responses WebSocket stream ID');
131
135
  }
132
- if (this.#lanes.has(streamID)) {
136
+ const { socket: physicalSocket } = this.#connection;
137
+ let reservations = reservedLanes.get(physicalSocket);
138
+ if (!reservations) {
139
+ reservations = new Set();
140
+ reservedLanes.set(physicalSocket, reservations);
141
+ }
142
+ if (reservations.has(streamID)) {
133
143
  throw new OpenAIError('Responses WebSocket lane is already registered');
134
144
  }
135
- if (this.#lanes.size >= this.#maxLanes) {
145
+ if (reservations.size >= this.#maxLanes) {
136
146
  throw new OpenAIError('Responses WebSocket lane limit exceeded');
137
147
  }
138
148
  const entry: LaneState = {
@@ -160,6 +170,7 @@ export class ResponsesWebSocketSession {
160
170
  positiveInteger(limits.maxBufferedBytes ?? this.#maxBytes),
161
171
  ),
162
172
  };
173
+ reservations.add(streamID);
163
174
  this.#lanes.set(streamID, entry);
164
175
  return entry.lane;
165
176
  }
@@ -3667,6 +3667,12 @@ export namespace Environment {
3667
3667
  */
3668
3668
  type: 'openai_hosted';
3669
3669
 
3670
+ /**
3671
+ * The effective CPU and memory tier, or null when unknown or outside the public
3672
+ * tiers.
3673
+ */
3674
+ container_size?: 'small' | 'medium' | 'large' | null;
3675
+
3670
3676
  /**
3671
3677
  * The effective desktop configuration.
3672
3678
  */
@@ -3791,6 +3797,11 @@ export namespace EnvironmentParam {
3791
3797
  */
3792
3798
  capability_directories?: Array<string> | null;
3793
3799
 
3800
+ /**
3801
+ * The hosted container size. Omission selects the medium tier.
3802
+ */
3803
+ container_size?: 'small' | 'medium' | 'large';
3804
+
3794
3805
  /**
3795
3806
  * Desktop provisioning. Omission or null inherits the template setting, or
3796
3807
  * defaults to disabled.
@@ -17,11 +17,12 @@ function resolveResourceRequestOptions(
17
17
 
18
18
  export class Events extends APIResource {
19
19
  /**
20
- * Submits message, cancellation, or tool-result events to a managed agent session.
21
- * Cancellation can recover a still-open turn whose backend execution has ended by
22
- * marking it cancelled and abandoning unpublished outputs. Saved results,
23
- * published files, and existing terminal outcomes are preserved. HTTP 202 confirms
24
- * acceptance, not durable completion. See
20
+ * Submits message, cancellation, tool-result, or computer-use approval-response
21
+ * events to a managed agent session. Cancellation can recover a still-open turn
22
+ * whose backend execution has ended by marking it cancelled and abandoning
23
+ * unpublished outputs. Saved results, published files, and existing terminal
24
+ * outcomes are preserved. HTTP 202 confirms acceptance, not durable completion.
25
+ * See
25
26
  * [session events](https://developers.openai.com/api/docs/guides/agents-api/sessions/events).
26
27
  *
27
28
  * @example
@@ -21,4 +21,5 @@ export {
21
21
  type SessionListParams,
22
22
  } from './sessions';
23
23
  export { Subagents, type SubagentRetrieveParams, type SubagentListParams } from './subagents/index';
24
+ export { Traces, type SessionTrace, type TraceListParams, type SessionTracesPage } from './traces';
24
25
  export { Turns, type Turn, type TurnRetrieveParams, type TurnListParams, type TurnsPage } from './turns';
@@ -4,6 +4,12 @@ import {
4
4
  AgentSessionStream,
5
5
  type AgentSessionStreamParams,
6
6
  } from '../../../../lib/agents/agent-session-stream';
7
+ import {
8
+ type AgentSessionCreateStream,
9
+ withAgentTurnResult,
10
+ } from '../../../../lib/beta/agents/agent-session-create-stream';
11
+ import type { AgentOutputFormat } from '../../../../lib/beta/agents/output-format-types';
12
+ import { captureAgentOutput } from '../../../../lib/beta/agents/parse-result';
7
13
  import { APIResource } from '../../../../core/resource';
8
14
  import * as SessionsAPI from './sessions';
9
15
  import * as AgentsAPI from '../agents';
@@ -23,13 +29,15 @@ import * as EventsAPI from './events';
23
29
  import { EventCreateParams, Events } from './events';
24
30
  import * as ItemsAPI from './items';
25
31
  import { ItemListParams, Items } from './items';
32
+ import * as TracesAPI from './traces';
33
+ import { SessionTrace, SessionTracesPage, TraceListParams, Traces } from './traces';
26
34
  import * as TurnsAPI from './turns';
27
35
  import { Turn, TurnListParams, TurnRetrieveParams, Turns, TurnsPage } from './turns';
28
36
  import * as SubagentsAPI from './subagents/subagents';
29
37
  import { SubagentListParams, SubagentRetrieveParams, Subagents } from './subagents/subagents';
30
38
  import { APIPromise } from '../../../../core/api-promise';
31
39
  import { CursorPage, type CursorPageParams, PagePromise } from '../../../../core/pagination';
32
- import { Stream } from '../../../../core/streaming';
40
+ import type { Stream } from '../../../../core/streaming';
33
41
  import { buildHeaders } from '../../../../internal/headers';
34
42
  import { RequestOptions } from '../../../../internal/request-options';
35
43
  import { path } from '../../../../internal/utils/path';
@@ -150,7 +158,11 @@ function normalizeRequestOptionsForQuery(
150
158
 
151
159
  export class Sessions extends APIResource {
152
160
  /** Stream one turn on an idle session with a single input writer. See AgentSessionStream for lifecycle and tool handling. */
153
- stream(sessionID: string, params: AgentSessionStreamParams, options?: RequestOptions): AgentSessionStream {
161
+ stream<T = never>(
162
+ sessionID: string,
163
+ params: AgentSessionStreamParams<T>,
164
+ options?: RequestOptions,
165
+ ): AgentSessionStream<T> {
154
166
  return new AgentSessionStream(this, sessionID, params, options);
155
167
  }
156
168
 
@@ -158,6 +170,7 @@ export class Sessions extends APIResource {
158
170
  artifacts: ArtifactsAPI.Artifacts = new ArtifactsAPI.Artifacts(this._client);
159
171
  items: ItemsAPI.Items = new ItemsAPI.Items(this._client);
160
172
  events: EventsAPI.Events = new EventsAPI.Events(this._client);
173
+ traces: TracesAPI.Traces = new TracesAPI.Traces(this._client);
161
174
  turns: TurnsAPI.Turns = new TurnsAPI.Turns(this._client);
162
175
 
163
176
  /**
@@ -173,29 +186,38 @@ export class Sessions extends APIResource {
173
186
  * });
174
187
  * ```
175
188
  */
176
- create(body: SessionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<AgentsAPI.AgentSession>;
177
- create(
178
- body: SessionCreateParamsStreaming,
189
+ create<T>(
190
+ body: SessionCreateParamsStreaming & { agent: { text: { format: AgentOutputFormat<T> } } },
179
191
  options?: RequestOptions,
180
- ): APIPromise<Stream<AgentsAPI.AgentSessionEvent>>;
192
+ ): APIPromise<AgentSessionCreateStream<T>>;
193
+ create(body: SessionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<AgentsAPI.AgentSession>;
194
+ create(body: SessionCreateParamsStreaming, options?: RequestOptions): APIPromise<AgentSessionCreateStream>;
181
195
  create(
182
196
  body: SessionCreateParamsBase,
183
197
  options?: RequestOptions,
184
- ): APIPromise<Stream<AgentsAPI.AgentSessionEvent> | AgentsAPI.AgentSession>;
198
+ ): APIPromise<AgentSessionCreateStream | AgentsAPI.AgentSession>;
185
199
  create(
186
200
  body: SessionCreateParams,
187
201
  options?: RequestOptions,
188
- ): APIPromise<AgentsAPI.AgentSession> | APIPromise<Stream<AgentsAPI.AgentSessionEvent>> {
189
- return this._client.post(
190
- '/agents/sessions',
191
- resolveResourceRequestOptions(options, (options) => ({
192
- body,
193
- ...options,
194
- headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
195
- stream: body.stream ?? false,
196
- __security: { bearerAuth: true },
197
- })),
198
- ) as APIPromise<AgentsAPI.AgentSession> | APIPromise<Stream<AgentsAPI.AgentSessionEvent>>;
202
+ ): APIPromise<AgentsAPI.AgentSession> | APIPromise<AgentSessionCreateStream> {
203
+ const output = captureAgentOutput(body, options);
204
+ return this._client
205
+ .post<AgentsAPI.AgentSession | Stream<AgentsAPI.AgentSessionEvent>>(
206
+ '/agents/sessions',
207
+ resolveResourceRequestOptions(output.options, (options) => ({
208
+ body: output.body,
209
+ ...options,
210
+ headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
211
+ stream: output.body.stream ?? false,
212
+ __security: { bearerAuth: true },
213
+ })),
214
+ )
215
+ ._thenUnwrap((data, { options }) =>
216
+ // SAFETY: defaultParseResponse uses this same resolved flag to return the configured stream instance.
217
+ options.stream
218
+ ? withAgentTurnResult(data as Stream<AgentsAPI.AgentSessionEvent>, output.format)
219
+ : data,
220
+ ) as APIPromise<AgentsAPI.AgentSession> | APIPromise<AgentSessionCreateStream>;
199
221
  }
200
222
 
201
223
  /**
@@ -587,6 +609,7 @@ Sessions.Subagents = Subagents;
587
609
  Sessions.Artifacts = Artifacts;
588
610
  Sessions.Items = Items;
589
611
  Sessions.Events = Events;
612
+ Sessions.Traces = Traces;
590
613
  Sessions.Turns = Turns;
591
614
 
592
615
  export declare namespace Sessions {
@@ -619,6 +642,13 @@ export declare namespace Sessions {
619
642
 
620
643
  export { Events as Events, type EventCreateParams as EventCreateParams };
621
644
 
645
+ export {
646
+ Traces as Traces,
647
+ type SessionTrace as SessionTrace,
648
+ type SessionTracesPage as SessionTracesPage,
649
+ type TraceListParams as TraceListParams,
650
+ };
651
+
622
652
  export {
623
653
  Turns as Turns,
624
654
  type Turn as Turn,