@allbluecn/web-app 0.27.26 → 0.27.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/changelog/sdk-versions.ts +1 -1
- package/src/routes/api/harness/$.ts +3 -4
- package/src/server/harness/__tests__/model-catalog.test.ts +129 -0
- package/src/server/harness/define.server.ts +15 -1
- package/src/server/harness/host.server.ts +30 -4
- package/src/server/harness/model-catalog.server.ts +117 -4
- package/src/server/harness/permission-mode.server.ts +1 -1
- package/src/server/serverFns/chat/conversations.ts +1 -1
- package/src/server/serverFns/design/ai/providers.ts +48 -0
- package/src/server/serverFns/harness/fork-thread.ts +1 -1
package/package.json
CHANGED
|
@@ -112,7 +112,7 @@ export const SDK_GROUPS: SdkGroup[] = [
|
|
|
112
112
|
"items": [
|
|
113
113
|
{
|
|
114
114
|
"name": "@allbluecn/web-app",
|
|
115
|
-
"version": "v0.27.
|
|
115
|
+
"version": "v0.27.28",
|
|
116
116
|
"lastUpdate": "Nov 10, 2026",
|
|
117
117
|
"source": "apps/web/package.json",
|
|
118
118
|
"docsUrl": "https://github.com/allbluecn/allblue"
|
|
@@ -48,9 +48,8 @@ async function handleHarnessRequest(request: Request): Promise<Response> {
|
|
|
48
48
|
// describe/snapshot/transcript 三个 GET 全部 `Harness * failed (500)` 且 SSE 重连
|
|
49
49
|
// 退避耗尽 → 「重试次数已达上限」。收敛为结构化 503,不再让装配期故障裸奔。
|
|
50
50
|
try {
|
|
51
|
-
const [{
|
|
51
|
+
const [{ getHarnessRuntime, harnessMediaSecret }, { createHarnessHandler }, { getCurrentSession }, { checkAiRateLimit, RateLimitExceededError }] = await Promise.all([
|
|
52
52
|
import('@/server/harness/host.server'),
|
|
53
|
-
import('@/server/harness/define.server'),
|
|
54
53
|
import('@tanstack/ai-harness/server'),
|
|
55
54
|
import('@/lib/session'),
|
|
56
55
|
import('@/server/lib/rate-limit'),
|
|
@@ -84,8 +83,8 @@ async function handleHarnessRequest(request: Request): Promise<Response> {
|
|
|
84
83
|
// 可信上下文覆写)。access/acceptInput 已在 getHarnessHost 单例内装配。
|
|
85
84
|
// media 签名密钥:host 带 ownership(Prisma LogStore)时官方强制,缺失即抛错
|
|
86
85
|
// (桌面真机 Bug#1 根因,详见 harnessMediaSecret 注释)。
|
|
87
|
-
const host =
|
|
88
|
-
const handler = createHarnessHandler({ host, harness
|
|
86
|
+
const { host, harness } = await getHarnessRuntime()
|
|
87
|
+
const handler = createHarnessHandler({ host, harness, media: { secret: harnessMediaSecret() } })
|
|
89
88
|
return await handler(request)
|
|
90
89
|
} catch (error) {
|
|
91
90
|
console.error('[harness] 请求处理失败(host 装配或 handler 异常):', error)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// harness 模型目录展开(多 provider 修复):
|
|
6
|
+
// kernel 种子全目录进 catalog(key=裸模型 id + provider/model 别名),adapterKind
|
|
7
|
+
// 分派正确,未装 adapter 的 kind(gemini/bedrock/harness-*)跳过。
|
|
8
|
+
|
|
9
|
+
import { describe, expect, it } from 'vitest'
|
|
10
|
+
import { SEED_AI_PROVIDERS } from '@allbluecn/kernel'
|
|
11
|
+
import { buildModelCatalog } from '../model-catalog.server'
|
|
12
|
+
|
|
13
|
+
describe('buildModelCatalog(多 provider 目录)', () => {
|
|
14
|
+
const catalog = buildModelCatalog()
|
|
15
|
+
const keys = Object.keys(catalog)
|
|
16
|
+
|
|
17
|
+
it('default 缺省条目存在(OpenRouter auto)', () => {
|
|
18
|
+
expect(keys).toContain('default')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('种子全目录展开:每个 provider×model 都有裸 id + provider/model 别名', () => {
|
|
22
|
+
let seedModelCount = 0
|
|
23
|
+
for (const p of SEED_AI_PROVIDERS) {
|
|
24
|
+
for (const m of p.models ?? []) {
|
|
25
|
+
seedModelCount += 1
|
|
26
|
+
const skippedKind = ['gemini', 'bedrock', 'openrouter'].includes(p.adapterKind) ||
|
|
27
|
+
p.adapterKind.startsWith('harness-')
|
|
28
|
+
if (skippedKind && !['openrouter'].includes(p.adapterKind)) continue
|
|
29
|
+
// 跳过的 kind 无条目;其余 kind 必有裸 id 条目
|
|
30
|
+
if (p.adapterKind === 'gemini' || p.adapterKind === 'bedrock' || p.adapterKind.startsWith('harness-')) {
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
expect(keys).toContain(m.id)
|
|
34
|
+
expect(keys).toContain(`${p.providerId}/${m.id}`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// 目录规模与种子同量级(default + 每模型两键,跳过的 kind 除外)
|
|
38
|
+
expect(keys.length).toBeGreaterThan(seedModelCount)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('sensenova(openai-compatible)条目存在——真机验收用户的 provider', () => {
|
|
42
|
+
const sensenova = SEED_AI_PROVIDERS.find((p) => p.providerId === 'sensenova')
|
|
43
|
+
expect(sensenova).toBeDefined()
|
|
44
|
+
expect(sensenova!.adapterKind).toBe('openai-compatible')
|
|
45
|
+
for (const m of sensenova!.models ?? []) {
|
|
46
|
+
expect(keys).toContain(m.id)
|
|
47
|
+
expect(keys).toContain(`sensenova/${m.id}`)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('gemini/bedrock/harness-* 不进目录(未装 adapter / 非云端通道)', () => {
|
|
52
|
+
for (const p of SEED_AI_PROVIDERS) {
|
|
53
|
+
if (p.adapterKind === 'gemini' || p.adapterKind === 'bedrock') {
|
|
54
|
+
for (const m of p.models ?? []) {
|
|
55
|
+
expect(keys).not.toContain(`gemini/${m.id}`)
|
|
56
|
+
expect(keys).not.toContain(`bedrock/${m.id}`)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (p.adapterKind.startsWith('harness-')) {
|
|
60
|
+
// harness-* 是本地 ACP 通道(LocalAgentAdapter),不占模型目录
|
|
61
|
+
expect(keys).not.toContain(`${p.providerId}/`)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// ============ 桌面动态目录(buildDesktopModelCatalog) ============
|
|
68
|
+
import { beforeEach, vi } from 'vitest'
|
|
69
|
+
|
|
70
|
+
const prismaState = {
|
|
71
|
+
configs: [] as Array<{ providerId: string; models: unknown; baseUrl: string | null }>,
|
|
72
|
+
}
|
|
73
|
+
vi.mock('@allbluecn/database', () => ({
|
|
74
|
+
prisma: {
|
|
75
|
+
aiProviderConfig: {
|
|
76
|
+
findMany: vi.fn(async () => prismaState.configs),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
}))
|
|
80
|
+
|
|
81
|
+
// gate:桌面态(动态目录仅桌面派生)
|
|
82
|
+
vi.mock('@/server/harness/gate.server', () => ({
|
|
83
|
+
isHarnessHostEnabled: () => true,
|
|
84
|
+
}))
|
|
85
|
+
vi.mock('@/server/desktop-guest', () => ({
|
|
86
|
+
isDesktopServer: () => true,
|
|
87
|
+
GUEST_USER_ID: 'local-guest',
|
|
88
|
+
buildGuestSession: () => ({}),
|
|
89
|
+
}))
|
|
90
|
+
|
|
91
|
+
describe('buildDesktopModelCatalog(用户配置动态派生)', () => {
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
prismaState.configs = []
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('刷新模型拿回的 models 进目录(裸 id + 别名,baseUrl 用户值优先)', async () => {
|
|
97
|
+
const { buildDesktopModelCatalog } = await import('../model-catalog.server')
|
|
98
|
+
prismaState.configs = [
|
|
99
|
+
{ providerId: 'sensenova', models: ['SenseNova-2', '自定义模型X'], baseUrl: 'https://my-proxy.example.com/v1' },
|
|
100
|
+
]
|
|
101
|
+
const catalog = await buildDesktopModelCatalog()
|
|
102
|
+
expect(Object.keys(catalog)).toContain('SenseNova-2')
|
|
103
|
+
expect(Object.keys(catalog)).toContain('自定义模型X')
|
|
104
|
+
expect(Object.keys(catalog)).toContain('sensenova/SenseNova-2')
|
|
105
|
+
expect(Object.keys(catalog)).toContain('default')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('种子不再参与:内置过期的模型(未在用户配置中)不在目录', async () => {
|
|
109
|
+
const { buildDesktopModelCatalog } = await import('../model-catalog.server')
|
|
110
|
+
prismaState.configs = [
|
|
111
|
+
{ providerId: 'sensenova', models: ['SenseNova-2'], baseUrl: null },
|
|
112
|
+
]
|
|
113
|
+
const catalog = await buildDesktopModelCatalog()
|
|
114
|
+
// 种子的 SenseChat-6 未被用户配置 → 不进桌面目录
|
|
115
|
+
expect(Object.keys(catalog)).not.toContain('SenseChat-6')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('models 非字符串项被过滤;无种子元数据的 providerId 跳过', async () => {
|
|
119
|
+
const { buildDesktopModelCatalog } = await import('../model-catalog.server')
|
|
120
|
+
prismaState.configs = [
|
|
121
|
+
{ providerId: 'unknown-provider', models: ['m1'], baseUrl: null },
|
|
122
|
+
{ providerId: 'sensenova', models: ['ok-model', 42, null], baseUrl: null },
|
|
123
|
+
]
|
|
124
|
+
const catalog = await buildDesktopModelCatalog()
|
|
125
|
+
expect(Object.keys(catalog)).toContain('ok-model')
|
|
126
|
+
expect(Object.keys(catalog)).not.toContain('m1')
|
|
127
|
+
expect(Object.keys(catalog)).not.toContain('42')
|
|
128
|
+
})
|
|
129
|
+
})
|
|
@@ -209,5 +209,19 @@ export function buildHarnessDefinition(overrides?: {
|
|
|
209
209
|
})
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
/** 单例 harness
|
|
212
|
+
/** 单例 harness 定义(静态种子目录;测试与默认引用)。 */
|
|
213
213
|
export const allblueHarness: AnyHarness = buildHarnessDefinition()
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 运行时 harness 定义:桌面用**动态目录**(当前用户 AiProviderConfig 派生——
|
|
217
|
+
* 刷新模型/自定义 id,内置种子会过期),云端/web 保持种子静态目录。
|
|
218
|
+
* host.server 的单例重建(配置变更 → closeHarnessHost)时一起重建。
|
|
219
|
+
*/
|
|
220
|
+
export async function buildAllblueHarnessForRuntime(): Promise<AnyHarness> {
|
|
221
|
+
const { isDesktopServer } = await import('@/server/desktop-guest')
|
|
222
|
+
if (isDesktopServer()) {
|
|
223
|
+
const { buildDesktopModelCatalog } = await import('@/server/harness/model-catalog.server')
|
|
224
|
+
return buildHarnessDefinition({ models: await buildDesktopModelCatalog() })
|
|
225
|
+
}
|
|
226
|
+
return allblueHarness
|
|
227
|
+
}
|
|
@@ -22,7 +22,7 @@ import { createHarnessHost, type AcceptInput, type AnyHarness, type HarnessAcces
|
|
|
22
22
|
import { createHash, randomBytes } from 'node:crypto'
|
|
23
23
|
|
|
24
24
|
import { isHarnessHostEnabled } from '@/server/harness/gate.server'
|
|
25
|
-
import {
|
|
25
|
+
import { buildAllblueHarnessForRuntime } from '@/server/harness/define.server'
|
|
26
26
|
import { createReadOnlyCredentialStore } from '@/server/harness/credentials.server'
|
|
27
27
|
import { harnessAccess } from '@/server/harness/access.server'
|
|
28
28
|
import { trustedAcceptInput } from '@/server/harness/trusted-context.server'
|
|
@@ -34,6 +34,7 @@ export type { HarnessHostUser }
|
|
|
34
34
|
/** globalThis 上的单例槽位(HMR 重复构造防护)。 */
|
|
35
35
|
interface HostGlobal {
|
|
36
36
|
__allblue_harness_host__?: HarnessHost<HarnessHostUser>
|
|
37
|
+
__allblue_harness_def__?: AnyHarness
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -90,7 +91,17 @@ export function buildHarnessHost(
|
|
|
90
91
|
* 续接上次未完的回合);后续调用复用同一实例(含 HMR 后的模块重载——globalThis
|
|
91
92
|
* 跨模块实例存活,故 recover 每进程只跑一次)。
|
|
92
93
|
*/
|
|
93
|
-
|
|
94
|
+
/** host 与 harness 定义成对返回(路由 createHarnessHandler 必须用同一次构建的 harness)。 */
|
|
95
|
+
export async function getHarnessRuntime(): Promise<{
|
|
96
|
+
host: HarnessHost<HarnessHostUser>
|
|
97
|
+
harness: AnyHarness
|
|
98
|
+
}> {
|
|
99
|
+
const host = await getHarnessHost()
|
|
100
|
+
const g = globalThis as unknown as HostGlobal
|
|
101
|
+
return { host, harness: g.__allblue_harness_def__! }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function getHarnessHost(): Promise<HarnessHost<HarnessHostUser>> {
|
|
94
105
|
if (!isHarnessHostEnabled()) {
|
|
95
106
|
throw new Error(
|
|
96
107
|
'[harness] host 未启用:仅在桌面部署(DEPLOY_TARGET=desktop)或显式 dev 开关' +
|
|
@@ -99,16 +110,22 @@ export function getHarnessHost(): HarnessHost<HarnessHostUser> {
|
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
const g = globalThis as unknown as HostGlobal
|
|
102
|
-
if (g.__allblue_harness_host__
|
|
113
|
+
if (g.__allblue_harness_host__ && g.__allblue_harness_def__) {
|
|
114
|
+
return g.__allblue_harness_host__
|
|
115
|
+
}
|
|
103
116
|
|
|
104
117
|
// 装配 access(getCurrentSession 映射 + owner-only + 抢建防护)与 acceptInput
|
|
105
118
|
// (可信上下文覆写,P0-2)。host.server.ts 仅服务端加载(经 /api/harness 路由,
|
|
106
119
|
// server.handlers 剥离),故服务端 import 安全;客户端永不 import 本文件。
|
|
107
|
-
|
|
120
|
+
// harness 定义走运行时工厂:桌面目录按当前用户配置动态派生(刷新模型/自定义
|
|
121
|
+
// id,内置种子会过期),配置变更由 serverFn closeHarnessHost() 触发本函数重建。
|
|
122
|
+
const harness = await buildAllblueHarnessForRuntime()
|
|
123
|
+
const host = buildHarnessHost(harness, {
|
|
108
124
|
access: harnessAccess(),
|
|
109
125
|
acceptInput: trustedAcceptInput(),
|
|
110
126
|
})
|
|
111
127
|
g.__allblue_harness_host__ = host
|
|
128
|
+
g.__allblue_harness_def__ = harness
|
|
112
129
|
|
|
113
130
|
// 启动恢复(官方 host.recover(),host.d.ts:845):接管上次宿主停止后遗留的
|
|
114
131
|
// 待跑输入 / 到期 schedule。fire-and-forget——getHarnessHost 同步返回,恢复在后台
|
|
@@ -161,6 +178,15 @@ export async function closeHarnessHost(options: {
|
|
|
161
178
|
const host = g.__allblue_harness_host__
|
|
162
179
|
if (host) {
|
|
163
180
|
await host.close({ recoverable: options.recoverable === true })
|
|
181
|
+
}
|
|
182
|
+
// host 与 harness 定义成对清除:模型目录变更(刷新模型/保存/删除)后
|
|
183
|
+
// 下次 getHarnessHost() 以新目录重建 host + harness 定义。
|
|
184
|
+
// 注意 recoverable close(桌面退出)语义不变:不清场待续接——仅在
|
|
185
|
+
// 非 recoverable(目录变更/测试)时成对清 harness 定义。
|
|
186
|
+
if (options.recoverable === true) {
|
|
187
|
+
g.__allblue_harness_host__ = undefined
|
|
188
|
+
} else {
|
|
164
189
|
g.__allblue_harness_host__ = undefined
|
|
190
|
+
g.__allblue_harness_def__ = undefined
|
|
165
191
|
}
|
|
166
192
|
}
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
|
|
16
16
|
import { keyedAdapter, type AnyTextAdapter, type KeyedAdapter } from '@tanstack/ai'
|
|
17
17
|
import { createOpenRouterText } from '@tanstack/ai-openrouter'
|
|
18
|
+
import { createOpenaiChat } from '@tanstack/ai-openai'
|
|
19
|
+
import { openaiCompatibleText } from '@tanstack/ai-openai/compatible'
|
|
20
|
+
import { createAnthropicChat } from '@tanstack/ai-anthropic'
|
|
21
|
+
import { prisma } from '@allbluecn/database'
|
|
22
|
+
import { SEED_AI_PROVIDERS, type AiProviderMeta } from '@allbluecn/kernel'
|
|
18
23
|
|
|
19
24
|
/**
|
|
20
25
|
* 默认模型条目(OpenRouter,缺省走用户 DB 档 key)。
|
|
@@ -32,20 +37,86 @@ const DEFAULT_MODEL = 'openrouter/auto'
|
|
|
32
37
|
* `default` 是未选模型时的缺省 adapter。生产环境每个用户配置不同,但 keyedAdapter
|
|
33
38
|
* 只在调用时解析 key,故目录本身可以静态共享。
|
|
34
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* 单个 provider×model 的 keyedAdapter 工厂(按 adapterKind 分派)。
|
|
42
|
+
*
|
|
43
|
+
* providerId 传平台 providerId——host 以它调 CredentialStore.get({ id }),桥映射到
|
|
44
|
+
* AiProviderConfig.providerId 取该回合用户的 key(T2.2 只读桥)。
|
|
45
|
+
*
|
|
46
|
+
* 未装 adapter 的 kind 跳过(返回 null,不进目录):gemini(无官方包;其
|
|
47
|
+
* OpenAI 兼容端点未实测不冒进)、bedrock(云端专用)、harness-*(本地 ACP
|
|
48
|
+
* 经 LocalAgentAdapter 通道,不进模型目录)、ollama(openai-compatible 通道覆盖)。
|
|
49
|
+
*/
|
|
50
|
+
function keyedAdapterFactory(
|
|
51
|
+
provider: AiProviderMeta,
|
|
52
|
+
modelId: string,
|
|
53
|
+
baseUrlOverride?: string | null,
|
|
54
|
+
): KeyedAdapter<AnyTextAdapter> | null {
|
|
55
|
+
// 用户配置的 baseUrl 优先(BYOK 自定义端点),回落 provider 种子默认
|
|
56
|
+
const baseURL = baseUrlOverride || provider.defaultBaseUrl
|
|
57
|
+
switch (provider.adapterKind) {
|
|
58
|
+
case 'openai':
|
|
59
|
+
// create*Chat 形式把 apiKey 作独立参数(keyedAdapter 工厂约定);模型 id
|
|
60
|
+
// 越出官方清单(自定义条目)用 as never——运行时按字符串构建 client
|
|
61
|
+
return keyedAdapter(provider.providerId, (key): AnyTextAdapter =>
|
|
62
|
+
createOpenaiChat(modelId as never, key) as unknown as AnyTextAdapter,
|
|
63
|
+
)
|
|
64
|
+
case 'openai-compatible':
|
|
65
|
+
case 'groq':
|
|
66
|
+
case 'grok':
|
|
67
|
+
case 'mistral':
|
|
68
|
+
case 'byteplus':
|
|
69
|
+
case 'ollama':
|
|
70
|
+
// OpenAI 兼容端点(SenseNova/DeepSeek/Groq/Grok/Mistral…):chat-completions
|
|
71
|
+
// API + 各自 defaultBaseUrl。baseURL 缺失的条目不进目录(无法寻址)。
|
|
72
|
+
if (!baseURL) return null
|
|
73
|
+
return keyedAdapter(provider.providerId, (key): AnyTextAdapter =>
|
|
74
|
+
openaiCompatibleText(modelId as never, {
|
|
75
|
+
baseURL,
|
|
76
|
+
apiKey: key,
|
|
77
|
+
api: 'chat-completions',
|
|
78
|
+
}) as unknown as AnyTextAdapter,
|
|
79
|
+
)
|
|
80
|
+
case 'anthropic':
|
|
81
|
+
return keyedAdapter(provider.providerId, (key): AnyTextAdapter =>
|
|
82
|
+
createAnthropicChat(modelId as never, key) as unknown as AnyTextAdapter,
|
|
83
|
+
)
|
|
84
|
+
case 'openrouter':
|
|
85
|
+
// OpenRouter 模型名自带 provider/ 前缀
|
|
86
|
+
return keyedAdapter(provider.providerId, (key): AnyTextAdapter =>
|
|
87
|
+
createOpenRouterText(modelId as never, key, { appTitle: 'AllBlue' }) as unknown as AnyTextAdapter,
|
|
88
|
+
)
|
|
89
|
+
default:
|
|
90
|
+
// gemini / bedrock / harness-*:见函数头注释
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
35
95
|
export function buildModelCatalog(): Record<
|
|
36
96
|
string,
|
|
37
97
|
AnyTextAdapter | KeyedAdapter<AnyTextAdapter>
|
|
38
98
|
> {
|
|
39
|
-
|
|
99
|
+
const catalog: Record<string, AnyTextAdapter | KeyedAdapter<AnyTextAdapter>> = {
|
|
40
100
|
default: keyedAdapter('openrouter', (key): AnyTextAdapter =>
|
|
41
101
|
createOpenRouterText(DEFAULT_MODEL as never, key, {
|
|
42
102
|
appTitle: 'AllBlue',
|
|
43
103
|
}) as unknown as AnyTextAdapter,
|
|
44
104
|
),
|
|
45
|
-
// 多 provider 条目示例(key 存在才可用;展开见后续 Phase):
|
|
46
|
-
// 'openai/gpt-5.5': keyedAdapter('openai', (key) => openaiText('gpt-5.5' as never, { apiKey: key })),
|
|
47
|
-
// 'anthropic/claude-sonnet-5-5': keyedAdapter('anthropic', (key) => anthropicText('claude-sonnet-5-5' as never, { apiKey: key })),
|
|
48
105
|
}
|
|
106
|
+
// 平台全目录(kernel 种子):条目即白名单,可用性由「key 存在 + UI 过滤 +
|
|
107
|
+
// updateThreadSettings 校验」三重决定(设计 §5.6)。
|
|
108
|
+
// key 用**裸模型 id**(与工作台 选择模型/availableModels 同域——UI 发裸 id),
|
|
109
|
+
// 另挂 `${providerId}/${modelId}` 别名。裸 id 跨 provider 撞名时先到先得。
|
|
110
|
+
for (const provider of SEED_AI_PROVIDERS) {
|
|
111
|
+
for (const model of provider.models ?? []) {
|
|
112
|
+
const factory = keyedAdapterFactory(provider, model.id)
|
|
113
|
+
if (!factory) continue
|
|
114
|
+
if (!(model.id in catalog)) catalog[model.id] = factory
|
|
115
|
+
const alias = `${provider.providerId}/${model.id}`
|
|
116
|
+
if (!(alias in catalog)) catalog[alias] = factory
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return catalog
|
|
49
120
|
}
|
|
50
121
|
|
|
51
122
|
/** 供 title 插件等使用同一 keyedAdapter 工厂(设计 §5.6:title 同样用 keyed)。 */
|
|
@@ -54,3 +125,45 @@ export function defaultKeyedAdapter(): KeyedAdapter<AnyTextAdapter> {
|
|
|
54
125
|
createOpenRouterText(DEFAULT_MODEL as never, key, { appTitle: 'AllBlue' }) as unknown as AnyTextAdapter,
|
|
55
126
|
)
|
|
56
127
|
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 桌面动态模型目录:从**当前用户的 AiProviderConfig** 派生(刷新模型 API 拿回的
|
|
131
|
+
* models / 用户手填的自定义 id),而非 kernel 种子——内置清单会过期(真机验收
|
|
132
|
+
* 实证:商汤种子 id SenseChat-6/5/5-Lite 全被用户端点 404)。桌面是单用户场景,
|
|
133
|
+
* 目录即该用户配置的全集;配置变更(刷新模型/保存/删除)由 serverFn 触发
|
|
134
|
+
* closeHarnessHost() → 下次请求重建 host + harness 定义。
|
|
135
|
+
*
|
|
136
|
+
* key 域与 #662 一致:裸模型 id(与工作台 选择模型 同域)+ providerId/modelId 别名。
|
|
137
|
+
* baseUrl 取用户配置值优先(BYOK 自定义端点)。
|
|
138
|
+
*/
|
|
139
|
+
export async function buildDesktopModelCatalog(): Promise<
|
|
140
|
+
Record<string, AnyTextAdapter | KeyedAdapter<AnyTextAdapter>>
|
|
141
|
+
> {
|
|
142
|
+
const catalog: Record<string, AnyTextAdapter | KeyedAdapter<AnyTextAdapter>> = {
|
|
143
|
+
default: keyedAdapter('openrouter', (key): AnyTextAdapter =>
|
|
144
|
+
createOpenRouterText(DEFAULT_MODEL as never, key, {
|
|
145
|
+
appTitle: 'AllBlue',
|
|
146
|
+
}) as unknown as AnyTextAdapter,
|
|
147
|
+
),
|
|
148
|
+
}
|
|
149
|
+
const configs = await prisma.aiProviderConfig.findMany({
|
|
150
|
+
where: { enabled: true, apiKey: { not: null } },
|
|
151
|
+
select: { providerId: true, models: true, baseUrl: true },
|
|
152
|
+
})
|
|
153
|
+
for (const cfg of configs) {
|
|
154
|
+
const provider = SEED_AI_PROVIDERS.find((p) => p.providerId === cfg.providerId)
|
|
155
|
+
// 无种子元数据的 providerId(未来自定义服务商)跳过——adapterKind/baseUrl 无法判定
|
|
156
|
+
if (!provider) continue
|
|
157
|
+
const modelIds = Array.isArray(cfg.models)
|
|
158
|
+
? (cfg.models as unknown[]).filter((m): m is string => typeof m === 'string')
|
|
159
|
+
: []
|
|
160
|
+
for (const modelId of modelIds) {
|
|
161
|
+
const factory = keyedAdapterFactory(provider, modelId, cfg.baseUrl)
|
|
162
|
+
if (!factory) continue
|
|
163
|
+
if (!(modelId in catalog)) catalog[modelId] = factory
|
|
164
|
+
const alias = `${cfg.providerId}/${modelId}`
|
|
165
|
+
if (!(alias in catalog)) catalog[alias] = factory
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return catalog
|
|
169
|
+
}
|
|
@@ -58,7 +58,7 @@ export async function applyHarnessPermissionMode(
|
|
|
58
58
|
const mode = sandboxPolicyToPermissionMode(policy)
|
|
59
59
|
const { getHarnessHost } = await import('@/server/harness/host.server')
|
|
60
60
|
const { allblueHarness } = await import('@/server/harness/define.server')
|
|
61
|
-
const host = getHarnessHost()
|
|
61
|
+
const host = await getHarnessHost()
|
|
62
62
|
const session = await host.open(allblueHarness, { threadId, user })
|
|
63
63
|
try {
|
|
64
64
|
await session.setPluginSetting({ key: 'mode', value: mode, user })
|
|
@@ -270,7 +270,7 @@ export const deleteConversationFn = createServerFn({ method: "POST" })
|
|
|
270
270
|
const { isHarnessHostEnabled } = await import("@/server/harness/gate.server")
|
|
271
271
|
if (isHarnessHostEnabled()) {
|
|
272
272
|
const { getHarnessHost } = await import("@/server/harness/host.server")
|
|
273
|
-
await getHarnessHost().sessions.delete({
|
|
273
|
+
await (await getHarnessHost()).sessions.delete({
|
|
274
274
|
threadId: data.id,
|
|
275
275
|
user: { id: context.user.id },
|
|
276
276
|
})
|
|
@@ -587,6 +587,54 @@ export const createCustomProviderFn = createServerFn({ method: "POST" })
|
|
|
587
587
|
invalidateAiConfigCache(userId);
|
|
588
588
|
}
|
|
589
589
|
|
|
590
|
+
// harness host/harness 定义成对重建:模型目录按用户配置动态派生(刷新模型/
|
|
591
|
+
// 自定义 id),目录变更后旧 host 的目录已过期(真机验收:商汤种子 id 全 404)。
|
|
592
|
+
try {
|
|
593
|
+
const { isHarnessHostEnabled } = await import("@/server/harness/gate.server")
|
|
594
|
+
if (isHarnessHostEnabled()) {
|
|
595
|
+
const { closeHarnessHost } = await import("@/server/harness/host.server")
|
|
596
|
+
await closeHarnessHost()
|
|
597
|
+
}
|
|
598
|
+
} catch (error) {
|
|
599
|
+
console.warn("[providers] harness host 重建触发失败(下次请求自然重建):", error instanceof Error ? error.message : error)
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// harness host/harness 定义成对重建:模型目录按用户配置动态派生(刷新模型/
|
|
603
|
+
// 自定义 id),目录变更后旧 host 的目录已过期(真机验收:商汤种子 id 全 404)。
|
|
604
|
+
try {
|
|
605
|
+
const { isHarnessHostEnabled } = await import("@/server/harness/gate.server")
|
|
606
|
+
if (isHarnessHostEnabled()) {
|
|
607
|
+
const { closeHarnessHost } = await import("@/server/harness/host.server")
|
|
608
|
+
await closeHarnessHost()
|
|
609
|
+
}
|
|
610
|
+
} catch (error) {
|
|
611
|
+
console.warn("[providers] harness host 重建触发失败(下次请求自然重建):", error instanceof Error ? error.message : error)
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// harness host/harness 定义成对重建:模型目录按用户配置动态派生(刷新模型/
|
|
615
|
+
// 自定义 id),目录变更后旧 host 的目录已过期(真机验收:商汤种子 id 全 404)。
|
|
616
|
+
try {
|
|
617
|
+
const { isHarnessHostEnabled } = await import("@/server/harness/gate.server")
|
|
618
|
+
if (isHarnessHostEnabled()) {
|
|
619
|
+
const { closeHarnessHost } = await import("@/server/harness/host.server")
|
|
620
|
+
await closeHarnessHost()
|
|
621
|
+
}
|
|
622
|
+
} catch (error) {
|
|
623
|
+
console.warn("[providers] harness host 重建触发失败(下次请求自然重建):", error instanceof Error ? error.message : error)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// harness host/harness 定义成对重建:模型目录按用户配置动态派生(刷新模型/
|
|
627
|
+
// 自定义 id),目录变更后旧 host 的目录已过期(真机验收:商汤种子 id 全 404)。
|
|
628
|
+
try {
|
|
629
|
+
const { isHarnessHostEnabled } = await import("@/server/harness/gate.server")
|
|
630
|
+
if (isHarnessHostEnabled()) {
|
|
631
|
+
const { closeHarnessHost } = await import("@/server/harness/host.server")
|
|
632
|
+
await closeHarnessHost()
|
|
633
|
+
}
|
|
634
|
+
} catch (error) {
|
|
635
|
+
console.warn("[providers] harness host 重建触发失败(下次请求自然重建):", error instanceof Error ? error.message : error)
|
|
636
|
+
}
|
|
637
|
+
|
|
590
638
|
return {
|
|
591
639
|
success: true,
|
|
592
640
|
providerId,
|
|
@@ -58,7 +58,7 @@ export const forkHarnessThreadFn = createServerFn({ method: "POST" })
|
|
|
58
58
|
}
|
|
59
59
|
const { getHarnessHost } = await import("@/server/harness/host.server")
|
|
60
60
|
const { allblueHarness } = await import("@/server/harness/define.server")
|
|
61
|
-
const host = getHarnessHost()
|
|
61
|
+
const host = await getHarnessHost()
|
|
62
62
|
const newThreadId = crypto.randomUUID()
|
|
63
63
|
await host.fork(allblueHarness, {
|
|
64
64
|
threadId: data.threadId,
|