@scottwalker/claude-connector 0.1.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/LICENSE +21 -0
- package/README.md +444 -0
- package/dist/builder/args-builder.d.ts +64 -0
- package/dist/builder/args-builder.d.ts.map +1 -0
- package/dist/builder/args-builder.js +134 -0
- package/dist/builder/args-builder.js.map +1 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +2 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/client/claude.d.ts +120 -0
- package/dist/client/claude.d.ts.map +1 -0
- package/dist/client/claude.js +182 -0
- package/dist/client/claude.js.map +1 -0
- package/dist/client/session.d.ts +64 -0
- package/dist/client/session.d.ts.map +1 -0
- package/dist/client/session.js +128 -0
- package/dist/client/session.js.map +1 -0
- package/dist/errors/errors.d.ts +52 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +78 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/executor/cli-executor.d.ts +35 -0
- package/dist/executor/cli-executor.d.ts.map +1 -0
- package/dist/executor/cli-executor.js +223 -0
- package/dist/executor/cli-executor.js.map +1 -0
- package/dist/executor/index.d.ts +4 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +3 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/interface.d.ts +65 -0
- package/dist/executor/interface.d.ts.map +1 -0
- package/dist/executor/interface.js +2 -0
- package/dist/executor/interface.js.map +1 -0
- package/dist/executor/sdk-executor.d.ts +102 -0
- package/dist/executor/sdk-executor.d.ts.map +1 -0
- package/dist/executor/sdk-executor.js +256 -0
- package/dist/executor/sdk-executor.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/index.d.ts +3 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +3 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/json-parser.d.ts +22 -0
- package/dist/parser/json-parser.d.ts.map +1 -0
- package/dist/parser/json-parser.js +87 -0
- package/dist/parser/json-parser.js.map +1 -0
- package/dist/parser/stream-parser.d.ts +21 -0
- package/dist/parser/stream-parser.d.ts.map +1 -0
- package/dist/parser/stream-parser.js +84 -0
- package/dist/parser/stream-parser.js.map +1 -0
- package/dist/scheduler/index.d.ts +2 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +65 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/scheduler.js +134 -0
- package/dist/scheduler/scheduler.js.map +1 -0
- package/dist/types/client.d.ts +184 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +2 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/result.d.ts +94 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +2 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/session.d.ts +37 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +2 -0
- package/dist/types/session.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validation.d.ts +15 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +45 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { QueryOptions, QueryResult } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Event map for ScheduledJob.
|
|
5
|
+
*/
|
|
6
|
+
export interface ScheduledJobEvents {
|
|
7
|
+
result: [QueryResult];
|
|
8
|
+
error: [Error];
|
|
9
|
+
tick: [number];
|
|
10
|
+
stop: [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A scheduled recurring query job.
|
|
14
|
+
*
|
|
15
|
+
* Implements the equivalent of Claude Code's `/loop` command,
|
|
16
|
+
* but at the Node.js level — so it works outside interactive sessions.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const job = claude.loop('5m', 'Check deploy status')
|
|
21
|
+
* job.on('result', (r) => console.log(r.text))
|
|
22
|
+
* job.on('error', (e) => console.error(e))
|
|
23
|
+
* job.stop()
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class ScheduledJob extends EventEmitter<ScheduledJobEvents> {
|
|
27
|
+
private readonly queryFn;
|
|
28
|
+
private readonly options?;
|
|
29
|
+
private timer;
|
|
30
|
+
private _tickCount;
|
|
31
|
+
private _running;
|
|
32
|
+
private _stopped;
|
|
33
|
+
readonly intervalMs: number;
|
|
34
|
+
readonly prompt: string;
|
|
35
|
+
constructor(intervalMs: number, prompt: string, queryFn: (prompt: string, options?: QueryOptions) => Promise<QueryResult>, options?: QueryOptions | undefined);
|
|
36
|
+
/** Number of ticks (executions) so far. */
|
|
37
|
+
get tickCount(): number;
|
|
38
|
+
/** Whether a query is currently running. */
|
|
39
|
+
get running(): boolean;
|
|
40
|
+
/** Whether the job has been stopped. */
|
|
41
|
+
get stopped(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Start the scheduled job.
|
|
44
|
+
* Executes immediately, then repeats at the configured interval.
|
|
45
|
+
*/
|
|
46
|
+
start(): this;
|
|
47
|
+
/**
|
|
48
|
+
* Stop the scheduled job.
|
|
49
|
+
*/
|
|
50
|
+
stop(): void;
|
|
51
|
+
private tick;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Scheduler factory — creates ScheduledJob instances.
|
|
55
|
+
*
|
|
56
|
+
* Separated from Claude class to keep the client focused on core query logic.
|
|
57
|
+
*/
|
|
58
|
+
export declare class Scheduler {
|
|
59
|
+
private readonly client;
|
|
60
|
+
constructor(client: {
|
|
61
|
+
query: (prompt: string, options?: QueryOptions) => Promise<QueryResult>;
|
|
62
|
+
});
|
|
63
|
+
schedule(interval: string | number, prompt: string, options?: QueryOptions): ScheduledJob;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/scheduler/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA4BnE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC;IACtB,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IACf,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,IAAI,EAAE,EAAE,CAAC;CACV;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,YAAY,CAAC,kBAAkB,CAAC;IAY9D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAZ3B,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IAEzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,EACzE,OAAO,CAAC,EAAE,YAAY,YAAA;IAOzC,2CAA2C;IAC3C,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,4CAA4C;IAC5C,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,wCAAwC;IACxC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;OAGG;IACH,KAAK,IAAI,IAAI;IAqBb;;OAEG;IACH,IAAI,IAAI,IAAI;YASE,IAAI;CAkBnB;AAED;;;;GAIG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;KAAE;IAGtG,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,YAAY;CAK1F"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { ValidationError } from '../errors/errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interval string parser.
|
|
5
|
+
* Supports: '30s', '5m', '2h', '1d', or raw milliseconds.
|
|
6
|
+
*/
|
|
7
|
+
function parseInterval(interval) {
|
|
8
|
+
if (typeof interval === 'number')
|
|
9
|
+
return interval;
|
|
10
|
+
const match = interval.match(/^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/i);
|
|
11
|
+
if (!match) {
|
|
12
|
+
throw new ValidationError('interval', `Invalid format '${interval}'. Use: '30s', '5m', '2h', '1d'`);
|
|
13
|
+
}
|
|
14
|
+
const value = parseFloat(match[1]);
|
|
15
|
+
const unit = match[2].toLowerCase();
|
|
16
|
+
const multipliers = {
|
|
17
|
+
s: 1_000,
|
|
18
|
+
m: 60_000,
|
|
19
|
+
h: 3_600_000,
|
|
20
|
+
d: 86_400_000,
|
|
21
|
+
};
|
|
22
|
+
return Math.round(value * multipliers[unit]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A scheduled recurring query job.
|
|
26
|
+
*
|
|
27
|
+
* Implements the equivalent of Claude Code's `/loop` command,
|
|
28
|
+
* but at the Node.js level — so it works outside interactive sessions.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const job = claude.loop('5m', 'Check deploy status')
|
|
33
|
+
* job.on('result', (r) => console.log(r.text))
|
|
34
|
+
* job.on('error', (e) => console.error(e))
|
|
35
|
+
* job.stop()
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export class ScheduledJob extends EventEmitter {
|
|
39
|
+
queryFn;
|
|
40
|
+
options;
|
|
41
|
+
timer = null;
|
|
42
|
+
_tickCount = 0;
|
|
43
|
+
_running = false;
|
|
44
|
+
_stopped = false;
|
|
45
|
+
intervalMs;
|
|
46
|
+
prompt;
|
|
47
|
+
constructor(intervalMs, prompt, queryFn, options) {
|
|
48
|
+
super();
|
|
49
|
+
this.queryFn = queryFn;
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.intervalMs = intervalMs;
|
|
52
|
+
this.prompt = prompt;
|
|
53
|
+
}
|
|
54
|
+
/** Number of ticks (executions) so far. */
|
|
55
|
+
get tickCount() {
|
|
56
|
+
return this._tickCount;
|
|
57
|
+
}
|
|
58
|
+
/** Whether a query is currently running. */
|
|
59
|
+
get running() {
|
|
60
|
+
return this._running;
|
|
61
|
+
}
|
|
62
|
+
/** Whether the job has been stopped. */
|
|
63
|
+
get stopped() {
|
|
64
|
+
return this._stopped;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Start the scheduled job.
|
|
68
|
+
* Executes immediately, then repeats at the configured interval.
|
|
69
|
+
*/
|
|
70
|
+
start() {
|
|
71
|
+
if (this._stopped)
|
|
72
|
+
return this;
|
|
73
|
+
// Execute immediately on first tick
|
|
74
|
+
void this.tick();
|
|
75
|
+
this.timer = setInterval(() => {
|
|
76
|
+
// Skip if previous tick is still running (no overlap)
|
|
77
|
+
if (!this._running) {
|
|
78
|
+
void this.tick();
|
|
79
|
+
}
|
|
80
|
+
}, this.intervalMs);
|
|
81
|
+
// Allow the process to exit even if the timer is running
|
|
82
|
+
if (this.timer && typeof this.timer === 'object' && 'unref' in this.timer) {
|
|
83
|
+
this.timer.unref();
|
|
84
|
+
}
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Stop the scheduled job.
|
|
89
|
+
*/
|
|
90
|
+
stop() {
|
|
91
|
+
this._stopped = true;
|
|
92
|
+
if (this.timer) {
|
|
93
|
+
clearInterval(this.timer);
|
|
94
|
+
this.timer = null;
|
|
95
|
+
}
|
|
96
|
+
this.emit('stop');
|
|
97
|
+
}
|
|
98
|
+
async tick() {
|
|
99
|
+
this._running = true;
|
|
100
|
+
this._tickCount++;
|
|
101
|
+
this.emit('tick', this._tickCount);
|
|
102
|
+
try {
|
|
103
|
+
const result = await this.queryFn(this.prompt, this.options);
|
|
104
|
+
if (!this._stopped) {
|
|
105
|
+
this.emit('result', result);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (!this._stopped) {
|
|
110
|
+
this.emit('error', error instanceof Error ? error : new Error(String(error)));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
this._running = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Scheduler factory — creates ScheduledJob instances.
|
|
120
|
+
*
|
|
121
|
+
* Separated from Claude class to keep the client focused on core query logic.
|
|
122
|
+
*/
|
|
123
|
+
export class Scheduler {
|
|
124
|
+
client;
|
|
125
|
+
constructor(client) {
|
|
126
|
+
this.client = client;
|
|
127
|
+
}
|
|
128
|
+
schedule(interval, prompt, options) {
|
|
129
|
+
const ms = parseInterval(interval);
|
|
130
|
+
const job = new ScheduledJob(ms, prompt, (p, o) => this.client.query(p, o), options);
|
|
131
|
+
return job.start();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/scheduler/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;GAGG;AACH,SAAS,aAAa,CAAC,QAAyB;IAC9C,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAElD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC/D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,eAAe,CAAC,UAAU,EAAE,mBAAmB,QAAQ,iCAAiC,CAAC,CAAC;IACtG,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC;IAErC,MAAM,WAAW,GAA2B;QAC1C,CAAC,EAAE,KAAK;QACR,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,SAAS;QACZ,CAAC,EAAE,UAAU;KACd,CAAC;IAEF,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAE,CAAC,CAAC;AAChD,CAAC;AAYD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAa,SAAQ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;QACxE,MAAM,EAAE,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACrF,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Claude client instance.
|
|
3
|
+
*
|
|
4
|
+
* Options set here act as defaults for all queries made through this client.
|
|
5
|
+
* Per-query overrides are available via {@link QueryOptions}.
|
|
6
|
+
*/
|
|
7
|
+
export interface ClientOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Path to the Claude Code CLI executable.
|
|
10
|
+
* Defaults to 'claude' (resolved from PATH).
|
|
11
|
+
*
|
|
12
|
+
* Useful when multiple CLI versions are installed:
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* new Claude({ executable: '/usr/local/bin/claude-2.0' })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
readonly executable?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Use the Claude Agent SDK (V2) instead of spawning CLI processes.
|
|
21
|
+
*
|
|
22
|
+
* When `true`, creates a persistent SDK session that stays warm.
|
|
23
|
+
* First query requires initialization (~5-10s), but subsequent queries
|
|
24
|
+
* are near-instant. Call `claude.init()` to warm up explicitly,
|
|
25
|
+
* or let it auto-initialize on the first query.
|
|
26
|
+
*
|
|
27
|
+
* Subscribe to initialization events:
|
|
28
|
+
* ```ts
|
|
29
|
+
* claude.on('init:stage', (stage, msg) => console.log(stage, msg))
|
|
30
|
+
* claude.on('init:ready', () => console.log('Ready!'))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Requires `@anthropic-ai/claude-agent-sdk` to be installed.
|
|
34
|
+
*/
|
|
35
|
+
readonly useSdk?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Working directory for Claude Code operations.
|
|
38
|
+
* Defaults to `process.cwd()`.
|
|
39
|
+
*/
|
|
40
|
+
readonly cwd?: string;
|
|
41
|
+
/** Model identifier: 'opus', 'sonnet', 'haiku', or a full model ID. */
|
|
42
|
+
readonly model?: string;
|
|
43
|
+
/** Thinking depth: 'low' | 'medium' | 'high'. */
|
|
44
|
+
readonly effortLevel?: EffortLevel;
|
|
45
|
+
/** Model to fall back to if the primary model fails. */
|
|
46
|
+
readonly fallbackModel?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Permission mode controlling tool approval behavior.
|
|
49
|
+
*
|
|
50
|
+
* - `'default'` — prompt on first use
|
|
51
|
+
* - `'acceptEdits'` — auto-accept file edits
|
|
52
|
+
* - `'plan'` — read-only, no modifications
|
|
53
|
+
* - `'bypassPermissions'` — skip all checks (dangerous)
|
|
54
|
+
*/
|
|
55
|
+
readonly permissionMode?: PermissionMode;
|
|
56
|
+
/** Tools that are auto-approved without prompting. Supports glob patterns. */
|
|
57
|
+
readonly allowedTools?: readonly string[];
|
|
58
|
+
/** Tools that are always denied. */
|
|
59
|
+
readonly disallowedTools?: readonly string[];
|
|
60
|
+
/** Override the entire system prompt. */
|
|
61
|
+
readonly systemPrompt?: string;
|
|
62
|
+
/** Append text to the default system prompt. */
|
|
63
|
+
readonly appendSystemPrompt?: string;
|
|
64
|
+
/** Maximum number of agentic turns per query. */
|
|
65
|
+
readonly maxTurns?: number;
|
|
66
|
+
/** Maximum spend in USD per query. */
|
|
67
|
+
readonly maxBudget?: number;
|
|
68
|
+
/** Additional working directories to include. */
|
|
69
|
+
readonly additionalDirs?: readonly string[];
|
|
70
|
+
/** Path(s) to MCP config JSON files. */
|
|
71
|
+
readonly mcpConfig?: string | readonly string[];
|
|
72
|
+
/** Inline MCP server definitions. */
|
|
73
|
+
readonly mcpServers?: Readonly<Record<string, McpServerConfig>>;
|
|
74
|
+
/** Custom subagent definitions. */
|
|
75
|
+
readonly agents?: Readonly<Record<string, AgentConfig>>;
|
|
76
|
+
/** Lifecycle hooks. */
|
|
77
|
+
readonly hooks?: Readonly<HooksConfig>;
|
|
78
|
+
/** Extra environment variables passed to the CLI process. */
|
|
79
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
80
|
+
/** Disable session persistence (useful for CI/automation). */
|
|
81
|
+
readonly noSessionPersistence?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Per-query options that override client defaults.
|
|
85
|
+
*
|
|
86
|
+
* Any field set here takes precedence over the corresponding {@link ClientOptions} field
|
|
87
|
+
* for the duration of a single query.
|
|
88
|
+
*/
|
|
89
|
+
export interface QueryOptions {
|
|
90
|
+
/** Override working directory for this query. */
|
|
91
|
+
readonly cwd?: string;
|
|
92
|
+
/** Override model for this query. */
|
|
93
|
+
readonly model?: string;
|
|
94
|
+
/** Override effort level for this query. */
|
|
95
|
+
readonly effortLevel?: EffortLevel;
|
|
96
|
+
/** Override permission mode for this query. */
|
|
97
|
+
readonly permissionMode?: PermissionMode;
|
|
98
|
+
/** Override allowed tools for this query. */
|
|
99
|
+
readonly allowedTools?: readonly string[];
|
|
100
|
+
/** Override disallowed tools for this query. */
|
|
101
|
+
readonly disallowedTools?: readonly string[];
|
|
102
|
+
/** Override system prompt for this query. */
|
|
103
|
+
readonly systemPrompt?: string;
|
|
104
|
+
/** Append to system prompt for this query. */
|
|
105
|
+
readonly appendSystemPrompt?: string;
|
|
106
|
+
/** Override max turns for this query. */
|
|
107
|
+
readonly maxTurns?: number;
|
|
108
|
+
/** Override max budget for this query. */
|
|
109
|
+
readonly maxBudget?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Piped input — equivalent to `echo "data" | claude -p "prompt"`.
|
|
112
|
+
* Provides additional context alongside the prompt.
|
|
113
|
+
*/
|
|
114
|
+
readonly input?: string;
|
|
115
|
+
/**
|
|
116
|
+
* JSON Schema for structured output.
|
|
117
|
+
* Claude will return validated JSON matching this schema.
|
|
118
|
+
*/
|
|
119
|
+
readonly schema?: Record<string, unknown>;
|
|
120
|
+
/**
|
|
121
|
+
* Run in an isolated git worktree.
|
|
122
|
+
* Pass `true` for auto-generated name, or a string for a specific name.
|
|
123
|
+
*/
|
|
124
|
+
readonly worktree?: boolean | string;
|
|
125
|
+
/** Additional directories for this query. */
|
|
126
|
+
readonly additionalDirs?: readonly string[];
|
|
127
|
+
/** Extra environment variables for this query. */
|
|
128
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
129
|
+
}
|
|
130
|
+
export type PermissionMode = 'default' | 'acceptEdits' | 'plan' | 'dontAsk' | 'bypassPermissions';
|
|
131
|
+
export type EffortLevel = 'low' | 'medium' | 'high';
|
|
132
|
+
export interface McpServerConfig {
|
|
133
|
+
/** Transport type. */
|
|
134
|
+
readonly type?: 'stdio' | 'http' | 'sse';
|
|
135
|
+
/** Command to start stdio server. */
|
|
136
|
+
readonly command?: string;
|
|
137
|
+
/** Arguments for stdio server command. */
|
|
138
|
+
readonly args?: readonly string[];
|
|
139
|
+
/** URL for http/sse server. */
|
|
140
|
+
readonly url?: string;
|
|
141
|
+
/** Environment variables for the server process. */
|
|
142
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
143
|
+
/** HTTP headers for http/sse servers. */
|
|
144
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
145
|
+
}
|
|
146
|
+
export interface AgentConfig {
|
|
147
|
+
/** When to delegate to this agent. */
|
|
148
|
+
readonly description: string;
|
|
149
|
+
/** Initial prompt / instructions for the agent. */
|
|
150
|
+
readonly prompt?: string;
|
|
151
|
+
/** Model for this agent: 'opus', 'sonnet', 'haiku', 'inherit'. */
|
|
152
|
+
readonly model?: string;
|
|
153
|
+
/** Tools available to this agent. */
|
|
154
|
+
readonly tools?: readonly string[];
|
|
155
|
+
/** Tools denied to this agent. */
|
|
156
|
+
readonly disallowedTools?: readonly string[];
|
|
157
|
+
/** Permission mode for this agent. */
|
|
158
|
+
readonly permissionMode?: PermissionMode;
|
|
159
|
+
/** Max agentic turns. */
|
|
160
|
+
readonly maxTurns?: number;
|
|
161
|
+
/** Run in isolated git worktree. */
|
|
162
|
+
readonly isolation?: 'worktree';
|
|
163
|
+
/** Always run as background task. */
|
|
164
|
+
readonly background?: boolean;
|
|
165
|
+
}
|
|
166
|
+
export interface HookEntry {
|
|
167
|
+
/** Shell command to execute. */
|
|
168
|
+
readonly command: string;
|
|
169
|
+
/** Timeout in seconds. */
|
|
170
|
+
readonly timeout?: number;
|
|
171
|
+
}
|
|
172
|
+
export interface HookMatcher {
|
|
173
|
+
/** Regex pattern to match tool names. */
|
|
174
|
+
readonly matcher: string;
|
|
175
|
+
/** Hook entries to execute when matched. */
|
|
176
|
+
readonly hooks: readonly HookEntry[];
|
|
177
|
+
}
|
|
178
|
+
export interface HooksConfig {
|
|
179
|
+
readonly PreToolUse?: readonly HookMatcher[];
|
|
180
|
+
readonly PostToolUse?: readonly HookMatcher[];
|
|
181
|
+
readonly Stop?: readonly HookMatcher[];
|
|
182
|
+
readonly [key: string]: readonly HookMatcher[] | undefined;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/types/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;OASG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEtB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB,iDAAiD;IACjD,QAAQ,CAAC,WAAW,CAAC,E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AU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,SAAS;IACxB,gCAAgC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7C,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAC9C,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IACvC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,WAAW,EAAE,GAAG,SAAS,CAAC;CAC5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/types/client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { ClientOptions, QueryOptions, PermissionMode, EffortLevel, McpServerConfig, AgentConfig, HookEntry, HookMatcher, HooksConfig, } from './client.js';
|
|
2
|
+
export type { QueryResult, StreamEvent, StreamTextEvent, StreamToolUseEvent, StreamResultEvent, StreamErrorEvent, StreamSystemEvent, TokenUsage, Message, ContentBlock, TextBlock, ToolUseBlock, ToolResultBlock, } from './result.js';
|
|
3
|
+
export type { SessionOptions, SessionInfo, } from './session.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACX,eAAe,EACf,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,WAAW,EACX,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,EACd,WAAW,GACZ,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a completed (non-streaming) query.
|
|
3
|
+
*/
|
|
4
|
+
export interface QueryResult {
|
|
5
|
+
/** The text response from Claude. */
|
|
6
|
+
readonly text: string;
|
|
7
|
+
/** Session ID for resuming this conversation. */
|
|
8
|
+
readonly sessionId: string;
|
|
9
|
+
/** Token usage statistics. */
|
|
10
|
+
readonly usage: TokenUsage;
|
|
11
|
+
/** Total cost in USD (available for API users). */
|
|
12
|
+
readonly cost: number | null;
|
|
13
|
+
/** Wall-clock duration in milliseconds. */
|
|
14
|
+
readonly durationMs: number;
|
|
15
|
+
/** Full message history from the conversation. */
|
|
16
|
+
readonly messages: readonly Message[];
|
|
17
|
+
/**
|
|
18
|
+
* Structured output when a JSON schema was provided.
|
|
19
|
+
* `null` if no schema was used.
|
|
20
|
+
*/
|
|
21
|
+
readonly structured: unknown | null;
|
|
22
|
+
/** Raw JSON response from CLI (for advanced use). */
|
|
23
|
+
readonly raw: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A single event emitted during streaming.
|
|
27
|
+
*
|
|
28
|
+
* Discriminated union on the `type` field.
|
|
29
|
+
*/
|
|
30
|
+
export type StreamEvent = StreamTextEvent | StreamToolUseEvent | StreamResultEvent | StreamErrorEvent | StreamSystemEvent;
|
|
31
|
+
export interface StreamTextEvent {
|
|
32
|
+
readonly type: 'text';
|
|
33
|
+
/** Incremental text chunk. */
|
|
34
|
+
readonly text: string;
|
|
35
|
+
}
|
|
36
|
+
export interface StreamToolUseEvent {
|
|
37
|
+
readonly type: 'tool_use';
|
|
38
|
+
/** Tool being invoked (e.g. 'Read', 'Bash'). */
|
|
39
|
+
readonly toolName: string;
|
|
40
|
+
/** Input parameters passed to the tool. */
|
|
41
|
+
readonly toolInput: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export interface StreamResultEvent {
|
|
44
|
+
readonly type: 'result';
|
|
45
|
+
/** Final text result. */
|
|
46
|
+
readonly text: string;
|
|
47
|
+
/** Session ID. */
|
|
48
|
+
readonly sessionId: string;
|
|
49
|
+
/** Token usage. */
|
|
50
|
+
readonly usage: TokenUsage;
|
|
51
|
+
/** Cost in USD. */
|
|
52
|
+
readonly cost: number | null;
|
|
53
|
+
/** Duration in milliseconds. */
|
|
54
|
+
readonly durationMs: number;
|
|
55
|
+
}
|
|
56
|
+
export interface StreamErrorEvent {
|
|
57
|
+
readonly type: 'error';
|
|
58
|
+
/** Error message. */
|
|
59
|
+
readonly message: string;
|
|
60
|
+
/** Error code if available. */
|
|
61
|
+
readonly code?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface StreamSystemEvent {
|
|
64
|
+
readonly type: 'system';
|
|
65
|
+
/** System event subtype. */
|
|
66
|
+
readonly subtype: string;
|
|
67
|
+
/** Event-specific data. */
|
|
68
|
+
readonly data: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
export interface TokenUsage {
|
|
71
|
+
readonly inputTokens: number;
|
|
72
|
+
readonly outputTokens: number;
|
|
73
|
+
}
|
|
74
|
+
export interface Message {
|
|
75
|
+
readonly role: 'user' | 'assistant';
|
|
76
|
+
readonly content: string | readonly ContentBlock[];
|
|
77
|
+
}
|
|
78
|
+
export type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock;
|
|
79
|
+
export interface TextBlock {
|
|
80
|
+
readonly type: 'text';
|
|
81
|
+
readonly text: string;
|
|
82
|
+
}
|
|
83
|
+
export interface ToolUseBlock {
|
|
84
|
+
readonly type: 'tool_use';
|
|
85
|
+
readonly id: string;
|
|
86
|
+
readonly name: string;
|
|
87
|
+
readonly input: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface ToolResultBlock {
|
|
90
|
+
readonly type: 'tool_result';
|
|
91
|
+
readonly tool_use_id: string;
|
|
92
|
+
readonly content: string;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/types/result.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAE3B,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAEtC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAEpC,qDAAqD;IACrD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACnB,eAAe,GACf,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,iBAAiB,CAAC;AAE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;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,YAAY,EAAE,CAAC;CACpD;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,YAAY,GAAG,eAAe,CAAC;AAEtE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/types/result.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating or resuming a session.
|
|
3
|
+
*/
|
|
4
|
+
export interface SessionOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Resume an existing session by ID.
|
|
7
|
+
* If omitted, a new session is created on first query.
|
|
8
|
+
*/
|
|
9
|
+
readonly resume?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Fork the session instead of continuing in-place.
|
|
12
|
+
* Creates a new session ID branching from the resumed session.
|
|
13
|
+
* Only meaningful when `resume` is set.
|
|
14
|
+
*/
|
|
15
|
+
readonly fork?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Continue the most recent session in the working directory.
|
|
18
|
+
* Mutually exclusive with `resume`.
|
|
19
|
+
*/
|
|
20
|
+
readonly continue?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Metadata about a stored session.
|
|
24
|
+
*/
|
|
25
|
+
export interface SessionInfo {
|
|
26
|
+
/** Unique session identifier. */
|
|
27
|
+
readonly sessionId: string;
|
|
28
|
+
/** Human-readable session name (if renamed). */
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
/** Brief summary of the session. */
|
|
31
|
+
readonly summary?: string;
|
|
32
|
+
/** ISO 8601 timestamp of last activity. */
|
|
33
|
+
readonly lastActive: string;
|
|
34
|
+
/** Working directory associated with this session. */
|
|
35
|
+
readonly cwd: string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,gDAAgD;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,sDAAsD;IACtD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ClientOptions, QueryOptions } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates client options at construction time.
|
|
4
|
+
* Fails fast with descriptive error messages.
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateClientOptions(options: ClientOptions): void;
|
|
7
|
+
/**
|
|
8
|
+
* Validates per-query options.
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateQueryOptions(options: QueryOptions): void;
|
|
11
|
+
/**
|
|
12
|
+
* Validates that a prompt is non-empty.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validatePrompt(prompt: string): void;
|
|
15
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErE;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAmBlE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAOhE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAInD"}
|