diff --git a/docs/subsystems/session.md b/docs/subsystems/session.md index 369347b71d..0284bfddec 100644 --- a/docs/subsystems/session.md +++ b/docs/subsystems/session.md @@ -930,7 +930,8 @@ resolveAgent(sessionId: SessionId): Promise @Remote('selectModel') selectModel(request: SessionSelectModelRequest): Promise /** - * 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 diff --git a/docs/subsystems/session.zh.md b/docs/subsystems/session.zh.md index e7997c8922..88d84b3c69 100644 --- a/docs/subsystems/session.zh.md +++ b/docs/subsystems/session.zh.md @@ -930,7 +930,8 @@ resolveAgent(sessionId: SessionId): Promise @Remote('selectModel') selectModel(request: SessionSelectModelRequest): Promise /** - * 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 diff --git a/packages/api/session-controller/README.i18n.yaml b/packages/api/session-controller/README.i18n.yaml index b14f075f66..882fd8316b 100644 --- a/packages/api/session-controller/README.i18n.yaml +++ b/packages/api/session-controller/README.i18n.yaml @@ -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 diff --git a/packages/api/session-controller/README.md b/packages/api/session-controller/README.md index 5c313bfcd0..b06ebf676e 100644 --- a/packages/api/session-controller/README.md +++ b/packages/api/session-controller/README.md @@ -96,7 +96,7 @@ References keep local Session data, scoped Contexts, and history streams alive, `SessionMediaReferences` mounts `GET|HEAD /api/file?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. diff --git a/packages/api/session-controller/README.zh.md b/packages/api/session-controller/README.zh.md index a259731087..bca001e445 100644 --- a/packages/api/session-controller/README.zh.md +++ b/packages/api/session-controller/README.zh.md @@ -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` 的动态访问器读取最近一次成功保存的默认值。显式选择即使与默认值相同也会记录。省略推理强度会清除显式强度,让每次请求使用适配器默认值。 diff --git a/packages/api/session-controller/src/index.ts b/packages/api/session-controller/src/index.ts index 2b4e7984a9..39eedbb176 100644 --- a/packages/api/session-controller/src/index.ts +++ b/packages/api/session-controller/src/index.ts @@ -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(model.reasoning.defaultEffort) }, diff --git a/packages/api/session-controller/tests/session-models.host.spec.ts b/packages/api/session-controller/tests/session-models.host.spec.ts index ca59d78501..f82e838603 100644 --- a/packages/api/session-controller/tests/session-models.host.spec.ts +++ b/packages/api/session-controller/tests/session-models.host.spec.ts @@ -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('max') }, + }, + { + outcome: 'replaces an account model the account no longer lists', configuredKey: false, replaced: true, + saved: { provider: 'deepseek-account', model: 'delisted-model', reasoningEffort: brandString('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() }) diff --git a/packages/extensions/cordis-host-runner/src/api-catalog.ts b/packages/extensions/cordis-host-runner/src/api-catalog.ts index 2986108f1f..4b5facae1f 100644 --- a/packages/extensions/cordis-host-runner/src/api-catalog.ts +++ b/packages/extensions/cordis-host-runner/src/api-catalog.ts @@ -3766,7 +3766,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [ }, { signature: '@Remote async initializeDefaultModel(): Promise', - 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.', },