Skip to content

fix: adapt to Cordis 4 / DSH 0.1.2-alpha.5 slots & webServer inject API - #3

Open
hao1196561270 wants to merge 1 commit into
BeiZi6:mainfrom
hao1196561270:fix/cordis4-slots-inject
Open

hao1196561270 wants to merge 1 commit into
BeiZi6:mainfrom
hao1196561270:fix/cordis4-slots-inject

Conversation

@hao1196561270

Copy link
Copy Markdown

修复在 DSH 0.1.2-alpha.5(Cordis 4.0.2)上呼吸灯不显示的问题。

现象

  • curl /opencodego-usage 正常返回 rolling/weekly/monthly 窗口数据,Host 侧路由工作正常
  • 但 Web GUI 输入框右下角呼吸灯及液态玻璃面板始终不出现

根因

Cordis 4 收紧了服务注入模型:

  1. Client 侧 slots 服务 现在为异步提供,旧写法通过 ctx.get('slots') 绕过注入检查:

    const slots = ctx.get('slots')
    if (slots === undefined) return   // strict 模式下在 apply 时拿不到,直接静默 return
    ctx.effect(() => slots.inject('conversation.input.right', ...))

    在 0.1.2-alpha.5 中 apply 时 slots 尚未就绪,插件直接 return,导致 conversation.input.right(见 dsh-client-ui-conversation/lib/client.js: renderSlot("conversation.input.right"))从未注册。对比新版官方插件 dsh-client-ui-attachment 的正确范式:

    const inject = ['slots']
    function apply(ctx){ ctx.slots.inject(... ctx.slots.register(...)) }
  2. Host 侧 webServer 旧 ctx.inject(['webServer'], httpCtx => httpCtx.webServer.register) 仍兼容但已废弃,新版 dsh-free-search / dsh-web-app 均改为静态 export const inject = ['webServer'] + ctx.webServer.register。

改动

  • client.js: 声明 inject: ['slots'],改用 ctx.slots.inject / ctx.slots.register,移除 ctx.get + ctx.effect 包装,与 dsh-client-ui-attachment 保持一致。
  • index.js: 声明 export const inject = ['webServer'],改用 ctx.effect(() => ctx.webServer.register({...})),移除动态 ctx.inject 包装。

验证

  • node --check index.js 通过,import('index.js') 导出 inject/apply 正常
  • 本地复刻 C:\Users\admin\.dsh\profiles\web 覆盖安装后,curl /opencodego-usage 仍正常
  • 重启 dsh web 后输入框右下角呼吸灯恢复(绿>50% / 黄20–50% / 红<20%),点击可展开三窗口进度条,fetch /opencodego-usage 每 2 分钟自动刷新

兼容性

仅调整注入声明,不改业务逻辑与对外 API,向后兼容旧版 DSH(inject 声明在旧 Cordis 上会被忽略,ctx.slots 访问仍需服务就绪后才调用,但旧版 slots 同步提供故不影响)。

- client: declare inject=['slots'] and use ctx.slots.inject/register
  instead of ctx.get('slots') + ctx.effect(()=>slots.inject)
  Fixes silent early-return where slots was undefined at apply time,
  causing breathing indicator (conversation.input.right) to never register
  on DSH 0.1.2-alpha.5 (Cordis 4.0.2).

- host: declare inject=['webServer'] and use ctx.webServer.register
  instead of ctx.inject(['webServer'], httpCtx=> httpCtx.webServer.register)
  Aligns with modern dsh-free-search / dsh-web-app pattern and removes
  deprecated dynamic inject wrapper. Verified host route /opencodego-usage
  still returns windows JSON.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant