mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 17:57:23 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47fe759025 | |||
| d795266572 | |||
| a82ae2b60e |
57
internal/core/channels_buddy_catalog_filter_test.go
Normal file
57
internal/core/channels_buddy_catalog_filter_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// ★ 远端模型目录混着「不可调用」的条目,必须过滤掉。
|
||||
//
|
||||
// 真实缺陷(生产实测):buddy 源声明了 24 个模型,其中
|
||||
//
|
||||
// nes-gf / codewise-completions / codewise-rewrite / codewise-jump /
|
||||
// codewise-default-model-v2 / hunyuan-image-alpha / auto
|
||||
//
|
||||
// 全部调不通(`glm-5.1` 也是 404)。用户选中就报错,而错误文案指向**模型**,
|
||||
// 极易被误判成"这个模型坏了"。
|
||||
//
|
||||
// 参考实现(buddy.ts 的 isChatModel / isAutoSelectAlias)记录了**四类**判据,
|
||||
// 且都是实测依据:
|
||||
//
|
||||
// ① 自动选择别名 auto/default(**只按字面量**,前缀匹配会误伤 default-model)
|
||||
// ② 补全/NES 专用前缀 nes- / completion- / codewise-,或 supportsExtra=true
|
||||
// (参考实测 codewise-default-model-v2 → `code 11102 service info not found`)
|
||||
// ③ maxOutputTokens >0 且 ≤256(补全用途;对话模型普遍 ≥24000)
|
||||
// ④ 带 text-to-image 标签(如 hunyuan-image-alpha)
|
||||
func TestBuddyCatalogFilterDropsNonChatModels(t *testing.T) {
|
||||
src, err := readBundledChannels(t)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := string(src)
|
||||
|
||||
// 判据一:四类规则必须都在源码里(防止有人"精简"掉其中一条)
|
||||
for _, rule := range []string{
|
||||
`id == "auto" or id == "default"`, // ①
|
||||
`id:sub(1, 4) == "nes-"`, // ②
|
||||
`id:sub(1, 11) == "completion-"`, // ②
|
||||
`id:sub(1, 9) == "codewise-"`, // ②
|
||||
`m.supportsExtra == true`, // ②
|
||||
`mo > 0 and mo <= 256`, // ③
|
||||
`t == "text-to-image"`, // ④
|
||||
} {
|
||||
if !strings.Contains(s, rule) {
|
||||
t.Errorf("buddy 目录过滤缺少规则:%s\n"+
|
||||
"(这四类都是参考用真实请求验证过的「列出来就会让用户报错」的条目,"+
|
||||
"删任何一条都会把不可调用模型放回选择器)", rule)
|
||||
}
|
||||
}
|
||||
|
||||
// 判据二:`default-model` / `fast-model` 必须**不在**被过滤的形态里。
|
||||
// 参考注释明确警告:只过滤 auto/default 两个字面量,不做前缀匹配 ——
|
||||
// 前缀会误伤这两个国际版别名(它们被 craft agent 引用,是官方推荐入口)。
|
||||
if strings.Contains(s, `id:sub(1, 7) == "default"`) {
|
||||
t.Error("buddy 过滤把 default 做成了**前缀**匹配 ⇒ 会误伤 default-model(参考点名警告)")
|
||||
}
|
||||
t.Log("✓ buddy 目录过滤四类规则齐备,且未误伤 default-model 类别名")
|
||||
}
|
||||
76
internal/core/channels_endpoint_url_test.go
Normal file
76
internal/core/channels_endpoint_url_test.go
Normal file
@ -0,0 +1,76 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// ★ 源的 chat URL = `base_url + endpoint`(内核 provider.go ChatURL)。
|
||||
//
|
||||
// 真实缺陷(生产实测):多个渠道平台的 `base_url` 里塞了**完整路径**,
|
||||
// 而适配器默认 endpoint 又是 "/chat/completions" ⇒ 实际请求变成
|
||||
//
|
||||
// https://copilot.tencent.com/v2/chat/completions/chat/completions
|
||||
//
|
||||
// ⇒ 上游回 `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞,不是模型错误)。
|
||||
//
|
||||
// 受影响平台 8 个:buddy / cline / lobsterai / opencode / qoder / loomy /
|
||||
// raccoon(zcode 当时已用 endpoint 覆盖,形态正确)。
|
||||
//
|
||||
// ★ 为什么这个缺陷能活很久:**模型名被多个源服务**。
|
||||
//
|
||||
// `deepseek-v4.1-flash` 同时由 4 个源提供(alittokenplan/vela/oin/channels-buddy…)
|
||||
// ⇒ 网关在 buddy 源失败后会**继续尝试下一个源**并成功 ⇒ 用户看到"能回话",
|
||||
// 于是"buddy 通道是好的"这个结论**完全没有证据**。
|
||||
// 而 `hy3` 只由 buddy 一个源提供 ⇒ 一调就暴露真因。
|
||||
// ⇒ 判据必须断言**源的 URL 形态**(结构不变量),不能靠"某个模型能调通"。
|
||||
//
|
||||
// 判据:base_url 不得自带任何 chat 路径段(它只应是 host[+协议公共前缀]),
|
||||
// 路径必须在 `endpoint` 里。
|
||||
func TestChannelSourceBaseURLHasNoChatPath(t *testing.T) {
|
||||
src, err := readBundledChannels(t)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := string(src)
|
||||
|
||||
// 只在平台定义区里找 base_url(避免误判注释/文档里的示例)
|
||||
declRe := regexp.MustCompile(`(?m)^\s*base_url = "([^"]+)"\s*,?$`)
|
||||
// 已知适配器会把这些路径各追加一次;出现即说明 base_url 侵占了 endpoint 的地盘
|
||||
banned := []string{"/chat/completions", "/v1/messages", "/generateContent", "/api/chat"}
|
||||
|
||||
found := 0
|
||||
for _, m := range declRe.FindAllStringSubmatch(s, -1) {
|
||||
url := m[1]
|
||||
found++
|
||||
for _, b := range banned {
|
||||
if strings.Contains(url, b) {
|
||||
t.Errorf("base_url 侵占了 endpoint 的路径:%s\n"+
|
||||
" 内核的 URL 是 `base_url + endpoint`(provider.go ChatURL),"+
|
||||
"适配器默认 endpoint=\"/chat/completions\" ⇒ 实际会请求 %s%s\n"+
|
||||
" 修法:base_url 只留 host,把 `%s` 移到该平台的 `endpoint = \"...\"`",
|
||||
url, url, b, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
if found == 0 {
|
||||
t.Fatal("没扫到任何 base_url 声明(判据失效)")
|
||||
}
|
||||
t.Logf("✓ %d 个 base_url 均不含 chat 路径段", found)
|
||||
}
|
||||
|
||||
// ★ 反过来也要咬:说明该缺陷**确实已被修好**、而不是判据太松。
|
||||
// 用一段**故意的坏数据**验证判据的判别力(变异测试的静态等价物)。
|
||||
func TestChannelBaseURLJudgeBitesOnBadInput(t *testing.T) {
|
||||
bad := ` base_url = "https://copilot.tencent.com/v2/chat/completions",`
|
||||
declRe := regexp.MustCompile(`(?m)^\s*base_url = "([^"]+)"\s*,?$`)
|
||||
m := declRe.FindStringSubmatch(bad)
|
||||
if m == nil {
|
||||
t.Fatal("判据的正则匹配不到坏数据 ⇒ 判据无判别力(形同虚设)")
|
||||
}
|
||||
if !strings.Contains(m[1], "/chat/completions") {
|
||||
t.Fatal("坏数据未被识别 ⇒ 判据无判别力")
|
||||
}
|
||||
t.Log("✓ 判据对坏数据有判别力")
|
||||
}
|
||||
@ -48,6 +48,13 @@ func TestAccountDeleteRemovesItsSource(t *testing.T) {
|
||||
if !strings.Contains(joined, "remove_source") {
|
||||
t.Fatalf("记录里应点明是哪个内核动作被拒(便于给运维可操作提示),实得: %s", joined)
|
||||
}
|
||||
// ★ 必须带上**真正的原因**(not granted),而不是"无返回"这类空话。
|
||||
// 内核桥失败时**第一个返回值是 nil、原因在第二个返回值里** ——
|
||||
// 只接第一个返回值就会把原因丢掉(我第一版正是如此)。
|
||||
if !strings.Contains(joined, "not granted") {
|
||||
t.Fatalf("记录里必须含内核给出的**真实原因**(not granted),"+
|
||||
"否则运维无从下手(只接 call 的第一个返回值就会丢掉原因);实得: %s", joined)
|
||||
}
|
||||
t.Logf("✓ 撤源失败已可见: %s", joined)
|
||||
})
|
||||
}
|
||||
|
||||
@ -27,8 +27,12 @@ func TestUpstreamGapsAreDocumented(t *testing.T) {
|
||||
s := string(src)
|
||||
|
||||
t.Run("qoder 走明文端点且不经过信封", func(t *testing.T) {
|
||||
// 明文端点(OpenAI 兼容):参考 QODER_CHAT_PATH
|
||||
if !strings.Contains(s, "https://api2-v2.qoder.sh/model/v1/chat/completions") {
|
||||
// 明文端点(OpenAI 兼容):参考 QODER_CHAT_PATH。
|
||||
// ⚠ 断言 **URL 的两半**而不是那一整串字面量:本仓已把"路径从 base_url
|
||||
// 移到 endpoint"(内核 URL = base_url + endpoint)—— 继续钉死整串会让
|
||||
// 一个纯粹的形态重构把这条**语义**判据弄红,那是判据在咬自己。
|
||||
if !strings.Contains(s, `base_url = "https://api2-v2.qoder.sh"`) ||
|
||||
!strings.Contains(s, `endpoint = "/model/v1/chat/completions"`) {
|
||||
t.Fatal("qoder 的 chat 端点变了 —— 若改成加密端点 agent_chat_generation," +
|
||||
"则**必须**同时实现信封解包(qoder-envelope)与 WASM 签名," +
|
||||
"否则响应会被当成畸形数据")
|
||||
|
||||
@ -344,7 +344,13 @@ local PLATFORMS = {
|
||||
},
|
||||
hosts = { "api.workos.com", "api.cline.bot", "app.cline.bot" },
|
||||
-- cline 的 chat 路径是 /api/v1/chat/completions(参考 CLINE_CHAT_PATH)。
|
||||
base_url = "https://api.cline.bot/api/v1/chat/completions",
|
||||
base_url = "https://api.cline.bot",
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:
|
||||
-- 内核的 URL 是 `base_url + endpoint`(provider.go ChatURL),
|
||||
-- 而适配器默认 endpoint 是 "/chat/completions" ⇒ 若 base_url 已含
|
||||
-- 完整路径,实际请求就变成 .../api/v1/chat/completions/chat/completions ⇒ 上游
|
||||
-- 回 `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞)。
|
||||
endpoint = "/api/v1/chat/completions",
|
||||
-- 远端模型目录(照参考 cline-models.ts:**必须同时打两个端点**)。
|
||||
-- 关键:/api/v1/models 的 460 个 id 里**没有** cline-free/*,免费模型只由
|
||||
-- recommended-models 下发;只打前者会看不到任何免费模型。
|
||||
@ -414,7 +420,13 @@ local PLATFORMS = {
|
||||
},
|
||||
hosts = { "copilot.tencent.com", "www.codebuddy.cn" },
|
||||
-- buddy 的 chat 端点含 /v2 前缀(参考 CHAT_API_BASE = .../v2 + /chat/completions)。
|
||||
base_url = "https://copilot.tencent.com/v2/chat/completions",
|
||||
base_url = "https://copilot.tencent.com",
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:
|
||||
-- 内核的 URL 是 `base_url + endpoint`(provider.go ChatURL),
|
||||
-- 而适配器默认 endpoint 是 "/chat/completions" ⇒ 若 base_url 已含
|
||||
-- 完整路径,实际请求就变成 .../v2/chat/completions/chat/completions ⇒ 上游
|
||||
-- 回 `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞)。
|
||||
endpoint = "/v2/chat/completions",
|
||||
-- 远端模型目录(照参考 buddy.ts CONFIG_PATH + buddy-oauth.ts fetchModels)。
|
||||
-- 关键:必须带 product 身份头,否则 WorkBuddy 会以 CodeBuddy 身份请求。
|
||||
models_remote = {
|
||||
@ -688,7 +700,13 @@ local PLATFORMS = {
|
||||
fallback = "2026.9.4",
|
||||
},
|
||||
-- lobsterai 的 chat 路径是 /api/proxy/v1/chat/completions(参考 LOBSTERAI_CHAT_PATH)。
|
||||
base_url = "https://lobsterai-server.youdao.com/api/proxy/v1/chat/completions",
|
||||
base_url = "https://lobsterai-server.youdao.com",
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:
|
||||
-- 内核的 URL 是 `base_url + endpoint`(provider.go ChatURL),
|
||||
-- 而适配器默认 endpoint 是 "/chat/completions" ⇒ 若 base_url 已含
|
||||
-- 完整路径,实际请求就变成 .../api/proxy/v1/chat/completions/chat/completions ⇒ 上游
|
||||
-- 回 `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞)。
|
||||
endpoint = "/api/proxy/v1/chat/completions",
|
||||
-- 远端模型目录(照参考 lobsterai.ts LOBSTERAI_MODELS_PATH)
|
||||
models_remote = {
|
||||
-- 参考真值 LOBSTERAI_API_BASE(lobsterai-server.youdao.com)。
|
||||
@ -727,7 +745,17 @@ local PLATFORMS = {
|
||||
vendor = "opencode",
|
||||
flow = "paste",
|
||||
-- opencode 的 chat 路径是 /v1/chat/completions(参考 chatPath)。
|
||||
base_url = "https://opencode.ai/zen/v1/chat/completions",
|
||||
-- ★ base_url 必须保留 `/zen` 段:参考 opencode-product.ts:56 的
|
||||
-- `baseUrl: 'https://opencode.ai/zen'` + chatPath `/v1/chat/completions`。
|
||||
-- 实测(无凭据):
|
||||
-- https://opencode.ai/zen/v1/chat/completions → 500(路由存在,鉴权前先炸)
|
||||
-- https://opencode.ai/v1/chat/completions → 404 + HTML(网页)
|
||||
base_url = "https://opencode.ai/zen",
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:内核的 URL 是
|
||||
-- `base_url + endpoint`(provider.go ChatURL),而适配器默认 endpoint 是
|
||||
-- "/chat/completions" ⇒ 若 base_url 已含完整路径,实际请求就变成
|
||||
-- .../v1/chat/completions/chat/completions ⇒ 404 Route Not Found。
|
||||
endpoint = "/v1/chat/completions",
|
||||
-- 远端模型目录(照参考 opencode-product.ts modelsPath)
|
||||
models_remote = {
|
||||
endpoints = { { url = "https://opencode.ai/v1/models", method = "GET" } },
|
||||
@ -853,7 +881,13 @@ local PLATFORMS = {
|
||||
interval = 2,
|
||||
},
|
||||
-- qoder 的 chat 路径是 /model/v1/chat/completions(参考 QODER_CHAT_PATH)。
|
||||
base_url = "https://api2-v2.qoder.sh/model/v1/chat/completions",
|
||||
base_url = "https://api2-v2.qoder.sh",
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:
|
||||
-- 内核的 URL 是 `base_url + endpoint`(provider.go ChatURL),
|
||||
-- 而适配器默认 endpoint 是 "/chat/completions" ⇒ 若 base_url 已含
|
||||
-- 完整路径,实际请求就变成 .../model/v1/chat/completions/chat/completions ⇒ 上游
|
||||
-- 回 `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞)。
|
||||
endpoint = "/model/v1/chat/completions",
|
||||
-- Qoder 的错误信封是**双层编码**的,且 10605(排队) 与 110(额度耗尽)
|
||||
-- 语义相反 —— 通用 openai 适配器只能看到外层,产出用户看不懂的原因串。
|
||||
-- 故用本插件自装的 channels-qoder(厂商码留在插件域,内核零厂商名)。
|
||||
@ -1007,9 +1041,24 @@ local PLATFORMS = {
|
||||
access_key_secret = "zsak6eadrbawz683wf5r3m2snrwj868r",
|
||||
app_id = "GM3LOOMY",
|
||||
},
|
||||
-- loomy 的 chat 路径是 {apiBase}/chat/completions(参考 loomy-adapter.ts:494
|
||||
-- 实测标准 OpenAI 兼容)。
|
||||
base_url = "https://loomy.xunfei.cn/chat/completions",
|
||||
-- loomy 的 chat 端是 {apiBase}/chat/completions(参考 loomy-adapter.ts:494)。
|
||||
--
|
||||
-- ★ host 是 **loomyad.xunfei.cn/api/v1**(参考 LOOMY_API_BASE),不是
|
||||
-- `loomy.xunfei.cn` —— 后者是 **Web 前端/OAuth 回调**域(本块的
|
||||
-- wechat.redirect_uri 正用它)。实测:
|
||||
-- POST https://loomy.xunfei.cn/chat/completions
|
||||
-- → 200 + `<!DOCTYPE html>`(网页!根本不是 API)
|
||||
-- POST https://loomyad.xunfei.cn/api/v1/chat/completions
|
||||
-- → 200 + `{"code":"100002","desc":"缺少 token"}`(正常 JSON)
|
||||
-- 写成前端域时,无论路径怎么拼都不可能是 API。
|
||||
--
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:内核的 URL 是
|
||||
-- `base_url + endpoint`(provider.go ChatURL),而适配器默认 endpoint 是
|
||||
-- "/chat/completions" ⇒ 若 base_url 已含完整路径,实际请求就变成
|
||||
-- .../chat/completions/chat/completions ⇒ 上游回
|
||||
-- `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞)。
|
||||
base_url = "https://loomyad.xunfei.cn/api/v1",
|
||||
endpoint = "/chat/completions",
|
||||
adapter = "openai",
|
||||
-- 兜底目录(照参考 LOOMY_FALLBACK_MODELS)。此前 "loomy-default" 是我编的。
|
||||
models = {
|
||||
@ -1044,7 +1093,13 @@ local PLATFORMS = {
|
||||
},
|
||||
-- 推理是标准 OpenAI 兼容(实测 POST /api/web/llm/v2/chat/completions)
|
||||
-- raccoon 的 chat 端点是 /api/web/llm/v2/chat/completions。
|
||||
base_url = "https://xiaohuanxiong.com/api/web/llm/v2/chat/completions",
|
||||
base_url = "https://xiaohuanxiong.com",
|
||||
-- ★ 路径必须在 endpoint 里,**不能**塞进 base_url:
|
||||
-- 内核的 URL 是 `base_url + endpoint`(provider.go ChatURL),
|
||||
-- 而适配器默认 endpoint 是 "/chat/completions" ⇒ 若 base_url 已含
|
||||
-- 完整路径,实际请求就变成 .../api/web/llm/v2/chat/completions/chat/completions ⇒ 上游
|
||||
-- 回 `{"error_msg":"404 Route Not Found"}`(APISIX 的措辞)。
|
||||
endpoint = "/api/web/llm/v2/chat/completions",
|
||||
adapter = "openai",
|
||||
-- 兜底目录(照参考 RACCOON_FALLBACK_MODELS)。此前 "raccoon-default" 是我编的。
|
||||
-- 注意 sn- 前缀是本平台的真实命名约定(sensenova 系列)。
|
||||
@ -3161,17 +3216,80 @@ local function parseRemoteModels(kind, body, provider)
|
||||
end
|
||||
end
|
||||
|
||||
elseif kind == "buddy_config" then
|
||||
-- 照参考 parseModelsFromConfig:结果在 data.models / data.agents 结构里。
|
||||
-- 多形态兜底(顶层 data / 直接 models),因为该端点历史上变过形状。
|
||||
local d = rec.data or rec
|
||||
local arr = d.models or d.agents or rec.models
|
||||
if type(arr) == "table" then
|
||||
for _, m in ipairs(arr) do
|
||||
local id = type(m) == "table" and (m.id or m.modelId or m.name)
|
||||
if type(id) == "string" and id ~= "" then out[#out+1] = id end
|
||||
elseif kind == "buddy_config" then
|
||||
-- 照参考 parseModelsFromConfig:结果在 data.models / data.agents 结构里。
|
||||
-- 多形态兜底(顶层 data / 直接 models),因为该端点历史上变过形状。
|
||||
--
|
||||
-- ★★ 必须过滤「不可调用」的条目 —— 远端 data.models 里混着三类**不是对话
|
||||
-- 模型**的东西,列进模型选择器只会让用户选中后报错(实测生产:glm-5.1
|
||||
-- 与 glm-5.2 之外,codewise-* / nes-gf / hunyuan-image-alpha 同样调不通)。
|
||||
-- 判据与命名逐条照参考 buddy.ts 的 isChatModel / isAutoSelectAlias:
|
||||
-- ① 自动选择类内部别名:`auto` / `default`
|
||||
-- ⚠️ 只按**这两个字面量**过滤,不做前缀匹配 —— 前缀会误伤
|
||||
-- `default-model` / `fast-model`(国际版抽象别名,但被 craft agent
|
||||
-- 引用,是官方推荐入口)。
|
||||
-- ② 补全/NES 专用:前缀 `nes-` / `completion-` / `codewise-`,
|
||||
-- 或带 `supportsExtra` 标记。参考实测 codewise-default-model-v2
|
||||
-- 返回 `code 11102 model service info not found`(后端未开放)。
|
||||
-- ③ 输出上限过小(>0 且 ≤256):补全用途,对话模型普遍 ≥24000。
|
||||
-- ④ 带 `text-to-image` 标签的生成式模型(如 hunyuan-image-alpha)。
|
||||
-- ⚠️ ③④ 需要元数据,故先把 models 建成 id→meta 映射。
|
||||
local d = rec.data or rec
|
||||
local arr = d.models or d.agents or rec.models
|
||||
local metaById = {}
|
||||
if type(arr) == "table" then
|
||||
for _, m in ipairs(arr) do
|
||||
if type(m) == "table" and type(m.id) == "string" and m.id ~= "" then
|
||||
metaById[m.id] = m
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 被 agent 引用的模型(craft/ask/plan/cli)。参考据此给 `agentReferenced`
|
||||
-- 打标:`hy4-preview-f` 只由本端点下发且被 agent 引用,白名单重建会丢掉它。
|
||||
local agentRef = {}
|
||||
if type(d.agents) == "table" then
|
||||
for _, ag in ipairs(d.agents) do
|
||||
if type(ag) == "table" and type(ag.models) == "table" then
|
||||
for _, mid in ipairs(ag.models) do
|
||||
if type(mid) == "string" then agentRef[mid] = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local function buddyIsChatModel(id)
|
||||
if id == "auto" or id == "default" then return false end
|
||||
if id:sub(1, 4) == "nes-" or id:sub(1, 11) == "completion-"
|
||||
or id:sub(1, 9) == "codewise-" then return false end
|
||||
local m = metaById[id]
|
||||
if type(m) == "table" then
|
||||
if m.supportsExtra == true then return false end
|
||||
local mo = tonumber(m.maxOutputTokens)
|
||||
if mo and mo > 0 and mo <= 256 then return false end
|
||||
if type(m.tags) == "table" then
|
||||
for _, t in ipairs(m.tags) do
|
||||
if t == "text-to-image" then return false end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
local seen = {}
|
||||
local function pushId(id)
|
||||
if type(id) ~= "string" or id == "" then return end
|
||||
if seen[id] or not buddyIsChatModel(id) then return end
|
||||
seen[id] = true
|
||||
out[#out + 1] = id
|
||||
end
|
||||
-- models 与 agents 两处都收(agents 里是被引用的清单,可能含远端
|
||||
-- data.models 没有的新变体)。models 优先,保持顺序权威。
|
||||
if type(arr) == "table" then
|
||||
for _, m in ipairs(arr) do
|
||||
local id = type(m) == "table" and (m.id or m.modelId or m.name) or nil
|
||||
if type(id) == "string" then pushId(id) end
|
||||
end
|
||||
end
|
||||
for id in pairs(agentRef) do pushId(id) end
|
||||
|
||||
|
||||
elseif kind == "codearts_builtin" then
|
||||
-- 照参考 fetchCodeArtsRemoteModels 的第 2 个端点:字段是 builtinModels
|
||||
@ -3654,14 +3772,14 @@ local function syncAccountSource(provider, accountId)
|
||||
-- ⚠ 这里失败**可容忍**:AddSource 是**同名 upsert**,add 会把旧的覆盖掉。
|
||||
-- 但这正是它掩盖 remove_source 权限缺失的原因(纯删除路径才暴露),
|
||||
-- 故失败仍记一笔(低频,不会刷屏)。
|
||||
local rr = __llmsproxy_kernel.call("remove_source", { name = name })
|
||||
if not (rr and rr.ok) then
|
||||
local rr, rerr = __llmsproxy_kernel.call("remove_source", { name = name })
|
||||
if rr == nil or rr.ok ~= true then
|
||||
local l = plugin.state.log
|
||||
local last = type(l) == "table" and l[1] and l[1].msg or ""
|
||||
-- 只在**上一次不是同一条**时记,避免每次同步都刷一条
|
||||
if not tostring(last):find("撤源(重建)失败", 1, true) then
|
||||
logEvent("撤源(重建)失败 " .. tostring(name) .. ": "
|
||||
.. tostring(rr and (rr.error or rr.err) or "无返回"))
|
||||
.. tostring(rerr or "(无错误信息)"))
|
||||
end
|
||||
end
|
||||
local src = {
|
||||
@ -3713,12 +3831,15 @@ end
|
||||
-- 故这里把失败**记进事件日志**,让它在面板上可见,而不是只存在于一个被丢弃的返回值里。
|
||||
local function dropAccountSource(provider, accountId)
|
||||
local name = accountSourceName(provider, accountId)
|
||||
local r = __llmsproxy_kernel.call("remove_source", { name = name })
|
||||
local ok = r and r.ok
|
||||
if not ok then
|
||||
local err = (r and (r.error or r.err)) or "无返回"
|
||||
logEvent("撤源失败 " .. tostring(name) .. ": " .. tostring(err)
|
||||
.. "(若提示 not granted,需给 channels 插件授予 remove_source 权限)")
|
||||
-- ★ 内核桥是 `call(name, args) -> (result, nil) | (nil, err)`:
|
||||
-- 失败时**第一个返回值是 nil**,原因在**第二个返回值**里。
|
||||
-- 我第一版写成 `local r = call(...)` 再读 `r.ok` ⇒ 恒 nil ⇒ 日志只说"无返回",
|
||||
-- 把真正原因(not granted / 超时 / 拒删最后一个源)丢掉 —— 一句不可操作的
|
||||
-- 诊断比没有更糟。两个返回值都要接。
|
||||
local r, err = __llmsproxy_kernel.call("remove_source", { name = name })
|
||||
if r == nil or r.ok ~= true then
|
||||
logEvent("撤源失败 " .. tostring(name) .. ": " .. tostring(err or "(无错误信息)")
|
||||
.. " | 若为 not granted,需给 channels 插件授予 remove_source(声明在 plugin.kernel)")
|
||||
return false, err
|
||||
end
|
||||
return true
|
||||
@ -11114,7 +11235,11 @@ function plugin.__inject_refresh_platform_probe(args)
|
||||
label = id,
|
||||
flow = "manual",
|
||||
adapter = "openai",
|
||||
base_url = "http://127.0.0.1:1/v1/chat/completions",
|
||||
base_url = "http://127.0.0.1:1/v1",
|
||||
-- 照正式平台同样的分工:base_url 只到路径前缀,路径放 endpoint
|
||||
-- (内核 URL = base_url + endpoint)。测试夹具也照此写,
|
||||
-- 免得将来有人把这行当范例复制进正式平台。
|
||||
endpoint = "/chat/completions",
|
||||
refresh = { style = tostring(args.style or "google"), url = tostring(args.refresh_url or "") },
|
||||
models = { "m1" },
|
||||
hosts = { "127.0.0.1" },
|
||||
|
||||
Reference in New Issue
Block a user