mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-30 09:09:35 +08:00
fix(session-controller): keep the selected account model when signing in again
Account login without a provider API key replaced the saved default with the first account model and its default reasoning effort. A saved default that names a listed account model is now retained with its effort; every other case is unchanged. Fixes #9392
This commit is contained in:
1 parent
1cb8a494dc
commit
181e7bdf1b
8 files changed
+31
-14
No files matched your search
@@ -930,7 +930,8 @@ resolveAgent(sessionId: SessionId): Promise<ApiSessionAgentResult>
|
||||
@Remote('selectModel') selectModel(request: SessionSelectModelRequest): Promise<SessionSelectModelValue>
|
||||
|
||||
/**
|
||||
* Select the first available account model after login when no provider API key is configured.
|
||||
* Make the default an account model after login when no provider API key is configured.
|
||||
* A saved default naming a listed account model is retained with its reasoning effort.
|
||||
* @returns after saving the first available model or retaining the existing default.
|
||||
*/
|
||||
@Remote async initializeDefaultModel(): Promise<void>
|
||||
|
||||
@@ -930,7 +930,8 @@ resolveAgent(sessionId: SessionId): Promise<ApiSessionAgentResult>
|
||||
@Remote('selectModel') selectModel(request: SessionSelectModelRequest): Promise<SessionSelectModelValue>
|
||||
|
||||
/**
|
||||
* Select the first available account model after login when no provider API key is configured.
|
||||
* Make the default an account model after login when no provider API key is configured.
|
||||
* A saved default naming a listed account model is retained with its reasoning effort.
|
||||
* @returns after saving the first available model or retaining the existing default.
|
||||
*/
|
||||
@Remote async initializeDefaultModel(): Promise<void>
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
en: 8c9fb80b590c47ff
|
||||
zh: db2902daf76e46f8
|
||||
/session-controller/session-media-references:
|
||||
en: 954923654eebe2dc
|
||||
zh: 6bd9a7d2ea965aed
|
||||
en: ac6765a7e4785fac
|
||||
zh: 9b36f91c4fc037cd
|
||||
/session-controller/configuration:
|
||||
en: 8f62f7183c67fc02
|
||||
zh: 0e2db400b376629f
|
||||
|
||||
@@ -96,7 +96,7 @@ References keep local Session data, scoped Contexts, and history streams alive,
|
||||
|
||||
`SessionMediaReferences` mounts `GET|HEAD /api/file?path=<absolute path>` on the authenticated `connection.fetch` channel when `connection`, `fs`, and `attachments` are composed. It reads ordinary files through `ctx.fs`, including temporary paths outside registered workspaces and files in remote providers. Neither directory containment nor MIME categories restrict access; `mime-types` supplies the response type, with `application/octet-stream` for unknown extensions. GET reuses `readBytes` for preflight and ongoing byte limits; HEAD reads metadata only. All files use `ctx.attachments.imageLimits.maxImageBytes` (normally 50 MiB); exceeding this limit returns 413. A request whose `v` parameter differs from the file's current `ctx.fs` version, including a request without one, receives a `private, no-store` 302 to the same route with only `path` and the current `v`; the versioned response is `private, max-age=31536000, immutable`, so browsers reuse cached bytes until the file changes, and private file contents may enter the browser disk cache. Responses contain the complete file, ignore Range, and carry `nosniff`, and a sandbox CSP so directly opened HTML/SVG cannot execute with the API origin. The Client rewrite lives in `ui-chat` (`AssistantMarkdown`); audio/video responses are available, while Markdown audio/video player nodes remain separate work.
|
||||
|
||||
GUI model selection requires the exact provider/model pair in the available catalog; unavailable choices reject with `session/model-unavailable`. Prompt admission retains the saved route without a catalog availability gate, so request execution reports missing credentials or unavailable models. `initializeDefaultModel()` saves the first available account model after login when no other provider has a configured API key; credential checks use configured references independently of model availability. A provider with no available models rejects initialization with `session/provider-models-unavailable`. Availability never substitutes another model or rewrites a Session selection.
|
||||
GUI model selection requires the exact provider/model pair in the available catalog; unavailable choices reject with `session/model-unavailable`. Prompt admission retains the saved route without a catalog availability gate, so request execution reports missing credentials or unavailable models. `initializeDefaultModel()` saves the first available account model after login when no other provider has a configured API key, and retains a saved default that names a listed account model together with its reasoning effort; credential checks use configured references independently of model availability. A provider with no available models rejects initialization with `session/provider-models-unavailable`. Availability never substitutes another model or rewrites a Session selection.
|
||||
|
||||
A successful `selectModel` response acknowledges the recorded Session selection without waiting for the default profile setting to save. The loop registers its projection; a change applies to the next step while a prepared step retains its captured choice. Default saves run in the background in submission order; a failure logs a warning and leaves the Session selection intact. A Session with no recorded selection or request reads the last successfully saved default through live `AgentOptions` accessors. An explicit choice is recorded even when it equals that default. Omitting reasoning effort clears the explicit effort and lets each request use the adapter default.
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ Client 的首次 `follow`、重连首屏与 `loadOlder()` 至少请求 50 条以
|
||||
|
||||
当 `connection`、`fs` 与 `attachments` 均被组合时,`SessionMediaReferences` 在鉴权 `connection.fetch` 通道上挂载 `GET|HEAD /api/file?path=<绝对路径>`。它通过 `ctx.fs` 读取普通文件,包括已注册工作区之外的临时路径与远程提供方中的文件。目录包含关系与 MIME 类别均不限制访问;`mime-types` 提供响应类型,未知扩展名使用 `application/octet-stream`。GET 复用 `readBytes` 执行读取前及读取中的字节限制;HEAD 只读取元数据。所有文件均使用 `ctx.attachments.imageLimits.maxImageBytes`(通常为 50 MiB);超过此上限返回 413。`v` 参数与文件当前 `ctx.fs` 版本不同(包括没有该参数)的请求,会收到 `private, no-store` 的 302,跳转到只含 `path` 与当前 `v` 的同一路由;版本化响应为 `private, max-age=31536000, immutable`,因此浏览器在文件变化前复用缓存内容,私有文件内容可能进入浏览器磁盘缓存。响应包含完整文件,忽略 Range,并携带 `nosniff` 与沙箱 CSP,使直接打开的 HTML/SVG 无法以 API 源身份执行脚本。客户端重写位于 `ui-chat`(`AssistantMarkdown`);音视频文件响应已可用,Markdown 音视频播放器节点仍是独立工作。
|
||||
|
||||
GUI 模型选择要求确切提供方/模型对出现在可用目录中;不可用的选择以 `session/model-unavailable` 拒绝。提示词准入保留已保存的路由,不按目录可用性阻断发送,由请求执行报告凭据缺失或模型不可用。`initializeDefaultModel()` 在账号登录后、其他提供方均未配置 API key 时,将第一个可用账号模型保存为默认模型;凭据检查使用已配置的引用,不依赖模型是否可用。提供方没有可用模型时,初始化以 `session/provider-models-unavailable` 拒绝。可用性变化不会替换模型或改写会话选择。
|
||||
GUI 模型选择要求确切提供方/模型对出现在可用目录中;不可用的选择以 `session/model-unavailable` 拒绝。提示词准入保留已保存的路由,不按目录可用性阻断发送,由请求执行报告凭据缺失或模型不可用。`initializeDefaultModel()` 在账号登录后、其他提供方均未配置 API key 时,将第一个可用账号模型保存为默认模型,已保存的默认模型若是账号目录仍列出的模型,则连同其推理强度一并保留;凭据检查使用已配置的引用,不依赖模型是否可用。提供方没有可用模型时,初始化以 `session/provider-models-unavailable` 拒绝。可用性变化不会替换模型或改写会话选择。
|
||||
|
||||
`selectModel` 成功返回表示会话模型选择已记录,不等待默认 profile 设置保存。循环注册该投影;变更从下一个步骤开始生效,已准备的步骤保留捕获的选择。默认设置在后台按提交顺序保存;保存失败会记录警告,并保留会话选择。尚未记录选择或请求的会话通过 `AgentOptions` 的动态访问器读取最近一次成功保存的默认值。显式选择即使与默认值相同也会记录。省略推理强度会清除显式强度,让每次请求使用适配器默认值。
|
||||
|
||||
|
||||
@@ -292,7 +292,8 @@ export class SessionController extends TypertRemoteService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the first available account model after login when no provider API key is configured.
|
||||
* Make the default an account model after login when no provider API key is configured.
|
||||
* A saved default naming a listed account model is retained with its reasoning effort.
|
||||
* @returns after saving the first available model or retaining the existing default.
|
||||
*/
|
||||
@Remote
|
||||
@@ -300,9 +301,12 @@ export class SessionController extends TypertRemoteService {
|
||||
const provider = 'deepseek-account'
|
||||
if (await hasProviderApiKey(this.ctx)) return
|
||||
const catalog = await buildModelCatalog(this.ctx)
|
||||
const model = catalog.groups.find(group => group.id === provider)?.models[0]
|
||||
const models = catalog.groups.find(group => group.id === provider)?.models ?? []
|
||||
const model = models[0]
|
||||
if (model === undefined) throw new RemoteError('session/provider-models-unavailable',
|
||||
`provider "${provider}" has no available models`, { provider })
|
||||
const saved = this.ctx.agentDefaultModel.currentSelection()
|
||||
if (saved.provider === provider && models.some(listed => listed.id === saved.model)) return
|
||||
const selection = { provider, model: model.id,
|
||||
...model.reasoning?.defaultEffort === undefined ? {}
|
||||
: { reasoningEffort: brandString<ReasoningEffortId>(model.reasoning.defaultEffort) },
|
||||
|
||||
@@ -360,7 +360,18 @@ describe('Web session model selection', () => {
|
||||
} finally { await ctx.fiber.dispose() }
|
||||
})
|
||||
|
||||
it.each([false, true])('account login replaces a saved default only without another API key: %s', async (configuredKey) => {
|
||||
it.each([
|
||||
{ outcome: 'replaces a default of another provider', configuredKey: false, saved: { provider: 'removed', model: 'saved' }, replaced: true },
|
||||
{ outcome: 'keeps the default when another API key is configured', configuredKey: true, saved: { provider: 'removed', model: 'saved' }, replaced: false },
|
||||
{
|
||||
outcome: 'keeps a listed account model with its effort', configuredKey: false, replaced: false,
|
||||
saved: { provider: 'deepseek-account', model: 'second-model', reasoningEffort: brandString<ReasoningEffortId>('max') },
|
||||
},
|
||||
{
|
||||
outcome: 'replaces an account model the account no longer lists', configuredKey: false, replaced: true,
|
||||
saved: { provider: 'deepseek-account', model: 'delisted-model', reasoningEffort: brandString<ReasoningEffortId>('max') },
|
||||
},
|
||||
])('account login $outcome', async ({ configuredKey, saved, replaced }) => {
|
||||
const { configurationFixture } = await import('../../../settings/settings/tests/configuration-fixture.ts')
|
||||
const configured = await configurationFixture({ hmr: false })
|
||||
const { ctx } = await harness(undefined, configured.ctx)
|
||||
@@ -378,15 +389,15 @@ describe('Web session model selection', () => {
|
||||
ns: 'first' as never, autoGenerate: false, schema: {}, revision: 0, applies: 'live',
|
||||
value: { providers: { custom: { apiKeyEnv: 'CUSTOM_API_KEY', models: [] } } },
|
||||
}])
|
||||
await ctx.agentDefaultModel.saveSelection({ provider: 'removed', model: 'saved' })
|
||||
await ctx.agentDefaultModel.saveSelection(saved)
|
||||
const controller = await createSessionTestController(ctx, {
|
||||
defaultModelSelection: () => ctx.agentDefaultModel.currentSelection(), cwd: '/tmp',
|
||||
})
|
||||
await controller.initializeDefaultModel()
|
||||
expect(describe).toHaveBeenCalledWith('CUSTOM_API_KEY')
|
||||
expect(ctx.agentDefaultModel.currentSelection()).toEqual(configuredKey
|
||||
? { provider: 'removed', model: 'saved' }
|
||||
: { provider: 'deepseek-account', model: 'first-model', reasoningEffort: 'high' })
|
||||
expect(ctx.agentDefaultModel.currentSelection()).toEqual(replaced
|
||||
? { provider: 'deepseek-account', model: 'first-model', reasoningEffort: 'high' }
|
||||
: saved)
|
||||
await ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
|
||||
@@ -3766,7 +3766,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
},
|
||||
{
|
||||
signature: '@Remote async initializeDefaultModel(): Promise<void>',
|
||||
description: 'Select the first available account model after login when no provider API key is configured.',
|
||||
description: 'Make the default an account model after login when no provider API key is configured. A saved default naming a listed account model is retained with its reasoning effort.',
|
||||
parameters: [],
|
||||
returns: 'after saving the first available model or retaining the existing default.',
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user