@dieulc/pi-office-protocol

中文文档
0.5.1发布于 2026/10/31MITTypeScriptES Module近 30 天下载 2186

Shared bridge wire protocol + office op catalog between the pi-office-bridge Pi extension and the pi-for-office task-pane add-in.

原始使用文档
文档目录4 节
  1. Messages
  2. Protocol v2 (breaking)
  3. Protocol v3 (additive)
  4. Version & capabilities

@dieulc/pi-office-protocol

Shared WebSocket wire protocol between the pi-for-office task-pane add-in (packages/add-in/src/bridge/) and the Pi bridge extension (packages/bridge-extension/).

Holding the protocol in one package keeps the two halves of the bridge in lockstep — a breaking change is one commit, and the end-to-end interop test (packages/bridge-extension/tests/pane-interop.mjs) proves both sides speak the same format at runtime.

Messages

  • Client → Server: hello, ping, tool_result, user_message, status, pane_state, abort
  • Server → Client: welcome, pong, tool_call, agent_message (delta/final), tool_activity, error

Protocol v2 (breaking)

v2 adds document identity and targeting so the bridge can serve several open documents of the same host app:

  • hello.document: DocumentIdentity — required. { id, name, source } where id is a stable local hash (url_sha256:… / wps_path_sha256:…) or null for unsaved documents, and source is one of "document.url", "wps.activeWorkbook.fullName", "unknown". Raw URLs/paths are never sent.
  • pane_state (client → server) — best-effort { focused?, visible?, activeAt? } so document: "active" can resolve to the document the user is looking at.
  • tool_call.documentId?: string — the document the call was routed to (echoed for logging and pane-side validation).
  • agent_message final gains promptId?: string — correlates a reply with the pane prompt that triggered it.
  • OFFICE_TARGET_PARAM = "document" — the tool-argument key that selects a target; the server strips it before forwarding the call to a pane.

A v1 client is rejected at the handshake with protocol_mismatch; update both halves together (protocol 0.4.0, bridge 0.4.0).

Protocol v3 (additive)

v3 makes a pane prompt feel live and interruptible. It is additive: a v2 pane is still accepted and simply receives final replies only.

  • agent_message delta frames are now actually produced: while the agent answers a pane prompt the server streams { type: "agent_message", kind: "delta", text, promptId?, messageId? }, coalesced to stay under MAX_TEXT_CHARS. Deltas are display-only: the concatenation is not guaranteed to equal the final text, so the pane replaces its live buffer with kind: "final" when it arrives.
  • abort (client → server) — { type: "abort", promptId? } stops the run answering that prompt (or whatever run is in flight for this pane when promptId is omitted). A v2 server ignores the frame, so a Stop button must stay usable if the reply keeps arriving.
  • MIN_SUPPORTED_PROTOCOL_VERSION = 2 and isProtocolVersionSupported() — the server accepts the whole [MIN_SUPPORTED_PROTOCOL_VERSION, BRIDGE_PROTOCOL_VERSION] window instead of demanding an exact match.
  • Deltas are only sent to panes whose hello.protocolVersion >= 3; the server never sends a delta to a v2 pane (which would drop it).

Update both halves together on a breaking change; an additive change may ship protocol-first (protocol 0.5.1, bridge 0.6.0).

Version & capabilities

BRIDGE_PROTOCOL_VERSION is bumped only on breaking message-shape changes. Additive fields keep both halves compatible:

  • welcome.serverVersion?: string — the bridge extension's package version.
  • welcome.capabilities?: BridgeCapability[] — currently "http-health" (the server answers GET /health with JSON metadata), "agent-deltas" (the server streams agent_message deltas), "client-abort" (the server honours the abort frame), and "manual-lifecycle" (the bridge stays off until /office connect; a client must not assume the 0.6 commands exist on a bridge without this capability). Prefer a capability check over a version comparison so a peer's features are discoverable at runtime.

Both are optional. An absent capabilities array (or absent serverVersion) means the peer is a legacy 0.1.0 bridge: clients must degrade gracefully (the live WebSocket status is still authoritative) instead of assuming the server is unreachable.

See src/protocol.ts for the typed shapes.

版本与发布记录

@dieulc/pi-office-protocol 共发布 6 个版本,首次发布于 2026/09/09;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.5.1latest2026/10/3113 天前
0.5.02026/09/191 个月前
0.4.02026/09/151 个月前
0.3.02026/09/132 个月前
0.2.02026/09/112 个月前
0.1.02026/09/092 个月前

关于 @dieulc/pi-office-protocol 的常见问题

@dieulc/pi-office-protocol 是什么?

Shared bridge wire protocol + office op catalog between the pi-office-bridge Pi extension and the pi-for-office task-pane add-in.

如何安装 @dieulc/pi-office-protocol?

在项目目录运行 npm install @dieulc/pi-office-protocol,或使用 pnpm add / yarn add / bun add。

@dieulc/pi-office-protocol 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dieulc/pi-office-protocol 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dieulc/pi-office-protocol 可以商用吗?

@dieulc/pi-office-protocol 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dieulc/pi-office-protocol 的下载量有多少?

根据 npm 官方下载统计,@dieulc/pi-office-protocol 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,186 次,日均约 73 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dieulc/pi-office-protocol 还在维护吗?

最新版本 0.5.1 发布于 2026/10/31(13 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/09/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。