Skip to content

Commit fef846a

Browse files
authored
build(protocol): make @openclaw/gateway-protocol publishable to npm (#111664)
* build(protocol): make @openclaw/gateway-protocol publishable to npm * chore(mxc): align package version with release train * fix(release): support gateway-only core packages
1 parent 8e40acb commit fef846a

16 files changed

Lines changed: 719 additions & 74 deletions

.github/workflows/openclaw-npm-release.yml

Lines changed: 159 additions & 39 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ apps/swabble/build/
247247

248248
# Generated protocol schema (produced via pnpm protocol:gen)
249249
dist/protocol.schema.json
250+
packages/gateway-protocol/protocol.schema.json
250251
.ant-colony/
251252

252253
# Eclipse

extensions/mxc/npm-shrinkwrap.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/mxc/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openclaw/mxc-sandbox",
3-
"version": "2026.6.11",
3+
"version": "2026.7.2",
44
"description": "OpenClaw MXC sandbox execution plugin for MXC-capable hosts",
55
"repository": {
66
"type": "git",
@@ -24,10 +24,10 @@
2424
"minHostVersion": ">=2026.6.11"
2525
},
2626
"compat": {
27-
"pluginApi": ">=2026.6.11"
27+
"pluginApi": ">=2026.7.2"
2828
},
2929
"build": {
30-
"openclawVersion": "2026.6.11",
30+
"openclawVersion": "2026.7.2",
3131
"bundledDist": false,
3232
"staticAssets": [
3333
{
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Changelog — @openclaw/gateway-protocol
2+
3+
Wire-protocol and schema contracts for the OpenClaw Gateway (WebSocket JSON-RPC-style
4+
frames, handshake, and method/event payload schemas). Protocol version is negotiated
5+
per connection via `minProtocol`/`maxProtocol`. This log covers the wire protocol
6+
version and the additive schema surface. Dates are authoring dates (2026).
7+
8+
## Unreleased
9+
10+
- Rename structured-question item `id` to `questionId` and flatten keyed answer arrays.
11+
- Slim worker and session-catalog payloads to the active wire contract.
12+
- Remove dead protocol surfaces and add since-vintage metadata to retained schemas and methods.
13+
14+
## Protocol v4 (current)
15+
16+
Introduced 2026-05-07 (commit `330ba1f`). The stable, current wire version.
17+
18+
Wire contract:
19+
- Frame envelopes: `req` / `res` / `event`, discriminated on `type`.
20+
- Handshake: client sends `ConnectParams` (advertises `minProtocol`/`maxProtocol`,
21+
client identity, `caps`, `commands`, `permissions`, `role`/`scopes`, optional signed
22+
`device` identity, and an `auth` bag: token / bootstrapToken / deviceToken / password /
23+
approvalRuntimeToken / agentRuntimeIdentityToken).
24+
- Server replies `hello-ok` with the negotiated `protocol`, server identity, the live
25+
`features` map (`methods`, `events`, `capabilities`), initial `snapshot`, minted `auth`
26+
device tokens, and connection `policy` (maxPayload / maxBufferedBytes / tickIntervalMs).
27+
- Server events: `tick` heartbeat and `shutdown` notice; event frames may carry `seq`
28+
and `stateVersion` for ordered state sync.
29+
30+
Changed vs v3:
31+
- `hello-ok` handshake replaced the single `canvasHostUrl` string with a
32+
`pluginSurfaceUrls` map (canvas generalized into arbitrary plugin surfaces). This
33+
field change is the breaking bump behind v4.
34+
- Later additively extended (no bump) with `controlUiTabs` (plugin-declared Control UI
35+
tabs) and multi-`deviceTokens` in the handshake auth block.
36+
37+
Compatibility window (`version.ts`):
38+
- `MIN_CLIENT_PROTOCOL_VERSION = 4` — general clients must speak v4.
39+
- `MIN_NODE_PROTOCOL_VERSION = 3` and `MIN_PROBE_PROTOCOL_VERSION = 3` — authenticated
40+
nodes and lightweight probes are accepted at N-1 (v3) to stay manageable during
41+
rolling upgrades. Added 2026-07-06 (#101109).
42+
- A transient v5 (2026-05-16, `07f05e9`) renamed `inboundTurnKind` -> `inboundEventKind`;
43+
it was reverted the next day (2026-05-17, `ad155fb`, "restore v4 message action
44+
protocol"). v5 never shipped as a stable ceiling; v4 remains current.
45+
46+
## Protocol v3
47+
48+
Baseline wire version. Present since repo genesis (2026-04-21) as an inline literal in
49+
`protocol-schemas.ts`; extracted into `version.ts` unchanged on 2026-05-04 (`2949171`).
50+
The first externally-relevant version — there is no 2->3 bump in tracked history.
51+
52+
Established the still-current shape: `req`/`res`/`event` frame envelopes, the
53+
`ConnectParams` -> `hello-ok` handshake with protocol negotiation, `snapshot` state sync,
54+
and the founding method/event families: sessions, agent chat, cron, devices, nodes,
55+
channels, config, commands, logs-chat, exec-approvals, plugin-approvals, secrets, push,
56+
wizard. (v3 `hello-ok` carried `canvasHostUrl`; v4 replaced it — see above.)
57+
58+
## Schema surface history
59+
60+
Additive method/event/schema families added over time. Pure refactors, test-only, and
61+
docs commits are omitted. The package was extracted from `src/gateway/protocol` to
62+
`packages/gateway-protocol` on 2026-05-29 (#87797); paths before that date lived under
63+
the old tree.
64+
65+
### 2026-04 (v3 baseline era)
66+
67+
- Ship baseline families: frames/handshake, sessions, agent chat, cron, devices, nodes,
68+
channels, config, commands, logs-chat, exec-approvals, plugin-approvals, secrets, push,
69+
wizard, snapshot, primitives, agents-models-skills.
70+
- Add WhatsApp `replyToMode` quoting (#62305).
71+
- Add browser realtime Talk and transports — origin of the talk/voice families.
72+
- Add Control UI PWA web push support (#44590).
73+
- Add plugins and artifacts schema modules.
74+
- Add OpenClaw SDK package and authenticated iOS background presence beacon (#73330).
75+
76+
### 2026-05
77+
78+
- Add environments discovery RPCs (#74867) and task-ledger RPCs (#74847) — tasks family.
79+
- Add unified Talk gateway sessions, realtime active-run control, and typed `sessionKey`
80+
on the wake protocol.
81+
- Add SDK `tools.invoke` RPC; extend cron with agentId filtering (#77602), run
82+
diagnostics (#75928), and direct job lookup.
83+
- Add Skill Workshop gateway methods: proposal files, revision requests, persisted origin.
84+
- Add core session goals (#87469).
85+
- Add heartbeat flag on agent event broadcast (#80610), warm-MCP effective inventory, and
86+
plugin approval action metadata.
87+
- Harden auth/device identity: bind approval access to requester metadata (#81380);
88+
require approval for setup-code device pairing (#81292); scope Talk session to resolver.
89+
- Introduce and revert transient protocol v5 (`07f05e9` / `ad155fb`).
90+
91+
### 2026-06
92+
93+
Enhancement-only month (no new schema modules):
94+
- Extend cron with command jobs, compact list responses (#93395), and an on-exit
95+
schedule kind that fires when a watched command exits.
96+
- Forward-port fast-Talks auto mode (#85104); add session workspace rail (#92856).
97+
98+
### 2026-07 (largest expansion)
99+
100+
- Add terminal family: `terminal.*` RPC methods/events, detach/reattach with output
101+
replay, `terminal.list`/`terminal.text`, and file uploads into terminals (#107364).
102+
- Add managed git worktrees: lifecycle create/provision/snapshot/restore/GC (#100535),
103+
new-session-in-worktree (#100788), session worktree targeting and branch listing
104+
(#103432); add read-only `agents.workspace` browsing RPCs (#100738).
105+
- Add audit family: metadata-only message audit events (#103903), native-search audit
106+
correlation (#98704), and audit-activity schema.
107+
- Add `tts.speak` returning synthesized audio inline (#100770).
108+
- Add cooperative host suspension / gateway-suspend prepare/status/resume RPCs (#103618).
109+
- Add durable approvals: persisted operator approvals (#103579), typed cross-surface
110+
approval actions (#103679), approval-id, and the durable-approvals stack (#104837).
111+
- Add cloud-workers stack: durable environments + lifecycle RPCs (#104401), worker bundle
112+
+ SSH bootstrap + admission handshake (#104532), authenticated worker protocol with
113+
minted credentials (#104688), durable transcript commit (#104809), live-event streaming
114+
(#105275), inference proxy (#105719), and session placement/dispatch (#106332).
115+
- Add session catalog: sessions-catalog + sessions-create with external-session
116+
pagination unification (#104717).
117+
- Add fs family: `sessions.files.set` hash-CAS writes (#104757) and gateway/node folder
118+
browsing (#105114).
119+
- Add node-hosted plugins — dynamic tools, MCP servers, skills (#90431) — plus node
120+
invoke/presence protocol schemas.
121+
- Add migrations family: log-migration protocol schemas and Codex/Claude memory import
122+
(#106406).
123+
- Add durable device rename for human-friendly device names (#94517).
124+
- Add follow-up task suggestions (#102422) and task-suggestions schema.
125+
- Add cron event triggers via polled condition-watcher scripts (#101195) and native
126+
mobile Automations parity (#106355).
127+
- Add system-agent conversational onboarding (#99935); rename `crestodian.*` methods to
128+
`openclaw.chat` / `openclaw.setup.*` (2026-07-14, `a6a0716`).
129+
- Add typed structured questions / `ask_user` with live option cards (#109922, #110242)
130+
and the questions schema module.
131+
- Add ui-command / screen-tool Control UI layout control and capability-gated
132+
`show_widget` inline web chat widgets (#101840).
133+
- Add direct watch/watchOS node connect to Gateway (#102893); widen node/probe protocol
134+
acceptance to N-1 (#101109).
135+
136+
## Notes for external versioning
137+
138+
- Post-v4 changes are additive except: the transient v5 rename (reverted, net-zero) and
139+
the 2026-07-14 `crestodian.*` -> `openclaw.*` method rename. The renamed feature was
140+
introduced only 9 days earlier (2026-07-05, #99935), never left the v4 window, and
141+
predates public publish, so no released method name changed under v4.
142+
- `schema/types.ts` was removed 2026-07-11 (#103679); it re-exported compile-time type
143+
aliases only and has no wire impact.

packages/gateway-protocol/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 OpenClaw Foundation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# `@openclaw/gateway-protocol`
2+
3+
Typed schemas, inferred TypeScript types, and runtime validators for the OpenClaw
4+
Gateway WebSocket protocol.
5+
6+
The current wire protocol is version 4. General clients must use v4; authenticated
7+
node clients and lightweight probes may use the N-1 window during rolling upgrades.
8+
See the [Gateway protocol specification](https://docs.openclaw.ai/gateway/protocol)
9+
for transport, authentication, roles, scopes, and complete frame examples.
10+
11+
## Versioning
12+
13+
Package versions follow the OpenClaw calendar release train:
14+
`YYYY.M.PATCH`, with the same prerelease suffix when applicable. A package version
15+
therefore identifies the OpenClaw source release that produced the schemas; it is
16+
not the wire protocol number.
17+
18+
The wire protocol integer is versioned separately. Its current value is exported
19+
as `PROTOCOL_VERSION` from `@openclaw/gateway-protocol/version`. Gateway protocol
20+
changes are additive first. An incompatible wire change requires an explicit
21+
protocol-version decision and coordinated client follow-through. See
22+
[`CHANGELOG.md`](./CHANGELOG.md) for the wire and schema history.
23+
24+
## Install
25+
26+
```bash
27+
npm install @openclaw/gateway-protocol
28+
```
29+
30+
## Entry points
31+
32+
- `@openclaw/gateway-protocol` exports runtime validators, selected schemas, error
33+
formatting, and their TypeScript types. This is the main TypeBox-backed entry.
34+
- `@openclaw/gateway-protocol/schema` exports the TypeBox schema graph, including
35+
the `ProtocolSchemas` registry used by generators.
36+
- `@openclaw/gateway-protocol/frame-guards` exports dependency-free structural
37+
guards for gateway event and response envelopes.
38+
- `@openclaw/gateway-protocol/client-info` exports client ID, mode, and capability
39+
registries plus normalization helpers.
40+
- `@openclaw/gateway-protocol/connect-error-details` exports structured connect
41+
error readers and recovery metadata.
42+
- `@openclaw/gateway-protocol/gateway-error-details` exports helpers for reading
43+
structured details from general gateway errors.
44+
- `@openclaw/gateway-protocol/startup-unavailable` exports startup retry constants
45+
and helpers.
46+
- `@openclaw/gateway-protocol/version` exports the current and minimum accepted
47+
protocol versions.
48+
49+
The `frame-guards`, `client-info`, `connect-error-details`, `gateway-error-details`,
50+
`startup-unavailable`, and `version` entry points are TypeBox-free. Prefer them when
51+
a browser bundle only needs envelope dispatch, handshake constants, or reconnect
52+
policy. This also avoids runtime compilation in CSP-sensitive consumers. The root
53+
and `schema` entry points provide the full validation surface and depend on TypeBox.
54+
55+
## Validate an inbound frame
56+
57+
The compiled validators are callable type guards. Their `errors` property contains
58+
the most recent validation errors.
59+
60+
```ts
61+
import { formatValidationErrors, validateRequestFrame } from "@openclaw/gateway-protocol";
62+
63+
const frame: unknown = JSON.parse(inboundText);
64+
65+
if (!validateRequestFrame(frame)) {
66+
throw new Error(formatValidationErrors(validateRequestFrame.errors));
67+
}
68+
69+
console.log(frame.id, frame.method);
70+
```
71+
72+
`validateRequestFrame` validates the request envelope. Dispatch code must also use
73+
the validator for the selected method's `params`; the root entry point exports those
74+
validators as `validate*Params` functions.
75+
76+
## Guard an event without TypeBox
77+
78+
Use the lightweight guards when code only needs safe frame discrimination. They
79+
check dispatch-critical envelope fields and intentionally allow additive payload
80+
fields.
81+
82+
```ts
83+
import { isGatewayEventFrame } from "@openclaw/gateway-protocol/frame-guards";
84+
85+
const frame: unknown = JSON.parse(inboundText);
86+
87+
if (isGatewayEventFrame(frame)) {
88+
console.log(frame.event, frame.seq);
89+
}
90+
```
91+
92+
## Build handshake version and capability fields
93+
94+
Protocol levels and client capabilities live in TypeBox-free entry points.
95+
96+
```ts
97+
import { GATEWAY_CLIENT_CAPS } from "@openclaw/gateway-protocol/client-info";
98+
import { MIN_CLIENT_PROTOCOL_VERSION, PROTOCOL_VERSION } from "@openclaw/gateway-protocol/version";
99+
100+
const handshake = {
101+
minProtocol: MIN_CLIENT_PROTOCOL_VERSION,
102+
maxProtocol: PROTOCOL_VERSION,
103+
caps: [GATEWAY_CLIENT_CAPS.TOOL_EVENTS],
104+
};
105+
```
106+
107+
Nodes and probes use `MIN_NODE_PROTOCOL_VERSION` and
108+
`MIN_PROBE_PROTOCOL_VERSION`, respectively. A capability advertises client support;
109+
it does not grant authorization.
110+
111+
## Contract notes
112+
113+
### Session identifiers
114+
115+
Several identifier names coexist because they identify different things:
116+
117+
- `key` is the established logical session selector used by most `sessions.*`
118+
CRUD, send, subscription, patch, reset, delete, compaction, and usage methods.
119+
A key can be canonicalized or resolved within an agent's session store.
120+
- `sessionKey` names the same logical routing identity where the contract needs to
121+
make that meaning explicit. `chat.*`, session file and diff APIs, transcript
122+
branch/rewind/fork APIs, agent events, and channel delivery payloads use this
123+
spelling.
124+
- `sessionId` is the opaque stored transcript or runtime instance ID. Session
125+
results may return it beside a key. Talk, terminal, worker, and selected channel
126+
protocols also use `sessionId` for their own concrete session instances; do not
127+
substitute a logical session key there.
128+
129+
Follow each method schema rather than converting fields based on their spelling.
130+
`sessions.resolve` is the explicit bridge when a caller has a key, raw session ID,
131+
label, or parent/agent scope.
132+
133+
### Intentionally open fields
134+
135+
The schema graph is strict by default, but roughly 60 fields intentionally use
136+
`Type.Unknown()` passthroughs. The main clusters are transport-owned channel
137+
payloads, logs-chat message and attachment passthrough, worker and node tool
138+
arguments/results, and the dynamic `config.schema` response. Frame `params`,
139+
`payload`, and error `details` are also open at the envelope layer because the
140+
selected method, event, or error code owns their concrete shape.
141+
142+
Do not treat these fields as validated domain objects. Narrow them at their owner
143+
boundary before reading nested values.
144+
145+
### Machine-readable schema
146+
147+
`protocol.schema.json` ships in the npm tarball as the generated machine-readable
148+
contract. It contains the frame union, named schema definitions, and core method
149+
metadata. It is generated during `prepack` and is not committed to the repository.
150+
151+
### Method discovery
152+
153+
The `hello-ok.features.methods` list is conservative discovery, not a complete
154+
enumeration of every callable method. It reflects the methods the connected
155+
Gateway intentionally advertises. Core-internal, role-specific, plugin-provided,
156+
or otherwise non-advertised methods can have valid schemas without appearing in
157+
that list. Clients should use discovery to enable optional UI, not to reject an
158+
otherwise documented method contract.

packages/gateway-protocol/npm-shrinkwrap.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)