Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Own key: an address that answers with a web page is said so, not shown as its HTML (#218)

WEBGRSd057c79b1af6
diff --git a/.changeset/own-key-web-page.md b/.changeset/own-key-web-page.md
new file mode 100644
index 0000000..69994b2
--- /dev/null
+++ b/.changeset/own-key-web-page.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+Own key: an address that answers with a web page instead of the API (a site, or a sign-in page in front of one) is said so when the model is checked, instead of its HTML filling the form, and a page that answers 200 is no longer taken for a model that works.
diff --git a/apps/desktop/src/agent-roster.mjs b/apps/desktop/src/agent-roster.mjs
index b2d64bf..9617bbc 100644
--- a/apps/desktop/src/agent-roster.mjs
+++ b/apps/desktop/src/agent-roster.mjs
@@ -160,7 +160,8 @@ export function probeRequest(format, baseUrl, key, model) {
/**
* Whether a model reads pictures: one request with a picture in it, in the format's own shape. Resolves `{ ok }` or the
- * service's own words for what went wrong (a model that cannot take pictures is said so).
+ * service's own words for what went wrong (a model that cannot take pictures is said so, and so is a web page where the
+ * API should be).
* @param {{ format: string, baseUrl: string, key: string, model: string, fetch?: typeof fetch }} o
*/
export async function probeModel({ format, baseUrl, key, model, fetch: fetchImpl = fetch }) {
@@ -171,12 +172,15 @@ export async function probeModel({ format, baseUrl, key, model, fetch: fetchImpl
} catch (e) {
return { ok: false, error: `The service could not be reached: ${e instanceof Error ? e.message : String(e)}` };
}
- if (res.ok) return { ok: true };
+ /* a web page answers an address that is a site's, not an API's (or a sign-in page in front of one), whatever its status */
+ const page = /text\/html/i.test(res.headers.get('content-type') ?? '');
+ if (res.ok && !page) return { ok: true };
const body = await res.text().catch(() => '');
let message = body;
try { message = JSON.parse(body)?.error?.message ?? body; } catch { /* not JSON */ }
message = String(message).slice(0, 300);
if (res.status === 401 || res.status === 403) return { ok: false, error: 'The service did not accept this key.' };
+ if (page || /^\s*</.test(body)) return { ok: false, error: `${req.url} answers with a web page (${res.status}), not the API: check the address and the API format.` };
if (/image|vision|multimodal|modalit/i.test(message)) return { ok: false, error: 'This model cannot read pictures, and the agent has to look at its frames: choose one that does.', code: 'no-images' };
if (res.status === 404 && !/model/i.test(message)) return { ok: false, error: `Nothing answers at ${req.url}: check the address and the API format.` };
return { ok: false, error: message || `The service answered ${res.status}.` };
diff --git a/apps/desktop/src/agent-roster.test.mjs b/apps/desktop/src/agent-roster.test.mjs
index 14b4d91..e75345d 100644
--- a/apps/desktop/src/agent-roster.test.mjs
+++ b/apps/desktop/src/agent-roster.test.mjs
@@ -52,6 +52,24 @@ test('a model is kept only once its service took the key with a picture; one tha
assert.equal(JSON.stringify(readChoices(dir)).includes('sk-good'), false, 'never in the choices file');
});
+test('an address that answers with a web page is said so, not shown as its HTML, and nothing is kept', async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'of-roster-'));
+ let answer = { status: 405, type: 'text/html', body: '<!doctype html><html lang="en"><head><title>Example Domain</title></head></html>' };
+ const fetch = async () => new Response(answer.body, { status: answer.status, headers: { 'content-type': answer.type } });
+ const r = roster(dir, fetch);
+ const save = () => r.saveOwnModel({ format: 'responses', baseUrl: 'https://example.com/v1', model: 'm', key: 'sk-1234' });
+ const refused = await save();
+ assert.equal(refused.ok, false);
+ assert.equal(refused.error, 'https://example.com/v1/responses answers with a web page (405), not the API: check the address and the API format.');
+ /* a page that answers 200 is not the model taking the picture, and one that mentions images is not a model refusing it */
+ answer = { status: 200, type: 'text/html; charset=utf-8', body: '<html><head><meta property="og:image" content="card.png"></head></html>' };
+ assert.match((await save()).error, /web page \(200\)/);
+ /* an HTML error page sent as text */
+ answer = { status: 502, type: 'text/plain', body: '<html><body>Bad gateway</body></html>' };
+ assert.match((await save()).error, /web page \(502\)/);
+ assert.equal(readChoices(dir).byok, null, 'nothing kept');
+});
+
test('each model is its own service with its own key; a key left empty is the one of another model on that address', async () => {
const dir = mkdtempSync(join(tmpdir(), 'of-roster-'));
const r = roster(dir, async () => new Response('{}', { status: 200 }));