Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(server): 用 AI 生成 id 只用项目里的免费模型

lmliheng37ea1dbafccf
diff --git a/changelog/unreleased/2026-11-14-free-model-id-suggestions.md b/changelog/unreleased/2026-11-14-free-model-id-suggestions.md
new file mode 100644
index 00000000..c2e5ecf1
--- /dev/null
+++ b/changelog/unreleased/2026-11-14-free-model-id-suggestions.md
@@ -0,0 +1,31 @@
+# Generate with AI uses only the Project's free models
+
+- **Date:** 2026-11-14
+- **Type:** feature
+- **Scope:** `server`, `web`, `docs`
+
+[中文版](2026-11-14-free-model-id-suggestions.zh.md)
+
+**Generate with AI**, the button beside every id field (Project, Agent, Benchmark, organization, channel), used the **default model configured for that Project** — and a new Project is seeded with a paid one (`deepseek/deepseek-flash`). So an action whose whole purpose is naming something spent money on the reader's own key. It never showed up in the cost center (the request is deliberately not metered), but the provider billed it.
+
+The ask now looks only for **free models**: the entries in that Project whose `pricing` says 0 on all three buckets — the ones the models page badges as free. Free endpoints get throttled and get retired, so it does not stop at the first: they are tried **in config order**, at most four, sharing a 30-second budget, and the first one that produces a usable id wins. Every $0 entry that carries a key sits on that walk — OpenRouter's `:free` rows and its free router among them.
+
+The Project's **default model is no longer consulted here**, so generating an id never costs anything. The trade-off: with no usable free model in the Project, a non-English name falls back to the ASCII slug of the name, and a name with no ASCII at all lands on a dated placeholder that says why. The reason code `no_default_model` became `no_free_model`, in both languages.
+
+## Details
+
+- `packages/server/src/services/project-config-service.ts`: `completeOnce` went from reading the `default_model` entry to walking the free ones. New pure `freeModelEntries(raw)` — the entries whose `pricing` is present with all three buckets at 0, in config order, one row per reference. An entry with no `pricing` at all reads as unpriced rather than free, and a self-hosted (vLLM/custom) row that bills nobody through a rate the catalog cannot know is deliberately left out.
+- A candidate that **cannot be built** (no credential, no routable id) is skipped without consuming one of the four attempts or any waiting time — otherwise a config full of unusable free rows would eat the budget of the one that works. Each attempt's timeout is the smaller of the single-attempt cap (15 s) and what is left of the walk's budget, so the last candidate cannot overshoot it either.
+- Nothing was ever sent — no free entry, or none usable — reports `cause: "no_model"`; something was sent and none answered reports `cause: "failed"`. Both are recorded by the route in the errors panel (`id_suggest` / `id_suggest_failed`), so it can say why only a placeholder was filled in.
+- `packages/server/src/api/types.ts`: the `SemanticIdSuggestReason` value `no_default_model` was renamed `no_free_model`. A client that does not know a reason still draws a sentence for it (`reasonUnknown`), so mixed old/new builds do not lose the note.
+- `packages/web/src/lib/strings.ts`, `strings-en.ts`: the `no_free_model` and `model_failed` phrases now talk about free models.
+
+## Tests
+
+- `packages/server/test/utility-completion.test.ts`: `freeModelEntries`' selection, config order, de-duplication and "a missing bucket is 0, a price on any bucket is not free"; `completeOnce` reporting `no_model` with the new wording when the Project holds only paid rows — even the default one; and a walk over two credentialless free rows that **skips the first** and reports the second's dead end, which only holds if it really moved on. Plus `utilityCompletionConfig`'s timeout parameter: 15 s by default, shortened to what is left of the budget on the walk.
+- `packages/server/test/suggest-id-routes.test.ts`, `packages/server/test/organization-runtime.test.ts`: reason code and wording.
+- `packages/web/test/id-suggest-notice.test.ts`: the reason dictionary matches the new code.
+
+## Compatibility
+
+The wire contract changes by one enum value (`reason`). No new dependency, no Project config change, no database change. The behaviour is a **change** rather than a pure addition: an id that used to come from the default model now appears only when the Project carries a usable free model; otherwise the name transliteration or the placeholder answers. To get the old behaviour back, put a key on a $0 entry in the Project.
diff --git a/changelog/unreleased/2026-11-14-free-model-id-suggestions.zh.md b/changelog/unreleased/2026-11-14-free-model-id-suggestions.zh.md
new file mode 100644
index 00000000..e7d733b9
--- /dev/null
+++ b/changelog/unreleased/2026-11-14-free-model-id-suggestions.zh.md
@@ -0,0 +1,31 @@
+# 用 AI 生成 id 只用项目里的免费模型
+
+- **Date:** 2026-11-14
+- **Type:** feature
+- **Scope:** `server`, `web`, `docs`
+
+[English](2026-11-14-free-model-id-suggestions.md)
+
+每个 id 输入框旁边的**用 AI 生成**(项目、Agent、Benchmark、组织、频道)此前用的是**这个项目配置的默认模型** —— 而新建项目的种子默认是 `deepseek/deepseek-flash` 这类付费模型,于是一个只是想给项目起个 id 的动作,会按你自己的 key 花钱。它不挂会话、也不进成本中心(代码里就不记账),但厂商那边是真扣的。
+
+现在这条请求只找**免费模型**:这个项目里 `pricing` 三个桶都是 0 的条目(模型页面上带「免费」标记的那种)。这类免费端点常被限流、也常被下架,所以不是一个,而是**按配置顺序依次试**:最多 4 个、合计不超过 30 秒,一个不给回答就换下一个,任何一个给了可用 id 就返回。项目里凡是配了 key 的 $0 条目都在这条链上 —— OpenRouter 的 `:free` 系列和 `openrouter/free` 免费路由就在其中。
+
+**项目的默认模型不再参与这一步**,所以生成 id 永远不会花钱。代价是:项目里没有能用的免费模型时,中文名会退到名称的 ASCII 转写;连转写都做不出(纯中文、没有 ASCII)时,落到带日期的占位 id 并说明原因 —— 原因码从 `no_default_model`(未配置默认模型)改成 `no_free_model`(这个项目里没有可用的免费模型),中文与英文文案同步改了。
+
+## 细节
+
+- `packages/server/src/services/project-config-service.ts`:`completeOnce` 从「读 `default_model` 那一条」改成「走一遍免费条目」。新增纯函数 `freeModelEntries(raw)` —— 按配置顺序取出 `pricing` 存在且三个桶都是 0 的条目,同一引用只留一次;没有 `pricing` 的算「未定价」而不是免费,自建(vLLM/custom)那种「谁都不收费但目录里写不出价格」的行也刻意不算。
+- 候选**构造不出来**(没有凭据、id 无法路由)时直接跳过,既不占用 4 次尝试、也不花等待时间 —— 否则一个塞满不可用免费行的配置会吃掉可用那条的预算。每个尝试的超时取「单次上限(15 秒)」与「剩余预算」的较小值,所以最后一条也不会超时。
+- 一次都没发出去(项目里没有免费条目,或没有一条能用)→ `cause: "no_model"`;发出去过但都没回答 → `cause: "failed"`。两者都由路线记进错误中心(`id_suggest` / `id_suggest_failed`),错误面板能说明为什么只给了占位 id。
+- `packages/server/src/api/types.ts`:`SemanticIdSuggestReason` 的 `no_default_model` 改名 `no_free_model`。前端遇到不认识的原因码仍会照常画一句说明(`reasonUnknown`),所以新旧前端/服务端混用不会丢提示。
+- `packages/web/src/lib/strings.ts`、`strings-en.ts`:`no_free_model` 与 `model_failed` 两句改成说「免费模型」。
+
+## 测试
+
+- `packages/server/test/utility-completion.test.ts`:`freeModelEntries` 的取舍、配置顺序、去重与「缺桶算 0、任一桶有价就不算免费」;`completeOnce` 在项目里只有付费条目(哪怕它就是默认模型)时报 `no_model` 并给出新文案;两条没有凭据的免费行时,会**跳过第一条**、报告第二条的死因 —— 这条只有在真的往下走了才成立。另加 `utilityCompletionConfig` 的超时参数:默认 15 秒、走链时按剩余预算缩短。
+- `packages/server/test/suggest-id-routes.test.ts`、`packages/server/test/organization-runtime.test.ts`:原因码与新文案同步。
+- `packages/web/test/id-suggest-notice.test.ts`:原因字典与新码对齐。
+
+## 兼容性
+
+线上协议只换了一个枚举值(`reason`),没有新依赖、没有 Project 配置变更、没有数据库变更。行为上是**变化**而不是纯增量:以前从默认模型拿到的 id,现在只有在项目里配了可用的免费模型时才会出现;否则退到名称转写或占位 id。想改回去就在项目里把一个 $0 条目配上 key。
diff --git a/packages/docs/content/agents.en.md b/packages/docs/content/agents.en.md
index e8d02976..6e14d7fe 100644
--- a/packages/docs/content/agents.en.md
+++ b/packages/docs/content/agents.en.md
@@ -53,7 +53,7 @@ The **Report-writing agent** example creates an agent with the id `report-writer
1. On the **Agents** page, select **Create manually**. The **Create agent** dialog opens.
2. Optional: in **Name**, enter a name. An empty name uses the agent id.
-3. In **Agent id**, enter an id, or select **Generate with AI** beside the field to have the Project's default model derive one from the name, or from the description while the name is empty. An id is 2–64 characters long, starts with a lowercase letter, and uses only lowercase letters, digits and underscores. A proposal replaces what is in the box and stays editable. You cannot change the id later.
+3. In **Agent id**, enter an id, or select **Generate with AI** beside the field to have a free ($0-priced) model of the Project derive one from the name — one that gives no answer is followed by the next, and the default model is never consulted, so this step costs nothing — or from the description while the name is empty. An id is 2–64 characters long, starts with a lowercase letter, and uses only lowercase letters, digits and underscores. A proposal replaces what is in the box and stays editable. You cannot change the id later.
4. Optional: fill in **Description**.
5. Optional: in **Plugins**, select plugins from the plugin library to install on the new agent. Their Skills and hook packages are installed when the agent is created.
6. Optional: in **Import Skills from a project directory**, select a directory. Adelie reads the Skills under its `.agents/skills` and `.claude/skills` folders; select the ones to install. If a Skill from the directory has the same name as a Skill from a selected plugin, the directory's Skill is installed.
diff --git a/packages/docs/content/agents.zh.md b/packages/docs/content/agents.zh.md
index bd612878..0d4c3b83 100644
--- a/packages/docs/content/agents.zh.md
+++ b/packages/docs/content/agents.zh.md
@@ -53,7 +53,7 @@ Agent 是 Project 里配置好的助手。每个 Agent 都有自己的指令、
1. 在**智能体**页面选择**手动创建**,打开**创建 Agent** 对话框。
2. 可选:在**名称**中填写名称。名称留空时用 Agent id。
-3. 在 **Agent id** 中输入 id,也可以点击输入框旁边的**用 AI 生成**,由 Project 的默认模型根据名称生成一个;名称为空时则根据描述生成。id 长度为 2–64 个字符,以小写字母开头,只能用小写字母、数字和下划线。生成的 id 会覆盖框里原有的内容,之后仍可以手动修改。创建后 id 不能再改。
+3. 在 **Agent id** 中输入 id,也可以点击输入框旁边的**用 AI 生成**,由 Project 里一个免费(0 定价)的模型根据名称生成一个,一个不行就换下一个;名称为空时则根据描述生成。这一步不花钱,默认模型不参与。id 长度为 2–64 个字符,以小写字母开头,只能用小写字母、数字和下划线。生成的 id 会覆盖框里原有的内容,之后仍可以手动修改。创建后 id 不能再改。
4. 可选:填写**描述**。
5. 可选:在**插件**中从插件库选择要装到新 Agent 上的插件。Agent 创建时会一并装上这些插件的 Skill 和钩子包。
6. 可选:在**从项目目录导入技能**中选择一个目录。Adelie 会读取这个目录下 `.agents/skills` 和 `.claude/skills` 文件夹里的 Skill,从中勾选要安装的。目录里的 Skill 与所选插件里的 Skill 同名时,装的是目录里的那个。
diff --git a/packages/docs/content/company-mode.en.md b/packages/docs/content/company-mode.en.md
index 8adf8a81..255d0227 100644
--- a/packages/docs/content/company-mode.en.md
+++ b/packages/docs/content/company-mode.en.md
@@ -39,7 +39,7 @@ An organization lives inside a Project, at `<project>/organizations/<org_id>/`,
5. Optional: choose a **Model**, a **Company workspace** and a **CEO budget**.
6. Select **Create**. The CEO's desk session opens.
-**Generate with AI** always leaves an id in the box. The Project's default model proposes a short English snake_case id. When it cannot, an ASCII slug of the name is used. When neither works, the field gets a dated placeholder, and a note under it says why and asks you to replace it.
+**Generate with AI** always leaves an id in the box. A **free ($0-priced)** model of the Project proposes a short English snake_case id, and one that gives no answer is followed by the next. When none of them can, an ASCII slug of the name is used. When neither works, the field gets a dated placeholder, and a note under it says why and asks you to replace it. The Project's default model is not consulted — this step costs nothing.
### From the CLI
diff --git a/packages/docs/content/company-mode.zh.md b/packages/docs/content/company-mode.zh.md
index e0ec7d4c..9cf03189 100644
--- a/packages/docs/content/company-mode.zh.md
+++ b/packages/docs/content/company-mode.zh.md
@@ -39,7 +39,7 @@ description: 把一句话的使命变成一个由 Agent 组成的组织:它靠
5. 可选:选择**模型**、**公司工作区**和 **CEO 预算**。
6. 选择**创建**。CEO 的工位会话随即打开。
-**用 AI 生成**一定会在输入框里留下一个 id:Project 的默认模型先提议一个简短的英文 snake_case id;模型给不出时,改用名称转写成的 ASCII slug;两者都不行时,字段里会填入一个带日期的占位 id,下方写明原因,并请你改掉。
+**用 AI 生成**一定会在输入框里留下一个 id:先由 Project 里一个**免费(0 定价)**的模型提议一个简短的英文 snake_case id,一个不行就换下一个;试过都不行时,改用名称转写成的 ASCII slug;两者都不行时,字段里会填入一个带日期的占位 id,下方写明原因,并请你改掉。Project 的默认模型不参与,这一步不花钱。
### 用 CLI 创建
diff --git a/packages/docs/content/server-api.en.md b/packages/docs/content/server-api.en.md
index 8d548357..6c6f9b7a 100644
--- a/packages/docs/content/server-api.en.md
+++ b/packages/docs/content/server-api.en.md
@@ -361,9 +361,9 @@ Projects, their members, and the Project-wide settings stored in `.project_confi
`POST /api/projects/:projectId/suggest-id` takes `{name, kind, taken?}` and returns `{id, source, reason?}`. `kind` is `project`, `agent`, `benchmark`, `org` or `channel`, and `taken` names the ids the proposal must avoid. It is the one route behind every **Generate with AI** button beside an id field.
-- The default model of the Project in the path translates the name into one English id in the kind's spelling (`source: model`); the **New Project** dialog borrows the Project it was opened from. An answer that yields no id has the model asked once more, with the format spelled out.
-- An ASCII slug of the name answers when no model is configured or neither answer is usable (`source: fallback`).
-- A name neither path can name gets a dated placeholder (`source: placeholder`) with a `reason` of `no_default_model`, `model_failed`, `unusable_answer` or `no_ascii`: `project_<yyyymmdd>`, `agent_<yyyymmdd>`, `benchmark-<yyyymmdd>`, `co_org_<yyyymmdd>` or `ch_channel_<yyyymmdd>`, with the username in front for a non-admin's Project.
+- A **free** model of the Project in the path — one whose `pricing` says 0 on all three buckets — translates the name into one English id in the kind's spelling (`source: model`). There is usually more than one, and free endpoints are throttled and retired routinely, so they are tried in config order: at most four, sharing a 30-second budget, and one that gives no answer is followed by the next. The Project's **default model is not among them** — this step must not cost anything. The **New Project** dialog borrows the Project it was opened from. An answer that yields no id has the model asked once more, with the format spelled out.
+- An ASCII slug of the name answers when the Project has no usable free model, or none of the ones tried produced a usable id (`source: fallback`).
+- A name neither path can name gets a dated placeholder (`source: placeholder`) with a `reason` of `no_free_model`, `model_failed`, `unusable_answer` or `no_ascii`: `project_<yyyymmdd>`, `agent_<yyyymmdd>`, `benchmark-<yyyymmdd>`, `co_org_<yyyymmdd>` or `ch_channel_<yyyymmdd>`, with the username in front for a non-admin's Project.
- The kinds differ only in the id's shape, the ids the server avoids on its own, and who may ask. `project` is snake_case for an admin and `<username>-<suffix>` for everyone else, and avoids every Project id on the server; `agent` is snake_case and avoids the Project's agents; `benchmark` is kebab-case, avoids the Project's Benchmarks and is owner only; `org` and `channel` carry the `co_` and `ch_` prefix, never doubled when the answer already has it, and return `404` `company_mode_off` while company mode is off. Every other caller must be a member of the Project.
- The ids the server avoids on its own are the names the kind's create route would refuse as taken, a leftover folder no list shows included. They never reach the prompt; a collision only adds a `_2` / `-2` suffix. A core the kind's rule rejects for starting with a digit or being one character long is retried behind the kind's noun (`3D Viewer` → `agent_3d_viewer`).
- The route never fails for a name it cannot translate, so a dialog that asked for an id always gets one. Every model dead end is recorded as an `id_suggest_failed` error, under the source `organization` for `org` and `channel` and `id_suggest` for the rest. The completion runs with thinking off and within the shared meta budget, belongs to no Session and is not metered.
diff --git a/packages/docs/content/server-api.zh.md b/packages/docs/content/server-api.zh.md
index bdbdb879..b90dbf17 100644
--- a/packages/docs/content/server-api.zh.md
+++ b/packages/docs/content/server-api.zh.md
@@ -361,9 +361,9 @@ Project、Project 成员,以及保存在 `.project_config.toml` 中的 Project
`POST /api/projects/:projectId/suggest-id` 接收 `{name, kind, taken?}`,返回 `{id, source, reason?}`。`kind` 取 `project`、`agent`、`benchmark`、`org` 或 `channel`,`taken` 是提议必须避开的一批 id。id 输入框旁边的**用 AI 生成**按钮,背后都是这一条路由。
-- 路径里这个 Project 的默认模型把名称翻译成一个符合该 kind 拼写风格的英文 id(`source: model`);**新建 Project** 对话框借用的是打开它时所在的那个 Project。回答没有得出 id 时,会带着明确的格式要求再问模型一次。
-- 没有配置模型,或两次回答都不可用时,改用名称生成的 ASCII slug(`source: fallback`)。
-- 两条路径都生成不出 id 时,给出一个带日期的占位 id(`source: placeholder`),`reason` 为 `no_default_model`、`model_failed`、`unusable_answer` 或 `no_ascii`:`project_<yyyymmdd>`、`agent_<yyyymmdd>`、`benchmark-<yyyymmdd>`、`co_org_<yyyymmdd>` 或 `ch_channel_<yyyymmdd>`;非管理员的 Project id 前面还带用户名。
+- 路径里这个 Project 中一个**免费(`pricing` 三个桶都是 0)**的模型把名称翻译成一个符合该 kind 拼写风格的英文 id(`source: model`)。这类模型通常不只一个、也常被限流或下架,所以服务端会按配置顺序依次试,最多 4 个、合计不超过 30 秒,一个不给回答就换下一个;**Project 的默认模型不参与**,这一步不花任何钱。**新建 Project** 对话框借用的是打开它时所在的那个 Project。回答没有得出 id 时,会带着明确的格式要求再问一次。
+- 这个 Project 里没有能用的免费模型,或试过的免费模型都没给出可用 id 时,改用名称生成的 ASCII slug(`source: fallback`)。
+- 两条路径都生成不出 id 时,给出一个带日期的占位 id(`source: placeholder`),`reason` 为 `no_free_model`、`model_failed`、`unusable_answer` 或 `no_ascii`:`project_<yyyymmdd>`、`agent_<yyyymmdd>`、`benchmark-<yyyymmdd>`、`co_org_<yyyymmdd>` 或 `ch_channel_<yyyymmdd>`;非管理员的 Project id 前面还带用户名。
- 各个 kind 的差别只有三处:id 的形状、服务端自己要避开的 id,以及谁可以请求。`project` 对管理员是 snake_case,对其他人是 `<username>-<后缀>`,要避开服务器上的每一个 Project id;`agent` 是 snake_case,要避开这个 Project 的 Agent;`benchmark` 是 kebab-case,要避开这个 Project 的 Benchmark,且仅限所有者;`org` 和 `channel` 带 `co_`、`ch_` 前缀,回答里已有前缀时不会重复添加,公司模式关闭时返回 `404` `company_mode_off`。其余情况下调用者必须是这个 Project 的成员。
- 服务端自己要避开的,是该 kind 的创建路由会以「已占用」拒绝的那些名称,包括任何列表都不显示的残留目录。它们不会进入提示词;发生冲突时只会加上 `_2` / `-2` 后缀。核心词因为以数字开头或只有一个字符而被该 kind 的规则拒绝时,会放到这个 kind 的名词后面再试一次(`3D Viewer` → `agent_3d_viewer`)。
- 名称翻译不出来时路由也不会失败,因此请求 id 的对话框总能拿到结果。模型侧的每一次失败都会记录为 `id_suggest_failed` 错误,`org` 和 `channel` 记在 `organization` 来源下,其余记在 `id_suggest` 下。这次补全关闭思考运行,使用共享的元请求预算,不属于任何 Session,也不计量。
diff --git a/packages/docs/content/web-app.en.md b/packages/docs/content/web-app.en.md
index c7eb3a6e..77767014 100644
--- a/packages/docs/content/web-app.en.md
+++ b/packages/docs/content/web-app.en.md
@@ -153,7 +153,7 @@ Any signed-in user can create a Project and becomes its owner.
1. Open the Project switcher at the top of the sidebar.
2. Select **New Project**.
3. In **Display name**, enter an optional display name. If you leave it empty, the id is shown.
-4. In **Project id**, enter an id, or select **Generate with AI** beside the field to derive one from the display name. The current Project's default model writes the proposal, since a Project is not inside a Project.
+4. In **Project id**, enter an id, or select **Generate with AI** beside the field to derive one from the display name. A free ($0-priced) model of the current Project writes the proposal — one that gives no answer is followed by the next, and the Project's default model is deliberately not among them, because this step should not cost anything. Since a Project is not inside a Project, the proposal is borrowed from the Project the dialog was opened from.
5. Select **Create**. You are now the Project's owner.
The id is 2–64 characters long. It starts with a lowercase letter and uses only lowercase letters, digits, and underscores. For a user other than the admin, it starts with the username and a hyphen, and only the part after that prefix is typed.
diff --git a/packages/docs/content/web-app.zh.md b/packages/docs/content/web-app.zh.md
index 8ec66a25..e2fde666 100644
--- a/packages/docs/content/web-app.zh.md
+++ b/packages/docs/content/web-app.zh.md
@@ -153,7 +153,7 @@ penguin web
1. 打开侧边栏顶部的 Project 切换器。
2. 选择**新建 Project**。
3. 在**显示名**中填写显示名,可以不填,不填时显示 id。
-4. 在 **Project id** 中填写 id,也可以点输入框旁边的**用 AI 生成**,从显示名生成一个。提议由当前 Project 的默认模型写出,因为 Project 本身不在任何 Project 之内。
+4. 在 **Project id** 中填写 id,也可以点输入框旁边的**用 AI 生成**,从显示名生成一个。提议由当前 Project 里一个免费(0 定价)的模型写出 —— 一个不行就换下一个;Project 的默认模型不参与,因为这一步不该花钱。Project 本身不在任何 Project 之内,所以借的就是打开这个对话框时所在的那个 Project。
5. 选择**创建**。你就是这个 Project 的 owner 了。
id 长 2–64 个字符,以小写字母开头,只能包含小写字母、数字和下划线。admin 以外的用户创建的 id 以「用户名-」开头,输入框里只需填写这个前缀后面的部分。
diff --git a/packages/server/src/api/types.ts b/packages/server/src/api/types.ts
index ceb3137d..83b203e6 100644
--- a/packages/server/src/api/types.ts
+++ b/packages/server/src/api/types.ts
@@ -6164,13 +6164,14 @@ export interface SemanticIdSuggestRequest {
/**
* Why a proposal fell all the way through to a placeholder — what the client tells the user to
- * explain the id it was just handed. `no_default_model`: the Project has no default model to
- * ask. `model_failed`: it was asked and the request failed (no credential, a rejection, a
- * timeout). `unusable_answer`: it answered twice and neither answer yielded an id.
- * `no_ascii`: no model was consulted at all and the name carries no ASCII to transliterate.
+ * explain the id it was just handed. `no_free_model`: the Project lists no free ($0-priced)
+ * model that can be asked, or no such entry carries a usable credential. `model_failed`: a free
+ * model was asked and every request failed (a rejection, a timeout). `unusable_answer`: it
+ * answered twice and neither answer yielded an id. `no_ascii`: no model was consulted at all
+ * and the name carries no ASCII to transliterate.
*/
export type SemanticIdSuggestReason =
- "no_default_model" | "model_failed" | "unusable_answer" | "no_ascii";
+ "no_free_model" | "model_failed" | "unusable_answer" | "no_ascii";
export interface SemanticIdSuggestResponse {
/**
diff --git a/packages/server/src/services/project-config-service.ts b/packages/server/src/services/project-config-service.ts
index 97df2cab..cefd20f7 100644
--- a/packages/server/src/services/project-config-service.ts
+++ b/packages/server/src/services/project-config-service.ts
@@ -339,6 +339,15 @@ const SPEED_PROBE_PROMPT =
*/
const UTILITY_COMPLETION_BUDGET = 300;
const UTILITY_COMPLETION_TIMEOUT_MS = 15_000;
+/**
+ * How many free models one utility ask may actually be sent to, and how long the whole walk may
+ * take. A naming dialog is waiting on the answer, so a run of dead or throttled free endpoints
+ * must not add up to a stall: each attempt gets what is left of the budget, up to the single
+ * attempt timeout above, and candidates that cannot be built at all (no credential, no
+ * routable id) cost neither an attempt nor a wait.
+ */
+const UTILITY_COMPLETION_ATTEMPTS = 4;
+const UTILITY_COMPLETION_WALK_BUDGET_MS = 30_000;
/**
* What one utility completion produced: the model's text, or why there is none. A bare null
@@ -368,9 +377,9 @@ function outcomeDetail(outcome: LLMOutcome): string {
}
/**
- * The model config one utility completion runs with, built from the Project's default model
- * entry. Exported because two of its fields decide whether an answer arrives at all, and
- * reading them here costs no network:
+ * The model config one utility completion runs with, built from a Project's model entry.
+ * Exported because two of its fields decide whether an answer arrives at all, and reading them
+ * here costs no network:
*
* - `thinkingLevel: "none"`, the level core's own out-of-band requests use. Every provider the
* product ships works with it; a level that leaves thinking on spends the budget below on
@@ -379,10 +388,14 @@ function outcomeDetail(outcome: LLMOutcome): string {
* a budget cut to the size of an identifier. A reasoning model spends its thinking out of the
* same cap, so a budget that small ends the request at `finish_reason=length` with the answer
* never started (see `probeVerdict`, which tolerates exactly that ending for the probe).
+ *
+ * `requestTimeoutMs` defaults to the single attempt timeout; the walk in `completeOnce` passes
+ * what is left of its budget, so the last candidate of a slow run cannot overshoot it.
*/
export function utilityCompletionConfig(
modelId: string,
entry: Record<string, unknown>,
+ requestTimeoutMs: number = UTILITY_COMPLETION_TIMEOUT_MS,
): GenerativeModelConfig {
const clientType = canonicalClientType(optStr(entry.client_type));
// The same credential rule as every other client the harness builds (see core's
@@ -402,10 +415,40 @@ export function utilityCompletionConfig(
tools: [],
thinkingLevel: "none",
maxTokens: metaMaxTokens(UTILITY_COMPLETION_BUDGET, optNum(entry.max_tokens)),
- requestTimeoutMs: UTILITY_COMPLETION_TIMEOUT_MS,
+ requestTimeoutMs,
};
}
+/**
+ * A Project's free model entries, in the order its config lists them: what a utility ask is
+ * allowed to spend. "Free" is the same reading the models page badges with — a `pricing` table
+ * that is present and says 0 on all three buckets. An entry with no pricing at all is unpriced
+ * rather than free, and a self-hosted row that bills nobody through a rate the catalog cannot
+ * know is deliberately not counted here: this is about not spending, not about who pays.
+ *
+ * Pure, so the walk's own ordering and filtering are unit tested without a config file.
+ */
+export function freeModelEntries(
+ raw: RawTable,
+): Array<{ provider: string; modelId: string; entry: RawTable }> {
+ const out: Array<{ provider: string; modelId: string; entry: RawTable }> = [];
+ const seen = new Set<string>();
+ for (const entry of asArray(raw.models)) {
+ const provider = optStr(entry.provider);
+ const modelId = optStr(entry.model_id);
+ if (provider === undefined || modelId === undefined) continue;
+ const pricing = pricingDtoOf(entry.pricing);
+ if (pricing === undefined) continue;
+ if (pricing.cacheRead !== 0 || pricing.cacheWrite !== 0 || pricing.output !== 0) continue;
+ // One entry per reference: a duplicated row in a hand-edited file must not be asked twice.
+ const key = `${provider}\u0000${modelId}`;
+ if (seen.has(key)) continue;
+ seen.add(key);
+ out.push({ provider, modelId, entry });
+ }
+ return out;
+}
+
/**
* Drains a model stream into the answer's text, or the reason there is none.
*
@@ -928,15 +971,21 @@ export class ProjectConfigService implements ProjectConfigStore {
}
/**
- * One short completion on the Project's **default** model, for utility asks that belong to
- * no Session — today the English identifier a display name is translated into. Everything
- * comes from the stored default entry (credential, base URL, pinned protocol), and the
- * answer is the model's plain text. Nothing throws: no default model, no entry for it, a
- * construction that throws on a missing credential, a refusal, a timeout, or an answer with
- * no text all come back as `{ ok: false }` carrying the reason, which the caller records so
- * the errors panel can say why the ask produced nothing. Callers must still have a result
- * that works without it. The request is not metered — it carries no Session to attribute
- * it to.
+ * One short completion on a **free** model of the Project, for utility asks that belong to
+ * no Session — today the English identifier a display name is translated into. A free model
+ * is walked first, and several of them: free endpoints are throttled, delisted and retired
+ * routinely, one dead endpoint says nothing about the next, and the ask must not cost
+ * anything, so the Project's default model is deliberately not among the candidates. What
+ * the caller gets when none of them answers is the reason, and its own fallback.
+ *
+ * The walk is bounded twice over: at most `UTILITY_COMPLETION_ATTEMPTS` requests are sent,
+ * and together they get `UTILITY_COMPLETION_WALK_BUDGET_MS`. A candidate that cannot be built
+ * at all — no credential, no routable id — costs neither an attempt nor a wait, so a config
+ * full of unusable free rows does not eat the budget of the ones that work. Nothing throws:
+ * no free entry, an entry with no credential, a refusal, a timeout, or an answer with no text
+ * all come back as `{ ok: false }` carrying the reason, which the caller records so the
+ * errors panel can say why the ask produced nothing. Callers must still have a result that
+ * works without it. The request is not metered — it carries no Session to attribute it to.
*
* Thinking is off and the budget is the shared meta budget, for the same reason core's own
* out-of-band requests set them that way: a reasoning model spends thinking out of
@@ -945,36 +994,60 @@ export class ProjectConfigService implements ProjectConfigStore {
*/
async completeOnce(projectId: string, prompt: string): Promise<UtilityCompletion> {
const raw = await this.readRaw(projectId);
- const ref = optRef(raw.default_model);
- if (ref === undefined) {
- return { ok: false, cause: "no_model", error: "the Project names no default model" };
- }
- const entry = asArray(raw.models).find((m) => entryMatches(m, ref.provider, ref.model_id));
- if (entry === undefined) {
- return {
- ok: false,
- cause: "no_model",
- error: `the default model ${ref.provider}/${ref.model_id} has no entry in the Project config`,
- };
- }
- try {
- // Inside the try for the same reason as the probes: the SDK throws during
- // construction when a credential is missing, and that must read as a failure with a
- // reason rather than an exception out of a dialog's helper.
- const llm = new GenerativeModel({
- ...utilityCompletionConfig(ref.model_id, entry),
- ...this.requestApiKeyResolver(projectId, ref.provider, ref.model_id),
- });
- return await collectUtilityCompletion(
+ const candidates = freeModelEntries(raw);
+ const deadline = Date.now() + UTILITY_COMPLETION_WALK_BUDGET_MS;
+ // The last thing that went wrong, whether it was a build that threw or a request that
+ // produced nothing: the caller records one line, and the most recent dead end is the one
+ // worth naming.
+ let failure: Extract<UtilityCompletion, { ok: false }> | undefined;
+ let sent = 0;
+ for (const candidate of candidates) {
+ if (sent >= UTILITY_COMPLETION_ATTEMPTS) break;
+ const remaining = deadline - Date.now();
+ if (remaining < 1000) break;
+ let llm: GenerativeModel;
+ try {
+ // Inside the try for the same reason as the probes: the SDK throws during
+ // construction when a credential is missing or the id cannot be routed, and that must
+ // read as one candidate being unusable rather than an exception out of a dialog's
+ // helper. Such a candidate is skipped without being asked.
+ llm = new GenerativeModel({
+ ...utilityCompletionConfig(
+ candidate.modelId,
+ candidate.entry,
+ Math.min(UTILITY_COMPLETION_TIMEOUT_MS, remaining),
+ ),
+ ...this.requestApiKeyResolver(projectId, candidate.provider, candidate.modelId),
+ });
+ } catch (err) {
+ failure = {
+ ok: false,
+ cause: "failed",
+ error: (err instanceof Error ? err.message : String(err)).slice(0, MAX_FAILURE_DETAIL),
+ };
+ continue;
+ }
+ sent += 1;
+ const res = await collectUtilityCompletion(
llm.streamGenerate({ newMessages: [userText(prompt)] }),
);
- } catch (err) {
+ if (res.ok) return res;
+ failure = res;
+ }
+ if (sent === 0) {
+ // Nothing was ever asked, so "no model" is the honest reading rather than a model that
+ // failed: the Project either lists no free entry or has no credential for any of them.
return {
ok: false,
- cause: "failed",
- error: (err instanceof Error ? err.message : String(err)).slice(0, MAX_FAILURE_DETAIL),
+ cause: "no_model",
+ error: failure?.error ?? "the Project has no free ($0-priced) model that can be run",
};
}
+ return {
+ ok: false,
+ cause: "failed",
+ error: failure?.error ?? "every free model of the Project gave no answer",
+ };
}
async testModel(projectId: string, req: ModelTestRequest): Promise<ModelTestResponse> {
diff --git a/packages/server/src/services/semantic-id-suggest.ts b/packages/server/src/services/semantic-id-suggest.ts
index 5940c9bb..52850c9f 100644
--- a/packages/server/src/services/semantic-id-suggest.ts
+++ b/packages/server/src/services/semantic-id-suggest.ts
@@ -1,12 +1,12 @@
/**
* A semantic id for a display name, whatever kind of object the create dialog names: the one
- * proposal every `suggest-id` answer comes from. The Project's default model translates the
+ * proposal every `suggest-id` answer comes from. A free model of the Project translates the
* name into one English identifier in the kind's spelling — the common case is a Chinese name,
* which nothing mechanical can transliterate — and the ASCII slug of the name answers whenever
- * the model is unavailable, refuses or answers with something no id can be built from. A name
- * that neither path can name gets a dated placeholder and the reason it fell that far: the
- * dialog fills the box and asks for a meaningful name in its place, which is a better answer
- * than a refusal that leaves the box empty and the user with nothing to type.
+ * no free model is configured, none of them answers, or the answer names nothing an id can be
+ * built from. A name that neither path can name gets a dated placeholder and the reason it fell
+ * that far: the dialog fills the box and asks for a meaningful name in its place, which is a
+ * better answer than a refusal that leaves the box empty and the user with nothing to type.
*
* The caller decides what surrounds the proposal and passes it in: the kind's rule (a
* non-admin's Project rule depends on who asks), the ids to avoid, where a dead end is
@@ -22,7 +22,7 @@ import { fallbackSemanticId, placeholderSemanticId, sanitizeSuggestedId } from "
import type { SemanticIdRule } from "./semantic-id.js";
export interface SemanticIdSuggestDeps {
- /** One short completion on the Project's default model; absent when nothing can be asked at all. */
+ /** One short completion on a free model of the Project; absent when nothing can be asked at all. */
completeOnce?: ((projectId: string, prompt: string) => Promise<UtilityCompletion>) | undefined;
/** Records one dead end of the model half (already truncated), for the log and the errors panel. */
recordFailure: (projectId: string, detail: string) => void;
@@ -102,7 +102,7 @@ async function modelSemanticId(
const res = await complete(projectId, prompt);
if (!res.ok) {
record(res.error);
- return { reason: res.cause === "no_model" ? "no_default_model" : "model_failed" };
+ return { reason: res.cause === "no_model" ? "no_free_model" : "model_failed" };
}
const id = sanitizeSuggestedId(res.text, input.rule, avoid);
if (id !== null) return { id };
diff --git a/packages/server/test/organization-runtime.test.ts b/packages/server/test/organization-runtime.test.ts
index bd1b178e..9f8c6c06 100644
--- a/packages/server/test/organization-runtime.test.ts
+++ b/packages/server/test/organization-runtime.test.ts
@@ -53,7 +53,7 @@ const LIBRARY_VERSION = "2026.09.14.1";
const NO_MODEL: UtilityCompletion = {
ok: false,
cause: "no_model",
- error: "the Project names no default model",
+ error: "the Project has no free ($0-priced) model that can be run",
};
const answered = (text: string): UtilityCompletion => ({ ok: true, text });
const failed = (error: string): UtilityCompletion => ({ ok: false, cause: "failed", error });
@@ -958,12 +958,12 @@ describe("organization runtime", () => {
source: "placeholder",
reason: "unusable_answer",
});
- // Nothing to ask: the Project names no default model.
+ // Nothing to ask: the Project has no free model to run.
completion.answers = [];
expect(await service.suggestId(P, { name: "市场推广", kind: "channel" })).toEqual({
id: placeholderFor("channel"),
source: "placeholder",
- reason: "no_default_model",
+ reason: "no_free_model",
});
// The request failed on the wire.
completion.answers = [failed("connect ETIMEDOUT")];
diff --git a/packages/server/test/suggest-id-routes.test.ts b/packages/server/test/suggest-id-routes.test.ts
index fdbc7570..b4f56eff 100644
--- a/packages/server/test/suggest-id-routes.test.ts
+++ b/packages/server/test/suggest-id-routes.test.ts
@@ -28,7 +28,7 @@ const failed = (error: string): UtilityCompletion => ({ ok: false, cause: "faile
const NO_MODEL: UtilityCompletion = {
ok: false,
cause: "no_model",
- error: "the Project names no default model",
+ error: "the Project has no free ($0-priced) model that can be run",
};
/** Today's `yyyymmdd`, which is what a placeholder carries. */
@@ -127,7 +127,7 @@ describe("suggest-id routes", () => {
expect(await suggest(owner, { name: "报告写手", kind: "agent" })).toEqual({
id: `agent_${stamp()}`,
source: "placeholder",
- reason: "no_default_model",
+ reason: "no_free_model",
});
completion.answers = [answered("报告写手"), answered("写手")];
expect(await suggest(owner, { name: "官网改版", kind: "project" })).toEqual({
@@ -163,7 +163,7 @@ describe("suggest-id routes", () => {
expect(await suggest(owner, { name: "报告写作", kind: "benchmark" })).toEqual({
id: `benchmark-${stamp()}`,
source: "placeholder",
- reason: "no_default_model",
+ reason: "no_free_model",
});
// A member may create Agents but not Benchmarks, and is refused the proposal the same way.
diff --git a/packages/server/test/utility-completion-walk.test.ts b/packages/server/test/utility-completion-walk.test.ts
new file mode 100644
index 00000000..ca576ff9
--- /dev/null
+++ b/packages/server/test/utility-completion-walk.test.ts
@@ -0,0 +1,119 @@
+/**
+ * The walk `completeOnce` takes over a Project's free models, against a real socket: a free
+ * endpoint that refuses is followed by the next free one, and the Project's paid default model
+ * is never asked at all — the point of the walk being that generating an id costs nothing.
+ *
+ * The mock speaks the OpenAI streaming shape on `/chat/completions`, the same branch
+ * `packages/web/e2e/mock-llm.mjs` serves: a model pinned to `openai-chat` reaches it. Nothing
+ * outside this process is contacted.
+ */
+import http from "node:http";
+import fs from "node:fs/promises";
+import type { AddressInfo } from "node:net";
+import { afterEach, describe, expect, it } from "vitest";
+import { wire } from "@adelie/core/kernel";
+import { projectConfigPath, projectDir } from "@adelie/core";
+import { ProjectConfigService } from "../src/services/project-config-service.js";
+import { makeTempRoot } from "./helpers.js";
+
+/** One streaming chat completion, as the OpenAI client expects to read one. */
+function answer(res: http.ServerResponse, model: string, text: string): void {
+ res.writeHead(200, {
+ "content-type": "text/event-stream",
+ "cache-control": "no-cache",
+ connection: "keep-alive",
+ });
+ const chunk = (delta: Record<string, unknown>, finish: string | null = null) =>
+ `data: ${JSON.stringify({
+ id: "chatcmpl-walk",
+ object: "chat.completion.chunk",
+ created: 0,
+ model,
+ choices: [{ index: 0, delta, finish_reason: finish }],
+ })}\n\n`;
+ res.write(chunk({ role: "assistant", content: "" }));
+ res.write(chunk({ content: text }));
+ res.write(chunk({}, "stop"));
+ res.write(
+ `data: ${JSON.stringify({
+ id: "chatcmpl-walk",
+ object: "chat.completion.chunk",
+ created: 0,
+ model,
+ choices: [],
+ usage: { prompt_tokens: 20, completion_tokens: 3, total_tokens: 23 },
+ })}\n\n`,
+ );
+ res.write("data: [DONE]\n\n");
+ res.end();
+}
+
+describe("completeOnce's walk over a Project's free models", () => {
+ let server: http.Server | undefined;
+
+ afterEach(() => {
+ server?.close();
+ server = undefined;
+ });
+
+ it("moves on from a free model that refuses, and never asks the paid default", async () => {
+ const asked: string[] = [];
+ server = http.createServer((req, res) => {
+ let body = "";
+ req.on("data", (c) => (body += c));
+ req.on("end", () => {
+ if (req.method !== "POST" || !(req.url ?? "").includes("chat/completions")) {
+ res.writeHead(404).end();
+ return;
+ }
+ let model = "";
+ try {
+ model = String((JSON.parse(body) as { model?: unknown }).model ?? "");
+ } catch {
+ /* a body this test cannot read is not what it is here to check */
+ }
+ asked.push(model);
+ // The first free model of the config is throttled out of existence; the second one
+ // answers. `paid-model` would answer too — it must never be reached.
+ if (model === "free-one") {
+ res.writeHead(401, { "content-type": "application/json" });
+ res.end(JSON.stringify({ error: { message: "invalid api key", type: "auth" } }));
+ return;
+ }
+ answer(res, model, model === "free-two" ? "report_writer" : "paid_model_answer");
+ });
+ });
+ await new Promise<void>((resolve) => server!.listen(0, "127.0.0.1", resolve));
+ const port = (server.address() as AddressInfo).port;
+
+ const root = await makeTempRoot();
+ await fs.mkdir(projectDir(root, "p1"), { recursive: true });
+ const free = (modelId: string) =>
+ `[[models]]\nprovider = "custom"\nmodel_id = "${modelId}"\n` +
+ `api_key = "sk-${modelId}"\nbase_url = "http://127.0.0.1:${port}/v1"\n` +
+ `client_type = "openai-chat"\n` +
+ `pricing = { unit = "usd_per_mtok", cache_read = 0, cache_write = 0, output = 0 }\n`;
+ // The paid row is the Project's default model, and the one an earlier build would have
+ // asked: it sits first in the file, so only the free filter keeps it out of the walk.
+ await fs.writeFile(
+ projectConfigPath(root, "p1"),
+ '[default_model]\nprovider = "custom"\nmodel_id = "paid-model"\n\n' +
+ `[[models]]\nprovider = "custom"\nmodel_id = "paid-model"\n` +
+ `api_key = "sk-paid"\nbase_url = "http://127.0.0.1:${port}/v1"\n` +
+ `client_type = "openai-chat"\n` +
+ `pricing = { unit = "usd_per_mtok", cache_read = 0.04, cache_write = 2, output = 8 }\n\n` +
+ free("free-one") +
+ "\n" +
+ free("free-two"),
+ "utf8",
+ );
+
+ const service = wire(ProjectConfigService, { paths: { root } });
+ expect(await service.completeOnce("p1", "Name: Report Writer")).toEqual({
+ ok: true,
+ text: "report_writer",
+ });
+ // Config order, and the paid default never asked.
+ expect(asked).toEqual(["free-one", "free-two"]);
+ });
+});
diff --git a/packages/server/test/utility-completion.test.ts b/packages/server/test/utility-completion.test.ts
index ddbccd74..e146a531 100644
--- a/packages/server/test/utility-completion.test.ts
+++ b/packages/server/test/utility-completion.test.ts
@@ -22,6 +22,7 @@ import type { LLMOutcome, OmniMessage } from "@adelie/core";
import {
ProjectConfigService,
collectUtilityCompletion,
+ freeModelEntries,
utilityCompletionConfig,
} from "../src/services/project-config-service.js";
import { makeTempRoot } from "./helpers.js";
@@ -74,6 +75,13 @@ describe("utilityCompletionConfig", () => {
300,
);
});
+
+ it("waits out the single-attempt timeout unless the walk hands it what is left of its budget", () => {
+ expect(utilityCompletionConfig("m-bench", { api_key: "sk-1" }).requestTimeoutMs).toBe(15_000);
+ expect(utilityCompletionConfig("m-bench", { api_key: "sk-1" }, 4_000).requestTimeoutMs).toBe(
+ 4_000,
+ );
+ });
});
describe("collectUtilityCompletion", () => {
@@ -139,57 +147,107 @@ describe("collectUtilityCompletion", () => {
});
});
+/** One `[[models]]` row, as the config stores one: a paired reference, plus whatever is given. */
+const row = (provider: string, modelId: string, rest = ""): string =>
+ `[[models]]\nprovider = "${provider}"\nmodel_id = "${modelId}"\n${rest}\n`;
+
+/** The three-bucket pricing table a $0 row carries. */
+const ZERO_PRICING =
+ 'pricing = { unit = "usd_per_mtok", cache_read = 0, cache_write = 0, output = 0 }\n';
+
+describe("freeModelEntries", () => {
+ it("keeps the Project's $0-priced rows in config order, and drops everything else", () => {
+ const raw = {
+ models: [
+ {
+ provider: "openrouter",
+ model_id: "a:free",
+ pricing: { cache_read: 0, cache_write: 0, output: 0 },
+ },
+ {
+ provider: "deepseek",
+ model_id: "paid",
+ pricing: { cache_read: 0.04, cache_write: 2, output: 8 },
+ },
+ // No pricing at all is unpriced, not free.
+ { provider: "vllm", model_id: "unpriced" },
+ {
+ provider: "zai",
+ model_id: "glm-4.7-flash",
+ pricing: { cache_read: 0, cache_write: 0, output: 0 },
+ },
+ // A hand-edited file may carry the same reference twice; it is asked once.
+ {
+ provider: "openrouter",
+ model_id: "a:free",
+ pricing: { cache_read: 0, cache_write: 0, output: 0 },
+ },
+ { model_id: "providerless" },
+ ],
+ };
+ expect(freeModelEntries(raw).map((c) => `${c.provider}/${c.modelId}`)).toEqual([
+ "openrouter/a:free",
+ "zai/glm-4.7-flash",
+ ]);
+ });
+
+ it("reads a missing bucket as 0 and any price on any bucket as not free", () => {
+ const raw = {
+ models: [
+ { provider: "p", model_id: "one-bucket", pricing: { cache_read: 0 } },
+ { provider: "p", model_id: "output-priced", pricing: { cache_read: 0, output: 0.5 } },
+ ],
+ };
+ expect(freeModelEntries(raw).map((c) => c.modelId)).toEqual(["one-bucket"]);
+ });
+});
+
describe("completeOnce", () => {
- it("says which way it fell through when the Project has nothing to run it on", async () => {
+ it("says there is no free model to run when the Project lists none", async () => {
const root = await makeTempRoot();
const service = wire(ProjectConfigService, { paths: { root } });
// No `.project_config.toml` at all.
expect(await service.completeOnce("p1", "Name: Plugin Marketplace")).toEqual({
ok: false,
cause: "no_model",
- error: "the Project names no default model",
+ error: "the Project has no free ($0-priced) model that can be run",
});
await fs.mkdir(projectDir(root, "p1"), { recursive: true });
const file = projectConfigPath(root, "p1");
- // A config that names no default model.
- await fs.writeFile(file, '[[models]]\nprovider = "custom"\nmodel_id = "m-bench"\n', "utf8");
- expect(await service.completeOnce("p1", "Name: Plugin Marketplace")).toMatchObject({
- ok: false,
- cause: "no_model",
- });
-
- // A default model whose entry is gone: there is nothing to build a client from, and a
- // guess at the credential would be worse than no answer.
+ // A paid row is not a candidate even when it is the Project's default model: this ask must
+ // not spend anything, which is the whole point of the walk.
await fs.writeFile(
file,
- '[default_model]\nprovider = "custom"\nmodel_id = "m-bench"\n',
+ '[default_model]\nprovider = "deepseek"\nmodel_id = "deepseek-flash"\n\n' +
+ row("deepseek", "deepseek-flash", 'api_key = "sk-paid"\n') +
+ 'pricing = { unit = "usd_per_mtok", cache_read = 0.04, cache_write = 2, output = 8 }\n',
"utf8",
);
expect(await service.completeOnce("p1", "Name: Plugin Marketplace")).toEqual({
ok: false,
cause: "no_model",
- error: "the default model custom/m-bench has no entry in the Project config",
+ error: "the Project has no free ($0-priced) model that can be run",
});
});
- it("collapses a construction that throws into a reason instead of an exception", async () => {
+ it("walks past a free row it cannot build and names the next one's dead end", async () => {
const root = await makeTempRoot();
const service = wire(ProjectConfigService, { paths: { root } });
await fs.mkdir(projectDir(root, "p1"), { recursive: true });
- // An entry whose model id no client can be routed from, and no protocol pinned: the SDK
- // throws while building the client, before any network I/O.
+ // Two free rows, neither carrying a credential: the first is skipped without being asked
+ // and the second one's dead end is the one reported — which holds only if the walk moved on.
await fs.writeFile(
projectConfigPath(root, "p1"),
- '[default_model]\nprovider = "custom"\nmodel_id = "not-a-routable-model-xyz"\n\n' +
- '[[models]]\nprovider = "custom"\nmodel_id = "not-a-routable-model-xyz"\n',
+ row("custom", "free-one", ZERO_PRICING) + "\n" + row("custom", "free-two", ZERO_PRICING),
"utf8",
);
const result = await service.completeOnce("p1", "Name: Plugin Marketplace");
expect(result.ok).toBe(false);
if (!result.ok) {
- expect(result.cause).toBe("failed");
- expect(result.error).toContain("not-a-routable-model-xyz");
+ // Never asked, so "nothing to run it on" rather than a model that failed.
+ expect(result.cause).toBe("no_model");
+ expect(result.error).toContain("free-two");
}
});
});
diff --git a/packages/ui-gallery/src/app/mock/routes.ts b/packages/ui-gallery/src/app/mock/routes.ts
index 79b63816..532cef20 100644
--- a/packages/ui-gallery/src/app/mock/routes.ts
+++ b/packages/ui-gallery/src/app/mock/routes.ts
@@ -2912,7 +2912,7 @@ router
.replace(/^-+|-+$/g, "");
return id === ""
? { id: `untitled-${dayKey(Date.now())}`, source: "placeholder", reason: "no_ascii" }
- : { id, source: "fallback", reason: "no_default_model" };
+ : { id, source: "fallback", reason: "no_free_model" };
})
.get("/api/projects/:projectId/organizations/:orgId", companyOff)
.patch("/api/projects/:projectId/organizations/:orgId", companyOff)
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 838be352..ab4c893d 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -1384,8 +1384,8 @@ export const en: Strings = {
`The model gave no usable id (${reason}); a placeholder was filled in — please change it to something meaningful`,
/** Why the proposal fell through, keyed by the server's reason code. */
reasons: {
- no_default_model: "no default model configured",
- model_failed: "the model request failed",
+ no_free_model: "this Project has no free ($0-priced) model to ask",
+ model_failed: "every free model request failed",
unusable_answer: "the model's answer was unusable",
no_ascii: "the name carries no ASCII to transliterate",
},
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 970fe607..06c58e81 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -1438,8 +1438,8 @@ export const zh = {
`模型没有给出可用的 ID(${reason}),已填入占位 ID,请改成有含义的英文名`,
/** Why the proposal fell through, keyed by the server's reason code. */
reasons: {
- no_default_model: "未配置默认模型",
- model_failed: "模型调用失败",
+ no_free_model: "这个 Project 里没有可用的免费(0 定价)模型",
+ model_failed: "免费模型的调用都失败了",
unusable_answer: "模型回答不可用",
no_ascii: "名称里没有可转写的英文",
},
diff --git a/packages/web/test/id-suggest-notice.test.ts b/packages/web/test/id-suggest-notice.test.ts
index df84ac76..621648ad 100644
--- a/packages/web/test/id-suggest-notice.test.ts
+++ b/packages/web/test/id-suggest-notice.test.ts
@@ -12,7 +12,7 @@ import { zh } from "../src/lib/strings";
import { en } from "../src/lib/strings-en";
const REASONS = Object.keys({
- no_default_model: true,
+ no_free_model: true,
model_failed: true,
unusable_answer: true,
no_ascii: true,