{"version":3,"file":"web.mjs","names":[],"sources":["../../src/host/web.ts"],"sourcesContent":["/**\n * dsh-recommend web 半：把本地缓存的 registry.json 以同源路由供给浏览器。\n *\n * 独立成行（而非并入 host 工具半）是因为 cordis 的 inject 是强依赖：\n * webServer 只在 web profile 存在，headless 下挂载本行会永远 PENDING。\n * 所以 tools 半（main）不带 webServer，本半（./web）带，由 patch 分两行挂载。\n */\nimport { readFile } from 'node:fs/promises'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\n\nexport const name = 'dsh-recommend-web'\nexport const inject = ['webServer']\n\nexport interface Config {\n  /** 本地缓存路径（与 host 半一致）。 */\n  cachePath: string\n}\n\nexport function apply(ctx: Context, config: Config): void {\n  // 注册同源 JSON 路由；浏览器半从此路径拉取（避免 CSP/跨域问题）\n  ctx.effect(() => ctx.webServer.register({\n    kind: 'exact',\n    path: '/dsh-recommend/registry.json',\n    async handler(_req, res) {\n      try {\n        const body = await readFile(config.cachePath)\n        res.writeHead(200, {\n          'content-type': 'application/json; charset=utf-8',\n          'cache-control': 'no-store',\n        })\n        res.end(body)\n      } catch {\n        res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' })\n        res.end('registry cache missing — run sync_registry first')\n      }\n    },\n  }), 'dsh-recommend: registry route')\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,OAAO;AACpB,MAAa,SAAS,CAAC,WAAW;AAOlC,SAAgB,MAAM,KAAc,QAAsB;CAExD,IAAI,aAAa,IAAI,UAAU,SAAS;EACtC,MAAM;EACN,MAAM;EACN,MAAM,QAAQ,MAAM,KAAK;GACvB,IAAI;IACF,MAAM,OAAO,MAAM,SAAS,OAAO,SAAS;IAC5C,IAAI,UAAU,KAAK;KACjB,gBAAgB;KAChB,iBAAiB;IACnB,CAAC;IACD,IAAI,IAAI,IAAI;GACd,QAAQ;IACN,IAAI,UAAU,KAAK,EAAE,gBAAgB,4BAA4B,CAAC;IAClE,IAAI,IAAI,kDAAkD;GAC5D;EACF;CACF,CAAC,GAAG,+BAA+B;AACrC"}