npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-openai-responses-patcher

v0.1.0

Published

CLI patcher that rewrites pi's built-in openai-responses transport to use instructions and a stable prompt_cache_key.

Readme

pi-openai-responses-patcher

一个普通 npm CLI 包,用来自动定位本机已安装的 pi,并直接 patch 内建文件:

  • 目标文件 @earendil-works/pi-ai/dist/api/openai-responses.js
  • 将 system/developer prompt 改成走 instructions
  • input 里移除重复的 system/developer prompt
  • prompt_cache_key 策略可配置,默认保持 session 语义
  • 提供备份查看和最近备份回退能力

这个包的目标是把本机手工 patch 产品化,而不是新增一个 provider。

用法

npx pi-openai-responses-patcher
npx pi-openai-responses-patcher --list-backups
npx pi-openai-responses-patcher --restore

它会做什么

执行时会按下面顺序检查:

  1. 自动探测本机全局安装的 pi / @earendil-works/pi-ai
  2. 校验 @earendil-works/pi-ai 版本必须 >= 0.80.3
  3. 校验目标文件内容锚点必须匹配当前支持版本
  4. 通过后先备份目标文件,再写入 patch
  5. 如果已经 patch 过,则直接退出,不重复改写

如果版本或锚点不匹配,会拒绝 patch,并提示你“发布新支持版本”。

当前支持策略

  • 最低支持版本:0.80.3
  • 高于该版本时不会盲目 patch
  • 必须同时满足:
    • 版本门禁通过
    • 文件锚点门禁通过

这意味着后续 pi 升级导致目标实现变化时,需要为新版本发布新的 patcher 支持版本。

patch 行为

这个 patch 只修改 buildParams() 这一段行为,并插入少量辅助函数:

  • 读取 input 中的 system/developer prompt,写入顶层 instructions
  • 删除 input 中与 instructions 重复的 system/developer prompt
  • 默认保留 pi 当前更接近内建行为的 sessionprompt_cache_key
  • 可切换到 stable 模式,基于 provider + model + baseUrl + instructions + tools 指纹生成稳定 prompt_cache_key
  • cacheRetention === "none" 时,不设置 prompt_cache_key

prompt_cache_key 模式

通过环境变量控制:

PI_OPENAI_RESPONSES_PATCHER_CACHE_KEY_MODE=session

支持值:

  • session 默认值;保留当前 pi 内建更接近的语义,继续使用 sessionId
  • stable 改成稳定指纹,适合你明确想做跨 session 的前缀缓存复用

回退与备份

列出当前可恢复的备份:

pi-openai-responses-patcher --list-backups

恢复最近一次备份:

pi-openai-responses-patcher --restore

行为说明:

  • 每次 patch 前都会生成一个备份文件,格式类似:
.../openai-responses.js.bak.1751440000000
  • --restore 会恢复最新的备份文件
  • 恢复前会先把当前文件再备份一次,避免误回退后无法撤销

本地开发

npm run check:syntax
npm test

发布建议

发布后即可直接使用:

npx pi-openai-responses-patcher

如果后续 pi 升级导致目标文件锚点变化:

  1. 更新本包版本
  2. 调整锚点与 patch 内容
  3. 重新发布对应支持版本