This commit is contained in:
seb
2026-10-18 16:24:37 +02:00
parent 7445a573ab
commit 69a9781cb6
2 changed files with 11 additions and 48 deletions

View File

@@ -1,7 +1,6 @@
import fs from 'fs';
import path from 'path';
import sharp from 'sharp';
import jwt from 'jsonwebtoken';
import { defineTool, ToolError, OpenRouterProvider } from 'libllmorbiter';
import env from '../config/env.js';
import { getImageByHash } from '../db/pic.js';
@@ -23,7 +22,7 @@ import {
* - 1 image → resized to fit 400×400 and sent as a single WebP.
* - 2-9 → composited into a labelled grid (2x1/3x1/2x2/3x2/3x3) with the file name
* printed under each cell, so one cheap call can compare many candidates.
* - Database images are addressed as `image/<fullHash>` and fetched from `/image/:hash`.
* - Database images are addressed as `image/<fullHash>`.
*
* The prompt is assembled from the caller's `prompt` plus a layout summary, so the model
* knows which cell is which file.
@@ -41,7 +40,6 @@ const GRID_CONFIGS = {
const MAX_IMAGES = 9;
const SINGLE_BOX = 400;
const WEBP_QUALITY = 80;
const IMAGE_TIMEOUT_MS = 10_000;
const LABEL_HEIGHT = 26;
const LABEL_PAD = 5;
@@ -241,34 +239,17 @@ function extractImageInputs(args = {}) {
}
/**
* Fetches a database image by its content hash using store or authenticated local endpoint.
* Fetches a database image by its content hash using the database store.
* @param {string} hash 8-char SHA-256 Base62
* @param {number} googleAuthId
* @returns {Promise<Buffer>}
*/
async function fetchDatabaseImage(hash, googleAuthId) {
try {
const image = await getImageByHash(googleAuthId, hash);
if (image?.buffer) {
return image.buffer;
}
} catch (dbErr) {
try {
const url = `http://127.0.0.1:${env.port}/api/image/${hash}`;
const token = jwt.sign({ id: googleAuthId }, env.jwtSecret, { expiresIn: '5m' });
const res = await fetch(url, {
headers: { Cookie: `token=${token}` },
signal: AbortSignal.timeout(IMAGE_TIMEOUT_MS),
});
if (res.ok) {
return Buffer.from(await res.arrayBuffer());
}
} catch {
// fallback error ignored
}
throw dbErr;
const image = await getImageByHash(googleAuthId, hash);
if (!image?.buffer) {
throw new Error('Image not found');
}
throw new Error('Image not found');
return image.buffer;
}
/**

View File

@@ -1,7 +1,6 @@
import fs from 'fs';
import path from 'path';
import sharp from 'sharp';
import jwt from 'jsonwebtoken';
import { defineTool, ToolError } from 'libllmorbiter';
import env from '../config/env.js';
import { getImageByHash } from '../db/pic.js';
@@ -135,34 +134,17 @@ function resolveImagesApiUrl() {
}
/**
* Fetches a database image by its 8-char content hash using store or authenticated local endpoint.
* Fetches a database image by its content hash using the database store.
* @param {string} hash
* @param {number} googleAuthId
* @returns {Promise<Buffer>}
*/
async function fetchDatabaseImage(hash, googleAuthId) {
try {
const image = await getImageByHash(googleAuthId, hash);
if (image?.buffer) {
return image.buffer;
}
} catch (dbErr) {
try {
const url = `http://127.0.0.1:${env.port}/api/image/${hash}`;
const token = jwt.sign({ id: googleAuthId }, env.jwtSecret, { expiresIn: '5m' });
const res = await fetch(url, {
headers: { Cookie: `token=${token}` },
signal: AbortSignal.timeout(IMAGE_FETCH_TIMEOUT_MS),
});
if (res.ok) {
return Buffer.from(await res.arrayBuffer());
}
} catch {
// fallback error ignored
}
throw dbErr;
const image = await getImageByHash(googleAuthId, hash);
if (!image?.buffer) {
throw new Error('Image not found');
}
throw new Error('Image not found');
return image.buffer;
}
/**