Skip to content

Projects(项目基础接口) ​

这一页讲 Project 的生命周期写入面(创建 / 更新 / 归档 / 恢复 / 复制)、基础读取面和成员管理面:创建与维护 Project、列出 Project、读取详情、列出会话、查询事件、订阅事件流、维护成员。

Project 级的派生结果、收件箱、Agent 启用和设置覆盖各有自己的页面,请从总览进入。

什么时候需要看这页 ​

  • 你要创建、更新、归档、恢复或复制一个 manual Project。
  • 你要列出当前账号可访问的 Project。
  • 你要查看某个 Project 下有哪些会话。
  • 你要按顺序查询 Project Event,或用 SSE 持续订阅。
  • 你要给 Project 增加或移除 observer、deriver 成员。

如果你只是普通聊天接入,不需要看这页。普通客户端创建会话时不需要传任何 Project 字段。

如果你要基于某个 Project 开一个不污染主叙事的研究、整理或候选起草容器,请看 Temporary Conversations。那组接口会通过 POST /projects/:id/temporary-conversations 创建临时对话。

一个简单例子 ​

bash
# 列出当前账号可访问的 Project
curl 'http://localhost:3000/projects?status=active&limit=20'

# 读取某个 Project 下的会话
curl 'http://localhost:3000/projects/proj_main/sessions'

# 从头开始查询 Project Event
curl 'http://localhost:3000/projects/proj_main/events?after=0&limit=100'

先理解几个词 ​

词这里的意思
Project工作区内的会话联动边界。一个 Project 下可以有多个 Session
session_default服务端为单个 Session 自动创建的 Project,区别于手动创建的 manual
Project EventProject 范围内的事件摘要日志,带单调递增的 sequence
after事件查询游标。只返回 sequence 大于该值的事件
observer只读成员。能看 Project、Session 摘要、事件和派生结果,不能写
deriver派生成员。能写派生结果和收件箱条目,不能改主 Session
subject成员主体。可以是一个账号(account),也可以是一个 Client(client)

响应格式说明 ​

这组接口不使用通用的 data 包裹。列表接口返回 items 加游标字段,详情接口直接返回对象,成员写接口返回 { "item": ... }。这是这组路由的既有契约,本页示例以实际响应为准。

公共类型 ​

Project ​

字段类型说明
idstringProject ID
workspace_idstring所属 Workspace
account_idstring所属账号(owner)
namestring名称
descriptionstring | null描述
kindstringsession_default 或 manual
statusstringactive 或 archived
rolestring当前调用方在这个 Project 中的角色:owner / observer / deriver
settings_overrideanyProject 级设置覆盖的原始 JSON
created_atinteger创建时间戳(ms)
updated_atinteger更新时间戳(ms)

Project Event ​

字段类型说明
idstring事件 ID
workspace_idstring所属 Workspace
project_idstring所属 Project
sequenceintegerProject 内单调递增序号,从 1 开始。查询和断点续传都用它
typestring事件类型,例如 floor.committed
visibilitystringproject / owner / internal
sourcestringapi / runtime_job / migration / system
actor_account_idstring | null触发事件的账号
actor_client_idstring | null触发事件的 Client
session_idstring | null关联会话
branch_idstring | null关联分支
floor_idstring | null关联楼层
page_idstring | null关联消息页
message_idstring | null关联消息
operation_log_idstring | null关联操作日志
correlation_idstring | null业务关联 ID
causation_event_idstring | null引发本事件的上游事件 ID
payloadany事件摘要数据,不含完整正文
created_atinteger创建时间戳(ms)

事件可见性按角色过滤:owner 能看到 project 和 owner 两档,observer 和 deriver 只能看到 project 一档。internal 不对外返回。

Project Member ​

字段类型说明
idstring成员记录 ID
workspace_idstring所属 Workspace
project_idstring所属 Project
account_idstring成员归属账号
rolestringowner / observer / deriver
statusstringactive 或 removed
subject_typestringaccount 或 client
subject_idstring成员主体 ID
client_idstring | null当主体是 Client 时的 Client ID
created_by_account_idstring | null操作者账号
created_by_client_idstring | null操作者 Client
created_atinteger创建时间戳(ms)
updated_atinteger更新时间戳(ms)

列出 Project ​

http
GET /projects

查询参数 ​

参数类型必填默认值说明
rolestring否-按角色过滤:owner / observer / deriver
statusstring否activeactive 或 archived
limitinteger否50每页条数,最大 200
cursorstring否-上一页返回的 next_cursor

响应 200 ​

json
{
  "items": [
    {
      "id": "proj_main",
      "workspace_id": "ws_default_default-admin",
      "account_id": "default-admin",
      "name": "Campfire Project",
      "description": null,
      "kind": "manual",
      "status": "active",
      "role": "owner",
      "settings_override": {},
      "created_at": 1735689600000,
      "updated_at": 1735689600000
    }
  ],
  "next_cursor": null
}

next_cursor 不为 null 时,把它作为下一次请求的 cursor 即可翻页。

示例 ​

bash
curl 'http://localhost:3000/projects?role=observer'

读取 Project 详情 ​

http
GET /projects/:id

需要 project.read 权限。owner、observer、deriver 都可以读。

响应 200 ​

直接返回 Project 对象。

错误 ​

状态码error.code说明
403project_access_denied当前角色没有读取权限
404project_not_foundProject 不存在,或当前调用方不是成员
409project_archivedProject 已归档

非成员访问时统一返回 404 project_not_found,不暴露资源存在性。

创建 Project ​

http
POST /projects

创建一个 manual Project,归属当前调用方账号,并自动写入一条 owner 成员记录。创建会记录 project.create 操作日志,并向 Project 发出 project.lifecycle.created 事件。

session_default Project 由服务端在创建 Session 时自动生成,不通过这个接口创建。

请求体 ​

字段类型必填说明
namestring是Project 名称,1–200 字符,首尾空白会被去除
workspace_idstring否目标 Workspace。省略时落在当前账号的默认 Workspace
descriptionstring | null否描述,最长 2000 字符
settingsobject | null否Project 级设置覆盖,原样存储。审计日志只记录脱敏摘要

请求示例 ​

bash
curl -X POST http://localhost:3000/projects \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Research Container",
    "description": "candidate drafts",
    "settings": { "model": "gpt" }
  }'

响应 201 ​

直接返回 Project 对象,kind 为 manual,role 为 owner。

错误 ​

状态码error.code说明
400project_name_requiredname 为空
404workspace_not_found指定的 workspace_id 不存在或不属于当前账号
409workspace_archived目标 Workspace 已归档

更新 Project ​

http
PATCH /projects/:id

需要 project.manage_settings 权限(owner)。只更新请求体中出现的字段,至少要提供一个。记录 project.update 操作日志并发出 project.lifecycle.updated 事件。

请求体 ​

字段类型必填说明
namestring否新名称,1–200 字符
descriptionstring | null否新描述。传 null 清空
settingsobject | null否覆盖设置。传 null 清空为 {}

三个字段全部省略时返回 400。

响应 200 ​

直接返回更新后的 Project 对象。

错误 ​

状态码error.code说明
400project_update_empty没有提供任何可更新字段
400project_name_requiredname 传了但为空
403project_access_denied当前角色不能改设置
404project_not_foundProject 不存在或不可见
409project_archivedProject 已归档

归档与恢复 Project ​

http
POST /projects/:id/archive
POST /projects/:id/restore

需要 project.write 权限(owner)。归档把 status 置为 archived 并记录归档时间;恢复置回 active。归档会记录 project.archive 操作日志与 project.lifecycle.archived 事件,恢复对应 project.restore 与 project.lifecycle.restored。

session_default Project 不能归档。归档事件在状态改写前写入,保证事件链不会因为归档而中断。

响应 200 ​

直接返回操作后的 Project 对象。

错误 ​

状态码error.code说明
403project_access_denied当前角色不能写
404project_not_foundProject 不存在或不可见
409project_session_default_immutablesession_default Project 不能归档
409project_not_archived恢复一个并未归档的 Project

复制 Project ​

http
POST /projects/:id/duplicate

需要 project.manage_settings 权限(owner)。只复制元数据(name / description / settings)到同一个 Workspace 下的新 manual Project,不复制 Session、事件和成员。新 Project 归当前调用方账号所有,并写入 owner 成员记录。记录 project.duplicate 操作日志并发出 project.lifecycle.created 事件。

源 Project 即使已归档也可以复制,复制出的副本为 active。

请求体 ​

字段类型必填说明
namestring否副本名称。省略时用 <源名称> (副本)

响应 201 ​

直接返回新建的 Project 对象。

错误 ​

状态码error.code说明
403project_access_denied当前角色不能复制
404project_not_found源 Project 不存在或不可见

列出 Project 下的会话 ​

http
GET /projects/:id/sessions

查询参数 ​

参数类型必填默认值说明
statusstring否-active 或 archived
limitinteger否50每页条数,最大 200
cursorstring否-上一页返回的 next_cursor

响应 200 ​

json
{
  "items": [
    {
      "id": "sess_001",
      "workspace_id": "ws_default_default-admin",
      "project_id": "proj_main",
      "title": "Campfire",
      "status": "active",
      "created_at": 1735689600000,
      "updated_at": 1735689600000
    }
  ],
  "next_cursor": null
}

这里返回的是会话摘要,不包含会话完整配置。需要完整会话对象时,再调用 GET /sessions/:id。

查询 Project Event ​

http
GET /projects/:id/events

需要 project.observe 权限。

查询参数 ​

参数类型必填默认值说明
afterinteger否0只返回 sequence 大于该值的事件
typesstring否-事件类型过滤,逗号分隔,例如 floor.committed,session.archived
session_idstring否-只看某个会话的事件。该会话必须属于这个 Project
limitinteger否100每页条数,最大 500

响应 200 ​

json
{
  "items": [
    {
      "id": "pev_001",
      "workspace_id": "ws_default_default-admin",
      "project_id": "proj_main",
      "sequence": 12,
      "type": "floor.committed",
      "visibility": "project",
      "source": "api",
      "actor_account_id": "default-admin",
      "actor_client_id": null,
      "session_id": "sess_001",
      "branch_id": "main",
      "floor_id": "floor_012",
      "page_id": null,
      "message_id": null,
      "operation_log_id": "op_034",
      "correlation_id": null,
      "causation_event_id": null,
      "payload": { "floor_no": 12 },
      "created_at": 1735689600000
    }
  ],
  "next_after": 12,
  "has_more": false
}

轮询时把上一次的 next_after 作为下一次的 after 即可,不会漏也不会重。

示例 ​

bash
curl 'http://localhost:3000/projects/proj_main/events?after=12&types=floor.committed'

订阅 Project Event 流 ​

http
GET /projects/:id/events/stream

以 SSE(Server-Sent Events,服务器持续向客户端推送文本事件的 HTTP 长连接)返回事件。需要 project.observe 权限。

查询参数 ​

参数类型必填说明
afterinteger否断点续传游标。也可以改用 Last-Event-ID 请求头传同样的值
typesstring否事件类型过滤,逗号分隔
session_idstring否只订阅某个会话的事件

流格式 ​

连接建立后,服务端先补发 after 之后的全部历史事件,再切换到实时推送。每个事件块为:

text
id: 13
event: floor.committed
data: {"id":"pev_002","sequence":13, ...}
  • id 行是事件 sequence。客户端断线重连时把最后收到的值通过 Last-Event-ID 带回即可续传。
  • data 行是与 GET /projects/:id/events 相同结构的事件 JSON。
  • 服务端每 15 秒发送一行 : heartbeat 注释保持连接。
  • 流内部出错时会发送 event: error,data 为 { "code", "message" }。

示例 ​

bash
curl -N 'http://localhost:3000/projects/proj_main/events/stream?after=0'

错误 ​

状态码error.code说明
404project_not_foundProject 不存在或不可见
503feature_unavailable服务端未启用事件流

列出成员 ​

http
GET /projects/:id/members

响应 200 ​

json
{
  "items": [
    {
      "id": "pm_001",
      "workspace_id": "ws_default_default-admin",
      "project_id": "proj_main",
      "account_id": "acc_observer",
      "role": "observer",
      "status": "active",
      "subject_type": "account",
      "subject_id": "acc_observer",
      "client_id": null,
      "created_by_account_id": "default-admin",
      "created_by_client_id": null,
      "created_at": 1735689600000,
      "updated_at": 1735689600000
    }
  ]
}

添加成员 ​

http
POST /projects/:id/members

只有 owner 可以调用。通过成员接口只能添加 observer 和 deriver,owner 身份由 Project 归属决定,不通过这组接口授予。

请求体 ​

字段类型必填说明
rolestring是observer 或 deriver
account_idstring二选一以账号为主体添加。等价于 subject_type=account
subject_typestring二选一account 或 client,与 subject_id 一起使用
subject_idstring二选一主体 ID

account_id 与 subject_type + subject_id 必须提供其中一组。

请求示例 ​

bash
curl -X POST http://localhost:3000/projects/proj_main/members \
  -H 'Content-Type: application/json' \
  -d '{
    "account_id": "acc_observer",
    "role": "observer"
  }'

响应 200 ​

json
{
  "item": {
    "id": "pm_001",
    "project_id": "proj_main",
    "account_id": "acc_observer",
    "role": "observer",
    "status": "active",
    "subject_type": "account",
    "subject_id": "acc_observer",
    "client_id": null,
    "workspace_id": "ws_default_default-admin",
    "created_by_account_id": "default-admin",
    "created_by_client_id": null,
    "created_at": 1735689600000,
    "updated_at": 1735689600000
  }
}

错误 ​

状态码error.code说明
400project_member_role_not_supported成员接口只支持 observer 和 deriver
400project_member_owner_role_conflict不能把 owner 添加为成员,也不能降级 owner
400project_member_subject_invalidsubject_type 不是 account 或 client
400project_member_default_client_owner_conflictowner 的默认 Client 不能再作为成员添加
404project_member_client_not_found主体 Client 不存在
409project_member_role_conflict该主体已经持有成员角色
409project_member_client_not_found主体 Client 已被禁用

移除成员 ​

http
DELETE /projects/:id/members/:subject_type/:subject_id

subject_type 为 account 或 client。另有一条旧路径继续可用:

http
DELETE /projects/:id/members/:account_id

旧路径等价于 subject_type=account。

响应 200 ​

json
{
  "item": {
    "id": "pm_001",
    "role": "observer",
    "status": "removed",
    "subject_type": "account",
    "subject_id": "acc_observer",
    "project_id": "proj_main",
    "workspace_id": "ws_default_default-admin",
    "account_id": "acc_observer",
    "client_id": null,
    "created_by_account_id": "default-admin",
    "created_by_client_id": null,
    "created_at": 1735689600000,
    "updated_at": 1735689700000
  }
}

错误 ​

状态码error.code说明
400project_member_owner_remove_not_supported不能通过成员接口移除 owner
404project_member_not_found成员不存在

相关页面 ​