open-agents-ai 0.139.5 → 0.139.6
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/index.js +38 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13903,24 +13903,41 @@ var init_image_generate = __esm({
|
|
|
13903
13903
|
cachedImageModel = null;
|
|
13904
13904
|
constructor(cwd4, ollamaUrl = "http://localhost:11434") {
|
|
13905
13905
|
this.cwd = cwd4;
|
|
13906
|
-
this.ollamaUrl = ollamaUrl;
|
|
13906
|
+
this.ollamaUrl = ollamaUrl.replace(/\/v1\/?$/, "").replace(/\/$/, "");
|
|
13907
13907
|
}
|
|
13908
13908
|
async execute(args) {
|
|
13909
13909
|
const prompt = String(args.prompt ?? "");
|
|
13910
13910
|
const width = Number(args.width ?? 1024);
|
|
13911
13911
|
const height = Number(args.height ?? 1024);
|
|
13912
13912
|
const steps = args.steps ? Number(args.steps) : void 0;
|
|
13913
|
-
const
|
|
13913
|
+
const rawModel = args.model ? String(args.model) : void 0;
|
|
13914
|
+
const requestedModel = rawModel === "auto" ? void 0 : rawModel;
|
|
13914
13915
|
const start = performance.now();
|
|
13915
13916
|
if (!prompt.trim()) {
|
|
13916
13917
|
return { success: false, output: "No prompt provided", error: "Empty prompt", durationMs: 0 };
|
|
13917
13918
|
}
|
|
13918
13919
|
try {
|
|
13919
|
-
|
|
13920
|
+
let model = requestedModel ?? await this.findImageGenModel();
|
|
13921
|
+
if (!model) {
|
|
13922
|
+
try {
|
|
13923
|
+
const pullResp = await fetch(`${this.ollamaUrl}/api/pull`, {
|
|
13924
|
+
method: "POST",
|
|
13925
|
+
headers: { "Content-Type": "application/json" },
|
|
13926
|
+
body: JSON.stringify({ name: "x/z-image-turbo", stream: false }),
|
|
13927
|
+
signal: AbortSignal.timeout(6e5)
|
|
13928
|
+
// 10 min for model download
|
|
13929
|
+
});
|
|
13930
|
+
if (pullResp.ok) {
|
|
13931
|
+
model = "x/z-image-turbo";
|
|
13932
|
+
this.cachedImageModel = model;
|
|
13933
|
+
}
|
|
13934
|
+
} catch {
|
|
13935
|
+
}
|
|
13936
|
+
}
|
|
13920
13937
|
if (!model) {
|
|
13921
13938
|
return {
|
|
13922
13939
|
success: false,
|
|
13923
|
-
output: "No image generation model available.\nPull
|
|
13940
|
+
output: "No image generation model available and auto-pull failed.\nPull manually: ollama pull x/z-image-turbo\nOr: ollama pull x/flux2-klein\nNote: Image generation is currently macOS-only in Ollama. Linux/Windows support is coming soon.",
|
|
13924
13941
|
error: "No image gen model",
|
|
13925
13942
|
durationMs: performance.now() - start
|
|
13926
13943
|
};
|
|
@@ -13981,10 +13998,19 @@ ${errText.slice(0, 200)}`,
|
|
|
13981
13998
|
};
|
|
13982
13999
|
}
|
|
13983
14000
|
}
|
|
13984
|
-
/** Find the best available image gen model on Ollama
|
|
14001
|
+
/** Find the best available image gen model on Ollama.
|
|
14002
|
+
* Priority: 1) known image models by name, 2) capabilities="image" check */
|
|
13985
14003
|
async findImageGenModel() {
|
|
13986
14004
|
if (this.cachedImageModel)
|
|
13987
14005
|
return this.cachedImageModel;
|
|
14006
|
+
const KNOWN_IMAGE_MODELS = [
|
|
14007
|
+
"x/z-image-turbo",
|
|
14008
|
+
// 6B, Apache 2.0, photorealistic + bilingual text
|
|
14009
|
+
"x/flux2-klein",
|
|
14010
|
+
// 4B, Apache 2.0, good text rendering
|
|
14011
|
+
"x/flux2-klein:9b"
|
|
14012
|
+
// 9B, non-commercial, higher quality
|
|
14013
|
+
];
|
|
13988
14014
|
try {
|
|
13989
14015
|
const resp = await fetch(`${this.ollamaUrl}/api/tags`, {
|
|
13990
14016
|
signal: AbortSignal.timeout(5e3)
|
|
@@ -13993,6 +14019,13 @@ ${errText.slice(0, 200)}`,
|
|
|
13993
14019
|
return null;
|
|
13994
14020
|
const data = await resp.json();
|
|
13995
14021
|
const models = data.models ?? [];
|
|
14022
|
+
const modelNames = new Set(models.map((m) => m.name));
|
|
14023
|
+
for (const known of KNOWN_IMAGE_MODELS) {
|
|
14024
|
+
if (modelNames.has(known) || modelNames.has(known + ":latest")) {
|
|
14025
|
+
this.cachedImageModel = known;
|
|
14026
|
+
return known;
|
|
14027
|
+
}
|
|
14028
|
+
}
|
|
13996
14029
|
for (const m of models) {
|
|
13997
14030
|
try {
|
|
13998
14031
|
const showResp = await fetch(`${this.ollamaUrl}/api/show`, {
|
package/package.json
CHANGED