@scottwalker/claude-connector 0.3.0 → 0.4.1
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 +174 -3
- package/dist/client/claude.d.ts +70 -27
- package/dist/client/claude.d.ts.map +1 -1
- package/dist/client/claude.js +145 -26
- package/dist/client/claude.js.map +1 -1
- package/dist/client/stream-handle.d.ts +12 -12
- package/dist/client/stream-handle.d.ts.map +1 -1
- package/dist/client/stream-handle.js +26 -11
- package/dist/client/stream-handle.js.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/executor/cli-executor.d.ts.map +1 -1
- package/dist/executor/cli-executor.js +27 -0
- package/dist/executor/cli-executor.js.map +1 -1
- package/dist/executor/interface.d.ts +5 -0
- package/dist/executor/interface.d.ts.map +1 -1
- package/dist/executor/sdk-executor.d.ts +138 -22
- package/dist/executor/sdk-executor.d.ts.map +1 -1
- package/dist/executor/sdk-executor.js +387 -53
- package/dist/executor/sdk-executor.js.map +1 -1
- package/dist/index.d.ts +72 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -4
- package/dist/index.js.map +1 -1
- package/dist/types/client.d.ts +343 -3
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/result.d.ts +116 -1
- package/dist/types/result.d.ts.map +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<
|
|
2
|
+
<picture>
|
|
3
|
+
<img src="landing/assets/origin.png" alt="Claude Connector" width="250" style="border-radius: 16px" />
|
|
4
|
+
</picture>
|
|
3
5
|
</p>
|
|
4
6
|
|
|
5
|
-
<h1 align="center">Claude Connector</h1>
|
|
6
|
-
|
|
7
7
|
Programmatic Node.js interface for [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) CLI.
|
|
8
8
|
|
|
9
9
|
Use Claude Code from your application code — no terminal required. Works with your existing Max/Team/Enterprise subscription.
|
|
@@ -299,6 +299,177 @@ const claude = new Claude({
|
|
|
299
299
|
})
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
+
### Programmatic Permissions
|
|
303
|
+
|
|
304
|
+
Control tool approval with a callback instead of static permission modes:
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { Claude } from '@scottwalker/claude-connector'
|
|
308
|
+
|
|
309
|
+
const claude = new Claude({
|
|
310
|
+
canUseTool: (tool, args) => {
|
|
311
|
+
if (tool === 'Bash' && args.command?.includes('rm ')) return false
|
|
312
|
+
if (tool === 'Edit') return true
|
|
313
|
+
return 'ask' // fall back to default behavior
|
|
314
|
+
},
|
|
315
|
+
})
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### In-Process MCP Tools
|
|
319
|
+
|
|
320
|
+
Define custom tools that run in-process — no external MCP server required:
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { Claude, createSdkMcpServer, sdkTool } from '@scottwalker/claude-connector'
|
|
324
|
+
|
|
325
|
+
const server = createSdkMcpServer({
|
|
326
|
+
tools: {
|
|
327
|
+
getUser: sdkTool({ id: { type: 'string' } }, async ({ id }) => {
|
|
328
|
+
return { name: 'Alice', role: 'admin' }
|
|
329
|
+
}),
|
|
330
|
+
},
|
|
331
|
+
})
|
|
332
|
+
const claude = new Claude({ mcpServers: { myTools: server } })
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### JS Hook Callbacks
|
|
336
|
+
|
|
337
|
+
Subscribe to all 21 hook events with native JS callbacks (no shell commands):
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
import { Claude } from '@scottwalker/claude-connector'
|
|
341
|
+
|
|
342
|
+
const claude = new Claude({
|
|
343
|
+
hookCallbacks: {
|
|
344
|
+
PreToolUse: ({ toolName, args }) => {
|
|
345
|
+
if (toolName === 'Bash' && args.command?.includes('sudo')) return 'deny'
|
|
346
|
+
},
|
|
347
|
+
PostToolUse: ({ toolName, result }) => console.log(`${toolName} done`),
|
|
348
|
+
Notification: ({ message }) => sendSlack(message),
|
|
349
|
+
},
|
|
350
|
+
})
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Thinking Config
|
|
354
|
+
|
|
355
|
+
Control Claude's reasoning behavior:
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
import { Claude } from '@scottwalker/claude-connector'
|
|
359
|
+
|
|
360
|
+
const claude = new Claude({ thinking: { type: 'enabled' } })
|
|
361
|
+
// 'adaptive' — Claude decides | 'enabled' — always think | 'disabled' — no thinking
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Runtime Control
|
|
365
|
+
|
|
366
|
+
Change model or permission mode during a session:
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
import { Claude, PERMISSION_PLAN } from '@scottwalker/claude-connector'
|
|
370
|
+
|
|
371
|
+
const claude = new Claude({ model: 'sonnet' })
|
|
372
|
+
claude.setModel('opus') // switch to a more capable model
|
|
373
|
+
claude.setPermissionMode(PERMISSION_PLAN) // tighten permissions mid-session
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Dynamic MCP
|
|
377
|
+
|
|
378
|
+
Add, reconnect, or toggle MCP servers at runtime:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
const claude = new Claude()
|
|
382
|
+
claude.setMcpServers({ db: { command: 'npx', args: ['@db/mcp'] } })
|
|
383
|
+
await claude.reconnectMcpServer('db') // restart after config change
|
|
384
|
+
claude.toggleMcpServer('db', false) // temporarily disable
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### File Checkpointing
|
|
388
|
+
|
|
389
|
+
Snapshot and restore files modified by Claude:
|
|
390
|
+
|
|
391
|
+
```typescript
|
|
392
|
+
const claude = new Claude({ enableFileCheckpointing: true })
|
|
393
|
+
const result = await claude.query('Refactor the auth module')
|
|
394
|
+
// Something went wrong? Roll back all file changes:
|
|
395
|
+
await claude.rewindFiles(result.sessionId!)
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Account & Model Info
|
|
399
|
+
|
|
400
|
+
Query your subscription info and available models:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const claude = new Claude()
|
|
404
|
+
const account = await claude.accountInfo() // { plan, usage, limits }
|
|
405
|
+
const models = await claude.supportedModels() // ['opus', 'sonnet', ...]
|
|
406
|
+
const agents = await claude.supportedAgents() // available agent types
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Per-Query Abort
|
|
410
|
+
|
|
411
|
+
Cancel individual queries with standard `AbortSignal`:
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
const controller = new AbortController()
|
|
415
|
+
setTimeout(() => controller.abort(), 30_000) // 30s timeout
|
|
416
|
+
|
|
417
|
+
const result = await claude.query('Long analysis task', {
|
|
418
|
+
signal: controller.signal,
|
|
419
|
+
})
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Subagent Control
|
|
423
|
+
|
|
424
|
+
Monitor and stop spawned subagent tasks:
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
const handle = claude.stream('Run a full analysis')
|
|
428
|
+
.on('task_started', (e) => console.log(`Subagent: ${e.taskId}`))
|
|
429
|
+
.on('task_progress', (e) => console.log(`Progress: ${e.status}`))
|
|
430
|
+
.on('task_notification', (e) => console.log(e.message))
|
|
431
|
+
|
|
432
|
+
// Stop a specific subagent
|
|
433
|
+
await claude.stopTask(taskId)
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Settings & Plugins
|
|
437
|
+
|
|
438
|
+
Provide CLAUDE.md instructions, settings overrides, and plugins programmatically:
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
const claude = new Claude({
|
|
442
|
+
settingSources: ['./project/CLAUDE.md', './team/CLAUDE.md'],
|
|
443
|
+
settings: { preferredLanguage: 'TypeScript', maxFileSize: 10_000 },
|
|
444
|
+
plugins: ['@claude/eslint-plugin', '@claude/prettier-plugin'],
|
|
445
|
+
})
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Custom Process Spawn
|
|
449
|
+
|
|
450
|
+
Override how Claude Code processes are created — useful for VMs, containers, or remote execution:
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
import { Claude } from '@scottwalker/claude-connector'
|
|
454
|
+
|
|
455
|
+
const claude = new Claude({
|
|
456
|
+
spawnClaudeCodeProcess: (args, env) => {
|
|
457
|
+
// Run inside a Docker container instead of locally
|
|
458
|
+
return spawn('docker', ['exec', 'my-sandbox', 'claude', ...args], { env })
|
|
459
|
+
},
|
|
460
|
+
})
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Session Utilities
|
|
464
|
+
|
|
465
|
+
List and inspect past sessions:
|
|
466
|
+
|
|
467
|
+
```typescript
|
|
468
|
+
const claude = new Claude()
|
|
469
|
+
const sessions = await claude.listSessions() // all session IDs + metadata
|
|
470
|
+
const messages = await claude.getSessionMessages(id) // full message history
|
|
471
|
+
```
|
|
472
|
+
|
|
302
473
|
### Full Configuration
|
|
303
474
|
|
|
304
475
|
All Claude Code CLI capabilities in one place:
|
package/dist/client/claude.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClientOptions, QueryOptions, QueryResult } from '../types/index.js';
|
|
1
|
+
import type { ClientOptions, QueryOptions, QueryResult, AccountInfo, ModelInfo, SlashCommand, AgentInfo, McpServerStatus, McpSetServersResult, RewindFilesResult, McpServerConfig, McpSdkServerConfig, PermissionMode } from '../types/index.js';
|
|
2
2
|
import type { SessionOptions } from '../types/session.js';
|
|
3
3
|
import type { IExecutor } from '../executor/interface.js';
|
|
4
4
|
import { type InitStage } from '../executor/sdk-executor.js';
|
|
@@ -54,37 +54,11 @@ export declare class Claude {
|
|
|
54
54
|
* Execute a query with streaming response.
|
|
55
55
|
* Returns a {@link StreamHandle} with fluent callbacks, Node.js stream support,
|
|
56
56
|
* and backward-compatible async iteration.
|
|
57
|
-
*
|
|
58
|
-
* ```ts
|
|
59
|
-
* // Fluent
|
|
60
|
-
* await claude.stream('Fix bugs').on('text', t => process.stdout.write(t)).done()
|
|
61
|
-
*
|
|
62
|
-
* // Collect text
|
|
63
|
-
* const text = await claude.stream('Summarize').text()
|
|
64
|
-
*
|
|
65
|
-
* // Pipe
|
|
66
|
-
* const result = await claude.stream('Explain').pipe(process.stdout)
|
|
67
|
-
*
|
|
68
|
-
* // Node.js Readable
|
|
69
|
-
* claude.stream('Generate').toReadable().pipe(createWriteStream('out.txt'))
|
|
70
|
-
*
|
|
71
|
-
* // Raw iteration (backward compat)
|
|
72
|
-
* for await (const event of claude.stream('Analyze')) { ... }
|
|
73
|
-
* ```
|
|
74
57
|
*/
|
|
75
58
|
stream(prompt: string, options?: QueryOptions): StreamHandle;
|
|
76
59
|
/**
|
|
77
60
|
* Open a bidirectional chat — a persistent CLI process for real-time conversation.
|
|
78
61
|
* Uses `--input-format stream-json` for multi-turn dialogue over a single process.
|
|
79
|
-
*
|
|
80
|
-
* ```ts
|
|
81
|
-
* const chat = claude.chat()
|
|
82
|
-
* .on('text', (t) => process.stdout.write(t))
|
|
83
|
-
*
|
|
84
|
-
* await chat.send('What files are in src?')
|
|
85
|
-
* await chat.send('Now fix the bugs')
|
|
86
|
-
* chat.end()
|
|
87
|
-
* ```
|
|
88
62
|
*/
|
|
89
63
|
chat(options?: QueryOptions): ChatHandle;
|
|
90
64
|
/**
|
|
@@ -114,5 +88,74 @@ export declare class Claude {
|
|
|
114
88
|
* Access the underlying executor (for advanced use / testing).
|
|
115
89
|
*/
|
|
116
90
|
getExecutor(): IExecutor;
|
|
91
|
+
/**
|
|
92
|
+
* Change the model for subsequent responses.
|
|
93
|
+
* SDK mode only — throws in CLI mode.
|
|
94
|
+
*/
|
|
95
|
+
setModel(model?: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Change the permission mode for the session.
|
|
98
|
+
* SDK mode only — throws in CLI mode.
|
|
99
|
+
*/
|
|
100
|
+
setPermissionMode(mode: PermissionMode): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Rewind files to their state at a specific user message.
|
|
103
|
+
* Requires `enableFileCheckpointing: true`.
|
|
104
|
+
* SDK mode only — throws in CLI mode.
|
|
105
|
+
*/
|
|
106
|
+
rewindFiles(userMessageId: string, options?: {
|
|
107
|
+
dryRun?: boolean;
|
|
108
|
+
}): Promise<RewindFilesResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Stop a running subagent task.
|
|
111
|
+
* SDK mode only — throws in CLI mode.
|
|
112
|
+
*/
|
|
113
|
+
stopTask(taskId: string): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Dynamically set MCP servers for this session.
|
|
116
|
+
* SDK mode only — throws in CLI mode.
|
|
117
|
+
*/
|
|
118
|
+
setMcpServers(servers: Record<string, McpServerConfig | McpSdkServerConfig>): Promise<McpSetServersResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Reconnect a disconnected MCP server.
|
|
121
|
+
* SDK mode only — throws in CLI mode.
|
|
122
|
+
*/
|
|
123
|
+
reconnectMcpServer(serverName: string): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Enable or disable an MCP server.
|
|
126
|
+
* SDK mode only — throws in CLI mode.
|
|
127
|
+
*/
|
|
128
|
+
toggleMcpServer(serverName: string, enabled: boolean): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Get account information (email, org, subscription).
|
|
131
|
+
* SDK mode only — throws in CLI mode.
|
|
132
|
+
*/
|
|
133
|
+
accountInfo(): Promise<AccountInfo>;
|
|
134
|
+
/**
|
|
135
|
+
* Get available models with their capabilities.
|
|
136
|
+
* SDK mode only — throws in CLI mode.
|
|
137
|
+
*/
|
|
138
|
+
supportedModels(): Promise<ModelInfo[]>;
|
|
139
|
+
/**
|
|
140
|
+
* Get available slash commands.
|
|
141
|
+
* SDK mode only — throws in CLI mode.
|
|
142
|
+
*/
|
|
143
|
+
supportedCommands(): Promise<SlashCommand[]>;
|
|
144
|
+
/**
|
|
145
|
+
* Get available subagents.
|
|
146
|
+
* SDK mode only — throws in CLI mode.
|
|
147
|
+
*/
|
|
148
|
+
supportedAgents(): Promise<AgentInfo[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Get MCP server connection statuses.
|
|
151
|
+
* SDK mode only — throws in CLI mode.
|
|
152
|
+
*/
|
|
153
|
+
mcpServerStatus(): Promise<McpServerStatus[]>;
|
|
154
|
+
/**
|
|
155
|
+
* Interrupt the current query execution.
|
|
156
|
+
* SDK mode only — throws in CLI mode.
|
|
157
|
+
*/
|
|
158
|
+
interrupt(): Promise<void>;
|
|
159
|
+
private requireSdk;
|
|
117
160
|
}
|
|
118
161
|
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/client/claude.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/client/claude.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,YAAY,EAAE,WAAW,EACxC,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAC/C,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,EACvD,eAAe,EAAE,kBAAkB,EAAE,cAAc,EACpD,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAe,KAAK,SAAS,EAA2B,MAAM,6BAA6B,CAAC;AAGnG,OAAO,EAIL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,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I,CAAC;IAK1E;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAKzC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK7C;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAKlD;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK7C;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAKnD;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAKhC,OAAO,CAAC,UAAU;CAKnB"}
|
package/dist/client/claude.js
CHANGED
|
@@ -42,6 +42,7 @@ export class Claude {
|
|
|
42
42
|
const sdkOpts = {
|
|
43
43
|
model: options.model,
|
|
44
44
|
pathToClaudeCodeExecutable: options.executable,
|
|
45
|
+
cwd: options.cwd,
|
|
45
46
|
permissionMode: options.permissionMode,
|
|
46
47
|
allowedTools: options.allowedTools ? [...options.allowedTools] : undefined,
|
|
47
48
|
disallowedTools: options.disallowedTools ? [...options.disallowedTools] : undefined,
|
|
@@ -49,6 +50,35 @@ export class Claude {
|
|
|
49
50
|
systemPrompt: options.systemPrompt,
|
|
50
51
|
appendSystemPrompt: options.appendSystemPrompt,
|
|
51
52
|
maxTurns: options.maxTurns,
|
|
53
|
+
maxBudget: options.maxBudget,
|
|
54
|
+
effortLevel: options.effortLevel,
|
|
55
|
+
fallbackModel: options.fallbackModel,
|
|
56
|
+
// New SDK-level options
|
|
57
|
+
canUseTool: options.canUseTool,
|
|
58
|
+
thinking: options.thinking,
|
|
59
|
+
enableFileCheckpointing: options.enableFileCheckpointing,
|
|
60
|
+
onElicitation: options.onElicitation,
|
|
61
|
+
hookCallbacks: options.hookCallbacks,
|
|
62
|
+
mcpServers: options.mcpServers,
|
|
63
|
+
agents: options.agents,
|
|
64
|
+
agent: options.agent,
|
|
65
|
+
tools: options.tools ? [...options.tools] : undefined,
|
|
66
|
+
additionalDirs: options.additionalDirs ? [...options.additionalDirs] : undefined,
|
|
67
|
+
noSessionPersistence: options.noSessionPersistence,
|
|
68
|
+
strictMcpConfig: options.strictMcpConfig,
|
|
69
|
+
betas: options.betas ? [...options.betas] : undefined,
|
|
70
|
+
includePartialMessages: options.includePartialMessages,
|
|
71
|
+
promptSuggestions: options.promptSuggestions,
|
|
72
|
+
agentProgressSummaries: options.agentProgressSummaries,
|
|
73
|
+
debug: options.debug,
|
|
74
|
+
debugFile: options.debugFile,
|
|
75
|
+
// New passthrough options
|
|
76
|
+
stderr: options.stderr,
|
|
77
|
+
allowDangerouslySkipPermissions: options.allowDangerouslySkipPermissions,
|
|
78
|
+
settingSources: options.settingSources,
|
|
79
|
+
settings: options.settings,
|
|
80
|
+
plugins: options.plugins,
|
|
81
|
+
spawnClaudeCodeProcess: options.spawnClaudeCodeProcess,
|
|
52
82
|
};
|
|
53
83
|
this.sdkExecutor = new SdkExecutor(sdkOpts);
|
|
54
84
|
this.executor = this.sdkExecutor;
|
|
@@ -96,29 +126,13 @@ export class Claude {
|
|
|
96
126
|
env,
|
|
97
127
|
input: options?.input,
|
|
98
128
|
systemPrompt: resolved.systemPrompt,
|
|
129
|
+
signal: options?.signal,
|
|
99
130
|
});
|
|
100
131
|
}
|
|
101
132
|
/**
|
|
102
133
|
* Execute a query with streaming response.
|
|
103
134
|
* Returns a {@link StreamHandle} with fluent callbacks, Node.js stream support,
|
|
104
135
|
* and backward-compatible async iteration.
|
|
105
|
-
*
|
|
106
|
-
* ```ts
|
|
107
|
-
* // Fluent
|
|
108
|
-
* await claude.stream('Fix bugs').on('text', t => process.stdout.write(t)).done()
|
|
109
|
-
*
|
|
110
|
-
* // Collect text
|
|
111
|
-
* const text = await claude.stream('Summarize').text()
|
|
112
|
-
*
|
|
113
|
-
* // Pipe
|
|
114
|
-
* const result = await claude.stream('Explain').pipe(process.stdout)
|
|
115
|
-
*
|
|
116
|
-
* // Node.js Readable
|
|
117
|
-
* claude.stream('Generate').toReadable().pipe(createWriteStream('out.txt'))
|
|
118
|
-
*
|
|
119
|
-
* // Raw iteration (backward compat)
|
|
120
|
-
* for await (const event of claude.stream('Analyze')) { ... }
|
|
121
|
-
* ```
|
|
122
136
|
*/
|
|
123
137
|
stream(prompt, options) {
|
|
124
138
|
validatePrompt(prompt);
|
|
@@ -136,21 +150,13 @@ export class Claude {
|
|
|
136
150
|
env,
|
|
137
151
|
input: options?.input,
|
|
138
152
|
systemPrompt: resolved.systemPrompt,
|
|
153
|
+
signal: options?.signal,
|
|
139
154
|
};
|
|
140
155
|
return new StreamHandle(() => executor.stream(args, execOpts));
|
|
141
156
|
}
|
|
142
157
|
/**
|
|
143
158
|
* Open a bidirectional chat — a persistent CLI process for real-time conversation.
|
|
144
159
|
* Uses `--input-format stream-json` for multi-turn dialogue over a single process.
|
|
145
|
-
*
|
|
146
|
-
* ```ts
|
|
147
|
-
* const chat = claude.chat()
|
|
148
|
-
* .on('text', (t) => process.stdout.write(t))
|
|
149
|
-
*
|
|
150
|
-
* await chat.send('What files are in src?')
|
|
151
|
-
* await chat.send('Now fix the bugs')
|
|
152
|
-
* chat.end()
|
|
153
|
-
* ```
|
|
154
160
|
*/
|
|
155
161
|
chat(options) {
|
|
156
162
|
if (options)
|
|
@@ -211,5 +217,118 @@ export class Claude {
|
|
|
211
217
|
getExecutor() {
|
|
212
218
|
return this.executor;
|
|
213
219
|
}
|
|
220
|
+
// ── SDK Control Methods ─────────────────────────────────────────
|
|
221
|
+
// These methods delegate to the underlying SdkExecutor.
|
|
222
|
+
// In CLI mode they throw an error.
|
|
223
|
+
/**
|
|
224
|
+
* Change the model for subsequent responses.
|
|
225
|
+
* SDK mode only — throws in CLI mode.
|
|
226
|
+
*/
|
|
227
|
+
async setModel(model) {
|
|
228
|
+
this.requireSdk('setModel');
|
|
229
|
+
await this.sdkExecutor.setModel(model);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Change the permission mode for the session.
|
|
233
|
+
* SDK mode only — throws in CLI mode.
|
|
234
|
+
*/
|
|
235
|
+
async setPermissionMode(mode) {
|
|
236
|
+
this.requireSdk('setPermissionMode');
|
|
237
|
+
await this.sdkExecutor.setPermissionMode(mode);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Rewind files to their state at a specific user message.
|
|
241
|
+
* Requires `enableFileCheckpointing: true`.
|
|
242
|
+
* SDK mode only — throws in CLI mode.
|
|
243
|
+
*/
|
|
244
|
+
async rewindFiles(userMessageId, options) {
|
|
245
|
+
this.requireSdk('rewindFiles');
|
|
246
|
+
return this.sdkExecutor.rewindFiles(userMessageId, options);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Stop a running subagent task.
|
|
250
|
+
* SDK mode only — throws in CLI mode.
|
|
251
|
+
*/
|
|
252
|
+
async stopTask(taskId) {
|
|
253
|
+
this.requireSdk('stopTask');
|
|
254
|
+
await this.sdkExecutor.stopTask(taskId);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Dynamically set MCP servers for this session.
|
|
258
|
+
* SDK mode only — throws in CLI mode.
|
|
259
|
+
*/
|
|
260
|
+
async setMcpServers(servers) {
|
|
261
|
+
this.requireSdk('setMcpServers');
|
|
262
|
+
return this.sdkExecutor.setMcpServers(servers);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Reconnect a disconnected MCP server.
|
|
266
|
+
* SDK mode only — throws in CLI mode.
|
|
267
|
+
*/
|
|
268
|
+
async reconnectMcpServer(serverName) {
|
|
269
|
+
this.requireSdk('reconnectMcpServer');
|
|
270
|
+
await this.sdkExecutor.reconnectMcpServer(serverName);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Enable or disable an MCP server.
|
|
274
|
+
* SDK mode only — throws in CLI mode.
|
|
275
|
+
*/
|
|
276
|
+
async toggleMcpServer(serverName, enabled) {
|
|
277
|
+
this.requireSdk('toggleMcpServer');
|
|
278
|
+
await this.sdkExecutor.toggleMcpServer(serverName, enabled);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Get account information (email, org, subscription).
|
|
282
|
+
* SDK mode only — throws in CLI mode.
|
|
283
|
+
*/
|
|
284
|
+
async accountInfo() {
|
|
285
|
+
this.requireSdk('accountInfo');
|
|
286
|
+
return this.sdkExecutor.accountInfo();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get available models with their capabilities.
|
|
290
|
+
* SDK mode only — throws in CLI mode.
|
|
291
|
+
*/
|
|
292
|
+
async supportedModels() {
|
|
293
|
+
this.requireSdk('supportedModels');
|
|
294
|
+
return this.sdkExecutor.supportedModels();
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get available slash commands.
|
|
298
|
+
* SDK mode only — throws in CLI mode.
|
|
299
|
+
*/
|
|
300
|
+
async supportedCommands() {
|
|
301
|
+
this.requireSdk('supportedCommands');
|
|
302
|
+
return this.sdkExecutor.supportedCommands();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get available subagents.
|
|
306
|
+
* SDK mode only — throws in CLI mode.
|
|
307
|
+
*/
|
|
308
|
+
async supportedAgents() {
|
|
309
|
+
this.requireSdk('supportedAgents');
|
|
310
|
+
return this.sdkExecutor.supportedAgents();
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get MCP server connection statuses.
|
|
314
|
+
* SDK mode only — throws in CLI mode.
|
|
315
|
+
*/
|
|
316
|
+
async mcpServerStatus() {
|
|
317
|
+
this.requireSdk('mcpServerStatus');
|
|
318
|
+
return this.sdkExecutor.mcpServerStatus();
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Interrupt the current query execution.
|
|
322
|
+
* SDK mode only — throws in CLI mode.
|
|
323
|
+
*/
|
|
324
|
+
async interrupt() {
|
|
325
|
+
this.requireSdk('interrupt');
|
|
326
|
+
await this.sdkExecutor.interrupt();
|
|
327
|
+
}
|
|
328
|
+
requireSdk(method) {
|
|
329
|
+
if (!this.sdkExecutor) {
|
|
330
|
+
throw new Error(`${method}() is only available in SDK mode. Set useSdk: true (default) to use this method.`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
214
333
|
}
|
|
215
334
|
//# sourceMappingURL=claude.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/client/claude.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/client/claude.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAA2C,MAAM,6BAA6B,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GAInB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAqB,MAAM,2BAA2B,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,MAAM;IACA,OAAO,CAA0B;IACjC,QAAQ,CAAY;IACpB,WAAW,GAAuB,IAAI,CAAC;IAExD,YAAY,UAAyB,EAAE,EAAE,QAAoB;QAC3D,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;QAE7C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,KAAK,C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C,UAAU,CAAC,iBAAiB,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,WAAY,CAAC,eAAe,EAAE,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,iBAAiB;QACrB,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,WAAY,CAAC,iBAAiB,EAAE,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,WAAY,CAAC,eAAe,EAAE,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,WAAY,CAAC,eAAe,EAAE,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7B,MAAM,IAAI,CAAC,WAAY,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAEO,UAAU,CAAC,MAAc;QAC/B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,kFAAkF,CAAC,CAAC;QAC/G,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import { EVENT_TEXT, EVENT_TOOL_USE, EVENT_RESULT, EVENT_ERROR, EVENT_SYSTEM } from '../constants.js';
|
|
3
|
-
import type { StreamEvent, StreamToolUseEvent, StreamResultEvent, StreamErrorEvent, StreamSystemEvent } from '../types/index.js';
|
|
2
|
+
import { EVENT_TEXT, EVENT_TOOL_USE, EVENT_RESULT, EVENT_ERROR, EVENT_SYSTEM, EVENT_TASK_STARTED, EVENT_TASK_PROGRESS, EVENT_TASK_NOTIFICATION } from '../constants.js';
|
|
3
|
+
import type { StreamEvent, StreamToolUseEvent, StreamResultEvent, StreamErrorEvent, StreamSystemEvent, StreamTaskStartedEvent, StreamTaskProgressEvent, StreamTaskNotificationEvent } from '../types/index.js';
|
|
4
4
|
type TextCallback = (text: string) => void;
|
|
5
5
|
type ToolUseCallback = (event: StreamToolUseEvent) => void;
|
|
6
6
|
type ResultCallback = (event: StreamResultEvent) => void;
|
|
7
7
|
type ErrorCallback = (event: StreamErrorEvent) => void;
|
|
8
8
|
type SystemCallback = (event: StreamSystemEvent) => void;
|
|
9
|
+
type TaskStartedCallback = (event: StreamTaskStartedEvent) => void;
|
|
10
|
+
type TaskProgressCallback = (event: StreamTaskProgressEvent) => void;
|
|
11
|
+
type TaskNotificationCallback = (event: StreamTaskNotificationEvent) => void;
|
|
9
12
|
/**
|
|
10
13
|
* A streaming response handle with fluent callback API and Node.js stream support.
|
|
11
14
|
*
|
|
@@ -15,6 +18,7 @@ type SystemCallback = (event: StreamSystemEvent) => void;
|
|
|
15
18
|
* await claude.stream('Refactor auth')
|
|
16
19
|
* .on('text', (text) => process.stdout.write(text))
|
|
17
20
|
* .on('tool_use', (event) => console.log(event.toolName))
|
|
21
|
+
* .on('task_started', (event) => console.log(`Task: ${event.description}`))
|
|
18
22
|
* .done()
|
|
19
23
|
* ```
|
|
20
24
|
*
|
|
@@ -45,6 +49,9 @@ export declare class StreamHandle implements AsyncIterable<StreamEvent> {
|
|
|
45
49
|
private readonly resultCallbacks;
|
|
46
50
|
private readonly errorCallbacks;
|
|
47
51
|
private readonly systemCallbacks;
|
|
52
|
+
private readonly taskStartedCallbacks;
|
|
53
|
+
private readonly taskProgressCallbacks;
|
|
54
|
+
private readonly taskNotificationCallbacks;
|
|
48
55
|
constructor(source: () => AsyncIterable<StreamEvent>);
|
|
49
56
|
/**
|
|
50
57
|
* Register a callback for a specific event type. Returns `this` for chaining.
|
|
@@ -56,6 +63,9 @@ export declare class StreamHandle implements AsyncIterable<StreamEvent> {
|
|
|
56
63
|
on(type: typeof EVENT_RESULT, callback: ResultCallback): this;
|
|
57
64
|
on(type: typeof EVENT_ERROR, callback: ErrorCallback): this;
|
|
58
65
|
on(type: typeof EVENT_SYSTEM, callback: SystemCallback): this;
|
|
66
|
+
on(type: typeof EVENT_TASK_STARTED, callback: TaskStartedCallback): this;
|
|
67
|
+
on(type: typeof EVENT_TASK_PROGRESS, callback: TaskProgressCallback): this;
|
|
68
|
+
on(type: typeof EVENT_TASK_NOTIFICATION, callback: TaskNotificationCallback): this;
|
|
59
69
|
/**
|
|
60
70
|
* Consume the stream, fire all registered callbacks, return the final result.
|
|
61
71
|
*/
|
|
@@ -77,16 +87,6 @@ export declare class StreamHandle implements AsyncIterable<StreamEvent> {
|
|
|
77
87
|
/**
|
|
78
88
|
* Get a Node.js Readable that emits text chunks.
|
|
79
89
|
* Use for `pipeline()`, standard `.pipe()` chaining, HTTP responses, etc.
|
|
80
|
-
*
|
|
81
|
-
* ```ts
|
|
82
|
-
* claude.stream('Generate').toReadable().pipe(res)
|
|
83
|
-
*
|
|
84
|
-
* await pipeline(
|
|
85
|
-
* claude.stream('Report').toReadable(),
|
|
86
|
-
* createGzip(),
|
|
87
|
-
* createWriteStream('report.gz'),
|
|
88
|
-
* )
|
|
89
|
-
* ```
|
|
90
90
|
*/
|
|
91
91
|
toReadable(): Readable;
|
|
92
92
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handle.d.ts","sourceRoot":"","sources":["../../src/client/stream-handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,WAAW,EACX,YAAY,
|
|
1
|
+
{"version":3,"file":"stream-handle.d.ts","sourceRoot":"","sources":["../../src/client/stream-handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAA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