读取文件版本

更新时间:
复制 MD 格式

使用 GetItemVersion 接口按 versionId 读取一个历史版本的内容,不再传 itemId 或版本序号。

前提条件

  • 已创建 AgentStorage 实例且状态为 normal,并获取实例访问地址(endpoint)和实例名。

  • 已创建 API Key。

  • 版本操作使用精确 Scope,scope 的四级字段(appId、tenantId、agentId、runId)全部必填,不支持通配符 *。

  • 读取版本内容时设置 view=full。

  • 公共请求头与认证方式参见使用 API。

请求参数

字段

类型

必填

说明

versionId

string

是

要读取的历史版本 ID

view

string

否

默认 basic;读取内容时传 full

请求示例

使用 API Key 认证时,通过 x-ots-instancename 和 x-ots-apikey 请求头传入实例名和 API Key。

curl -X POST https://<endpoint>/GetItemVersion \
  -H "x-ots-instancename: <instance-name>" \
  -H "x-ots-apikey: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "memoryfile",
  "memoryStoreName": "agent_files",
  "scope": {
    "appId": "app-001",
    "tenantId": "user-001",
    "agentId": "assistant",
    "runId": "session-001"
  },
  "versionId": "<version-id>",
  "view": "full"
}'

响应

文本版本在 view=full 时通过 content 返回正文;二进制版本通过 contentBase64 返回标准 Base64 编码内容,并返回 mediaType。

{
  "type": "memoryfile",
  "versionId": "<version-id>",
  "itemId": "mem_01M2Z...",
  "scope": { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "run-001" },
  "operation": "modified",
  "path": "/profile/preferences.md",
  "content": "# 用户偏好\n\n- 喜欢美式咖啡\n",
  "contentSha256": "40556ec6...",
  "contentSizeBytes": 37,
  "createdAt": "2026-09-20T09:03:24Z"
}