@scottwalker/claude-connector 0.2.0 → 0.4.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 +249 -21
- package/dist/builder/args-builder.d.ts +2 -1
- package/dist/builder/args-builder.d.ts.map +1 -1
- package/dist/builder/args-builder.js +38 -31
- package/dist/builder/args-builder.js.map +1 -1
- package/dist/client/chat-handle.d.ts +115 -0
- package/dist/client/chat-handle.d.ts.map +1 -0
- package/dist/client/chat-handle.js +246 -0
- package/dist/client/chat-handle.js.map +1 -0
- package/dist/client/claude.d.ts +96 -55
- package/dist/client/claude.d.ts.map +1 -1
- package/dist/client/claude.js +192 -46
- package/dist/client/claude.js.map +1 -1
- package/dist/client/session.d.ts +4 -2
- package/dist/client/session.d.ts.map +1 -1
- package/dist/client/session.js +19 -12
- package/dist/client/session.js.map +1 -1
- package/dist/client/stream-handle.d.ts +99 -0
- package/dist/client/stream-handle.d.ts.map +1 -0
- package/dist/client/stream-handle.js +173 -0
- package/dist/client/stream-handle.js.map +1 -0
- package/dist/constants.d.ts +119 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +164 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/errors.d.ts.map +1 -1
- package/dist/errors/errors.js +7 -6
- package/dist/errors/errors.js.map +1 -1
- package/dist/executor/cli-executor.d.ts.map +1 -1
- package/dist/executor/cli-executor.js +34 -11
- 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 +143 -26
- package/dist/executor/sdk-executor.d.ts.map +1 -1
- package/dist/executor/sdk-executor.js +417 -88
- package/dist/executor/sdk-executor.js.map +1 -1
- package/dist/index.d.ts +74 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -4
- package/dist/index.js.map +1 -1
- package/dist/parser/json-parser.d.ts.map +1 -1
- package/dist/parser/json-parser.js +20 -19
- package/dist/parser/json-parser.js.map +1 -1
- package/dist/parser/stream-parser.d.ts.map +1 -1
- package/dist/parser/stream-parser.js +26 -25
- package/dist/parser/stream-parser.js.map +1 -1
- package/dist/scheduler/scheduler.js +6 -11
- package/dist/scheduler/scheduler.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/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +5 -6
- package/dist/utils/validation.js.map +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Readable, Duplex } from 'node:stream';
|
|
2
|
+
import { EVENT_TEXT, EVENT_TOOL_USE, EVENT_RESULT, EVENT_ERROR, EVENT_SYSTEM } from '../constants.js';
|
|
3
|
+
import type { StreamToolUseEvent, StreamResultEvent, StreamErrorEvent, StreamSystemEvent } from '../types/index.js';
|
|
4
|
+
type TextCallback = (text: string) => void;
|
|
5
|
+
type ToolUseCallback = (event: StreamToolUseEvent) => void;
|
|
6
|
+
type ResultCallback = (event: StreamResultEvent) => void;
|
|
7
|
+
type ErrorCallback = (event: StreamErrorEvent) => void;
|
|
8
|
+
type SystemCallback = (event: StreamSystemEvent) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Bidirectional streaming handle for real-time conversation.
|
|
11
|
+
*
|
|
12
|
+
* Uses `--input-format stream-json` to maintain a persistent CLI process.
|
|
13
|
+
* Send prompts with `.send()`, receive responses via callbacks or Node.js streams.
|
|
14
|
+
*
|
|
15
|
+
* ## Fluent callbacks
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const chat = claude.chat()
|
|
19
|
+
* .on('text', (text) => process.stdout.write(text))
|
|
20
|
+
* .on('result', (event) => console.log('Turn done'))
|
|
21
|
+
*
|
|
22
|
+
* await chat.send('What files are in src?')
|
|
23
|
+
* await chat.send('Fix the largest one')
|
|
24
|
+
* chat.end()
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Node.js Duplex stream
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const duplex = claude.chat().toDuplex()
|
|
31
|
+
* inputStream.pipe(duplex).pipe(process.stdout)
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class ChatHandle {
|
|
35
|
+
private readonly child;
|
|
36
|
+
private readonly textCallbacks;
|
|
37
|
+
private readonly toolUseCallbacks;
|
|
38
|
+
private readonly resultCallbacks;
|
|
39
|
+
private readonly errorCallbacks;
|
|
40
|
+
private readonly systemCallbacks;
|
|
41
|
+
private buffer;
|
|
42
|
+
private _closed;
|
|
43
|
+
private _sessionId;
|
|
44
|
+
private _turnCount;
|
|
45
|
+
constructor(executable: string, args: readonly string[], options: {
|
|
46
|
+
cwd: string;
|
|
47
|
+
env: Record<string, string>;
|
|
48
|
+
});
|
|
49
|
+
/** Session ID (populated after the first result). */
|
|
50
|
+
get sessionId(): string | null;
|
|
51
|
+
/** Number of completed turns. */
|
|
52
|
+
get turnCount(): number;
|
|
53
|
+
/** Whether the chat has been closed. */
|
|
54
|
+
get closed(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Register a callback. Returns `this` for chaining.
|
|
57
|
+
*/
|
|
58
|
+
on(type: typeof EVENT_TEXT, callback: TextCallback): this;
|
|
59
|
+
on(type: typeof EVENT_TOOL_USE, callback: ToolUseCallback): this;
|
|
60
|
+
on(type: typeof EVENT_RESULT, callback: ResultCallback): this;
|
|
61
|
+
on(type: typeof EVENT_ERROR, callback: ErrorCallback): this;
|
|
62
|
+
on(type: typeof EVENT_SYSTEM, callback: SystemCallback): this;
|
|
63
|
+
/**
|
|
64
|
+
* Send a prompt and wait for the complete response.
|
|
65
|
+
* Returns the result event when this turn finishes.
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const result = await chat.send('Find bugs in auth.ts')
|
|
69
|
+
* console.log(result.durationMs)
|
|
70
|
+
*
|
|
71
|
+
* const result2 = await chat.send('Now fix them')
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
send(prompt: string): Promise<StreamResultEvent>;
|
|
75
|
+
/**
|
|
76
|
+
* Pipe text output to a writable stream.
|
|
77
|
+
* Returns the destination for chaining (Node.js convention).
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* chat.pipe(process.stdout)
|
|
81
|
+
* chat.pipe(fs.createWriteStream('log.txt'))
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
pipe<T extends NodeJS.WritableStream>(dest: T): T;
|
|
85
|
+
/**
|
|
86
|
+
* Get a Node.js Readable that emits text chunks.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* claude.chat().toReadable().pipe(res)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
toReadable(): Readable;
|
|
93
|
+
/**
|
|
94
|
+
* Get a Node.js Duplex stream.
|
|
95
|
+
* Write side accepts prompts (one per write). Read side emits text.
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const duplex = claude.chat().toDuplex()
|
|
99
|
+
* inputStream.pipe(duplex).pipe(process.stdout)
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
toDuplex(): Duplex;
|
|
103
|
+
/**
|
|
104
|
+
* Close the chat gracefully — signals EOF to the CLI process.
|
|
105
|
+
*/
|
|
106
|
+
end(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Abort the chat — kills the CLI process immediately.
|
|
109
|
+
*/
|
|
110
|
+
abort(): void;
|
|
111
|
+
private startReading;
|
|
112
|
+
private dispatch;
|
|
113
|
+
}
|
|
114
|
+
export {};
|
|
115
|
+
//# sourceMappingURL=chat-handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-handle.d.ts","sourceRoot":"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MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;IAWvD,qDAAqD;IACrD,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED,iCAAiC;IACjC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,wCAAwC;IACxC,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED;;OAEG;IACH,EAAE,CAAC,IAAI,EAAE,OAAO,UAAU,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI;IACzD,EAAE,CAAC,IAAI,EAAE,OAAO,cAAc,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI;IAChE,EAAE,CAAC,IAAI,EAAE,OAAO,YAAY,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IAC7D,EAAE,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAC3D,EAAE,CAAC,IAAI,EAAE,OAAO,YAAY,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IAY7D;;;;;;;;;;OAUG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwBhD;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;IAKjD;;;;;;OAMG;IACH,UAAU,IAAI,QAAQ;IAYtB;;;;;;;;OAQG;IACH,QAAQ,IAAI,MAAM;IAsBlB;;OAEG;IACH,GAAG,IAAI,IAAI;IAQX;;OAEG;IACH,KAAK,IAAI,IAAI;IASb,OAAO,CAAC,YAAY;IAgCpB,OAAO,CAAC,QAAQ;CAmBjB"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { Readable, Duplex } from 'node:stream';
|
|
3
|
+
import { parseStreamLine } from '../parser/stream-parser.js';
|
|
4
|
+
import { EVENT_TEXT, EVENT_TOOL_USE, EVENT_RESULT, EVENT_ERROR, EVENT_SYSTEM, CHAT_USER_MESSAGE, SIGNAL_SIGTERM, } from '../constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* Bidirectional streaming handle for real-time conversation.
|
|
7
|
+
*
|
|
8
|
+
* Uses `--input-format stream-json` to maintain a persistent CLI process.
|
|
9
|
+
* Send prompts with `.send()`, receive responses via callbacks or Node.js streams.
|
|
10
|
+
*
|
|
11
|
+
* ## Fluent callbacks
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const chat = claude.chat()
|
|
15
|
+
* .on('text', (text) => process.stdout.write(text))
|
|
16
|
+
* .on('result', (event) => console.log('Turn done'))
|
|
17
|
+
*
|
|
18
|
+
* await chat.send('What files are in src?')
|
|
19
|
+
* await chat.send('Fix the largest one')
|
|
20
|
+
* chat.end()
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ## Node.js Duplex stream
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const duplex = claude.chat().toDuplex()
|
|
27
|
+
* inputStream.pipe(duplex).pipe(process.stdout)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class ChatHandle {
|
|
31
|
+
child;
|
|
32
|
+
textCallbacks = [];
|
|
33
|
+
toolUseCallbacks = [];
|
|
34
|
+
resultCallbacks = [];
|
|
35
|
+
errorCallbacks = [];
|
|
36
|
+
systemCallbacks = [];
|
|
37
|
+
buffer = '';
|
|
38
|
+
_closed = false;
|
|
39
|
+
_sessionId = null;
|
|
40
|
+
_turnCount = 0;
|
|
41
|
+
constructor(executable, args, options) {
|
|
42
|
+
this.child = spawn(executable, args, {
|
|
43
|
+
cwd: options.cwd,
|
|
44
|
+
env: { ...process.env, ...options.env },
|
|
45
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
46
|
+
});
|
|
47
|
+
this.startReading();
|
|
48
|
+
}
|
|
49
|
+
/** Session ID (populated after the first result). */
|
|
50
|
+
get sessionId() {
|
|
51
|
+
return this._sessionId;
|
|
52
|
+
}
|
|
53
|
+
/** Number of completed turns. */
|
|
54
|
+
get turnCount() {
|
|
55
|
+
return this._turnCount;
|
|
56
|
+
}
|
|
57
|
+
/** Whether the chat has been closed. */
|
|
58
|
+
get closed() {
|
|
59
|
+
return this._closed;
|
|
60
|
+
}
|
|
61
|
+
on(type, callback) {
|
|
62
|
+
switch (type) {
|
|
63
|
+
case EVENT_TEXT:
|
|
64
|
+
this.textCallbacks.push(callback);
|
|
65
|
+
break;
|
|
66
|
+
case EVENT_TOOL_USE:
|
|
67
|
+
this.toolUseCallbacks.push(callback);
|
|
68
|
+
break;
|
|
69
|
+
case EVENT_RESULT:
|
|
70
|
+
this.resultCallbacks.push(callback);
|
|
71
|
+
break;
|
|
72
|
+
case EVENT_ERROR:
|
|
73
|
+
this.errorCallbacks.push(callback);
|
|
74
|
+
break;
|
|
75
|
+
case EVENT_SYSTEM:
|
|
76
|
+
this.systemCallbacks.push(callback);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Send a prompt and wait for the complete response.
|
|
83
|
+
* Returns the result event when this turn finishes.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const result = await chat.send('Find bugs in auth.ts')
|
|
87
|
+
* console.log(result.durationMs)
|
|
88
|
+
*
|
|
89
|
+
* const result2 = await chat.send('Now fix them')
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
send(prompt) {
|
|
93
|
+
if (this._closed) {
|
|
94
|
+
return Promise.reject(new Error('Chat is closed'));
|
|
95
|
+
}
|
|
96
|
+
const message = JSON.stringify({ type: CHAT_USER_MESSAGE, content: prompt });
|
|
97
|
+
this.child.stdin.write(message + '\n');
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
const onResult = (event) => {
|
|
100
|
+
const idx = this.resultCallbacks.indexOf(onResult);
|
|
101
|
+
if (idx >= 0)
|
|
102
|
+
this.resultCallbacks.splice(idx, 1);
|
|
103
|
+
resolve(event);
|
|
104
|
+
};
|
|
105
|
+
const onError = (event) => {
|
|
106
|
+
const idx = this.errorCallbacks.indexOf(onError);
|
|
107
|
+
if (idx >= 0)
|
|
108
|
+
this.errorCallbacks.splice(idx, 1);
|
|
109
|
+
reject(new Error(event.message));
|
|
110
|
+
};
|
|
111
|
+
this.resultCallbacks.push(onResult);
|
|
112
|
+
this.errorCallbacks.push(onError);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Pipe text output to a writable stream.
|
|
117
|
+
* Returns the destination for chaining (Node.js convention).
|
|
118
|
+
*
|
|
119
|
+
* ```ts
|
|
120
|
+
* chat.pipe(process.stdout)
|
|
121
|
+
* chat.pipe(fs.createWriteStream('log.txt'))
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
pipe(dest) {
|
|
125
|
+
this.textCallbacks.push((text) => dest.write(text));
|
|
126
|
+
return dest;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get a Node.js Readable that emits text chunks.
|
|
130
|
+
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* claude.chat().toReadable().pipe(res)
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
toReadable() {
|
|
136
|
+
const readable = new Readable({
|
|
137
|
+
encoding: 'utf-8',
|
|
138
|
+
read() { },
|
|
139
|
+
});
|
|
140
|
+
this.textCallbacks.push((text) => readable.push(text));
|
|
141
|
+
this.child.on('close', () => readable.push(null));
|
|
142
|
+
return readable;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get a Node.js Duplex stream.
|
|
146
|
+
* Write side accepts prompts (one per write). Read side emits text.
|
|
147
|
+
*
|
|
148
|
+
* ```ts
|
|
149
|
+
* const duplex = claude.chat().toDuplex()
|
|
150
|
+
* inputStream.pipe(duplex).pipe(process.stdout)
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
toDuplex() {
|
|
154
|
+
const chat = this;
|
|
155
|
+
const duplex = new Duplex({
|
|
156
|
+
encoding: 'utf-8',
|
|
157
|
+
write(chunk, _encoding, callback) {
|
|
158
|
+
const prompt = chunk.toString().trim();
|
|
159
|
+
if (prompt) {
|
|
160
|
+
const message = JSON.stringify({ type: CHAT_USER_MESSAGE, content: prompt });
|
|
161
|
+
chat.child.stdin.write(message + '\n');
|
|
162
|
+
}
|
|
163
|
+
callback();
|
|
164
|
+
},
|
|
165
|
+
read() { },
|
|
166
|
+
});
|
|
167
|
+
this.textCallbacks.push((text) => duplex.push(text));
|
|
168
|
+
this.child.on('close', () => duplex.push(null));
|
|
169
|
+
return duplex;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Close the chat gracefully — signals EOF to the CLI process.
|
|
173
|
+
*/
|
|
174
|
+
end() {
|
|
175
|
+
if (this._closed)
|
|
176
|
+
return;
|
|
177
|
+
this._closed = true;
|
|
178
|
+
if (this.child.stdin && !this.child.stdin.destroyed) {
|
|
179
|
+
this.child.stdin.end();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Abort the chat — kills the CLI process immediately.
|
|
184
|
+
*/
|
|
185
|
+
abort() {
|
|
186
|
+
this._closed = true;
|
|
187
|
+
if (!this.child.killed) {
|
|
188
|
+
this.child.kill(SIGNAL_SIGTERM);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ── Private ───────────────────────────────────────────────────────
|
|
192
|
+
startReading() {
|
|
193
|
+
this.child.stdout.on('data', (chunk) => {
|
|
194
|
+
this.buffer += chunk.toString('utf-8');
|
|
195
|
+
const lines = this.buffer.split('\n');
|
|
196
|
+
this.buffer = lines.pop() ?? '';
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
const trimmed = line.trim();
|
|
199
|
+
if (!trimmed)
|
|
200
|
+
continue;
|
|
201
|
+
const event = parseStreamLine(trimmed);
|
|
202
|
+
if (event) {
|
|
203
|
+
if (event.type === EVENT_RESULT) {
|
|
204
|
+
this._sessionId = event.sessionId || this._sessionId;
|
|
205
|
+
this._turnCount++;
|
|
206
|
+
}
|
|
207
|
+
this.dispatch(event);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
// Flush remaining buffer on close
|
|
212
|
+
this.child.stdout.on('end', () => {
|
|
213
|
+
const trimmed = this.buffer.trim();
|
|
214
|
+
if (trimmed) {
|
|
215
|
+
const event = parseStreamLine(trimmed);
|
|
216
|
+
if (event)
|
|
217
|
+
this.dispatch(event);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
dispatch(event) {
|
|
222
|
+
switch (event.type) {
|
|
223
|
+
case EVENT_TEXT:
|
|
224
|
+
for (const cb of this.textCallbacks)
|
|
225
|
+
cb(event.text);
|
|
226
|
+
break;
|
|
227
|
+
case EVENT_TOOL_USE:
|
|
228
|
+
for (const cb of this.toolUseCallbacks)
|
|
229
|
+
cb(event);
|
|
230
|
+
break;
|
|
231
|
+
case EVENT_RESULT:
|
|
232
|
+
for (const cb of this.resultCallbacks)
|
|
233
|
+
cb(event);
|
|
234
|
+
break;
|
|
235
|
+
case EVENT_ERROR:
|
|
236
|
+
for (const cb of this.errorCallbacks)
|
|
237
|
+
cb(event);
|
|
238
|
+
break;
|
|
239
|
+
case EVENT_SYSTEM:
|
|
240
|
+
for (const cb of this.systemCallbacks)
|
|
241
|
+
cb(event);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=chat-handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-handle.js","sourceRoot":"","sources":["../../src/client/chat-handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC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KAAkB;QACjC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,UAAU;gBACb,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,aAAa;oBAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACpD,MAAM;YACR,KAAK,cAAc;gBACjB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,gBAAgB;oBAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,YAAY;gBACf,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,eAAe;oBAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,WAAW;gBACd,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,cAAc;oBAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBAChD,MAAM;YACR,KAAK,YAAY;gBACf,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,eAAe;oBAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBACjD,MAAM;QACV,CAAC;IACH,CAAC;CACF"}
|
package/dist/client/claude.d.ts
CHANGED
|
@@ -1,93 +1,66 @@
|
|
|
1
|
-
import type { ClientOptions, QueryOptions, QueryResult,
|
|
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';
|
|
5
|
+
import { INIT_EVENT_STAGE, INIT_EVENT_READY, INIT_EVENT_ERROR } from '../constants.js';
|
|
5
6
|
import { Session } from './session.js';
|
|
7
|
+
import { StreamHandle } from './stream-handle.js';
|
|
8
|
+
import { ChatHandle } from './chat-handle.js';
|
|
6
9
|
import { type ScheduledJob } from '../scheduler/scheduler.js';
|
|
7
10
|
/**
|
|
8
11
|
* Main entry point for claude-connector.
|
|
9
12
|
*
|
|
10
|
-
* `Claude` is a **facade** that orchestrates the executor, argument builder,
|
|
11
|
-
* and parsers behind a clean, minimal API.
|
|
12
|
-
*
|
|
13
|
-
* ## Execution modes
|
|
14
|
-
*
|
|
15
|
-
* - **CLI mode** (default): each query spawns a new `claude -p` process.
|
|
16
|
-
* Simple, no warm-up needed, but slower for interactive use.
|
|
17
|
-
*
|
|
18
|
-
* - **SDK mode** (`useSdk: true`): creates a persistent session via the
|
|
19
|
-
* Claude Agent SDK. First query requires warm-up (~5-10s), but subsequent
|
|
20
|
-
* queries are near-instant. Best for interactive and high-throughput use.
|
|
21
|
-
*
|
|
22
13
|
* @example
|
|
23
14
|
* ```ts
|
|
24
|
-
* // CLI mode (default)
|
|
25
15
|
* const claude = new Claude({ model: 'sonnet' })
|
|
16
|
+
* const result = await claude.query('Fix bugs')
|
|
17
|
+
*
|
|
18
|
+
* // Streaming with fluent API
|
|
19
|
+
* await claude.stream('Explain auth.ts')
|
|
20
|
+
* .on('text', (t) => process.stdout.write(t))
|
|
21
|
+
* .done()
|
|
26
22
|
*
|
|
27
|
-
* //
|
|
28
|
-
* const
|
|
29
|
-
*
|
|
30
|
-
* await
|
|
31
|
-
*
|
|
23
|
+
* // Bidirectional chat
|
|
24
|
+
* const chat = claude.chat()
|
|
25
|
+
* await chat.send('What files are in src?')
|
|
26
|
+
* await chat.send('Fix the largest one')
|
|
27
|
+
* chat.end()
|
|
32
28
|
* ```
|
|
33
29
|
*/
|
|
34
30
|
export declare class Claude {
|
|
35
|
-
/** Frozen client-level options. */
|
|
36
31
|
private readonly options;
|
|
37
|
-
/** Executor responsible for running CLI commands. */
|
|
38
32
|
private readonly executor;
|
|
39
|
-
/** SdkExecutor reference (only when useSdk: true) for lifecycle control. */
|
|
40
33
|
private readonly sdkExecutor;
|
|
41
34
|
constructor(options?: ClientOptions, executor?: IExecutor);
|
|
42
35
|
/**
|
|
43
36
|
* Initialize the SDK session (warm up).
|
|
44
|
-
*
|
|
45
37
|
* Only needed when `useSdk: true`. In CLI mode this is a no-op.
|
|
46
|
-
*
|
|
47
|
-
* Subscribe to initialization events before calling:
|
|
48
|
-
* ```ts
|
|
49
|
-
* claude.on('init:stage', (stage, message) => {
|
|
50
|
-
* console.log(`[${stage}] ${message}`)
|
|
51
|
-
* })
|
|
52
|
-
* claude.on('init:ready', () => console.log('Ready!'))
|
|
53
|
-
* claude.on('init:error', (err) => console.error(err))
|
|
54
|
-
*
|
|
55
|
-
* await claude.init()
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* Safe to call multiple times — only initializes once.
|
|
59
38
|
*/
|
|
60
39
|
init(): Promise<void>;
|
|
61
40
|
/** Whether the SDK session is initialized and ready (always true for CLI mode). */
|
|
62
41
|
get ready(): boolean;
|
|
63
42
|
/**
|
|
64
43
|
* Subscribe to initialization events.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* - `init:ready` — session is warm and queries will be fast
|
|
70
|
-
* - `init:error` `(error: Error)` — initialization failed
|
|
71
|
-
*
|
|
72
|
-
* Only meaningful when `useSdk: true`. In CLI mode, listeners are never called.
|
|
73
|
-
*/
|
|
74
|
-
on(event: 'init:stage', listener: (stage: InitStage, message: string) => void): this;
|
|
75
|
-
on(event: 'init:ready', listener: () => void): this;
|
|
76
|
-
on(event: 'init:error', listener: (error: Error) => void): this;
|
|
44
|
+
*/
|
|
45
|
+
on(event: typeof INIT_EVENT_STAGE, listener: (stage: InitStage, message: string) => void): this;
|
|
46
|
+
on(event: typeof INIT_EVENT_READY, listener: () => void): this;
|
|
47
|
+
on(event: typeof INIT_EVENT_ERROR, listener: (error: Error) => void): this;
|
|
77
48
|
on(event: string, listener: (...args: never[]) => void): this;
|
|
78
49
|
/**
|
|
79
50
|
* Execute a one-shot query and return the complete result.
|
|
80
|
-
*
|
|
81
|
-
* In SDK mode, auto-initializes if `init()` hasn't been called yet.
|
|
82
51
|
*/
|
|
83
52
|
query(prompt: string, options?: QueryOptions): Promise<QueryResult>;
|
|
84
53
|
/**
|
|
85
54
|
* Execute a query with streaming response.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
55
|
+
* Returns a {@link StreamHandle} with fluent callbacks, Node.js stream support,
|
|
56
|
+
* and backward-compatible async iteration.
|
|
57
|
+
*/
|
|
58
|
+
stream(prompt: string, options?: QueryOptions): StreamHandle;
|
|
59
|
+
/**
|
|
60
|
+
* Open a bidirectional chat — a persistent CLI process for real-time conversation.
|
|
61
|
+
* Uses `--input-format stream-json` for multi-turn dialogue over a single process.
|
|
89
62
|
*/
|
|
90
|
-
|
|
63
|
+
chat(options?: QueryOptions): ChatHandle;
|
|
91
64
|
/**
|
|
92
65
|
* Create a session for multi-turn conversation.
|
|
93
66
|
*/
|
|
@@ -109,12 +82,80 @@ export declare class Claude {
|
|
|
109
82
|
abort(): void;
|
|
110
83
|
/**
|
|
111
84
|
* Close the SDK session and free resources.
|
|
112
|
-
* Only needed when `useSdk: true`. In CLI mode this is a no-op.
|
|
113
85
|
*/
|
|
114
86
|
close(): void;
|
|
115
87
|
/**
|
|
116
88
|
* Access the underlying executor (for advanced use / testing).
|
|
117
89
|
*/
|
|
118
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;
|
|
119
160
|
}
|
|
120
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,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAA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