fix(headless): dsh run is a direct core front door
This commit is contained in:
6
packages/core/agent-default-model/README.i18n.yaml
Normal file
6
packages/core/agent-default-model/README.i18n.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/core/agent-default-model/README.md
|
||||
README.md: 02bcc9be3adee2293a20b3ae87ddaf4d52e70deb
|
||||
README.zh.md: 807b612bd25e49aa318c13c8c8dc7595a6459080
|
||||
25
packages/core/agent-default-model/README.md
Normal file
25
packages/core/agent-default-model/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# @deepseek-ai/dsh-agent-default-model
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
The deployment default used when a front door creates an Agent that has no session-local model selection. `AgentDefaultModelService` provides `ctx.agentDefaultModel`; direct front doors such as `dsh run` and Host-backed front doors such as ApiProxy read the same service instead of owning parallel provider/model defaults.
|
||||
|
||||
The plugin config requires `{ provider, model }`. That composition entry is the base of the `agent-default-model` Settings section; a mounted settings provider layers the user's choice over it and changes are visible on the next `currentSelection()` read. `reasoningEffort` belongs to the Settings section but deliberately not to plugin config: a complete saved selection can clear an effort when the next selected model has none, while a composition value would be inherited again.
|
||||
|
||||
- `ctx.agentDefaultModel.currentSelection()` returns a detached `{ provider, model, reasoningEffort? }` selection for a newly created Agent.
|
||||
- `ctx.agentDefaultModel.saveSelection(selection)` saves the complete user selection. Without a settings provider it is a no-op and the composition entry remains current.
|
||||
|
||||
The service does not validate catalog membership. A provider route may serve an unadvertised model, and the consumer that actually opens a model request owns availability diagnostics.
|
||||
|
||||
## Model Experience
|
||||
|
||||
Indirectly, through the provider/model selection supplied to a front door; request assembly and adapters own the model-visible request.
|
||||
|
||||
#### KV Cache effect
|
||||
|
||||
Changing the default affects only Agents that subsequently resolve from it. An existing session whose request log already names a selection keeps that selection, so this service does not invalidate its established prefix.
|
||||
|
||||
## Known Limitations and Deferred Work
|
||||
|
||||
- The service owns one process-wide default; per-session selection remains the front door's responsibility.
|
||||
- Without a settings provider, `saveSelection()` cannot retain a selection for a later Agent.
|
||||
25
packages/core/agent-default-model/README.zh.md
Normal file
25
packages/core/agent-default-model/README.zh.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# @deepseek-ai/dsh-agent-default-model
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
该部署默认值供入口在创建尚无会话级模型选择的 Agent 时使用。`AgentDefaultModelService` 提供 `ctx.agentDefaultModel`;`dsh run` 这类直接入口与 ApiProxy 这类由 Host 支撑的入口读取同一服务,而不是分别持有平行的提供方/模型默认值。
|
||||
|
||||
插件配置必须提供 `{ provider, model }`。该组合配置项构成 Settings 中 `agent-default-model` 分节的基础层;挂载的设置提供方在其上叠加用户选择,更改会在下一次调用 `currentSelection()` 时可见。`reasoningEffort` 属于该 Settings 分节,但特意不属于插件配置:完整保存的选择必须能在下一个选定模型没有推理(reasoning)强度时清除旧值,而组合配置值会再次被继承。
|
||||
|
||||
- `ctx.agentDefaultModel.currentSelection()` 返回一份独立的 `{ provider, model, reasoningEffort? }` 选择,供新创建的 Agent 使用。
|
||||
- `ctx.agentDefaultModel.saveSelection(selection)` 保存完整的用户选择。未挂载设置提供方时,此调用不执行任何操作,组合配置项仍为当前值。
|
||||
|
||||
该服务不校验目录成员关系。提供方路由可以服务未在目录中公布的模型;实际发起模型请求的消费方负责可用性诊断。
|
||||
|
||||
## 模型体验
|
||||
|
||||
通过提供给入口的提供方/模型选择间接影响;模型可见请求由请求组装与适配器负责。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
更改默认值只影响之后从该默认值解析选择的 Agent。请求日志已经指明选择的现有会话仍沿用该选择,因此本服务不会使其已建立的前缀失效。
|
||||
|
||||
## 已知限制与暂缓事项
|
||||
|
||||
- 该服务只拥有一项进程级默认值;每个会话的选择仍由入口负责。
|
||||
- 未挂载设置提供方时,`saveSelection()` 无法保留选择供后续 Agent 使用。
|
||||
44
packages/core/agent-default-model/package.json
Normal file
44
packages/core/agent-default-model/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@deepseek-ai/dsh-agent-default-model",
|
||||
"description": "Default model selection shared by Agent front doors",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./invariant": {
|
||||
"types": "./lib/types/invariant.d.ts",
|
||||
"default": "./lib/invariant.js"
|
||||
},
|
||||
"./src/*": "./src/*",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"lib/index.js",
|
||||
"lib/invariant.js",
|
||||
"lib/types/**/*.d.ts"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"schemastery": "^3.18.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/dsh-agent": "^0.0.1",
|
||||
"@deepseek-ai/dsh-invariants": "^0.0.1",
|
||||
"@deepseek-ai/dsh-llm": "^0.0.1",
|
||||
"@deepseek-ai/dsh-settings": "^0.0.1",
|
||||
"cordis": "^4.0.0-rc.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/dsh-agent": "workspace:^",
|
||||
"@deepseek-ai/dsh-invariants": "workspace:^",
|
||||
"@deepseek-ai/dsh-llm": "workspace:^",
|
||||
"@deepseek-ai/dsh-settings": "workspace:^",
|
||||
"cordis": "^4.0.0-rc.7"
|
||||
}
|
||||
}
|
||||
107
packages/core/agent-default-model/src/index.ts
Normal file
107
packages/core/agent-default-model/src/index.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Default model selection for an Agent without a session-specific selection.
|
||||
*
|
||||
* @module @deepseek-ai/dsh-agent-default-model
|
||||
*/
|
||||
|
||||
import { Context, Service } from 'cordis'
|
||||
import z from 'schemastery'
|
||||
import type { ModelSelection } from '@deepseek-ai/dsh-agent'
|
||||
import { ReasoningEffortId } from '@deepseek-ai/dsh-llm'
|
||||
import { installSettingsSection, settingsNamespace } from '@deepseek-ai/dsh-settings'
|
||||
|
||||
declare module 'cordis' {
|
||||
interface Context {
|
||||
/** Default model selection for Agents created without an explicit model. */
|
||||
agentDefaultModel: AgentDefaultModelService
|
||||
}
|
||||
}
|
||||
|
||||
/** Settings namespace carrying the default model selection for future Agents. */
|
||||
export const AGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE = settingsNamespace('agent-default-model')
|
||||
|
||||
/** Stored and composed default model selection. */
|
||||
export interface AgentDefaultModelSettings {
|
||||
/** Registered provider route. */
|
||||
provider: string
|
||||
/** Provider-owned model id. */
|
||||
model: string
|
||||
/** Adapter-owned reasoning effort, or provider/default behavior when absent. */
|
||||
reasoningEffort?: string
|
||||
}
|
||||
|
||||
/** Schema of the default Agent model settings section. */
|
||||
export const AGENT_DEFAULT_MODEL_SETTINGS_SCHEMA: z<AgentDefaultModelSettings> = z.object({
|
||||
provider: z.string().required(),
|
||||
model: z.string().required(),
|
||||
reasoningEffort: z.string(),
|
||||
})
|
||||
|
||||
/** Composition entry for the default model selection. */
|
||||
export interface Config {
|
||||
/** Registered provider route. */
|
||||
provider: string
|
||||
/** Provider-owned model id. */
|
||||
model: string
|
||||
}
|
||||
|
||||
/** Project stored settings onto the Agent-facing selection type. */
|
||||
function selection(settings: AgentDefaultModelSettings): ModelSelection {
|
||||
return {
|
||||
provider: settings.provider,
|
||||
model: settings.model,
|
||||
...settings.reasoningEffort === undefined
|
||||
? {}
|
||||
: { reasoningEffort: ReasoningEffortId(settings.reasoningEffort) },
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Owns the default model selection independently of any Host or transport.
|
||||
* The composition entry remains usable without a settings provider; when one
|
||||
* is mounted, its user layer is read live.
|
||||
*/
|
||||
export class AgentDefaultModelService extends Service {
|
||||
static Config: z<Config> = z.object({
|
||||
provider: z.string().required(),
|
||||
model: z.string().required(),
|
||||
})
|
||||
|
||||
private source: () => AgentDefaultModelSettings
|
||||
|
||||
constructor(ctx: Context, config: Config) {
|
||||
super(ctx, 'agentDefaultModel')
|
||||
const entry: AgentDefaultModelSettings = { provider: config.provider, model: config.model }
|
||||
this.source = () => entry
|
||||
installSettingsSection(ctx, AGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE, AGENT_DEFAULT_MODEL_SETTINGS_SCHEMA, entry, {
|
||||
setSource: (current) => { this.source = current },
|
||||
// Every consumer reads through currentSelection(), so no registration-level fact
|
||||
// needs rebuilding when the settings document changes.
|
||||
onChange: () => {},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the current default model selection.
|
||||
* @returns a detached provider, model, and optional reasoning selection.
|
||||
*/
|
||||
currentSelection(): ModelSelection {
|
||||
return selection(this.source())
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the complete default model selection. A deployment without a settings
|
||||
* provider keeps its composition entry.
|
||||
* @param next - resolved selection accepted by a front door.
|
||||
* @returns fulfillment after the optional settings write settles.
|
||||
*/
|
||||
async saveSelection(next: ModelSelection): Promise<void> {
|
||||
await this.ctx.get('settings')?.replace(AGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE, {
|
||||
provider: next.provider,
|
||||
model: next.model,
|
||||
...next.reasoningEffort === undefined ? {} : { reasoningEffort: String(next.reasoningEffort) },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default AgentDefaultModelService
|
||||
30
packages/core/agent-default-model/src/invariant.ts
Normal file
30
packages/core/agent-default-model/src/invariant.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Package-owned invariant companion for the default Agent model selection.
|
||||
*
|
||||
* The service owns no independent event relationship: settings registration
|
||||
* already validates every mutable value before `currentSelection()` can observe it.
|
||||
* The empty installer keeps that absence explicit in composed invariant sets.
|
||||
*
|
||||
* @module @deepseek-ai/dsh-agent-default-model/invariant
|
||||
*/
|
||||
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-agent-default-model'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'agent-default-model-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** No runtime invariant: settings validation owns the only mutable-value relationship. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
|
||||
/**
|
||||
* Register the intentionally empty invariant contribution.
|
||||
* @param ctx - Cordis context carrying the invariant service.
|
||||
* @returns the installed registration's disposer after setup succeeds.
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
@@ -0,0 +1,98 @@
|
||||
/** Default Agent model settings layered over a real settings provider. */
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import AgentDefaultModelService, { AGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE } from '../src/index.ts'
|
||||
import { Settings } from '@deepseek-ai/dsh-settings'
|
||||
import type { SettingsNamespace } from '@deepseek-ai/dsh-settings'
|
||||
import { ReasoningEffortId } from '@deepseek-ai/dsh-llm'
|
||||
|
||||
/** The smallest real provider: one in-memory document, always writable. */
|
||||
class MemorySettings extends Settings {
|
||||
doc: Record<string, unknown> = {}
|
||||
|
||||
get writable(): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
protected load(): Promise<Record<string, unknown>> {
|
||||
return Promise.resolve(structuredClone(this.doc))
|
||||
}
|
||||
|
||||
protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
|
||||
this.doc = { ...this.doc, [ns]: structuredClone(section) }
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
async function boot(): Promise<{
|
||||
ctx: Context
|
||||
settingsFiber: Context['fiber']
|
||||
defaultModel: AgentDefaultModelService
|
||||
}> {
|
||||
const ctx = new Context()
|
||||
const settingsFiber = ctx.plugin(MemorySettings)
|
||||
await settingsFiber.await()
|
||||
await ctx.plugin(AgentDefaultModelService, {
|
||||
provider: 'deepseek-official',
|
||||
model: 'deepseek-v4-flash',
|
||||
})
|
||||
return { ctx, settingsFiber, defaultModel: ctx.agentDefaultModel }
|
||||
}
|
||||
|
||||
describe('AgentDefaultModelService', () => {
|
||||
it('resolves the user layer over the composition entry', async () => {
|
||||
const bench = await boot()
|
||||
expect(bench.defaultModel.currentSelection()).toEqual({
|
||||
provider: 'deepseek-official', model: 'deepseek-v4-flash',
|
||||
})
|
||||
|
||||
await bench.defaultModel.saveSelection({
|
||||
provider: 'acme-gateway', model: 'acme-large', reasoningEffort: ReasoningEffortId('high'),
|
||||
})
|
||||
expect(bench.defaultModel.currentSelection()).toEqual({
|
||||
provider: 'acme-gateway', model: 'acme-large', reasoningEffort: 'high',
|
||||
})
|
||||
await bench.ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
it('clears a stored effort when the saved selection has none', async () => {
|
||||
const bench = await boot()
|
||||
await bench.defaultModel.saveSelection({
|
||||
provider: 'acme-gateway', model: 'acme-large', reasoningEffort: ReasoningEffortId('high'),
|
||||
})
|
||||
await bench.defaultModel.saveSelection({ provider: 'acme-gateway', model: 'acme-plain' })
|
||||
expect(bench.defaultModel.currentSelection()).toEqual({ provider: 'acme-gateway', model: 'acme-plain' })
|
||||
await bench.ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
it('layers a hand-written partial section over the entry', async () => {
|
||||
const bench = await boot()
|
||||
await bench.settingsFiber.ctx.settings.replace(AGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE, {
|
||||
model: 'deepseek-reasoner',
|
||||
})
|
||||
expect(bench.defaultModel.currentSelection()).toEqual({
|
||||
provider: 'deepseek-official', model: 'deepseek-reasoner',
|
||||
})
|
||||
await bench.ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
it('falls back to the composition entry when the settings provider detaches', async () => {
|
||||
const bench = await boot()
|
||||
await bench.defaultModel.saveSelection({ provider: 'acme-gateway', model: 'acme-large' })
|
||||
expect(bench.defaultModel.currentSelection().provider).toBe('acme-gateway')
|
||||
await bench.settingsFiber.dispose()
|
||||
expect(bench.defaultModel.currentSelection()).toEqual({
|
||||
provider: 'deepseek-official', model: 'deepseek-v4-flash',
|
||||
})
|
||||
await bench.ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
it('keeps the composition entry when no settings provider is mounted', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(AgentDefaultModelService, { provider: 'p', model: 'm' })
|
||||
await ctx.agentDefaultModel.saveSelection({ provider: 'other', model: 'other' })
|
||||
expect(ctx.agentDefaultModel.currentSelection()).toEqual({ provider: 'p', model: 'm' })
|
||||
await ctx.fiber.dispose()
|
||||
})
|
||||
})
|
||||
30
packages/core/agent-default-model/tsconfig.json
Normal file
30
packages/core/agent-default-model/tsconfig.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../vendor/cordis"
|
||||
},
|
||||
{
|
||||
"path": "../../../vendor/schemastery"
|
||||
},
|
||||
{
|
||||
"path": "../../core/agent"
|
||||
},
|
||||
{
|
||||
"path": "../../llm/llm"
|
||||
},
|
||||
{
|
||||
"path": "../../settings/settings"
|
||||
},
|
||||
{
|
||||
"path": "../../support/invariants"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
packages/core/agent-default-model/tsdown.config.ts
Normal file
25
packages/core/agent-default-model/tsdown.config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { defineConfig } from 'tsdown'
|
||||
|
||||
/** Build the package root and invariant companion as independent bundles. */
|
||||
export default defineConfig([
|
||||
{
|
||||
entry: ['lib/types/index.js'],
|
||||
outDir: 'lib',
|
||||
format: ['esm'],
|
||||
platform: 'node',
|
||||
target: 'es2024',
|
||||
fixedExtension: false,
|
||||
dts: false,
|
||||
clean: false,
|
||||
},
|
||||
{
|
||||
entry: ['lib/types/invariant.js'],
|
||||
outDir: 'lib',
|
||||
format: ['esm'],
|
||||
platform: 'node',
|
||||
target: 'es2024',
|
||||
fixedExtension: false,
|
||||
dts: false,
|
||||
clean: false,
|
||||
},
|
||||
])
|
||||
Reference in New Issue
Block a user