@theokit/sdk 4.8.0 → 4.9.1
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/dist/cron.cjs +203 -0
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.js +203 -0
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +203 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +203 -0
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +203 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +203 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/llm/responses.d.ts +21 -0
- package/package.json +1 -1
package/dist/cron.cjs
CHANGED
|
@@ -13119,6 +13119,201 @@ function abortError2(signal) {
|
|
|
13119
13119
|
return new Error("AbortError");
|
|
13120
13120
|
}
|
|
13121
13121
|
|
|
13122
|
+
// src/internal/llm/responses.ts
|
|
13123
|
+
function messageToInputItems(message) {
|
|
13124
|
+
const items = [];
|
|
13125
|
+
if (message.role === "user") {
|
|
13126
|
+
const content = [];
|
|
13127
|
+
for (const part of message.content) {
|
|
13128
|
+
if (part.type === "text") {
|
|
13129
|
+
content.push({ type: "input_text", text: part.text });
|
|
13130
|
+
} else if (part.type === "image") {
|
|
13131
|
+
const url = part.source.type === "base64" ? `data:${part.source.media_type};base64,${part.source.data}` : part.source.url;
|
|
13132
|
+
content.push({ type: "input_image", image_url: url });
|
|
13133
|
+
} else if (part.type === "tool_result") {
|
|
13134
|
+
items.push({
|
|
13135
|
+
type: "function_call_output",
|
|
13136
|
+
call_id: part.toolUseId,
|
|
13137
|
+
output: toStringToolResultContent(part.content, "openai-responses")
|
|
13138
|
+
});
|
|
13139
|
+
}
|
|
13140
|
+
}
|
|
13141
|
+
if (content.length > 0) items.push({ role: "user", content });
|
|
13142
|
+
return items;
|
|
13143
|
+
}
|
|
13144
|
+
if (message.role === "assistant") {
|
|
13145
|
+
const content = [];
|
|
13146
|
+
for (const part of message.content) {
|
|
13147
|
+
if (part.type === "text") {
|
|
13148
|
+
content.push({ type: "output_text", text: part.text });
|
|
13149
|
+
} else if (part.type === "tool_use") {
|
|
13150
|
+
items.push({
|
|
13151
|
+
type: "function_call",
|
|
13152
|
+
call_id: part.id,
|
|
13153
|
+
name: part.name,
|
|
13154
|
+
arguments: JSON.stringify(part.input)
|
|
13155
|
+
});
|
|
13156
|
+
}
|
|
13157
|
+
}
|
|
13158
|
+
if (content.length > 0) items.push({ role: "assistant", content });
|
|
13159
|
+
return items;
|
|
13160
|
+
}
|
|
13161
|
+
const text = message.content.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
13162
|
+
if (text.length > 0) items.push({ role: "system", content: text });
|
|
13163
|
+
return items;
|
|
13164
|
+
}
|
|
13165
|
+
function buildResponsesBody(request) {
|
|
13166
|
+
const input = [];
|
|
13167
|
+
for (const message of request.messages) {
|
|
13168
|
+
for (const item of messageToInputItems(message)) input.push(item);
|
|
13169
|
+
}
|
|
13170
|
+
const slash = request.model.lastIndexOf("/");
|
|
13171
|
+
const model = slash >= 0 ? request.model.slice(slash + 1) : request.model;
|
|
13172
|
+
const body = { model, input, stream: true, store: false };
|
|
13173
|
+
const instructions = collapseSystemText(request.system);
|
|
13174
|
+
if (instructions.length > 0) body.instructions = instructions;
|
|
13175
|
+
if (request.maxTokens !== void 0) body.max_output_tokens = request.maxTokens;
|
|
13176
|
+
if (request.temperature !== void 0) body.temperature = request.temperature;
|
|
13177
|
+
const tools = (request.tools ?? []).map((tool) => ({
|
|
13178
|
+
type: "function",
|
|
13179
|
+
name: tool.name,
|
|
13180
|
+
description: tool.description,
|
|
13181
|
+
parameters: tool.inputSchema,
|
|
13182
|
+
strict: false
|
|
13183
|
+
}));
|
|
13184
|
+
if (tools.length > 0) body.tools = tools;
|
|
13185
|
+
if (request.reasoning !== void 0) body.reasoning = { effort: request.reasoning.effort };
|
|
13186
|
+
return body;
|
|
13187
|
+
}
|
|
13188
|
+
var ResponsesApiClient = class {
|
|
13189
|
+
constructor(options) {
|
|
13190
|
+
this.options = options;
|
|
13191
|
+
this.name = options.providerName ?? "openai-responses";
|
|
13192
|
+
this.baseUrl = (options.baseUrl ?? "https://api.openai.com/v1").replace(/\/+$/, "");
|
|
13193
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
13194
|
+
}
|
|
13195
|
+
options;
|
|
13196
|
+
name;
|
|
13197
|
+
baseUrl;
|
|
13198
|
+
fetchImpl;
|
|
13199
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: the SSE dispatch (text / reasoning / tool-call add+delta+done / terminal+usage / error) is one cohesive state machine, mirroring OpenAIStreamAccumulator.consume.
|
|
13200
|
+
async *stream(request, signal) {
|
|
13201
|
+
const providerId = this.options.providerName ?? "openai";
|
|
13202
|
+
const headers = {
|
|
13203
|
+
"content-type": "application/json",
|
|
13204
|
+
accept: "text/event-stream",
|
|
13205
|
+
authorization: `Bearer ${this.options.apiKey}`,
|
|
13206
|
+
...this.options.extraHeaders ?? {}
|
|
13207
|
+
};
|
|
13208
|
+
const url = `${this.baseUrl}/responses`;
|
|
13209
|
+
const response = await this.fetchImpl(url, {
|
|
13210
|
+
method: "POST",
|
|
13211
|
+
signal,
|
|
13212
|
+
headers,
|
|
13213
|
+
body: JSON.stringify(buildResponsesBody(request))
|
|
13214
|
+
});
|
|
13215
|
+
if (!response.ok) {
|
|
13216
|
+
const text2 = await response.text().catch(() => "");
|
|
13217
|
+
let body = text2;
|
|
13218
|
+
try {
|
|
13219
|
+
body = JSON.parse(text2);
|
|
13220
|
+
} catch {
|
|
13221
|
+
}
|
|
13222
|
+
throw mapOpenAICompatibleError({
|
|
13223
|
+
providerId,
|
|
13224
|
+
status: response.status,
|
|
13225
|
+
body,
|
|
13226
|
+
headers: response.headers,
|
|
13227
|
+
endpoint: "/responses"
|
|
13228
|
+
});
|
|
13229
|
+
}
|
|
13230
|
+
let text = "";
|
|
13231
|
+
const toolCalls = [];
|
|
13232
|
+
let stopReason = "end_turn";
|
|
13233
|
+
let inputTokens;
|
|
13234
|
+
let outputTokens;
|
|
13235
|
+
let reasoningTokens;
|
|
13236
|
+
const pending = {};
|
|
13237
|
+
if (response.body !== null) {
|
|
13238
|
+
for await (const record of parseSseStream(response.body, signal)) {
|
|
13239
|
+
if (record.data === "[DONE]") break;
|
|
13240
|
+
let event;
|
|
13241
|
+
try {
|
|
13242
|
+
event = JSON.parse(record.data);
|
|
13243
|
+
} catch {
|
|
13244
|
+
continue;
|
|
13245
|
+
}
|
|
13246
|
+
const t = event.type;
|
|
13247
|
+
if (t === "response.output_text.delta") {
|
|
13248
|
+
const d = event.delta ?? "";
|
|
13249
|
+
if (d.length > 0) {
|
|
13250
|
+
text += d;
|
|
13251
|
+
yield { type: "text_delta", text: d };
|
|
13252
|
+
}
|
|
13253
|
+
} else if (t === "response.reasoning_summary_text.delta" || t === "response.reasoning_text.delta") {
|
|
13254
|
+
const d = event.delta ?? "";
|
|
13255
|
+
if (d.length > 0) yield { type: "reasoning_delta", text: d };
|
|
13256
|
+
} else if (t === "response.output_item.added" && event.item?.type === "function_call") {
|
|
13257
|
+
const id = event.item.id ?? event.item.call_id ?? "call-0";
|
|
13258
|
+
pending[id] = {
|
|
13259
|
+
callId: event.item.call_id ?? id,
|
|
13260
|
+
name: event.item.name ?? "",
|
|
13261
|
+
args: event.item.arguments ?? ""
|
|
13262
|
+
};
|
|
13263
|
+
} else if (t === "response.function_call_arguments.delta") {
|
|
13264
|
+
const c = event.item_id !== void 0 ? pending[event.item_id] : void 0;
|
|
13265
|
+
if (c !== void 0) c.args += event.delta ?? "";
|
|
13266
|
+
} else if (t === "response.output_item.done" && event.item?.type === "function_call") {
|
|
13267
|
+
const id = event.item.id ?? event.item.call_id ?? "call-0";
|
|
13268
|
+
const c = pending[id] ?? {
|
|
13269
|
+
callId: event.item.call_id ?? id,
|
|
13270
|
+
name: event.item.name ?? "",
|
|
13271
|
+
args: event.item.arguments ?? ""
|
|
13272
|
+
};
|
|
13273
|
+
const rawArgs = event.item.arguments ?? c.args;
|
|
13274
|
+
const call = {
|
|
13275
|
+
type: "tool_use",
|
|
13276
|
+
id: c.callId,
|
|
13277
|
+
name: c.name.length > 0 ? c.name : event.item.name ?? "",
|
|
13278
|
+
input: parseToolArguments(rawArgs)
|
|
13279
|
+
};
|
|
13280
|
+
toolCalls.push(call);
|
|
13281
|
+
delete pending[id];
|
|
13282
|
+
yield { type: "tool_use", id: call.id, name: call.name, input: call.input };
|
|
13283
|
+
} else if (t === "response.completed" || t === "response.incomplete") {
|
|
13284
|
+
const usage = event.response?.usage;
|
|
13285
|
+
if (usage !== void 0) {
|
|
13286
|
+
inputTokens = usage.input_tokens;
|
|
13287
|
+
outputTokens = usage.output_tokens;
|
|
13288
|
+
reasoningTokens = usage.output_tokens_details?.reasoning_tokens;
|
|
13289
|
+
}
|
|
13290
|
+
stopReason = t === "response.incomplete" ? "max_tokens" : "end_turn";
|
|
13291
|
+
} else if (t === "response.failed" || t === "error") {
|
|
13292
|
+
const msg = event.response?.error?.message ?? event.message ?? "responses stream failed";
|
|
13293
|
+
yield { type: "error", message: msg };
|
|
13294
|
+
throw mapOpenAICompatibleError({
|
|
13295
|
+
providerId,
|
|
13296
|
+
status: 502,
|
|
13297
|
+
body: { error: { message: msg } },
|
|
13298
|
+
headers: response.headers,
|
|
13299
|
+
endpoint: "/responses"
|
|
13300
|
+
});
|
|
13301
|
+
}
|
|
13302
|
+
}
|
|
13303
|
+
}
|
|
13304
|
+
if (toolCalls.length > 0 && stopReason === "end_turn") stopReason = "tool_use";
|
|
13305
|
+
yield { type: "stop", reason: stopReason };
|
|
13306
|
+
return makeLlmFinish({
|
|
13307
|
+
stopReason,
|
|
13308
|
+
text,
|
|
13309
|
+
toolCalls,
|
|
13310
|
+
inputTokens,
|
|
13311
|
+
outputTokens,
|
|
13312
|
+
reasoningTokens
|
|
13313
|
+
});
|
|
13314
|
+
}
|
|
13315
|
+
};
|
|
13316
|
+
|
|
13122
13317
|
// src/internal/llm/vertex-anthropic.ts
|
|
13123
13318
|
init_errors();
|
|
13124
13319
|
|
|
@@ -13521,6 +13716,14 @@ function selectTransport(profile, apiKey) {
|
|
|
13521
13716
|
const realKey = apiKey === "__bedrock_lazy_token__" ? void 0 : apiKey;
|
|
13522
13717
|
return new BedrockAnthropicClient(realKey !== void 0 ? { apiKey: realKey } : {});
|
|
13523
13718
|
}
|
|
13719
|
+
if (profile.apiMode === "responses_api") {
|
|
13720
|
+
return new ResponsesApiClient({
|
|
13721
|
+
apiKey,
|
|
13722
|
+
...profile.baseUrl !== void 0 ? { baseUrl: profile.baseUrl } : {},
|
|
13723
|
+
...profile.extraHeaders !== void 0 ? { extraHeaders: profile.extraHeaders } : {},
|
|
13724
|
+
providerName: profile.name
|
|
13725
|
+
});
|
|
13726
|
+
}
|
|
13524
13727
|
throw new ConfigurationError(
|
|
13525
13728
|
`Provider "${profile.name}" requires apiMode "${profile.apiMode}" but no transport is registered. Install a third-party transport plugin (@theokit-transport-${profile.apiMode}) or use a provider with apiMode "chat_completions" or "anthropic_messages".`,
|
|
13526
13729
|
{ code: "transport_unavailable" }
|