@ljoukov/llm 7.0.13 → 7.0.15
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 +73 -3
- package/dist/index.cjs +346 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -4
- package/dist/index.d.ts +76 -4
- package/dist/index.js +339 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -221,6 +221,10 @@ var OPENAI_IMAGE_MODEL_IDS = ["gpt-image-2"];
|
|
|
221
221
|
function isOpenAiImageModelId(value) {
|
|
222
222
|
return OPENAI_IMAGE_MODEL_IDS.includes(value);
|
|
223
223
|
}
|
|
224
|
+
var CHATGPT_IMAGE_MODEL_IDS = ["chatgpt-gpt-image-2"];
|
|
225
|
+
function isChatGptImageModelId(value) {
|
|
226
|
+
return CHATGPT_IMAGE_MODEL_IDS.includes(value);
|
|
227
|
+
}
|
|
224
228
|
var OPENAI_GPT_IMAGE_2_POPULAR_RESOLUTIONS = [
|
|
225
229
|
"1024x1024",
|
|
226
230
|
"1536x1024",
|
|
@@ -303,6 +307,7 @@ var CHATGPT_MODEL_IDS = [
|
|
|
303
307
|
var FAST_MODEL_SUFFIX = "-fast";
|
|
304
308
|
var OPENAI_PRIORITY_MODEL_IDS = ["gpt-5.5-fast"];
|
|
305
309
|
var CHATGPT_PRIORITY_MODEL_IDS = ["chatgpt-gpt-5.5-fast", "chatgpt-gpt-5.4-fast"];
|
|
310
|
+
var CHATGPT_IMAGE_GENERATION_PROVIDER_MODEL = "gpt-5.4";
|
|
306
311
|
var EXPERIMENTAL_CHATGPT_MODEL_PREFIX = "experimental-chatgpt-";
|
|
307
312
|
function isExperimentalChatGptModelId(value) {
|
|
308
313
|
return value.startsWith(EXPERIMENTAL_CHATGPT_MODEL_PREFIX) && value.length > EXPERIMENTAL_CHATGPT_MODEL_PREFIX.length;
|
|
@@ -329,6 +334,9 @@ function resolveChatGptProviderModel(model) {
|
|
|
329
334
|
const providerModel = stripChatGptPrefix(model);
|
|
330
335
|
return CHATGPT_PRIORITY_MODEL_IDS.includes(model) ? stripFastSuffix(providerModel) : providerModel;
|
|
331
336
|
}
|
|
337
|
+
function resolveChatGptImageProviderModel(_model) {
|
|
338
|
+
return CHATGPT_IMAGE_GENERATION_PROVIDER_MODEL;
|
|
339
|
+
}
|
|
332
340
|
function resolveChatGptServiceTier(model) {
|
|
333
341
|
return CHATGPT_PRIORITY_MODEL_IDS.includes(model) ? "priority" : void 0;
|
|
334
342
|
}
|
|
@@ -423,7 +431,7 @@ function getOpenAiPricing(modelId) {
|
|
|
423
431
|
return void 0;
|
|
424
432
|
}
|
|
425
433
|
function getOpenAiImagePricing(modelId) {
|
|
426
|
-
return isOpenAiImageModelId(modelId) ? OPENAI_GPT_IMAGE_2_PRICING : void 0;
|
|
434
|
+
return isOpenAiImageModelId(modelId) || isChatGptImageModelId(modelId) ? OPENAI_GPT_IMAGE_2_PRICING : void 0;
|
|
427
435
|
}
|
|
428
436
|
|
|
429
437
|
// src/utils/cost.ts
|
|
@@ -547,7 +555,7 @@ function resolveOpenAiImagePriceResolution(imageSize) {
|
|
|
547
555
|
|
|
548
556
|
// src/openai/chatgpt-codex.ts
|
|
549
557
|
import os2 from "os";
|
|
550
|
-
import { TextDecoder } from "util";
|
|
558
|
+
import { TextDecoder as TextDecoder2 } from "util";
|
|
551
559
|
|
|
552
560
|
// src/utils/runtimeSingleton.ts
|
|
553
561
|
var runtimeSingletonStoreKey = /* @__PURE__ */ Symbol.for("@ljoukov/llm.runtimeSingletonStore");
|
|
@@ -1698,6 +1706,8 @@ async function collectChatGptCodexStream(options) {
|
|
|
1698
1706
|
const toolCallOrder = [];
|
|
1699
1707
|
const webSearchCalls = /* @__PURE__ */ new Map();
|
|
1700
1708
|
const webSearchCallOrder = [];
|
|
1709
|
+
const imageGenerationCalls = /* @__PURE__ */ new Map();
|
|
1710
|
+
const imageGenerationCallOrder = [];
|
|
1701
1711
|
let text = "";
|
|
1702
1712
|
const reasoningText = "";
|
|
1703
1713
|
let reasoningSummaryText = "";
|
|
@@ -1768,6 +1778,20 @@ async function collectChatGptCodexStream(options) {
|
|
|
1768
1778
|
action: item.action && typeof item.action === "object" ? item.action : void 0
|
|
1769
1779
|
});
|
|
1770
1780
|
}
|
|
1781
|
+
} else if (item.type === "image_generation_call") {
|
|
1782
|
+
const id = typeof item.id === "string" ? item.id : "";
|
|
1783
|
+
const result = typeof item.result === "string" ? item.result : "";
|
|
1784
|
+
if (id && result) {
|
|
1785
|
+
if (!imageGenerationCalls.has(id)) {
|
|
1786
|
+
imageGenerationCallOrder.push(id);
|
|
1787
|
+
}
|
|
1788
|
+
imageGenerationCalls.set(id, {
|
|
1789
|
+
id,
|
|
1790
|
+
status: typeof item.status === "string" ? item.status : void 0,
|
|
1791
|
+
revisedPrompt: typeof item.revised_prompt === "string" ? item.revised_prompt : void 0,
|
|
1792
|
+
result
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1771
1795
|
}
|
|
1772
1796
|
}
|
|
1773
1797
|
continue;
|
|
@@ -1807,12 +1831,14 @@ async function collectChatGptCodexStream(options) {
|
|
|
1807
1831
|
}
|
|
1808
1832
|
const orderedToolCalls = toolCallOrder.map((id) => toolCalls.get(id)).filter((call) => call !== void 0);
|
|
1809
1833
|
const orderedWebSearchCalls = webSearchCallOrder.map((id) => webSearchCalls.get(id)).filter((call) => call !== void 0);
|
|
1834
|
+
const orderedImageGenerationCalls = imageGenerationCallOrder.map((id) => imageGenerationCalls.get(id)).filter((call) => call !== void 0);
|
|
1810
1835
|
return {
|
|
1811
1836
|
text,
|
|
1812
1837
|
reasoningText,
|
|
1813
1838
|
reasoningSummaryText,
|
|
1814
1839
|
toolCalls: orderedToolCalls,
|
|
1815
1840
|
webSearchCalls: orderedWebSearchCalls,
|
|
1841
|
+
imageGenerationCalls: orderedImageGenerationCalls,
|
|
1816
1842
|
usage,
|
|
1817
1843
|
id: responseId,
|
|
1818
1844
|
model,
|
|
@@ -1860,7 +1886,7 @@ function buildUserAgent() {
|
|
|
1860
1886
|
}
|
|
1861
1887
|
async function* parseEventStream(stream) {
|
|
1862
1888
|
const reader = stream.getReader();
|
|
1863
|
-
const decoder = new
|
|
1889
|
+
const decoder = new TextDecoder2();
|
|
1864
1890
|
let buffer = "";
|
|
1865
1891
|
while (true) {
|
|
1866
1892
|
const { done, value } = await reader.read();
|
|
@@ -4524,13 +4550,17 @@ var LLM_TEXT_MODEL_IDS = [
|
|
|
4524
4550
|
...FIREWORKS_MODEL_IDS,
|
|
4525
4551
|
...GEMINI_TEXT_MODEL_IDS
|
|
4526
4552
|
];
|
|
4527
|
-
var LLM_IMAGE_MODEL_IDS = [
|
|
4553
|
+
var LLM_IMAGE_MODEL_IDS = [
|
|
4554
|
+
...OPENAI_IMAGE_MODEL_IDS,
|
|
4555
|
+
...CHATGPT_IMAGE_MODEL_IDS,
|
|
4556
|
+
...GEMINI_IMAGE_MODEL_IDS
|
|
4557
|
+
];
|
|
4528
4558
|
var LLM_MODEL_IDS = [...LLM_TEXT_MODEL_IDS, ...LLM_IMAGE_MODEL_IDS];
|
|
4529
4559
|
function isLlmTextModelId(value) {
|
|
4530
4560
|
return isOpenAiModelId(value) || isChatGptModelId(value) || isFireworksModelId(value) || isGeminiTextModelId(value);
|
|
4531
4561
|
}
|
|
4532
4562
|
function isLlmImageModelId(value) {
|
|
4533
|
-
return isOpenAiImageModelId(value) || isGeminiImageModelId(value);
|
|
4563
|
+
return isOpenAiImageModelId(value) || isChatGptImageModelId(value) || isGeminiImageModelId(value);
|
|
4534
4564
|
}
|
|
4535
4565
|
function isLlmModelId(value) {
|
|
4536
4566
|
return isLlmTextModelId(value) || isLlmImageModelId(value);
|
|
@@ -4545,6 +4575,9 @@ var LlmJsonCallError = class extends Error {
|
|
|
4545
4575
|
function isOpenAiGenerateImagesRequest(request) {
|
|
4546
4576
|
return isOpenAiImageModelId(request.model);
|
|
4547
4577
|
}
|
|
4578
|
+
function isChatGptGenerateImagesRequest(request) {
|
|
4579
|
+
return isChatGptImageModelId(request.model);
|
|
4580
|
+
}
|
|
4548
4581
|
function tool(options) {
|
|
4549
4582
|
return {
|
|
4550
4583
|
type: "function",
|
|
@@ -5138,6 +5171,12 @@ function resolveProvider(model) {
|
|
|
5138
5171
|
if (isOpenAiImageModelId(model)) {
|
|
5139
5172
|
return { provider: "openai", model };
|
|
5140
5173
|
}
|
|
5174
|
+
if (isChatGptImageModelId(model)) {
|
|
5175
|
+
return {
|
|
5176
|
+
provider: "chatgpt",
|
|
5177
|
+
model: resolveChatGptImageProviderModel(model)
|
|
5178
|
+
};
|
|
5179
|
+
}
|
|
5141
5180
|
if (isOpenAiModelId(model)) {
|
|
5142
5181
|
return {
|
|
5143
5182
|
provider: "openai",
|
|
@@ -6292,6 +6331,50 @@ function toOpenAiTools(tools, options) {
|
|
|
6292
6331
|
}
|
|
6293
6332
|
});
|
|
6294
6333
|
}
|
|
6334
|
+
function extractOpenAiResponseMetadata(response) {
|
|
6335
|
+
if (!response || typeof response !== "object") {
|
|
6336
|
+
return void 0;
|
|
6337
|
+
}
|
|
6338
|
+
const record = response;
|
|
6339
|
+
const responseId = typeof record.id === "string" ? record.id : void 0;
|
|
6340
|
+
const output = Array.isArray(record.output) ? record.output : [];
|
|
6341
|
+
const containers = [];
|
|
6342
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6343
|
+
const addContainer = (container) => {
|
|
6344
|
+
const key = `${container.toolType}:${container.containerId}:${container.itemId ?? ""}:${container.callId ?? ""}`;
|
|
6345
|
+
if (seen.has(key)) {
|
|
6346
|
+
return;
|
|
6347
|
+
}
|
|
6348
|
+
seen.add(key);
|
|
6349
|
+
containers.push(container);
|
|
6350
|
+
};
|
|
6351
|
+
for (const item of output) {
|
|
6352
|
+
if (!item || typeof item !== "object") {
|
|
6353
|
+
continue;
|
|
6354
|
+
}
|
|
6355
|
+
const itemRecord = item;
|
|
6356
|
+
const itemId = typeof itemRecord.id === "string" ? itemRecord.id : void 0;
|
|
6357
|
+
const callId = typeof itemRecord.call_id === "string" ? itemRecord.call_id : void 0;
|
|
6358
|
+
if (itemRecord.type === "shell_call") {
|
|
6359
|
+
const environment = itemRecord.environment && typeof itemRecord.environment === "object" ? itemRecord.environment : void 0;
|
|
6360
|
+
const containerId = environment?.type === "container_reference" && typeof environment.container_id === "string" ? environment.container_id : void 0;
|
|
6361
|
+
if (containerId) {
|
|
6362
|
+
addContainer({ containerId, toolType: "shell", itemId, callId });
|
|
6363
|
+
}
|
|
6364
|
+
continue;
|
|
6365
|
+
}
|
|
6366
|
+
if (itemRecord.type === "code_interpreter_call") {
|
|
6367
|
+
const containerId = typeof itemRecord.container_id === "string" ? itemRecord.container_id : void 0;
|
|
6368
|
+
if (containerId) {
|
|
6369
|
+
addContainer({ containerId, toolType: "code_interpreter", itemId, callId });
|
|
6370
|
+
}
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
if (!responseId && containers.length === 0) {
|
|
6374
|
+
return void 0;
|
|
6375
|
+
}
|
|
6376
|
+
return { ...responseId ? { responseId } : {}, containers };
|
|
6377
|
+
}
|
|
6295
6378
|
function mergeTokenUpdates(current, next) {
|
|
6296
6379
|
if (!next) {
|
|
6297
6380
|
return current;
|
|
@@ -7903,6 +7986,7 @@ async function runTextCall(params) {
|
|
|
7903
7986
|
let modelVersion = request.model;
|
|
7904
7987
|
let blocked = false;
|
|
7905
7988
|
let grounding;
|
|
7989
|
+
let openAi;
|
|
7906
7990
|
const responseParts = [];
|
|
7907
7991
|
let responseRole;
|
|
7908
7992
|
let latestUsage;
|
|
@@ -8013,6 +8097,7 @@ async function runTextCall(params) {
|
|
|
8013
8097
|
}
|
|
8014
8098
|
}
|
|
8015
8099
|
const finalResponse = await stream.finalResponse();
|
|
8100
|
+
openAi = extractOpenAiResponseMetadata(finalResponse);
|
|
8016
8101
|
modelVersion = typeof finalResponse.model === "string" ? finalResponse.model : request.model;
|
|
8017
8102
|
pushEvent({ type: "model", modelVersion });
|
|
8018
8103
|
if (finalResponse.error) {
|
|
@@ -8044,6 +8129,11 @@ async function runTextCall(params) {
|
|
|
8044
8129
|
}
|
|
8045
8130
|
}, modelForProvider);
|
|
8046
8131
|
} else if (provider === "chatgpt") {
|
|
8132
|
+
if (isChatGptImageModelId(request.model)) {
|
|
8133
|
+
throw new Error(
|
|
8134
|
+
"chatgpt-gpt-image-2 is an image generation model; use generateImages()."
|
|
8135
|
+
);
|
|
8136
|
+
}
|
|
8047
8137
|
const chatGptInput = toChatGptInput(contents, {
|
|
8048
8138
|
defaultMediaResolution: request.mediaResolution,
|
|
8049
8139
|
model: request.model
|
|
@@ -8251,6 +8341,7 @@ async function runTextCall(params) {
|
|
|
8251
8341
|
costUsd,
|
|
8252
8342
|
usage: latestUsage,
|
|
8253
8343
|
grounding: grounding ? sanitiseLogValue(grounding) : void 0,
|
|
8344
|
+
openAi: openAi ? sanitiseLogValue(openAi) : void 0,
|
|
8254
8345
|
responseChars: text.length,
|
|
8255
8346
|
thoughtChars: thoughts.length,
|
|
8256
8347
|
responseImages,
|
|
@@ -8267,7 +8358,8 @@ async function runTextCall(params) {
|
|
|
8267
8358
|
blocked,
|
|
8268
8359
|
usage: latestUsage,
|
|
8269
8360
|
costUsd,
|
|
8270
|
-
grounding
|
|
8361
|
+
grounding,
|
|
8362
|
+
openAi
|
|
8271
8363
|
};
|
|
8272
8364
|
} catch (error) {
|
|
8273
8365
|
const partialParts = mergeConsecutiveTextParts(responseParts);
|
|
@@ -10497,10 +10589,144 @@ async function generateImagesWithOpenAiImageApi(request) {
|
|
|
10497
10589
|
await telemetry.flush();
|
|
10498
10590
|
}
|
|
10499
10591
|
}
|
|
10592
|
+
function buildChatGptImageInputContent(params) {
|
|
10593
|
+
const parts = [
|
|
10594
|
+
{
|
|
10595
|
+
type: "text",
|
|
10596
|
+
text: params.prompt
|
|
10597
|
+
}
|
|
10598
|
+
];
|
|
10599
|
+
for (const [index, image] of (params.styleImages ?? []).entries()) {
|
|
10600
|
+
const mimeType = image.mimeType ?? "image/png";
|
|
10601
|
+
parts.push({
|
|
10602
|
+
type: "inlineData",
|
|
10603
|
+
data: image.data.toString("base64"),
|
|
10604
|
+
mimeType,
|
|
10605
|
+
filename: `style-${index + 1}.${resolveAttachmentExtension(mimeType)}`
|
|
10606
|
+
});
|
|
10607
|
+
}
|
|
10608
|
+
return [{ role: "user", parts }];
|
|
10609
|
+
}
|
|
10610
|
+
async function generateImagesWithChatGptImageTool(request) {
|
|
10611
|
+
const promptEntries = Array.from(request.imagePrompts, (rawPrompt, index) => {
|
|
10612
|
+
const prompt = rawPrompt.trim();
|
|
10613
|
+
if (!prompt) {
|
|
10614
|
+
throw new Error(`imagePrompts[${index}] must be a non-empty string`);
|
|
10615
|
+
}
|
|
10616
|
+
return prompt;
|
|
10617
|
+
});
|
|
10618
|
+
if (promptEntries.length === 0) {
|
|
10619
|
+
return [];
|
|
10620
|
+
}
|
|
10621
|
+
const providerInfo = resolveProvider(request.model);
|
|
10622
|
+
const telemetry = createLlmTelemetryEmitter({
|
|
10623
|
+
telemetry: request.telemetry,
|
|
10624
|
+
operation: "generateImages",
|
|
10625
|
+
provider: providerInfo.provider,
|
|
10626
|
+
model: request.model
|
|
10627
|
+
});
|
|
10628
|
+
const startedAtMs = Date.now();
|
|
10629
|
+
const numImagesPerPrompt = request.numImages ?? 1;
|
|
10630
|
+
let totalUsage;
|
|
10631
|
+
let costUsd = 0;
|
|
10632
|
+
let outputImages = 0;
|
|
10633
|
+
telemetry.emit({
|
|
10634
|
+
type: "llm.call.started",
|
|
10635
|
+
imagePromptCount: promptEntries.length,
|
|
10636
|
+
styleImageCount: request.styleImages?.length ?? 0,
|
|
10637
|
+
numImagesPerPrompt
|
|
10638
|
+
});
|
|
10639
|
+
try {
|
|
10640
|
+
const images = [];
|
|
10641
|
+
for (const imagePrompt of promptEntries) {
|
|
10642
|
+
const prompt = buildOpenAiImagePrompt({
|
|
10643
|
+
stylePrompt: request.stylePrompt,
|
|
10644
|
+
imagePrompt,
|
|
10645
|
+
hasStyleImages: Boolean(request.styleImages && request.styleImages.length > 0)
|
|
10646
|
+
});
|
|
10647
|
+
for (let imageIndex = 0; imageIndex < numImagesPerPrompt; imageIndex += 1) {
|
|
10648
|
+
const chatGptInput = toChatGptInput(
|
|
10649
|
+
buildChatGptImageInputContent({
|
|
10650
|
+
prompt,
|
|
10651
|
+
styleImages: request.styleImages
|
|
10652
|
+
}),
|
|
10653
|
+
{ model: request.model }
|
|
10654
|
+
);
|
|
10655
|
+
const preparedInput = await maybePrepareOpenAiPromptInput(chatGptInput.input, {
|
|
10656
|
+
model: request.model,
|
|
10657
|
+
provider: "chatgpt"
|
|
10658
|
+
});
|
|
10659
|
+
const result = await collectChatGptCodexResponseWithRetry({
|
|
10660
|
+
request: {
|
|
10661
|
+
model: providerInfo.model,
|
|
10662
|
+
store: false,
|
|
10663
|
+
stream: true,
|
|
10664
|
+
instructions: chatGptInput.instructions ?? "Use the image_generation tool to generate exactly one PNG image. Do not return prose instead of the image.",
|
|
10665
|
+
input: preparedInput,
|
|
10666
|
+
tool_choice: "required",
|
|
10667
|
+
parallel_tool_calls: false,
|
|
10668
|
+
tools: [{ type: "image_generation", output_format: "png" }]
|
|
10669
|
+
},
|
|
10670
|
+
signal: request.signal
|
|
10671
|
+
});
|
|
10672
|
+
if (result.status && result.status !== "completed") {
|
|
10673
|
+
throw new Error(`ChatGPT image generation response status ${result.status}`);
|
|
10674
|
+
}
|
|
10675
|
+
if (result.imageGenerationCalls.length === 0) {
|
|
10676
|
+
throw new Error("ChatGPT image generation returned no image_generation_call result.");
|
|
10677
|
+
}
|
|
10678
|
+
for (const call of result.imageGenerationCalls) {
|
|
10679
|
+
images.push({
|
|
10680
|
+
mimeType: "image/png",
|
|
10681
|
+
data: Buffer5.from(call.result, "base64")
|
|
10682
|
+
});
|
|
10683
|
+
}
|
|
10684
|
+
outputImages = images.length;
|
|
10685
|
+
const usage = extractChatGptUsageTokens(result.usage);
|
|
10686
|
+
totalUsage = sumUsageTokens(totalUsage, usage);
|
|
10687
|
+
costUsd += estimateCallCostUsd({
|
|
10688
|
+
modelId: request.model,
|
|
10689
|
+
tokens: usage,
|
|
10690
|
+
responseImages: result.imageGenerationCalls.length,
|
|
10691
|
+
imageSize: "1024x1024",
|
|
10692
|
+
imageQuality: "medium"
|
|
10693
|
+
});
|
|
10694
|
+
}
|
|
10695
|
+
}
|
|
10696
|
+
telemetry.emit({
|
|
10697
|
+
type: "llm.call.completed",
|
|
10698
|
+
success: true,
|
|
10699
|
+
durationMs: Math.max(0, Date.now() - startedAtMs),
|
|
10700
|
+
modelVersion: request.model,
|
|
10701
|
+
usage: totalUsage,
|
|
10702
|
+
costUsd,
|
|
10703
|
+
imageCount: images.length,
|
|
10704
|
+
attempts: promptEntries.length * numImagesPerPrompt
|
|
10705
|
+
});
|
|
10706
|
+
return images;
|
|
10707
|
+
} catch (error) {
|
|
10708
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
10709
|
+
telemetry.emit({
|
|
10710
|
+
type: "llm.call.completed",
|
|
10711
|
+
success: false,
|
|
10712
|
+
durationMs: Math.max(0, Date.now() - startedAtMs),
|
|
10713
|
+
usage: totalUsage,
|
|
10714
|
+
costUsd,
|
|
10715
|
+
imageCount: outputImages,
|
|
10716
|
+
error: err.message
|
|
10717
|
+
});
|
|
10718
|
+
throw err;
|
|
10719
|
+
} finally {
|
|
10720
|
+
await telemetry.flush();
|
|
10721
|
+
}
|
|
10722
|
+
}
|
|
10500
10723
|
async function generateImages(request) {
|
|
10501
10724
|
if (isOpenAiGenerateImagesRequest(request)) {
|
|
10502
10725
|
return await generateImagesWithOpenAiImageApi(request);
|
|
10503
10726
|
}
|
|
10727
|
+
if (isChatGptGenerateImagesRequest(request)) {
|
|
10728
|
+
return await generateImagesWithChatGptImageTool(request);
|
|
10729
|
+
}
|
|
10504
10730
|
const maxAttempts = Math.max(1, Math.floor(request.maxAttempts ?? 4));
|
|
10505
10731
|
const promptList = Array.from(request.imagePrompts);
|
|
10506
10732
|
if (promptList.length === 0) {
|
|
@@ -10782,6 +11008,104 @@ function appendMarkdownSourcesSection(value, sources) {
|
|
|
10782
11008
|
${lines}`;
|
|
10783
11009
|
}
|
|
10784
11010
|
|
|
11011
|
+
// src/openai/containers.ts
|
|
11012
|
+
import { toFile as toFile2 } from "openai";
|
|
11013
|
+
function toOpenAiContainerNetworkPolicy(policy) {
|
|
11014
|
+
if (!policy) {
|
|
11015
|
+
return void 0;
|
|
11016
|
+
}
|
|
11017
|
+
if (policy.type === "disabled") {
|
|
11018
|
+
return { type: "disabled" };
|
|
11019
|
+
}
|
|
11020
|
+
return {
|
|
11021
|
+
type: "allowlist",
|
|
11022
|
+
allowed_domains: Array.from(policy.allowedDomains),
|
|
11023
|
+
...policy.domainSecrets ? {
|
|
11024
|
+
domain_secrets: policy.domainSecrets.map((secret) => ({
|
|
11025
|
+
domain: secret.domain,
|
|
11026
|
+
name: secret.name,
|
|
11027
|
+
value: secret.value
|
|
11028
|
+
}))
|
|
11029
|
+
} : {}
|
|
11030
|
+
};
|
|
11031
|
+
}
|
|
11032
|
+
function toContainer(container) {
|
|
11033
|
+
return {
|
|
11034
|
+
id: String(container.id),
|
|
11035
|
+
name: typeof container.name === "string" ? container.name : "",
|
|
11036
|
+
status: typeof container.status === "string" ? container.status : "",
|
|
11037
|
+
...typeof container.created_at === "number" ? { createdAt: container.created_at } : {},
|
|
11038
|
+
...typeof container.last_active_at === "number" ? { lastActiveAt: container.last_active_at } : {},
|
|
11039
|
+
...typeof container.memory_limit === "string" ? { memoryLimit: container.memory_limit } : {}
|
|
11040
|
+
};
|
|
11041
|
+
}
|
|
11042
|
+
function toContainerFile(file) {
|
|
11043
|
+
return {
|
|
11044
|
+
id: String(file.id),
|
|
11045
|
+
containerId: typeof file.container_id === "string" ? file.container_id : "",
|
|
11046
|
+
path: typeof file.path === "string" ? file.path : "",
|
|
11047
|
+
...typeof file.bytes === "number" || file.bytes === null ? { bytes: file.bytes } : {},
|
|
11048
|
+
...typeof file.created_at === "number" ? { createdAt: file.created_at } : {},
|
|
11049
|
+
...typeof file.source === "string" ? { source: file.source } : {}
|
|
11050
|
+
};
|
|
11051
|
+
}
|
|
11052
|
+
async function createOpenAiContainer(options) {
|
|
11053
|
+
const container = await runOpenAiCall(
|
|
11054
|
+
async (client) => await client.containers.create({
|
|
11055
|
+
name: options.name,
|
|
11056
|
+
...options.fileIds ? { file_ids: Array.from(options.fileIds) } : {},
|
|
11057
|
+
...options.memoryLimit ? { memory_limit: options.memoryLimit } : {},
|
|
11058
|
+
...options.networkPolicy ? { network_policy: toOpenAiContainerNetworkPolicy(options.networkPolicy) } : {},
|
|
11059
|
+
...options.expiresAfterMinutes ? {
|
|
11060
|
+
expires_after: {
|
|
11061
|
+
anchor: "last_active_at",
|
|
11062
|
+
minutes: options.expiresAfterMinutes
|
|
11063
|
+
}
|
|
11064
|
+
} : {}
|
|
11065
|
+
}),
|
|
11066
|
+
"openai-containers"
|
|
11067
|
+
);
|
|
11068
|
+
return toContainer(container);
|
|
11069
|
+
}
|
|
11070
|
+
async function deleteOpenAiContainer(containerId) {
|
|
11071
|
+
await runOpenAiCall(
|
|
11072
|
+
async (client) => await client.containers.delete(containerId),
|
|
11073
|
+
"openai-containers"
|
|
11074
|
+
);
|
|
11075
|
+
}
|
|
11076
|
+
async function listOpenAiContainerFiles(containerId) {
|
|
11077
|
+
const files2 = [];
|
|
11078
|
+
await runOpenAiCall(async (client) => {
|
|
11079
|
+
for await (const file of client.containers.files.list(containerId)) {
|
|
11080
|
+
files2.push(toContainerFile(file));
|
|
11081
|
+
}
|
|
11082
|
+
}, "openai-containers");
|
|
11083
|
+
return files2;
|
|
11084
|
+
}
|
|
11085
|
+
async function uploadOpenAiContainerFile(upload) {
|
|
11086
|
+
const file = await toFile2(upload.data, upload.filename, {
|
|
11087
|
+
...upload.mimeType ? { type: upload.mimeType } : {}
|
|
11088
|
+
});
|
|
11089
|
+
const created = await runOpenAiCall(
|
|
11090
|
+
async (client) => await client.containers.files.create(upload.containerId, { file }),
|
|
11091
|
+
"openai-containers"
|
|
11092
|
+
);
|
|
11093
|
+
return toContainerFile(created);
|
|
11094
|
+
}
|
|
11095
|
+
async function downloadOpenAiContainerFile(params) {
|
|
11096
|
+
const response = await runOpenAiCall(
|
|
11097
|
+
async (client) => await client.containers.files.content.retrieve(params.fileId, {
|
|
11098
|
+
container_id: params.containerId
|
|
11099
|
+
}),
|
|
11100
|
+
"openai-containers"
|
|
11101
|
+
);
|
|
11102
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
11103
|
+
}
|
|
11104
|
+
async function downloadOpenAiContainerFileText(params) {
|
|
11105
|
+
const bytes = await downloadOpenAiContainerFile(params);
|
|
11106
|
+
return new TextDecoder().decode(bytes);
|
|
11107
|
+
}
|
|
11108
|
+
|
|
10785
11109
|
// src/agent.ts
|
|
10786
11110
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
10787
11111
|
import path9 from "path";
|
|
@@ -14527,6 +14851,7 @@ async function runCandidateEvolution(options) {
|
|
|
14527
14851
|
};
|
|
14528
14852
|
}
|
|
14529
14853
|
export {
|
|
14854
|
+
CHATGPT_IMAGE_MODEL_IDS,
|
|
14530
14855
|
CHATGPT_MODEL_IDS,
|
|
14531
14856
|
CODEX_APPLY_PATCH_FREEFORM_TOOL_DESCRIPTION,
|
|
14532
14857
|
CODEX_APPLY_PATCH_JSON_TOOL_DESCRIPTION,
|
|
@@ -14580,12 +14905,16 @@ export {
|
|
|
14580
14905
|
createListDirectoryTool,
|
|
14581
14906
|
createModelAgnosticFilesystemToolSet,
|
|
14582
14907
|
createNodeAgentFilesystem,
|
|
14908
|
+
createOpenAiContainer,
|
|
14583
14909
|
createReplaceTool,
|
|
14584
14910
|
createRgSearchTool,
|
|
14585
14911
|
createToolLoopSteeringChannel,
|
|
14586
14912
|
createViewImageTool,
|
|
14587
14913
|
createWriteFileTool,
|
|
14588
14914
|
customTool,
|
|
14915
|
+
deleteOpenAiContainer,
|
|
14916
|
+
downloadOpenAiContainerFile,
|
|
14917
|
+
downloadOpenAiContainerFileText,
|
|
14589
14918
|
emptyFileUploadMetrics,
|
|
14590
14919
|
encodeChatGptAuthJson,
|
|
14591
14920
|
encodeChatGptAuthJsonB64,
|
|
@@ -14598,6 +14927,7 @@ export {
|
|
|
14598
14927
|
generateText,
|
|
14599
14928
|
getChatGptAuthProfile,
|
|
14600
14929
|
getCurrentToolCallContext,
|
|
14930
|
+
isChatGptImageModelId,
|
|
14601
14931
|
isChatGptModelId,
|
|
14602
14932
|
isExperimentalChatGptModelId,
|
|
14603
14933
|
isFireworksModelId,
|
|
@@ -14609,12 +14939,14 @@ export {
|
|
|
14609
14939
|
isLlmTextModelId,
|
|
14610
14940
|
isOpenAiImageModelId,
|
|
14611
14941
|
isOpenAiModelId,
|
|
14942
|
+
listOpenAiContainerFiles,
|
|
14612
14943
|
loadEnvFromFile,
|
|
14613
14944
|
loadLocalEnv,
|
|
14614
14945
|
parseJsonFromLlmText,
|
|
14615
14946
|
refreshChatGptOauthToken,
|
|
14616
14947
|
resetModelConcurrencyConfig,
|
|
14617
14948
|
resetTelemetry,
|
|
14949
|
+
resolveChatGptImageProviderModel,
|
|
14618
14950
|
resolveFilesystemToolProfile,
|
|
14619
14951
|
resolveFireworksModelId,
|
|
14620
14952
|
runAgentLoop,
|
|
@@ -14628,6 +14960,7 @@ export {
|
|
|
14628
14960
|
stripCodexCitationMarkers,
|
|
14629
14961
|
toGeminiJsonSchema,
|
|
14630
14962
|
tool,
|
|
14963
|
+
uploadOpenAiContainerFile,
|
|
14631
14964
|
validateOpenAiGptImage2Resolution
|
|
14632
14965
|
};
|
|
14633
14966
|
//# sourceMappingURL=index.js.map
|