@deepstrike/sdk 0.2.52 → 0.2.60
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/README.md +28 -28
- package/dist/agent-ir.d.ts +103 -0
- package/dist/agent-ir.js +134 -0
- package/dist/agent.d.ts +67 -0
- package/dist/agent.js +36 -0
- package/dist/collaboration/harness.js +1 -1
- package/dist/collaboration/modes/creator-verifier.d.ts +2 -7
- package/dist/collaboration/modes/creator-verifier.js +4 -6
- package/dist/collaboration/pool.d.ts +8 -20
- package/dist/collaboration/pool.js +27 -97
- package/dist/compat/anthropic/mcp.d.ts +15 -0
- package/dist/compat/anthropic/mcp.js +10 -0
- package/dist/compat/openai/agent.d.ts +34 -0
- package/dist/compat/openai/agent.js +24 -0
- package/dist/governance.d.ts +1 -17
- package/dist/governance.js +1 -34
- package/dist/guardrail.d.ts +6 -0
- package/dist/guardrail.js +1 -0
- package/dist/handoff-target.d.ts +12 -0
- package/dist/handoff-target.js +1 -0
- package/dist/harness/manifest.js +0 -4
- package/dist/index.d.ts +19 -7
- package/dist/index.js +8 -5
- package/dist/kernel.d.ts +2 -20
- package/dist/knowledge/public.d.ts +29 -0
- package/dist/knowledge/public.js +1 -0
- package/dist/mcp-server.d.ts +28 -0
- package/dist/mcp-server.js +1 -0
- package/dist/memory/agent.d.ts +2 -2
- package/dist/memory/agent.js +2 -2
- package/dist/memory/durable.d.ts +16 -0
- package/dist/memory/durable.js +46 -0
- package/dist/memory/in-memory-store.d.ts +9 -7
- package/dist/memory/in-memory-store.js +8 -2
- package/dist/memory/protocols.d.ts +22 -4
- package/dist/memory/public.d.ts +4 -3
- package/dist/memory/public.js +3 -2
- package/dist/providers/anthropic-adapter.d.ts +47 -0
- package/dist/providers/anthropic-adapter.js +444 -0
- package/dist/providers/anthropic-compatible.d.ts +2 -3
- package/dist/providers/anthropic-compatible.js +8 -5
- package/dist/providers/anthropic.d.ts +19 -23
- package/dist/providers/anthropic.js +169 -395
- package/dist/providers/base.js +43 -3
- package/dist/providers/capability-router.d.ts +29 -0
- package/dist/providers/capability-router.js +43 -0
- package/dist/providers/catalog.d.ts +16 -4
- package/dist/providers/catalog.js +112 -21
- package/dist/providers/content-normalization.d.ts +57 -0
- package/dist/providers/content-normalization.js +238 -0
- package/dist/providers/content-policy.d.ts +16 -0
- package/dist/providers/content-policy.js +39 -0
- package/dist/providers/credentials.d.ts +83 -0
- package/dist/providers/credentials.js +190 -0
- package/dist/providers/endpoints.d.ts +137 -0
- package/dist/providers/endpoints.js +128 -0
- package/dist/providers/factories.js +9 -3
- package/dist/providers/gemini-adapter.d.ts +33 -0
- package/dist/providers/gemini-adapter.js +272 -0
- package/dist/providers/gemini.d.ts +16 -3
- package/dist/providers/gemini.js +97 -195
- package/dist/providers/model-catalog.d.ts +37 -0
- package/dist/providers/model-catalog.js +62 -0
- package/dist/providers/model-registry.d.ts +98 -0
- package/dist/providers/model-registry.js +315 -0
- package/dist/providers/ollama-adapter.d.ts +65 -0
- package/dist/providers/ollama-adapter.js +188 -0
- package/dist/providers/ollama.d.ts +9 -4
- package/dist/providers/ollama.js +96 -109
- package/dist/providers/openai-chat-dialects.d.ts +154 -0
- package/dist/providers/openai-chat-dialects.js +179 -0
- package/dist/providers/openai-chat.d.ts +46 -18
- package/dist/providers/openai-chat.js +418 -51
- package/dist/providers/openai-responses-adapter.d.ts +42 -0
- package/dist/providers/openai-responses-adapter.js +341 -0
- package/dist/providers/openai-responses.d.ts +14 -33
- package/dist/providers/openai-responses.js +131 -264
- package/dist/providers/openai.d.ts +29 -76
- package/dist/providers/openai.js +195 -292
- package/dist/providers/protocol-adapter.d.ts +34 -0
- package/dist/providers/protocol-adapter.js +9 -0
- package/dist/providers/protocol-capabilities.d.ts +34 -0
- package/dist/providers/protocol-capabilities.js +44 -0
- package/dist/providers/provider-error.d.ts +31 -0
- package/dist/providers/provider-error.js +149 -0
- package/dist/providers/public.d.ts +26 -3
- package/dist/providers/public.js +13 -1
- package/dist/providers/registry.d.ts +7 -6
- package/dist/providers/registry.js +47 -20
- package/dist/providers/request-plan.d.ts +86 -0
- package/dist/providers/request-plan.js +175 -0
- package/dist/providers/usage-normalizer.d.ts +48 -0
- package/dist/providers/usage-normalizer.js +96 -0
- package/dist/providers/vendor-profiles.d.ts +2 -15
- package/dist/providers/vendor-profiles.js +14 -60
- package/dist/runtime/canonical-kernel-step.d.ts +1 -2
- package/dist/runtime/canonical-kernel-step.js +47 -12
- package/dist/runtime/context-policy.d.ts +10 -12
- package/dist/runtime/context-policy.js +6 -8
- package/dist/runtime/durable-content.d.ts +50 -0
- package/dist/runtime/durable-content.js +159 -0
- package/dist/runtime/execution-plane.d.ts +2 -2
- package/dist/runtime/execution-plane.js +2 -2
- package/dist/runtime/kernel-event-log.js +0 -1
- package/dist/runtime/kernel-step.d.ts +0 -1
- package/dist/runtime/kernel-step.js +4 -2
- package/dist/runtime/mcp-proxy-plane.d.ts +25 -1
- package/dist/runtime/mcp-proxy-plane.js +44 -6
- package/dist/runtime/output-schema.d.ts +1 -2
- package/dist/runtime/provider-replay.d.ts +1 -1
- package/dist/runtime/provider-replay.js +12 -27
- package/dist/runtime/reactive-session.d.ts +1 -1
- package/dist/runtime/reactive-session.js +2 -3
- package/dist/runtime/run-group.d.ts +1 -1
- package/dist/runtime/runner.d.ts +26 -40
- package/dist/runtime/runner.js +145 -63
- package/dist/runtime/session-log.d.ts +8 -1
- package/dist/runtime/session-log.js +42 -2
- package/dist/runtime/session-repair.d.ts +1 -1
- package/dist/runtime/session-repair.js +1 -1
- package/dist/runtime/sub-agent-orchestrator.d.ts +1 -1
- package/dist/runtime/sub-agent-orchestrator.js +8 -11
- package/dist/runtime/workflow-control-flow.d.ts +0 -4
- package/dist/runtime/workflow-control-flow.js +0 -16
- package/dist/session.d.ts +11 -0
- package/dist/session.js +1 -0
- package/dist/skill.d.ts +17 -0
- package/dist/skill.js +16 -0
- package/dist/skills/loader.d.ts +3 -0
- package/dist/tools/errors.d.ts +1 -3
- package/dist/tools/errors.js +1 -3
- package/dist/tools/index.d.ts +3 -0
- package/dist/types/agent.d.ts +21 -9
- package/dist/types/agent.js +30 -4
- package/dist/types.d.ts +128 -13
- package/package.json +3 -3
- package/dist/providers/deepseek.d.ts +0 -46
- package/dist/providers/deepseek.js +0 -97
- package/dist/providers/glm.d.ts +0 -25
- package/dist/providers/glm.js +0 -48
- package/dist/providers/kimi.d.ts +0 -23
- package/dist/providers/kimi.js +0 -30
- package/dist/providers/minimax.d.ts +0 -49
- package/dist/providers/minimax.js +0 -98
- package/dist/providers/profiles.d.ts +0 -1992
- package/dist/providers/profiles.js +0 -796
- package/dist/providers/qwen.d.ts +0 -38
- package/dist/providers/qwen.js +0 -97
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { normalizeCanonicalContext } from "./content-normalization.js";
|
|
2
|
+
import { normalizeToolCall, UnsupportedModalityError } from "./base.js";
|
|
3
|
+
import { ProtocolResponseError, } from "./protocol-adapter.js";
|
|
4
|
+
import { OPENAI_RESPONSES_PROTOCOL_CAPABILITIES } from "./protocol-capabilities.js";
|
|
5
|
+
function numberField(raw, field) {
|
|
6
|
+
const value = raw[field];
|
|
7
|
+
if (value === undefined || value === null)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
10
|
+
throw new ProtocolResponseError("openai-responses", `usage.${field} must be a non-negative finite number`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function cacheReadTokens(usage) {
|
|
15
|
+
const inputDetails = usage.input_tokens_details;
|
|
16
|
+
if (inputDetails === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (!inputDetails || typeof inputDetails !== "object" || Array.isArray(inputDetails)) {
|
|
19
|
+
throw new ProtocolResponseError("openai-responses", "usage.input_tokens_details must be an object");
|
|
20
|
+
}
|
|
21
|
+
return numberField(inputDetails, "cached_tokens");
|
|
22
|
+
}
|
|
23
|
+
function toolResultOutput(result) {
|
|
24
|
+
const output = [];
|
|
25
|
+
for (const block of result.blocks) {
|
|
26
|
+
if (block.type === "text") {
|
|
27
|
+
output.push({ type: "input_text", text: block.text });
|
|
28
|
+
}
|
|
29
|
+
else if (block.type === "image") {
|
|
30
|
+
if (block.source.kind === "base64") {
|
|
31
|
+
output.push({
|
|
32
|
+
type: "input_image",
|
|
33
|
+
image_url: `data:${block.mediaType ?? "image/png"};base64,${block.source.data}`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else if (block.source.kind === "url") {
|
|
37
|
+
output.push({ type: "input_image", image_url: block.source.url });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
output.push({ type: "input_text", text: "[image]" });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
output.push({ type: "input_text", text: `[${block.type}]` });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result.contentForm !== "blocks" && output.length === 1 && output[0].type === "input_text"
|
|
48
|
+
? String(output[0].text ?? "")
|
|
49
|
+
: output;
|
|
50
|
+
}
|
|
51
|
+
function messageContent(message) {
|
|
52
|
+
const content = [];
|
|
53
|
+
for (const block of message.blocks) {
|
|
54
|
+
if (block.type === "tool_result")
|
|
55
|
+
continue;
|
|
56
|
+
if (block.type === "text") {
|
|
57
|
+
content.push({ type: "input_text", text: block.text });
|
|
58
|
+
}
|
|
59
|
+
else if (block.type === "image") {
|
|
60
|
+
const imageUrl = block.source.kind === "url"
|
|
61
|
+
? block.source.url
|
|
62
|
+
: block.source.kind === "base64"
|
|
63
|
+
? `data:${block.mediaType ?? "image/png"};base64,${block.source.data}`
|
|
64
|
+
: undefined;
|
|
65
|
+
if (imageUrl) {
|
|
66
|
+
content.push({
|
|
67
|
+
type: "input_image",
|
|
68
|
+
detail: String(block.providerOptions?.openai_detail ?? "auto"),
|
|
69
|
+
image_url: imageUrl,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (block.type === "file") {
|
|
74
|
+
if (block.source.kind === "fileId") {
|
|
75
|
+
content.push({ type: "input_file", file_id: block.source.id });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new UnsupportedModalityError("file source", "openai-responses");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (block.type === "audio") {
|
|
82
|
+
throw new UnsupportedModalityError("audio", "openai-responses");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return message.contentForm !== "blocks" && content.length === 1 && content[0].type === "input_text"
|
|
86
|
+
? String(content[0].text ?? "")
|
|
87
|
+
: content;
|
|
88
|
+
}
|
|
89
|
+
function hasMessageContent(message) {
|
|
90
|
+
return message.blocks.some(block => block.type !== "tool_result" && (block.type !== "text" || block.text.length > 0));
|
|
91
|
+
}
|
|
92
|
+
function appendMessage(input, message) {
|
|
93
|
+
if (message.role === "assistant" && message.toolCalls?.length) {
|
|
94
|
+
if (hasMessageContent(message)) {
|
|
95
|
+
input.push({ role: "assistant", content: messageContent(message) });
|
|
96
|
+
}
|
|
97
|
+
for (const call of message.toolCalls) {
|
|
98
|
+
input.push({
|
|
99
|
+
type: "function_call",
|
|
100
|
+
call_id: call.id,
|
|
101
|
+
name: call.name,
|
|
102
|
+
arguments: call.arguments,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (message.role === "tool") {
|
|
108
|
+
for (const block of message.blocks) {
|
|
109
|
+
if (block.type !== "tool_result")
|
|
110
|
+
continue;
|
|
111
|
+
input.push({
|
|
112
|
+
type: "function_call_output",
|
|
113
|
+
call_id: block.callId,
|
|
114
|
+
output: toolResultOutput(block),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
input.push({ role: message.role, content: messageContent(message) });
|
|
120
|
+
}
|
|
121
|
+
function canonicalInputItems(context, state) {
|
|
122
|
+
const input = [];
|
|
123
|
+
const turns = state?.previousResponseId
|
|
124
|
+
? context.turns.slice(state.coveredMessageCount)
|
|
125
|
+
: context.turns;
|
|
126
|
+
for (const message of turns)
|
|
127
|
+
appendMessage(input, message);
|
|
128
|
+
if (context.stateTurn)
|
|
129
|
+
appendMessage(input, context.stateTurn);
|
|
130
|
+
return input;
|
|
131
|
+
}
|
|
132
|
+
function requestExtensions(extensions) {
|
|
133
|
+
const blocked = new Set([
|
|
134
|
+
"model", "input", "instructions", "tools", "stream", "previous_response_id",
|
|
135
|
+
"web_search", "builtin_tools", "__deepstrikeThinkingEnabled", "degradeMissingReasoningReplay",
|
|
136
|
+
]);
|
|
137
|
+
return Object.fromEntries(Object.entries(extensions).filter(([key]) => !blocked.has(key)));
|
|
138
|
+
}
|
|
139
|
+
function builtinTools(extensions) {
|
|
140
|
+
const output = [];
|
|
141
|
+
if (extensions.web_search) {
|
|
142
|
+
output.push(typeof extensions.web_search === "object"
|
|
143
|
+
? { type: "web_search", ...extensions.web_search }
|
|
144
|
+
: { type: "web_search" });
|
|
145
|
+
}
|
|
146
|
+
if (Array.isArray(extensions.builtin_tools)) {
|
|
147
|
+
output.push(...extensions.builtin_tools);
|
|
148
|
+
}
|
|
149
|
+
return output;
|
|
150
|
+
}
|
|
151
|
+
function decodeOutput(output) {
|
|
152
|
+
let content = "";
|
|
153
|
+
const toolCalls = [];
|
|
154
|
+
for (const item of output) {
|
|
155
|
+
if (item.type === "message") {
|
|
156
|
+
for (const part of item.content ?? []) {
|
|
157
|
+
if (part.type === "output_text")
|
|
158
|
+
content += String(part.text ?? "");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (item.type === "function_call") {
|
|
162
|
+
const call = normalizeToolCall(String(item.call_id ?? item.id ?? ""), String(item.name ?? ""), item.arguments ?? "{}");
|
|
163
|
+
if (call)
|
|
164
|
+
toolCalls.push(call);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return { content, toolCalls };
|
|
168
|
+
}
|
|
169
|
+
export class OpenAIResponsesAdapter {
|
|
170
|
+
protocol = "openai-responses";
|
|
171
|
+
protocolCapabilities = OPENAI_RESPONSES_PROTOCOL_CAPABILITIES;
|
|
172
|
+
buildRequest(input, state) {
|
|
173
|
+
const functionTools = this.buildTools(input.tools);
|
|
174
|
+
const tools = [...functionTools, ...builtinTools(input.extensions)];
|
|
175
|
+
return {
|
|
176
|
+
params: {
|
|
177
|
+
...requestExtensions(input.extensions),
|
|
178
|
+
model: input.resolved.identity.modelId,
|
|
179
|
+
input: canonicalInputItems(input.context, state),
|
|
180
|
+
...(input.context.systemText ? { instructions: input.context.systemText } : {}),
|
|
181
|
+
...(state?.previousResponseId ? { previous_response_id: state.previousResponseId } : {}),
|
|
182
|
+
...(tools.length ? { tools } : {}),
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
decodeComplete(raw, _input) {
|
|
187
|
+
const decoded = decodeOutput(raw.output ?? []);
|
|
188
|
+
const usage = raw.usage && typeof raw.usage === "object"
|
|
189
|
+
? raw.usage
|
|
190
|
+
: undefined;
|
|
191
|
+
if (usage)
|
|
192
|
+
this.normalizeUsage(usage);
|
|
193
|
+
const tokenCount = usage
|
|
194
|
+
? numberField(usage, "output_tokens") ?? numberField(usage, "total_tokens")
|
|
195
|
+
: undefined;
|
|
196
|
+
return {
|
|
197
|
+
message: {
|
|
198
|
+
role: "assistant",
|
|
199
|
+
content: decoded.content,
|
|
200
|
+
toolCalls: decoded.toolCalls,
|
|
201
|
+
...(tokenCount !== undefined ? { tokenCount } : {}),
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
createStreamState(input, _state) {
|
|
206
|
+
return { input: input.input, functionCalls: new Map() };
|
|
207
|
+
}
|
|
208
|
+
pushStreamChunk(chunk, state) {
|
|
209
|
+
const events = [];
|
|
210
|
+
let runStatePatch;
|
|
211
|
+
if (chunk.type === "response.output_text.delta") {
|
|
212
|
+
events.push({ type: "text_delta", delta: chunk.delta });
|
|
213
|
+
}
|
|
214
|
+
else if (chunk.type === "response.output_item.added" && chunk.item.type === "function_call") {
|
|
215
|
+
state.functionCalls.set(chunk.output_index, {
|
|
216
|
+
id: chunk.item.call_id,
|
|
217
|
+
name: chunk.item.name,
|
|
218
|
+
argsBuffer: chunk.item.arguments ?? "",
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else if (chunk.type === "response.function_call_arguments.delta") {
|
|
222
|
+
const call = state.functionCalls.get(chunk.output_index);
|
|
223
|
+
if (call)
|
|
224
|
+
call.argsBuffer += chunk.delta;
|
|
225
|
+
}
|
|
226
|
+
else if (chunk.type === "response.function_call_arguments.done") {
|
|
227
|
+
const call = state.functionCalls.get(chunk.output_index);
|
|
228
|
+
if (call)
|
|
229
|
+
call.argsBuffer = chunk.arguments;
|
|
230
|
+
}
|
|
231
|
+
else if (chunk.type === "response.output_item.done" && chunk.item.type === "function_call") {
|
|
232
|
+
const call = state.functionCalls.get(chunk.output_index) ?? {
|
|
233
|
+
id: chunk.item.call_id,
|
|
234
|
+
name: chunk.item.name,
|
|
235
|
+
argsBuffer: chunk.item.arguments ?? "{}",
|
|
236
|
+
};
|
|
237
|
+
let args = {};
|
|
238
|
+
try {
|
|
239
|
+
args = JSON.parse(call.argsBuffer || "{}");
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
args = {};
|
|
243
|
+
}
|
|
244
|
+
events.push({ type: "tool_call", id: call.id, name: call.name, arguments: args });
|
|
245
|
+
}
|
|
246
|
+
else if (chunk.type === "response.completed" || chunk.type === "response.incomplete") {
|
|
247
|
+
const response = chunk.response;
|
|
248
|
+
runStatePatch = {
|
|
249
|
+
previousResponseId: String(response.id),
|
|
250
|
+
coveredMessageCount: state.input.context.turns.length + 1,
|
|
251
|
+
};
|
|
252
|
+
const usage = response.usage;
|
|
253
|
+
if (usage) {
|
|
254
|
+
const totalTokens = numberField(usage, "total_tokens");
|
|
255
|
+
const providerUsage = this.normalizeUsage(usage);
|
|
256
|
+
const cacheReadInputTokens = cacheReadTokens(usage);
|
|
257
|
+
const inputTokens = numberField(usage, "input_tokens");
|
|
258
|
+
const outputTokens = numberField(usage, "output_tokens");
|
|
259
|
+
const rawStopReason = typeof response.incomplete_details?.reason === "string"
|
|
260
|
+
? response.incomplete_details.reason
|
|
261
|
+
: undefined;
|
|
262
|
+
const stopReason = this.normalizeStopReason(rawStopReason);
|
|
263
|
+
if (totalTokens && totalTokens > 0) {
|
|
264
|
+
events.push({
|
|
265
|
+
type: "usage",
|
|
266
|
+
totalTokens,
|
|
267
|
+
...(inputTokens ? { inputTokens } : {}),
|
|
268
|
+
...(outputTokens ? { outputTokens } : {}),
|
|
269
|
+
...(cacheReadInputTokens ? { cacheReadInputTokens } : {}),
|
|
270
|
+
...(providerUsage && (inputTokens || outputTokens) ? { providerUsage } : {}),
|
|
271
|
+
...(stopReason ? { stopReason } : {}),
|
|
272
|
+
...(rawStopReason ? { rawStopReason } : {}),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return { events, ...(runStatePatch ? { runStatePatch } : {}) };
|
|
278
|
+
}
|
|
279
|
+
finishStream(_state) {
|
|
280
|
+
return { events: [] };
|
|
281
|
+
}
|
|
282
|
+
normalizeUsage(raw) {
|
|
283
|
+
if (raw === undefined || raw === null)
|
|
284
|
+
return undefined;
|
|
285
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
286
|
+
throw new ProtocolResponseError("openai-responses", "usage must be an object");
|
|
287
|
+
}
|
|
288
|
+
const usage = raw;
|
|
289
|
+
const inputTokens = numberField(usage, "input_tokens");
|
|
290
|
+
const outputTokens = numberField(usage, "output_tokens");
|
|
291
|
+
numberField(usage, "total_tokens");
|
|
292
|
+
const outputDetails = usage.output_tokens_details;
|
|
293
|
+
if (outputDetails !== undefined && (!outputDetails || typeof outputDetails !== "object" || Array.isArray(outputDetails))) {
|
|
294
|
+
throw new ProtocolResponseError("openai-responses", "usage.output_tokens_details must be an object");
|
|
295
|
+
}
|
|
296
|
+
cacheReadTokens(usage);
|
|
297
|
+
const reasoningTokens = outputDetails
|
|
298
|
+
? numberField(outputDetails, "reasoning_tokens")
|
|
299
|
+
: undefined;
|
|
300
|
+
if (inputTokens === undefined && outputTokens === undefined)
|
|
301
|
+
return undefined;
|
|
302
|
+
return {
|
|
303
|
+
inputTokens: inputTokens ?? 0,
|
|
304
|
+
outputTokens: outputTokens ?? 0,
|
|
305
|
+
...(reasoningTokens !== undefined ? { reasoningTokens } : {}),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
normalizeStopReason(raw) {
|
|
309
|
+
if (raw === undefined)
|
|
310
|
+
return undefined;
|
|
311
|
+
if (raw === "max_output_tokens")
|
|
312
|
+
return "max_tokens";
|
|
313
|
+
if (raw === "content_filter")
|
|
314
|
+
return "content_filter";
|
|
315
|
+
return "other";
|
|
316
|
+
}
|
|
317
|
+
// Published compatibility helpers retained while internally routing through canonical input.
|
|
318
|
+
buildTools(tools) {
|
|
319
|
+
return tools.map(tool => ({
|
|
320
|
+
type: "function",
|
|
321
|
+
name: tool.name,
|
|
322
|
+
description: tool.description,
|
|
323
|
+
parameters: JSON.parse(tool.parameters),
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
buildInstructions(context) {
|
|
327
|
+
return context.systemText || undefined;
|
|
328
|
+
}
|
|
329
|
+
buildInput(context, state) {
|
|
330
|
+
return canonicalInputItems(normalizeCanonicalContext(context), state);
|
|
331
|
+
}
|
|
332
|
+
decodeOutput(output) {
|
|
333
|
+
return decodeOutput(output);
|
|
334
|
+
}
|
|
335
|
+
builtinTools(extensions) {
|
|
336
|
+
return builtinTools(extensions ?? {});
|
|
337
|
+
}
|
|
338
|
+
requestExtensions(extensions) {
|
|
339
|
+
return requestExtensions(extensions ?? {});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import type { Message, ProviderRunState, RenderedContext, StreamEvent, ToolSchema
|
|
2
|
+
import type { LLMProvider, Message, ProviderRunState, RenderedContext, RuntimePolicy, StreamEvent, ToolSchema } from "../types.js";
|
|
3
3
|
import { CircuitBreaker } from "./base.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
buildTools(tools: ToolSchema[]): {
|
|
10
|
-
type: "function";
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
parameters: any;
|
|
14
|
-
}[];
|
|
15
|
-
buildInstructions(context: RenderedContext): string | undefined;
|
|
16
|
-
buildInput(context: RenderedContext, state?: OpenAIResponsesRunState): Array<Record<string, unknown>>;
|
|
17
|
-
decodeOutput(output: Array<Record<string, unknown>>): {
|
|
18
|
-
content: string;
|
|
19
|
-
toolCalls: Array<{
|
|
20
|
-
id: string;
|
|
21
|
-
name: string;
|
|
22
|
-
arguments: string;
|
|
23
|
-
}>;
|
|
24
|
-
};
|
|
25
|
-
private buildMessageContent;
|
|
26
|
-
}
|
|
4
|
+
import { type CanonicalAdapterInput } from "./content-normalization.js";
|
|
5
|
+
import { OpenAIResponsesAdapter, type OpenAIResponsesRunState } from "./openai-responses-adapter.js";
|
|
6
|
+
export { OpenAIResponsesAdapter } from "./openai-responses-adapter.js";
|
|
7
|
+
export type { OpenAIResponsesRequestPlan, OpenAIResponsesRunState, OpenAIResponsesStreamState, } from "./openai-responses-adapter.js";
|
|
8
|
+
type ResolvedOpenAIResponsesRuntime = CanonicalAdapterInput["resolved"];
|
|
27
9
|
export declare class OpenAIResponsesProvider implements LLMProvider {
|
|
28
10
|
protected readonly model: string;
|
|
29
11
|
protected client: OpenAI;
|
|
@@ -31,20 +13,19 @@ export declare class OpenAIResponsesProvider implements LLMProvider {
|
|
|
31
13
|
protected maxRetries: number;
|
|
32
14
|
protected baseDelay: number;
|
|
33
15
|
protected readonly responses: OpenAIResponsesAdapter;
|
|
16
|
+
private readonly resolvedRuntimePolicy;
|
|
17
|
+
private resolvedRuntime?;
|
|
34
18
|
constructor(apiKey: string, model?: string, retry?: {
|
|
35
19
|
maxRetries: number;
|
|
36
20
|
baseDelay: number;
|
|
37
|
-
}, baseURL?: string);
|
|
38
|
-
runtimePolicy():
|
|
21
|
+
}, baseURL?: string, runtimePolicy?: RuntimePolicy, authMode?: "api_key" | "bearer");
|
|
22
|
+
runtimePolicy(): RuntimePolicy;
|
|
23
|
+
bindResolvedRuntime(resolved: ResolvedOpenAIResponsesRuntime): void;
|
|
39
24
|
createRunState(): OpenAIResponsesRunState;
|
|
25
|
+
private adapterInput;
|
|
40
26
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
41
|
-
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>, state?: ProviderRunState): AsyncIterable<StreamEvent>;
|
|
42
|
-
private requestExtensions;
|
|
43
|
-
/** Responses API built-in server tools from extensions (live in the same tools[] as function tools):
|
|
44
|
-
* `web_search: true` (or a config object), plus a `builtin_tools` list passed through verbatim for
|
|
45
|
-
* file_search / code_interpreter. They run server-side; results return inline. Mirrors py. */
|
|
27
|
+
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>, state?: ProviderRunState, signal?: AbortSignal): AsyncIterable<StreamEvent>;
|
|
46
28
|
private builtinTools;
|
|
47
|
-
|
|
48
|
-
private allTools;
|
|
29
|
+
private requestExtensions;
|
|
49
30
|
private asRunState;
|
|
50
31
|
}
|