Skip to content

Projects(项目基础接口)

这一页只讲 Project 的基础读取面和成员管理面:列出 Project、读取详情、列出会话、查询事件、订阅事件流、维护成员。

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

什么时候需要看这页

  • 你要列出当前账号可访问的 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_defaultmanual
statusstringactivearchived
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 能看到 projectowner 两档,observer 和 deriver 只能看到 project 一档。internal 不对外返回。

Project Member

字段类型说明
idstring成员记录 ID
workspace_idstring所属 Workspace
project_idstring所属 Project
account_idstring成员归属账号
rolestringowner / observer / deriver
statusstringactiveremoved
subject_typestringaccountclient
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
statusstringactiveactivearchived
limitinteger50每页条数,最大 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
GET /projects/:id/sessions

查询参数

参数类型必填默认值说明
statusstring-activearchived
limitinteger50每页条数,最大 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 权限。

查询参数

参数类型必填默认值说明
afterinteger0只返回 sequence 大于该值的事件
typesstring-事件类型过滤,逗号分隔,例如 floor.committed,session.archived
session_idstring-只看某个会话的事件。该会话必须属于这个 Project
limitinteger100每页条数,最大 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: errordata{ "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 可以调用。通过成员接口只能添加 observerderiver,owner 身份由 Project 归属决定,不通过这组接口授予。

请求体

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

account_idsubject_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成员接口只支持 observerderiver
400project_member_owner_role_conflict不能把 owner 添加为成员,也不能降级 owner
400project_member_subject_invalidsubject_type 不是 accountclient
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_typeaccountclient。另有一条旧路径继续可用:

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成员不存在

相关页面