Files
order-notification-automation/docs/superpowers/plans/2026-10-28-dsh-providers-conversations.md
T

8.6 KiB

DSH Providers and Conversation Management Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: 复用官方 DSH 多供应商能力,完成助手设置/对话模型选择、会话回收站,以及醒目的返回工具按钮。

Architecture: 独立 ProviderRegistry 复用 assistant 数据库与加密,官方 DeepSeek/pi-ai 分别承担协议路由。会话新增删除状态、模型选择与独立额度记账;浏览器设置、模型控件与目录菜单通过现有 API 适配。

Tech Stack: CommonJS、原生 JS/Tabler、SQLite/AES-GCM、DSH0.2.1-rc.2、Playwright、Node test runner。

Spec: approved design

Global Constraints

  • 用户已明确批准执行和助手设置/返回按钮补充;不再请求同项批准。
  • 使用现有 dsh 分支,保留三个未跟踪业务文档,不改业务发送/归档/审批规则。
  • DSH 固定0.2.1-rc.2,复用 dsh-llm-pi-ai;原生 Shell/文件/MCP/插件工具保持未挂载。
  • 密钥加密只写、不回显;更换端点/协议重新输入密钥;供应商修改仅管理员。
  • 回收站无自动清空;永久删除需本人显式确认,不释放调用额度、不删除操作审计。
  • 测试使用独立临时 LOCALAPPDATA;通过 junction 引用已安装运行包,不复用运行服务凭据目录。
  • 只更新已授权本机测试副本,先备份;不启用真实模型、不发送测试以外的业务操作。

Task 1: Provider registry and official protocol adaptation

Files: Create src/modules/assistant/providers.cjs, provider-catalog.cjs, tests providers.test.cjs, providers-runtime.test.cjs; modify dsh-runtime.cjs only. Store/API/service are integrated by root in Task2.

Interfaces: new ProviderRegistry(store), methods list(), save(input), chooseDefault(input), remove(id,input), resolve(selection?), syncLegacy(settings), discover(id,{version,signal}={}). list() returns {version,providers,defaultSelection,catalog}; providers expose {id,version,name,preset,protocol,apiBase,enabled,hasApiKey,models:[{id,name,contextWindow?,maxTokens?}]}. resolve returns private config {providerId,providerName,providerVersion,preset,protocol,apiBase,apiKey,model,modelName,contextWindow,maxTokens}. Fixed legacy provider ID is deepseek.

  • Write tests proving migration from old DeepSeek configuration retains secret/default; multiple providers stay isolated/encrypted; address/protocol changes require a new key; version conflicts/disabled/missing models fail. Run red before implementation.
const registry=new ProviderRegistry(store);
registry.syncLegacy({apiBase:'https://api.deepseek.com/anthropic',model:'legacy',apiKey:'TEST_KEY'});
assert.equal(registry.resolve().model,'legacy');
assert.equal(registry.list().providers[0].apiKey,undefined);
  • Implement encrypted provider records and independently versioned defaults. Limit30 providers/100 models, validate names/IDs/endpoints/model bounds; save id absent creates stable ID, new version0 and stale existing version reject. Blank key preserves existing, no source/environment key discovery.
  • Reuse installed native catalogue metadata where possible; expose DeepSeek/OpenAI/Anthropic/custom presets. Explicit discover lists models with a bounded GET using only that provider's key; unsupported response fails without saving.
  • Adapt profilePatch/environment to selected route: legacy DeepSeek remains byte-compatible in behavior, other protocols mount only native dsh-llm-pi-ai with the chosen explicit route/model and fixed private credential reference. No tools or additional ambient credentials. Honor timeout/output limits.
const profile=profilePatch({...config,protocol:'openai-responses',providerId:'fixture'});
assert.match(profile,/dsh-llm-pi-ai/);
assert.doesNotMatch(profile,/TEST_KEY/);
  • Test actual fixed official DSH against local fake Messages, Chat Completions and Responses endpoints, ensure zero native tools, correct route, credentials and cancellation cleanup. Run previous dsh-runtime/dsh-events tests and commit owned paths only.

Task 2: Conversation lifecycle, settings and routing integration

Files: Modify assistant store.cjs, service.cjs, conversation-history.cjs, conversation-search.cjs, api.cjs, event-stream.cjs; backup restore.cjs; add conversation-trash.test.cjs, provider-http.test.cjs, assistant-restore.test.cjs.

Interfaces: store.providers is ProviderRegistry; service.resolve per-conversation or default selection before each new run; existing settings API fields remain compatible. Conversation model choice endpoint updates encrypted metadata with version. Store methods trash, restoreDeleted, purge implement deleted scope; usage() reads durable ledger.

  • Write failing tests for deleted filtering/restoration, owner/version/busy guards, quota retained after purge, continued child usable after parent deletion, and model selection pinned to a running turn.
const c=store.create('owner'),turn=store.beginTurn(c.id,'owner','fixture');
store.updateTurn(turn.id,'success',{reply:'done'});
const used=store.usage().calls;
const deleted=store.trash(c.id,'owner',{version:store.conversation(c.id,'owner').version});
store.purge(c.id,'owner',{version:deleted.version,confirm:'delete'});
assert.equal(store.usage().calls,used);
  • Add deleted_at and call ledger migration. Exclude deleted rows from active/search/send/actions; explicit deleted scope permits read-only history. Inherit three successful turns into child metadata before parent removal. Delete events/requests/turns atomically on purge, independent audit/ledger survive.
  • Integrate registry in store; legacy saveFields sync only explicit legacy writes. New runtime settings omit old endpoint/key fields. Enabling checks selected usable config, preserving old tests and stored settings.
  • Integrate provider/default/model endpoints with same-origin, admin/owner, secure credential transport, version and running provider-delete guards. Pin private provider config to each run and persist only public per-turn selection metadata.
  • Update SSE/polling with conversation_removed terminal control, no authentication logout on deleted conversation. Update backup payload AAD mapping for config/providers/defaults/events/requests and verify backup/restore roundtrip.
  • Run focused HTTP, lifecycle, old assistant and backup tests. Commit only task paths after Task1 implementation agent has committed.

Task 3: Settings/model menu, row actions and return controls

Files: Create web/modules/assistant/providers.js, model-picker.js; modify assistant view.js, layout.js, workspace.css, commands.js, events-client.js, web/app.js, assets/index, user guide; add browser tests providers-ui.test.cjs, conversation-trash-ui.test.cjs.

  • Add failing UI tests: add/edit supplier via actual assistant-settings route; models fetched into draft then saved; default and composer selection consistent; trash/archive visible from row menus; recover/purge confirmation; return controls44px high and target tools on desktop/mobile.
  • Build supplier rows/one expanded editor, protocol presets, write-only key input, editable model rows, explicit model discovery, default model chooser. Keep runtime/permissions in a separate existing settings form and honor dirty draft guards.
  • Add grouped searchable picker and /model, showing unavailable selection honestly. Selecting updates conversation version; the next request uses it while a running turn retains the previous choice. No key reaches browser pickers.
  • Add ⋯ row actions and deleted scope; owner-confirmation dialog for permanent deletion; stop and discard event subscriptions when current conversation is deleted elsewhere. Preserve existing draft/search/scroll and archive/continue behavior.
  • Emphasize return button with text/arrow,44px height and110px minimum width, #tools; adapt tools subpage breadcrumb consistently and verify narrow screens.
  • Run new+old UI, assistant suite and isolated fresh npm test; perform independent final review and fix important findings. Preserve known full-suite baseline limitations from prior verification, avoid unrelated fixes.
  • Update guide/design/verification, commit and push dsh. Stop local test copy, verified backup, deploy tracked files, retain config/dependencies, restart healthy and open both settings/assistant for visual review; no actual credential setup or real model calls.