Skip to content

docs(zh): rewrite the server API reference - #3483

Open
liruifengv wants to merge 47 commits into
mainfrom
docs/server-api-reference
Open

docs(zh): rewrite the server API reference#3483
liruifengv wants to merge 47 commits into
mainfrom
docs/server-api-reference

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

Internal docs work — no linked issue.

Problem

The zh server API reference (docs/zh/reference/server-api.md) was a narrative walkthrough: endpoint coverage was partial, request/response shapes were described loosely in prose, WebSocket frames were only sketched, and there was no authoritative type index — readers had to cross-read source code to learn the actual wire shapes.

What changed

Rewrites docs/zh/reference/server-api.md as a complete typed reference, fact-checked against the current server implementation:

  • REST API: every mounted endpoint, grouped by domain (service, account, config, models & providers, workspaces & sessions, conversation, tasks, terminal, extensions, files & misc). Each endpoint entry carries: description, triggered WS event (linked to its frame entry), request-body table, ResponseType<T> response table with per-field optionality/nullability, non-zero business codes, and a pretty-printed response example.
  • WebSocket frames: the full frame inventory under named types — control frames (ServerSystemMessage / ClientControlMessage), event.* protocol events, agent events (AgentEvent), and transcript frames (TranscriptResetEvent / TranscriptOpsEvent) — with durability/volatility and delivery semantics. Dead protocol surface is documented as such instead of being presented as live.
  • Type appendix: T-* entries split into REST types and WS types (event payloads + transcript family), each as a TypeScript definition block using the system's canonical type names, with "optional" (?) vs "nullable" (| null) spelled out per field.
  • Fixes the now-dangling walkthrough anchor link in docs/zh/reference/kimi-command.md.

Intentionally left for follow-ups:

  • The 完整错误码 section is a TODO placeholder; the full error-code table lands separately.
  • The English mirror (docs/en/reference/server-api.md) is untouched and will be synced separately.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue — N/A, internal docs work.
  • I have added tests that prove my feature works — N/A, docs-only; cd docs && npm run build passes.
  • Ran gen-changesets skill, or this PR needs no changeset. — No changeset: docs-only change that never enters the shipped artifact.
  • Ran gen-docs skill, or this PR needs no doc update. — This PR is the doc update.

…e entries

Rewrite docs/zh/reference/server-api.md as a field-level reference: minimal prose, structured tables for every endpoint's body/query/data and non-zero codes, plus one compact example per endpoint. Covers all 104 v1 endpoints (the 101 previously documented plus the new workspaces add-dir route and the two experimental file-history routes), 15 v2 endpoints, and all 80 WS frame types, with a new WebSocket lifecycle section (handshake, one turn, interaction branches, reconnect recovery) and a shared-type dictionary at the bottom. The English page is intentionally left unchanged for now.

Corrected against the current server:
- GET /sessions/{id} last_seq is now the real event watermark (the old page claimed it was always 0)
- the heartbeat behavior is documented (the old page claimed the server sends no heartbeats and never disconnects idle connections)
- terminal WS frames are documented as a dead protocol (declared in AsyncAPI, never produced or consumed by the server)
- profile agent_config now lists tower_mode / tower_base
- message no longer lists the phantom prompt_id / parent_message_id fields (declared in schema, never produced)
- the 40911 undo error data shape is marked engine-dependent instead of a fixed object
- subscribe payload gains the watch_fs field, and watch_fs_add/remove payload gains runtime_id alongside recursive
- event delivery scopes are documented precisely: event.question.*/event.approval.* are session events, event.fs.changed goes only to watchers

Moved:
- the "用 API 驱动一个会话" walkthrough moves to docs/zh/guides/web.md as a new section (guide-style narrative belongs in a guide; the reference page keeps a link); docs/zh/reference/kimi-command.md now points at the new anchor

Omitted:
- per-endpoint narrative paragraphs whose facts now live in the same entry's body/data/error tables (compressed, no fact lost)
- the rollback-buffer note on the terminal object (it described output replay over the terminal WS channel, which is a dead protocol and is now documented as such)
- the fixed 40911 undo data shape {reason, requestedCount, undoableCount} (unverifiable; the server passes through engine details whose shape is not fixed)
Remove the "用 API 驱动一个会话" walkthrough instead of relocating it to guides/web.md (per review direction). The reference page and kimi-command.md no longer link to it.
Define ResponseType<T> once in the conventions section and rewrite all 122 endpoint entries from "**data**(code = 0)" to "**返回**:ResponseType<T>". The WS event-envelope concept (frame outer fields) is a separate concept and stays.
Remove the 40001 details note and the non-zero-code-with-data specials table from the ResponseType section; each affected endpoint entry already carries (or now carries) its own data shape inline, and 40001 mentions in non-zero-code lines now state the { path, message }[] details shape.
…business domains

Merge the flat per-registry sections into business domains (服务与账号 / 工作区与会话 / 对话 / 任务与终端 / 扩展 / 文件与其他); former sections become bold dividers inside each domain. v2 sessions and v2 MCP fold into their business domains, with the /api/v1 vs /api/v2 path prefix called out as the version marker. Endpoint headings and anchors are unchanged.
New per-endpoint shape: domain H2 with intro and one merged endpoint table; endpoint H3 with description, 请求体 table (when present), 响应体 type + table, non-zero codes, and a pretty-printed 响应示例. The REST 端点 wrapper heading is dropped in favor of an unheaded lead-in.
@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7056aeb

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

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

commit: 7056aeb

@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: 27b8518068

ℹ️ 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".

::: warning 注意
本页描述的 REST 与 WebSocket API 为实验性特性:不保证接口稳定性,端点、字段与事件类型可能随任何版本更改。集成时请以你所用版本服务的 `/openapi.json` 与 `/asyncapi.json` 文档为准。
:::
此页面记录 kap-server 的 API 接口类型,分为 REST API 与 WebSocket 事件流两种。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the English mirror in the same change

This rewrite changes the Chinese page's structure, endpoint inventory, and type reference while leaving docs/en/reference/server-api.md on the older partial walkthrough, so users receive materially different API contracts depending on locale. Update the English mirror alongside this page rather than deferring it to a follow-up.

AGENTS.md reference: docs/AGENTS.md:L16-L21

Useful? React with 👍 / 👎.

::: warning 注意
本页描述的 REST 与 WebSocket API 为实验性特性:不保证接口稳定性,端点、字段与事件类型可能随任何版本更改。集成时请以你所用版本服务的 `/openapi.json` 与 `/asyncapi.json` 文档为准。
:::
此页面记录 kap-server 的 API 接口类型,分为 REST API 与 WebSocket 事件流两种。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore the experimental API compatibility warning

For readers building integrations against this reference, the rewrite removes the only warning that these REST and WebSocket contracts are experimental and may change in any release, along with the direction to prefer the running server's /openapi.json and /asyncapi.json schemas. Nothing in this change graduates the API to a stable contract, so presenting the new exhaustive type catalog without that caveat can cause consumers to rely on unsupported compatibility guarantees; retain the warning and live-schema guidance.

AGENTS.md reference: docs/AGENTS.md:L23-L28

Useful? React with 👍 / 👎.

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