Skip to content

Commit 4eeb0c1

Browse files
Clean up Node readme
1 parent 622fec4 commit 4eeb0c1

1 file changed

Lines changed: 42 additions & 28 deletions

File tree

nodejs/README.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ await client.stop();
6060
Sessions also support `Symbol.asyncDispose` for use with [`await using`](https://github.com/tc39/proposal-explicit-resource-management) (TypeScript 5.2+/Node.js 18.0+):
6161

6262
```typescript
63-
await using session = await client.createSession({ model: "gpt-5", onPermissionRequest: approveAll });
63+
await using session = await client.createSession({
64+
model: "gpt-5",
65+
onPermissionRequest: approveAll,
66+
});
6467
// session is automatically disconnected when leaving scope
6568
```
6669

@@ -76,7 +79,7 @@ new CopilotClient(options?: CopilotClientOptions)
7679

7780
**Options:**
7881

79-
- `cliPath?: string` - Path to CLI executable (default: "copilot" from PATH)
82+
- `cliPath?: string` - Path to CLI executable (default: uses COPILOT_CLI_PATH env var or bundled instance)
8083
- `cliArgs?: string[]` - Extra arguments prepended before SDK-managed flags (e.g. `["./dist-cli/index.js"]` when using `node`)
8184
- `cliUrl?: string` - URL of existing CLI server to connect to (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client will not spawn a CLI process.
8285
- `port?: number` - Server port (default: 0 for random)
@@ -184,6 +187,7 @@ const unsubscribe = client.on((event) => {
184187
```
185188

186189
**Lifecycle Event Types:**
190+
187191
- `session.created` - A new session was created
188192
- `session.deleted` - A session was deleted
189193
- `session.updated` - A session was updated (e.g., new messages)
@@ -293,7 +297,7 @@ if (session.capabilities.ui?.elicitation) {
293297

294298
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.
295299

296-
##### `destroy(): Promise<void>` *(deprecated)*
300+
##### `destroy(): Promise<void>` _(deprecated)_
297301

298302
Deprecated — use `disconnect()` instead.
299303

@@ -454,8 +458,10 @@ defineTool("edit_file", {
454458
description: "Custom file editor with project-specific validation",
455459
parameters: z.object({ path: z.string(), content: z.string() }),
456460
overridesBuiltInTool: true,
457-
handler: async ({ path, content }) => { /* your logic */ },
458-
})
461+
handler: async ({ path, content }) => {
462+
/* your logic */
463+
},
464+
});
459465
```
460466

461467
#### Skipping Permission Prompts
@@ -467,8 +473,10 @@ defineTool("safe_lookup", {
467473
description: "A read-only lookup that needs no confirmation",
468474
parameters: z.object({ id: z.string() }),
469475
skipPermission: true,
470-
handler: async ({ id }) => { /* your logic */ },
471-
})
476+
handler: async ({ id }) => {
477+
/* your logic */
478+
},
479+
});
472480
```
473481

474482
### Commands
@@ -571,7 +579,10 @@ const session = await client.createSession({
571579
mode: "customize",
572580
sections: {
573581
// Replace the tone/style section
574-
tone: { action: "replace", content: "Respond in a warm, professional tone. Be thorough in explanations." },
582+
tone: {
583+
action: "replace",
584+
content: "Respond in a warm, professional tone. Be thorough in explanations.",
585+
},
575586
// Remove coding-specific rules
576587
code_change_rules: { action: "remove" },
577588
// Append to existing guidelines
@@ -586,6 +597,7 @@ const session = await client.createSession({
586597
Available section IDs: `identity`, `tone`, `tool_efficiency`, `environment_context`, `code_change_rules`, `guidelines`, `safety`, `tool_instructions`, `custom_instructions`, `last_instructions`. Use the `SYSTEM_PROMPT_SECTIONS` constant for descriptions of each section.
587598

588599
Each section override supports four actions:
600+
589601
- **`replace`** — Replace the section content entirely
590602
- **`remove`** — Remove the section from the prompt
591603
- **`append`** — Add content after the existing section
@@ -624,7 +636,7 @@ const session = await client.createSession({
624636
model: "gpt-5",
625637
infiniteSessions: {
626638
enabled: true,
627-
backgroundCompactionThreshold: 0.80, // Start compacting at 80% context usage
639+
backgroundCompactionThreshold: 0.8, // Start compacting at 80% context usage
628640
bufferExhaustionThreshold: 0.95, // Block at 95% until compaction completes
629641
},
630642
});
@@ -723,8 +735,8 @@ const session = await client.createSession({
723735
const session = await client.createSession({
724736
model: "gpt-4",
725737
provider: {
726-
type: "azure", // Must be "azure" for Azure endpoints, NOT "openai"
727-
baseUrl: "https://my-resource.openai.azure.com", // Just the host, no path
738+
type: "azure", // Must be "azure" for Azure endpoints, NOT "openai"
739+
baseUrl: "https://my-resource.openai.azure.com", // Just the host, no path
728740
apiKey: process.env.AZURE_OPENAI_KEY,
729741
azure: {
730742
apiVersion: "2024-10-21",
@@ -734,6 +746,7 @@ const session = await client.createSession({
734746
```
735747

736748
> **Important notes:**
749+
>
737750
> - When using a custom provider, the `model` parameter is **required**. The SDK will throw an error if no model is specified.
738751
> - For Azure OpenAI endpoints (`*.openai.azure.com`), you **must** use `type: "azure"`, not `type: "openai"`.
739752
> - The `baseUrl` should be just the host (e.g., `https://my-resource.openai.azure.com`). Do **not** include `/openai/v1` in the URL - the SDK handles path construction automatically.
@@ -744,9 +757,9 @@ The SDK supports OpenTelemetry for distributed tracing. Provide a `telemetry` co
744757

745758
```typescript
746759
const client = new CopilotClient({
747-
telemetry: {
748-
otlpEndpoint: "http://localhost:4318",
749-
},
760+
telemetry: {
761+
otlpEndpoint: "http://localhost:4318",
762+
},
750763
});
751764
```
752765

@@ -772,12 +785,12 @@ If you're already using `@opentelemetry/api` in your app and want this linkage,
772785
import { propagation, context } from "@opentelemetry/api";
773786

774787
const client = new CopilotClient({
775-
telemetry: { otlpEndpoint: "http://localhost:4318" },
776-
onGetTraceContext: () => {
777-
const carrier: Record<string, string> = {};
778-
propagation.inject(context.active(), carrier);
779-
return carrier;
780-
},
788+
telemetry: { otlpEndpoint: "http://localhost:4318" },
789+
onGetTraceContext: () => {
790+
const carrier: Record<string, string> = {};
791+
propagation.inject(context.active(), carrier);
792+
return carrier;
793+
},
781794
});
782795
```
783796

@@ -837,14 +850,15 @@ const session = await client.createSession({
837850

838851
### Permission Result Kinds
839852

840-
| Kind | Meaning |
841-
|------|---------|
842-
| `"approved"` | Allow the tool to run |
843-
| `"denied-interactively-by-user"` | User explicitly denied the request |
844-
| `"denied-no-approval-rule-and-could-not-request-from-user"` | No approval rule matched and user could not be asked |
845-
| `"denied-by-rules"` | Denied by a policy rule |
846-
| `"denied-by-content-exclusion-policy"` | Denied due to a content exclusion policy |
847-
| `"no-result"` | Leave the request unanswered (only valid with protocol v1; rejected by protocol v2 servers) |
853+
| Kind | Meaning |
854+
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
855+
| `"approved"` | Allow the tool to run |
856+
| `"denied-interactively-by-user"` | User explicitly denied the request |
857+
| `"denied-no-approval-rule-and-could-not-request-from-user"` | No approval rule matched and user could not be asked |
858+
| `"denied-by-rules"` | Denied by a policy rule |
859+
| `"denied-by-content-exclusion-policy"` | Denied due to a content exclusion policy |
860+
| `"no-result"` | Leave the request unanswered (only valid with protocol v1; rejected by protocol v2 servers) |
861+
848862
### Resuming Sessions
849863

850864
Pass `onPermissionRequest` when resuming a session too — it is required:

0 commit comments

Comments
 (0)