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.
- package/CHANGELOG.md +51 -0
- package/README.md +4 -1
- package/client.d.mts +1 -1
- package/client.d.mts.map +1 -1
- package/client.d.ts +1 -1
- package/client.d.ts.map +1 -1
- package/client.js +43 -5
- package/client.js.map +1 -1
- package/client.mjs +43 -5
- package/client.mjs.map +1 -1
- package/internal/responses/canonical-output-text.d.mts +8 -4
- package/internal/responses/canonical-output-text.d.mts.map +1 -1
- package/internal/responses/canonical-output-text.d.ts +8 -4
- package/internal/responses/canonical-output-text.d.ts.map +1 -1
- package/internal/responses/canonical-output-text.js +11 -0
- package/internal/responses/canonical-output-text.js.map +1 -1
- package/internal/responses/canonical-output-text.mjs +11 -0
- package/internal/responses/canonical-output-text.mjs.map +1 -1
- package/internal/responses/response-accumulator.d.mts +12 -1
- package/internal/responses/response-accumulator.d.mts.map +1 -1
- package/internal/responses/response-accumulator.d.ts +12 -1
- package/internal/responses/response-accumulator.d.ts.map +1 -1
- package/internal/responses/response-accumulator.js +99 -25
- package/internal/responses/response-accumulator.js.map +1 -1
- package/internal/responses/response-accumulator.mjs +97 -26
- package/internal/responses/response-accumulator.mjs.map +1 -1
- package/internal/ws.d.mts +6 -2
- package/internal/ws.d.mts.map +1 -1
- package/internal/ws.d.ts +6 -2
- package/internal/ws.d.ts.map +1 -1
- package/internal/ws.js +5 -3
- package/internal/ws.js.map +1 -1
- package/internal/ws.mjs +5 -3
- package/internal/ws.mjs.map +1 -1
- package/lib/live/transcript-grouping.d.mts.map +1 -1
- package/lib/live/transcript-grouping.d.ts.map +1 -1
- package/lib/live/transcript-grouping.js +6 -5
- package/lib/live/transcript-grouping.js.map +1 -1
- package/lib/live/transcript-grouping.mjs +6 -5
- package/lib/live/transcript-grouping.mjs.map +1 -1
- package/lib/responses/responses-websocket-accumulator.d.mts +72 -0
- package/lib/responses/responses-websocket-accumulator.d.mts.map +1 -0
- package/lib/responses/responses-websocket-accumulator.d.ts +72 -0
- package/lib/responses/responses-websocket-accumulator.d.ts.map +1 -0
- package/lib/responses/responses-websocket-accumulator.js +291 -0
- package/lib/responses/responses-websocket-accumulator.js.map +1 -0
- package/lib/responses/responses-websocket-accumulator.mjs +287 -0
- package/lib/responses/responses-websocket-accumulator.mjs.map +1 -0
- package/package.json +1 -1
- package/realtime/translations/ws.d.mts +84 -0
- package/realtime/translations/ws.d.mts.map +1 -0
- package/realtime/translations/ws.d.ts +84 -0
- package/realtime/translations/ws.d.ts.map +1 -0
- package/realtime/translations/ws.js +444 -0
- package/realtime/translations/ws.js.map +1 -0
- package/realtime/translations/ws.mjs +439 -0
- package/realtime/translations/ws.mjs.map +1 -0
- package/resources/audio/speech.d.mts +2 -2
- package/resources/audio/speech.d.mts.map +1 -1
- package/resources/audio/speech.d.ts +2 -2
- package/resources/audio/speech.d.ts.map +1 -1
- package/resources/audio/speech.js +1 -1
- package/resources/audio/speech.mjs +1 -1
- package/resources/audio/transcriptions.d.mts +2 -1
- package/resources/audio/transcriptions.d.mts.map +1 -1
- package/resources/audio/transcriptions.d.ts +2 -1
- package/resources/audio/transcriptions.d.ts.map +1 -1
- package/resources/audio/transcriptions.js.map +1 -1
- package/resources/audio/transcriptions.mjs.map +1 -1
- package/resources/beta/agents/agents.d.mts +577 -18
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +577 -18
- package/resources/beta/agents/agents.d.ts.map +1 -1
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/agents/environments/templates.d.mts +62 -9
- package/resources/beta/agents/environments/templates.d.mts.map +1 -1
- package/resources/beta/agents/environments/templates.d.ts +62 -9
- package/resources/beta/agents/environments/templates.d.ts.map +1 -1
- package/resources/beta/agents/index.d.mts +1 -1
- package/resources/beta/agents/index.d.mts.map +1 -1
- package/resources/beta/agents/index.d.ts +1 -1
- package/resources/beta/agents/index.d.ts.map +1 -1
- package/resources/beta/agents/index.js.map +1 -1
- package/resources/beta/agents/index.mjs.map +1 -1
- package/resources/beta/agents/sessions/events.d.mts +10 -7
- package/resources/beta/agents/sessions/events.d.mts.map +1 -1
- package/resources/beta/agents/sessions/events.d.ts +10 -7
- package/resources/beta/agents/sessions/events.d.ts.map +1 -1
- package/resources/beta/agents/sessions/events.js +10 -7
- package/resources/beta/agents/sessions/events.js.map +1 -1
- package/resources/beta/agents/sessions/events.mjs +10 -7
- package/resources/beta/agents/sessions/events.mjs.map +1 -1
- package/resources/beta/agents/sessions/sessions.d.mts +4 -2
- package/resources/beta/agents/sessions/sessions.d.mts.map +1 -1
- package/resources/beta/agents/sessions/sessions.d.ts +4 -2
- package/resources/beta/agents/sessions/sessions.d.ts.map +1 -1
- package/resources/beta/agents/sessions/sessions.js.map +1 -1
- package/resources/beta/agents/sessions/sessions.mjs.map +1 -1
- package/resources/beta/agents/vaults/credentials.d.mts +24 -7
- package/resources/beta/agents/vaults/credentials.d.mts.map +1 -1
- package/resources/beta/agents/vaults/credentials.d.ts +24 -7
- package/resources/beta/agents/vaults/credentials.d.ts.map +1 -1
- package/resources/beta/agents/vaults/credentials.js +2 -6
- package/resources/beta/agents/vaults/credentials.js.map +1 -1
- package/resources/beta/agents/vaults/credentials.mjs +2 -6
- package/resources/beta/agents/vaults/credentials.mjs.map +1 -1
- package/resources/beta/beta.d.mts +2 -2
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +2 -2
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.mts +1 -1
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/responses/responses.d.mts +69 -10
- package/resources/beta/responses/responses.d.mts.map +1 -1
- package/resources/beta/responses/responses.d.ts +69 -10
- package/resources/beta/responses/responses.d.ts.map +1 -1
- package/resources/beta/responses/responses.js.map +1 -1
- package/resources/beta/responses/responses.mjs.map +1 -1
- package/resources/files.d.mts +2 -2
- package/resources/files.d.mts.map +1 -1
- package/resources/files.d.ts +2 -2
- package/resources/files.d.ts.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/live/forks/ws-base.js +1 -1
- package/resources/live/forks/ws-base.js.map +1 -1
- package/resources/live/forks/ws-base.mjs +1 -1
- package/resources/live/forks/ws-base.mjs.map +1 -1
- package/resources/live/sideband/ws-base.js +1 -1
- package/resources/live/sideband/ws-base.js.map +1 -1
- package/resources/live/sideband/ws-base.mjs +1 -1
- package/resources/live/sideband/ws-base.mjs.map +1 -1
- package/resources/live/ws-base.js +1 -1
- package/resources/live/ws-base.js.map +1 -1
- package/resources/live/ws-base.mjs +1 -1
- package/resources/live/ws-base.mjs.map +1 -1
- package/resources/realtime/index.d.mts +1 -0
- package/resources/realtime/index.d.mts.map +1 -1
- package/resources/realtime/index.d.ts +1 -0
- package/resources/realtime/index.d.ts.map +1 -1
- package/resources/realtime/index.js +3 -1
- package/resources/realtime/index.js.map +1 -1
- package/resources/realtime/index.mjs +1 -0
- package/resources/realtime/index.mjs.map +1 -1
- package/resources/realtime/realtime.d.mts +4 -0
- package/resources/realtime/realtime.d.mts.map +1 -1
- package/resources/realtime/realtime.d.ts +4 -0
- package/resources/realtime/realtime.d.ts.map +1 -1
- package/resources/realtime/realtime.js +4 -0
- package/resources/realtime/realtime.js.map +1 -1
- package/resources/realtime/realtime.mjs +4 -0
- package/resources/realtime/realtime.mjs.map +1 -1
- package/resources/realtime/translations/client-secrets.d.mts +67 -0
- package/resources/realtime/translations/client-secrets.d.mts.map +1 -0
- package/resources/realtime/translations/client-secrets.d.ts +67 -0
- package/resources/realtime/translations/client-secrets.d.ts.map +1 -0
- package/resources/realtime/translations/client-secrets.js +39 -0
- package/resources/realtime/translations/client-secrets.js.map +1 -0
- package/resources/realtime/translations/client-secrets.mjs +35 -0
- package/resources/realtime/translations/client-secrets.mjs.map +1 -0
- package/resources/realtime/translations/index.d.mts +3 -0
- package/resources/realtime/translations/index.d.mts.map +1 -0
- package/resources/realtime/translations/index.d.ts +3 -0
- package/resources/realtime/translations/index.d.ts.map +1 -0
- package/resources/realtime/translations/index.js +9 -0
- package/resources/realtime/translations/index.js.map +1 -0
- package/resources/realtime/translations/index.mjs +4 -0
- package/resources/realtime/translations/index.mjs.map +1 -0
- package/resources/realtime/translations/translations.d.mts +10 -0
- package/resources/realtime/translations/translations.d.mts.map +1 -0
- package/resources/realtime/translations/translations.d.ts +10 -0
- package/resources/realtime/translations/translations.d.ts.map +1 -0
- package/resources/realtime/translations/translations.js +17 -0
- package/resources/realtime/translations/translations.js.map +1 -0
- package/resources/realtime/translations/translations.mjs +12 -0
- package/resources/realtime/translations/translations.mjs.map +1 -0
- package/resources/realtime/translations.d.mts +2 -0
- package/resources/realtime/translations.d.mts.map +1 -0
- package/resources/realtime/translations.d.ts +2 -0
- package/resources/realtime/translations.d.ts.map +1 -0
- package/resources/realtime/translations.js +6 -0
- package/resources/realtime/translations.js.map +1 -0
- package/resources/realtime/translations.mjs +3 -0
- package/resources/realtime/translations.mjs.map +1 -0
- package/resources/responses/responses.d.mts +66 -7
- package/resources/responses/responses.d.mts.map +1 -1
- package/resources/responses/responses.d.ts +66 -7
- package/resources/responses/responses.d.ts.map +1 -1
- package/resources/responses/responses.js.map +1 -1
- package/resources/responses/responses.mjs.map +1 -1
- package/resources/shared.d.mts +1 -1
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +1 -1
- package/resources/shared.d.ts.map +1 -1
- package/src/client.ts +42 -6
- package/src/internal/responses/canonical-output-text.ts +30 -5
- package/src/internal/responses/response-accumulator.ts +155 -56
- package/src/internal/ws.ts +5 -3
- package/src/lib/live/transcript-grouping.ts +6 -5
- package/src/lib/responses/responses-websocket-accumulator.ts +374 -0
- package/src/realtime/translations/ws.ts +539 -0
- package/src/resources/audio/speech.ts +4 -1
- package/src/resources/audio/transcriptions.ts +2 -1
- package/src/resources/beta/agents/agents.ts +699 -12
- package/src/resources/beta/agents/environments/templates.ts +70 -9
- package/src/resources/beta/agents/index.ts +3 -0
- package/src/resources/beta/agents/sessions/events.ts +10 -7
- package/src/resources/beta/agents/sessions/sessions.ts +4 -2
- package/src/resources/beta/agents/vaults/credentials.ts +21 -7
- package/src/resources/beta/beta.ts +6 -0
- package/src/resources/beta/index.ts +3 -0
- package/src/resources/beta/responses/responses.ts +75 -6
- package/src/resources/files.ts +3 -3
- package/src/resources/index.ts +1 -1
- package/src/resources/live/forks/ws-base.ts +1 -1
- package/src/resources/live/sideband/ws-base.ts +1 -1
- package/src/resources/live/ws-base.ts +1 -1
- package/src/resources/realtime/api.md +8 -0
- package/src/resources/realtime/index.ts +1 -0
- package/src/resources/realtime/realtime.ts +6 -0
- package/src/resources/realtime/translations/client-secrets.ts +93 -0
- package/src/resources/realtime/translations/index.ts +4 -0
- package/src/resources/realtime/translations/translations.ts +15 -0
- package/src/resources/realtime/translations.ts +3 -0
- package/src/resources/responses/responses.ts +72 -6
- package/src/resources/shared.ts +1 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/resources/shared.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type AllModels = (string & {}) | ChatModel | 'o1-pro' | 'o1-pro-2025-03-19' | 'o3-pro' | 'o3-pro-2025-06-10' | 'o3-deep-research' | 'o3-deep-research-2025-06-26' | 'o4-mini-deep-research' | 'o4-mini-deep-research-2025-06-26' | 'computer-use-preview' | 'computer-use-preview-2025-03-11' | 'gpt-5.5-pro' | 'gpt-5.5-pro-2026-04-23' | 'gpt-5-codex' | 'gpt-5-pro' | 'gpt-5-pro-2025-10-06' | 'gpt-5.1-codex-max' | 'gpt-daybreak-blue-latest' | 'gpt-daybreak-red-latest' | 'gpt-5.6-cyber' | 'gpt-rosalind-research';
|
|
2
|
-
export type ChatModel = 'gpt-6-astra' | 'gpt-6-sol' | 'gpt-6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-5.6-luna' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.4' | 'gpt-5.4-mini' | 'gpt-5.4-nano' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.3-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-codex' | 'gpt-5.1-mini' | 'gpt-5.1-chat-latest' | 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-5-2025-08-07' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano-2025-04-14' | 'o4-mini' | 'o4-mini-2025-04-16' | 'o3' | 'o3-2025-04-16' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o1' | 'o1-2024-12-17' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o1-mini' | 'o1-mini-2024-09-12' | 'gpt-4o' | 'gpt-4o-2024-11-20' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-05-13' | 'gpt-audio-mini' | 'gpt-audio-mini-2025-12-15' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-mini-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview-2025-03-11' | 'chatgpt-4o-latest' | 'codex-mini-latest' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613';
|
|
2
|
+
export type ChatModel = 'gpt-6-astra' | 'gpt-6.1-sol' | 'gpt-6-sol' | 'gpt-6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-5.6-luna' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.4' | 'gpt-5.4-mini' | 'gpt-5.4-nano' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.3-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-codex' | 'gpt-5.1-mini' | 'gpt-5.1-chat-latest' | 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-5-2025-08-07' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano-2025-04-14' | 'o4-mini' | 'o4-mini-2025-04-16' | 'o3' | 'o3-2025-04-16' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o1' | 'o1-2024-12-17' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o1-mini' | 'o1-mini-2024-09-12' | 'gpt-4o' | 'gpt-4o-2024-11-20' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-05-13' | 'gpt-audio-mini' | 'gpt-audio-mini-2025-12-15' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-mini-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview-2025-03-11' | 'chatgpt-4o-latest' | 'codex-mini-latest' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613';
|
|
3
3
|
/**
|
|
4
4
|
* A filter used to compare a specified attribute key to a given value using a
|
|
5
5
|
* defined comparison operation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/resources/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GACjB,CAAC,MAAM,GAAG,EAAE,CAAC,GACb,S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AEG;IACH,IAAI,EAAE,SAAS,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GACtB,CAAC,MAAM,GAAG,EAAE,CAAC,GACb,SAAS,GACT,QAAQ,GACR,mBAAmB,GACnB,QAAQ,GACR,mBAAmB,GACnB,kBAAkB,GAClB,6BAA6B,GAC7B,uBAAuB,GACvB,kCAAkC,GAClC,sBAAsB,GACtB,iCAAiC,GACjC,aAAa,GACb,wBAAwB,GACxB,aAAa,GACb,WAAW,GACX,sBAAsB,GACtB,mBAAmB,GACnB,0BAA0B,GAC1B,yBAAyB,GACzB,eAAe,GACf,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/resources/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GACjB,CAAC,MAAM,GAAG,EAAE,CAAC,GACb,SAAS,GACT,QAAQ,GACR,mBAAmB,GACnB,QAAQ,GACR,mBAAmB,GACnB,kBAAkB,GAClB,6BAA6B,GAC7B,uBAAuB,GACvB,kCAAkC,GAClC,sBAAsB,GACtB,iCAAiC,GACjC,aAAa,GACb,wBAAwB,GACxB,aAAa,GACb,WAAW,GACX,sBAAsB,GACtB,mBAAmB,GACnB,0BAA0B,GAC1B,yBAAyB,GACzB,eAAe,GACf,uBAAuB,CAAC;AAE5B,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,aAAa,GACb,WAAW,GACX,YAAY,GACZ,aAAa,GACb,eAAe,GACf,cAAc,GACd,SAAS,GACT,oBAAoB,GACpB,SAAS,GACT,cAAc,GACd,cAAc,GACd,yBAAyB,GACzB,yBAAyB,GACzB,qBAAqB,GACrB,SAAS,GACT,oBAAoB,GACpB,qBAAqB,GACrB,aAAa,GACb,wBAAwB,GACxB,SAAS,GACT,oBAAoB,GACpB,eAAe,GACf,cAAc,GACd,qBAAqB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;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,WAAW,EAAE,wBAAwB,CAAC,UAAU,CAAC;IAEjD;;OAEG;IACH,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,yBAAiB,wBAAwB,CAAC;IACxC;;OAEG;IACH,UAAiB,UAAU;QACzB;;;WAGG;QACH,IAAI,EAAE,MAAM,CAAC;QAEb;;;WAGG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;QAErB;;;WAGG;QACH,MAAM,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAC;QAEpC;;;;;;WAMG;QACH,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;KACzB;CACF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GACtB,CAAC,MAAM,GAAG,EAAE,CAAC,GACb,SAAS,GACT,QAAQ,GACR,mBAAmB,GACnB,QAAQ,GACR,mBAAmB,GACnB,kBAAkB,GAClB,6BAA6B,GAC7B,uBAAuB,GACvB,kCAAkC,GAClC,sBAAsB,GACtB,iCAAiC,GACjC,aAAa,GACb,wBAAwB,GACxB,aAAa,GACb,WAAW,GACX,sBAAsB,GACtB,mBAAmB,GACnB,0BAA0B,GAC1B,yBAAyB,GACzB,eAAe,GACf,uBAAuB,CAAC"}
|
package/src/client.ts
CHANGED
|
@@ -924,18 +924,54 @@ export class OpenAI {
|
|
|
924
924
|
defaultBaseURL?: string | undefined,
|
|
925
925
|
): string {
|
|
926
926
|
const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
927
|
+
let url: URL;
|
|
928
|
+
let baseQuery: Record<string, string> = {};
|
|
929
|
+
let baseParams: URLSearchParams | undefined;
|
|
930
|
+
if (isAbsoluteURL(path)) {
|
|
931
|
+
url = new URL(path);
|
|
932
|
+
} else if (baseURL.includes('?')) {
|
|
933
|
+
const base = new URL(baseURL);
|
|
934
|
+
baseParams = new URLSearchParams(base.search);
|
|
935
|
+
baseQuery = Object.fromEntries(baseParams);
|
|
936
|
+
base.search = '';
|
|
937
|
+
base.hash = '';
|
|
938
|
+
url = new URL(
|
|
939
|
+
base.toString() + (base.pathname.endsWith('/') && path.startsWith('/') ? path.slice(1) : path),
|
|
940
|
+
);
|
|
941
|
+
} else {
|
|
942
|
+
url = new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
943
|
+
}
|
|
930
944
|
|
|
931
945
|
const defaultQuery = this.defaultQuery();
|
|
932
946
|
const pathQuery = Object.fromEntries(url.searchParams);
|
|
933
|
-
|
|
934
|
-
|
|
947
|
+
let overridingQuery: Record<string, unknown> | undefined;
|
|
948
|
+
if (!isEmptyObj(baseQuery) || !isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
949
|
+
overridingQuery = { ...pathQuery, ...defaultQuery, ...query };
|
|
950
|
+
query = { ...baseQuery, ...overridingQuery };
|
|
935
951
|
}
|
|
936
952
|
|
|
937
953
|
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
938
954
|
url.search = this.stringifyQuery(query);
|
|
955
|
+
if (baseParams && overridingQuery) {
|
|
956
|
+
const seen = new Set<string>();
|
|
957
|
+
const repeated = new Set<string>();
|
|
958
|
+
for (const key of baseParams.keys()) {
|
|
959
|
+
if (seen.has(key) && !hasOwn(overridingQuery, key)) {
|
|
960
|
+
repeated.add(key);
|
|
961
|
+
}
|
|
962
|
+
seen.add(key);
|
|
963
|
+
}
|
|
964
|
+
if (repeated.size) {
|
|
965
|
+
const merged = new URLSearchParams();
|
|
966
|
+
for (const [key, value] of url.searchParams) {
|
|
967
|
+
if (!repeated.has(key)) merged.append(key, value);
|
|
968
|
+
}
|
|
969
|
+
for (const [key, value] of baseParams) {
|
|
970
|
+
if (repeated.has(key)) merged.append(key, value);
|
|
971
|
+
}
|
|
972
|
+
url.search = merged.toString();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
939
975
|
}
|
|
940
976
|
|
|
941
977
|
return url.toString();
|
|
@@ -2599,10 +2635,10 @@ export declare namespace OpenAI {
|
|
|
2599
2635
|
|
|
2600
2636
|
export {
|
|
2601
2637
|
Files as Files,
|
|
2602
|
-
type FileContent as FileContent,
|
|
2603
2638
|
type FileDeleted as FileDeleted,
|
|
2604
2639
|
type FileObject as FileObject,
|
|
2605
2640
|
type FilePurpose as FilePurpose,
|
|
2641
|
+
type FileContent as FileContent,
|
|
2606
2642
|
type FileObjectsPage as FileObjectsPage,
|
|
2607
2643
|
type FileCreateParams as FileCreateParams,
|
|
2608
2644
|
type FileListParams as FileListParams,
|
|
@@ -2,11 +2,15 @@ import type { Response } from '../../resources/responses/responses';
|
|
|
2
2
|
import { OutputTextIndex } from './output-text-index';
|
|
3
3
|
|
|
4
4
|
type ResponseOutput = Response['output'][number];
|
|
5
|
+
export type ResponseOutputSnapshot = Pick<Response, 'output' | 'output_text'>;
|
|
5
6
|
|
|
6
7
|
export interface ResponseAccumulatorContext {
|
|
7
|
-
canonicalSnapshot:
|
|
8
|
+
canonicalSnapshot: ResponseOutputSnapshot | undefined;
|
|
8
9
|
outputTextLengths: WeakMap<ResponseOutput, number>;
|
|
9
10
|
outputTextIndex: OutputTextIndex;
|
|
11
|
+
/** Only the caller-fed WebSocket helper can defer the aggregate until a snapshot is read. */
|
|
12
|
+
deferOutputText?: boolean;
|
|
13
|
+
outputTextDirty?: boolean;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export function createCanonicalResponseContext(): ResponseAccumulatorContext {
|
|
@@ -32,7 +36,14 @@ export function getOutputText(context: ResponseAccumulatorContext, output: Respo
|
|
|
32
36
|
return text;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
export function ensureCanonicalOutputText(
|
|
39
|
+
export function ensureCanonicalOutputText(
|
|
40
|
+
context: ResponseAccumulatorContext,
|
|
41
|
+
snapshot: ResponseOutputSnapshot,
|
|
42
|
+
): void {
|
|
43
|
+
if (context.deferOutputText) {
|
|
44
|
+
context.canonicalSnapshot = undefined;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
36
47
|
if (context.canonicalSnapshot === snapshot) {
|
|
37
48
|
return;
|
|
38
49
|
}
|
|
@@ -51,7 +62,10 @@ export function ensureCanonicalOutputText(context: ResponseAccumulatorContext, s
|
|
|
51
62
|
context.canonicalSnapshot = snapshot;
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
export function cloneResponse
|
|
65
|
+
export function cloneResponse<T extends ResponseOutputSnapshot>(
|
|
66
|
+
context: ResponseAccumulatorContext,
|
|
67
|
+
response: T,
|
|
68
|
+
): T {
|
|
55
69
|
context.canonicalSnapshot = undefined;
|
|
56
70
|
context.outputTextLengths = new WeakMap();
|
|
57
71
|
context.outputTextIndex = new OutputTextIndex();
|
|
@@ -75,6 +89,9 @@ export function updateCachedOutputTextLength(
|
|
|
75
89
|
previousText: string,
|
|
76
90
|
nextText: string,
|
|
77
91
|
): void {
|
|
92
|
+
if (context.deferOutputText) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
78
95
|
const length = context.outputTextLengths.get(output);
|
|
79
96
|
if (length !== undefined) {
|
|
80
97
|
const nextLength = length - previousText.length + nextText.length;
|
|
@@ -83,7 +100,11 @@ export function updateCachedOutputTextLength(
|
|
|
83
100
|
}
|
|
84
101
|
}
|
|
85
102
|
|
|
86
|
-
function replaceOutputTextSuffix(
|
|
103
|
+
function replaceOutputTextSuffix(
|
|
104
|
+
snapshot: ResponseOutputSnapshot,
|
|
105
|
+
previousText: string,
|
|
106
|
+
nextText: string,
|
|
107
|
+
): void {
|
|
87
108
|
if (previousText.length === 0) {
|
|
88
109
|
snapshot.output_text += nextText;
|
|
89
110
|
return;
|
|
@@ -127,7 +148,7 @@ function getPrecedingContentTextLength(
|
|
|
127
148
|
|
|
128
149
|
export function updateOutputText(
|
|
129
150
|
context: ResponseAccumulatorContext,
|
|
130
|
-
snapshot:
|
|
151
|
+
snapshot: ResponseOutputSnapshot,
|
|
131
152
|
outputIndex: number,
|
|
132
153
|
previousText: string,
|
|
133
154
|
nextText: string,
|
|
@@ -136,6 +157,10 @@ export function updateOutputText(
|
|
|
136
157
|
if (previousText === nextText) {
|
|
137
158
|
return;
|
|
138
159
|
}
|
|
160
|
+
if (context.deferOutputText) {
|
|
161
|
+
context.outputTextDirty = true;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
139
164
|
|
|
140
165
|
const output = snapshot.output[outputIndex];
|
|
141
166
|
if (
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Response, ResponseOutputText, ResponseStreamEvent } from '../../resources/responses/responses';
|
|
2
|
-
import type { ResponseAccumulatorContext } from './canonical-output-text';
|
|
2
|
+
import type { ResponseAccumulatorContext, ResponseOutputSnapshot } from './canonical-output-text';
|
|
3
3
|
import { OpenAIError } from '../../error';
|
|
4
4
|
import { hasOwn } from '../utils';
|
|
5
|
+
import { isObj } from '../utils/values';
|
|
5
6
|
import {
|
|
6
7
|
cloneResponse,
|
|
7
8
|
createCanonicalResponseContext,
|
|
@@ -139,7 +140,7 @@ type ResponseIgnoredEvent = Extract<
|
|
|
139
140
|
>;
|
|
140
141
|
|
|
141
142
|
interface ResponseOutputIdentityIndex {
|
|
142
|
-
snapshot:
|
|
143
|
+
snapshot: ResponseOutputSnapshot;
|
|
143
144
|
output: Response['output'];
|
|
144
145
|
length: number;
|
|
145
146
|
identities: Set<string>;
|
|
@@ -175,7 +176,7 @@ function validateArrayAppend(
|
|
|
175
176
|
validateArrayIndex(collection, index, kind, true);
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
function getOutput(snapshot:
|
|
179
|
+
function getOutput(snapshot: ResponseOutputSnapshot, outputIndex: number): Response['output'][number] {
|
|
179
180
|
validateArrayIndex(snapshot.output, outputIndex, 'output');
|
|
180
181
|
const output = snapshot.output[outputIndex];
|
|
181
182
|
if (!output) {
|
|
@@ -243,7 +244,7 @@ function addOutputItemIdentities(identities: Set<string>, keys: readonly string[
|
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
function createResponseOutputIdentityIndex(snapshot:
|
|
247
|
+
function createResponseOutputIdentityIndex(snapshot: ResponseOutputSnapshot): ResponseOutputIdentityIndex {
|
|
247
248
|
const identityIndex: ResponseOutputIdentityIndex = {
|
|
248
249
|
snapshot,
|
|
249
250
|
output: snapshot.output,
|
|
@@ -261,7 +262,7 @@ function createResponseOutputIdentityIndex(snapshot: Response): ResponseOutputId
|
|
|
261
262
|
|
|
262
263
|
function getResponseOutputIdentityIndex(
|
|
263
264
|
context: ResponseAccumulatorContext,
|
|
264
|
-
snapshot:
|
|
265
|
+
snapshot: ResponseOutputSnapshot,
|
|
265
266
|
): ResponseOutputIdentityIndex {
|
|
266
267
|
const cached = responseOutputIdentityIndexes.get(context);
|
|
267
268
|
if (
|
|
@@ -278,7 +279,10 @@ function getResponseOutputIdentityIndex(
|
|
|
278
279
|
return identityIndex;
|
|
279
280
|
}
|
|
280
281
|
|
|
281
|
-
function cloneValidatedResponse
|
|
282
|
+
export function cloneValidatedResponse<T extends ResponseOutputSnapshot>(
|
|
283
|
+
context: ResponseAccumulatorContext,
|
|
284
|
+
response: T,
|
|
285
|
+
): T {
|
|
282
286
|
const nextContext = createCanonicalResponseContext();
|
|
283
287
|
const snapshot = cloneResponse(nextContext, response);
|
|
284
288
|
const identityIndex = createResponseOutputIdentityIndex(snapshot);
|
|
@@ -348,7 +352,7 @@ function getExpectedOutputItemType(event: ResponseItemScopedEvent): Response['ou
|
|
|
348
352
|
|
|
349
353
|
function validateCompletedOutputItemIdentity(
|
|
350
354
|
event: Extract<ResponseOutputItemEvent, { type: 'response.output_item.done' }>,
|
|
351
|
-
snapshot:
|
|
355
|
+
snapshot: ResponseOutputSnapshot,
|
|
352
356
|
): void {
|
|
353
357
|
const output = getOutput(snapshot, event.output_index);
|
|
354
358
|
const replacement = event.item;
|
|
@@ -376,7 +380,7 @@ function validateCompletedOutputItemIdentity(
|
|
|
376
380
|
|
|
377
381
|
function validateOutputItemIdentity(
|
|
378
382
|
event: ResponseAccumulatorEvent,
|
|
379
|
-
snapshot:
|
|
383
|
+
snapshot: ResponseOutputSnapshot,
|
|
380
384
|
rejectInvalidShellTargets: boolean,
|
|
381
385
|
): void {
|
|
382
386
|
if (event.type === 'response.output_item.done') {
|
|
@@ -434,7 +438,7 @@ function getContent<T>(content: T[], contentIndex: number): T {
|
|
|
434
438
|
}
|
|
435
439
|
|
|
436
440
|
function getShellOutputContent(
|
|
437
|
-
snapshot:
|
|
441
|
+
snapshot: ResponseOutputSnapshot,
|
|
438
442
|
output: Extract<Response['output'][number], { type: 'shell_call_output' }>,
|
|
439
443
|
commandIndex: number,
|
|
440
444
|
): (typeof output.output)[number] {
|
|
@@ -616,7 +620,7 @@ function sanitizeResponseEvent(
|
|
|
616
620
|
|
|
617
621
|
function accumulateOutputItemEvent(
|
|
618
622
|
event: ResponseAccumulatorEvent,
|
|
619
|
-
snapshot:
|
|
623
|
+
snapshot: ResponseOutputSnapshot,
|
|
620
624
|
context: ResponseAccumulatorContext,
|
|
621
625
|
): event is ResponseOutputItemEvent {
|
|
622
626
|
switch (event.type) {
|
|
@@ -637,7 +641,11 @@ function accumulateOutputItemEvent(
|
|
|
637
641
|
context.outputTextIndex.append(text.length);
|
|
638
642
|
}
|
|
639
643
|
if (text) {
|
|
640
|
-
|
|
644
|
+
if (context.deferOutputText) {
|
|
645
|
+
context.outputTextDirty = true;
|
|
646
|
+
} else {
|
|
647
|
+
snapshot.output_text += text;
|
|
648
|
+
}
|
|
641
649
|
}
|
|
642
650
|
return true;
|
|
643
651
|
}
|
|
@@ -664,7 +672,7 @@ function accumulateOutputItemEvent(
|
|
|
664
672
|
|
|
665
673
|
function accumulateContentPartAddedEvent(
|
|
666
674
|
event: ResponseAccumulatorEvent,
|
|
667
|
-
snapshot:
|
|
675
|
+
snapshot: ResponseOutputSnapshot,
|
|
668
676
|
context: ResponseAccumulatorContext,
|
|
669
677
|
): event is ResponseContentPartAddedEvent {
|
|
670
678
|
switch (event.type) {
|
|
@@ -701,7 +709,7 @@ function accumulateContentPartAddedEvent(
|
|
|
701
709
|
|
|
702
710
|
function accumulateContentPartDoneEvent(
|
|
703
711
|
event: ResponseAccumulatorEvent,
|
|
704
|
-
snapshot:
|
|
712
|
+
snapshot: ResponseOutputSnapshot,
|
|
705
713
|
context: ResponseAccumulatorContext,
|
|
706
714
|
): event is ResponseContentPartDoneEvent {
|
|
707
715
|
switch (event.type) {
|
|
@@ -735,9 +743,57 @@ function accumulateContentPartDoneEvent(
|
|
|
735
743
|
}
|
|
736
744
|
}
|
|
737
745
|
|
|
746
|
+
// Streamed logprobs have a looser type than final output: bytes and even the
|
|
747
|
+
// top token fields may be missing. Do not fabricate them in typed SSE snapshots.
|
|
748
|
+
function isLogprobWithBytes(value: unknown): value is ResponseOutputText.Logprob.TopLogprob {
|
|
749
|
+
return (
|
|
750
|
+
isObj(value) &&
|
|
751
|
+
typeof value['token'] === 'string' &&
|
|
752
|
+
typeof value['logprob'] === 'number' &&
|
|
753
|
+
Array.isArray(value['bytes']) &&
|
|
754
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- This boundary checks each byte against the generated final-output contract before exposing a typed SSE snapshot.
|
|
755
|
+
value['bytes'].every((byte) => typeof byte === 'number')
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function isOutputLogprobs(value: unknown): value is ResponseOutputText.Logprob[] {
|
|
760
|
+
return (
|
|
761
|
+
Array.isArray(value) &&
|
|
762
|
+
value.every(
|
|
763
|
+
(entry) =>
|
|
764
|
+
isLogprobWithBytes(entry) &&
|
|
765
|
+
'top_logprobs' in entry &&
|
|
766
|
+
Array.isArray(entry.top_logprobs) &&
|
|
767
|
+
entry.top_logprobs.every(isLogprobWithBytes),
|
|
768
|
+
)
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function accumulateOutputLogprobs(
|
|
773
|
+
content: ResponseOutputText,
|
|
774
|
+
event: Extract<ResponseOutputTextEvent, { logprobs: unknown }>,
|
|
775
|
+
): void {
|
|
776
|
+
const logprobs = structuredClone(event.logprobs);
|
|
777
|
+
if (!isOutputLogprobs(logprobs)) {
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
if (event.type === 'response.output_text.done') {
|
|
781
|
+
if (logprobs.length > 0 || (Array.isArray(content.logprobs) && content.logprobs.length > 0)) {
|
|
782
|
+
content.logprobs = logprobs;
|
|
783
|
+
}
|
|
784
|
+
} else if (logprobs.length > 0) {
|
|
785
|
+
if (!Array.isArray(content.logprobs)) {
|
|
786
|
+
content.logprobs = [];
|
|
787
|
+
}
|
|
788
|
+
for (const logprob of logprobs) {
|
|
789
|
+
content.logprobs.push(logprob);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
738
794
|
function accumulateOutputTextEvent(
|
|
739
795
|
event: ResponseAccumulatorEvent,
|
|
740
|
-
snapshot:
|
|
796
|
+
snapshot: ResponseOutputSnapshot,
|
|
741
797
|
context: ResponseAccumulatorContext,
|
|
742
798
|
): event is ResponseOutputTextEvent {
|
|
743
799
|
switch (event.type) {
|
|
@@ -748,6 +804,7 @@ function accumulateOutputTextEvent(
|
|
|
748
804
|
if (content.type !== 'output_text') {
|
|
749
805
|
throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);
|
|
750
806
|
}
|
|
807
|
+
accumulateOutputLogprobs(content, event);
|
|
751
808
|
const previousText = content.text;
|
|
752
809
|
ensureCanonicalOutputText(context, snapshot);
|
|
753
810
|
content.text = previousText + event.delta;
|
|
@@ -756,7 +813,13 @@ function accumulateOutputTextEvent(
|
|
|
756
813
|
event.output_index === snapshot.output.length - 1 &&
|
|
757
814
|
event.content_index === output.content.length - 1
|
|
758
815
|
) {
|
|
759
|
-
|
|
816
|
+
if (context.deferOutputText) {
|
|
817
|
+
if (event.delta !== '') {
|
|
818
|
+
context.outputTextDirty = true;
|
|
819
|
+
}
|
|
820
|
+
} else {
|
|
821
|
+
snapshot.output_text += event.delta;
|
|
822
|
+
}
|
|
760
823
|
} else {
|
|
761
824
|
updateOutputText(
|
|
762
825
|
context,
|
|
@@ -777,6 +840,7 @@ function accumulateOutputTextEvent(
|
|
|
777
840
|
if (content.type !== 'output_text') {
|
|
778
841
|
throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);
|
|
779
842
|
}
|
|
843
|
+
accumulateOutputLogprobs(content, event);
|
|
780
844
|
const previousText = content.text;
|
|
781
845
|
ensureCanonicalOutputText(context, snapshot);
|
|
782
846
|
content.text = event.text;
|
|
@@ -815,7 +879,7 @@ function accumulateOutputTextEvent(
|
|
|
815
879
|
|
|
816
880
|
function accumulateRefusalAndArgumentsEvent(
|
|
817
881
|
event: ResponseAccumulatorEvent,
|
|
818
|
-
snapshot:
|
|
882
|
+
snapshot: ResponseOutputSnapshot,
|
|
819
883
|
): event is ResponseRefusalAndArgumentsEvent {
|
|
820
884
|
switch (event.type) {
|
|
821
885
|
case 'response.refusal.delta': {
|
|
@@ -890,7 +954,7 @@ function accumulateRefusalAndArgumentsEvent(
|
|
|
890
954
|
|
|
891
955
|
function accumulateShellEvent(
|
|
892
956
|
event: ResponseAccumulatorEvent,
|
|
893
|
-
snapshot:
|
|
957
|
+
snapshot: ResponseOutputSnapshot,
|
|
894
958
|
): event is ResponseShellEvent {
|
|
895
959
|
switch (event.type) {
|
|
896
960
|
case 'response.shell_call_command.added':
|
|
@@ -937,7 +1001,7 @@ function accumulateShellEvent(
|
|
|
937
1001
|
|
|
938
1002
|
function accumulateReasoningEvent(
|
|
939
1003
|
event: ResponseAccumulatorEvent,
|
|
940
|
-
snapshot:
|
|
1004
|
+
snapshot: ResponseOutputSnapshot,
|
|
941
1005
|
): event is ResponseReasoningEvent {
|
|
942
1006
|
switch (event.type) {
|
|
943
1007
|
case 'response.reasoning_text.delta': {
|
|
@@ -1008,7 +1072,7 @@ function accumulateReasoningEvent(
|
|
|
1008
1072
|
|
|
1009
1073
|
function accumulateCodeInterpreterEvent(
|
|
1010
1074
|
event: ResponseAccumulatorEvent,
|
|
1011
|
-
snapshot:
|
|
1075
|
+
snapshot: ResponseOutputSnapshot,
|
|
1012
1076
|
): event is ResponseCodeInterpreterEvent {
|
|
1013
1077
|
switch (event.type) {
|
|
1014
1078
|
case 'response.code_interpreter_call_code.delta': {
|
|
@@ -1054,7 +1118,7 @@ function accumulateCodeInterpreterEvent(
|
|
|
1054
1118
|
|
|
1055
1119
|
function accumulateSearchStatusEvent(
|
|
1056
1120
|
event: ResponseAccumulatorEvent,
|
|
1057
|
-
snapshot:
|
|
1121
|
+
snapshot: ResponseOutputSnapshot,
|
|
1058
1122
|
): event is ResponseSearchStatusEvent {
|
|
1059
1123
|
switch (event.type) {
|
|
1060
1124
|
case 'response.file_search_call.in_progress': {
|
|
@@ -1107,7 +1171,7 @@ function accumulateSearchStatusEvent(
|
|
|
1107
1171
|
|
|
1108
1172
|
function accumulateImageAndMcpStatusEvent(
|
|
1109
1173
|
event: ResponseAccumulatorEvent,
|
|
1110
|
-
snapshot:
|
|
1174
|
+
snapshot: ResponseOutputSnapshot,
|
|
1111
1175
|
): event is ResponseImageAndMcpStatusEvent {
|
|
1112
1176
|
switch (event.type) {
|
|
1113
1177
|
case 'response.image_generation_call.in_progress': {
|
|
@@ -1158,7 +1222,7 @@ function accumulateImageAndMcpStatusEvent(
|
|
|
1158
1222
|
}
|
|
1159
1223
|
}
|
|
1160
1224
|
|
|
1161
|
-
function isResponseLifecycleEvent(event:
|
|
1225
|
+
function isResponseLifecycleEvent(event: { type: string }): event is ResponseLifecycleEvent {
|
|
1162
1226
|
switch (event.type) {
|
|
1163
1227
|
case 'response.created':
|
|
1164
1228
|
case 'response.queued':
|
|
@@ -1174,7 +1238,7 @@ function isResponseLifecycleEvent(event: ResponseAccumulatorEvent): event is Res
|
|
|
1174
1238
|
}
|
|
1175
1239
|
}
|
|
1176
1240
|
|
|
1177
|
-
function isIgnoredResponseEvent(event:
|
|
1241
|
+
function isIgnoredResponseEvent(event: { type: string }): event is ResponseIgnoredEvent {
|
|
1178
1242
|
switch (event.type) {
|
|
1179
1243
|
case 'response.audio.delta':
|
|
1180
1244
|
case 'response.audio.done':
|
|
@@ -1199,65 +1263,100 @@ export function createResponseContext(): ResponseAccumulatorContext {
|
|
|
1199
1263
|
return createCanonicalResponseContext();
|
|
1200
1264
|
}
|
|
1201
1265
|
|
|
1202
|
-
|
|
1203
|
-
event: ResponseAccumulatorEvent,
|
|
1204
|
-
snapshot: Response | undefined,
|
|
1205
|
-
context: ResponseAccumulatorContext,
|
|
1206
|
-
rejectInvalidShellTargets = false,
|
|
1207
|
-
onSanitizedEvent?: (event: ResponseStreamEvent) => void,
|
|
1208
|
-
): Response {
|
|
1209
|
-
const dispatchEvent = sanitizeResponseEvent(event);
|
|
1210
|
-
if (onSanitizedEvent && dispatchEvent.type !== 'keepalive') {
|
|
1211
|
-
onSanitizedEvent(dispatchEvent);
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
if (!snapshot) {
|
|
1215
|
-
if (dispatchEvent.type !== 'response.created') {
|
|
1216
|
-
throw new OpenAIError(
|
|
1217
|
-
`When snapshot hasn't been set yet, expected 'response.created' event, got ${dispatchEvent.type}`,
|
|
1218
|
-
);
|
|
1219
|
-
}
|
|
1220
|
-
return cloneValidatedResponse(context, dispatchEvent.response);
|
|
1221
|
-
}
|
|
1266
|
+
type ResponseOutputEvent = Exclude<ResponseAccumulatorEvent, ResponseLifecycleEvent>;
|
|
1222
1267
|
|
|
1268
|
+
function accumulateResponseOutput(
|
|
1269
|
+
dispatchEvent: ResponseAccumulatorEvent,
|
|
1270
|
+
snapshot: ResponseOutputSnapshot,
|
|
1271
|
+
context: ResponseAccumulatorContext,
|
|
1272
|
+
rejectInvalidShellTargets: boolean,
|
|
1273
|
+
): dispatchEvent is ResponseOutputEvent {
|
|
1223
1274
|
validateOutputItemIdentity(dispatchEvent, snapshot, rejectInvalidShellTargets);
|
|
1224
|
-
|
|
1225
1275
|
if (accumulateOutputItemEvent(dispatchEvent, snapshot, context)) {
|
|
1226
|
-
return
|
|
1276
|
+
return true;
|
|
1227
1277
|
}
|
|
1228
1278
|
if (accumulateContentPartAddedEvent(dispatchEvent, snapshot, context)) {
|
|
1229
|
-
return
|
|
1279
|
+
return true;
|
|
1230
1280
|
}
|
|
1231
1281
|
if (accumulateContentPartDoneEvent(dispatchEvent, snapshot, context)) {
|
|
1232
|
-
return
|
|
1282
|
+
return true;
|
|
1233
1283
|
}
|
|
1234
1284
|
if (accumulateOutputTextEvent(dispatchEvent, snapshot, context)) {
|
|
1235
|
-
return
|
|
1285
|
+
return true;
|
|
1236
1286
|
}
|
|
1237
1287
|
if (accumulateRefusalAndArgumentsEvent(dispatchEvent, snapshot)) {
|
|
1238
|
-
return
|
|
1288
|
+
return true;
|
|
1239
1289
|
}
|
|
1240
1290
|
if (accumulateShellEvent(dispatchEvent, snapshot)) {
|
|
1241
|
-
return
|
|
1291
|
+
return true;
|
|
1242
1292
|
}
|
|
1243
1293
|
if (accumulateReasoningEvent(dispatchEvent, snapshot)) {
|
|
1244
|
-
return
|
|
1294
|
+
return true;
|
|
1245
1295
|
}
|
|
1246
1296
|
if (accumulateCodeInterpreterEvent(dispatchEvent, snapshot)) {
|
|
1247
|
-
return
|
|
1297
|
+
return true;
|
|
1248
1298
|
}
|
|
1249
1299
|
if (accumulateSearchStatusEvent(dispatchEvent, snapshot)) {
|
|
1250
|
-
return
|
|
1300
|
+
return true;
|
|
1251
1301
|
}
|
|
1252
1302
|
if (accumulateImageAndMcpStatusEvent(dispatchEvent, snapshot)) {
|
|
1253
|
-
return
|
|
1303
|
+
return true;
|
|
1254
1304
|
}
|
|
1255
1305
|
|
|
1256
|
-
if (
|
|
1306
|
+
if (isIgnoredResponseEvent(dispatchEvent)) {
|
|
1307
|
+
return true;
|
|
1308
|
+
}
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
/** Matches shared events that can change output. Validation still occurs before mutation. */
|
|
1313
|
+
export function isResponseOutputEvent(event: { type: string }): event is ResponseOutputEvent {
|
|
1314
|
+
// SAFETY: Membership of the existing SSE tag set is checked before using shared output validators.
|
|
1315
|
+
return (
|
|
1316
|
+
supportedResponseEventTypes.has(event.type as ResponseAccumulatorEvent['type']) &&
|
|
1317
|
+
!isResponseLifecycleEvent(event) &&
|
|
1318
|
+
!isIgnoredResponseEvent(event)
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/** Applies the same strict output validation and mutations without requiring response metadata. */
|
|
1323
|
+
export function accumulateWebSocketOutput(
|
|
1324
|
+
event: ResponseOutputEvent,
|
|
1325
|
+
snapshot: ResponseOutputSnapshot,
|
|
1326
|
+
context: ResponseAccumulatorContext,
|
|
1327
|
+
): void {
|
|
1328
|
+
const dispatchEvent = sanitizeResponseEvent(event);
|
|
1329
|
+
if (!accumulateResponseOutput(dispatchEvent, snapshot, context, true)) {
|
|
1330
|
+
throw new OpenAIError('Unsupported WebSocket output event');
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
export function accumulateResponseWithContext(
|
|
1335
|
+
event: ResponseAccumulatorEvent,
|
|
1336
|
+
snapshot: Response | undefined,
|
|
1337
|
+
context: ResponseAccumulatorContext,
|
|
1338
|
+
rejectInvalidShellTargets = false,
|
|
1339
|
+
onSanitizedEvent?: (event: ResponseStreamEvent) => void,
|
|
1340
|
+
): Response {
|
|
1341
|
+
const dispatchEvent = sanitizeResponseEvent(event);
|
|
1342
|
+
if (onSanitizedEvent && dispatchEvent.type !== 'keepalive') {
|
|
1343
|
+
onSanitizedEvent(dispatchEvent);
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
if (!snapshot) {
|
|
1347
|
+
if (dispatchEvent.type !== 'response.created') {
|
|
1348
|
+
throw new OpenAIError(
|
|
1349
|
+
`When snapshot hasn't been set yet, expected 'response.created' event, got ${dispatchEvent.type}`,
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1257
1352
|
return cloneValidatedResponse(context, dispatchEvent.response);
|
|
1258
1353
|
}
|
|
1259
|
-
|
|
1354
|
+
|
|
1355
|
+
if (accumulateResponseOutput(dispatchEvent, snapshot, context, rejectInvalidShellTargets)) {
|
|
1260
1356
|
return snapshot;
|
|
1261
1357
|
}
|
|
1358
|
+
if (isResponseLifecycleEvent(dispatchEvent)) {
|
|
1359
|
+
return cloneValidatedResponse(context, dispatchEvent.response);
|
|
1360
|
+
}
|
|
1262
1361
|
return assertNever(dispatchEvent);
|
|
1263
1362
|
}
|
package/src/internal/ws.ts
CHANGED
|
@@ -299,16 +299,18 @@ export class SendQueue<T = unknown> {
|
|
|
299
299
|
/**
|
|
300
300
|
* Send every queued message via `send`. If `send` throws, the failing
|
|
301
301
|
* message and all subsequent messages are re-queued and the error is
|
|
302
|
-
* re-thrown so the caller can report it.
|
|
302
|
+
* re-thrown so the caller can report it. Endpoints that cannot safely replay
|
|
303
|
+
* an attempted write use `requeueFailed: false`. Never-attempted messages
|
|
304
|
+
* remain queued, including messages enqueued during the failed send.
|
|
303
305
|
*/
|
|
304
|
-
flush(send: (data: RawWebSocketData) => void): void {
|
|
306
|
+
flush(send: (data: RawWebSocketData) => void, options?: { requeueFailed?: boolean }): void {
|
|
305
307
|
const pending = this._queue.splice(0);
|
|
306
308
|
this._bytes = 0;
|
|
307
309
|
for (let i = 0; i < pending.length; i++) {
|
|
308
310
|
try {
|
|
309
311
|
send(pending[i]!.data);
|
|
310
312
|
} catch (err) {
|
|
311
|
-
const remaining = pending.slice(i);
|
|
313
|
+
const remaining = pending.slice(options?.requeueFailed === false ? i + 1 : i);
|
|
312
314
|
this._queue = [...remaining, ...this._queue];
|
|
313
315
|
this._bytes = this._queue.reduce((sum, item) => sum + item.byteLength, 0);
|
|
314
316
|
throw err;
|