Skip to content

feat: pi native 模式——fetch 拦截层 + 插件胶水(native 模式 B) #519

Description

@ranxianglei

来源: #513 分析 native 模式时拆出的子任务(owner 已确认方案)。

目标:装好插件后直接跑裸 pi,无需 bili pi launcher,用户无感。

设计(#513 讨论定稿):

  • fetch 拦截层(新模块,核心机制):在宿主 Node 进程内包一层 globalThis.fetch。仅当请求目标 origin 精确等于"当前模型的上游 origin"(取自 ctx.model.baseUrl)时,改写成 http://127.0.0.1:<会话端口>/bili/<原URL>;其余一切流量原样放行。永不改写已带 /bili/ 前缀的 URL;非 http(s) 协议放行;提供卸载函数与防双重包装标记
  • 插件胶水:session_start 时从插件文件自身路径解析包根(<root>/dist/agent/pi.js → 上两级),用 process.execPath spawn node <root>/dist/index.js daemon --fresh --json --parent-pid <pid> → 解析 JSON 得 origin → 安装拦截器 → 现有工具注册/header 盖章逻辑复用(proxyBase 改由 daemon 输出提供而非 detectProxyBase
  • marker 门控bili plugin install pi --native(或等价开关)写 marker 文件;无 marker 时行为与现状完全一致
  • e2e 可行性验证先行:真实 pi 实测——patch globalThis.fetch 能否拦到 provider 请求、SSE 流式响应是否正常回传。这是全设计唯一未验证的承重假设;若不成立,回 探索如何发布为native模式 #513 报告并带替代方案,不硬推
  • 单测:拦截器 URL 匹配/改写纯逻辑(string/URL/Request 输入、非 http 协议、防双包、排除规则)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions