openclaw-client 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +183 -6
- package/dist/client.d.ts +46 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +86 -14
- package/dist/types.d.ts +170 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +115 -14
- package/src/protocol.schema.json +801 -79
- package/src/types.ts +198 -17
package/README.md
CHANGED
|
@@ -51,26 +51,133 @@ interface OpenClawClientConfig {
|
|
|
51
51
|
clientVersion?: string; // Client version (default: '1.0.0')
|
|
52
52
|
platform?: string; // Platform name (default: 'web')
|
|
53
53
|
mode?: string; // Client mode (default: 'ui')
|
|
54
|
+
connectTimeoutMs?: number; // Timeout for connect handshake (default: 120000)
|
|
55
|
+
requestTimeoutMs?: number; // Timeout for RPC requests (default: 30000)
|
|
56
|
+
connectParams?: Partial<ConnectParams>; // Extra fields merged into handshake
|
|
54
57
|
}
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
#### Methods
|
|
58
61
|
|
|
62
|
+
**Connection Management**
|
|
59
63
|
- `connect(): Promise<HelloOk>` - Connect and authenticate
|
|
60
64
|
- `disconnect(): void` - Disconnect from Gateway
|
|
61
65
|
- `isConnected(): boolean` - Check connection status
|
|
66
|
+
- `getConnectionId(): string | null` - Get the current connection ID
|
|
62
67
|
- `addEventListener(listener): () => void` - Add event listener
|
|
68
|
+
|
|
69
|
+
**Configuration**
|
|
63
70
|
- `getConfig(params?): Promise<any>` - Get configuration
|
|
64
71
|
- `setConfig(params): Promise<any>` - Update configuration
|
|
72
|
+
- `getConfigSchema(params?): Promise<ConfigSchemaResponse>` - Get configuration schema
|
|
73
|
+
- `applyConfig(params): Promise<any>` - Apply configuration changes
|
|
74
|
+
- `patchConfig(params): Promise<any>` - Patch configuration
|
|
75
|
+
|
|
76
|
+
**Sessions**
|
|
65
77
|
- `listSessions(params?): Promise<any>` - List sessions
|
|
66
78
|
- `deleteSession(params): Promise<any>` - Delete a session
|
|
67
|
-
- `
|
|
79
|
+
- `previewSessions(params): Promise<any>` - Preview sessions
|
|
80
|
+
- `resolveSession(params): Promise<any>` - Resolve session
|
|
81
|
+
- `patchSession(params): Promise<any>` - Patch session
|
|
82
|
+
- `resetSession(params): Promise<any>` - Reset session
|
|
83
|
+
- `compactSession(params): Promise<any>` - Compact session
|
|
84
|
+
- `getSessionsUsage(params?): Promise<any>` - Get session usage
|
|
85
|
+
|
|
86
|
+
**Agents**
|
|
87
|
+
- `listAgents(params?): Promise<AgentsListResult>` - List available agents
|
|
88
|
+
- `createAgent(params): Promise<AgentsCreateResult>` - Create agent
|
|
89
|
+
- `updateAgent(params): Promise<AgentsUpdateResult>` - Update agent
|
|
90
|
+
- `deleteAgent(params): Promise<AgentsDeleteResult>` - Delete agent
|
|
91
|
+
- `getAgentIdentity(params?): Promise<AgentIdentityResult>` - Get agent identity
|
|
92
|
+
- `sendToAgent(params): Promise<any>` - Send a message to agent
|
|
93
|
+
- `waitForAgent(params): Promise<any>` - Wait for agent run to complete
|
|
94
|
+
|
|
95
|
+
**Agent Files**
|
|
68
96
|
- `getAgentFile(params): Promise<AgentsFilesGetResult>` - Get agent file
|
|
69
97
|
- `listAgentFiles(params): Promise<AgentsFilesListResult>` - List agent files
|
|
70
98
|
- `setAgentFile(params): Promise<AgentsFilesSetResult>` - Update agent file
|
|
99
|
+
|
|
100
|
+
**Models**
|
|
71
101
|
- `listModels(params?): Promise<ModelsListResult>` - List available models
|
|
102
|
+
|
|
103
|
+
**Messaging**
|
|
104
|
+
- `send(params): Promise<any>` - Send a message
|
|
105
|
+
- `poll(params): Promise<any>` - Send a poll
|
|
106
|
+
- `wake(params): Promise<any>` - Wake the system
|
|
107
|
+
|
|
108
|
+
**Chat**
|
|
109
|
+
- `getChatHistory(params): Promise<any>` - Get chat history
|
|
110
|
+
- `sendChat(params): Promise<any>` - Send chat message
|
|
111
|
+
- `abortChat(params): Promise<any>` - Abort chat
|
|
112
|
+
- `injectChat(params): Promise<any>` - Inject chat message
|
|
113
|
+
|
|
114
|
+
**Wizard**
|
|
115
|
+
- `startWizard(params?): Promise<WizardStartResult>` - Start wizard
|
|
116
|
+
- `wizardNext(params): Promise<WizardNextResult>` - Wizard next step
|
|
117
|
+
- `cancelWizard(params): Promise<any>` - Cancel wizard
|
|
118
|
+
- `getWizardStatus(params): Promise<WizardStatusResult>` - Get wizard status
|
|
119
|
+
|
|
120
|
+
**Channels & Talk**
|
|
121
|
+
- `getChannelsStatus(params?): Promise<ChannelsStatusResult>` - Get channels status
|
|
122
|
+
- `logoutChannel(params): Promise<any>` - Logout from channel
|
|
123
|
+
- `setTalkMode(params): Promise<any>` - Set talk mode
|
|
124
|
+
- `getTalkConfig(params?): Promise<TalkConfigResult>` - Get talk config
|
|
125
|
+
|
|
126
|
+
**Authentication**
|
|
127
|
+
- `startWebLogin(params?): Promise<any>` - Start web login
|
|
128
|
+
- `waitForWebLogin(params?): Promise<any>` - Wait for web login
|
|
129
|
+
|
|
130
|
+
**Skills**
|
|
131
|
+
- `getSkillsStatus(params?): Promise<any>` - Get skills status
|
|
132
|
+
- `getSkillsBins(params?): Promise<SkillsBinsResult>` - Get skills bins
|
|
133
|
+
- `installSkill(params): Promise<any>` - Install skill
|
|
134
|
+
- `updateSkill(params): Promise<any>` - Update skill
|
|
135
|
+
|
|
136
|
+
**Cron Jobs**
|
|
137
|
+
- `listCronJobs(params?): Promise<{ jobs: CronJob[] }>` - List cron jobs
|
|
138
|
+
- `getCronStatus(params?): Promise<any>` - Get cron status
|
|
139
|
+
- `addCronJob(params): Promise<{ job: CronJob }>` - Add cron job
|
|
140
|
+
- `updateCronJob(params): Promise<{ job: CronJob }>` - Update cron job
|
|
141
|
+
- `removeCronJob(params): Promise<any>` - Remove cron job
|
|
142
|
+
- `runCronJob(params): Promise<any>` - Run cron job
|
|
143
|
+
- `getCronRuns(params): Promise<{ runs: CronRunLogEntry[] }>` - Get cron job runs
|
|
144
|
+
|
|
145
|
+
**Execution Approvals**
|
|
146
|
+
- `getExecApprovals(params?): Promise<ExecApprovalsSnapshot>` - Get exec approvals
|
|
147
|
+
- `setExecApprovals(params): Promise<ExecApprovalsSnapshot>` - Set exec approvals
|
|
148
|
+
- `getNodeExecApprovals(params): Promise<ExecApprovalsSnapshot>` - Get node exec approvals
|
|
149
|
+
- `setNodeExecApprovals(params): Promise<ExecApprovalsSnapshot>` - Set node exec approvals
|
|
150
|
+
- `requestExecApproval(params): Promise<any>` - Request exec approval
|
|
151
|
+
- `resolveExecApproval(params): Promise<any>` - Resolve exec approval
|
|
152
|
+
|
|
153
|
+
**Device Pairing**
|
|
154
|
+
- `listDevicePairings(params?): Promise<any>` - List device pairing requests
|
|
155
|
+
- `approveDevicePairing(params): Promise<any>` - Approve device pairing
|
|
156
|
+
- `rejectDevicePairing(params): Promise<any>` - Reject device pairing
|
|
157
|
+
- `removeDevicePairing(params): Promise<any>` - Remove paired device
|
|
158
|
+
- `rotateDeviceToken(params): Promise<any>` - Rotate device token
|
|
159
|
+
- `revokeDeviceToken(params): Promise<any>` - Revoke device token
|
|
160
|
+
|
|
161
|
+
**Node Management**
|
|
162
|
+
- `requestNodePairing(params): Promise<any>` - Request node pairing
|
|
163
|
+
- `listNodePairings(params?): Promise<any>` - List node pairing requests
|
|
164
|
+
- `approveNodePairing(params): Promise<any>` - Approve node pairing
|
|
165
|
+
- `rejectNodePairing(params): Promise<any>` - Reject node pairing
|
|
166
|
+
- `verifyNodePairing(params): Promise<any>` - Verify node pairing
|
|
167
|
+
- `renameNode(params): Promise<any>` - Rename node
|
|
168
|
+
- `listNodes(params?): Promise<any>` - List nodes
|
|
169
|
+
- `describeNode(params): Promise<any>` - Describe node
|
|
170
|
+
- `invokeNode(params): Promise<any>` - Invoke node command
|
|
171
|
+
- `testPush(params): Promise<PushTestResult>` - Test push notification to node
|
|
172
|
+
|
|
173
|
+
**Logs**
|
|
72
174
|
- `getLogTail(params?): Promise<LogsTailResult>` - Get log tail
|
|
73
|
-
|
|
175
|
+
|
|
176
|
+
**Updates**
|
|
177
|
+
- `updateRun(params): Promise<any>` - Update and run
|
|
178
|
+
|
|
179
|
+
**Generic**
|
|
180
|
+
- `call<T>(method, params?): Promise<T>` - Generic RPC method call for any method
|
|
74
181
|
|
|
75
182
|
### `ServerOpenClawClient`
|
|
76
183
|
|
|
@@ -94,17 +201,60 @@ Environment variables:
|
|
|
94
201
|
- `OPENCLAW_GATEWAY_URL` - Gateway URL (default: `http://localhost:18789`)
|
|
95
202
|
- `OPENCLAW_TOKEN` - Authentication token
|
|
96
203
|
|
|
97
|
-
## Type Generation
|
|
204
|
+
## Type Generation & Client Wrapper Maintenance
|
|
205
|
+
|
|
206
|
+
This package uses a deterministic process to keep types and client method wrappers in sync with the OpenClaw protocol schema.
|
|
98
207
|
|
|
99
|
-
|
|
208
|
+
### Step 1: Update the schema
|
|
100
209
|
|
|
101
|
-
|
|
210
|
+
Place the latest `protocol.schema.json` from the OpenClaw Gateway into `src/protocol.schema.json`.
|
|
211
|
+
|
|
212
|
+
### Step 2: Regenerate types
|
|
102
213
|
|
|
103
214
|
```bash
|
|
104
215
|
npm run generate:types
|
|
105
216
|
```
|
|
106
217
|
|
|
107
|
-
|
|
218
|
+
This runs `src/generate-openclaw-types.ts` which uses `json-schema-to-typescript` to compile every definition in the schema into TypeScript interfaces. The output is written to `src/types.ts` (auto-generated, do not edit manually).
|
|
219
|
+
|
|
220
|
+
### Step 3: Update client method wrappers
|
|
221
|
+
|
|
222
|
+
The method wrappers in `src/client.ts` follow a deterministic pattern derived from the type names in `src/types.ts`:
|
|
223
|
+
|
|
224
|
+
1. **Find all `*Params` types** - Each `*Params` interface represents an RPC method.
|
|
225
|
+
2. **Derive the method name** - Convert the type name to a dot-separated RPC method name:
|
|
226
|
+
- `ConfigGetParams` → `config.get`
|
|
227
|
+
- `SessionsListParams` → `sessions.list`
|
|
228
|
+
- `AgentsFilesGetParams` → `agents.files.get`
|
|
229
|
+
- `ExecApprovalsNodeSetParams` → `exec.approvals.node.set`
|
|
230
|
+
- Top-level methods like `SendParams`, `PollParams`, `WakeParams` → `send`, `poll`, `wake`
|
|
231
|
+
3. **Match result types** - If a corresponding `*Result` type exists (e.g. `AgentsListResult` for `AgentsListParams`), use it as the return type. Otherwise use `Promise<any>`.
|
|
232
|
+
4. **Choose a wrapper method name** - Use a readable camelCase name (e.g. `listSessions`, `getConfig`, `deleteAgent`).
|
|
233
|
+
5. **Default empty params** - If the `*Params` interface has no required fields (e.g. `interface ConfigGetParams {}`), default the parameter to `= {}`.
|
|
234
|
+
6. **Import and add** - Import the new Params/Result types at the top of `client.ts` and add the wrapper method.
|
|
235
|
+
|
|
236
|
+
**Skipped types:** Some `*Params` types are not RPC request methods but are used for node-side responses or event payloads (e.g. `NodeInvokeResultParams`, `NodeEventParams`). These are skipped.
|
|
237
|
+
|
|
238
|
+
### Full update workflow
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# 1. Drop in updated schema
|
|
242
|
+
cp /path/to/new/protocol.schema.json src/protocol.schema.json
|
|
243
|
+
|
|
244
|
+
# 2. Regenerate types
|
|
245
|
+
npm run generate:types
|
|
246
|
+
|
|
247
|
+
# 3. Update client wrappers (compare types.ts *Params exports against client.ts imports)
|
|
248
|
+
# - Add imports for any new *Params/*Result types
|
|
249
|
+
# - Add wrapper methods following the pattern above
|
|
250
|
+
# - Verify no existing types were removed/renamed
|
|
251
|
+
|
|
252
|
+
# 4. Build and verify
|
|
253
|
+
npm run build
|
|
254
|
+
|
|
255
|
+
# 5. Publish
|
|
256
|
+
npm publish
|
|
257
|
+
```
|
|
108
258
|
|
|
109
259
|
## Development
|
|
110
260
|
|
|
@@ -122,6 +272,33 @@ npm run build
|
|
|
122
272
|
npm publish
|
|
123
273
|
```
|
|
124
274
|
|
|
275
|
+
## Changelog
|
|
276
|
+
|
|
277
|
+
### 2.0.0
|
|
278
|
+
|
|
279
|
+
**Breaking Changes**
|
|
280
|
+
|
|
281
|
+
- **Connect handshake protocol** - The client now implements a challenge-response handshake. On connect, the gateway sends a `connect.challenge` event with a nonce before the client sends its `connect` request. This requires a compatible gateway version.
|
|
282
|
+
|
|
283
|
+
**New Features**
|
|
284
|
+
|
|
285
|
+
- **Configurable timeouts** - New `connectTimeoutMs` (default 120s) and `requestTimeoutMs` (default 30s) config options.
|
|
286
|
+
- **Connect params override** - New `connectParams` config option to merge additional fields into the handshake request (e.g. `device`, `caps`, `commands`).
|
|
287
|
+
- **New API methods:**
|
|
288
|
+
- `createAgent` / `updateAgent` / `deleteAgent` - Full agent CRUD
|
|
289
|
+
- `getSessionsUsage` - Session usage stats
|
|
290
|
+
- `getTalkConfig` - Talk configuration
|
|
291
|
+
- `removeDevicePairing` - Remove a paired device
|
|
292
|
+
- `testPush` - Test push notifications to a node
|
|
293
|
+
|
|
294
|
+
### 1.1.1
|
|
295
|
+
|
|
296
|
+
- Documentation updates.
|
|
297
|
+
|
|
298
|
+
### 1.1.0
|
|
299
|
+
|
|
300
|
+
- Initial public release with full Gateway RPC coverage.
|
|
301
|
+
|
|
125
302
|
## License
|
|
126
303
|
|
|
127
304
|
MIT
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentIdentityParams, AgentIdentityResult, AgentParams, AgentsFilesGetParams, AgentsFilesGetResult, AgentsFilesListParams, AgentsFilesListResult, AgentsFilesSetParams, AgentsFilesSetResult, AgentsListParams, AgentsListResult, AgentWaitParams, ChannelsLogoutParams, ChannelsStatusParams, ChannelsStatusResult, ChatAbortParams, ChatHistoryParams, ChatInjectParams, ChatSendParams, ConfigApplyParams, ConfigGetParams, ConfigPatchParams, ConfigSchemaParams, ConfigSchemaResponse, ConfigSetParams, ConnectParams, CronAddParams, CronJob, CronListParams, CronRemoveParams, CronRunLogEntry, CronRunParams, CronRunsParams, CronStatusParams, CronUpdateParams, DevicePairApproveParams, DevicePairListParams, DevicePairRejectParams, DeviceTokenRevokeParams, DeviceTokenRotateParams, EventFrame, ExecApprovalRequestParams, ExecApprovalResolveParams, ExecApprovalsGetParams, ExecApprovalsNodeGetParams, ExecApprovalsNodeSetParams, ExecApprovalsSetParams, ExecApprovalsSnapshot, HelloOk, LogsTailParams, LogsTailResult, ModelsListParams, ModelsListResult, NodeDescribeParams, NodeInvokeParams, NodeListParams, NodePairApproveParams, NodePairListParams, NodePairRejectParams, NodePairRequestParams, NodePairVerifyParams, NodeRenameParams, PollParams, SendParams, SessionsCompactParams, SessionsDeleteParams, SessionsListParams, SessionsPatchParams, SessionsPreviewParams, SessionsResetParams, SessionsResolveParams, SkillsBinsParams, SkillsBinsResult, SkillsInstallParams, SkillsStatusParams, SkillsUpdateParams, TalkModeParams, UpdateRunParams, WakeParams, WebLoginStartParams, WebLoginWaitParams, WizardCancelParams, WizardNextParams, WizardNextResult, WizardStartParams, WizardStartResult, WizardStatusParams, WizardStatusResult } from './types';
|
|
1
|
+
import type { AgentIdentityParams, AgentIdentityResult, AgentParams, AgentsCreateParams, AgentsCreateResult, AgentsDeleteParams, AgentsDeleteResult, AgentsFilesGetParams, AgentsFilesGetResult, AgentsFilesListParams, AgentsFilesListResult, AgentsFilesSetParams, AgentsFilesSetResult, AgentsListParams, AgentsListResult, AgentsUpdateParams, AgentsUpdateResult, AgentWaitParams, ChannelsLogoutParams, ChannelsStatusParams, ChannelsStatusResult, ChatAbortParams, ChatHistoryParams, ChatInjectParams, ChatSendParams, ConfigApplyParams, ConfigGetParams, ConfigPatchParams, ConfigSchemaParams, ConfigSchemaResponse, ConfigSetParams, ConnectParams, CronAddParams, CronJob, CronListParams, CronRemoveParams, CronRunLogEntry, CronRunParams, CronRunsParams, CronStatusParams, CronUpdateParams, DevicePairApproveParams, DevicePairListParams, DevicePairRejectParams, DevicePairRemoveParams, DeviceTokenRevokeParams, DeviceTokenRotateParams, EventFrame, ExecApprovalRequestParams, ExecApprovalResolveParams, ExecApprovalsGetParams, ExecApprovalsNodeGetParams, ExecApprovalsNodeSetParams, ExecApprovalsSetParams, ExecApprovalsSnapshot, HelloOk, LogsTailParams, LogsTailResult, ModelsListParams, ModelsListResult, NodeDescribeParams, NodeInvokeParams, NodeListParams, NodePairApproveParams, NodePairListParams, NodePairRejectParams, NodePairRequestParams, NodePairVerifyParams, NodeRenameParams, PollParams, PushTestParams, PushTestResult, SendParams, SessionsCompactParams, SessionsDeleteParams, SessionsListParams, SessionsPatchParams, SessionsPreviewParams, SessionsResetParams, SessionsResolveParams, SessionsUsageParams, SkillsBinsParams, SkillsBinsResult, SkillsInstallParams, SkillsStatusParams, SkillsUpdateParams, TalkConfigParams, TalkConfigResult, TalkModeParams, UpdateRunParams, WakeParams, WebLoginStartParams, WebLoginWaitParams, WizardCancelParams, WizardNextParams, WizardNextResult, WizardStartParams, WizardStartResult, WizardStatusParams, WizardStatusResult } from './types';
|
|
2
2
|
export interface OpenClawClientConfig {
|
|
3
3
|
gatewayUrl: string;
|
|
4
4
|
token: string;
|
|
@@ -6,6 +6,14 @@ export interface OpenClawClientConfig {
|
|
|
6
6
|
clientVersion?: string;
|
|
7
7
|
platform?: string;
|
|
8
8
|
mode?: ConnectParams['client']['mode'];
|
|
9
|
+
/** Timeout in ms for the connect handshake (default: 120000).
|
|
10
|
+
* Set this higher if device approval may take a while. */
|
|
11
|
+
connectTimeoutMs?: number;
|
|
12
|
+
/** Timeout in ms for regular RPC requests (default: 30000). */
|
|
13
|
+
requestTimeoutMs?: number;
|
|
14
|
+
/** Additional ConnectParams fields to merge into the handshake request
|
|
15
|
+
* (e.g. `device` for device identity, `caps`, `commands`). */
|
|
16
|
+
connectParams?: Partial<ConnectParams>;
|
|
9
17
|
}
|
|
10
18
|
export type EventListener = (event: EventFrame) => void;
|
|
11
19
|
export declare class OpenClawClient {
|
|
@@ -18,7 +26,13 @@ export declare class OpenClawClient {
|
|
|
18
26
|
private connectionId;
|
|
19
27
|
constructor(config: OpenClawClientConfig);
|
|
20
28
|
/**
|
|
21
|
-
* Connect to the OpenClaw Gateway and perform handshake
|
|
29
|
+
* Connect to the OpenClaw Gateway and perform handshake.
|
|
30
|
+
*
|
|
31
|
+
* The protocol flow is:
|
|
32
|
+
* 1. Open WebSocket connection
|
|
33
|
+
* 2. Gateway sends a `connect.challenge` event with a nonce
|
|
34
|
+
* 3. Client responds with a `connect` request (including auth token)
|
|
35
|
+
* 4. Gateway replies with `hello-ok` containing server info and snapshot
|
|
22
36
|
*/
|
|
23
37
|
connect(): Promise<HelloOk>;
|
|
24
38
|
/**
|
|
@@ -38,7 +52,8 @@ export declare class OpenClawClient {
|
|
|
38
52
|
*/
|
|
39
53
|
addEventListener(listener: EventListener): () => void;
|
|
40
54
|
/**
|
|
41
|
-
* Perform the connection handshake
|
|
55
|
+
* Perform the connection handshake after receiving the challenge.
|
|
56
|
+
* Uses connectTimeoutMs (default 120s) since device approval may take a while.
|
|
42
57
|
*/
|
|
43
58
|
private handshake;
|
|
44
59
|
/**
|
|
@@ -101,6 +116,18 @@ export declare class OpenClawClient {
|
|
|
101
116
|
* List available agents
|
|
102
117
|
*/
|
|
103
118
|
listAgents(params?: AgentsListParams): Promise<AgentsListResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Create agent
|
|
121
|
+
*/
|
|
122
|
+
createAgent(params: AgentsCreateParams): Promise<AgentsCreateResult>;
|
|
123
|
+
/**
|
|
124
|
+
* Update agent
|
|
125
|
+
*/
|
|
126
|
+
updateAgent(params: AgentsUpdateParams): Promise<AgentsUpdateResult>;
|
|
127
|
+
/**
|
|
128
|
+
* Delete agent
|
|
129
|
+
*/
|
|
130
|
+
deleteAgent(params: AgentsDeleteParams): Promise<AgentsDeleteResult>;
|
|
104
131
|
/**
|
|
105
132
|
* Get agent identity
|
|
106
133
|
*/
|
|
@@ -141,6 +168,10 @@ export declare class OpenClawClient {
|
|
|
141
168
|
* Compact session
|
|
142
169
|
*/
|
|
143
170
|
compactSession(params: SessionsCompactParams): Promise<any>;
|
|
171
|
+
/**
|
|
172
|
+
* Get session usage
|
|
173
|
+
*/
|
|
174
|
+
getSessionsUsage(params?: SessionsUsageParams): Promise<any>;
|
|
144
175
|
/**
|
|
145
176
|
* Send a message to agent
|
|
146
177
|
*/
|
|
@@ -181,6 +212,10 @@ export declare class OpenClawClient {
|
|
|
181
212
|
* Set talk mode
|
|
182
213
|
*/
|
|
183
214
|
setTalkMode(params: TalkModeParams): Promise<any>;
|
|
215
|
+
/**
|
|
216
|
+
* Get talk config
|
|
217
|
+
*/
|
|
218
|
+
getTalkConfig(params?: TalkConfigParams): Promise<TalkConfigResult>;
|
|
184
219
|
/**
|
|
185
220
|
* Get channels status
|
|
186
221
|
*/
|
|
@@ -285,6 +320,10 @@ export declare class OpenClawClient {
|
|
|
285
320
|
* Reject device pairing
|
|
286
321
|
*/
|
|
287
322
|
rejectDevicePairing(params: DevicePairRejectParams): Promise<any>;
|
|
323
|
+
/**
|
|
324
|
+
* Remove paired device
|
|
325
|
+
*/
|
|
326
|
+
removeDevicePairing(params: DevicePairRemoveParams): Promise<any>;
|
|
288
327
|
/**
|
|
289
328
|
* Rotate device token
|
|
290
329
|
*/
|
|
@@ -345,6 +384,10 @@ export declare class OpenClawClient {
|
|
|
345
384
|
* Invoke node command
|
|
346
385
|
*/
|
|
347
386
|
invokeNode(params: NodeInvokeParams): Promise<any>;
|
|
387
|
+
/**
|
|
388
|
+
* Test push notification to node
|
|
389
|
+
*/
|
|
390
|
+
testPush(params: PushTestParams): Promise<PushTestResult>;
|
|
348
391
|
/**
|
|
349
392
|
* Update and run
|
|
350
393
|
*/
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,aAAa,EACb,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,UAAU,EACV,yBAAyB,EACzB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,aAAa,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AM,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IAItD;;;OAGG;IACG,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;CAG9D"}
|
package/dist/client.js
CHANGED
|
@@ -17,7 +17,13 @@ export class OpenClawClient {
|
|
|
17
17
|
this.config = config;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Connect to the OpenClaw Gateway and perform handshake
|
|
20
|
+
* Connect to the OpenClaw Gateway and perform handshake.
|
|
21
|
+
*
|
|
22
|
+
* The protocol flow is:
|
|
23
|
+
* 1. Open WebSocket connection
|
|
24
|
+
* 2. Gateway sends a `connect.challenge` event with a nonce
|
|
25
|
+
* 3. Client responds with a `connect` request (including auth token)
|
|
26
|
+
* 4. Gateway replies with `hello-ok` containing server info and snapshot
|
|
21
27
|
*/
|
|
22
28
|
async connect() {
|
|
23
29
|
if (this.connected && this.ws?.readyState === WebSocket.OPEN) {
|
|
@@ -26,23 +32,44 @@ export class OpenClawClient {
|
|
|
26
32
|
// Create WebSocket connection
|
|
27
33
|
const WS = getWebSocketConstructor();
|
|
28
34
|
this.ws = new WS(this.config.gatewayUrl);
|
|
29
|
-
// Wait for connection to open
|
|
30
|
-
await new Promise((resolve, reject) => {
|
|
35
|
+
// Wait for connection to open and receive the challenge event
|
|
36
|
+
const challenge = await new Promise((resolve, reject) => {
|
|
31
37
|
if (!this.ws) {
|
|
32
38
|
reject(new Error('WebSocket not initialized'));
|
|
33
39
|
return;
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
const timeout = setTimeout(() => {
|
|
42
|
+
reject(new Error('Connection timeout: no challenge received'));
|
|
43
|
+
}, 15000);
|
|
44
|
+
this.ws.onerror = (error) => {
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
reject(error);
|
|
47
|
+
};
|
|
48
|
+
this.ws.onmessage = (event) => {
|
|
49
|
+
try {
|
|
50
|
+
const frame = JSON.parse(event.data);
|
|
51
|
+
if (frame.type === 'event' && frame.event === 'connect.challenge') {
|
|
52
|
+
clearTimeout(timeout);
|
|
53
|
+
resolve(frame.payload);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
reject(new Error('Failed to parse challenge frame'));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.ws.onopen = () => {
|
|
62
|
+
// Wait for the challenge event after connection opens
|
|
63
|
+
};
|
|
37
64
|
});
|
|
38
|
-
// Set up message handler
|
|
65
|
+
// Set up message handler for subsequent messages
|
|
39
66
|
if (this.ws) {
|
|
40
67
|
this.ws.onmessage = (event) => this.handleMessage(event);
|
|
41
68
|
this.ws.onclose = () => this.handleClose();
|
|
42
69
|
this.ws.onerror = (error) => this.handleError(error);
|
|
43
70
|
}
|
|
44
|
-
// Perform handshake
|
|
45
|
-
const result = await this.handshake();
|
|
71
|
+
// Perform handshake (send connect request after receiving challenge)
|
|
72
|
+
const result = await this.handshake(challenge);
|
|
46
73
|
this.connected = true;
|
|
47
74
|
this.connectionId = result.server.connId;
|
|
48
75
|
return result;
|
|
@@ -88,9 +115,10 @@ export class OpenClawClient {
|
|
|
88
115
|
};
|
|
89
116
|
}
|
|
90
117
|
/**
|
|
91
|
-
* Perform the connection handshake
|
|
118
|
+
* Perform the connection handshake after receiving the challenge.
|
|
119
|
+
* Uses connectTimeoutMs (default 120s) since device approval may take a while.
|
|
92
120
|
*/
|
|
93
|
-
async handshake() {
|
|
121
|
+
async handshake(_challenge) {
|
|
94
122
|
const params = {
|
|
95
123
|
minProtocol: 3,
|
|
96
124
|
maxProtocol: 3,
|
|
@@ -105,13 +133,15 @@ export class OpenClawClient {
|
|
|
105
133
|
auth: {
|
|
106
134
|
token: this.config.token,
|
|
107
135
|
},
|
|
136
|
+
...this.config.connectParams,
|
|
108
137
|
};
|
|
109
|
-
|
|
138
|
+
const connectTimeout = this.config.connectTimeoutMs ?? 120000;
|
|
139
|
+
return this.request('connect', params, connectTimeout);
|
|
110
140
|
}
|
|
111
141
|
/**
|
|
112
142
|
* Send a request and wait for response
|
|
113
143
|
*/
|
|
114
|
-
async request(method, params) {
|
|
144
|
+
async request(method, params, timeoutMs) {
|
|
115
145
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
116
146
|
throw new Error('Not connected');
|
|
117
147
|
}
|
|
@@ -124,11 +154,11 @@ export class OpenClawClient {
|
|
|
124
154
|
};
|
|
125
155
|
return new Promise((resolve, reject) => {
|
|
126
156
|
this.pending.set(id, { resolve, reject });
|
|
127
|
-
|
|
157
|
+
const effectiveTimeout = timeoutMs ?? this.config.requestTimeoutMs ?? 30000;
|
|
128
158
|
const timeout = setTimeout(() => {
|
|
129
159
|
this.pending.delete(id);
|
|
130
160
|
reject(new Error(`Request timeout: ${method}`));
|
|
131
|
-
},
|
|
161
|
+
}, effectiveTimeout);
|
|
132
162
|
// Clear timeout when promise settles
|
|
133
163
|
const originalResolve = resolve;
|
|
134
164
|
const originalReject = reject;
|
|
@@ -266,6 +296,24 @@ export class OpenClawClient {
|
|
|
266
296
|
async listAgents(params = {}) {
|
|
267
297
|
return this.request('agents.list', params);
|
|
268
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Create agent
|
|
301
|
+
*/
|
|
302
|
+
async createAgent(params) {
|
|
303
|
+
return this.request('agents.create', params);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Update agent
|
|
307
|
+
*/
|
|
308
|
+
async updateAgent(params) {
|
|
309
|
+
return this.request('agents.update', params);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Delete agent
|
|
313
|
+
*/
|
|
314
|
+
async deleteAgent(params) {
|
|
315
|
+
return this.request('agents.delete', params);
|
|
316
|
+
}
|
|
269
317
|
/**
|
|
270
318
|
* Get agent identity
|
|
271
319
|
*/
|
|
@@ -326,6 +374,12 @@ export class OpenClawClient {
|
|
|
326
374
|
async compactSession(params) {
|
|
327
375
|
return this.request('sessions.compact', params);
|
|
328
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Get session usage
|
|
379
|
+
*/
|
|
380
|
+
async getSessionsUsage(params = {}) {
|
|
381
|
+
return this.request('sessions.usage', params);
|
|
382
|
+
}
|
|
329
383
|
/**
|
|
330
384
|
* Send a message to agent
|
|
331
385
|
*/
|
|
@@ -386,6 +440,12 @@ export class OpenClawClient {
|
|
|
386
440
|
async setTalkMode(params) {
|
|
387
441
|
return this.request('talk.mode', params);
|
|
388
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Get talk config
|
|
445
|
+
*/
|
|
446
|
+
async getTalkConfig(params = {}) {
|
|
447
|
+
return this.request('talk.config', params);
|
|
448
|
+
}
|
|
389
449
|
/**
|
|
390
450
|
* Get channels status
|
|
391
451
|
*/
|
|
@@ -530,6 +590,12 @@ export class OpenClawClient {
|
|
|
530
590
|
async rejectDevicePairing(params) {
|
|
531
591
|
return this.request('device.pair.reject', params);
|
|
532
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* Remove paired device
|
|
595
|
+
*/
|
|
596
|
+
async removeDevicePairing(params) {
|
|
597
|
+
return this.request('device.pair.remove', params);
|
|
598
|
+
}
|
|
533
599
|
/**
|
|
534
600
|
* Rotate device token
|
|
535
601
|
*/
|
|
@@ -620,6 +686,12 @@ export class OpenClawClient {
|
|
|
620
686
|
async invokeNode(params) {
|
|
621
687
|
return this.request('node.invoke', params);
|
|
622
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* Test push notification to node
|
|
691
|
+
*/
|
|
692
|
+
async testPush(params) {
|
|
693
|
+
return this.request('push.test', params);
|
|
694
|
+
}
|
|
623
695
|
/**
|
|
624
696
|
* Update and run
|
|
625
697
|
*/
|