Skip to content

docs: split and rewrite the server API reference - #4841

Merged
wbxl2000 merged 4 commits into
release/2026-11-12from
docs/server-api-rewrite
Nov 11, 2026
Merged

wbxl2000 merged 4 commits into
release/2026-11-12from
docs/server-api-rewrite

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

服务 API 文档(docs/{zh,en}/reference/server-api.md)是一个 2500 行的单页,170 多个标题,客户端最需要的 WebSocket 协议压在页尾,几种帧的字段挤在单个长段落里,基本不可读;并且有多处说法和当前实现不一致。这个 PR 把它拆成一组页面重写,内容以当前实现为准,作为这一版对外发布的服务 API 文档。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

页面结构(中英文镜像,导航挂在参考手册「服务 API【测试版】」下):

 docs/{zh,en}/reference/
-└── server-api.md                 # 一页包含全部内容
+├── server-api.md                 # 概览:地址、鉴权、信封、错误码、分页、入门流程、各页入口
+├── server-api-conversation.md    # 会话与对话:WebSocket 协议和客户端流程
+├── server-api-sessions.md        # 会话接口:/api/v1/sessions 下的 REST 接口和 /api/v2/sessions
+├── server-api-service.md         # 服务与配置接口:登录、远程控制、配置、模型、插件、工作区、上传、搜索、/api/v2/mcp
+└── server-api-files.md           # 文件接口:会话、工作区、本机文件,以及二进制与流式端点

「会话与对话」是新写的客户端协议指南,按客户端的使用顺序组织:连接与心跳、订阅会话(含订阅后的帧序)、帧的投递范围和顺序、轮次与条目、实时更新的处理规则、提交输入(开始还是排队、幂等、插话)、停止 / 撤销 / 压缩、审批与提问、任务、Agent 状态、断线恢复、全局事件。三个参考页沿用原文的接口说明,改成统一格式:一句话说明、参数表、三个以上字段的响应用表格、错误码列表放最后。

写法上:短句、一段一件事;不用破折号串补充说明;字段说明进表格;术语按 docs/AGENTS.md 统一(Skill、main agent、subagent、轮次等)。

按当前实现修正的内容

每一条都对照了 packages/kap-server 和 packages/agent-core-v2 的代码。主要的:

  • 订阅后的帧序写清楚:应答 → 待处理交互 → 各 agent 的 task.list 和状态帧 → turns(异步,可能晚于实时状态帧);对话帧不会早于 turns。
  • 补齐此前没写的客户端规则:心跳断开的关闭码和实际时机、同一连接上命令的处理顺序、会话被空闲回收或 :reload 后订阅仍有效且会重发 turns、会话归档或删除时订阅被移除、帧的发送顺序保证、usage 按 250 毫秒合并、prompt_id 幂等的细节、插话的可用条件、停止一轮后队列里的输入会继续、多客户端回应同一交互(40902 / 40404)、任务输出的续传合并规则、重连后应丢弃本地轮次等。
  • 全局事件按代码重写:补上 event.session.deleted、event.config.warning、event.plugin.changed、event.capability.changed 和各事件的 payload;删掉服务端并不发出的 event.session.status_changed;删掉「目前没有会话删除事件」。
  • prompts/{prompt_id}:abort 删掉不存在的 40903(已结束或不存在时返回 40402);:abort 无论是否在运行都返回 { aborted: true }。
  • :compact 删掉不存在的 compaction.* 帧,改为客户端实际看到的 agent.compacting、system 轮次和 compaction.cancelled 通知;目标接口的 goal.updated 同理改为 goal 帧。
  • 提交输入时 metadata 和 swarm_mode 会生效(原文说不生效);设置的应用顺序和生效时机写清楚。
  • 补上实现里有、文档没写的参数和字段:会话动作 :delete、创建会话的 environment_id / environment_cwd、profile 的 tower_mode / tower_base、目标的预算字段、供应商的 api_key_env、:import_registry 的 credential_env、能力安装的 stopRunningProcesses、文件条目的 is_directory、会话 fs:list / fs:read 的 allow_external_symlinks 等;删掉 schema 声明了但实现从不返回的文件条目字段(git_status 等)。
  • profile 接口的 metadata 是整体替换,不是原文说的「合并」;保留键被忽略、已存的值保留这一句对应 fix(kap-server): drop reserved metadata keys from session profile updates #4842 的修复。
  • 各接口补上路由实际会返回、原文漏掉的错误码;删掉 untrust 接口后面从别处复制残留的错误码。
  • /api/v2/mcp 的 cwd 位置、shutdown 路由的挂载条件、插件市场按平台过滤的规则、:refresh_oauth 只刷新 managed:kimi-code 等描述按代码改准。

删掉或合并的内容

没有删除事实,只合并了重复:

  • POST /api/v1/config 请求体参数表和 GET 响应表逐字段重复,改为链接,只单列请求体特有的两条规则。
  • 会话文件系统 16 个动作共有的 40001 / 40401、工作区文件接口共有的 40001 / 40410,合并到「共同规则」。
  • 入门流程里重复的信封说明、几处「见上文」式的重复描述,改为链接。
  • 合并在一个标题下的多个接口(/api/v2/sessions:archive 与 :restore、v2 MCP 的 CRUD 和 OAuth 接口)拆成每个接口一节,共用的错误码按适用范围分到各接口。

其他

  • 原文页内链接用的接口锚点(#post-apiv1sessions... 风格)在 VitePress 下本来就打不开,全部改为 VitePress 实际生成的锚点;config-files.md 里指向这一页和另外两处坏掉的锚点一并修正。
  • 旧单页的书签和外部深链接:概览页加载时,锚点在本页不存在、但属于旧单页的标题,就跳转到它在子页面的新位置(docs/.vitepress/theme/serverApiLegacyAnchors.ts,映射表由旧页面的全部标题生成,改名和拆分的章节手动对应)。
  • 「服务 API」的 H1 和导航标签加了「【测试版】」/「(Beta)」,这是维护者明确要求的改动(docs/AGENTS.md 默认不改 H1 和导航标签)。

从 docs/zh/reference/server-api-conversation.md 开始读。

Behavior Changes and Affected Users

None。只改文档和文档站导航,产物代码未改动。

对文档读者的影响:原来指向 server-api.md#某个接口 或某个章节的书签和外部链接,会自动跳转到子页面的新位置;仓库内所有指向这一页的链接都已更新,并用和 VitePress 相同的锚点规则逐个校验。vitepress build 通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6ebacde

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T13:48:24.217937Z 6ebacde New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@6ebacde
npx https://pkg.pr.new/@moonshot-ai/kimi-code@6ebacde

commit: 6ebacde

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e92cc712ce

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread docs/en/reference/server-api.md Resolved
Comment thread docs/en/reference/server-api.md Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45163e33ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000
wbxl2000 force-pushed the docs/server-api-rewrite branch from 45163e3 to 6ebacde Compare November 11, 2026 13:44
@wbxl2000
wbxl2000 merged commit 9759415 into release/2026-11-12 Nov 11, 2026
14 checks passed
@wbxl2000
wbxl2000 deleted the docs/server-api-rewrite branch November 11, 2026 13:49
Grapedge added a commit that referenced this pull request Nov 12, 2026
* fix(agent-core-v2): truncate oversized skill content (#4834)

* fix(kap-server): bind the main agent when a session is created (#4839)

* fix(kap-server): bind the main agent when a session is created

* fix(kap-server): reject a profile on prompt submissions

* fix(kap-server): reject a profile change through the session profile

* fix(kap-server): wait for model configuration before binding a new session

* fix(agent-core-v2): deduplicate restored task notifications (#4836)

* fix(agent-core-v2): deduplicate restored task notifications

* chore: add notification replay fix changeset

* fix(agent-core-v2): preserve task notifications after prompt-only crashes

* fix(agent-core-v2): complete prompts before ending turns

* test: align lifecycle snapshots with prompt completion order

* fix(agent-core-v2): settle all prompts during turn finalization

* fix(kap-server): drop reserved metadata keys from session profile updates (#4842)

* fix(kap-server): drop reserved metadata keys from session profile updates

* fix(kap-server): keep stored reserved metadata keys on profile updates

* docs: split and rewrite the server API reference (#4841)

* docs: split and rewrite the server API reference

* docs: redirect old server API anchors to the split pages

* docs: describe profile metadata as a replacement

* docs: mark question responses as answered-only

* fix(kap-server): avoid heartbeat timeout after scheduling stalls (#4823)

* fix(kap-server): avoid heartbeat timeout reaping after stalls or clock jumps

* fix(kap-server): grace heartbeat window for short scheduling stalls

* fix(kap-server): treat only clearly late heartbeats as scheduling stalls

* fix(kap-server): time heartbeats on a monotonic clock and drain queued input before reaping

---------

Co-authored-by: Kimi Code (Grok Bot) <[email protected]>

* fix(kap-server): undo a turn only once when requests race (#4846)

* docs: describe heartbeat stall handling (#4849)

* docs: describe heartbeat stall handling

* docs: explain the monotonic clock in the heartbeat notes

* fix(agent-core-v2): acquire session lock before loop restoration (#4848)

* fix(agent-core-v2): acquire session lock before loop restoration

* chore: add session lock lifecycle changeset

* fix(agent-core-v2): hold session lock through loop restoration

- add an operation-scoped lease to the session run gate
- hold it across loop initialization, reset, and pending drains
- cover idle timeout and release ordering

* fix(agent-core-v2): keep the output of stopped tool calls (#4854)

* fix(kap-server): drop the partial reply of a retried step (#4855)

* fix(agent-core-v2): dedupe historical tool schemas (#4862)

* fix(agent-core-v2): dedupe historical tool schemas

* chore: add duplicate tool schema changeset

* fix(agent-core-v2): preserve first tool schema declaration

* fix(agent-core-v2): remind on changed tool schemas

* fix(agent-core-v2): block stale tool schema calls

* fix(agent-core-v2): normalize registry schemas in pending checks

* fix(agent-core-v2): import registry tool metadata type

* fix(agent-core-v2): preserve abort handling during validation

* fix(agent-core-v2): refine validation hook preparation

* fix(agent-core-v2): make validation hooks synchronous

* fix(agent-core-v2): preserve tool result notes on fork (#4867)

* fix(agent-core-v2): preserve tool result notes on fork

* chore: add fork tool result note changeset

* fix(agent-core-v2): scope tool result note restoration to forks

* fix(agent-core-v2): normalize inherited tool result notes

* fix(agent-core-v2): isolate fork note restoration

* feat(tui): sweep running titles toward text and add KIMI_CODE_TUI_ANIMATION_FPS (#4843) (#4870)

* chore: sync web dist from code-app (#4871)

code-app: 8ab17294e031323186d357d121c5360b8353900e

Co-authored-by: kimi-agent-bot <[email protected]>

* ci: release packages (#4835)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: sync web dist from code-app

code-app: 5835391dac3a2b9e0c65ffbd418f0d6042a7adb2

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: qer <[email protected]>
Co-authored-by: Kimi Code (Grok Bot) <[email protected]>
Co-authored-by: grapedge <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant