fix: auto-detect Vercel for chat history path#436
Conversation
On Vercel, /var/task is read-only at runtime. ChatHistoryPath() now auto-detects Vercel via IsVercel() and defaults to /tmp/chat_history.json when no explicit DS2API_CHAT_HISTORY_PATH is set. Manual env var still works as explicit override.
|
@waiwaic is attempting to deploy a commit to the cjack's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @CJackHwang 👋 首先非常感谢你创建并维护 ds2api 这个项目,它帮了大忙! 🙏 我最近在 Vercel 上部署时遇到了 chat history 写入失败的问题( 不过有个小顾虑想跟你讨论一下——有朋友提醒我,Vercel Serverless 环境下的
所以当前这个修复虽然解决了 不知道你怎么看这个方向?如果你觉得需要更完善的持久化方案(比如集成 Vercel KV、Vercel Blob Storage,或者提供文档说明让用户在 Vercel 上使用外部存储),我也很乐意进一步贡献 PR 😊 期待你的反馈,再次感谢你的出色工作! |
说来挺有趣的,我用Vercel这么多年但从来没有用过任何外部存储的功能,在本项目里我一直都默认Vercel部署是属于“功能限制版”的状态,没有做太多深入的维护,主打的一个兼容和基础场景使用,毕竟免费版的active cpu time 只有4h,大量使用好像也不太现实,而维护Vercel的持久化似乎很麻烦。如果Vercel部署能使用外部存储那么本项目甚至都可以完全抛弃环境变量的配置方式了,毕竟当初就是为了方便在这个平台上使用才做的 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@waiwaic 很感谢你的贡献,现在看起来功能似乎完全正常了 |
Summary
On Vercel,
/var/taskis read-only at runtime. The chat history module previously tried to create directories under/var/task/data/, which fails with:Fix
Modified
ChatHistoryPath()ininternal/config/paths.goto auto-detect Vercel via the existingIsVercel()function. When running on Vercel and no explicitDS2API_CHAT_HISTORY_PATHenv var is set, it now defaults to/tmp/chat_history.json(the only writable directory on Vercel Serverless).If the user explicitly sets
DS2API_CHAT_HISTORY_PATH, that value is still respected as an override.Changes
internal/config/paths.go: +5 lines inChatHistoryPath()Verification
go build -o /dev/null ./cmd/ds2api/passesdata/chat_history.json