openai 7.25.0 → 7.27.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 +40 -0
- package/client.d.mts +5 -6
- package/client.d.mts.map +1 -1
- package/client.d.ts +5 -6
- package/client.d.ts.map +1 -1
- package/client.js +38 -10
- package/client.js.map +1 -1
- package/client.mjs +39 -11
- package/client.mjs.map +1 -1
- package/core/streaming.d.mts +4 -0
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts +4 -0
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +6 -0
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +6 -0
- package/core/streaming.mjs.map +1 -1
- package/helpers/beta/agents/filesystem.d.mts +17 -0
- package/helpers/beta/agents/filesystem.d.mts.map +1 -0
- package/helpers/beta/agents/filesystem.d.ts +17 -0
- package/helpers/beta/agents/filesystem.d.ts.map +1 -0
- package/helpers/beta/agents/filesystem.js +168 -0
- package/helpers/beta/agents/filesystem.js.map +1 -0
- package/helpers/beta/agents/filesystem.mjs +162 -0
- package/helpers/beta/agents/filesystem.mjs.map +1 -0
- package/helpers/beta/agents/standard-schema.d.mts +7 -0
- package/helpers/beta/agents/standard-schema.d.mts.map +1 -0
- package/helpers/beta/agents/standard-schema.d.ts +7 -0
- package/helpers/beta/agents/standard-schema.d.ts.map +1 -0
- package/helpers/beta/agents/standard-schema.js +12 -0
- package/helpers/beta/agents/standard-schema.js.map +1 -0
- package/helpers/beta/agents/standard-schema.mjs +9 -0
- package/helpers/beta/agents/standard-schema.mjs.map +1 -0
- package/helpers/beta/agents/zod.d.mts +10 -0
- package/helpers/beta/agents/zod.d.mts.map +1 -0
- package/helpers/beta/agents/zod.d.ts +10 -0
- package/helpers/beta/agents/zod.d.ts.map +1 -0
- package/helpers/beta/agents/zod.js +12 -0
- package/helpers/beta/agents/zod.js.map +1 -0
- package/helpers/beta/agents/zod.mjs +9 -0
- package/helpers/beta/agents/zod.mjs.map +1 -0
- package/internal/realtime-credentials.d.mts +22 -1
- package/internal/realtime-credentials.d.mts.map +1 -1
- package/internal/realtime-credentials.d.ts +22 -1
- package/internal/realtime-credentials.d.ts.map +1 -1
- package/internal/realtime-credentials.js +48 -4
- package/internal/realtime-credentials.js.map +1 -1
- package/internal/realtime-credentials.mjs +45 -4
- package/internal/realtime-credentials.mjs.map +1 -1
- package/internal/responses-ws-credentials.d.mts +23 -0
- package/internal/responses-ws-credentials.d.mts.map +1 -0
- package/internal/responses-ws-credentials.d.ts +23 -0
- package/internal/responses-ws-credentials.d.ts.map +1 -0
- package/internal/responses-ws-credentials.js +108 -0
- package/internal/responses-ws-credentials.js.map +1 -0
- package/internal/responses-ws-credentials.mjs +104 -0
- package/internal/responses-ws-credentials.mjs.map +1 -0
- package/internal/shim-types.d.mts +9 -0
- package/internal/shim-types.d.mts.map +1 -1
- package/internal/shim-types.d.ts +9 -0
- package/internal/shim-types.d.ts.map +1 -1
- package/internal/tslib.js +4 -0
- package/internal/ws-adapter-node.d.mts +4 -0
- package/internal/ws-adapter-node.d.mts.map +1 -1
- package/internal/ws-adapter-node.d.ts +4 -0
- package/internal/ws-adapter-node.d.ts.map +1 -1
- package/internal/ws-adapter-node.js +56 -0
- package/internal/ws-adapter-node.js.map +1 -1
- package/internal/ws-adapter-node.mjs +55 -0
- package/internal/ws-adapter-node.mjs.map +1 -1
- package/internal/ws.d.mts +27 -4
- package/internal/ws.d.mts.map +1 -1
- package/internal/ws.d.ts +27 -4
- package/internal/ws.d.ts.map +1 -1
- package/internal/ws.js +105 -5
- package/internal/ws.js.map +1 -1
- package/internal/ws.mjs +102 -4
- package/internal/ws.mjs.map +1 -1
- package/lib/agents/agent-session-stream.d.mts +13 -4
- package/lib/agents/agent-session-stream.d.mts.map +1 -1
- package/lib/agents/agent-session-stream.d.ts +13 -4
- package/lib/agents/agent-session-stream.d.ts.map +1 -1
- package/lib/agents/agent-session-stream.js +24 -21
- package/lib/agents/agent-session-stream.js.map +1 -1
- package/lib/agents/agent-session-stream.mjs +24 -21
- package/lib/agents/agent-session-stream.mjs.map +1 -1
- package/lib/beta/agents/agent-session-create-stream.d.mts +15 -0
- package/lib/beta/agents/agent-session-create-stream.d.mts.map +1 -0
- package/lib/beta/agents/agent-session-create-stream.d.ts +15 -0
- package/lib/beta/agents/agent-session-create-stream.d.ts.map +1 -0
- package/lib/beta/agents/agent-session-create-stream.js +25 -0
- package/lib/beta/agents/agent-session-create-stream.js.map +1 -0
- package/lib/beta/agents/agent-session-create-stream.mjs +22 -0
- package/lib/beta/agents/agent-session-create-stream.mjs.map +1 -0
- package/lib/beta/agents/agent-turn-result-collector.d.mts +17 -0
- package/lib/beta/agents/agent-turn-result-collector.d.mts.map +1 -0
- package/lib/beta/agents/agent-turn-result-collector.d.ts +17 -0
- package/lib/beta/agents/agent-turn-result-collector.d.ts.map +1 -0
- package/lib/beta/agents/agent-turn-result-collector.js +99 -0
- package/lib/beta/agents/agent-turn-result-collector.js.map +1 -0
- package/lib/beta/agents/agent-turn-result-collector.mjs +95 -0
- package/lib/beta/agents/agent-turn-result-collector.mjs.map +1 -0
- package/lib/beta/agents/agent-turn-result-error.d.mts +16 -0
- package/lib/beta/agents/agent-turn-result-error.d.mts.map +1 -0
- package/lib/beta/agents/agent-turn-result-error.d.ts +16 -0
- package/lib/beta/agents/agent-turn-result-error.d.ts.map +1 -0
- package/lib/beta/agents/agent-turn-result-error.js +22 -0
- package/lib/beta/agents/agent-turn-result-error.js.map +1 -0
- package/lib/beta/agents/agent-turn-result-error.mjs +18 -0
- package/lib/beta/agents/agent-turn-result-error.mjs.map +1 -0
- package/lib/beta/agents/agent-turn-result.d.mts +12 -0
- package/lib/beta/agents/agent-turn-result.d.mts.map +1 -0
- package/lib/beta/agents/agent-turn-result.d.ts +12 -0
- package/lib/beta/agents/agent-turn-result.d.ts.map +1 -0
- package/lib/beta/agents/agent-turn-result.js +22 -0
- package/lib/beta/agents/agent-turn-result.js.map +1 -0
- package/lib/beta/agents/agent-turn-result.mjs +18 -0
- package/lib/beta/agents/agent-turn-result.mjs.map +1 -0
- package/lib/beta/agents/files.d.mts +33 -0
- package/lib/beta/agents/files.d.mts.map +1 -0
- package/lib/beta/agents/files.d.ts +33 -0
- package/lib/beta/agents/files.d.ts.map +1 -0
- package/lib/beta/agents/files.js +93 -0
- package/lib/beta/agents/files.js.map +1 -0
- package/lib/beta/agents/files.mjs +86 -0
- package/lib/beta/agents/files.mjs.map +1 -0
- package/lib/beta/agents/function-tool.d.mts +27 -0
- package/lib/beta/agents/function-tool.d.mts.map +1 -0
- package/lib/beta/agents/function-tool.d.ts +27 -0
- package/lib/beta/agents/function-tool.d.ts.map +1 -0
- package/lib/beta/agents/function-tool.js +48 -0
- package/lib/beta/agents/function-tool.js.map +1 -0
- package/lib/beta/agents/function-tool.mjs +45 -0
- package/lib/beta/agents/function-tool.mjs.map +1 -0
- package/lib/beta/agents/output-format-types.d.mts +11 -0
- package/lib/beta/agents/output-format-types.d.mts.map +1 -0
- package/lib/beta/agents/output-format-types.d.ts +11 -0
- package/lib/beta/agents/output-format-types.d.ts.map +1 -0
- package/lib/beta/agents/output-format-types.js +3 -0
- package/lib/beta/agents/output-format-types.js.map +1 -0
- package/lib/beta/agents/output-format-types.mjs +2 -0
- package/lib/beta/agents/output-format-types.mjs.map +1 -0
- package/lib/beta/agents/output-format.d.mts +8 -0
- package/lib/beta/agents/output-format.d.mts.map +1 -0
- package/lib/beta/agents/output-format.d.ts +8 -0
- package/lib/beta/agents/output-format.d.ts.map +1 -0
- package/lib/beta/agents/output-format.js +20 -0
- package/lib/beta/agents/output-format.js.map +1 -0
- package/lib/beta/agents/output-format.mjs +14 -0
- package/lib/beta/agents/output-format.mjs.map +1 -0
- package/lib/beta/agents/output-parse-error.d.mts +11 -0
- package/lib/beta/agents/output-parse-error.d.mts.map +1 -0
- package/lib/beta/agents/output-parse-error.d.ts +11 -0
- package/lib/beta/agents/output-parse-error.d.ts.map +1 -0
- package/lib/beta/agents/output-parse-error.js +22 -0
- package/lib/beta/agents/output-parse-error.js.map +1 -0
- package/lib/beta/agents/output-parse-error.mjs +18 -0
- package/lib/beta/agents/output-parse-error.mjs.map +1 -0
- package/lib/beta/agents/pages.d.mts +9 -0
- package/lib/beta/agents/pages.d.mts.map +1 -0
- package/lib/beta/agents/pages.d.ts +9 -0
- package/lib/beta/agents/pages.d.ts.map +1 -0
- package/lib/beta/agents/pages.js +32 -0
- package/lib/beta/agents/pages.js.map +1 -0
- package/lib/beta/agents/pages.mjs +29 -0
- package/lib/beta/agents/pages.mjs.map +1 -0
- package/lib/beta/agents/parse-result.d.mts +95 -0
- package/lib/beta/agents/parse-result.d.mts.map +1 -0
- package/lib/beta/agents/parse-result.d.ts +95 -0
- package/lib/beta/agents/parse-result.d.ts.map +1 -0
- package/lib/beta/agents/parse-result.js +116 -0
- package/lib/beta/agents/parse-result.js.map +1 -0
- package/lib/beta/agents/parse-result.mjs +110 -0
- package/lib/beta/agents/parse-result.mjs.map +1 -0
- package/lib/beta/agents/parsed-agent-turn-result.d.mts +8 -0
- package/lib/beta/agents/parsed-agent-turn-result.d.mts.map +1 -0
- package/lib/beta/agents/parsed-agent-turn-result.d.ts +8 -0
- package/lib/beta/agents/parsed-agent-turn-result.d.ts.map +1 -0
- package/lib/beta/agents/parsed-agent-turn-result.js +14 -0
- package/lib/beta/agents/parsed-agent-turn-result.js.map +1 -0
- package/lib/beta/agents/parsed-agent-turn-result.mjs +10 -0
- package/lib/beta/agents/parsed-agent-turn-result.mjs.map +1 -0
- package/lib/beta/agents/result-artifacts.d.mts +19 -0
- package/lib/beta/agents/result-artifacts.d.mts.map +1 -0
- package/lib/beta/agents/result-artifacts.d.ts +19 -0
- package/lib/beta/agents/result-artifacts.d.ts.map +1 -0
- package/lib/beta/agents/result-artifacts.js +67 -0
- package/lib/beta/agents/result-artifacts.js.map +1 -0
- package/lib/beta/agents/result-artifacts.mjs +63 -0
- package/lib/beta/agents/result-artifacts.mjs.map +1 -0
- package/lib/beta/agents/result-collection.d.mts +15 -0
- package/lib/beta/agents/result-collection.d.mts.map +1 -0
- package/lib/beta/agents/result-collection.d.ts +15 -0
- package/lib/beta/agents/result-collection.d.ts.map +1 -0
- package/lib/beta/agents/result-collection.js +110 -0
- package/lib/beta/agents/result-collection.js.map +1 -0
- package/lib/beta/agents/result-collection.mjs +106 -0
- package/lib/beta/agents/result-collection.mjs.map +1 -0
- package/lib/beta/agents/tool-output.d.mts +7 -0
- package/lib/beta/agents/tool-output.d.mts.map +1 -0
- package/lib/beta/agents/tool-output.d.ts +7 -0
- package/lib/beta/agents/tool-output.d.ts.map +1 -0
- package/lib/beta/agents/tool-output.js +26 -0
- package/lib/beta/agents/tool-output.js.map +1 -0
- package/lib/beta/agents/tool-output.mjs +23 -0
- package/lib/beta/agents/tool-output.mjs.map +1 -0
- package/lib/responses/responses-websocket-session.d.mts +1 -1
- package/lib/responses/responses-websocket-session.d.mts.map +1 -1
- package/lib/responses/responses-websocket-session.d.ts +1 -1
- package/lib/responses/responses-websocket-session.d.ts.map +1 -1
- package/lib/responses/responses-websocket-session.js +12 -2
- package/lib/responses/responses-websocket-session.js.map +1 -1
- package/lib/responses/responses-websocket-session.mjs +12 -2
- package/lib/responses/responses-websocket-session.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +9 -0
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +9 -0
- 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/files.d.mts +12 -0
- package/resources/beta/agents/environments/files.d.mts.map +1 -1
- package/resources/beta/agents/environments/files.d.ts +12 -0
- package/resources/beta/agents/environments/files.d.ts.map +1 -1
- package/resources/beta/agents/environments/files.js +9 -0
- package/resources/beta/agents/environments/files.js.map +1 -1
- package/resources/beta/agents/environments/files.mjs +9 -0
- package/resources/beta/agents/environments/files.mjs.map +1 -1
- package/resources/beta/agents/sessions/artifacts.d.mts +4 -0
- package/resources/beta/agents/sessions/artifacts.d.mts.map +1 -1
- package/resources/beta/agents/sessions/artifacts.d.ts +4 -0
- package/resources/beta/agents/sessions/artifacts.d.ts.map +1 -1
- package/resources/beta/agents/sessions/artifacts.js +5 -0
- package/resources/beta/agents/sessions/artifacts.js.map +1 -1
- package/resources/beta/agents/sessions/artifacts.mjs +5 -0
- package/resources/beta/agents/sessions/artifacts.mjs.map +1 -1
- package/resources/beta/agents/sessions/events.d.mts +6 -5
- package/resources/beta/agents/sessions/events.d.mts.map +1 -1
- package/resources/beta/agents/sessions/events.d.ts +6 -5
- package/resources/beta/agents/sessions/events.d.ts.map +1 -1
- package/resources/beta/agents/sessions/events.js +6 -5
- package/resources/beta/agents/sessions/events.js.map +1 -1
- package/resources/beta/agents/sessions/events.mjs +6 -5
- package/resources/beta/agents/sessions/events.mjs.map +1 -1
- package/resources/beta/agents/sessions/index.d.mts +1 -0
- package/resources/beta/agents/sessions/index.d.mts.map +1 -1
- package/resources/beta/agents/sessions/index.d.ts +1 -0
- package/resources/beta/agents/sessions/index.d.ts.map +1 -1
- package/resources/beta/agents/sessions/index.js +3 -1
- package/resources/beta/agents/sessions/index.js.map +1 -1
- package/resources/beta/agents/sessions/index.mjs +1 -0
- package/resources/beta/agents/sessions/index.mjs.map +1 -1
- package/resources/beta/agents/sessions/sessions.d.mts +16 -4
- package/resources/beta/agents/sessions/sessions.d.mts.map +1 -1
- package/resources/beta/agents/sessions/sessions.d.ts +16 -4
- package/resources/beta/agents/sessions/sessions.d.ts.map +1 -1
- package/resources/beta/agents/sessions/sessions.js +17 -4
- package/resources/beta/agents/sessions/sessions.js.map +1 -1
- package/resources/beta/agents/sessions/sessions.mjs +17 -4
- package/resources/beta/agents/sessions/sessions.mjs.map +1 -1
- package/resources/beta/agents/sessions/traces.d.mts +68 -0
- package/resources/beta/agents/sessions/traces.d.mts.map +1 -0
- package/resources/beta/agents/sessions/traces.d.ts +68 -0
- package/resources/beta/agents/sessions/traces.d.ts.map +1 -0
- package/resources/beta/agents/sessions/traces.js +81 -0
- package/resources/beta/agents/sessions/traces.js.map +1 -0
- package/resources/beta/agents/sessions/traces.mjs +77 -0
- package/resources/beta/agents/sessions/traces.mjs.map +1 -0
- package/resources/beta/responses/ws-base.d.mts +3 -1
- package/resources/beta/responses/ws-base.d.mts.map +1 -1
- package/resources/beta/responses/ws-base.d.ts +3 -1
- package/resources/beta/responses/ws-base.d.ts.map +1 -1
- package/resources/beta/responses/ws-base.js +35 -6
- package/resources/beta/responses/ws-base.js.map +1 -1
- package/resources/beta/responses/ws-base.mjs +35 -6
- package/resources/beta/responses/ws-base.mjs.map +1 -1
- package/resources/beta/responses/ws.d.mts +10 -0
- package/resources/beta/responses/ws.d.mts.map +1 -1
- package/resources/beta/responses/ws.d.ts +10 -0
- package/resources/beta/responses/ws.d.ts.map +1 -1
- package/resources/beta/responses/ws.js +23 -22
- package/resources/beta/responses/ws.js.map +1 -1
- package/resources/beta/responses/ws.mjs +24 -23
- package/resources/beta/responses/ws.mjs.map +1 -1
- package/resources/chat/completions/completions.d.mts +1 -1
- package/resources/chat/completions/completions.d.mts.map +1 -1
- package/resources/chat/completions/completions.d.ts +1 -1
- package/resources/chat/completions/completions.d.ts.map +1 -1
- package/resources/evals/runs/runs.js +1 -1
- package/resources/evals/runs/runs.js.map +1 -1
- package/resources/evals/runs/runs.mjs +1 -1
- package/resources/evals/runs/runs.mjs.map +1 -1
- package/resources/live/forks/forks.d.mts +5 -1
- package/resources/live/forks/forks.d.mts.map +1 -1
- package/resources/live/forks/forks.d.ts +5 -1
- package/resources/live/forks/forks.d.ts.map +1 -1
- package/resources/live/live.d.mts +5 -1
- package/resources/live/live.d.mts.map +1 -1
- package/resources/live/live.d.ts +5 -1
- package/resources/live/live.d.ts.map +1 -1
- package/resources/live/live.js.map +1 -1
- package/resources/live/live.mjs.map +1 -1
- package/resources/responses/ws-base.d.mts +3 -1
- package/resources/responses/ws-base.d.mts.map +1 -1
- package/resources/responses/ws-base.d.ts +3 -1
- package/resources/responses/ws-base.d.ts.map +1 -1
- package/resources/responses/ws-base.js +35 -6
- package/resources/responses/ws-base.js.map +1 -1
- package/resources/responses/ws-base.mjs +35 -6
- package/resources/responses/ws-base.mjs.map +1 -1
- package/resources/responses/ws.d.mts +10 -0
- package/resources/responses/ws.d.mts.map +1 -1
- package/resources/responses/ws.d.ts +10 -0
- package/resources/responses/ws.d.ts.map +1 -1
- package/resources/responses/ws.js +23 -22
- package/resources/responses/ws.js.map +1 -1
- package/resources/responses/ws.mjs +24 -23
- package/resources/responses/ws.mjs.map +1 -1
- package/src/client.ts +55 -19
- package/src/core/streaming.ts +9 -0
- package/src/helpers/beta/agents/filesystem.ts +187 -0
- package/src/helpers/beta/agents/standard-schema.ts +13 -0
- package/src/helpers/beta/agents/zod.ts +10 -0
- package/src/internal/realtime-credentials.ts +70 -4
- package/src/internal/responses-ws-credentials.ts +160 -0
- package/src/internal/shim-types.ts +17 -0
- package/src/internal/ws-adapter-node.ts +66 -0
- package/src/internal/ws.ts +139 -11
- package/src/lib/agents/agent-session-stream.ts +36 -24
- package/src/lib/beta/agents/agent-session-create-stream.ts +36 -0
- package/src/lib/beta/agents/agent-turn-result-collector.ts +122 -0
- package/src/lib/beta/agents/agent-turn-result-error.ts +33 -0
- package/src/lib/beta/agents/agent-turn-result.ts +22 -0
- package/src/lib/beta/agents/files.ts +119 -0
- package/src/lib/beta/agents/function-tool.ts +60 -0
- package/src/lib/beta/agents/output-format-types.ts +12 -0
- package/src/lib/beta/agents/output-format.ts +20 -0
- package/src/lib/beta/agents/output-parse-error.ts +16 -0
- package/src/lib/beta/agents/pages.ts +32 -0
- package/src/lib/beta/agents/parse-result.ts +133 -0
- package/src/lib/beta/agents/parsed-agent-turn-result.ts +12 -0
- package/src/lib/beta/agents/result-artifacts.ts +76 -0
- package/src/lib/beta/agents/result-collection.ts +115 -0
- package/src/lib/beta/agents/tool-output.ts +22 -0
- package/src/lib/responses/responses-websocket-session.ts +14 -3
- package/src/resources/beta/agents/agents.ts +11 -0
- package/src/resources/beta/agents/environments/files.ts +16 -0
- package/src/resources/beta/agents/sessions/artifacts.ts +7 -0
- package/src/resources/beta/agents/sessions/events.ts +6 -5
- package/src/resources/beta/agents/sessions/index.ts +1 -0
- package/src/resources/beta/agents/sessions/sessions.ts +48 -18
- package/src/resources/beta/agents/sessions/traces.ts +298 -0
- package/src/resources/beta/responses/ws-base.ts +40 -6
- package/src/resources/beta/responses/ws.ts +37 -27
- package/src/resources/chat/completions/completions.ts +1 -1
- package/src/resources/evals/runs/runs.ts +1 -1
- package/src/resources/live/forks/forks.ts +6 -1
- package/src/resources/live/live.ts +6 -1
- package/src/resources/responses/ws-base.ts +40 -6
- package/src/resources/responses/ws.ts +37 -27
- package/src/tsconfig.dist-src-node.d.ts +7 -0
- package/src/tsconfig.dist-src.d.ts +3 -1
- 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
|
@@ -6,8 +6,7 @@ const tslib_1 = require("../../internal/tslib.js");
|
|
|
6
6
|
const WS = tslib_1.__importStar(require("ws"));
|
|
7
7
|
const ws_adapter_node_1 = require("../../internal/ws-adapter-node.js");
|
|
8
8
|
const ws_base_1 = require("./ws-base.js");
|
|
9
|
-
const
|
|
10
|
-
const ws_1 = require("../../internal/ws.js");
|
|
9
|
+
const responses_ws_credentials_1 = require("../../internal/responses-ws-credentials.js");
|
|
11
10
|
class ResponsesWS extends ws_base_1.ResponsesWSBase {
|
|
12
11
|
constructor(client, options) {
|
|
13
12
|
if (!WS?.WebSocket) {
|
|
@@ -15,32 +14,34 @@ class ResponsesWS extends ws_base_1.ResponsesWSBase {
|
|
|
15
14
|
}
|
|
16
15
|
const { reconnect, maxQueueSize, ...wsOptions } = options ?? {};
|
|
17
16
|
super(client, { reconnect, maxQueueSize });
|
|
17
|
+
this._credentials = new responses_ws_credentials_1.ResponsesWebSocketCredentials();
|
|
18
18
|
this._wsOptions = wsOptions;
|
|
19
19
|
this._connectInitial();
|
|
20
20
|
}
|
|
21
|
+
_authHeaders(apiKey) {
|
|
22
|
+
const headers = super._authHeaders(apiKey === undefined ? this._credentials.preparedAPIKey : apiKey);
|
|
23
|
+
this._credentials.trackInitialHeaders(this._client, headers, () => !!this.socket);
|
|
24
|
+
return headers;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether credentials passed to the Node transport use the SDK key.
|
|
28
|
+
* The SDK recognizes its key, including copies and additions in credential headers.
|
|
29
|
+
* Override and return true if your socket hook signs or otherwise irreversibly transforms it.
|
|
30
|
+
* Explicit caller options and header removals still take precedence on reconnect.
|
|
31
|
+
*/
|
|
32
|
+
_usesSDKAPIKey(authHeaders) {
|
|
33
|
+
return this._credentials.usesAPIKey(this._client, authHeaders);
|
|
34
|
+
}
|
|
21
35
|
_createSocket(url, authHeaders) {
|
|
22
36
|
const capturedAuthHeaders = { ...authHeaders };
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
headers.set(name.toLowerCase(), value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const socketOptions = {
|
|
33
|
-
...this._wsOptions,
|
|
34
|
-
headers: Object.fromEntries(headers),
|
|
35
|
-
followRedirects: false,
|
|
36
|
-
};
|
|
37
|
-
if (this._client._hasApiKeyProvider() &&
|
|
38
|
-
!capturedAuthHeaders['Authorization'] &&
|
|
39
|
-
!(0, ws_1.snapshotWebSocketCredentials)(socketOptions)) {
|
|
40
|
-
throw new error_1.OpenAIError('Cannot open a Responses WebSocket with an unresolved function-based apiKey. Resolve it before constructing the WebSocket or provide explicit WebSocket credentials.');
|
|
37
|
+
const socketOptions = this._credentials.build(this._client, capturedAuthHeaders, this._wsOptions, !this.socket ? this._usesSDKAPIKey(capturedAuthHeaders) : undefined);
|
|
38
|
+
return new ws_adapter_node_1.NodeWebSocket(new WS.WebSocket(url, socketOptions));
|
|
39
|
+
}
|
|
40
|
+
async _prepareReconnectSocket() {
|
|
41
|
+
if (!this._client._hasApiKeyProvider()) {
|
|
42
|
+
return super._prepareReconnectSocket();
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
return new ws_adapter_node_1.NodeWebSocket(ws);
|
|
44
|
+
return this._credentials.prepare(this._client, (0, ws_adapter_node_1.snapshotNodeWebSocketOptions)(this._wsOptions), (...args) => this._authHeaders(...args), (url, headers) => this._createSocket(url, headers));
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
exports.ResponsesWS = ResponsesWS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/resources/responses/ws.ts"],"names":[],"mappings":";AAAA,qFAAqF;;;;AAErF,+CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/resources/responses/ws.ts"],"names":[],"mappings":";AAAA,qFAAqF;;;;AAErF,+CAAyB;AACzB,uEAA6F;AAC7F,0CAAyE;AAEzE,yFAAwF;AAWxF,MAAa,WAAY,SAAQ,yBAA8B;IAI7D,YAAY,MAAc,EAAE,OAAqD;QAC/E,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAChE,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;QATrC,iBAAY,GAAG,IAAI,wDAA6B,EAAE,CAAC;QAUzD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;IAEkB,YAAY,CAAC,MAAsB;QACpD,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACrG,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACO,cAAc,CAAC,WAAmC;QAC1D,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAES,aAAa,CAAC,GAAQ,EAAE,WAAmC;QACnE,MAAM,mBAAmB,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;QAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAC3C,IAAI,CAAC,OAAO,EACZ,mBAAmB,EACnB,IAAI,CAAC,UAAU,EACf,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,SAAS,CACpE,CAAC;QACF,OAAO,IAAI,+BAAa,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IACjE,CAAC;IAEkB,KAAK,CAAC,uBAAuB;QAC9C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC,uBAAuB,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAC9B,IAAI,CAAC,OAAO,EACZ,IAAA,8CAA4B,EAAC,IAAI,CAAC,UAAU,CAAC,EAC7C,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,EACvC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CACnD,CAAC;IACJ,CAAC;CACF;AAtDD,kCAsDC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
|
|
2
2
|
import * as WS from 'ws';
|
|
3
|
-
import { NodeWebSocket } from "../../internal/ws-adapter-node.mjs";
|
|
3
|
+
import { NodeWebSocket, snapshotNodeWebSocketOptions } from "../../internal/ws-adapter-node.mjs";
|
|
4
4
|
import { ResponsesWSBase } from "./ws-base.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { snapshotWebSocketCredentials } from "../../internal/ws.mjs";
|
|
5
|
+
import { ResponsesWebSocketCredentials } from "../../internal/responses-ws-credentials.mjs";
|
|
7
6
|
export class ResponsesWS extends ResponsesWSBase {
|
|
8
7
|
constructor(client, options) {
|
|
9
8
|
if (!WS?.WebSocket) {
|
|
@@ -11,32 +10,34 @@ export class ResponsesWS extends ResponsesWSBase {
|
|
|
11
10
|
}
|
|
12
11
|
const { reconnect, maxQueueSize, ...wsOptions } = options ?? {};
|
|
13
12
|
super(client, { reconnect, maxQueueSize });
|
|
13
|
+
this._credentials = new ResponsesWebSocketCredentials();
|
|
14
14
|
this._wsOptions = wsOptions;
|
|
15
15
|
this._connectInitial();
|
|
16
16
|
}
|
|
17
|
+
_authHeaders(apiKey) {
|
|
18
|
+
const headers = super._authHeaders(apiKey === undefined ? this._credentials.preparedAPIKey : apiKey);
|
|
19
|
+
this._credentials.trackInitialHeaders(this._client, headers, () => !!this.socket);
|
|
20
|
+
return headers;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether credentials passed to the Node transport use the SDK key.
|
|
24
|
+
* The SDK recognizes its key, including copies and additions in credential headers.
|
|
25
|
+
* Override and return true if your socket hook signs or otherwise irreversibly transforms it.
|
|
26
|
+
* Explicit caller options and header removals still take precedence on reconnect.
|
|
27
|
+
*/
|
|
28
|
+
_usesSDKAPIKey(authHeaders) {
|
|
29
|
+
return this._credentials.usesAPIKey(this._client, authHeaders);
|
|
30
|
+
}
|
|
17
31
|
_createSocket(url, authHeaders) {
|
|
18
32
|
const capturedAuthHeaders = { ...authHeaders };
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
headers.set(name.toLowerCase(), value);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const socketOptions = {
|
|
29
|
-
...this._wsOptions,
|
|
30
|
-
headers: Object.fromEntries(headers),
|
|
31
|
-
followRedirects: false,
|
|
32
|
-
};
|
|
33
|
-
if (this._client._hasApiKeyProvider() &&
|
|
34
|
-
!capturedAuthHeaders['Authorization'] &&
|
|
35
|
-
!snapshotWebSocketCredentials(socketOptions)) {
|
|
36
|
-
throw new OpenAIError('Cannot open a Responses WebSocket with an unresolved function-based apiKey. Resolve it before constructing the WebSocket or provide explicit WebSocket credentials.');
|
|
33
|
+
const socketOptions = this._credentials.build(this._client, capturedAuthHeaders, this._wsOptions, !this.socket ? this._usesSDKAPIKey(capturedAuthHeaders) : undefined);
|
|
34
|
+
return new NodeWebSocket(new WS.WebSocket(url, socketOptions));
|
|
35
|
+
}
|
|
36
|
+
async _prepareReconnectSocket() {
|
|
37
|
+
if (!this._client._hasApiKeyProvider()) {
|
|
38
|
+
return super._prepareReconnectSocket();
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
return new NodeWebSocket(ws);
|
|
40
|
+
return this._credentials.prepare(this._client, snapshotNodeWebSocketOptions(this._wsOptions), (...args) => this._authHeaders(...args), (url, headers) => this._createSocket(url, headers));
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
//# sourceMappingURL=ws.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.mjs","sourceRoot":"","sources":["../../src/resources/responses/ws.ts"],"names":[],"mappings":"AAAA,qFAAqF;AAErF,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,2CAAuC;
|
|
1
|
+
{"version":3,"file":"ws.mjs","sourceRoot":"","sources":["../../src/resources/responses/ws.ts"],"names":[],"mappings":"AAAA,qFAAqF;AAErF,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,2CAAuC;AAC7F,OAAO,EAAE,eAAe,EAA+B,sBAAkB;AAEzE,OAAO,EAAE,6BAA6B,EAAE,oDAAgD;AAWxF,MAAM,OAAO,WAAY,SAAQ,eAA8B;IAI7D,YAAY,MAAc,EAAE,OAAqD;QAC/E,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAChE,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;QATrC,iBAAY,GAAG,IAAI,6BAA6B,EAAE,CAAC;QAUzD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;IAEkB,YAAY,CAAC,MAAsB;QACpD,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACrG,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACO,cAAc,CAAC,WAAmC;QAC1D,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAES,aAAa,CAAC,GAAQ,EAAE,WAAmC;QACnE,MAAM,mBAAmB,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;QAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAC3C,IAAI,CAAC,OAAO,EACZ,mBAAmB,EACnB,IAAI,CAAC,UAAU,EACf,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,SAAS,CACpE,CAAC;QACF,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IACjE,CAAC;IAEkB,KAAK,CAAC,uBAAuB;QAC9C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC,uBAAuB,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAC9B,IAAI,CAAC,OAAO,EACZ,4BAA4B,CAAC,IAAI,CAAC,UAAU,CAAC,EAC7C,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,EACvC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CACnD,CAAC;IACJ,CAAC;CACF"}
|
package/src/client.ts
CHANGED
|
@@ -48,7 +48,11 @@ import {
|
|
|
48
48
|
import * as Uploads from './core/uploads';
|
|
49
49
|
import * as API from './resources/index';
|
|
50
50
|
import { APIPromise } from './core/api-promise';
|
|
51
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
getDeferredRealtimeAPIKeyCache,
|
|
53
|
+
resolveRealtimeAPIKey,
|
|
54
|
+
validateCapturedAPIKey,
|
|
55
|
+
} from './internal/realtime-credentials';
|
|
52
56
|
import {
|
|
53
57
|
Batch,
|
|
54
58
|
BatchCreateParams,
|
|
@@ -258,6 +262,7 @@ import {
|
|
|
258
262
|
import { type Fetch } from './internal/builtin-types';
|
|
259
263
|
import { isRunningInBrowser } from './internal/detect-platform';
|
|
260
264
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
265
|
+
import { mergeWebSocketAuthHeaders, webSocketHeaderRemovals } from './internal/ws';
|
|
261
266
|
import { configureProvider, type Provider, type ProviderRuntime } from './internal/provider';
|
|
262
267
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
263
268
|
import { readEnv } from './internal/utils/env';
|
|
@@ -490,6 +495,8 @@ export class OpenAI {
|
|
|
490
495
|
protected idempotencyHeader?: string;
|
|
491
496
|
protected _options: ClientOptions;
|
|
492
497
|
private _provider: ProviderRuntime | undefined;
|
|
498
|
+
private _apiKeyInvocation = 0;
|
|
499
|
+
private _lastCachedAPIKeyInvocation = 0;
|
|
493
500
|
private _workloadIdentityAuth?: WorkloadIdentityAuth | X509WorkloadIdentityAuth;
|
|
494
501
|
|
|
495
502
|
/**
|
|
@@ -741,18 +748,33 @@ export class OpenAI {
|
|
|
741
748
|
}
|
|
742
749
|
|
|
743
750
|
/** @internal Client request headers for each new WebSocket handshake. */
|
|
744
|
-
_buildWebSocketHeaders(
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
},
|
|
751
|
+
_buildWebSocketHeaders(
|
|
752
|
+
authHeaders: Record<string, string>,
|
|
753
|
+
removedHeaders?: Set<string>,
|
|
754
|
+
): Record<string, string> {
|
|
755
|
+
const context = webSocketHeaderRemovals.get(this);
|
|
756
|
+
if (context?.baseHeaders) {
|
|
757
|
+
return mergeWebSocketAuthHeaders(
|
|
758
|
+
{ headers: context.baseHeaders },
|
|
752
759
|
authHeaders,
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
760
|
+
context.removedHeaders ?? new Set(),
|
|
761
|
+
).headers;
|
|
762
|
+
}
|
|
763
|
+
const headers = buildHeaders([
|
|
764
|
+
{
|
|
765
|
+
'User-Agent': this.getUserAgent(),
|
|
766
|
+
'OpenAI-Organization': this.organization,
|
|
767
|
+
'OpenAI-Project': this.project,
|
|
768
|
+
},
|
|
769
|
+
authHeaders,
|
|
770
|
+
this._options.defaultHeaders,
|
|
771
|
+
]);
|
|
772
|
+
headers.nulls.forEach((name) => (removedHeaders ?? context?.removedHeaders)?.add(name));
|
|
773
|
+
const result = Object.fromEntries(headers.values);
|
|
774
|
+
if (context) {
|
|
775
|
+
context.baseHeaders = { ...result };
|
|
776
|
+
}
|
|
777
|
+
return result;
|
|
756
778
|
}
|
|
757
779
|
|
|
758
780
|
protected validateHeaders(
|
|
@@ -877,11 +899,8 @@ export class OpenAI {
|
|
|
877
899
|
}
|
|
878
900
|
|
|
879
901
|
/**
|
|
880
|
-
* Resolves a
|
|
881
|
-
*
|
|
882
|
-
* invocation's key before another request updates the shared `apiKey` property.
|
|
883
|
-
* Overrides should forward `capture` or invoke it with their own resolved key
|
|
884
|
-
* to preserve invocation-local credentials in concurrent requests and Realtime factories.
|
|
902
|
+
* Resolves and retains a provider key, returning whether a provider was invoked.
|
|
903
|
+
* Overrides should forward `capture` (or call it with their resolved key) for local credentials.
|
|
885
904
|
* @internal
|
|
886
905
|
*/
|
|
887
906
|
async _callApiKey(capture?: (apiKey: string | null) => void): Promise<boolean> {
|
|
@@ -896,6 +915,8 @@ export class OpenAI {
|
|
|
896
915
|
return false;
|
|
897
916
|
}
|
|
898
917
|
|
|
918
|
+
const deferredCache = getDeferredRealtimeAPIKeyCache(this);
|
|
919
|
+
const invocation = ++this._apiKeyInvocation;
|
|
899
920
|
let token: unknown;
|
|
900
921
|
try {
|
|
901
922
|
token = await apiKey();
|
|
@@ -913,8 +934,23 @@ export class OpenAI {
|
|
|
913
934
|
`Expected 'apiKey' function argument to return a string but it returned ${token}`,
|
|
914
935
|
);
|
|
915
936
|
}
|
|
916
|
-
|
|
917
|
-
|
|
937
|
+
const resolvedToken = token;
|
|
938
|
+
const commit = () => {
|
|
939
|
+
if (capture) validateCapturedAPIKey(this, resolvedToken);
|
|
940
|
+
if (invocation < this._lastCachedAPIKeyInvocation) {
|
|
941
|
+
return resolvedToken;
|
|
942
|
+
}
|
|
943
|
+
this.apiKey = resolvedToken;
|
|
944
|
+
const cached = capture ? this.apiKey : resolvedToken;
|
|
945
|
+
this._lastCachedAPIKeyInvocation = invocation;
|
|
946
|
+
return cached;
|
|
947
|
+
};
|
|
948
|
+
if (deferredCache) {
|
|
949
|
+
deferredCache.providerKey = resolvedToken;
|
|
950
|
+
deferredCache.commit = commit;
|
|
951
|
+
}
|
|
952
|
+
const cached = deferredCache ? validateCapturedAPIKey(this, resolvedToken) : commit();
|
|
953
|
+
capture?.(cached);
|
|
918
954
|
return true;
|
|
919
955
|
}
|
|
920
956
|
|
package/src/core/streaming.ts
CHANGED
|
@@ -301,6 +301,15 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
301
301
|
return this.iterator();
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
/** Beta-only iterator decoration for Agents helpers, preserving custom stream identity.
|
|
305
|
+
* @internal
|
|
306
|
+
*/
|
|
307
|
+
__betaTransformIterator(
|
|
308
|
+
transform: (iterator: () => AsyncIterator<Item>) => () => AsyncIterator<Item>,
|
|
309
|
+
): void {
|
|
310
|
+
this.iterator = transform(this.iterator.bind(this));
|
|
311
|
+
}
|
|
312
|
+
|
|
304
313
|
/**
|
|
305
314
|
* Splits the stream into two streams which can be
|
|
306
315
|
* independently read from at different speeds.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import type { Stats } from 'node:fs';
|
|
3
|
+
import type { WritableStream as AgentWritableStream } from '../../../internal/shim-types';
|
|
4
|
+
import { lstat, open, realpath } from 'node:fs/promises';
|
|
5
|
+
import type { FileHandle } from 'node:fs/promises';
|
|
6
|
+
import nodePath from 'node:path';
|
|
7
|
+
import { OpenAIError } from '../../../core/error';
|
|
8
|
+
import { toStreamingFile } from '../../../internal/uploads';
|
|
9
|
+
import type { StreamingFile } from '../../../internal/uploads';
|
|
10
|
+
import type { RequestOptions } from '../../../internal/request-options';
|
|
11
|
+
import type { Files } from '../../../resources/beta/agents/environments/files';
|
|
12
|
+
import type { PreparedAgentFiles } from '../../../lib/beta/agents/files';
|
|
13
|
+
|
|
14
|
+
async function checkedPath(path: string, boundary?: string): Promise<{ path: string; info: Stats }> {
|
|
15
|
+
const absolute = nodePath.resolve(path);
|
|
16
|
+
const root = boundary ?? nodePath.dirname(absolute);
|
|
17
|
+
let current = root;
|
|
18
|
+
let selected: Stats | undefined;
|
|
19
|
+
for (const component of nodePath.relative(root, absolute).split(nodePath.sep)) {
|
|
20
|
+
current = nodePath.join(current, component);
|
|
21
|
+
// oxlint-disable-next-line no-await-in-loop -- Check each ancestor before following the next path component.
|
|
22
|
+
const info = await lstat(current);
|
|
23
|
+
selected = info;
|
|
24
|
+
if (info.isSymbolicLink()) {
|
|
25
|
+
throw new OpenAIError('Agent file sources cannot contain symbolic links');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const resolved = await realpath(absolute);
|
|
29
|
+
const info = await lstat(resolved);
|
|
30
|
+
const relative = boundary ? nodePath.relative(boundary, resolved) : '';
|
|
31
|
+
if (
|
|
32
|
+
!selected ||
|
|
33
|
+
selected.dev !== info.dev ||
|
|
34
|
+
selected.ino !== info.ino ||
|
|
35
|
+
selected.size !== info.size ||
|
|
36
|
+
(boundary &&
|
|
37
|
+
(relative === '..' || relative.startsWith(`..${nodePath.sep}`) || nodePath.isAbsolute(relative)))
|
|
38
|
+
) {
|
|
39
|
+
throw new OpenAIError('Selected agent file changed while resolving its path');
|
|
40
|
+
}
|
|
41
|
+
return { path: resolved, info: selected };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function selectedAgentFile({
|
|
45
|
+
path: absolute,
|
|
46
|
+
info,
|
|
47
|
+
}: {
|
|
48
|
+
path: string;
|
|
49
|
+
info: Stats;
|
|
50
|
+
}): StreamingFile & { size: number } {
|
|
51
|
+
if (!info.isFile()) {
|
|
52
|
+
throw new OpenAIError('Agent file sources must be regular files');
|
|
53
|
+
}
|
|
54
|
+
async function* bytes() {
|
|
55
|
+
// oxlint-disable-next-line no-bitwise -- Combine native filesystem open flags.
|
|
56
|
+
const handle = await open(absolute, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
57
|
+
try {
|
|
58
|
+
const current = await handle.stat();
|
|
59
|
+
if (
|
|
60
|
+
!current.isFile() ||
|
|
61
|
+
current.dev !== info.dev ||
|
|
62
|
+
current.ino !== info.ino ||
|
|
63
|
+
current.size !== info.size
|
|
64
|
+
) {
|
|
65
|
+
throw new OpenAIError('Selected agent file changed before upload');
|
|
66
|
+
}
|
|
67
|
+
let received = 0;
|
|
68
|
+
if (info.size > 0) {
|
|
69
|
+
for await (const chunk of handle.createReadStream({ autoClose: false, end: info.size - 1 })) {
|
|
70
|
+
received += chunk.length;
|
|
71
|
+
yield chunk;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const finalInfo = await handle.stat();
|
|
75
|
+
if (received !== info.size || finalInfo.size !== info.size) {
|
|
76
|
+
throw new OpenAIError('Selected agent file changed while uploading');
|
|
77
|
+
}
|
|
78
|
+
} finally {
|
|
79
|
+
await handle.close();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return Object.assign(toStreamingFile({ [Symbol.asyncIterator]: bytes }, nodePath.basename(absolute)), {
|
|
83
|
+
size: info.size,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Beta, Node.js: select an application-owned file in a stable directory for a lazy upload. */
|
|
88
|
+
export async function agentFile(path: string): Promise<StreamingFile & { size: number }> {
|
|
89
|
+
return selectedAgentFile(await checkedPath(path));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Beta, Node.js: prepare explicit files from a stable application-owned directory once. */
|
|
93
|
+
export async function prepareAgentDirectory(
|
|
94
|
+
resource: Files,
|
|
95
|
+
directory: string,
|
|
96
|
+
params: { include: readonly string[]; to?: string },
|
|
97
|
+
options?: RequestOptions,
|
|
98
|
+
): Promise<PreparedAgentFiles> {
|
|
99
|
+
const include = [...params.include];
|
|
100
|
+
const destination = params.to ?? '/workspace';
|
|
101
|
+
const { path: root, info: rootInfo } = await checkedPath(directory);
|
|
102
|
+
if (!rootInfo.isDirectory()) {
|
|
103
|
+
throw new OpenAIError('Expected a directory');
|
|
104
|
+
}
|
|
105
|
+
const selected: Record<string, StreamingFile & { size: number }> = {};
|
|
106
|
+
const seen = new Set<string>();
|
|
107
|
+
for (const relative of include) {
|
|
108
|
+
if (
|
|
109
|
+
relative.includes('\\') ||
|
|
110
|
+
relative.includes('\0') ||
|
|
111
|
+
relative.split('/').some((part) => part === '' || part === '.' || part === '..') ||
|
|
112
|
+
seen.has(relative)
|
|
113
|
+
) {
|
|
114
|
+
throw new OpenAIError('Directory selections must be unique relative file paths');
|
|
115
|
+
}
|
|
116
|
+
seen.add(relative);
|
|
117
|
+
// oxlint-disable-next-line no-await-in-loop -- Prepare each explicitly selected source before any upload begins.
|
|
118
|
+
const source = await checkedPath(nodePath.join(root, relative), root);
|
|
119
|
+
selected[`${destination}/${relative}`] = selectedAgentFile(source);
|
|
120
|
+
}
|
|
121
|
+
return resource.prepare(selected, options);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Beta, Node.js: an application-owned safe path in a stable directory, opened lazily for a download. */
|
|
125
|
+
export function agentFileDestination(path: string): AgentWritableStream<Uint8Array> {
|
|
126
|
+
const absolute = nodePath.resolve(path);
|
|
127
|
+
let handle: FileHandle | undefined;
|
|
128
|
+
const close = async () => {
|
|
129
|
+
await handle?.close();
|
|
130
|
+
handle = undefined;
|
|
131
|
+
};
|
|
132
|
+
const file = async () => {
|
|
133
|
+
if (handle) {
|
|
134
|
+
return handle;
|
|
135
|
+
}
|
|
136
|
+
let expected: Stats | undefined;
|
|
137
|
+
try {
|
|
138
|
+
expected = await lstat(absolute);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT')) {
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (expected && !expected.isFile()) {
|
|
145
|
+
throw new OpenAIError('Agent artifact destinations must be regular files');
|
|
146
|
+
}
|
|
147
|
+
// Never truncate before verifying the opened entry. Exclusive creation also rejects dangling links.
|
|
148
|
+
/* oxlint-disable no-bitwise -- Combine native flags; identity validation also covers Windows. */
|
|
149
|
+
const flags =
|
|
150
|
+
constants.O_WRONLY |
|
|
151
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
152
|
+
(constants.O_NONBLOCK ?? 0) |
|
|
153
|
+
(expected ? 0 : constants.O_CREAT | constants.O_EXCL);
|
|
154
|
+
/* oxlint-enable no-bitwise */
|
|
155
|
+
const opened = await open(absolute, flags);
|
|
156
|
+
try {
|
|
157
|
+
const current = await opened.stat();
|
|
158
|
+
if (!current.isFile() || (expected && (current.dev !== expected.dev || current.ino !== expected.ino))) {
|
|
159
|
+
throw new OpenAIError('Agent artifact destination changed before opening');
|
|
160
|
+
}
|
|
161
|
+
await opened.truncate(0);
|
|
162
|
+
handle = opened;
|
|
163
|
+
return handle;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
await opened.close();
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return new WritableStream<Uint8Array>({
|
|
170
|
+
async write(chunk) {
|
|
171
|
+
try {
|
|
172
|
+
const target = await file();
|
|
173
|
+
await target.writeFile(chunk);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
await close();
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
async close() {
|
|
180
|
+
await file();
|
|
181
|
+
await close();
|
|
182
|
+
},
|
|
183
|
+
async abort() {
|
|
184
|
+
await close();
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { standardTextFormat } from '../../standard-schema';
|
|
2
|
+
import type { JSONSchema } from '../../../lib/jsonschema';
|
|
3
|
+
import { agentOutputFormat } from '../../../lib/beta/agents/output-format';
|
|
4
|
+
|
|
5
|
+
/** Beta: bind a synchronous Standard Schema validator to Agents output. */
|
|
6
|
+
export function standardAgentTextFormat<S extends Parameters<typeof standardTextFormat>[0]>(
|
|
7
|
+
schema: S,
|
|
8
|
+
jsonSchema?: JSONSchema,
|
|
9
|
+
) {
|
|
10
|
+
const format = standardTextFormat(schema, 'agent_output', { schema: jsonSchema });
|
|
11
|
+
// SAFETY: The native Responses helper owns Standard Schema conversion and validation.
|
|
12
|
+
return agentOutputFormat(format.schema as JSONSchema, format.$parseRaw);
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { zodTextFormat } from '../../zod';
|
|
2
|
+
import type { JSONSchema } from '../../../lib/jsonschema';
|
|
3
|
+
import { agentOutputFormat } from '../../../lib/beta/agents/output-format';
|
|
4
|
+
|
|
5
|
+
/** Beta: bind a Zod v3/v4/Mini schema to an Agents text format and completed result. */
|
|
6
|
+
export function zodAgentTextFormat<S extends Parameters<typeof zodTextFormat>[0]>(schema: S) {
|
|
7
|
+
const format = zodTextFormat(schema, 'agent_output');
|
|
8
|
+
// SAFETY: The native Responses helper owns Zod schema conversion and validation.
|
|
9
|
+
return agentOutputFormat(format.schema as JSONSchema, format.$parseRaw);
|
|
10
|
+
}
|
|
@@ -1,4 +1,44 @@
|
|
|
1
1
|
import type { OpenAI } from '../client';
|
|
2
|
+
import { assertValidBedrockBearerCredential, brand_privateBedrockClient } from './bedrock';
|
|
3
|
+
|
|
4
|
+
type CaptureAPIKey = (apiKey: string | null) => void;
|
|
5
|
+
export interface DeferredAPIKeyCache {
|
|
6
|
+
client: Pick<OpenAI, 'apiKey'>;
|
|
7
|
+
providerKey?: string;
|
|
8
|
+
commit: () => string | null;
|
|
9
|
+
}
|
|
10
|
+
interface RealtimeAPIKeyCacheContext {
|
|
11
|
+
run: <T>(cache: DeferredAPIKeyCache | undefined, operation: () => T) => T;
|
|
12
|
+
getStore: () => DeferredAPIKeyCache | undefined;
|
|
13
|
+
}
|
|
14
|
+
// Only the key crosses module formats: the context belongs to each participating client.
|
|
15
|
+
const realtimeCacheContext = Symbol.for('openai.realtimeAPIKeyCacheContext');
|
|
16
|
+
type CredentialClient = Pick<OpenAI, 'apiKey'> & {
|
|
17
|
+
[realtimeCacheContext]?: RealtimeAPIKeyCacheContext;
|
|
18
|
+
};
|
|
19
|
+
let cacheContext: RealtimeAPIKeyCacheContext | undefined;
|
|
20
|
+
|
|
21
|
+
/** Installs the Node transport's invocation context without loading Node in the base client. @internal */
|
|
22
|
+
export function setRealtimeAPIKeyCacheContext(context: RealtimeAPIKeyCacheContext): void {
|
|
23
|
+
cacheContext = context;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Reserves a deferred commit when the base hook is entered for this invocation. @internal */
|
|
27
|
+
export function getDeferredRealtimeAPIKeyCache(client: CredentialClient): DeferredAPIKeyCache | undefined {
|
|
28
|
+
const deferred = client[realtimeCacheContext]?.getStore();
|
|
29
|
+
return deferred?.client === client ? deferred : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Applies the Bedrock getter's validation when a captured credential does not enter the cache. @internal */
|
|
33
|
+
export function validateCapturedAPIKey(
|
|
34
|
+
client: Pick<OpenAI, 'apiKey'>,
|
|
35
|
+
credential: string | null,
|
|
36
|
+
): string | null {
|
|
37
|
+
if (credential !== null && brand_privateBedrockClient in client) {
|
|
38
|
+
assertValidBedrockBearerCredential(credential);
|
|
39
|
+
}
|
|
40
|
+
return credential;
|
|
41
|
+
}
|
|
2
42
|
|
|
3
43
|
/** Selects a captured credential without treating an explicit null as absent. @internal */
|
|
4
44
|
export function getRealtimeAPIKey(
|
|
@@ -15,13 +55,39 @@ export function getRealtimeAPIKey(
|
|
|
15
55
|
* synchronizing concurrent credential updates.
|
|
16
56
|
* @internal
|
|
17
57
|
*/
|
|
18
|
-
export async function resolveRealtimeAPIKey(
|
|
58
|
+
export async function resolveRealtimeAPIKey(
|
|
59
|
+
client: CredentialClient & Pick<OpenAI, '_callApiKey'>,
|
|
60
|
+
deferCache = false,
|
|
61
|
+
): Promise<{
|
|
19
62
|
apiKey: string | null;
|
|
20
63
|
isProvider: boolean;
|
|
64
|
+
commit: () => string | null;
|
|
21
65
|
}> {
|
|
22
66
|
let apiKey: string | null | undefined;
|
|
23
|
-
const
|
|
67
|
+
const current: DeferredAPIKeyCache = {
|
|
68
|
+
client,
|
|
69
|
+
commit: () => (apiKey === undefined ? client.apiKey : apiKey),
|
|
70
|
+
};
|
|
71
|
+
const capture: CaptureAPIKey = (resolved) => {
|
|
24
72
|
apiKey = resolved;
|
|
25
|
-
}
|
|
26
|
-
|
|
73
|
+
};
|
|
74
|
+
const invoke = () => client._callApiKey(capture);
|
|
75
|
+
const context = client[realtimeCacheContext] ?? cacheContext;
|
|
76
|
+
if (deferCache && context && !client[realtimeCacheContext]) {
|
|
77
|
+
Object.defineProperty(client, realtimeCacheContext, { value: context });
|
|
78
|
+
}
|
|
79
|
+
// An HTTP or ordinary Realtime request nested inside a WebSocket hook owns its own cache writes.
|
|
80
|
+
const isProvider = await (context ? context.run(deferCache ? current : undefined, invoke) : invoke());
|
|
81
|
+
return {
|
|
82
|
+
apiKey: apiKey === undefined ? client.apiKey : apiKey,
|
|
83
|
+
isProvider,
|
|
84
|
+
commit: () => {
|
|
85
|
+
const hookKey =
|
|
86
|
+
current.providerKey !== undefined && apiKey !== undefined && apiKey !== current.providerKey
|
|
87
|
+
? validateCapturedAPIKey(client, apiKey)
|
|
88
|
+
: undefined;
|
|
89
|
+
const cached = current.commit();
|
|
90
|
+
return hookKey === undefined ? validateCapturedAPIKey(client, cached) : hookKey;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
27
93
|
}
|