You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: nodejs/README.md
+82Lines changed: 82 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -279,6 +279,20 @@ Get all events/messages from this session.
279
279
280
280
Disconnect the session and free resources. Session data on disk is preserved for later resumption.
281
281
282
+
##### `capabilities: SessionCapabilities`
283
+
284
+
Host capabilities reported when the session was created or resumed. Use this to check feature support before calling capability-gated APIs.
285
+
286
+
```typescript
287
+
if (session.capabilities.ui?.elicitation) {
288
+
const ok =awaitsession.ui.confirm("Deploy?");
289
+
}
290
+
```
291
+
292
+
##### `ui: SessionUiApi`
293
+
294
+
Interactive UI methods for showing dialogs to the user. Only available when the CLI host supports elicitation (`session.capabilities.ui?.elicitation === true`). See [UI Elicitation](#ui-elicitation) for full details.
295
+
282
296
##### `destroy(): Promise<void>`*(deprecated)*
283
297
284
298
Deprecated — use `disconnect()` instead.
@@ -294,6 +308,8 @@ Sessions emit various events during processing:
See `SessionEvent` type in the source for full details.
@@ -455,6 +471,72 @@ defineTool("safe_lookup", {
455
471
})
456
472
```
457
473
474
+
### Commands
475
+
476
+
Register slash commands so that users of the CLI's TUI can invoke custom actions via `/commandName`. Each command has a `name`, optional `description`, and a `handler` called when the user executes it.
477
+
478
+
```ts
479
+
const session =awaitclient.createSession({
480
+
onPermissionRequest: approveAll,
481
+
commands: [
482
+
{
483
+
name: "deploy",
484
+
description: "Deploy the app to production",
485
+
handler: async ({ commandName, args }) => {
486
+
console.log(`Deploying with args: ${args}`);
487
+
// Do work here — any thrown error is reported back to the CLI
488
+
},
489
+
},
490
+
],
491
+
});
492
+
```
493
+
494
+
When the user types `/deploy staging` in the CLI, the SDK receives a `command.execute` event, routes it to your handler, and automatically responds to the CLI. If the handler throws, the error message is forwarded.
495
+
496
+
Commands are sent to the CLI on both `createSession` and `resumeSession`, so you can update the command set when resuming.
497
+
498
+
### UI Elicitation
499
+
500
+
When the CLI is running with a TUI (not in headless mode), the SDK can request interactive form dialogs from the user. The `session.ui` object provides convenience methods built on a single generic `elicitation` RPC.
501
+
502
+
> **Capability check:** Elicitation is only available when the host advertises support. Always check `session.capabilities.ui?.elicitation` before calling UI methods.
0 commit comments