Repository navigation
feat(models): resolve the discovery endpoint from pi's provider catalog - #1006
Conversation
Model discovery required models.json to repeat the provider's baseUrl and api. Provider entries that only list models, and built-in providers pi ships without a models.json entry, therefore could not import their upstream model list -- even though pi itself resolves the endpoint and protocol for exactly those providers. resolveModelDiscoveryAuth() now also returns the effective baseUrl and api, read from the ModelRuntime, and the discover route falls back to them when models.json does not set its own. The Models panel no longer gates "Import models..." on a non-empty Base URL, since pi resolves the endpoint for it, and no longer sends the upstream default protocol.
# Conflicts: # components/ModelsConfig.test.mjs
… one With the Import button no longer gated on a Base URL, a custom provider without one reached resolveModelDiscoveryAuth(), which failed with a 500 naming the internal __pi_web_model_discovery__ placeholder. When no Base URL is configured, that failure now answers the old 400 "Base URL is required". The field hint says the fallback only applies to built-in providers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks @jidekaixin2dian, this is exactly the focused follow-up to #916. The fallback reuses what I pushed a few changes:
Checked in the browser: the hint shows under Base URL, and Import on an empty custom provider shows "Base URL is required". Generated by Claude Code |
解开 agegr#981 的 DirectoryPicker 冲突后,这一段(390e70f..f52fd84)实测 0 冲突: - agegr#992 移动端输入框停在键盘上方并给打字更多空间 - agegr#997 限制每客户端 SSE 积压 - agegr#1001 可配置发送键(Enter / Ctrl+Enter) - agegr#1006 从 pi 的 provider catalog 解析 discovery endpoint - agegr#1017 空闲关闭被禁用时回收 Stop 无法解除的运行 - agegr#1016 Stop 结束输出被幸存进程持住的命令 - agegr#1015 保留用户消息里输入的换行 - agegr#1019 在 Safari / iOS 16.2 上可加载(新增 browserslist,无新依赖)
…og (agegr#1006) * feat(models): resolve the discovery endpoint from pi's provider catalog Model discovery required models.json to repeat the provider's baseUrl and api. Provider entries that only list models, and built-in providers pi ships without a models.json entry, therefore could not import their upstream model list -- even though pi itself resolves the endpoint and protocol for exactly those providers. resolveModelDiscoveryAuth() now also returns the effective baseUrl and api, read from the ModelRuntime, and the discover route falls back to them when models.json does not set its own. The Models panel no longer gates "Import models..." on a non-empty Base URL, since pi resolves the endpoint for it, and no longer sends the upstream default protocol. * fix(models): keep "Base URL is required" for custom providers without one With the Import button no longer gated on a Base URL, a custom provider without one reached resolveModelDiscoveryAuth(), which failed with a 500 naming the internal __pi_web_model_discovery__ placeholder. When no Base URL is configured, that failure now answers the old 400 "Base URL is required". The field hint says the fallback only applies to built-in providers. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: jidekaixin2dian <[email protected]> Co-authored-by: Alex Yang <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…og (agegr#1006) * feat(models): resolve the discovery endpoint from pi's provider catalog Model discovery required models.json to repeat the provider's baseUrl and api. Provider entries that only list models, and built-in providers pi ships without a models.json entry, therefore could not import their upstream model list -- even though pi itself resolves the endpoint and protocol for exactly those providers. resolveModelDiscoveryAuth() now also returns the effective baseUrl and api, read from the ModelRuntime, and the discover route falls back to them when models.json does not set its own. The Models panel no longer gates "Import models..." on a non-empty Base URL, since pi resolves the endpoint for it, and no longer sends the upstream default protocol. * fix(models): keep "Base URL is required" for custom providers without one With the Import button no longer gated on a Base URL, a custom provider without one reached resolveModelDiscoveryAuth(), which failed with a 500 naming the internal __pi_web_model_discovery__ placeholder. When no Base URL is configured, that failure now answers the old 400 "Base URL is required". The field hint says the fallback only applies to built-in providers. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: jidekaixin2dian <[email protected]> Co-authored-by: Alex Yang <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
#916 关闭后的另一半。@agegr 在那条评论里写
resolveModelDiscoveryAuth()的baseUrl/apifallback「would make a small, focused PR on its own」,这个 PR 就是它。#916 里的 model-sync 动作、它的 UI(summary、checkbox、hint)、e2e/models-sync.mjs、新增的 i18n key、AGENTS.md 改动没有带过来。问题
Import models… 需要 Base URL 才能拼出上游模型列表的地址。两类 provider 条目给不出这个值:
deepseek: { models: [...] });这两类 provider 的 endpoint 和协议由 pi 解析,Models 面板是唯一拒绝拉取的地方。
改动
lib/model-discovery-auth.ts:resolveModelDiscoveryAuth()返回它通过ModelRuntime解析出的baseUrl与api(model.baseUrl回退到 provider 的,model.api回退到第一个模型的)。app/api/models-config/discover/route.ts:models.json 没给值时用上面两个,协议回退到 pi 的默认。models.json 里显式配置的 baseUrl/api 优先,已配置的 provider 行为不变。components/ModelsConfig.tsx:Base URL 为空时 Import models… 不再禁用,字段下加一行提示(与相邻的 API Key、Headers 提示同格式)。这两行组件改动是 fallback 可达的前提:没有它们,这些 provider 不会调到这个 route。要收服务端改动也可以,代价是 fallback 到不了。
测试
lib/model-discovery.test.mjs:断言配置了 baseUrl/api 的 provider,以及依赖 pi 内置 endpoint 的 models-only 条目,两者解析出的 baseUrl/api。components/ModelsConfig.test.mjs:源码级断言 discovery 不再以provider.baseUrl为门槛。本机
npm test:1325 tests,1309 pass,11 fail,5 skipped。11 个失败在 pristinemain上同样复现(node-pty 原生模块没编译,加上 file-viewer、PATH、symlink 三处),与本次 diff 无关;两个新测试通过。Models 面板没有现成的 e2e 覆盖。分支上的后续提交
@agegr 在分支上推了三个 commit:
0bdc46b0:合并main,解掉ModelsConfig.test.mjs与 fix(models): save a typed provider name with the Save button #969 provider rename 测试的冲突,上面的断言留成独立测试。66c02318:resolveModelDiscoveryAuth()外包 try/catch。自定义 provider 没配 Base URL 时返回 400Base URL is required,不再漏出 500 和内部占位名model __pi_web_model_discovery__: no "api" specified;配了 Base URL 的仍然抛。提示语改成Leave empty for a built-in provider to use the endpoint pi ships,自定义 provider 没有可回退的 endpoint。lib/model-discovery.test.mjs加了这条路径的 route 测试。他核对过的解析结果:
deepseek→https://api.deepseek.com/openai-completions,anthropic→https://api.anthropic.com/anthropic-messages,openrouter→https://openrouter.ai/api/v1。浏览器里验过提示与 400。