openai 7.24.0 → 7.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -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/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/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/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/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-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/audio/speech.d.mts +1 -1
- package/resources/audio/speech.d.ts +1 -1
- package/resources/audio/speech.js +1 -1
- package/resources/audio/speech.mjs +1 -1
- package/resources/beta/agents/agents.d.mts +574 -11
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +574 -11
- 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 +56 -3
- package/resources/beta/agents/environments/templates.d.mts.map +1 -1
- package/resources/beta/agents/environments/templates.d.ts +56 -3
- 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 +16 -12
- package/resources/beta/agents/sessions/events.d.mts.map +1 -1
- package/resources/beta/agents/sessions/events.d.ts +16 -12
- package/resources/beta/agents/sessions/events.d.ts.map +1 -1
- package/resources/beta/agents/sessions/events.js +16 -12
- package/resources/beta/agents/sessions/events.js.map +1 -1
- package/resources/beta/agents/sessions/events.mjs +16 -12
- 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/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/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/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/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/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/parse-result.ts +133 -0
- package/src/lib/beta/agents/parsed-agent-turn-result.ts +12 -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/audio/speech.ts +1 -1
- package/src/resources/beta/agents/agents.ts +697 -6
- package/src/resources/beta/agents/environments/templates.ts +64 -3
- package/src/resources/beta/agents/index.ts +3 -0
- package/src/resources/beta/agents/sessions/events.ts +16 -12
- 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/beta.ts +6 -0
- package/src/resources/beta/index.ts +3 -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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionTool = functionTool;
|
|
4
|
+
const error_1 = require("../../../core/error.js");
|
|
5
|
+
const tool_output_1 = require("./tool-output.js");
|
|
6
|
+
/**
|
|
7
|
+
* Adapts a `zodResponsesFunction` or `standardResponsesFunction` to beta Agents.
|
|
8
|
+
* Pass `definition` to `agent.tools` and register `handler` under `name` in
|
|
9
|
+
* `sessions.stream()`'s `toolHandlers`. Creating a definition does not execute it.
|
|
10
|
+
* The existing dispatcher handles callback results, failures, and submission retries.
|
|
11
|
+
* Scalar results and business-data arrays become JSON text; `undefined` becomes
|
|
12
|
+
* the text `undefined`. Supported text/image content arrays retain their format.
|
|
13
|
+
*
|
|
14
|
+
* @throws {OpenAIError} If the tool has no callback or argument schema.
|
|
15
|
+
*/
|
|
16
|
+
function functionTool(tool) {
|
|
17
|
+
const execute = tool.$callback;
|
|
18
|
+
const parse = tool.$parseRaw;
|
|
19
|
+
if (!execute || !tool.parameters) {
|
|
20
|
+
throw new error_1.OpenAIError('Agents function tools require a callback and argument schema');
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
name: tool.name,
|
|
24
|
+
definition: {
|
|
25
|
+
type: 'function',
|
|
26
|
+
name: tool.name,
|
|
27
|
+
description: tool.description ?? '',
|
|
28
|
+
parameters: tool.parameters,
|
|
29
|
+
...(tool.defer_loading === undefined ? {} : { defer_loading: tool.defer_loading }),
|
|
30
|
+
},
|
|
31
|
+
handler: async (arguments_) => {
|
|
32
|
+
const result = await execute(parse(JSON.stringify(arguments_)));
|
|
33
|
+
if (Array.isArray(result)) {
|
|
34
|
+
return result.length > 0 && result.every(tool_output_1.isInputContent) ? result : JSON.stringify(result);
|
|
35
|
+
}
|
|
36
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Existing schema-tool callbacks return arbitrary application values; adapt them to the Agents dispatcher's output contract.
|
|
37
|
+
if (typeof result === 'object' || typeof result === 'string') {
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
const text = result === undefined ? 'undefined' : JSON.stringify(result);
|
|
41
|
+
if (text === undefined) {
|
|
42
|
+
throw new error_1.OpenAIError('Tool output must be JSON serializable');
|
|
43
|
+
}
|
|
44
|
+
return text;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=function-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-tool.js","sourceRoot":"","sources":["../../../src/lib/beta/agents/function-tool.ts"],"names":[],"mappings":";;AA0BA,oCAiCC;AA3DD,kDAAkD;AAIlD,kDAA+C;AAY/C;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,IAAuE;IAEvE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC;IAC7B,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,MAAM,IAAI,mBAAW,CAAC,8DAA8D,CAAC,CAAC;IACxF,CAAC;IACD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE;YACV,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;YACnC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;SACnF;QACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;YAC5B,MAAM,MAAM,GAAY,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACzE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,4BAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7F,CAAC;YACD,qLAAqL;YACrL,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC7D,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACzE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,IAAI,mBAAW,CAAC,uCAAuC,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { OpenAIError } from "../../../core/error.mjs";
|
|
2
|
+
import { isInputContent } from "./tool-output.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Adapts a `zodResponsesFunction` or `standardResponsesFunction` to beta Agents.
|
|
5
|
+
* Pass `definition` to `agent.tools` and register `handler` under `name` in
|
|
6
|
+
* `sessions.stream()`'s `toolHandlers`. Creating a definition does not execute it.
|
|
7
|
+
* The existing dispatcher handles callback results, failures, and submission retries.
|
|
8
|
+
* Scalar results and business-data arrays become JSON text; `undefined` becomes
|
|
9
|
+
* the text `undefined`. Supported text/image content arrays retain their format.
|
|
10
|
+
*
|
|
11
|
+
* @throws {OpenAIError} If the tool has no callback or argument schema.
|
|
12
|
+
*/
|
|
13
|
+
export function functionTool(tool) {
|
|
14
|
+
const execute = tool.$callback;
|
|
15
|
+
const parse = tool.$parseRaw;
|
|
16
|
+
if (!execute || !tool.parameters) {
|
|
17
|
+
throw new OpenAIError('Agents function tools require a callback and argument schema');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
name: tool.name,
|
|
21
|
+
definition: {
|
|
22
|
+
type: 'function',
|
|
23
|
+
name: tool.name,
|
|
24
|
+
description: tool.description ?? '',
|
|
25
|
+
parameters: tool.parameters,
|
|
26
|
+
...(tool.defer_loading === undefined ? {} : { defer_loading: tool.defer_loading }),
|
|
27
|
+
},
|
|
28
|
+
handler: async (arguments_) => {
|
|
29
|
+
const result = await execute(parse(JSON.stringify(arguments_)));
|
|
30
|
+
if (Array.isArray(result)) {
|
|
31
|
+
return result.length > 0 && result.every(isInputContent) ? result : JSON.stringify(result);
|
|
32
|
+
}
|
|
33
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Existing schema-tool callbacks return arbitrary application values; adapt them to the Agents dispatcher's output contract.
|
|
34
|
+
if (typeof result === 'object' || typeof result === 'string') {
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
const text = result === undefined ? 'undefined' : JSON.stringify(result);
|
|
38
|
+
if (text === undefined) {
|
|
39
|
+
throw new OpenAIError('Tool output must be JSON serializable');
|
|
40
|
+
}
|
|
41
|
+
return text;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=function-tool.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-tool.mjs","sourceRoot":"","sources":["../../../src/lib/beta/agents/function-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAIlD,OAAO,EAAE,cAAc,EAAE,0BAAsB;AAY/C;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAuE;IAEvE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC;IAC7B,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,MAAM,IAAI,WAAW,CAAC,8DAA8D,CAAC,CAAC;IACxF,CAAC;IACD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE;YACV,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;YACnC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;SACnF;QACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;YAC5B,MAAM,MAAM,GAAY,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACzE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7F,CAAC;YACD,qLAAqL;YACrL,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC7D,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACzE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,IAAI,WAAW,CAAC,uCAAuC,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TextFormatParam } from "../../../resources/beta/agents/agents.mjs";
|
|
2
|
+
import type { AgentTurnResult } from "./agent-turn-result.mjs";
|
|
3
|
+
import type { ParsedAgentTurnResult } from "./parsed-agent-turn-result.mjs";
|
|
4
|
+
/** Beta: an Agents JSON Schema format with a local output validator. */
|
|
5
|
+
export interface AgentOutputFormat<T> extends TextFormatParam.TextFormatParamJSONSchema {
|
|
6
|
+
/** SDK-only parser; omitted from serialized requests. */
|
|
7
|
+
$parseRaw: (text: string) => T;
|
|
8
|
+
}
|
|
9
|
+
/** Beta: raw results remain unchanged unless a typed format is supplied. */
|
|
10
|
+
export type AgentResult<T> = [T] extends [never] ? AgentTurnResult : ParsedAgentTurnResult<T>;
|
|
11
|
+
//# sourceMappingURL=output-format-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format-types.d.mts","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kDAA8C;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,gCAA4B;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,uCAAmC;AAExE,wEAAwE;AACxE,MAAM,WAAW,iBAAiB,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,yBAAyB;IACrF,yDAAyD;IACzD,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;CAChC;AAED,4EAA4E;AAC5E,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,eAAe,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TextFormatParam } from "../../../resources/beta/agents/agents.js";
|
|
2
|
+
import type { AgentTurnResult } from "./agent-turn-result.js";
|
|
3
|
+
import type { ParsedAgentTurnResult } from "./parsed-agent-turn-result.js";
|
|
4
|
+
/** Beta: an Agents JSON Schema format with a local output validator. */
|
|
5
|
+
export interface AgentOutputFormat<T> extends TextFormatParam.TextFormatParamJSONSchema {
|
|
6
|
+
/** SDK-only parser; omitted from serialized requests. */
|
|
7
|
+
$parseRaw: (text: string) => T;
|
|
8
|
+
}
|
|
9
|
+
/** Beta: raw results remain unchanged unless a typed format is supplied. */
|
|
10
|
+
export type AgentResult<T> = [T] extends [never] ? AgentTurnResult : ParsedAgentTurnResult<T>;
|
|
11
|
+
//# sourceMappingURL=output-format-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format-types.d.ts","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iDAA8C;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA4B;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAmC;AAExE,wEAAwE;AACxE,MAAM,WAAW,iBAAiB,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,yBAAyB;IACrF,yDAAyD;IACzD,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;CAChC;AAED,4EAA4E;AAC5E,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,eAAe,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format-types.js","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format-types.mjs","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentOutputFormat } from "./output-format-types.mjs";
|
|
2
|
+
import type { JSONSchema } from "../../jsonschema.mjs";
|
|
3
|
+
export type { AgentOutputFormat, AgentResult } from "./output-format-types.mjs";
|
|
4
|
+
export { ParsedAgentTurnResult } from "./parsed-agent-turn-result.mjs";
|
|
5
|
+
export { AgentOutputParseError } from "./output-parse-error.mjs";
|
|
6
|
+
/** Beta: bind a JSON schema to its local output parser; the API validates schema support. */
|
|
7
|
+
export declare function agentOutputFormat<T>(schema: JSONSchema, parse: (text: string) => T): AgentOutputFormat<T>;
|
|
8
|
+
//# sourceMappingURL=output-format.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format.d.mts","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAA8B;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,6BAAyB;AAEnD,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,kCAA8B;AAE5E,OAAO,EAAE,qBAAqB,EAAE,uCAAmC;AACnE,OAAO,EAAE,qBAAqB,EAAE,iCAA6B;AAE7D,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CASzG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentOutputFormat } from "./output-format-types.js";
|
|
2
|
+
import type { JSONSchema } from "../../jsonschema.js";
|
|
3
|
+
export type { AgentOutputFormat, AgentResult } from "./output-format-types.js";
|
|
4
|
+
export { ParsedAgentTurnResult } from "./parsed-agent-turn-result.js";
|
|
5
|
+
export { AgentOutputParseError } from "./output-parse-error.js";
|
|
6
|
+
/** Beta: bind a JSON schema to its local output parser; the API validates schema support. */
|
|
7
|
+
export declare function agentOutputFormat<T>(schema: JSONSchema, parse: (text: string) => T): AgentOutputFormat<T>;
|
|
8
|
+
//# sourceMappingURL=output-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format.d.ts","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iCAA8B;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,4BAAyB;AAEnD,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,iCAA8B;AAE5E,OAAO,EAAE,qBAAqB,EAAE,sCAAmC;AACnE,OAAO,EAAE,qBAAqB,EAAE,gCAA6B;AAE7D,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CASzG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentOutputParseError = exports.ParsedAgentTurnResult = void 0;
|
|
4
|
+
exports.agentOutputFormat = agentOutputFormat;
|
|
5
|
+
var parsed_agent_turn_result_1 = require("./parsed-agent-turn-result.js");
|
|
6
|
+
Object.defineProperty(exports, "ParsedAgentTurnResult", { enumerable: true, get: function () { return parsed_agent_turn_result_1.ParsedAgentTurnResult; } });
|
|
7
|
+
var output_parse_error_1 = require("./output-parse-error.js");
|
|
8
|
+
Object.defineProperty(exports, "AgentOutputParseError", { enumerable: true, get: function () { return output_parse_error_1.AgentOutputParseError; } });
|
|
9
|
+
/** Beta: bind a JSON schema to its local output parser; the API validates schema support. */
|
|
10
|
+
function agentOutputFormat(schema, parse) {
|
|
11
|
+
// Keep spread-compatible parsing without exposing caller-owned serialization hooks.
|
|
12
|
+
const parser = Object.defineProperty((text) => parse(text), 'toJSON', {
|
|
13
|
+
value: () => {
|
|
14
|
+
/* Parser metadata is omitted from JSON requests. */
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// SAFETY: The API schema type exposes JSON Schema keywords as a record; preserve the supplied schema unchanged.
|
|
18
|
+
return { type: 'json_schema', schema: schema, $parseRaw: parser };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=output-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format.js","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format.ts"],"names":[],"mappings":";;;AAUA,8CASC;AAbD,0EAAmE;AAA1D,iIAAA,qBAAqB,OAAA;AAC9B,8DAA6D;AAApD,2HAAA,qBAAqB,OAAA;AAE9B,6FAA6F;AAC7F,SAAgB,iBAAiB,CAAI,MAAkB,EAAE,KAA0B;IACjF,oFAAoF;IACpF,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE;QAC5E,KAAK,EAAE,GAAG,EAAE;YACV,oDAAoD;QACtD,CAAC;KACF,CAAC,CAAC;IACH,gHAAgH;IAChH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAwC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { ParsedAgentTurnResult } from "./parsed-agent-turn-result.mjs";
|
|
2
|
+
export { AgentOutputParseError } from "./output-parse-error.mjs";
|
|
3
|
+
/** Beta: bind a JSON schema to its local output parser; the API validates schema support. */
|
|
4
|
+
export function agentOutputFormat(schema, parse) {
|
|
5
|
+
// Keep spread-compatible parsing without exposing caller-owned serialization hooks.
|
|
6
|
+
const parser = Object.defineProperty((text) => parse(text), 'toJSON', {
|
|
7
|
+
value: () => {
|
|
8
|
+
/* Parser metadata is omitted from JSON requests. */
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
// SAFETY: The API schema type exposes JSON Schema keywords as a record; preserve the supplied schema unchanged.
|
|
12
|
+
return { type: 'json_schema', schema: schema, $parseRaw: parser };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=output-format.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-format.mjs","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-format.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,uCAAmC;AACnE,OAAO,EAAE,qBAAqB,EAAE,iCAA6B;AAE7D,6FAA6F;AAC7F,MAAM,UAAU,iBAAiB,CAAI,MAAkB,EAAE,KAA0B;IACjF,oFAAoF;IACpF,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE;QAC5E,KAAK,EAAE,GAAG,EAAE;YACV,oDAAoD;QACtD,CAAC;KACF,CAAC,CAAC;IACH,gHAAgH;IAChH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAwC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OpenAIError } from "../../../core/error.mjs";
|
|
2
|
+
import type { AgentTurnResult } from "./agent-turn-result.mjs";
|
|
3
|
+
/** Beta: hosted execution completed, but local output parsing failed. */
|
|
4
|
+
export declare class AgentOutputParseError extends OpenAIError {
|
|
5
|
+
#private;
|
|
6
|
+
name: string;
|
|
7
|
+
constructor(result: AgentTurnResult);
|
|
8
|
+
/** Inspect the completed output explicitly; ordinary error logging omits it. */
|
|
9
|
+
get raw_result(): AgentTurnResult;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=output-parse-error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-parse-error.d.mts","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-parse-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,gCAA4B;AAE3D,yEAAyE;AACzE,qBAAa,qBAAsB,SAAQ,WAAW;;IAC3C,IAAI,SAA2B;gBAE5B,MAAM,EAAE,eAAe;IAInC,gFAAgF;IAChF,IAAI,UAAU,IAAI,eAAe,CAEhC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OpenAIError } from "../../../core/error.js";
|
|
2
|
+
import type { AgentTurnResult } from "./agent-turn-result.js";
|
|
3
|
+
/** Beta: hosted execution completed, but local output parsing failed. */
|
|
4
|
+
export declare class AgentOutputParseError extends OpenAIError {
|
|
5
|
+
#private;
|
|
6
|
+
name: string;
|
|
7
|
+
constructor(result: AgentTurnResult);
|
|
8
|
+
/** Inspect the completed output explicitly; ordinary error logging omits it. */
|
|
9
|
+
get raw_result(): AgentTurnResult;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=output-parse-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-parse-error.d.ts","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-parse-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,+BAA4B;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA4B;AAE3D,yEAAyE;AACzE,qBAAa,qBAAsB,SAAQ,WAAW;;IAC3C,IAAI,SAA2B;gBAE5B,MAAM,EAAE,eAAe;IAInC,gFAAgF;IAChF,IAAI,UAAU,IAAI,eAAe,CAEhC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _AgentOutputParseError_rawResult;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AgentOutputParseError = void 0;
|
|
5
|
+
const tslib_1 = require("../../../internal/tslib.js");
|
|
6
|
+
const error_1 = require("../../../core/error.js");
|
|
7
|
+
/** Beta: hosted execution completed, but local output parsing failed. */
|
|
8
|
+
class AgentOutputParseError extends error_1.OpenAIError {
|
|
9
|
+
constructor(result) {
|
|
10
|
+
super('The completed agent output could not be parsed');
|
|
11
|
+
this.name = 'AgentOutputParseError';
|
|
12
|
+
_AgentOutputParseError_rawResult.set(this, void 0);
|
|
13
|
+
tslib_1.__classPrivateFieldSet(this, _AgentOutputParseError_rawResult, result, "f");
|
|
14
|
+
}
|
|
15
|
+
/** Inspect the completed output explicitly; ordinary error logging omits it. */
|
|
16
|
+
get raw_result() {
|
|
17
|
+
return tslib_1.__classPrivateFieldGet(this, _AgentOutputParseError_rawResult, "f");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.AgentOutputParseError = AgentOutputParseError;
|
|
21
|
+
_AgentOutputParseError_rawResult = new WeakMap();
|
|
22
|
+
//# sourceMappingURL=output-parse-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-parse-error.js","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-parse-error.ts"],"names":[],"mappings":";;;;;AAAA,kDAAkD;AAGlD,yEAAyE;AACzE,MAAa,qBAAsB,SAAQ,mBAAW;IAGpD,YAAY,MAAuB;QACjC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAHjD,SAAI,GAAG,uBAAuB,CAAC;QAC/B,mDAA4B;QAGnC,+BAAA,IAAI,oCAAc,MAAM,MAAA,CAAC;IAC3B,CAAC;IACD,gFAAgF;IAChF,IAAI,UAAU;QACZ,OAAO,+BAAA,IAAI,wCAAW,CAAC;IACzB,CAAC;CACF;AAXD,sDAWC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var _AgentOutputParseError_rawResult;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../../../internal/tslib.mjs";
|
|
3
|
+
import { OpenAIError } from "../../../core/error.mjs";
|
|
4
|
+
/** Beta: hosted execution completed, but local output parsing failed. */
|
|
5
|
+
export class AgentOutputParseError extends OpenAIError {
|
|
6
|
+
constructor(result) {
|
|
7
|
+
super('The completed agent output could not be parsed');
|
|
8
|
+
this.name = 'AgentOutputParseError';
|
|
9
|
+
_AgentOutputParseError_rawResult.set(this, void 0);
|
|
10
|
+
__classPrivateFieldSet(this, _AgentOutputParseError_rawResult, result, "f");
|
|
11
|
+
}
|
|
12
|
+
/** Inspect the completed output explicitly; ordinary error logging omits it. */
|
|
13
|
+
get raw_result() {
|
|
14
|
+
return __classPrivateFieldGet(this, _AgentOutputParseError_rawResult, "f");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
_AgentOutputParseError_rawResult = new WeakMap();
|
|
18
|
+
//# sourceMappingURL=output-parse-error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-parse-error.mjs","sourceRoot":"","sources":["../../../src/lib/beta/agents/output-parse-error.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAGlD,yEAAyE;AACzE,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IAGpD,YAAY,MAAuB;QACjC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAHjD,SAAI,GAAG,uBAAuB,CAAC;QAC/B,mDAA4B;QAGnC,uBAAA,IAAI,oCAAc,MAAM,MAAA,CAAC;IAC3B,CAAC;IACD,gFAAgF;IAChF,IAAI,UAAU;QACZ,OAAO,uBAAA,IAAI,wCAAW,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { RequestOptions } from "../../../internal/request-options.mjs";
|
|
2
|
+
import type { SessionCreateParams } from "../../../resources/beta/agents/sessions/sessions.mjs";
|
|
3
|
+
import type { AgentTurnResult } from "./agent-turn-result.mjs";
|
|
4
|
+
import type { TextFormatParam } from "../../../resources/beta/agents/agents.mjs";
|
|
5
|
+
import type { AgentOutputFormat, AgentResult } from "./output-format-types.mjs";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare function parseAgentResult<T>(result: AgentTurnResult, format?: AgentOutputFormat<T>): AgentResult<T>;
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function agentFormatParser<T = unknown>(format: TextFormatParam | null | undefined): AgentOutputFormat<T> | undefined;
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function captureAgentOutput(input: SessionCreateParams, options?: RequestOptions): {
|
|
12
|
+
body: SessionCreateParams;
|
|
13
|
+
options: RequestOptions | undefined;
|
|
14
|
+
format?: never;
|
|
15
|
+
} | {
|
|
16
|
+
options: {
|
|
17
|
+
method?: import("../../../internal/types.mjs").HTTPMethod;
|
|
18
|
+
path?: string;
|
|
19
|
+
query?: object | undefined | null;
|
|
20
|
+
body?: unknown;
|
|
21
|
+
headers?: import("../../../internal/headers.mjs").HeadersLike;
|
|
22
|
+
maxRetries?: number;
|
|
23
|
+
stream?: boolean | undefined;
|
|
24
|
+
timeout?: number;
|
|
25
|
+
fetchOptions?: import("../../../internal/types.mjs").MergedRequestInit;
|
|
26
|
+
signal?: AbortSignal | undefined | null;
|
|
27
|
+
idempotencyKey?: string;
|
|
28
|
+
defaultBaseURL?: string | undefined;
|
|
29
|
+
__metadata?: Record<string, unknown>;
|
|
30
|
+
__security?: {
|
|
31
|
+
bearerAuth?: boolean;
|
|
32
|
+
adminAPIKeyAuth?: boolean;
|
|
33
|
+
};
|
|
34
|
+
__binaryResponse?: boolean | undefined;
|
|
35
|
+
__streamClass?: typeof import("../../../streaming.mjs").Stream;
|
|
36
|
+
__synthesizeEventData?: boolean;
|
|
37
|
+
};
|
|
38
|
+
body: {
|
|
39
|
+
agent: {
|
|
40
|
+
text: {
|
|
41
|
+
format: {
|
|
42
|
+
type: string;
|
|
43
|
+
schema: {
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
verbosity?: "low" | "medium" | "high" | null;
|
|
48
|
+
};
|
|
49
|
+
instructions?: string | null;
|
|
50
|
+
model?: string;
|
|
51
|
+
multi_agent?: import("../../../resources/beta.mjs").MultiAgentConfigParam | null;
|
|
52
|
+
reasoning?: import("../../../resources/beta.mjs").AgentReasoningParam | null;
|
|
53
|
+
service_tier?: "auto" | "default" | "flex" | "priority" | "fast" | "ultrafast" | null;
|
|
54
|
+
tools?: Array<import("../../../resources/beta.mjs").AgentToolParam> | null;
|
|
55
|
+
};
|
|
56
|
+
stream?: false;
|
|
57
|
+
environment: import("../../../resources/beta.mjs").EnvironmentParam;
|
|
58
|
+
agent_id?: string;
|
|
59
|
+
input?: string | Array<import("../../../resources/beta.mjs").AgentSessionInputMessageParam> | null;
|
|
60
|
+
metadata?: {
|
|
61
|
+
[key: string]: string;
|
|
62
|
+
} | null;
|
|
63
|
+
vault_ids?: Array<string> | null;
|
|
64
|
+
} | {
|
|
65
|
+
agent: {
|
|
66
|
+
text: {
|
|
67
|
+
format: {
|
|
68
|
+
type: string;
|
|
69
|
+
schema: {
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
verbosity?: "low" | "medium" | "high" | null;
|
|
74
|
+
};
|
|
75
|
+
instructions?: string | null;
|
|
76
|
+
model?: string;
|
|
77
|
+
multi_agent?: import("../../../resources/beta.mjs").MultiAgentConfigParam | null;
|
|
78
|
+
reasoning?: import("../../../resources/beta.mjs").AgentReasoningParam | null;
|
|
79
|
+
service_tier?: "auto" | "default" | "flex" | "priority" | "fast" | "ultrafast" | null;
|
|
80
|
+
tools?: Array<import("../../../resources/beta.mjs").AgentToolParam> | null;
|
|
81
|
+
};
|
|
82
|
+
stream: true;
|
|
83
|
+
environment: import("../../../resources/beta.mjs").EnvironmentParam;
|
|
84
|
+
agent_id?: string;
|
|
85
|
+
input?: string | Array<import("../../../resources/beta.mjs").AgentSessionInputMessageParam> | null;
|
|
86
|
+
metadata?: {
|
|
87
|
+
[key: string]: string;
|
|
88
|
+
} | null;
|
|
89
|
+
vault_ids?: Array<string> | null;
|
|
90
|
+
};
|
|
91
|
+
format: AgentOutputFormat<unknown>;
|
|
92
|
+
};
|
|
93
|
+
/** @internal */
|
|
94
|
+
export declare function parseAgentResultPromise<T>(result: Promise<AgentTurnResult>, format?: AgentOutputFormat<T>): Promise<AgentResult<T>>;
|
|
95
|
+
//# sourceMappingURL=parse-result.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-result.d.mts","sourceRoot":"","sources":["../../../src/lib/beta/agents/parse-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8CAA0C;AAExE,OAAO,KAAK,EAAE,mBAAmB,EAAE,6DAAyD;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,gCAA4B;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,kDAA8C;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,kCAA8B;AAI5E,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAuB1G;AAYD,gBAAgB;AAChB,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAC3C,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GACzC,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAiBlC;AAuBD,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;sBAzClE,CAAC;2BACZ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2EV;AAED,gBAAgB;AAChB,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,EAChC,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAEzB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { RequestOptions } from "../../../internal/request-options.js";
|
|
2
|
+
import type { SessionCreateParams } from "../../../resources/beta/agents/sessions/sessions.js";
|
|
3
|
+
import type { AgentTurnResult } from "./agent-turn-result.js";
|
|
4
|
+
import type { TextFormatParam } from "../../../resources/beta/agents/agents.js";
|
|
5
|
+
import type { AgentOutputFormat, AgentResult } from "./output-format-types.js";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare function parseAgentResult<T>(result: AgentTurnResult, format?: AgentOutputFormat<T>): AgentResult<T>;
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function agentFormatParser<T = unknown>(format: TextFormatParam | null | undefined): AgentOutputFormat<T> | undefined;
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function captureAgentOutput(input: SessionCreateParams, options?: RequestOptions): {
|
|
12
|
+
body: SessionCreateParams;
|
|
13
|
+
options: RequestOptions | undefined;
|
|
14
|
+
format?: never;
|
|
15
|
+
} | {
|
|
16
|
+
options: {
|
|
17
|
+
method?: import("../../../internal/types.js").HTTPMethod;
|
|
18
|
+
path?: string;
|
|
19
|
+
query?: object | undefined | null;
|
|
20
|
+
body?: unknown;
|
|
21
|
+
headers?: import("../../../internal/headers.js").HeadersLike;
|
|
22
|
+
maxRetries?: number;
|
|
23
|
+
stream?: boolean | undefined;
|
|
24
|
+
timeout?: number;
|
|
25
|
+
fetchOptions?: import("../../../internal/types.js").MergedRequestInit;
|
|
26
|
+
signal?: AbortSignal | undefined | null;
|
|
27
|
+
idempotencyKey?: string;
|
|
28
|
+
defaultBaseURL?: string | undefined;
|
|
29
|
+
__metadata?: Record<string, unknown>;
|
|
30
|
+
__security?: {
|
|
31
|
+
bearerAuth?: boolean;
|
|
32
|
+
adminAPIKeyAuth?: boolean;
|
|
33
|
+
};
|
|
34
|
+
__binaryResponse?: boolean | undefined;
|
|
35
|
+
__streamClass?: typeof import("../../../streaming.js").Stream;
|
|
36
|
+
__synthesizeEventData?: boolean;
|
|
37
|
+
};
|
|
38
|
+
body: {
|
|
39
|
+
agent: {
|
|
40
|
+
text: {
|
|
41
|
+
format: {
|
|
42
|
+
type: string;
|
|
43
|
+
schema: {
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
verbosity?: "low" | "medium" | "high" | null;
|
|
48
|
+
};
|
|
49
|
+
instructions?: string | null;
|
|
50
|
+
model?: string;
|
|
51
|
+
multi_agent?: import("../../../resources/beta.js").MultiAgentConfigParam | null;
|
|
52
|
+
reasoning?: import("../../../resources/beta.js").AgentReasoningParam | null;
|
|
53
|
+
service_tier?: "auto" | "default" | "flex" | "priority" | "fast" | "ultrafast" | null;
|
|
54
|
+
tools?: Array<import("../../../resources/beta.js").AgentToolParam> | null;
|
|
55
|
+
};
|
|
56
|
+
stream?: false;
|
|
57
|
+
environment: import("../../../resources/beta.js").EnvironmentParam;
|
|
58
|
+
agent_id?: string;
|
|
59
|
+
input?: string | Array<import("../../../resources/beta.js").AgentSessionInputMessageParam> | null;
|
|
60
|
+
metadata?: {
|
|
61
|
+
[key: string]: string;
|
|
62
|
+
} | null;
|
|
63
|
+
vault_ids?: Array<string> | null;
|
|
64
|
+
} | {
|
|
65
|
+
agent: {
|
|
66
|
+
text: {
|
|
67
|
+
format: {
|
|
68
|
+
type: string;
|
|
69
|
+
schema: {
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
verbosity?: "low" | "medium" | "high" | null;
|
|
74
|
+
};
|
|
75
|
+
instructions?: string | null;
|
|
76
|
+
model?: string;
|
|
77
|
+
multi_agent?: import("../../../resources/beta.js").MultiAgentConfigParam | null;
|
|
78
|
+
reasoning?: import("../../../resources/beta.js").AgentReasoningParam | null;
|
|
79
|
+
service_tier?: "auto" | "default" | "flex" | "priority" | "fast" | "ultrafast" | null;
|
|
80
|
+
tools?: Array<import("../../../resources/beta.js").AgentToolParam> | null;
|
|
81
|
+
};
|
|
82
|
+
stream: true;
|
|
83
|
+
environment: import("../../../resources/beta.js").EnvironmentParam;
|
|
84
|
+
agent_id?: string;
|
|
85
|
+
input?: string | Array<import("../../../resources/beta.js").AgentSessionInputMessageParam> | null;
|
|
86
|
+
metadata?: {
|
|
87
|
+
[key: string]: string;
|
|
88
|
+
} | null;
|
|
89
|
+
vault_ids?: Array<string> | null;
|
|
90
|
+
};
|
|
91
|
+
format: AgentOutputFormat<unknown>;
|
|
92
|
+
};
|
|
93
|
+
/** @internal */
|
|
94
|
+
export declare function parseAgentResultPromise<T>(result: Promise<AgentTurnResult>, format?: AgentOutputFormat<T>): Promise<AgentResult<T>>;
|
|
95
|
+
//# sourceMappingURL=parse-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-result.d.ts","sourceRoot":"","sources":["../../../src/lib/beta/agents/parse-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,6CAA0C;AAExE,OAAO,KAAK,EAAE,mBAAmB,EAAE,4DAAyD;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA4B;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,iDAA8C;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,iCAA8B;AAI5E,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAuB1G;AAYD,gBAAgB;AAChB,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAC3C,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GACzC,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAiBlC;AAuBD,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;sBAzClE,CAAC;2BACZ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2EV;AAED,gBAAgB;AAChB,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,EAChC,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAEzB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAgentResult = parseAgentResult;
|
|
4
|
+
exports.agentFormatParser = agentFormatParser;
|
|
5
|
+
exports.captureAgentOutput = captureAgentOutput;
|
|
6
|
+
exports.parseAgentResultPromise = parseAgentResultPromise;
|
|
7
|
+
const error_1 = require("../../../core/error.js");
|
|
8
|
+
const parsed_agent_turn_result_1 = require("./parsed-agent-turn-result.js");
|
|
9
|
+
const output_parse_error_1 = require("./output-parse-error.js");
|
|
10
|
+
/** @internal */
|
|
11
|
+
function parseAgentResult(result, format) {
|
|
12
|
+
try {
|
|
13
|
+
if (!format) {
|
|
14
|
+
// SAFETY: Absent formats use the default never/raw overload.
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
let first;
|
|
18
|
+
for (const message of result.messages) {
|
|
19
|
+
for (const content of message.content) {
|
|
20
|
+
if (content.type === 'output_text') {
|
|
21
|
+
const value = format.$parseRaw(content.text);
|
|
22
|
+
first ?? (first = { value });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!first) {
|
|
27
|
+
throw new output_parse_error_1.AgentOutputParseError(result);
|
|
28
|
+
}
|
|
29
|
+
// SAFETY: Callers preserve the format's inferred T.
|
|
30
|
+
return new parsed_agent_turn_result_1.ParsedAgentTurnResult(result, first.value);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new output_parse_error_1.AgentOutputParseError(result);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Inspect only JSON-visible data fields; leave getters and inherited values to normal serialization.
|
|
37
|
+
function ownJSONValue(object, key) {
|
|
38
|
+
const descriptor = object && Object.getOwnPropertyDescriptor(object, key);
|
|
39
|
+
// SAFETY: The own data descriptor corresponds to the requested property in T.
|
|
40
|
+
return descriptor?.enumerable && 'value' in descriptor ? descriptor.value : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
function agentFormatParser(format) {
|
|
44
|
+
if (!format) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const descriptor = Object.getOwnPropertyDescriptor(format, '$parseRaw');
|
|
48
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- An own parser data property is the explicit opt-in marker.
|
|
49
|
+
if (!descriptor || !('value' in descriptor) || typeof descriptor.value !== 'function') {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
// SAFETY: Inspect the schema data descriptor without evaluating a caller getter; validate its discriminator below.
|
|
53
|
+
const schema = ownJSONValue(format, 'schema');
|
|
54
|
+
if (ownJSONValue(format, 'type') !== 'json_schema' || !schema) {
|
|
55
|
+
throw new error_1.OpenAIError('Typed agent formats require own enumerable type and schema data properties');
|
|
56
|
+
}
|
|
57
|
+
// SAFETY: The own descriptor was checked for a callable parser; retain its receiver and never reread the property.
|
|
58
|
+
const parse = descriptor.value;
|
|
59
|
+
return { type: 'json_schema', schema, $parseRaw: (text) => parse.call(format, text) };
|
|
60
|
+
}
|
|
61
|
+
// Materialize JSON-visible envelope getters once without evaluating unrelated properties.
|
|
62
|
+
function snapshotJSONProperty(object, key, capture = (value) => value) {
|
|
63
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
64
|
+
if (!descriptor?.enumerable) {
|
|
65
|
+
return object;
|
|
66
|
+
}
|
|
67
|
+
const value = capture(object[key]);
|
|
68
|
+
if ('value' in descriptor && value === descriptor.value) {
|
|
69
|
+
return object;
|
|
70
|
+
}
|
|
71
|
+
// SAFETY: Preserve the original properties/prototype, replacing only this captured property's value.
|
|
72
|
+
return Object.create(Object.getPrototypeOf(object), {
|
|
73
|
+
...Object.getOwnPropertyDescriptors(object),
|
|
74
|
+
[key]: { value, enumerable: true, configurable: descriptor.configurable, writable: true },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** @internal */
|
|
78
|
+
function captureAgentOutput(input, options) {
|
|
79
|
+
const body = snapshotJSONProperty(input, 'agent', (agent) => agent
|
|
80
|
+
? snapshotJSONProperty(agent, 'text', (text) => (text ? snapshotJSONProperty(text, 'format') : text))
|
|
81
|
+
: agent);
|
|
82
|
+
const agent = ownJSONValue(body, 'agent');
|
|
83
|
+
const text = ownJSONValue(agent, 'text');
|
|
84
|
+
const format = agentFormatParser(ownJSONValue(text, 'format'));
|
|
85
|
+
if (!format) {
|
|
86
|
+
return { body, options };
|
|
87
|
+
}
|
|
88
|
+
const schema = structuredClone(format.schema);
|
|
89
|
+
for (const envelope of [body, agent, text]) {
|
|
90
|
+
if (envelope && 'toJSON' in envelope) {
|
|
91
|
+
throw new error_1.OpenAIError('Typed agent requests cannot customize body, agent, or text serialization');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Snapshot options once, matching the own enumerable fields native request spreading uses.
|
|
95
|
+
const capturedOptions = { ...options };
|
|
96
|
+
if (ownJSONValue(capturedOptions, 'body') !== undefined) {
|
|
97
|
+
throw new error_1.OpenAIError('Typed agent requests cannot override the body in request options');
|
|
98
|
+
}
|
|
99
|
+
delete capturedOptions.body;
|
|
100
|
+
return {
|
|
101
|
+
options: capturedOptions,
|
|
102
|
+
body: {
|
|
103
|
+
...body,
|
|
104
|
+
agent: {
|
|
105
|
+
...agent,
|
|
106
|
+
text: { ...text, format: { type: 'json_schema', schema } },
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
format,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** @internal */
|
|
113
|
+
async function parseAgentResultPromise(result, format) {
|
|
114
|
+
return parseAgentResult(await result, format);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=parse-result.js.map
|