@use-lattice/litmus 0.121.3
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/LICENSE +19 -0
- package/dist/src/accounts-Bt1oJb1Z.cjs +219 -0
- package/dist/src/accounts-DjOU8Rm3.js +178 -0
- package/dist/src/agentic-utils-D03IiXQc.js +153 -0
- package/dist/src/agentic-utils-Dh7xaMQM.cjs +180 -0
- package/dist/src/agents-C6BIMlZa.js +231 -0
- package/dist/src/agents-DvIpNX1L.cjs +666 -0
- package/dist/src/agents-ZP0RP9vV.cjs +231 -0
- package/dist/src/agents-maJXdjbR.js +665 -0
- package/dist/src/aimlapi-BTbQjG2E.cjs +30 -0
- package/dist/src/aimlapi-CwMxqfXP.js +30 -0
- package/dist/src/audio-BBUdvsde.cjs +97 -0
- package/dist/src/audio-D5DPZ7I-.js +97 -0
- package/dist/src/base-BEysXrkq.cjs +222 -0
- package/dist/src/base-C451JQfq.js +193 -0
- package/dist/src/blobs-BY8MDmpo.js +230 -0
- package/dist/src/blobs-BgcNn97m.cjs +256 -0
- package/dist/src/cache-BBE_lsTA.cjs +4 -0
- package/dist/src/cache-BkrqU5Ba.js +237 -0
- package/dist/src/cache-DsCxFlsZ.cjs +297 -0
- package/dist/src/chat-CPJWDP6a.cjs +289 -0
- package/dist/src/chat-CXX3xzkk.cjs +811 -0
- package/dist/src/chat-CcDgZFJ4.js +787 -0
- package/dist/src/chat-Dz5ZeGO2.js +289 -0
- package/dist/src/chatkit-Dw0mKkML.cjs +1158 -0
- package/dist/src/chatkit-swAIVuea.js +1157 -0
- package/dist/src/chunk-DEq-mXcV.js +15 -0
- package/dist/src/claude-agent-sdk-BXZJtOg6.js +379 -0
- package/dist/src/claude-agent-sdk-CkfyjDoG.cjs +383 -0
- package/dist/src/cloudflare-ai-BzpJcqUH.js +161 -0
- package/dist/src/cloudflare-ai-Cmy_R1y2.cjs +161 -0
- package/dist/src/cloudflare-gateway-B9tVQKok.cjs +272 -0
- package/dist/src/cloudflare-gateway-DrD3ew3H.js +272 -0
- package/dist/src/codex-sdk-Dezj9Nwm.js +1056 -0
- package/dist/src/codex-sdk-Dl9D4k5B.cjs +1060 -0
- package/dist/src/cometapi-C-9YvCHC.js +54 -0
- package/dist/src/cometapi-DHgDKoO2.cjs +54 -0
- package/dist/src/completion-B8Ctyxpr.js +120 -0
- package/dist/src/completion-Cxrt08sj.cjs +131 -0
- package/dist/src/createHash-BwgE13yv.cjs +27 -0
- package/dist/src/createHash-DmPQkvBh.js +15 -0
- package/dist/src/docker-BiqcTwLv.js +80 -0
- package/dist/src/docker-C7tEJnP-.cjs +80 -0
- package/dist/src/esm-C62Zofr1.cjs +409 -0
- package/dist/src/esm-DMVc93eh.js +379 -0
- package/dist/src/evalResult-C3NJPQOo.cjs +301 -0
- package/dist/src/evalResult-C7JJAPBb.js +295 -0
- package/dist/src/evalResult-DoVTZZWI.cjs +2 -0
- package/dist/src/extractor-DnMD3fwt.cjs +391 -0
- package/dist/src/extractor-DtlL28vL.js +374 -0
- package/dist/src/fetch-BTxakTSg.cjs +1133 -0
- package/dist/src/fetch-DQckpUFz.js +928 -0
- package/dist/src/fileExtensions-DnqA1y9x.js +85 -0
- package/dist/src/fileExtensions-bYh77CN8.cjs +114 -0
- package/dist/src/genaiTracer-CyZrmaK0.cjs +268 -0
- package/dist/src/genaiTracer-D3fD9dNV.js +256 -0
- package/dist/src/graders-BNscxFrU.js +13644 -0
- package/dist/src/graders-D2oE9Msq.js +2 -0
- package/dist/src/graders-c0Ez_w-9.cjs +2 -0
- package/dist/src/graders-d0F2M3e9.cjs +14056 -0
- package/dist/src/image-0ZhE0VlR.cjs +280 -0
- package/dist/src/image-CWE1pdNv.js +257 -0
- package/dist/src/image-D9ZK6hwL.js +163 -0
- package/dist/src/image-DKZgZITg.cjs +163 -0
- package/dist/src/index.cjs +11366 -0
- package/dist/src/index.d.cts +19640 -0
- package/dist/src/index.d.ts +19641 -0
- package/dist/src/index.js +11306 -0
- package/dist/src/invariant-Ddh24eXh.js +25 -0
- package/dist/src/invariant-kfQ8Bu82.cjs +30 -0
- package/dist/src/knowledgeBase-BgPyGFUd.cjs +122 -0
- package/dist/src/knowledgeBase-DyHilYaP.js +122 -0
- package/dist/src/litellm-CyMeneHS.js +135 -0
- package/dist/src/litellm-DWDF73yF.cjs +135 -0
- package/dist/src/logger-C40ZGil9.js +717 -0
- package/dist/src/logger-DyfK9PBt.cjs +917 -0
- package/dist/src/luma-ray-BAU9X_ep.cjs +315 -0
- package/dist/src/luma-ray-nwVseBbv.js +313 -0
- package/dist/src/messages-B5ADWTTv.js +245 -0
- package/dist/src/messages-BCnZfqrS.cjs +257 -0
- package/dist/src/meteor-DLZZ3osF.cjs +134 -0
- package/dist/src/meteor-DUiCJRC-.js +134 -0
- package/dist/src/modelslab-00cveB8L.cjs +163 -0
- package/dist/src/modelslab-D9sCU_L7.js +163 -0
- package/dist/src/nova-reel-CTapvqYH.js +276 -0
- package/dist/src/nova-reel-DlWuuroF.cjs +278 -0
- package/dist/src/nova-sonic-5UPWfeMv.cjs +363 -0
- package/dist/src/nova-sonic-BhSwQNym.js +363 -0
- package/dist/src/openai-BWrJK9d8.cjs +52 -0
- package/dist/src/openai-DumO8WQn.js +47 -0
- package/dist/src/openclaw-B8brrjC_.cjs +577 -0
- package/dist/src/openclaw-Bkayww9q.js +571 -0
- package/dist/src/opencode-sdk-7xjoDNiM.cjs +562 -0
- package/dist/src/opencode-sdk-SGwAPxht.js +558 -0
- package/dist/src/otlpReceiver-CoAHfAN9.cjs +15 -0
- package/dist/src/otlpReceiver-oO3EQwI9.js +14 -0
- package/dist/src/providerRegistry-4yjhaEM8.js +45 -0
- package/dist/src/providerRegistry-DhV4rJIc.cjs +50 -0
- package/dist/src/providers-B5RJVG-7.cjs +33609 -0
- package/dist/src/providers-BdmZCLzV.js +33262 -0
- package/dist/src/providers-CxtRxn8e.js +2 -0
- package/dist/src/providers-DnQLNbx1.cjs +3 -0
- package/dist/src/pythonUtils-BD0druiM.cjs +275 -0
- package/dist/src/pythonUtils-IBhn5YGR.js +249 -0
- package/dist/src/quiverai-BDOwZBsM.cjs +213 -0
- package/dist/src/quiverai-D3JTF5lD.js +213 -0
- package/dist/src/responses-B2LCDCXZ.js +667 -0
- package/dist/src/responses-BvNm4Xv9.cjs +685 -0
- package/dist/src/rubyUtils-B0NwnfpY.cjs +245 -0
- package/dist/src/rubyUtils-BroxzZ7c.cjs +2 -0
- package/dist/src/rubyUtils-hqVw5UvJ.js +222 -0
- package/dist/src/sagemaker-Cno2V-Sx.js +689 -0
- package/dist/src/sagemaker-fV_KUgs5.cjs +691 -0
- package/dist/src/server-BOuAXb06.cjs +238 -0
- package/dist/src/server-CtI-EWzm.cjs +2 -0
- package/dist/src/server-Cy3DZymt.js +189 -0
- package/dist/src/slack-CP8xBePa.js +135 -0
- package/dist/src/slack-DSQ1yXVb.cjs +135 -0
- package/dist/src/store-BwDDaBjb.cjs +246 -0
- package/dist/src/store-DcbLC593.cjs +2 -0
- package/dist/src/store-IGpqMIkv.js +240 -0
- package/dist/src/tables-3Q2cL7So.cjs +373 -0
- package/dist/src/tables-Bi2fjr4W.js +288 -0
- package/dist/src/telemetry-Bg2WqF79.js +161 -0
- package/dist/src/telemetry-D0x6u5kX.cjs +166 -0
- package/dist/src/telemetry-DXNimrI0.cjs +2 -0
- package/dist/src/text-B_UCRPp2.js +22 -0
- package/dist/src/text-CW1cyrwj.cjs +33 -0
- package/dist/src/tokenUsageUtils-NYT-WKS6.js +138 -0
- package/dist/src/tokenUsageUtils-bVa1ga6f.cjs +173 -0
- package/dist/src/transcription-Cl_W16Pr.js +122 -0
- package/dist/src/transcription-yt1EecY8.cjs +124 -0
- package/dist/src/transform-BCtGrl_W.cjs +228 -0
- package/dist/src/transform-Bv6gG2MJ.cjs +1688 -0
- package/dist/src/transform-CY1wbpRy.js +1507 -0
- package/dist/src/transform-DU8rUL9P.cjs +2 -0
- package/dist/src/transform-yWaShiKr.js +216 -0
- package/dist/src/transformersAvailability-BGkzavwb.js +35 -0
- package/dist/src/transformersAvailability-DKoRtQLy.cjs +35 -0
- package/dist/src/types-5aqHpBwE.cjs +3769 -0
- package/dist/src/types-Bn6D9c4U.js +3300 -0
- package/dist/src/util-BkKlTkI2.js +293 -0
- package/dist/src/util-CTh0bfOm.cjs +1119 -0
- package/dist/src/util-D17oBwo7.cjs +328 -0
- package/dist/src/util-DsS_-v4p.js +613 -0
- package/dist/src/util-DuntT1Ga.js +951 -0
- package/dist/src/util-aWjdCYMI.cjs +667 -0
- package/dist/src/utils-CisQwpjA.js +94 -0
- package/dist/src/utils-yWamDvmz.cjs +123 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/drizzle/0000_lush_hellion.sql +36 -0
- package/drizzle/0001_wide_calypso.sql +3 -0
- package/drizzle/0002_tidy_juggernaut.sql +1 -0
- package/drizzle/0003_lively_naoko.sql +8 -0
- package/drizzle/0004_minor_peter_quill.sql +19 -0
- package/drizzle/0005_silky_millenium_guard.sql +2 -0
- package/drizzle/0006_harsh_caretaker.sql +42 -0
- package/drizzle/0007_cloudy_wong.sql +1 -0
- package/drizzle/0008_broad_boomer.sql +2 -0
- package/drizzle/0009_strong_marten_broadcloak.sql +19 -0
- package/drizzle/0010_needy_bishop.sql +11 -0
- package/drizzle/0011_moaning_millenium_guard.sql +1 -0
- package/drizzle/0012_late_marten_broadcloak.sql +2 -0
- package/drizzle/0013_previous_dormammu.sql +9 -0
- package/drizzle/0014_lazy_captain_universe.sql +2 -0
- package/drizzle/0015_zippy_wallop.sql +29 -0
- package/drizzle/0016_jazzy_zemo.sql +2 -0
- package/drizzle/0017_reflective_praxagora.sql +4 -0
- package/drizzle/0018_fat_vanisher.sql +22 -0
- package/drizzle/0019_new_clint_barton.sql +8 -0
- package/drizzle/0020_skinny_maverick.sql +1 -0
- package/drizzle/0021_mysterious_madelyne_pryor.sql +13 -0
- package/drizzle/0022_sleepy_ultimo.sql +25 -0
- package/drizzle/0023_wooden_mandrill.sql +2 -0
- package/drizzle/AGENTS.md +68 -0
- package/drizzle/CLAUDE.md +1 -0
- package/drizzle/meta/0000_snapshot.json +221 -0
- package/drizzle/meta/0001_snapshot.json +214 -0
- package/drizzle/meta/0002_snapshot.json +221 -0
- package/drizzle/meta/0005_snapshot.json +369 -0
- package/drizzle/meta/0006_snapshot.json +638 -0
- package/drizzle/meta/0007_snapshot.json +640 -0
- package/drizzle/meta/0008_snapshot.json +649 -0
- package/drizzle/meta/0009_snapshot.json +554 -0
- package/drizzle/meta/0010_snapshot.json +619 -0
- package/drizzle/meta/0011_snapshot.json +627 -0
- package/drizzle/meta/0012_snapshot.json +639 -0
- package/drizzle/meta/0013_snapshot.json +717 -0
- package/drizzle/meta/0014_snapshot.json +717 -0
- package/drizzle/meta/0015_snapshot.json +897 -0
- package/drizzle/meta/0016_snapshot.json +1031 -0
- package/drizzle/meta/0018_snapshot.json +1210 -0
- package/drizzle/meta/0019_snapshot.json +1165 -0
- package/drizzle/meta/0020_snapshot.json +1232 -0
- package/drizzle/meta/0021_snapshot.json +1311 -0
- package/drizzle/meta/0022_snapshot.json +1481 -0
- package/drizzle/meta/0023_snapshot.json +1496 -0
- package/drizzle/meta/_journal.json +174 -0
- package/package.json +240 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
const require_logger = require("./logger-DyfK9PBt.cjs");
|
|
2
|
+
const require_fetch = require("./fetch-BTxakTSg.cjs");
|
|
3
|
+
const require_cache = require("./cache-DsCxFlsZ.cjs");
|
|
4
|
+
const require_openai = require("./openai-BWrJK9d8.cjs");
|
|
5
|
+
const require_util = require("./util-aWjdCYMI.cjs");
|
|
6
|
+
const require_text = require("./text-CW1cyrwj.cjs");
|
|
7
|
+
//#region src/providers/openai/image.ts
|
|
8
|
+
const DALLE2_VALID_SIZES = [
|
|
9
|
+
"256x256",
|
|
10
|
+
"512x512",
|
|
11
|
+
"1024x1024"
|
|
12
|
+
];
|
|
13
|
+
const DALLE3_VALID_SIZES = [
|
|
14
|
+
"1024x1024",
|
|
15
|
+
"1792x1024",
|
|
16
|
+
"1024x1792"
|
|
17
|
+
];
|
|
18
|
+
const GPT_IMAGE1_VALID_SIZES = [
|
|
19
|
+
"1024x1024",
|
|
20
|
+
"1024x1536",
|
|
21
|
+
"1536x1024"
|
|
22
|
+
];
|
|
23
|
+
const DEFAULT_SIZE = "1024x1024";
|
|
24
|
+
const DALLE2_COSTS = {
|
|
25
|
+
"256x256": .016,
|
|
26
|
+
"512x512": .018,
|
|
27
|
+
"1024x1024": .02
|
|
28
|
+
};
|
|
29
|
+
const DALLE3_COSTS = {
|
|
30
|
+
standard_1024x1024: .04,
|
|
31
|
+
standard_1024x1792: .08,
|
|
32
|
+
standard_1792x1024: .08,
|
|
33
|
+
hd_1024x1024: .08,
|
|
34
|
+
hd_1024x1792: .12,
|
|
35
|
+
hd_1792x1024: .12
|
|
36
|
+
};
|
|
37
|
+
const GPT_IMAGE1_COSTS = {
|
|
38
|
+
low_1024x1024: .011,
|
|
39
|
+
low_1024x1536: .016,
|
|
40
|
+
low_1536x1024: .016,
|
|
41
|
+
medium_1024x1024: .042,
|
|
42
|
+
medium_1024x1536: .063,
|
|
43
|
+
medium_1536x1024: .063,
|
|
44
|
+
high_1024x1024: .167,
|
|
45
|
+
high_1024x1536: .25,
|
|
46
|
+
high_1536x1024: .25
|
|
47
|
+
};
|
|
48
|
+
const GPT_IMAGE1_MINI_COSTS = {
|
|
49
|
+
low_1024x1024: .005,
|
|
50
|
+
low_1024x1536: .006,
|
|
51
|
+
low_1536x1024: .006,
|
|
52
|
+
medium_1024x1024: .011,
|
|
53
|
+
medium_1024x1536: .015,
|
|
54
|
+
medium_1536x1024: .015,
|
|
55
|
+
high_1024x1024: .036,
|
|
56
|
+
high_1024x1536: .052,
|
|
57
|
+
high_1536x1024: .052
|
|
58
|
+
};
|
|
59
|
+
const GPT_IMAGE1_5_COSTS = {
|
|
60
|
+
low_1024x1024: .064,
|
|
61
|
+
low_1024x1536: .096,
|
|
62
|
+
low_1536x1024: .096,
|
|
63
|
+
medium_1024x1024: .128,
|
|
64
|
+
medium_1024x1536: .192,
|
|
65
|
+
medium_1536x1024: .192,
|
|
66
|
+
high_1024x1024: .192,
|
|
67
|
+
high_1024x1536: .288,
|
|
68
|
+
high_1536x1024: .288
|
|
69
|
+
};
|
|
70
|
+
function isGptImage1(model) {
|
|
71
|
+
return model === "gpt-image-1" || model.startsWith("gpt-image-1-2025");
|
|
72
|
+
}
|
|
73
|
+
function isGptImage1Mini(model) {
|
|
74
|
+
return model === "gpt-image-1-mini" || model.startsWith("gpt-image-1-mini-2025");
|
|
75
|
+
}
|
|
76
|
+
function isGptImage15(model) {
|
|
77
|
+
return model === "gpt-image-1.5" || model.startsWith("gpt-image-1.5-2025");
|
|
78
|
+
}
|
|
79
|
+
function isGptImageModel(model) {
|
|
80
|
+
return isGptImage1(model) || isGptImage1Mini(model) || isGptImage15(model);
|
|
81
|
+
}
|
|
82
|
+
function validateSizeForModel(size, model) {
|
|
83
|
+
if (model === "dall-e-3" && !DALLE3_VALID_SIZES.includes(size)) return {
|
|
84
|
+
valid: false,
|
|
85
|
+
message: `Invalid size "${size}" for DALL-E 3. Valid sizes are: ${DALLE3_VALID_SIZES.join(", ")}`
|
|
86
|
+
};
|
|
87
|
+
if (model === "dall-e-2" && !DALLE2_VALID_SIZES.includes(size)) return {
|
|
88
|
+
valid: false,
|
|
89
|
+
message: `Invalid size "${size}" for DALL-E 2. Valid sizes are: ${DALLE2_VALID_SIZES.join(", ")}`
|
|
90
|
+
};
|
|
91
|
+
if (isGptImageModel(model) && size !== "auto" && !GPT_IMAGE1_VALID_SIZES.includes(size)) {
|
|
92
|
+
let modelName = model;
|
|
93
|
+
if (isGptImage15(model)) modelName = "GPT Image 1.5";
|
|
94
|
+
else if (isGptImage1Mini(model)) modelName = "GPT Image 1 Mini";
|
|
95
|
+
else if (isGptImage1(model)) modelName = "GPT Image 1";
|
|
96
|
+
return {
|
|
97
|
+
valid: false,
|
|
98
|
+
message: `Invalid size "${size}" for ${modelName}. Valid sizes are: ${GPT_IMAGE1_VALID_SIZES.join(", ")}, auto`
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return { valid: true };
|
|
102
|
+
}
|
|
103
|
+
function getMimeTypeForOutputFormat(outputFormat) {
|
|
104
|
+
switch (outputFormat) {
|
|
105
|
+
case "jpeg": return "image/jpeg";
|
|
106
|
+
case "webp": return "image/webp";
|
|
107
|
+
default: return "image/png";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function inferMimeTypeFromUrl(url) {
|
|
111
|
+
try {
|
|
112
|
+
const pathname = new URL(url).pathname.toLowerCase();
|
|
113
|
+
if (pathname.endsWith(".jpg") || pathname.endsWith(".jpeg")) return "image/jpeg";
|
|
114
|
+
if (pathname.endsWith(".webp")) return "image/webp";
|
|
115
|
+
if (pathname.endsWith(".gif")) return "image/gif";
|
|
116
|
+
if (pathname.endsWith(".svg")) return "image/svg+xml";
|
|
117
|
+
if (pathname.endsWith(".png")) return "image/png";
|
|
118
|
+
} catch {}
|
|
119
|
+
}
|
|
120
|
+
function buildStructuredImageOutputs(data, outputFormat) {
|
|
121
|
+
if (!Array.isArray(data.data) || data.data.length === 0) return;
|
|
122
|
+
return data.data.map((item) => {
|
|
123
|
+
if (item.b64_json) {
|
|
124
|
+
const mimeType = getMimeTypeForOutputFormat(outputFormat);
|
|
125
|
+
return {
|
|
126
|
+
data: `data:${mimeType};base64,${item.b64_json}`,
|
|
127
|
+
mimeType
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (item.url) {
|
|
131
|
+
const mimeType = inferMimeTypeFromUrl(item.url);
|
|
132
|
+
return mimeType ? {
|
|
133
|
+
data: item.url,
|
|
134
|
+
mimeType
|
|
135
|
+
} : { data: item.url };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}).filter((item) => item !== null);
|
|
139
|
+
}
|
|
140
|
+
function formatOutput(data, prompt, responseFormat, outputFormat) {
|
|
141
|
+
if (responseFormat === "b64_json") {
|
|
142
|
+
const b64Json = data.data[0].b64_json;
|
|
143
|
+
if (!b64Json) return { error: `No base64 image data found in response: ${JSON.stringify(data)}` };
|
|
144
|
+
return `data:${getMimeTypeForOutputFormat(outputFormat)};base64,${b64Json}`;
|
|
145
|
+
} else {
|
|
146
|
+
const url = data.data[0].url;
|
|
147
|
+
if (!url) return { error: `No image URL found in response: ${JSON.stringify(data)}` };
|
|
148
|
+
return `![${require_text.ellipsize(prompt.replace(/\r?\n|\r/g, " ").replace(/\[/g, "(").replace(/\]/g, ")"), 50)}](${url})`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function prepareRequestBody(model, prompt, size, responseFormat, config) {
|
|
152
|
+
const body = {
|
|
153
|
+
model,
|
|
154
|
+
prompt,
|
|
155
|
+
n: config.n || 1,
|
|
156
|
+
size
|
|
157
|
+
};
|
|
158
|
+
if (!isGptImageModel(model)) body.response_format = responseFormat;
|
|
159
|
+
if (model === "dall-e-3") {
|
|
160
|
+
if ("quality" in config && config.quality) body.quality = config.quality;
|
|
161
|
+
if ("style" in config && config.style) body.style = config.style;
|
|
162
|
+
}
|
|
163
|
+
if (isGptImageModel(model)) {
|
|
164
|
+
if ("quality" in config && config.quality) body.quality = config.quality;
|
|
165
|
+
if ("background" in config && config.background) body.background = config.background;
|
|
166
|
+
if ("output_format" in config && config.output_format) body.output_format = config.output_format;
|
|
167
|
+
if ("output_compression" in config && config.output_compression !== void 0) body.output_compression = config.output_compression;
|
|
168
|
+
if ("moderation" in config && config.moderation) body.moderation = config.moderation;
|
|
169
|
+
}
|
|
170
|
+
return body;
|
|
171
|
+
}
|
|
172
|
+
function calculateImageCost(model, size, quality, n = 1) {
|
|
173
|
+
const imageQuality = quality || "standard";
|
|
174
|
+
if (model === "dall-e-3") return (DALLE3_COSTS[`${imageQuality}_${size}`] || DALLE3_COSTS["standard_1024x1024"]) * n;
|
|
175
|
+
else if (model === "dall-e-2") return (DALLE2_COSTS[size] || DALLE2_COSTS["1024x1024"]) * n;
|
|
176
|
+
else if (isGptImage1(model)) return (GPT_IMAGE1_COSTS[`${quality || "low"}_${size}`] || GPT_IMAGE1_COSTS["low_1024x1024"]) * n;
|
|
177
|
+
else if (isGptImage1Mini(model)) return (GPT_IMAGE1_MINI_COSTS[`${quality || "low"}_${size}`] || GPT_IMAGE1_MINI_COSTS["low_1024x1024"]) * n;
|
|
178
|
+
else if (isGptImage15(model)) return (GPT_IMAGE1_5_COSTS[`${quality || "low"}_${size}`] || GPT_IMAGE1_5_COSTS["low_1024x1024"]) * n;
|
|
179
|
+
return .04 * n;
|
|
180
|
+
}
|
|
181
|
+
async function callOpenAiImageApi(url, body, headers, timeout) {
|
|
182
|
+
return await require_cache.fetchWithCache(url, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers,
|
|
185
|
+
body: JSON.stringify(body)
|
|
186
|
+
}, timeout);
|
|
187
|
+
}
|
|
188
|
+
async function processApiResponse(data, prompt, responseFormat, cached, model, size, latencyMs, quality, n = 1, outputFormat) {
|
|
189
|
+
if (data.error) {
|
|
190
|
+
await data?.deleteFromCache?.();
|
|
191
|
+
return { error: require_util.formatOpenAiError(data) };
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const formattedOutput = formatOutput(data, prompt, responseFormat, outputFormat);
|
|
195
|
+
if (typeof formattedOutput === "object") return formattedOutput;
|
|
196
|
+
const cost = cached ? 0 : calculateImageCost(model, size, quality, n);
|
|
197
|
+
return {
|
|
198
|
+
output: formattedOutput,
|
|
199
|
+
images: buildStructuredImageOutputs(data, outputFormat),
|
|
200
|
+
cached,
|
|
201
|
+
latencyMs,
|
|
202
|
+
cost,
|
|
203
|
+
...responseFormat === "b64_json" ? {
|
|
204
|
+
isBase64: true,
|
|
205
|
+
format: "json"
|
|
206
|
+
} : {}
|
|
207
|
+
};
|
|
208
|
+
} catch (err) {
|
|
209
|
+
await data?.deleteFromCache?.();
|
|
210
|
+
return { error: `API error: ${String(err)}: ${JSON.stringify(data)}` };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var OpenAiImageProvider = class extends require_openai.OpenAiGenericProvider {
|
|
214
|
+
config;
|
|
215
|
+
constructor(modelName, options = {}) {
|
|
216
|
+
super(modelName, options);
|
|
217
|
+
this.config = options.config || {};
|
|
218
|
+
}
|
|
219
|
+
async callApi(prompt, context, _callApiOptions) {
|
|
220
|
+
if (this.requiresApiKey() && !this.getApiKey()) throw new Error(this.getMissingApiKeyErrorMessage());
|
|
221
|
+
const config = {
|
|
222
|
+
...this.config,
|
|
223
|
+
...context?.prompt?.config
|
|
224
|
+
};
|
|
225
|
+
const model = config.model || this.modelName;
|
|
226
|
+
const operation = "operation" in config && config.operation || "generation";
|
|
227
|
+
const responseFormat = isGptImageModel(model) ? "b64_json" : config.response_format || "url";
|
|
228
|
+
if (operation !== "generation") return { error: `Only 'generation' operations are currently supported. '${operation}' operations are not implemented.` };
|
|
229
|
+
const endpoint = "/images/generations";
|
|
230
|
+
const size = config.size || DEFAULT_SIZE;
|
|
231
|
+
const sizeValidation = validateSizeForModel(size, model);
|
|
232
|
+
if (!sizeValidation.valid) return { error: sizeValidation.message };
|
|
233
|
+
const body = prepareRequestBody(model, prompt, size, responseFormat, config);
|
|
234
|
+
const headers = {
|
|
235
|
+
"Content-Type": "application/json",
|
|
236
|
+
...this.getApiKey() ? { Authorization: `Bearer ${this.getApiKey()}` } : {},
|
|
237
|
+
...this.getOrganization() ? { "OpenAI-Organization": this.getOrganization() } : {},
|
|
238
|
+
...config.headers
|
|
239
|
+
};
|
|
240
|
+
let data, status, statusText;
|
|
241
|
+
let cached = false;
|
|
242
|
+
let latencyMs;
|
|
243
|
+
try {
|
|
244
|
+
({data, cached, status, statusText, latencyMs} = await callOpenAiImageApi(`${this.getApiUrl()}${endpoint}`, body, headers, require_fetch.REQUEST_TIMEOUT_MS));
|
|
245
|
+
if (status < 200 || status >= 300) return { error: `API error: ${status} ${statusText}\n${typeof data === "string" ? data : JSON.stringify(data)}` };
|
|
246
|
+
} catch (err) {
|
|
247
|
+
require_logger.logger.error(`API call error: ${String(err)}`);
|
|
248
|
+
await data?.deleteFromCache?.();
|
|
249
|
+
return { error: `API call error: ${String(err)}` };
|
|
250
|
+
}
|
|
251
|
+
return processApiResponse(data, prompt, responseFormat, cached, model, size, latencyMs, config.quality, config.n || 1, "output_format" in config ? config.output_format : void 0);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
//#endregion
|
|
255
|
+
Object.defineProperty(exports, "OpenAiImageProvider", {
|
|
256
|
+
enumerable: true,
|
|
257
|
+
get: function() {
|
|
258
|
+
return OpenAiImageProvider;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(exports, "buildStructuredImageOutputs", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
get: function() {
|
|
264
|
+
return buildStructuredImageOutputs;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
Object.defineProperty(exports, "callOpenAiImageApi", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
get: function() {
|
|
270
|
+
return callOpenAiImageApi;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(exports, "formatOutput", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function() {
|
|
276
|
+
return formatOutput;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
//# sourceMappingURL=image-0ZhE0VlR.cjs.map
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { r as logger } from "./logger-C40ZGil9.js";
|
|
2
|
+
import { h as REQUEST_TIMEOUT_MS } from "./fetch-DQckpUFz.js";
|
|
3
|
+
import { r as fetchWithCache } from "./cache-BkrqU5Ba.js";
|
|
4
|
+
import { t as OpenAiGenericProvider } from "./openai-DumO8WQn.js";
|
|
5
|
+
import { s as formatOpenAiError } from "./util-DsS_-v4p.js";
|
|
6
|
+
import { t as ellipsize } from "./text-B_UCRPp2.js";
|
|
7
|
+
//#region src/providers/openai/image.ts
|
|
8
|
+
const DALLE2_VALID_SIZES = [
|
|
9
|
+
"256x256",
|
|
10
|
+
"512x512",
|
|
11
|
+
"1024x1024"
|
|
12
|
+
];
|
|
13
|
+
const DALLE3_VALID_SIZES = [
|
|
14
|
+
"1024x1024",
|
|
15
|
+
"1792x1024",
|
|
16
|
+
"1024x1792"
|
|
17
|
+
];
|
|
18
|
+
const GPT_IMAGE1_VALID_SIZES = [
|
|
19
|
+
"1024x1024",
|
|
20
|
+
"1024x1536",
|
|
21
|
+
"1536x1024"
|
|
22
|
+
];
|
|
23
|
+
const DEFAULT_SIZE = "1024x1024";
|
|
24
|
+
const DALLE2_COSTS = {
|
|
25
|
+
"256x256": .016,
|
|
26
|
+
"512x512": .018,
|
|
27
|
+
"1024x1024": .02
|
|
28
|
+
};
|
|
29
|
+
const DALLE3_COSTS = {
|
|
30
|
+
standard_1024x1024: .04,
|
|
31
|
+
standard_1024x1792: .08,
|
|
32
|
+
standard_1792x1024: .08,
|
|
33
|
+
hd_1024x1024: .08,
|
|
34
|
+
hd_1024x1792: .12,
|
|
35
|
+
hd_1792x1024: .12
|
|
36
|
+
};
|
|
37
|
+
const GPT_IMAGE1_COSTS = {
|
|
38
|
+
low_1024x1024: .011,
|
|
39
|
+
low_1024x1536: .016,
|
|
40
|
+
low_1536x1024: .016,
|
|
41
|
+
medium_1024x1024: .042,
|
|
42
|
+
medium_1024x1536: .063,
|
|
43
|
+
medium_1536x1024: .063,
|
|
44
|
+
high_1024x1024: .167,
|
|
45
|
+
high_1024x1536: .25,
|
|
46
|
+
high_1536x1024: .25
|
|
47
|
+
};
|
|
48
|
+
const GPT_IMAGE1_MINI_COSTS = {
|
|
49
|
+
low_1024x1024: .005,
|
|
50
|
+
low_1024x1536: .006,
|
|
51
|
+
low_1536x1024: .006,
|
|
52
|
+
medium_1024x1024: .011,
|
|
53
|
+
medium_1024x1536: .015,
|
|
54
|
+
medium_1536x1024: .015,
|
|
55
|
+
high_1024x1024: .036,
|
|
56
|
+
high_1024x1536: .052,
|
|
57
|
+
high_1536x1024: .052
|
|
58
|
+
};
|
|
59
|
+
const GPT_IMAGE1_5_COSTS = {
|
|
60
|
+
low_1024x1024: .064,
|
|
61
|
+
low_1024x1536: .096,
|
|
62
|
+
low_1536x1024: .096,
|
|
63
|
+
medium_1024x1024: .128,
|
|
64
|
+
medium_1024x1536: .192,
|
|
65
|
+
medium_1536x1024: .192,
|
|
66
|
+
high_1024x1024: .192,
|
|
67
|
+
high_1024x1536: .288,
|
|
68
|
+
high_1536x1024: .288
|
|
69
|
+
};
|
|
70
|
+
function isGptImage1(model) {
|
|
71
|
+
return model === "gpt-image-1" || model.startsWith("gpt-image-1-2025");
|
|
72
|
+
}
|
|
73
|
+
function isGptImage1Mini(model) {
|
|
74
|
+
return model === "gpt-image-1-mini" || model.startsWith("gpt-image-1-mini-2025");
|
|
75
|
+
}
|
|
76
|
+
function isGptImage15(model) {
|
|
77
|
+
return model === "gpt-image-1.5" || model.startsWith("gpt-image-1.5-2025");
|
|
78
|
+
}
|
|
79
|
+
function isGptImageModel(model) {
|
|
80
|
+
return isGptImage1(model) || isGptImage1Mini(model) || isGptImage15(model);
|
|
81
|
+
}
|
|
82
|
+
function validateSizeForModel(size, model) {
|
|
83
|
+
if (model === "dall-e-3" && !DALLE3_VALID_SIZES.includes(size)) return {
|
|
84
|
+
valid: false,
|
|
85
|
+
message: `Invalid size "${size}" for DALL-E 3. Valid sizes are: ${DALLE3_VALID_SIZES.join(", ")}`
|
|
86
|
+
};
|
|
87
|
+
if (model === "dall-e-2" && !DALLE2_VALID_SIZES.includes(size)) return {
|
|
88
|
+
valid: false,
|
|
89
|
+
message: `Invalid size "${size}" for DALL-E 2. Valid sizes are: ${DALLE2_VALID_SIZES.join(", ")}`
|
|
90
|
+
};
|
|
91
|
+
if (isGptImageModel(model) && size !== "auto" && !GPT_IMAGE1_VALID_SIZES.includes(size)) {
|
|
92
|
+
let modelName = model;
|
|
93
|
+
if (isGptImage15(model)) modelName = "GPT Image 1.5";
|
|
94
|
+
else if (isGptImage1Mini(model)) modelName = "GPT Image 1 Mini";
|
|
95
|
+
else if (isGptImage1(model)) modelName = "GPT Image 1";
|
|
96
|
+
return {
|
|
97
|
+
valid: false,
|
|
98
|
+
message: `Invalid size "${size}" for ${modelName}. Valid sizes are: ${GPT_IMAGE1_VALID_SIZES.join(", ")}, auto`
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return { valid: true };
|
|
102
|
+
}
|
|
103
|
+
function getMimeTypeForOutputFormat(outputFormat) {
|
|
104
|
+
switch (outputFormat) {
|
|
105
|
+
case "jpeg": return "image/jpeg";
|
|
106
|
+
case "webp": return "image/webp";
|
|
107
|
+
default: return "image/png";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function inferMimeTypeFromUrl(url) {
|
|
111
|
+
try {
|
|
112
|
+
const pathname = new URL(url).pathname.toLowerCase();
|
|
113
|
+
if (pathname.endsWith(".jpg") || pathname.endsWith(".jpeg")) return "image/jpeg";
|
|
114
|
+
if (pathname.endsWith(".webp")) return "image/webp";
|
|
115
|
+
if (pathname.endsWith(".gif")) return "image/gif";
|
|
116
|
+
if (pathname.endsWith(".svg")) return "image/svg+xml";
|
|
117
|
+
if (pathname.endsWith(".png")) return "image/png";
|
|
118
|
+
} catch {}
|
|
119
|
+
}
|
|
120
|
+
function buildStructuredImageOutputs(data, outputFormat) {
|
|
121
|
+
if (!Array.isArray(data.data) || data.data.length === 0) return;
|
|
122
|
+
return data.data.map((item) => {
|
|
123
|
+
if (item.b64_json) {
|
|
124
|
+
const mimeType = getMimeTypeForOutputFormat(outputFormat);
|
|
125
|
+
return {
|
|
126
|
+
data: `data:${mimeType};base64,${item.b64_json}`,
|
|
127
|
+
mimeType
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (item.url) {
|
|
131
|
+
const mimeType = inferMimeTypeFromUrl(item.url);
|
|
132
|
+
return mimeType ? {
|
|
133
|
+
data: item.url,
|
|
134
|
+
mimeType
|
|
135
|
+
} : { data: item.url };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}).filter((item) => item !== null);
|
|
139
|
+
}
|
|
140
|
+
function formatOutput(data, prompt, responseFormat, outputFormat) {
|
|
141
|
+
if (responseFormat === "b64_json") {
|
|
142
|
+
const b64Json = data.data[0].b64_json;
|
|
143
|
+
if (!b64Json) return { error: `No base64 image data found in response: ${JSON.stringify(data)}` };
|
|
144
|
+
return `data:${getMimeTypeForOutputFormat(outputFormat)};base64,${b64Json}`;
|
|
145
|
+
} else {
|
|
146
|
+
const url = data.data[0].url;
|
|
147
|
+
if (!url) return { error: `No image URL found in response: ${JSON.stringify(data)}` };
|
|
148
|
+
return `![${ellipsize(prompt.replace(/\r?\n|\r/g, " ").replace(/\[/g, "(").replace(/\]/g, ")"), 50)}](${url})`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function prepareRequestBody(model, prompt, size, responseFormat, config) {
|
|
152
|
+
const body = {
|
|
153
|
+
model,
|
|
154
|
+
prompt,
|
|
155
|
+
n: config.n || 1,
|
|
156
|
+
size
|
|
157
|
+
};
|
|
158
|
+
if (!isGptImageModel(model)) body.response_format = responseFormat;
|
|
159
|
+
if (model === "dall-e-3") {
|
|
160
|
+
if ("quality" in config && config.quality) body.quality = config.quality;
|
|
161
|
+
if ("style" in config && config.style) body.style = config.style;
|
|
162
|
+
}
|
|
163
|
+
if (isGptImageModel(model)) {
|
|
164
|
+
if ("quality" in config && config.quality) body.quality = config.quality;
|
|
165
|
+
if ("background" in config && config.background) body.background = config.background;
|
|
166
|
+
if ("output_format" in config && config.output_format) body.output_format = config.output_format;
|
|
167
|
+
if ("output_compression" in config && config.output_compression !== void 0) body.output_compression = config.output_compression;
|
|
168
|
+
if ("moderation" in config && config.moderation) body.moderation = config.moderation;
|
|
169
|
+
}
|
|
170
|
+
return body;
|
|
171
|
+
}
|
|
172
|
+
function calculateImageCost(model, size, quality, n = 1) {
|
|
173
|
+
const imageQuality = quality || "standard";
|
|
174
|
+
if (model === "dall-e-3") return (DALLE3_COSTS[`${imageQuality}_${size}`] || DALLE3_COSTS["standard_1024x1024"]) * n;
|
|
175
|
+
else if (model === "dall-e-2") return (DALLE2_COSTS[size] || DALLE2_COSTS["1024x1024"]) * n;
|
|
176
|
+
else if (isGptImage1(model)) return (GPT_IMAGE1_COSTS[`${quality || "low"}_${size}`] || GPT_IMAGE1_COSTS["low_1024x1024"]) * n;
|
|
177
|
+
else if (isGptImage1Mini(model)) return (GPT_IMAGE1_MINI_COSTS[`${quality || "low"}_${size}`] || GPT_IMAGE1_MINI_COSTS["low_1024x1024"]) * n;
|
|
178
|
+
else if (isGptImage15(model)) return (GPT_IMAGE1_5_COSTS[`${quality || "low"}_${size}`] || GPT_IMAGE1_5_COSTS["low_1024x1024"]) * n;
|
|
179
|
+
return .04 * n;
|
|
180
|
+
}
|
|
181
|
+
async function callOpenAiImageApi(url, body, headers, timeout) {
|
|
182
|
+
return await fetchWithCache(url, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers,
|
|
185
|
+
body: JSON.stringify(body)
|
|
186
|
+
}, timeout);
|
|
187
|
+
}
|
|
188
|
+
async function processApiResponse(data, prompt, responseFormat, cached, model, size, latencyMs, quality, n = 1, outputFormat) {
|
|
189
|
+
if (data.error) {
|
|
190
|
+
await data?.deleteFromCache?.();
|
|
191
|
+
return { error: formatOpenAiError(data) };
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const formattedOutput = formatOutput(data, prompt, responseFormat, outputFormat);
|
|
195
|
+
if (typeof formattedOutput === "object") return formattedOutput;
|
|
196
|
+
const cost = cached ? 0 : calculateImageCost(model, size, quality, n);
|
|
197
|
+
return {
|
|
198
|
+
output: formattedOutput,
|
|
199
|
+
images: buildStructuredImageOutputs(data, outputFormat),
|
|
200
|
+
cached,
|
|
201
|
+
latencyMs,
|
|
202
|
+
cost,
|
|
203
|
+
...responseFormat === "b64_json" ? {
|
|
204
|
+
isBase64: true,
|
|
205
|
+
format: "json"
|
|
206
|
+
} : {}
|
|
207
|
+
};
|
|
208
|
+
} catch (err) {
|
|
209
|
+
await data?.deleteFromCache?.();
|
|
210
|
+
return { error: `API error: ${String(err)}: ${JSON.stringify(data)}` };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var OpenAiImageProvider = class extends OpenAiGenericProvider {
|
|
214
|
+
config;
|
|
215
|
+
constructor(modelName, options = {}) {
|
|
216
|
+
super(modelName, options);
|
|
217
|
+
this.config = options.config || {};
|
|
218
|
+
}
|
|
219
|
+
async callApi(prompt, context, _callApiOptions) {
|
|
220
|
+
if (this.requiresApiKey() && !this.getApiKey()) throw new Error(this.getMissingApiKeyErrorMessage());
|
|
221
|
+
const config = {
|
|
222
|
+
...this.config,
|
|
223
|
+
...context?.prompt?.config
|
|
224
|
+
};
|
|
225
|
+
const model = config.model || this.modelName;
|
|
226
|
+
const operation = "operation" in config && config.operation || "generation";
|
|
227
|
+
const responseFormat = isGptImageModel(model) ? "b64_json" : config.response_format || "url";
|
|
228
|
+
if (operation !== "generation") return { error: `Only 'generation' operations are currently supported. '${operation}' operations are not implemented.` };
|
|
229
|
+
const endpoint = "/images/generations";
|
|
230
|
+
const size = config.size || DEFAULT_SIZE;
|
|
231
|
+
const sizeValidation = validateSizeForModel(size, model);
|
|
232
|
+
if (!sizeValidation.valid) return { error: sizeValidation.message };
|
|
233
|
+
const body = prepareRequestBody(model, prompt, size, responseFormat, config);
|
|
234
|
+
const headers = {
|
|
235
|
+
"Content-Type": "application/json",
|
|
236
|
+
...this.getApiKey() ? { Authorization: `Bearer ${this.getApiKey()}` } : {},
|
|
237
|
+
...this.getOrganization() ? { "OpenAI-Organization": this.getOrganization() } : {},
|
|
238
|
+
...config.headers
|
|
239
|
+
};
|
|
240
|
+
let data, status, statusText;
|
|
241
|
+
let cached = false;
|
|
242
|
+
let latencyMs;
|
|
243
|
+
try {
|
|
244
|
+
({data, cached, status, statusText, latencyMs} = await callOpenAiImageApi(`${this.getApiUrl()}${endpoint}`, body, headers, REQUEST_TIMEOUT_MS));
|
|
245
|
+
if (status < 200 || status >= 300) return { error: `API error: ${status} ${statusText}\n${typeof data === "string" ? data : JSON.stringify(data)}` };
|
|
246
|
+
} catch (err) {
|
|
247
|
+
logger.error(`API call error: ${String(err)}`);
|
|
248
|
+
await data?.deleteFromCache?.();
|
|
249
|
+
return { error: `API call error: ${String(err)}` };
|
|
250
|
+
}
|
|
251
|
+
return processApiResponse(data, prompt, responseFormat, cached, model, size, latencyMs, config.quality, config.n || 1, "output_format" in config ? config.output_format : void 0);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
//#endregion
|
|
255
|
+
export { formatOutput as i, buildStructuredImageOutputs as n, callOpenAiImageApi as r, OpenAiImageProvider as t };
|
|
256
|
+
|
|
257
|
+
//# sourceMappingURL=image-CWE1pdNv.js.map
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { r as logger, x as getEnvString } from "./logger-C40ZGil9.js";
|
|
2
|
+
import { h as REQUEST_TIMEOUT_MS } from "./fetch-DQckpUFz.js";
|
|
3
|
+
import { r as fetchWithCache } from "./cache-BkrqU5Ba.js";
|
|
4
|
+
//#region src/providers/hyperbolic/image.ts
|
|
5
|
+
const HYPERBOLIC_IMAGE_MODELS = [
|
|
6
|
+
{
|
|
7
|
+
id: "Flux.1-dev",
|
|
8
|
+
aliases: [
|
|
9
|
+
"flux-dev",
|
|
10
|
+
"flux.1-dev",
|
|
11
|
+
"FLUX.1-dev"
|
|
12
|
+
],
|
|
13
|
+
cost: .025
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: "SDXL1.0-base",
|
|
17
|
+
aliases: ["sdxl", "sdxl-base"],
|
|
18
|
+
cost: .01
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "SD1.5",
|
|
22
|
+
aliases: ["stable-diffusion-1.5", "sd-1.5"],
|
|
23
|
+
cost: .005
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "SD2",
|
|
27
|
+
aliases: ["stable-diffusion-2", "sd-2"],
|
|
28
|
+
cost: .008
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "SSD",
|
|
32
|
+
aliases: ["segmind-sd-1b"],
|
|
33
|
+
cost: .005
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "SDXL-turbo",
|
|
37
|
+
aliases: ["sdxl-turbo"],
|
|
38
|
+
cost: .008
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "SDXL-ControlNet",
|
|
42
|
+
aliases: ["sdxl-controlnet"],
|
|
43
|
+
cost: .015
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "SD1.5-ControlNet",
|
|
47
|
+
aliases: ["sd1.5-controlnet"],
|
|
48
|
+
cost: .008
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
function formatHyperbolicImageOutput(imageData, _prompt, responseFormat) {
|
|
52
|
+
if (responseFormat === "b64_json") return JSON.stringify({ data: [{ b64_json: imageData }] });
|
|
53
|
+
else {
|
|
54
|
+
let mimeType = "image/jpeg";
|
|
55
|
+
if (imageData.startsWith("/9j/")) mimeType = "image/jpeg";
|
|
56
|
+
else if (imageData.startsWith("iVBORw0KGgo")) mimeType = "image/png";
|
|
57
|
+
else if (imageData.startsWith("UklGR")) mimeType = "image/webp";
|
|
58
|
+
return `data:${mimeType};base64,${imageData}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var HyperbolicImageProvider = class {
|
|
62
|
+
modelName;
|
|
63
|
+
config;
|
|
64
|
+
env;
|
|
65
|
+
constructor(modelName, options = {}) {
|
|
66
|
+
this.modelName = modelName;
|
|
67
|
+
this.config = options.config || {};
|
|
68
|
+
this.env = options.env;
|
|
69
|
+
}
|
|
70
|
+
getApiKey() {
|
|
71
|
+
if (this.config?.apiKey) return this.config.apiKey;
|
|
72
|
+
return this.env?.HYPERBOLIC_API_KEY || getEnvString("HYPERBOLIC_API_KEY");
|
|
73
|
+
}
|
|
74
|
+
getApiUrl() {
|
|
75
|
+
return this.config?.apiBaseUrl || "https://api.hyperbolic.xyz/v1";
|
|
76
|
+
}
|
|
77
|
+
id() {
|
|
78
|
+
return `hyperbolic:image:${this.modelName}`;
|
|
79
|
+
}
|
|
80
|
+
toString() {
|
|
81
|
+
return `[Hyperbolic Image Provider ${this.modelName}]`;
|
|
82
|
+
}
|
|
83
|
+
getApiModelName() {
|
|
84
|
+
return HYPERBOLIC_IMAGE_MODELS.find((m) => m.id === this.modelName || m.aliases && m.aliases.includes(this.modelName))?.id || this.modelName;
|
|
85
|
+
}
|
|
86
|
+
calculateImageCost() {
|
|
87
|
+
return HYPERBOLIC_IMAGE_MODELS.find((m) => m.id === this.modelName || m.aliases && m.aliases.includes(this.modelName))?.cost || .01;
|
|
88
|
+
}
|
|
89
|
+
async callApi(prompt, context, _callApiOptions) {
|
|
90
|
+
const apiKey = this.getApiKey();
|
|
91
|
+
if (!apiKey) throw new Error("Hyperbolic API key is not set. Set the HYPERBOLIC_API_KEY environment variable or add `apiKey` to the provider config.");
|
|
92
|
+
const config = {
|
|
93
|
+
...this.config,
|
|
94
|
+
...context?.prompt?.config
|
|
95
|
+
};
|
|
96
|
+
const modelName = config.model_name || this.getApiModelName();
|
|
97
|
+
const endpoint = "/image/generation";
|
|
98
|
+
const responseFormat = config.response_format || "url";
|
|
99
|
+
const body = {
|
|
100
|
+
model_name: modelName,
|
|
101
|
+
prompt,
|
|
102
|
+
height: config.height || 1024,
|
|
103
|
+
width: config.width || 1024,
|
|
104
|
+
backend: config.backend || "auto"
|
|
105
|
+
};
|
|
106
|
+
if (config.prompt_2) body.prompt_2 = config.prompt_2;
|
|
107
|
+
if (config.negative_prompt) body.negative_prompt = config.negative_prompt;
|
|
108
|
+
if (config.negative_prompt_2) body.negative_prompt_2 = config.negative_prompt_2;
|
|
109
|
+
if (config.image) body.image = config.image;
|
|
110
|
+
if (config.strength !== void 0) body.strength = config.strength;
|
|
111
|
+
if (config.seed !== void 0) body.seed = config.seed;
|
|
112
|
+
if (config.cfg_scale !== void 0) body.cfg_scale = config.cfg_scale;
|
|
113
|
+
if (config.sampler) body.sampler = config.sampler;
|
|
114
|
+
if (config.steps !== void 0) body.steps = config.steps;
|
|
115
|
+
if (config.style_preset) body.style_preset = config.style_preset;
|
|
116
|
+
if (config.enable_refiner !== void 0) body.enable_refiner = config.enable_refiner;
|
|
117
|
+
if (config.controlnet_name) body.controlnet_name = config.controlnet_name;
|
|
118
|
+
if (config.controlnet_image) body.controlnet_image = config.controlnet_image;
|
|
119
|
+
if (config.loras) body.loras = config.loras;
|
|
120
|
+
const headers = {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
Authorization: `Bearer ${apiKey}`
|
|
123
|
+
};
|
|
124
|
+
let data, status, statusText, latencyMs;
|
|
125
|
+
let cached = false;
|
|
126
|
+
try {
|
|
127
|
+
({data, cached, status, statusText, latencyMs} = await fetchWithCache(`${this.getApiUrl()}${endpoint}`, {
|
|
128
|
+
method: "POST",
|
|
129
|
+
headers,
|
|
130
|
+
body: JSON.stringify(body)
|
|
131
|
+
}, REQUEST_TIMEOUT_MS));
|
|
132
|
+
if (status < 200 || status >= 300) return { error: `API error: ${status} ${statusText}\n${typeof data === "string" ? data : JSON.stringify(data)}` };
|
|
133
|
+
} catch (err) {
|
|
134
|
+
logger.error(`API call error: ${String(err)}`);
|
|
135
|
+
return { error: `API call error: ${String(err)}` };
|
|
136
|
+
}
|
|
137
|
+
if (data.error) return { error: typeof data.error === "string" ? data.error : JSON.stringify(data.error) };
|
|
138
|
+
try {
|
|
139
|
+
if (!data.images || !Array.isArray(data.images) || data.images.length === 0) return { error: "No images returned from API" };
|
|
140
|
+
const imageData = data.images[0].image;
|
|
141
|
+
const cost = cached ? 0 : this.calculateImageCost();
|
|
142
|
+
return {
|
|
143
|
+
output: formatHyperbolicImageOutput(imageData, prompt, responseFormat),
|
|
144
|
+
cached,
|
|
145
|
+
latencyMs,
|
|
146
|
+
cost,
|
|
147
|
+
...responseFormat === "b64_json" ? {
|
|
148
|
+
isBase64: true,
|
|
149
|
+
format: "json"
|
|
150
|
+
} : {}
|
|
151
|
+
};
|
|
152
|
+
} catch (err) {
|
|
153
|
+
return { error: `API error: ${String(err)}: ${JSON.stringify(data)}` };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
function createHyperbolicImageProvider(providerPath, options = {}) {
|
|
158
|
+
return new HyperbolicImageProvider(providerPath.split(":").slice(2).join(":") || "SDXL1.0-base", options);
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
export { createHyperbolicImageProvider };
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=image-D9ZK6hwL.js.map
|