The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Settings: an own model that is not saved says why in the app's language (#250)
WEBGRS53a6d7f37f60
diff --git a/.changeset/own-key-errors-translated.md b/.changeset/own-key-errors-translated.mdnew file mode 100644index 0000000..0c3d6c9--- /dev/null+++ b/.changeset/own-key-errors-translated.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Settings › Agents: when an own model is not saved, the reason is said in the app's language (简体中文, 日本語, 한국어, Español), not only in English: an address that is not https:// (or http:// on this computer), a model or key left out, an address that is a web page or that nothing answers at, a key refused, a model that cannot read pictures, a service out of reach. What the service itself says is shown as it said it.diff --git a/apps/desktop/src/agent-roster.mjs b/apps/desktop/src/agent-roster.mjsindex 907fa13..63cf17a 100644--- a/apps/desktop/src/agent-roster.mjs+++ b/apps/desktop/src/agent-roster.mjs@@ -174,7 +174,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, and so is a web page where the- * API should be).+ * API should be). The app's own words come with a `code`, and the `url`, `status` or `reason` they name, so Studio's+ * Settings say them in the person's language (its settings.agents.ownErrors); the service's own words have none.* @param {{ format: string, baseUrl: string, key: string, model: string, fetch?: typeof fetch }} o*/export async function probeModel({ format, baseUrl, key, model, fetch: fetchImpl = fetch }) {@@ -183,7 +184,8 @@ export async function probeModel({ format, baseUrl, key, model, fetch: fetchImpltry {res = await fetchImpl(req.url, { method: 'POST', headers: req.headers, body: JSON.stringify(req.body), signal: AbortSignal.timeout(60_000) });} catch (e) {- return { ok: false, error: `The service could not be reached: ${e instanceof Error ? e.message : String(e)}` };+ const reason = e instanceof Error ? e.message : String(e);+ return { ok: false, error: `The service could not be reached: ${reason}`, code: 'unreachable', reason };}/* 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') ?? '');@@ -192,11 +194,12 @@ export async function probeModel({ format, baseUrl, key, model, fetch: fetchImpllet 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 (res.status === 401 || res.status === 403) return { ok: false, error: 'The service did not accept this key.', code: 'key-refused' };+ 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.`, code: 'web-page', url: req.url, status: res.status };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}.` };+ if (res.status === 404 && !/model/i.test(message)) return { ok: false, error: `Nothing answers at ${req.url}: check the address and the API format.`, code: 'nothing-there', url: req.url };+ if (message) return { ok: false, error: message };+ return { ok: false, error: `The service answered ${res.status}.`, code: 'answered', status: res.status };}/**@@ -418,23 +421,23 @@ export function createRoster(deps) {* none), its API format, the service's address, the model asked for there, its key, its efforts (pi-config.mjs* EFFORTS: the ones it takes and the one it starts on) and its context length (none: 128K). A key left empty keeps* the one it has, or takes the key of another model on the same address. Checked first (the key is taken, the- * model reads pictures).+ * model reads pictures). What went wrong comes with a code, as probeModel's does.* @param {{ id?: string, name?: string, format: string, baseUrl?: string, model: string, key?: string, levels?: string[], effort?: string, context?: number }} config- * @returns {Promise<{ ok: true, id: string } | { ok: false, error: string, code?: string }>}+ * @returns {Promise<{ ok: true, id: string } | { ok: false, error: string, code?: string, url?: string, status?: number, reason?: string }>}*/async saveOwnModel(config) {const format = BYOK_FORMATS[config?.format];- if (!format) return { ok: false, error: 'Choose the API format.' };+ if (!format) return { ok: false, error: 'Choose the API format.', code: 'no-format' };const baseUrl = String(config.baseUrl || format.baseUrl).trim().replace(/\/+$/, '');- if (!keyAddress(baseUrl)) return { ok: false, error: 'The address has to start with https:// (or http:// for one on this computer).' };+ if (!keyAddress(baseUrl)) return { ok: false, error: 'The address has to start with https:// (or http:// for one on this computer).', code: 'address' };const model = String(config.model ?? '').trim();- if (!model) return { ok: false, error: 'Name the model.' };+ if (!model) return { ok: false, error: 'Name the model.', code: 'no-model' };const models = choices.byok?.models ?? [];const before = config.id ? models.find((m) => m.id === config.id) : null;- if (config.id && !before) return { ok: false, error: 'That model is no longer set up.' };+ if (config.id && !before) return { ok: false, error: 'That model is no longer set up.', code: 'model-gone' };const sameService = models.find((m) => m.id !== config.id && m.baseUrl === baseUrl && keyOf(m.id));const key = String(config.key ?? '').trim() || (before ? keyOf(before.id) : null) || (sameService ? keyOf(sameService.id) : null);- if (!key) return { ok: false, error: 'Paste the key.' };+ if (!key) return { ok: false, error: 'Paste the key.', code: 'no-key' };const probe = await probeModel({ format: config.format, baseUrl, key, model, fetch: deps.fetch });if (!probe.ok) return probe;let id = before?.id;diff --git a/apps/desktop/src/agent-roster.test.mjs b/apps/desktop/src/agent-roster.test.mjsindex 3c8c123..1fb4e9c 100644--- a/apps/desktop/src/agent-roster.test.mjs+++ b/apps/desktop/src/agent-roster.test.mjs@@ -4,6 +4,8 @@ import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { createRoster, keyAddress, probeRequest, readChoices } from './agent-roster.mjs';+import { LANGUAGES as STUDIO_LANGUAGES } from '../../../packages/openfilm/studio/ui/src/i18n/index.ts';+import { ownModelError } from '../../../packages/openfilm/studio/ui/src/lib/agent-row.ts';const roster = (dataDir, fetch, extra = {}) => createRoster({dataDir,@@ -83,6 +85,53 @@ test('a key goes over https://, or over http:// only to this computer; another hassert.equal(asked, 0, 'the key was not sent');});+test('the app\'s own words for a model not set up come with a code and what they name, for Settings to say in the person\'s language; the service\'s own words with none', async () => {+ let answer = { status: 401, type: 'application/json', body: '{}' };+ let reached = true;+ const fetch = async () => {+ if (!reached) throw new TypeError('fetch failed');+ return new Response(answer.body, { status: answer.status, headers: { 'content-type': answer.type } });+ };+ const r = roster(mkdtempSync(join(tmpdir(), 'of-roster-')), fetch);+ const failures = [];+ /** what comes with the words: the code, and the address, status or reason they name */+ const said = async (config = {}) => {+ const failure = await r.saveOwnModel({ format: 'responses', baseUrl: 'https://api.example.com/v1', model: 'm', key: 'sk-1', ...config });+ failures.push(failure);+ const { ok, error, ...rest } = failure;+ assert.equal(ok, false);+ assert.ok(error, 'in English too');+ return rest;+ };+ assert.deepEqual(await said({ format: 'soap' }), { code: 'no-format' });+ assert.deepEqual(await said({ baseUrl: 'http://example.com/v1' }), { code: 'address' });+ assert.deepEqual(await said({ model: ' ' }), { code: 'no-model' });+ assert.deepEqual(await said({ id: 'gone' }), { code: 'model-gone' });+ assert.deepEqual(await said({ key: '' }), { code: 'no-key' });+ assert.deepEqual(await said(), { code: 'key-refused' });+ answer = { status: 502, type: 'text/html', body: '<html></html>' };+ assert.deepEqual(await said(), { code: 'web-page', url: 'https://api.example.com/v1/responses', status: 502 });+ answer = { status: 404, type: 'application/json', body: '{}' };+ assert.deepEqual(await said(), { code: 'nothing-there', url: 'https://api.example.com/v1/responses' });+ answer = { status: 500, type: 'text/plain', body: '' };+ assert.deepEqual(await said(), { code: 'answered', status: 500 });+ reached = false;+ assert.deepEqual(await said(), { code: 'unreachable', reason: 'fetch failed' });+ reached = true;+ answer = { status: 400, type: 'application/json', body: JSON.stringify({ error: { message: 'Unknown parameter: max_output_tokens' } }) };+ assert.deepEqual(await r.saveOwnModel({ format: 'responses', baseUrl: 'https://api.example.com/v1', model: 'm', key: 'sk-1' }), { ok: false, error: 'Unknown parameter: max_output_tokens' });+ /* Studio's Settings has words for each code: in English the app's own, in every other language their own */+ answer = { status: 400, type: 'application/json', body: JSON.stringify({ error: { message: 'image input is not supported' } }) };+ assert.equal((await said()).code, 'no-images');+ for (const { code, words } of STUDIO_LANGUAGES) {+ const t = (path) => path.split('.').reduce((at, part) => at?.[part], words) ?? path;+ for (const failure of failures) {+ if (code === 'en') assert.equal(ownModelError(failure, t), failure.error, failure.code);+ else assert.notEqual(ownModelError(failure, t), failure.error, `${code}: ${failure.code}`);+ }+ }+});+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 }));diff --git a/packages/openfilm/studio/ui/src/components/settings/AgentsSection.tsx b/packages/openfilm/studio/ui/src/components/settings/AgentsSection.tsxindex 6a9f51d..54155b7 100644--- a/packages/openfilm/studio/ui/src/components/settings/AgentsSection.tsx+++ b/packages/openfilm/studio/ui/src/components/settings/AgentsSection.tsx@@ -23,7 +23,7 @@ import { Check, Copy, Download, KeyRound, Loader2, Plus, X } from 'lucide-react'import { useLanguage, useT } from '@/i18n';import { BYOK_EFFORTS, studioHost, type HostAgent, type HostAgentDiagnosis, type HostAgentId, type HostAgentUsage, type HostByokEffort, type HostByokEffortLevel, type HostByokFormat, type HostOwnModel } from '@/lib/host';import { parseContextLength } from '@/lib/context-length';-import { accountOrg, missingActions } from '@/lib/agent-row';+import { accountOrg, missingActions, ownModelError } from '@/lib/agent-row';/** What is left of the plan: what Codex can say (the app's agent-usage.mjs; Claude Code's own report is wrong for Team accounts). */const PLAN_AGENTS: readonly HostAgentId[] = ['codex'];@@ -515,7 +515,7 @@ function OwnModelForm({ model, models, onDone }: { model?: HostOwnModel; models:if (!host || !ready) return;setState({ busy: true, error: null });void host.saveOwnModel({ ...(model ? { id: model.id } : {}), name, format, baseUrl, model: modelId, ...(key.trim() ? { key } : {}), levels: effort.levels, effort: effort.effort, ...context })- .then((r) => { if (r.ok) onDone(); else setState({ busy: false, error: r.error || t('settings.agents.failed') }); })+ .then((r) => { if (r.ok) onDone(); else setState({ busy: false, error: ownModelError(r, t) || t('settings.agents.failed') }); }).catch((e: unknown) => setState({ busy: false, error: e instanceof Error ? e.message : String(e) }));};const keyHint = model ? t('settings.agents.keyKept').replace('{last4}', model.last4)diff --git a/packages/openfilm/studio/ui/src/i18n/en.ts b/packages/openfilm/studio/ui/src/i18n/en.tsindex e6c8e9b..16d3ac0 100644--- a/packages/openfilm/studio/ui/src/i18n/en.ts+++ b/packages/openfilm/studio/ui/src/i18n/en.ts@@ -1712,6 +1712,19 @@ export const en = {byokRules: 'Its rules are the project\'s own AGENTS.md (or CLAUDE.md), in the project\'s folder. One kept anywhere else, in a folder above or with the agent\'s settings, is not read.',save: 'Check and save',checkingKey: 'Checking…',+ ownErrors: {+ noFormat: 'Choose the API format.',+ address: 'The address has to start with https:// (or http:// for one on this computer).',+ noModel: 'Name the model.',+ modelGone: 'That model is no longer set up.',+ noKey: 'Paste the key.',+ unreachable: 'The service could not be reached: {reason}',+ keyRefused: 'The service did not accept this key.',+ webPage: '{url} answers with a web page ({status}), not the API: check the address and the API format.',+ noImages: 'This model cannot read pictures, and the agent has to look at its frames: choose one that does.',+ nothingThere: 'Nothing answers at {url}: check the address and the API format.',+ answered: 'The service answered {status}.',+ },cancel: 'Cancel',mcpSummary: 'Your MCP servers: {on} of {n} used in OpenFilm',mcpManage: 'Choose',diff --git a/packages/openfilm/studio/ui/src/i18n/es.ts b/packages/openfilm/studio/ui/src/i18n/es.tsindex abeb20a..a1936d9 100644--- a/packages/openfilm/studio/ui/src/i18n/es.ts+++ b/packages/openfilm/studio/ui/src/i18n/es.ts@@ -1711,6 +1711,19 @@ export const es: Words = {byokRules: 'Sus reglas son el AGENTS.md (o CLAUDE.md) de la carpeta del proyecto. Uno guardado en otro sitio, en una carpeta superior o con los ajustes del agente, no se lee.',save: 'Comprobar y guardar',checkingKey: 'Comprobando…',+ ownErrors: {+ noFormat: 'Elige el formato de API.',+ address: 'La dirección tiene que empezar por https:// (o http:// si el servicio está en este equipo).',+ noModel: 'Escribe el nombre del modelo.',+ modelGone: 'Ese modelo ya no está configurado.',+ noKey: 'Pega la clave.',+ unreachable: 'No se pudo contactar con el servicio: {reason}',+ keyRefused: 'El servicio no aceptó esta clave.',+ webPage: '{url} responde con una página web ({status}), no con la API: revisa la dirección y el formato de API.',+ noImages: 'Este modelo no puede leer imágenes, y el agente tiene que mirar sus propios fotogramas: elige uno que pueda.',+ nothingThere: 'Nada responde en {url}: revisa la dirección y el formato de API.',+ answered: 'El servicio respondió {status}.',+ },cancel: 'Cancelar',mcpSummary: 'Tus servidores MCP: {on} de {n} en uso en OpenFilm',mcpManage: 'Elegir',diff --git a/packages/openfilm/studio/ui/src/i18n/ja.ts b/packages/openfilm/studio/ui/src/i18n/ja.tsindex 3d19213..3408a42 100644--- a/packages/openfilm/studio/ui/src/i18n/ja.ts+++ b/packages/openfilm/studio/ui/src/i18n/ja.ts@@ -1711,6 +1711,19 @@ export const ja: Words = {byokRules: '従うルールは、プロジェクトのフォルダにある AGENTS.md(または CLAUDE.md)だけです。上位のフォルダやエージェントの設定フォルダなど、ほかの場所にあるものは読まれません。',save: '確認して保存',checkingKey: '確認中…',+ ownErrors: {+ noFormat: 'API 形式を選んでください。',+ address: 'アドレスは https:// で始めてください(このコンピューター上のサービスなら http:// も使えます)。',+ noModel: 'モデル名を入れてください。',+ modelGone: 'そのモデルはもう設定されていません。',+ noKey: 'キーを貼り付けてください。',+ unreachable: 'サービスに接続できませんでした: {reason}',+ keyRefused: 'サービスがこのキーを受け付けませんでした。',+ webPage: '{url} が返したのは API ではなくウェブページです({status})。アドレスと API 形式を確認してください。',+ noImages: 'このモデルは画像を読めません。エージェントは自分で作ったフレームを確認するため、画像を読めるモデルを選んでください。',+ nothingThere: '{url} には応答するものがありません。アドレスと API 形式を確認してください。',+ answered: 'サービスの応答は {status} でした。',+ },cancel: 'キャンセル',mcpSummary: 'あなたの MCP サーバー:{n} 個のうち {on} 個を OpenFilm で使用',mcpManage: '選ぶ',diff --git a/packages/openfilm/studio/ui/src/i18n/ko.ts b/packages/openfilm/studio/ui/src/i18n/ko.tsindex d8b793e..5f29024 100644--- a/packages/openfilm/studio/ui/src/i18n/ko.ts+++ b/packages/openfilm/studio/ui/src/i18n/ko.ts@@ -1707,6 +1707,19 @@ export const ko: Words = {byokRules: '따르는 규칙은 프로젝트 폴더에 있는 AGENTS.md(또는 CLAUDE.md)뿐입니다. 상위 폴더나 에이전트 설정 폴더 등 다른 곳에 둔 파일은 읽지 않습니다.',save: '확인 후 저장',checkingKey: '확인 중…',+ ownErrors: {+ noFormat: 'API 형식을 선택하세요.',+ address: '주소는 https://로 시작해야 합니다(이 컴퓨터의 서비스라면 http://도 됩니다).',+ noModel: '모델 이름을 입력하세요.',+ modelGone: '그 모델은 더 이상 설정되어 있지 않습니다.',+ noKey: '키를 붙여 넣으세요.',+ unreachable: '서비스에 연결할 수 없습니다: {reason}',+ keyRefused: '서비스가 이 키를 받아들이지 않았습니다.',+ webPage: '{url}이(가) API가 아닌 웹 페이지로 응답합니다({status}). 주소와 API 형식을 확인하세요.',+ noImages: '이 모델은 이미지를 읽을 수 없습니다. 에이전트가 직접 만든 프레임을 확인해야 하므로 이미지를 읽을 수 있는 모델을 선택하세요.',+ nothingThere: '{url}에서 응답하는 것이 없습니다. 주소와 API 형식을 확인하세요.',+ answered: '서비스가 {status}(으)로 응답했습니다.',+ },cancel: '취소',mcpSummary: '내 MCP 서버: {n}개 중 {on}개를 OpenFilm에서 사용',mcpManage: '선택',diff --git a/packages/openfilm/studio/ui/src/i18n/zh-CN.ts b/packages/openfilm/studio/ui/src/i18n/zh-CN.tsindex 91d590a..459d0f0 100644--- a/packages/openfilm/studio/ui/src/i18n/zh-CN.ts+++ b/packages/openfilm/studio/ui/src/i18n/zh-CN.ts@@ -1712,6 +1712,19 @@ export const zhCN: Words = {byokRules: '它遵循的规则只来自项目文件夹里的 AGENTS.md(或 CLAUDE.md)。放在别处的,比如上层文件夹或智能体自己的设置目录里,都不会被读取。',save: '检查并保存',checkingKey: '正在检查…',+ ownErrors: {+ noFormat: '请选择 API 格式。',+ address: '地址要以 https:// 开头(本机上的服务可以用 http://)。',+ noModel: '请填写模型。',+ modelGone: '这个模型已经不在设置里了。',+ noKey: '请粘贴密钥。',+ unreachable: '连不上这个服务:{reason}',+ keyRefused: '服务不接受这个密钥。',+ webPage: '{url} 返回的是网页({status}),不是 API:请检查地址和 API 格式。',+ noImages: '这个模型不能看图,而智能体需要查看自己生成的画面:请换一个能看图的模型。',+ nothingThere: '{url} 这里没有可用的接口:请检查地址和 API 格式。',+ answered: '服务返回了 {status}。',+ },cancel: '取消',mcpSummary: '你的 MCP 服务:{n} 个,其中 {on} 个在 OpenFilm 里使用',mcpManage: '选择',diff --git a/packages/openfilm/studio/ui/src/lib/agent-row.test.ts b/packages/openfilm/studio/ui/src/lib/agent-row.test.tsindex 4727091..6d70731 100644--- a/packages/openfilm/studio/ui/src/lib/agent-row.test.ts+++ b/packages/openfilm/studio/ui/src/lib/agent-row.test.ts@@ -1,6 +1,7 @@import { test } from 'node:test';import assert from 'node:assert/strict';-import { accountOrg, missingActions } from './agent-row.ts';+import { accountOrg, missingActions, ownModelError } from './agent-row.ts';+import { zhCN } from '../i18n/zh-CN.ts';test('an agent not found offers Locate and its installer, or its install page', () => {const host = { locate: true, install: true };@@ -19,3 +20,12 @@ test("an account's organization is named unless it only repeats the email, as aassert.equal(accountOrg({ org: "[email protected]'s Organization" }), "[email protected]'s Organization");assert.equal(accountOrg({ email: '[email protected]' }), null);});++test("an own model not saved is said in the person's language, with the address, status or reason; the service's own words as they are", () => {+ const t = (path: string) => path.split('.').reduce<unknown>((at, part) => (at as Record<string, unknown> | undefined)?.[part], zhCN) as string | undefined ?? path;+ assert.equal(ownModelError({ error: 'in English', code: 'web-page', url: 'https://example.test/v1/responses', status: 405 }, t), 'https://example.test/v1/responses 返回的是网页(405),不是 API:请检查地址和 API 格式。');+ assert.equal(ownModelError({ error: 'in English', code: 'unreachable', reason: 'fetch failed' }, t), '连不上这个服务:fetch failed');+ assert.equal(ownModelError({ error: 'in English', code: 'no-key' }, t), '请粘贴密钥。');+ assert.equal(ownModelError({ error: 'Unknown parameter: max_output_tokens' }, t), 'Unknown parameter: max_output_tokens');+ assert.equal(ownModelError({ error: 'from a newer app', code: 'something-new' }, t), 'from a newer app');+});diff --git a/packages/openfilm/studio/ui/src/lib/agent-row.ts b/packages/openfilm/studio/ui/src/lib/agent-row.tsindex f2367be..f85a1e8 100644--- a/packages/openfilm/studio/ui/src/lib/agent-row.ts+++ b/packages/openfilm/studio/ui/src/lib/agent-row.ts@@ -19,3 +19,16 @@ export function accountOrg(account: { org?: string | null; email?: string | nullif (!account.org) return null;return account.email && account.org === `${account.email}'s Organization` ? null : account.org;}++/**+ * Why one of the person's own models was not saved, in their language: the desktop app names each of its own+ * sentences by a code (agent-roster.mjs probeModel and saveOwnModel), with the address, status or reason it names.+ * The service's own words, and a code with no words here, are shown as the app said them.+ */+export function ownModelError(failure: { error: string; code?: string; url?: string; status?: number; reason?: string }, t: (path: string) => string): string {+ if (!failure.code) return failure.error;+ const path = `settings.agents.ownErrors.${failure.code.replace(/-(\w)/g, (_, c: string) => c.toUpperCase())}`;+ const words = t(path);+ if (words === path) return failure.error;+ return words.replace('{url}', failure.url ?? '').replace('{status}', String(failure.status ?? '')).replace('{reason}', failure.reason ?? '');+}diff --git a/packages/openfilm/studio/ui/src/lib/host.ts b/packages/openfilm/studio/ui/src/lib/host.tsindex 746ba5b..38b9b2f 100644--- a/packages/openfilm/studio/ui/src/lib/host.ts+++ b/packages/openfilm/studio/ui/src/lib/host.ts@@ -105,7 +105,7 @@ export interface StudioHost {* One of the person's own models set up (no `id`) or changed: checked before it is kept. A key left empty keeps its* own, or takes the one of another model on the same address.*/- saveOwnModel: (config: HostOwnModelConfig) => Promise<{ ok: true; id: string } | { ok: false; error: string; code?: string }>;+ saveOwnModel: (config: HostOwnModelConfig) => Promise<{ ok: true; id: string } | { ok: false; error: string; code?: string; url?: string; status?: number; reason?: string }>;removeOwnModel: (id: string) => Promise<unknown>;/*** The MCP servers the person added to an agent themselves (its maker's not among them), each let into the app or