megacode-agent-sdk 0.0.0-stage → 0.32.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.
@@ -0,0 +1,94 @@
1
+ import { type Options } from "./options.js";
2
+ import { type Compacted, type Decision, type Disposition, type Event, type Info, type State } from "./wire.js";
3
+ /** How long a start waits for `init` (R6.2). */
4
+ export declare const INIT_TIMEOUT_MS = 60000;
5
+ /** A turn's unread events past this end the session (R8.5.5). */
6
+ export declare const UNREAD_LIMIT = 10000;
7
+ /** How long `close` waits for the exit after `quit` (R8.6.2). */
8
+ export declare const QUIT_WAIT_MS = 5000;
9
+ /** How long `close` waits for handler and callback tasks before it stops
10
+ * waiting for them (R8.6.2). */
11
+ export declare const TASK_WAIT_MS = 5000;
12
+ /** How long the reader keeps reading stdout once the process has exited: its
13
+ * last lines are already in the pipe, while a descendant holding the pipe
14
+ * open may never end it. */
15
+ export declare const DRAIN_AFTER_EXIT_MS = 500;
16
+ /** Test support: shortens the wait for `init`. Not part of the API. */
17
+ export declare function setInitTimeoutMs(ms: number): void;
18
+ /** What `compact` did (R8.1.2): queued behind the running turn, or done,
19
+ * with the compaction its own response names (`null` when none was written). */
20
+ export type Compaction = {
21
+ readonly queued: true;
22
+ } | {
23
+ readonly done: Compacted | null;
24
+ };
25
+ /**
26
+ * A stream of events, a turn's or the session's between turns. An error ends
27
+ * the stream (thrown by `next`). `return()` (a `break` out of `for await`)
28
+ * drops the stream: the rest of its events are discarded.
29
+ */
30
+ export declare class Events implements AsyncIterableIterator<Event> {
31
+ constructor();
32
+ next(): Promise<IteratorResult<Event>>;
33
+ return(): Promise<IteratorResult<Event>>;
34
+ [Symbol.asyncIterator](): this;
35
+ }
36
+ /** One turn's events, `user` to `result`. It ends after `result`, or with
37
+ * no event once an abort took its queued prompt back (`dequeued`). */
38
+ export declare class TurnStream extends Events {
39
+ }
40
+ /** A session: every method usable while a turn's stream is read (R8.1.2). */
41
+ export declare class Client {
42
+ private readonly session;
43
+ /** `init`'s data. */
44
+ readonly info: Info;
45
+ private closing;
46
+ private constructor();
47
+ /** The session's id. */
48
+ get id(): string;
49
+ /** Starts a session and reads its `init`. */
50
+ static start(options?: Options): Promise<Client>;
51
+ /** Continues the session `sessionId` (R2.5): the options send only what
52
+ * a resume may give, and the same tools. */
53
+ static resume(sessionId: string, options?: Options): Promise<Client>;
54
+ private static open;
55
+ /** Starts a turn with `prompt` and returns its events, `user` to
56
+ * `result`. One turn at a time: until the wire's `result` (whether or not
57
+ * the stream is read), or an abort that took the prompt back, another
58
+ * `send` is `TurnInProgress`. */
59
+ send(prompt: string): Promise<TurnStream>;
60
+ /** Joins the running turn at its next landing point. */
61
+ steer(text: string): Promise<Disposition>;
62
+ /** Interrupts the program's turn, naming its prompt: a running one is
63
+ * `interrupting`; one still `queued` is taken back, `dequeued`, never runs,
64
+ * and its stream ends with no `result`. With no turn of the program's,
65
+ * whatever runs is interrupted. */
66
+ abort(): Promise<Disposition>;
67
+ /** Compacts the context: at once when idle, after the turn when one runs.
68
+ * `done` carries the compaction its own response names; every `compacted`
69
+ * line goes to the running turn's stream or `sessionEvents()`. */
70
+ compact(): Promise<Compaction>;
71
+ /** Puts the running or next task away, or ends away. */
72
+ away(on: boolean): Promise<Disposition>;
73
+ /** The session's state. */
74
+ state(): Promise<State>;
75
+ /** Answers the approval request `requestId` (R8.3.3). */
76
+ respond(requestId: string, decision: Decision): Promise<void>;
77
+ /** The events that arrive while no turn's stream is open; the first call
78
+ * takes the stream, later calls get `null`. Until it is taken, those
79
+ * events are dropped. */
80
+ sessionEvents(): Events | null;
81
+ /** Ends the session (R8.6.2): every running call's signal fires; `quit`,
82
+ * up to 5 s for the exit, SIGTERM, up to 5 s more, SIGKILL, the process
83
+ * reaped; meanwhile up to 5 s for handler and callback tasks, then they
84
+ * are no longer waited for. Returns within about 15 s. A `close()` never
85
+ * awaited still kills the process at this process's exit. */
86
+ close(): Promise<void>;
87
+ }
88
+ export interface Client {
89
+ [Symbol.asyncDispose](): Promise<void>;
90
+ }
91
+ /** Starts a session, sends `prompt`, and yields `init` and then that turn's
92
+ * events up to its `result`; then the session is closed (R8.1.1). Leaving
93
+ * the loop early closes it too. */
94
+ export declare function query(prompt: string, options?: Options): AsyncGenerator<Event, void, undefined>;