Skip to content

feat(adapters): 添加 Vercel AI SDK 记忆中间件#470

Open
Qiyuanqiii wants to merge 1 commit into
TencentCloud:mainfrom
Qiyuanqiii:feat/issue-235-ai-sdk-memory-middleware
Open

feat(adapters): 添加 Vercel AI SDK 记忆中间件#470
Qiyuanqiii wants to merge 1 commit into
TencentCloud:mainfrom
Qiyuanqiii:feat/issue-235-ai-sdk-memory-middleware

Conversation

@Qiyuanqiii

Copy link
Copy Markdown

关联 Issue

Related to #235

背景

#235 已确认 #316 为通用 Gateway client 基线、#372 为 MCP bridge 基线。本 PR 不引入新的 Gateway client、MCP server 或通用 Adapter SDK,而是补充一个尚未覆盖的平台原生接入方式:Vercel AI SDK v6 LanguageModelV3Middleware

功能

  • 新增 createAiSdkMemoryMiddleware()
  • transformParams:根据最后一条用户文本召回记忆,并追加到当前用户消息末尾。
  • wrapGenerate:在最终非工具调用响应后写入 user/assistant turn。
  • wrapStream:收集 text delta,在流正常结束后写入记忆。
  • 同一轮工具调用链只执行一次 recall,后续模型 step 复用结果。
  • recall/capture 均为 fail-open,Gateway 故障不会中断模型响应。
  • 重复执行时替换自身生成的 memory block,不产生重复注入。
  • 保留多模态 user message 中的 file part。
  • 提供独立 npm 子路径:
    @tencentdb-agent-memory/memory-tencentdb/ai-sdk
  • 独立构建产物约 4.78 KB,不加载 OpenClaw、SQLite 或完整插件入口。

范围边界

本 PR 不包含:

  • 新的 Gateway HTTP client
  • MCP server
  • Codex/Claude/Dify adapter
  • TdaiCore 或 Gateway server 修改
  • 新的运行时依赖
  • CI 或基础设施修改

验证命令

npm test -- src/adapters/ai-sdk/memory-middleware.test.ts
npm test
npm run build
node --check dist/ai-sdk.mjs
node --input-type=module -e "import('@tencentdb-agent-memory/memory-tencentdb/ai-sdk').then(m => console.log(typeof m.createAiSdkMemoryMiddleware))"
npm pack --dry-run --ignore-scripts
git diff --check origin/main...HEAD

验证结果

  • Targeted tests:1 file / 5 tests passed
  • Full tests:5 files / 72 tests passed
  • Build:passed
  • AI SDK 子路径导入:passed
  • npm package:包含 dist/ai-sdk.mjs 和接入文档
  • Diff check:passed

验证截图

image

@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program!
We have successfully received your submission. The program is currently in full swing, and we will complete the Code Review for you as soon as possible. Please keep an eye on the status notifications for this PR so you can follow up promptly once the review feedback is provided.
Thanks again for your contribution and open-source spirit! 🚀

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.

2 participants