@allbluecn/web-app 0.27.32 → 0.27.33
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/components/agents/__tests__/agent-bindings-tab.test.tsx +1 -0
- package/src/components/agents/__tests__/agents-page.test.tsx +1 -0
- package/src/components/agents/agent-form-dialog.tsx +39 -0
- package/src/components/agents/agents-page.tsx +1 -0
- package/src/components/agents/schemas/agent-form.ts +14 -0
- package/src/lib/changelog/sdk-versions.ts +1 -1
- package/src/paraglide/messages/_index.js +112 -0
- package/src/paraglide/messages/en.js +35 -0
- package/src/paraglide/messages/zh.js +35 -0
- package/src/routes/api/harness/$.ts +27 -16
- package/src/server/agents/__tests__/runtime-subagents.test.ts +50 -0
- package/src/server/agents/registry.server.ts +8 -0
- package/src/server/ai-gateway/__tests__/harness-kind-routing.test.ts +84 -0
- package/src/server/ai-gateway/chat-handler.ts +41 -6
- package/src/server/ai-gateway/runs/resolve-overrides.ts +3 -0
- package/src/server/ai-gateway/runs/user-agent.ts +18 -0
- package/src/server/harness/__tests__/define-registry-subagents.test.ts +80 -0
- package/src/server/harness/define.server.ts +32 -2
- package/src/server/serverFns/agents/agent-crud.ts +11 -0
package/package.json
CHANGED
|
@@ -62,6 +62,7 @@ const makeAgent = (over: { id: string; name: string; isDefault?: boolean }): Age
|
|
|
62
62
|
greeting: null,
|
|
63
63
|
suggestedPrompts: null,
|
|
64
64
|
knowledgeBaseIds: [],
|
|
65
|
+
harnessKind: null,
|
|
65
66
|
isDefault: false,
|
|
66
67
|
createdAt: new Date('2026-01-01T00:00:00Z'),
|
|
67
68
|
updatedAt: new Date('2026-01-01T00:00:00Z'),
|
|
@@ -19,6 +19,7 @@ import { Label } from '@/components/ui/label'
|
|
|
19
19
|
import { Badge } from '@/components/ui/badge'
|
|
20
20
|
import { Checkbox } from '@/components/ui/checkbox'
|
|
21
21
|
import { Switch } from '@/components/ui/switch'
|
|
22
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
22
23
|
import {
|
|
23
24
|
Plus,
|
|
24
25
|
X,
|
|
@@ -34,6 +35,15 @@ import { useKnowledgeBases } from '@/lib/ai/use-knowledge-bases'
|
|
|
34
35
|
import { t } from '@/lib/i18n/resolver'
|
|
35
36
|
import type { KnowledgeBaseItem } from '@/components/ai/ai-prompt-input'
|
|
36
37
|
|
|
38
|
+
/** harnessKind 选择项(value=null = 普通对话 agent;其余走桌面 ACP 通道)。 */
|
|
39
|
+
const HARNESS_KIND_OPTIONS: Array<{ value: string; label: () => string }> = [
|
|
40
|
+
{ value: 'normal', label: m.agents_agentForm_harnessKindNormal },
|
|
41
|
+
{ value: 'claude-code', label: m.agents_agentForm_harnessKindClaudeCode },
|
|
42
|
+
{ value: 'codex', label: m.agents_agentForm_harnessKindCodex },
|
|
43
|
+
{ value: 'acp', label: m.agents_agentForm_harnessKindAcp },
|
|
44
|
+
{ value: 'opencode', label: m.agents_agentForm_harnessKindOpendcode },
|
|
45
|
+
]
|
|
46
|
+
|
|
37
47
|
interface AgentFormDialogProps {
|
|
38
48
|
open: boolean
|
|
39
49
|
onOpenChange: (open: boolean) => void
|
|
@@ -67,6 +77,7 @@ export function AgentFormDialog({ open, onOpenChange, agent, onSuccess }: AgentF
|
|
|
67
77
|
greeting: agent?.greeting ?? '',
|
|
68
78
|
suggestedPrompts: agent?.suggestedPrompts ?? [],
|
|
69
79
|
knowledgeBaseIds: agent?.knowledgeBaseIds ?? [],
|
|
80
|
+
harnessKind: agent?.harnessKind ?? null,
|
|
70
81
|
} as AgentFormValues,
|
|
71
82
|
validators: [{ run: agentFormSchema, triggers: ['change'] }],
|
|
72
83
|
})
|
|
@@ -277,6 +288,34 @@ export function AgentFormDialog({ open, onOpenChange, agent, onSuccess }: AgentF
|
|
|
277
288
|
</div>
|
|
278
289
|
</div>
|
|
279
290
|
|
|
291
|
+
<div className="flex flex-col gap-2">
|
|
292
|
+
<Label>{m.agents_agentForm_harnessKindLabel()}</Label>
|
|
293
|
+
<p className="text-xs text-muted-foreground">
|
|
294
|
+
{m.agents_agentForm_harnessKindHint()}
|
|
295
|
+
</p>
|
|
296
|
+
<form.Field name="harnessKind">
|
|
297
|
+
{(field) => (
|
|
298
|
+
<Select
|
|
299
|
+
value={field.value ?? 'normal'}
|
|
300
|
+
onValueChange={(v) =>
|
|
301
|
+
field.handleChange(v === 'normal' ? null : (v as NonNullable<AgentFormValues['harnessKind']>))
|
|
302
|
+
}
|
|
303
|
+
>
|
|
304
|
+
<SelectTrigger className="w-full">
|
|
305
|
+
<SelectValue />
|
|
306
|
+
</SelectTrigger>
|
|
307
|
+
<SelectContent>
|
|
308
|
+
{HARNESS_KIND_OPTIONS.map((opt) => (
|
|
309
|
+
<SelectItem key={opt.value} value={opt.value}>
|
|
310
|
+
{opt.label()}
|
|
311
|
+
</SelectItem>
|
|
312
|
+
))}
|
|
313
|
+
</SelectContent>
|
|
314
|
+
</Select>
|
|
315
|
+
)}
|
|
316
|
+
</form.Field>
|
|
317
|
+
</div>
|
|
318
|
+
|
|
280
319
|
<div className="flex flex-col gap-2">
|
|
281
320
|
<Label>{m.agents_agentForm_suggestedPromptsLabel()}</Label>
|
|
282
321
|
<p className="text-xs text-muted-foreground">
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import { AGENT_TOOL_KEYS } from '@/server/ai-gateway/tools/select'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* harnessKind 合法值(与 server 侧 runs/user-agent.ts HARNESS_KINDS 同源同序)。
|
|
6
|
+
* ⚠ 此处内联字面量而非 import——user-agent.ts 顶层 import prisma,进客户端 bundle
|
|
7
|
+
* 会炸(同 agent-crud.ts AGENT_TOOL_KEYS 走纯净子路径 tools/select 的理由)。
|
|
8
|
+
* null/缺省 = 普通对话 agent(云 LLM);非 null = 桌面走 ACP 通道执行。
|
|
9
|
+
*/
|
|
10
|
+
export const HARNESS_KIND_VALUES = [
|
|
11
|
+
'claude-code',
|
|
12
|
+
'codex',
|
|
13
|
+
'acp',
|
|
14
|
+
'opencode',
|
|
15
|
+
] as const
|
|
16
|
+
|
|
4
17
|
export const agentFormSchema = z.object({
|
|
5
18
|
name: z.string().min(1).max(64),
|
|
6
19
|
description: z.string().max(512).optional(),
|
|
@@ -12,6 +25,7 @@ export const agentFormSchema = z.object({
|
|
|
12
25
|
greeting: z.string().max(1000).optional(),
|
|
13
26
|
suggestedPrompts: z.array(z.string().max(200)).max(4).optional(),
|
|
14
27
|
knowledgeBaseIds: z.array(z.string()).max(50).optional(),
|
|
28
|
+
harnessKind: z.enum(HARNESS_KIND_VALUES).nullable().optional(),
|
|
15
29
|
})
|
|
16
30
|
|
|
17
31
|
export const skillFormSchema = z.object({
|
|
@@ -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.33",
|
|
116
116
|
"lastUpdate": "Nov 10, 2026",
|
|
117
117
|
"source": "apps/web/package.json",
|
|
118
118
|
"docsUrl": "https://github.com/allbluecn/allblue"
|
|
@@ -75,6 +75,13 @@ import { getLocale, experimentalStaticLocale } from "../runtime.js"
|
|
|
75
75
|
/** @typedef {{}} Agents_Agentform_Greetinglabel2Inputs */
|
|
76
76
|
/** @typedef {{}} Agents_Agentform_Greetingoptional2Inputs */
|
|
77
77
|
/** @typedef {{}} Agents_Agentform_Greetingplaceholder2Inputs */
|
|
78
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindacp3Inputs */
|
|
79
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindclaudecode4Inputs */
|
|
80
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindcodex3Inputs */
|
|
81
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindhint3Inputs */
|
|
82
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindlabel3Inputs */
|
|
83
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindnormal3Inputs */
|
|
84
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindopendcode3Inputs */
|
|
78
85
|
/** @typedef {{}} Agents_Agentform_Invalid1Inputs */
|
|
79
86
|
/** @typedef {{}} Agents_Agentform_Knowledgebaseshint3Inputs */
|
|
80
87
|
/** @typedef {{}} Agents_Agentform_Knowledgebaseslabel3Inputs */
|
|
@@ -6893,6 +6900,111 @@ export { agents_agentform_greetingplaceholder2 as "agents_agentForm_greetingPlac
|
|
|
6893
6900
|
/**
|
|
6894
6901
|
* | output |
|
|
6895
6902
|
* | --- |
|
|
6903
|
+
* | "ACP (local CLI catalog)" |
|
|
6904
|
+
*
|
|
6905
|
+
* @param {Agents_Agentform_Harnesskindacp3Inputs} inputs
|
|
6906
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6907
|
+
* @returns {LocalizedString}
|
|
6908
|
+
*/
|
|
6909
|
+
const agents_agentform_harnesskindacp3 = /** @type {((inputs?: Agents_Agentform_Harnesskindacp3Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindacp3Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
6910
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
6911
|
+
if (locale === "en") return __en.agents_agentform_harnesskindacp3(inputs)
|
|
6912
|
+
return __zh.agents_agentform_harnesskindacp3(inputs)
|
|
6913
|
+
});
|
|
6914
|
+
export { agents_agentform_harnesskindacp3 as "agents_agentForm_harnessKindAcp" }
|
|
6915
|
+
/**
|
|
6916
|
+
* | output |
|
|
6917
|
+
* | --- |
|
|
6918
|
+
* | "Claude Code (local CLI)" |
|
|
6919
|
+
*
|
|
6920
|
+
* @param {Agents_Agentform_Harnesskindclaudecode4Inputs} inputs
|
|
6921
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6922
|
+
* @returns {LocalizedString}
|
|
6923
|
+
*/
|
|
6924
|
+
const agents_agentform_harnesskindclaudecode4 = /** @type {((inputs?: Agents_Agentform_Harnesskindclaudecode4Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindclaudecode4Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
6925
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
6926
|
+
if (locale === "en") return __en.agents_agentform_harnesskindclaudecode4(inputs)
|
|
6927
|
+
return __zh.agents_agentform_harnesskindclaudecode4(inputs)
|
|
6928
|
+
});
|
|
6929
|
+
export { agents_agentform_harnesskindclaudecode4 as "agents_agentForm_harnessKindClaudeCode" }
|
|
6930
|
+
/**
|
|
6931
|
+
* | output |
|
|
6932
|
+
* | --- |
|
|
6933
|
+
* | "Codex (local CLI)" |
|
|
6934
|
+
*
|
|
6935
|
+
* @param {Agents_Agentform_Harnesskindcodex3Inputs} inputs
|
|
6936
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6937
|
+
* @returns {LocalizedString}
|
|
6938
|
+
*/
|
|
6939
|
+
const agents_agentform_harnesskindcodex3 = /** @type {((inputs?: Agents_Agentform_Harnesskindcodex3Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindcodex3Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
6940
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
6941
|
+
if (locale === "en") return __en.agents_agentform_harnesskindcodex3(inputs)
|
|
6942
|
+
return __zh.agents_agentform_harnesskindcodex3(inputs)
|
|
6943
|
+
});
|
|
6944
|
+
export { agents_agentform_harnesskindcodex3 as "agents_agentForm_harnessKindCodex" }
|
|
6945
|
+
/**
|
|
6946
|
+
* | output |
|
|
6947
|
+
* | --- |
|
|
6948
|
+
* | "On desktop, run via a local ACP CLI (claude-code / codex / opencode); ignored on web, which uses the cloud model" |
|
|
6949
|
+
*
|
|
6950
|
+
* @param {Agents_Agentform_Harnesskindhint3Inputs} inputs
|
|
6951
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6952
|
+
* @returns {LocalizedString}
|
|
6953
|
+
*/
|
|
6954
|
+
const agents_agentform_harnesskindhint3 = /** @type {((inputs?: Agents_Agentform_Harnesskindhint3Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindhint3Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
6955
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
6956
|
+
if (locale === "en") return __en.agents_agentform_harnesskindhint3(inputs)
|
|
6957
|
+
return __zh.agents_agentform_harnesskindhint3(inputs)
|
|
6958
|
+
});
|
|
6959
|
+
export { agents_agentform_harnesskindhint3 as "agents_agentForm_harnessKindHint" }
|
|
6960
|
+
/**
|
|
6961
|
+
* | output |
|
|
6962
|
+
* | --- |
|
|
6963
|
+
* | "Execution channel" |
|
|
6964
|
+
*
|
|
6965
|
+
* @param {Agents_Agentform_Harnesskindlabel3Inputs} inputs
|
|
6966
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6967
|
+
* @returns {LocalizedString}
|
|
6968
|
+
*/
|
|
6969
|
+
const agents_agentform_harnesskindlabel3 = /** @type {((inputs?: Agents_Agentform_Harnesskindlabel3Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindlabel3Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
6970
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
6971
|
+
if (locale === "en") return __en.agents_agentform_harnesskindlabel3(inputs)
|
|
6972
|
+
return __zh.agents_agentform_harnesskindlabel3(inputs)
|
|
6973
|
+
});
|
|
6974
|
+
export { agents_agentform_harnesskindlabel3 as "agents_agentForm_harnessKindLabel" }
|
|
6975
|
+
/**
|
|
6976
|
+
* | output |
|
|
6977
|
+
* | --- |
|
|
6978
|
+
* | "Normal chat (cloud model)" |
|
|
6979
|
+
*
|
|
6980
|
+
* @param {Agents_Agentform_Harnesskindnormal3Inputs} inputs
|
|
6981
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6982
|
+
* @returns {LocalizedString}
|
|
6983
|
+
*/
|
|
6984
|
+
const agents_agentform_harnesskindnormal3 = /** @type {((inputs?: Agents_Agentform_Harnesskindnormal3Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindnormal3Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
6985
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
6986
|
+
if (locale === "en") return __en.agents_agentform_harnesskindnormal3(inputs)
|
|
6987
|
+
return __zh.agents_agentform_harnesskindnormal3(inputs)
|
|
6988
|
+
});
|
|
6989
|
+
export { agents_agentform_harnesskindnormal3 as "agents_agentForm_harnessKindNormal" }
|
|
6990
|
+
/**
|
|
6991
|
+
* | output |
|
|
6992
|
+
* | --- |
|
|
6993
|
+
* | "OpenCode (local CLI)" |
|
|
6994
|
+
*
|
|
6995
|
+
* @param {Agents_Agentform_Harnesskindopendcode3Inputs} inputs
|
|
6996
|
+
* @param {{ locale?: "zh" | "en" }} options
|
|
6997
|
+
* @returns {LocalizedString}
|
|
6998
|
+
*/
|
|
6999
|
+
const agents_agentform_harnesskindopendcode3 = /** @type {((inputs?: Agents_Agentform_Harnesskindopendcode3Inputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Agents_Agentform_Harnesskindopendcode3Inputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
7000
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
7001
|
+
if (locale === "en") return __en.agents_agentform_harnesskindopendcode3(inputs)
|
|
7002
|
+
return __zh.agents_agentform_harnesskindopendcode3(inputs)
|
|
7003
|
+
});
|
|
7004
|
+
export { agents_agentform_harnesskindopendcode3 as "agents_agentForm_harnessKindOpendcode" }
|
|
7005
|
+
/**
|
|
7006
|
+
* | output |
|
|
7007
|
+
* | --- |
|
|
6896
7008
|
* | "Please check the form fields" |
|
|
6897
7009
|
*
|
|
6898
7010
|
* @param {Agents_Agentform_Invalid1Inputs} inputs
|
|
@@ -73,6 +73,13 @@
|
|
|
73
73
|
/** @typedef {{}} Agents_Agentform_Greetinglabel2Inputs */
|
|
74
74
|
/** @typedef {{}} Agents_Agentform_Greetingoptional2Inputs */
|
|
75
75
|
/** @typedef {{}} Agents_Agentform_Greetingplaceholder2Inputs */
|
|
76
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindacp3Inputs */
|
|
77
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindclaudecode4Inputs */
|
|
78
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindcodex3Inputs */
|
|
79
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindhint3Inputs */
|
|
80
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindlabel3Inputs */
|
|
81
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindnormal3Inputs */
|
|
82
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindopendcode3Inputs */
|
|
76
83
|
/** @typedef {{}} Agents_Agentform_Invalid1Inputs */
|
|
77
84
|
/** @typedef {{}} Agents_Agentform_Knowledgebaseshint3Inputs */
|
|
78
85
|
/** @typedef {{}} Agents_Agentform_Knowledgebaseslabel3Inputs */
|
|
@@ -6086,6 +6093,34 @@ export const agents_agentform_greetingplaceholder2 = /** @type {(inputs: Agents_
|
|
|
6086
6093
|
return /** @type {LocalizedString} */ (`The agent's first message`)
|
|
6087
6094
|
};
|
|
6088
6095
|
|
|
6096
|
+
export const agents_agentform_harnesskindacp3 = /** @type {(inputs: Agents_Agentform_Harnesskindacp3Inputs) => LocalizedString} */ () => {
|
|
6097
|
+
return /** @type {LocalizedString} */ (`ACP (local CLI catalog)`)
|
|
6098
|
+
};
|
|
6099
|
+
|
|
6100
|
+
export const agents_agentform_harnesskindclaudecode4 = /** @type {(inputs: Agents_Agentform_Harnesskindclaudecode4Inputs) => LocalizedString} */ () => {
|
|
6101
|
+
return /** @type {LocalizedString} */ (`Claude Code (local CLI)`)
|
|
6102
|
+
};
|
|
6103
|
+
|
|
6104
|
+
export const agents_agentform_harnesskindcodex3 = /** @type {(inputs: Agents_Agentform_Harnesskindcodex3Inputs) => LocalizedString} */ () => {
|
|
6105
|
+
return /** @type {LocalizedString} */ (`Codex (local CLI)`)
|
|
6106
|
+
};
|
|
6107
|
+
|
|
6108
|
+
export const agents_agentform_harnesskindhint3 = /** @type {(inputs: Agents_Agentform_Harnesskindhint3Inputs) => LocalizedString} */ () => {
|
|
6109
|
+
return /** @type {LocalizedString} */ (`On desktop, run via a local ACP CLI (claude-code / codex / opencode); ignored on web, which uses the cloud model`)
|
|
6110
|
+
};
|
|
6111
|
+
|
|
6112
|
+
export const agents_agentform_harnesskindlabel3 = /** @type {(inputs: Agents_Agentform_Harnesskindlabel3Inputs) => LocalizedString} */ () => {
|
|
6113
|
+
return /** @type {LocalizedString} */ (`Execution channel`)
|
|
6114
|
+
};
|
|
6115
|
+
|
|
6116
|
+
export const agents_agentform_harnesskindnormal3 = /** @type {(inputs: Agents_Agentform_Harnesskindnormal3Inputs) => LocalizedString} */ () => {
|
|
6117
|
+
return /** @type {LocalizedString} */ (`Normal chat (cloud model)`)
|
|
6118
|
+
};
|
|
6119
|
+
|
|
6120
|
+
export const agents_agentform_harnesskindopendcode3 = /** @type {(inputs: Agents_Agentform_Harnesskindopendcode3Inputs) => LocalizedString} */ () => {
|
|
6121
|
+
return /** @type {LocalizedString} */ (`OpenCode (local CLI)`)
|
|
6122
|
+
};
|
|
6123
|
+
|
|
6089
6124
|
export const agents_agentform_invalid1 = /** @type {(inputs: Agents_Agentform_Invalid1Inputs) => LocalizedString} */ () => {
|
|
6090
6125
|
return /** @type {LocalizedString} */ (`Please check the form fields`)
|
|
6091
6126
|
};
|
|
@@ -73,6 +73,13 @@
|
|
|
73
73
|
/** @typedef {{}} Agents_Agentform_Greetinglabel2Inputs */
|
|
74
74
|
/** @typedef {{}} Agents_Agentform_Greetingoptional2Inputs */
|
|
75
75
|
/** @typedef {{}} Agents_Agentform_Greetingplaceholder2Inputs */
|
|
76
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindacp3Inputs */
|
|
77
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindclaudecode4Inputs */
|
|
78
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindcodex3Inputs */
|
|
79
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindhint3Inputs */
|
|
80
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindlabel3Inputs */
|
|
81
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindnormal3Inputs */
|
|
82
|
+
/** @typedef {{}} Agents_Agentform_Harnesskindopendcode3Inputs */
|
|
76
83
|
/** @typedef {{}} Agents_Agentform_Invalid1Inputs */
|
|
77
84
|
/** @typedef {{}} Agents_Agentform_Knowledgebaseshint3Inputs */
|
|
78
85
|
/** @typedef {{}} Agents_Agentform_Knowledgebaseslabel3Inputs */
|
|
@@ -6086,6 +6093,34 @@ export const agents_agentform_greetingplaceholder2 = /** @type {(inputs: Agents_
|
|
|
6086
6093
|
return /** @type {LocalizedString} */ (`智能体的第一句话`)
|
|
6087
6094
|
};
|
|
6088
6095
|
|
|
6096
|
+
export const agents_agentform_harnesskindacp3 = /** @type {(inputs: Agents_Agentform_Harnesskindacp3Inputs) => LocalizedString} */ () => {
|
|
6097
|
+
return /** @type {LocalizedString} */ (`ACP(本地 CLI 目录)`)
|
|
6098
|
+
};
|
|
6099
|
+
|
|
6100
|
+
export const agents_agentform_harnesskindclaudecode4 = /** @type {(inputs: Agents_Agentform_Harnesskindclaudecode4Inputs) => LocalizedString} */ () => {
|
|
6101
|
+
return /** @type {LocalizedString} */ (`Claude Code(本地 CLI)`)
|
|
6102
|
+
};
|
|
6103
|
+
|
|
6104
|
+
export const agents_agentform_harnesskindcodex3 = /** @type {(inputs: Agents_Agentform_Harnesskindcodex3Inputs) => LocalizedString} */ () => {
|
|
6105
|
+
return /** @type {LocalizedString} */ (`Codex(本地 CLI)`)
|
|
6106
|
+
};
|
|
6107
|
+
|
|
6108
|
+
export const agents_agentform_harnesskindhint3 = /** @type {(inputs: Agents_Agentform_Harnesskindhint3Inputs) => LocalizedString} */ () => {
|
|
6109
|
+
return /** @type {LocalizedString} */ (`桌面端可选本地 ACP CLI(claude-code / codex / opencode 等)执行;网页端忽略此设置走云模型`)
|
|
6110
|
+
};
|
|
6111
|
+
|
|
6112
|
+
export const agents_agentform_harnesskindlabel3 = /** @type {(inputs: Agents_Agentform_Harnesskindlabel3Inputs) => LocalizedString} */ () => {
|
|
6113
|
+
return /** @type {LocalizedString} */ (`执行通道`)
|
|
6114
|
+
};
|
|
6115
|
+
|
|
6116
|
+
export const agents_agentform_harnesskindnormal3 = /** @type {(inputs: Agents_Agentform_Harnesskindnormal3Inputs) => LocalizedString} */ () => {
|
|
6117
|
+
return /** @type {LocalizedString} */ (`普通对话(云模型)`)
|
|
6118
|
+
};
|
|
6119
|
+
|
|
6120
|
+
export const agents_agentform_harnesskindopendcode3 = /** @type {(inputs: Agents_Agentform_Harnesskindopendcode3Inputs) => LocalizedString} */ () => {
|
|
6121
|
+
return /** @type {LocalizedString} */ (`OpenCode(本地 CLI)`)
|
|
6122
|
+
};
|
|
6123
|
+
|
|
6089
6124
|
export const agents_agentform_invalid1 = /** @type {(inputs: Agents_Agentform_Invalid1Inputs) => LocalizedString} */ () => {
|
|
6090
6125
|
return /** @type {LocalizedString} */ (`请检查表单填写`)
|
|
6091
6126
|
};
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { createFileRoute } from '@tanstack/react-router'
|
|
16
16
|
|
|
17
17
|
import { isHarnessHostEnabled } from '@/server/harness/gate.server'
|
|
18
|
+
import { runWithIdentity } from '@/server/agents/context.server'
|
|
18
19
|
|
|
19
20
|
/** POST control 中需要限流的 op(对话类输入;其余 op 与 GET 不限流)。 */
|
|
20
21
|
const RATE_LIMITED_OPS = new Set(['prompt', 'steer', 'followUp'])
|
|
@@ -57,24 +58,31 @@ async function handleHarnessRequest(request: Request): Promise<Response> {
|
|
|
57
58
|
|
|
58
59
|
const url = new URL(request.url)
|
|
59
60
|
const isControl = url.pathname.endsWith('/control')
|
|
61
|
+
|
|
62
|
+
// access 层同源会话(client context 不可信,P0-2)。两个用途:①POST control
|
|
63
|
+
// 对话类 op 的限流身份;②把整个 handler 包进 runWithIdentity——业务 Agent 注册表
|
|
64
|
+
// 桥接(D12 / M6 harness 侧)后,detached 回合里的业务 subagent(toDefinedAgent)
|
|
65
|
+
// 靠 AsyncLocalStorage 取调用者身份。harness 回合虽脱离 HTTP 请求(session.send →
|
|
66
|
+
// enqueueTurn → drain → runTurn),但 drain 是纯微任务链(无 setTimeout),ALS 随
|
|
67
|
+
// 异步链传播:在此处建立身份,drain→runTurn→subagent run 全程可读(实测语义依赖,
|
|
68
|
+
// 见 runtime-subagents.test.ts 的 detached 用例)。取不到会话(未登录)不包 ALS,
|
|
69
|
+
// subagent 遇无身份按既有 fail-closed 抛 AgentGateError。
|
|
70
|
+
const session = await getCurrentSession(request)
|
|
71
|
+
const userId = session?.user?.id
|
|
72
|
+
|
|
60
73
|
if (request.method === 'POST' && isControl) {
|
|
61
74
|
const op = await readControlOp(request)
|
|
62
|
-
if (op && RATE_LIMITED_OPS.has(op)) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return new Response(
|
|
72
|
-
JSON.stringify({ error: 'rate_limited', retryAfterMs: err.retryAfterMs }),
|
|
73
|
-
{ status: 429, headers: { 'content-type': 'application/json', 'retry-after': String(Math.ceil(err.retryAfterMs / 1000)) } },
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
throw err
|
|
75
|
+
if (op && RATE_LIMITED_OPS.has(op) && userId) {
|
|
76
|
+
try {
|
|
77
|
+
await checkAiRateLimit(userId, 'chat')
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err instanceof RateLimitExceededError) {
|
|
80
|
+
return new Response(
|
|
81
|
+
JSON.stringify({ error: 'rate_limited', retryAfterMs: err.retryAfterMs }),
|
|
82
|
+
{ status: 429, headers: { 'content-type': 'application/json', 'retry-after': String(Math.ceil(err.retryAfterMs / 1000)) } },
|
|
83
|
+
)
|
|
77
84
|
}
|
|
85
|
+
throw err
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
}
|
|
@@ -85,7 +93,10 @@ async function handleHarnessRequest(request: Request): Promise<Response> {
|
|
|
85
93
|
// (桌面真机 Bug#1 根因,详见 harnessMediaSecret 注释)。
|
|
86
94
|
const { host, harness } = await getHarnessRuntime()
|
|
87
95
|
const handler = createHarnessHandler({ host, harness, media: { secret: harnessMediaSecret() } })
|
|
88
|
-
|
|
96
|
+
// ALS 身份包裹:见上方 session 注释。整条 handler 异步链(含 detached 回合的
|
|
97
|
+
// 业务 subagent)在 runWithIdentity 回调内启动,继承身份 store。
|
|
98
|
+
if (!userId) return await handler(request)
|
|
99
|
+
return await runWithIdentity({ userId }, () => handler(request))
|
|
89
100
|
} catch (error) {
|
|
90
101
|
console.error('[harness] 请求处理失败(host 装配或 handler 异常):', error)
|
|
91
102
|
return new Response(
|
|
@@ -223,3 +223,53 @@ describe("ALS 身份传播实证(裁决 6,M6 可行性技术前提)", () =
|
|
|
223
223
|
if (runError) throw runError
|
|
224
224
|
})
|
|
225
225
|
})
|
|
226
|
+
|
|
227
|
+
describe("detached 回合 ALS 传播(D12 harness 桥接技术前提)", () => {
|
|
228
|
+
// harness 回合脱离 HTTP 请求:session.send → enqueueTurn → drain() →
|
|
229
|
+
// runTurn() 是 fire-and-forget(请求不等回合跑完即返回 Response)。本用例复刻
|
|
230
|
+
// 该 detached 形态——在 runWithIdentity 回调内启动一条不被 await 的异步链(用
|
|
231
|
+
// 多级 await 模拟 drain→runTurn→subagent 的微任务深度),断言链内
|
|
232
|
+
// getIdentityFromContext() 仍可读到身份。这正是 /api/harness 路由把 handler 包进
|
|
233
|
+
// runWithIdentity 后,业务 subagent(toDefinedAgent)能取到身份的依据。
|
|
234
|
+
// AsyncLocalStorage 语义:store 随「回调内启动的异步链」传播(微任务 await 保持),
|
|
235
|
+
// 不随请求生命周期回收——故回调返回后已启动的链仍持有 store。
|
|
236
|
+
it("runWithIdentity 内启动的 detached 异步链(多级 await 后)仍读到身份", async () => {
|
|
237
|
+
const seen: Array<string | undefined> = []
|
|
238
|
+
let releaseDetached: () => void = () => {}
|
|
239
|
+
const detachedDone = new Promise<void>((resolve) => { releaseDetached = resolve })
|
|
240
|
+
|
|
241
|
+
// 模拟 harness 的 detached 回合:不 await,链内多级 await 后读 ALS
|
|
242
|
+
const detachedTurn = async () => {
|
|
243
|
+
await Promise.resolve() // 模拟 drain 微任务
|
|
244
|
+
await Promise.resolve() // 模拟 runTurn 首个 await
|
|
245
|
+
await Promise.resolve() // 模拟 subagent spawn
|
|
246
|
+
seen.push(getIdentityFromContext()?.userId) // toDefinedAgent.run 的断言点
|
|
247
|
+
releaseDetached()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
await runWithIdentity({ userId: USER_ID }, async () => {
|
|
251
|
+
void detachedTurn() // fire-and-forget:请求不等回合(对齐 session.send)
|
|
252
|
+
return "response-immediately" // 请求先于回合结束返回
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
// 回调已返回(请求已结束),detached 链仍在跑——等它完成并断言身份已传播
|
|
256
|
+
await detachedDone
|
|
257
|
+
expect(seen).toEqual([USER_ID])
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it("ALS 外启动的 detached 链读不到身份(对照:证明传播来自 runWithIdentity 而非全局)", async () => {
|
|
261
|
+
const seen: Array<string | undefined> = []
|
|
262
|
+
let release: () => void = () => {}
|
|
263
|
+
const done = new Promise<void>((resolve) => { release = resolve })
|
|
264
|
+
|
|
265
|
+
// 不在 runWithIdentity 内启动——模拟未登录(路由不包 ALS)路径
|
|
266
|
+
const detachedTurn = async () => {
|
|
267
|
+
await Promise.resolve()
|
|
268
|
+
seen.push(getIdentityFromContext()?.userId)
|
|
269
|
+
release()
|
|
270
|
+
}
|
|
271
|
+
void detachedTurn()
|
|
272
|
+
await done
|
|
273
|
+
expect(seen).toEqual([undefined])
|
|
274
|
+
})
|
|
275
|
+
})
|
|
@@ -70,6 +70,8 @@ export interface DynamicUserAgentDef extends AnyAgentDef {
|
|
|
70
70
|
model?: string
|
|
71
71
|
allowedTools?: string[]
|
|
72
72
|
knowledgeBaseIds?: string[]
|
|
73
|
+
/** 非 null = 桌面走 ACP 通道执行(设计 §13.6);null/缺省 = 普通对话 agent。 */
|
|
74
|
+
harnessKind?: string | null
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
const ALL_AGENTS: ReadonlyArray<AnyAgentDef> = [
|
|
@@ -143,6 +145,7 @@ export async function getAgentAsync(name: string): Promise<AnyAgentDef | undefin
|
|
|
143
145
|
temperature: true,
|
|
144
146
|
allowedTools: true,
|
|
145
147
|
knowledgeBaseIds: true,
|
|
148
|
+
harnessKind: true,
|
|
146
149
|
},
|
|
147
150
|
})
|
|
148
151
|
if (!row) return undefined
|
|
@@ -173,6 +176,7 @@ function synthesizeUserAgent(row: {
|
|
|
173
176
|
temperature: number | null
|
|
174
177
|
allowedTools: unknown
|
|
175
178
|
knowledgeBaseIds: unknown
|
|
179
|
+
harnessKind: string | null
|
|
176
180
|
}): DynamicUserAgentDef {
|
|
177
181
|
const name = `${USER_AGENT_PREFIX}${row.id}`
|
|
178
182
|
const allowedTools = toAgentToolKeyList(row.allowedTools)
|
|
@@ -199,6 +203,10 @@ function synthesizeUserAgent(row: {
|
|
|
199
203
|
...(row.temperature != null ? { temperature: row.temperature } : {}),
|
|
200
204
|
...(allowedTools.length > 0 ? { allowedTools } : {}),
|
|
201
205
|
...(knowledgeBaseIds.length > 0 ? { knowledgeBaseIds } : {}),
|
|
206
|
+
// harnessKind(设计 §13.6 / T-M7):非 null = 桌面走 ACP 通道执行。registry
|
|
207
|
+
// 路仅携带该字段供消费方(harness 子代理面 / 模型调度)分支;聊天路的
|
|
208
|
+
// harnessKind→ACP 路由走 resolveOverrides(runs/resolve-overrides.ts),不经此处。
|
|
209
|
+
...(row.harnessKind ? { harnessKind: row.harnessKind } : {}),
|
|
202
210
|
// 门控(T-M8 裁决 5):per-user 限流 + 缺 key fail-closed。动态 agent 是
|
|
203
211
|
// 对话类 LLM 调用,阈值对齐 chat(userAgentChat 端点)。feature/resource 留空
|
|
204
212
|
// ——动态 agent 是用户自有对话能力,不绑定商业 feature 或平台资源配额。
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// harnessKind → 桌面 ACP 路由单测(设计 §13.6 / T-M7):
|
|
6
|
+
// ① resolveHarnessKindLocalAgentId 四值映射(claude-code/codex/opencode 确定性 →
|
|
7
|
+
// acp:<kind>;泛型 acp 读 model 具体 catalog id,缺失回落 acp:claude-code)
|
|
8
|
+
// ② resolveOverrides 携带 harnessKind(聊天路据此分支到 resolveLocalAgentRoute)
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
11
|
+
|
|
12
|
+
const mocks = vi.hoisted(() => ({
|
|
13
|
+
findFirst: vi.fn(),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('@allbluecn/database', () => ({
|
|
16
|
+
prisma: { userAgent: { findFirst: mocks.findFirst } },
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
import { resolveHarnessKindLocalAgentId } from '@/server/ai-gateway/chat-handler'
|
|
20
|
+
import { resolveOverrides } from '@/server/ai-gateway/runs/resolve-overrides'
|
|
21
|
+
|
|
22
|
+
describe('resolveHarnessKindLocalAgentId 四值映射(设计 §13.6 桌面四值全走 ACP)', () => {
|
|
23
|
+
it('claude-code / codex / opencode 确定性映射 acp:<kind>', () => {
|
|
24
|
+
expect(resolveHarnessKindLocalAgentId('claude-code')).toBe('acp:claude-code')
|
|
25
|
+
expect(resolveHarnessKindLocalAgentId('codex')).toBe('acp:codex')
|
|
26
|
+
expect(resolveHarnessKindLocalAgentId('opencode')).toBe('acp:opencode')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('泛型 acp:model 存具体 catalog id 时用它(补 acp: 前缀)', () => {
|
|
30
|
+
expect(resolveHarnessKindLocalAgentId('acp', 'opencode')).toBe('acp:opencode')
|
|
31
|
+
expect(resolveHarnessKindLocalAgentId('acp', 'acp:goose')).toBe('acp:goose')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('泛型 acp:model 缺失回落 acp:claude-code(首个高可用 CLI,避免静默失败)', () => {
|
|
35
|
+
expect(resolveHarnessKindLocalAgentId('acp')).toBe('acp:claude-code')
|
|
36
|
+
expect(resolveHarnessKindLocalAgentId('acp', '')).toBe('acp:claude-code')
|
|
37
|
+
expect(resolveHarnessKindLocalAgentId('acp', ' ')).toBe('acp:claude-code')
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('resolveOverrides 携带 harnessKind(聊天路 ACP 分支依据)', () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
vi.clearAllMocks()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('UserAgent.harnessKind 非 null 时透传到 overrides.agent.harnessKind', async () => {
|
|
47
|
+
mocks.findFirst.mockResolvedValue({
|
|
48
|
+
id: 'ua-1',
|
|
49
|
+
systemPrompt: '你是代码助手',
|
|
50
|
+
model: null,
|
|
51
|
+
temperature: null,
|
|
52
|
+
allowedTools: [],
|
|
53
|
+
knowledgeBaseIds: [],
|
|
54
|
+
harnessKind: 'claude-code',
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const overrides = await resolveOverrides('u1', 'ua-1')
|
|
58
|
+
expect(overrides?.agent?.harnessKind).toBe('claude-code')
|
|
59
|
+
// persona 仍正常携带(harnessKind 不挤掉其余字段)
|
|
60
|
+
expect(overrides?.agent?.persona).toBe('你是代码助手')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('harnessKind 为 null(普通对话 agent)时不携带该字段', async () => {
|
|
64
|
+
mocks.findFirst.mockResolvedValue({
|
|
65
|
+
id: 'ua-2',
|
|
66
|
+
systemPrompt: '普通 agent',
|
|
67
|
+
model: 'gpt-x',
|
|
68
|
+
temperature: 0.7,
|
|
69
|
+
allowedTools: [],
|
|
70
|
+
knowledgeBaseIds: [],
|
|
71
|
+
harnessKind: null,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const overrides = await resolveOverrides('u1', 'ua-2')
|
|
75
|
+
expect(overrides?.agent?.harnessKind).toBeUndefined()
|
|
76
|
+
expect(overrides?.agent?.model).toBe('gpt-x')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('agentId 缺失时返回 undefined(不查库)', async () => {
|
|
80
|
+
const overrides = await resolveOverrides('u1', null)
|
|
81
|
+
expect(overrides).toBeUndefined()
|
|
82
|
+
expect(mocks.findFirst).not.toHaveBeenCalled()
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { type StreamChunk } from "@tanstack/ai"
|
|
19
19
|
import { resolveUnifiedAiRoute } from "./unified-router"
|
|
20
|
+
import { isHarnessKind, harnessKindToLocalAgentId } from "./runs/user-agent"
|
|
21
|
+
import { isDesktopServer } from "@/server/desktop-guest"
|
|
20
22
|
import {
|
|
21
23
|
resolveAiConfigForModel,
|
|
22
24
|
resolveDefaultProviderConfig,
|
|
@@ -43,6 +45,26 @@ import { hasBlobRefImageParts } from "./middlewares/attachment-deref"
|
|
|
43
45
|
import { resolveSearchableKbIds } from "@/server/knowledge/search-scope"
|
|
44
46
|
import { prisma } from "@allbluecn/database"
|
|
45
47
|
|
|
48
|
+
/**
|
|
49
|
+
* harnessKind → 桌面 ACP catalog agent id(`acp:<catalogId>`,LocalAgentAdapter
|
|
50
|
+
* 消费)。设计 §13.6 / T-M7「桌面四值全走 ACP 通道」:
|
|
51
|
+
* - claude-code / codex / opencode:确定性映射 `acp:<kind>`(Pro 仓 acp-catalog
|
|
52
|
+
* `KNOWN_ACP_AGENTS` 已含这三个 CLI,桌面后端经 ACP 子进程 spawn 每一个)。
|
|
53
|
+
* - 泛型 `acp`:catalog 无「泛型 acp」条目,需具体 CLI——决策点 1:UI 选 `acp` 时
|
|
54
|
+
* 把用户选的具体 catalog id 落进 UserAgent.model,执行时读它;缺失则回落
|
|
55
|
+
* `acp:claude-code`(首个高可用 CLI,避免静默失败)。
|
|
56
|
+
*/
|
|
57
|
+
export function resolveHarnessKindLocalAgentId(
|
|
58
|
+
harnessKind: string,
|
|
59
|
+
fallbackModel?: string,
|
|
60
|
+
): string {
|
|
61
|
+
if (harnessKind === "acp") {
|
|
62
|
+
const specific = fallbackModel?.trim()
|
|
63
|
+
return specific ? (specific.startsWith("acp:") ? specific : `acp:${specific}`) : "acp:claude-code"
|
|
64
|
+
}
|
|
65
|
+
return harnessKindToLocalAgentId(harnessKind as never)
|
|
66
|
+
}
|
|
67
|
+
|
|
46
68
|
// 导出供测试直接断言合并语义(纯函数,无服务端依赖;调用点 :428 以
|
|
47
69
|
// `{...body, ...mergeChatOverrides(...)}` 序展开——overrides 最后落笔)。
|
|
48
70
|
export function mergeChatOverrides(overrides?: ChatRequestOverrides): Partial<z.infer<typeof chatBodySchema>> {
|
|
@@ -213,7 +235,7 @@ export function filterWebSearchSections(
|
|
|
213
235
|
}
|
|
214
236
|
|
|
215
237
|
export interface ChatRequestOverrides {
|
|
216
|
-
agent?: { persona: string; knowledgeBaseIds?: string[]; allowedTools?: AgentToolKey[]; temperature?: number; model?: string }
|
|
238
|
+
agent?: { persona: string; knowledgeBaseIds?: string[]; allowedTools?: AgentToolKey[]; temperature?: number; model?: string; harnessKind?: string }
|
|
217
239
|
allowedTools?: AgentToolKey[]
|
|
218
240
|
knowledgeBaseIds?: string[]
|
|
219
241
|
temperature?: number
|
|
@@ -450,11 +472,24 @@ export async function* handleChatRequest(
|
|
|
450
472
|
// 空字符串已在 schema 被 min(1) 拒绝,这里只需处理 undefined。
|
|
451
473
|
const effectiveThreadId = threadId ?? crypto.randomUUID()
|
|
452
474
|
|
|
475
|
+
// harnessKind(设计 §13.6 / T-M7):用户自定义 agent 带 harnessKind = 桌面走 ACP
|
|
476
|
+
// 通道执行(而非云 LLM)。映射 harnessKind → 本地 ACP catalog agent id,复用既有
|
|
477
|
+
// engine=local 通道(校验/线程持久化/路由全套)。claude-code/codex/opencode 确定性
|
|
478
|
+
// 映射 acp:<kind>;泛型 acp 由 UI 落具体 catalog id 进 UserAgent.model(见
|
|
479
|
+
// resolveHarnessKindLocalAgentId)。cwd 仍取 body.cwd(工作台本地引擎带授权目录)。
|
|
480
|
+
// 非桌面(web/saas 无 ACP 运行时)优雅降级:忽略 harnessKind 走云路径。
|
|
481
|
+
const overrideHarnessKind = options?.overrides?.agent?.harnessKind
|
|
482
|
+
const harnessKindActive = isHarnessKind(overrideHarnessKind) && isDesktopServer()
|
|
483
|
+
const effectiveEngine = harnessKindActive ? "local" : engine
|
|
484
|
+
const effectiveLocalAgentId = harnessKindActive
|
|
485
|
+
? resolveHarnessKindLocalAgentId(overrideHarnessKind!, model)
|
|
486
|
+
: localAgentId
|
|
487
|
+
|
|
453
488
|
// 桌面本地 Agent(ACP):线程级引擎与 cwd 是持久化语义的一部分——
|
|
454
489
|
// - 既有的 cloud 线程不允许中途改成本地(会让历史消息与本地会话错位);
|
|
455
490
|
// - 线程必须先落 engine=local 再跑,本地 Agent 侧以 threadId 作为 session id 续接。
|
|
456
491
|
// 鉴权边界仍在桌面壳:cwd 必须精确命中 workspaces.json 授权清单。
|
|
457
|
-
if (
|
|
492
|
+
if (effectiveEngine === "local") {
|
|
458
493
|
if (attachments.length > 0) {
|
|
459
494
|
throw new Error("本地 Agent 不支持附件:请移除附件或切换到云端引擎")
|
|
460
495
|
}
|
|
@@ -481,15 +516,15 @@ export async function* handleChatRequest(
|
|
|
481
516
|
userId: session.user.id,
|
|
482
517
|
engine: "local",
|
|
483
518
|
localCwd: cwd ?? null,
|
|
484
|
-
localAgentId:
|
|
519
|
+
localAgentId: effectiveLocalAgentId ?? null,
|
|
485
520
|
},
|
|
486
521
|
})
|
|
487
|
-
} else if (
|
|
522
|
+
} else if (effectiveLocalAgentId && existing.localAgentId !== effectiveLocalAgentId) {
|
|
488
523
|
// 同一线程固定本地 agent(UI 在已有消息时禁用切换);首次显式选择时落库——
|
|
489
524
|
// 服务端兜底更新只影响续接的 agent 会话映射。
|
|
490
525
|
await prisma.chatThread.update({
|
|
491
526
|
where: { id: effectiveThreadId },
|
|
492
|
-
data: { localAgentId },
|
|
527
|
+
data: { localAgentId: effectiveLocalAgentId },
|
|
493
528
|
})
|
|
494
529
|
} else if (cwd && existing.localCwd !== cwd) {
|
|
495
530
|
// 同一线程固定工作目录(UI 在已有消息时禁用切换);服务端兜底更新
|
|
@@ -508,7 +543,7 @@ export async function* handleChatRequest(
|
|
|
508
543
|
parentRunId,
|
|
509
544
|
engine: "local",
|
|
510
545
|
localCwd: cwd,
|
|
511
|
-
localAgentId,
|
|
546
|
+
localAgentId: effectiveLocalAgentId,
|
|
512
547
|
localAgentModel,
|
|
513
548
|
aiSourceMode: session.user.aiSourceMode ?? null,
|
|
514
549
|
},
|
|
@@ -46,6 +46,9 @@ export async function resolveOverrides(
|
|
|
46
46
|
// 经 mergeChatOverrides 合并进 body.model(findUserAgent 的
|
|
47
47
|
// USER_AGENT_SELECT 已选 model,无额外查询成本)。
|
|
48
48
|
...(agent.model && { model: agent.model }),
|
|
49
|
+
// harnessKind(设计 §13.6 / T-M7):非 null = 桌面走 ACP 通道执行。聊天路
|
|
50
|
+
// 由 chat-handler 据此分支到 resolveLocalAgentRoute(桌面 ACP),而非云 LLM。
|
|
51
|
+
...(agent.harnessKind && { harnessKind: agent.harnessKind }),
|
|
49
52
|
},
|
|
50
53
|
};
|
|
51
54
|
}
|
|
@@ -18,6 +18,22 @@
|
|
|
18
18
|
import { prisma } from "@allbluecn/database"
|
|
19
19
|
import { isAgentToolKey, type AgentToolKey } from "../tools/select"
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* harnessKind 合法值(UserAgent.harnessKind,schema.prisma)。null = 普通对话
|
|
23
|
+
* agent(走云 LLM);非 null = 桌面走 ACP 通道(设计 §13.6 / T-M7)。
|
|
24
|
+
*/
|
|
25
|
+
export const HARNESS_KINDS = ["claude-code", "codex", "acp", "opencode"] as const
|
|
26
|
+
export type HarnessKind = (typeof HARNESS_KINDS)[number]
|
|
27
|
+
|
|
28
|
+
/** harnessKind → 桌面 ACP catalog agent id(LocalAgentAdapter 消费 `acp:<id>`)。 */
|
|
29
|
+
export function harnessKindToLocalAgentId(kind: HarnessKind): string {
|
|
30
|
+
return `acp:${kind}`
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isHarnessKind(v: unknown): v is HarnessKind {
|
|
34
|
+
return typeof v === "string" && (HARNESS_KINDS as readonly string[]).includes(v)
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
/**
|
|
22
38
|
* UserAgent 查询与 Json 字段过滤的单一来源
|
|
23
39
|
* (审计 2026-10-25 A3x-2 🔵:runs/agent-runtime.ts 与 runs/resolve-overrides.ts
|
|
@@ -31,6 +47,7 @@ export const USER_AGENT_SELECT = {
|
|
|
31
47
|
temperature: true,
|
|
32
48
|
allowedTools: true,
|
|
33
49
|
knowledgeBaseIds: true,
|
|
50
|
+
harnessKind: true,
|
|
34
51
|
} as const
|
|
35
52
|
|
|
36
53
|
export type UserAgentRow = {
|
|
@@ -40,6 +57,7 @@ export type UserAgentRow = {
|
|
|
40
57
|
temperature: number | null
|
|
41
58
|
allowedTools: unknown
|
|
42
59
|
knowledgeBaseIds: unknown
|
|
60
|
+
harnessKind: string | null
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
/** 过滤:非数组降级空数组;仅保留合法 tool key。 */
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// 业务 Agent 注册表桥接进 harness host(D12 互连 / M6 harness 侧):
|
|
6
|
+
// buildHarnessDefinition() 挂 subagents = chatSubagentsBag()(对话调度子集),
|
|
7
|
+
// 工作台主模型可按名委派只读业务 agent。断言:①subagents 已挂载;②agent 名集合
|
|
8
|
+
// 与 M6 对话调度子集一致(17 个只读);③含写副作用的 agent 不挂(knowledge.index /
|
|
9
|
+
// media.*)。身份传播由 /api/harness 路由的 runWithIdentity 保证(见
|
|
10
|
+
// runtime-subagents.test.ts 的 detached 用例),此处只验证装配。
|
|
11
|
+
|
|
12
|
+
import { describe, expect, it } from 'vitest'
|
|
13
|
+
|
|
14
|
+
import { buildHarnessDefinition } from '../define.server'
|
|
15
|
+
import { chatSubagentsBag } from '@/server/ai-gateway/chat-subagents.server'
|
|
16
|
+
|
|
17
|
+
/** M6 对话调度子集(chat-subagents.server.ts CHAT_SUBAGENT_NAMES,17 个只读 agent)。 */
|
|
18
|
+
const EXPECTED_SUBAGENT_NAMES = [
|
|
19
|
+
'translation.run',
|
|
20
|
+
'label.suggest',
|
|
21
|
+
'testcase.triage',
|
|
22
|
+
'testcase.exec',
|
|
23
|
+
'testcase.generate',
|
|
24
|
+
'bug.reproduce',
|
|
25
|
+
'task.run',
|
|
26
|
+
'design.annotation',
|
|
27
|
+
'design.prototype',
|
|
28
|
+
'design.prototype.stream',
|
|
29
|
+
'story.generate',
|
|
30
|
+
'story.split',
|
|
31
|
+
'story.polish',
|
|
32
|
+
'tiptap.improve',
|
|
33
|
+
'tiptap.generate',
|
|
34
|
+
'knowledge.search',
|
|
35
|
+
'knowledge.semanticSearch',
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/** 本批显式不挂载的写副作用 agent(留显式开启机制,M7/后续)。 */
|
|
39
|
+
const EXCLUDED_WRITE_AGENTS = [
|
|
40
|
+
'knowledge.index',
|
|
41
|
+
'media.image',
|
|
42
|
+
'media.video',
|
|
43
|
+
'media.speech',
|
|
44
|
+
'media.transcription',
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
function mountedSubagentNames(): string[] {
|
|
48
|
+
const harness = buildHarnessDefinition()
|
|
49
|
+
const subagents = (harness as { subagents?: { agents?: ReadonlyArray<{ name: string }> } })
|
|
50
|
+
.subagents
|
|
51
|
+
expect(subagents, 'buildHarnessDefinition 应挂载 subagents(D12 业务注册表桥接)').toBeTruthy()
|
|
52
|
+
return (subagents?.agents ?? []).map((a) => a.name)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('harness host 挂业务注册表 subagents(D12 / M6 harness 侧)', () => {
|
|
56
|
+
it('buildHarnessDefinition 挂载 subagents,agent 名集合 = M6 对话调度子集', () => {
|
|
57
|
+
const names = mountedSubagentNames()
|
|
58
|
+
expect([...names].sort()).toEqual([...EXPECTED_SUBAGENT_NAMES].sort())
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('与 chatSubagentsBag() 同源(复用 M6 子集,不重复定义)', () => {
|
|
62
|
+
const bagNames = chatSubagentsBag().agents.map((a) => a.name)
|
|
63
|
+
expect(mountedSubagentNames()).toEqual(bagNames)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('含写副作用的 agent 不挂载(knowledge.index / media.*)', () => {
|
|
67
|
+
const names = new Set(mountedSubagentNames())
|
|
68
|
+
for (const writeAgent of EXCLUDED_WRITE_AGENTS) {
|
|
69
|
+
expect(names.has(writeAgent), `${writeAgent} 不应挂载(写副作用,留显式开启)`).toBe(false)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('subagents 带 strategy exclusive(工具模式,主模型 function-calling 自主选择)', () => {
|
|
74
|
+
const harness = buildHarnessDefinition()
|
|
75
|
+
const strategy = (
|
|
76
|
+
harness as { subagents?: { strategy?: string } }
|
|
77
|
+
).subagents?.strategy
|
|
78
|
+
expect(strategy).toBe('exclusive')
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -38,6 +38,7 @@ import { workspaceTools, snapshots } from '@tanstack/ai-harness/plugins/coding'
|
|
|
38
38
|
import path from 'node:path'
|
|
39
39
|
import { createAiOutputGuardMiddleware } from '@/server/ai-gateway/ai-output-guard'
|
|
40
40
|
import { createToolBudgetMiddleware } from '@/server/ai-gateway/middlewares/tool-budget'
|
|
41
|
+
import { chatSubagentsBag } from '@/server/ai-gateway/chat-subagents.server'
|
|
41
42
|
import { createOpenRouterText } from '@tanstack/ai-openrouter'
|
|
42
43
|
import { buildHarnessCompaction } from '@/server/harness/compaction.server'
|
|
43
44
|
import { buildModelCatalog } from '@/server/harness/model-catalog.server'
|
|
@@ -136,6 +137,25 @@ function harnessAgentAdapter(model: string) {
|
|
|
136
137
|
)
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
/**
|
|
141
|
+
* harnessKind 用户 agent → agents() 插件 profile 的**接缝**(设计 §13.6 / T3.5 /
|
|
142
|
+
* T-M7「可在 harness 中被主模型当子代理调用」)。
|
|
143
|
+
*
|
|
144
|
+
* ⚠ 当前返回空集——in-harness ACP 子代理的**端到端执行留 follow-up**(决策点 2):
|
|
145
|
+
* ACP 是子进程通道(LocalAgentAdapter),而 harness host 跑云模型 + 文件工具;把
|
|
146
|
+
* ACP agent 桥成 harness 内可调度的 DefinedAgent/AgentProfile 需要一层「ACP-backed
|
|
147
|
+
* adapter」映射,且与 Phase 4 云端 harness 强耦合,架构未定。此处先钉住扩展点:
|
|
148
|
+
* 后续实现时,查当前用户 harnessKind 非 null 的 UserAgent,逐个映射成 AgentProfile
|
|
149
|
+
* (name=`user:<id>`、description、system、mode='subagent'),adapter 侧把 profile
|
|
150
|
+
* 路由到 LocalAgentAdapter(而非本文件的 OpenRouter keyedAdapter)。
|
|
151
|
+
*
|
|
152
|
+
* 聊天路(/api/chat)的 harnessKind→ACP 执行**已落地**(chat-handler
|
|
153
|
+
* resolveHarnessKindLocalAgentId → resolveLocalAgentRoute),不依赖本接缝。
|
|
154
|
+
*/
|
|
155
|
+
function harnessKindAgentProfiles(): ReadonlyArray<never> {
|
|
156
|
+
return []
|
|
157
|
+
}
|
|
158
|
+
|
|
139
159
|
function harnessPlugins(titleAdapter: AnyTextAdapter | KeyedAdapter<AnyTextAdapter>) {
|
|
140
160
|
return () => [
|
|
141
161
|
// default 'ask':写类/命令逐次审批;mode 由服务端 setPluginSetting 施加(T2.4)
|
|
@@ -145,8 +165,9 @@ function harnessPlugins(titleAdapter: AnyTextAdapter | KeyedAdapter<AnyTextAdapt
|
|
|
145
165
|
// 只读 primary(与 permissions plan 档互补);general/explore 为 subagent(主模型
|
|
146
166
|
// 按名委派)。adapter 把 profile.model 解析成 keyed OpenRouter adapter(per-user
|
|
147
167
|
// key 由 host 经 CredentialStore 解析,§5.6);内置 profile 均未指定 model,adapter
|
|
148
|
-
// 仅为带 model 的自定义 profile
|
|
149
|
-
|
|
168
|
+
// 仅为带 model 的自定义 profile 兜底。`agents` 选项挂 harnessKind 用户 agent
|
|
169
|
+
// profile(harnessKindAgentProfiles,follow-up)。
|
|
170
|
+
agents({ adapter: harnessAgentAdapter, agents: harnessKindAgentProfiles() }),
|
|
150
171
|
// 按线程工作区(T2.4):WorkspaceBinder 查 ChatThread.localCwd(不信客户端 cwd),
|
|
151
172
|
// backend=hostBackend;web 工具注入 guardedFetch(SSRF 唯一入口)+ SearXNG search。
|
|
152
173
|
workspaceTools({
|
|
@@ -199,6 +220,15 @@ export function buildHarnessDefinition(overrides?: {
|
|
|
199
220
|
models: catalog,
|
|
200
221
|
systemPrompts: harnessPrompts(),
|
|
201
222
|
tools: businessTools,
|
|
223
|
+
// 业务 Agent 注册表桥接(D12 互连 / M6 harness 侧):挂对话调度子集(17 个
|
|
224
|
+
// 只读 agent + SubagentLimits),工作台主模型可按名委派任一子 agent。复用 M6
|
|
225
|
+
// 的 chatSubagentsBag(与 /api/chat 主模型同子集同限额,避免两处漂移);身份
|
|
226
|
+
// 经 ALS 传播——/api/harness 路由把 handler 包进 runWithIdentity(见路由文件),
|
|
227
|
+
// detached 回合的 drain→runTurn→subagent run 继承 ALS,toDefinedAgent 读到身份。
|
|
228
|
+
// 含写副作用的 5 个 agent(knowledge.index / media.*)本批不挂(显式开启机制
|
|
229
|
+
// 属产品功能,留后续)。strategy 'exclusive' = 工具模式,与 workspaceTools 等
|
|
230
|
+
// 并列,工具名零冲突。
|
|
231
|
+
subagents: chatSubagentsBag(),
|
|
202
232
|
middleware: harnessMiddleware(),
|
|
203
233
|
agentLoopStrategy: maxIterations(50),
|
|
204
234
|
plugins: harnessPlugins(defaultAdapter),
|
|
@@ -23,6 +23,7 @@ import { z } from "zod"
|
|
|
23
23
|
// AGENT_TOOL_KEYS 在模块顶层(zod schema)被消费,会保留进客户端 split stub——
|
|
24
24
|
// 必须走纯净子路径 tools/select;tools index re-export 含 prisma 的 tools/server.ts
|
|
25
25
|
import { AGENT_TOOL_KEYS } from "@/server/ai-gateway/tools/select"
|
|
26
|
+
import { HARNESS_KINDS } from "@/server/ai-gateway/runs/user-agent"
|
|
26
27
|
import { requireFeature } from "@/server/entitlements"
|
|
27
28
|
import { requireResource } from "@/server/resources"
|
|
28
29
|
|
|
@@ -38,6 +39,10 @@ const agentInputSchema = z.object({
|
|
|
38
39
|
suggestedPrompts: z.array(z.string().max(200)).optional(),
|
|
39
40
|
// server 侧上限对齐前端 agent-form.ts max(50)(裁决 9:此前 server 无上限)
|
|
40
41
|
knowledgeBaseIds: z.array(z.string()).max(50).optional(),
|
|
42
|
+
// harnessKind(设计 §13.6 / T-M7):非 null = 桌面走 ACP 通道执行。null/缺省 =
|
|
43
|
+
// 普通对话 agent(云 LLM)。泛型 `acp` 时具体 CLI 落 model 字段(见 chat-handler
|
|
44
|
+
// resolveHarnessKindLocalAgentId)。
|
|
45
|
+
harnessKind: z.enum(HARNESS_KINDS).nullable().optional(),
|
|
41
46
|
})
|
|
42
47
|
|
|
43
48
|
type AgentRow = {
|
|
@@ -52,6 +57,7 @@ type AgentRow = {
|
|
|
52
57
|
greeting: string | null
|
|
53
58
|
suggestedPrompts: unknown
|
|
54
59
|
knowledgeBaseIds: unknown
|
|
60
|
+
harnessKind: string | null
|
|
55
61
|
isDefault: boolean
|
|
56
62
|
createdAt: Date
|
|
57
63
|
updatedAt: Date
|
|
@@ -70,6 +76,7 @@ function toAgentDTO(a: AgentRow) {
|
|
|
70
76
|
greeting: a.greeting,
|
|
71
77
|
suggestedPrompts: a.suggestedPrompts as string[] | null,
|
|
72
78
|
knowledgeBaseIds: a.knowledgeBaseIds as string[],
|
|
79
|
+
harnessKind: a.harnessKind,
|
|
73
80
|
isDefault: a.isDefault,
|
|
74
81
|
createdAt: a.createdAt,
|
|
75
82
|
updatedAt: a.updatedAt,
|
|
@@ -88,6 +95,7 @@ const AGENT_DTO_SELECT = {
|
|
|
88
95
|
greeting: true,
|
|
89
96
|
suggestedPrompts: true,
|
|
90
97
|
knowledgeBaseIds: true,
|
|
98
|
+
harnessKind: true,
|
|
91
99
|
isDefault: true,
|
|
92
100
|
createdAt: true,
|
|
93
101
|
updatedAt: true,
|
|
@@ -131,6 +139,7 @@ export const createAgentFn = createServerFn({ method: "POST" })
|
|
|
131
139
|
greeting: data.greeting,
|
|
132
140
|
suggestedPrompts: data.suggestedPrompts,
|
|
133
141
|
knowledgeBaseIds: data.knowledgeBaseIds ?? [],
|
|
142
|
+
harnessKind: data.harnessKind ?? null,
|
|
134
143
|
},
|
|
135
144
|
select: AGENT_DTO_SELECT,
|
|
136
145
|
})
|
|
@@ -169,6 +178,7 @@ const agentUpdateSchema = z.object({
|
|
|
169
178
|
suggestedPrompts: z.array(z.string().max(200)).optional(),
|
|
170
179
|
// server 侧上限对齐前端 agent-form.ts max(50)(裁决 9)
|
|
171
180
|
knowledgeBaseIds: z.array(z.string()).max(50).optional(),
|
|
181
|
+
harnessKind: z.enum(HARNESS_KINDS).nullable().optional(),
|
|
172
182
|
})
|
|
173
183
|
|
|
174
184
|
type AgentUpdateInput = z.infer<typeof agentUpdateSchema>
|
|
@@ -184,6 +194,7 @@ const UPDATE_FIELDS = [
|
|
|
184
194
|
"greeting",
|
|
185
195
|
"suggestedPrompts",
|
|
186
196
|
"knowledgeBaseIds",
|
|
197
|
+
"harnessKind",
|
|
187
198
|
] as const
|
|
188
199
|
|
|
189
200
|
function buildAgentUpdatePayload(input: AgentUpdateInput): Record<string, unknown> {
|