megacode-agent-sdk 0.0.0-stage → 0.31.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/dist/wire.d.ts ADDED
@@ -0,0 +1,241 @@
1
+ /** harness's limit on one command line, newline included (`cli/rpc.rs`'s `LINE_CAP`). */
2
+ export declare const LINE_LIMIT: number;
3
+ /** The most bytes an approval's reason, or a tool's error message, carries (R8.5.2). */
4
+ export declare const REASON_LIMIT: number;
5
+ /** A wire word this SDK knows, or any other the session sends (R6.3). */
6
+ type Word<T extends string> = T | (string & {});
7
+ export type UserKind = Word<"message" | "steer">;
8
+ export type ToolStatus = Word<"ok" | "failed">;
9
+ export type ApprovalDecision = Word<"allowed_once" | "allowed_for_turn" | "allowed_for_session" | "denied" | "denied_and_stopped" | "timed_out" | "refused">;
10
+ export type ApprovalKind = Word<"gate" | "protected" | "removal" | "decode_and_run" | "credential" | "escape" | "mcp" | "judge_flag" | "judge_unavailable" | "client_tool">;
11
+ export type Choice = Word<"allow_once" | "allow_for_turn" | "deny" | "deny_and_stop">;
12
+ export type Outcome = Word<"completed" | "tool_failed" | "model_failed" | "max_iterations" | "interrupted" | "truncated" | "prompt_blocked">;
13
+ export type Disposition = Word<"started" | "queued" | "accepted" | "dequeued" | "idle" | "stale" | "interrupting" | "answered" | "done" | "set" | "quitting">;
14
+ /** `init`: the session's facts. */
15
+ export interface Info {
16
+ readonly sessionId: string;
17
+ readonly model: string | null;
18
+ readonly mode: string | null;
19
+ readonly cwd: string | null;
20
+ readonly harnessVersion: string;
21
+ readonly commands: readonly string[];
22
+ readonly resumed: boolean;
23
+ /** The client tools' names, in order. */
24
+ readonly clientTools: readonly string[];
25
+ }
26
+ export interface InitEvent extends Info {
27
+ readonly type: "init";
28
+ }
29
+ export interface UserEvent {
30
+ readonly type: "user";
31
+ readonly text: string;
32
+ readonly kind: UserKind;
33
+ }
34
+ export interface ReasoningEvent {
35
+ readonly type: "reasoning";
36
+ readonly text: string;
37
+ }
38
+ export interface AssistantEvent {
39
+ readonly type: "assistant";
40
+ readonly text: string;
41
+ }
42
+ export interface ToolUseEvent {
43
+ readonly type: "tool_use";
44
+ readonly id: string;
45
+ readonly tool: string;
46
+ readonly input: unknown;
47
+ }
48
+ export interface ToolResultEvent {
49
+ readonly type: "tool_result";
50
+ readonly id: string;
51
+ readonly tool: string;
52
+ readonly status: ToolStatus;
53
+ readonly output: unknown;
54
+ readonly error: string | null;
55
+ }
56
+ export interface ApprovalEvent {
57
+ readonly type: "approval";
58
+ readonly id: string;
59
+ readonly tool: string;
60
+ readonly decision: ApprovalDecision;
61
+ readonly reason: string | null;
62
+ readonly session: string | null;
63
+ readonly agent: string | null;
64
+ }
65
+ export interface Escape {
66
+ /** `network` or `outside`. */
67
+ readonly kind: string;
68
+ readonly reason: string;
69
+ }
70
+ /** An answer to an approval request (R8.3.1): the protocol's decisions. */
71
+ export type Decision = {
72
+ readonly kind: "allow_once";
73
+ } | {
74
+ readonly kind: "allow_for_turn";
75
+ } | {
76
+ readonly kind: "deny";
77
+ readonly reason?: string;
78
+ } | {
79
+ readonly kind: "deny_and_stop";
80
+ };
81
+ export interface ApprovalRequest {
82
+ readonly type: "approval_request";
83
+ /** The id an answer names. */
84
+ readonly id: string;
85
+ /** The call's `tool_use` id (empty inside a `script`). */
86
+ readonly toolUseId: string;
87
+ readonly tool: string;
88
+ readonly kind: ApprovalKind;
89
+ readonly reason: string | null;
90
+ readonly escape: Escape | null;
91
+ readonly summary: string;
92
+ readonly input: unknown;
93
+ readonly choices: readonly Choice[];
94
+ readonly turnGrantSkipsKind: boolean;
95
+ readonly session: string | null;
96
+ readonly agent: string | null;
97
+ /** Answers this request (R8.3.3), as `Client.respond` does by id. */
98
+ respond(decision: Decision): Promise<void>;
99
+ }
100
+ export interface Compacted {
101
+ readonly type: "compacted";
102
+ /** `automatic` or `manual`. */
103
+ readonly trigger: string | null;
104
+ readonly preTokens: number | null;
105
+ }
106
+ export interface Usage {
107
+ readonly inputTokens: number;
108
+ readonly outputTokens: number;
109
+ readonly cachedInputTokens: number | null;
110
+ readonly reasoningTokens: number;
111
+ }
112
+ export interface Denied {
113
+ readonly tool: string;
114
+ readonly summary: string;
115
+ }
116
+ export interface Cost {
117
+ readonly usd: number | null;
118
+ readonly priced: number;
119
+ readonly unpriced: number;
120
+ readonly free: number;
121
+ readonly bound: string | null;
122
+ readonly basis: string | null;
123
+ }
124
+ export interface Result {
125
+ readonly type: "result";
126
+ readonly sessionId: string;
127
+ readonly outcome: Outcome | null;
128
+ readonly isError: boolean;
129
+ readonly result: string | null;
130
+ readonly error: string | null;
131
+ readonly model: string | null;
132
+ readonly durationMs: number;
133
+ readonly modelCalls: number;
134
+ readonly usage: Usage;
135
+ readonly denied: readonly Denied[];
136
+ readonly turnId: string | null;
137
+ readonly promptId: string | null;
138
+ readonly cost: Cost | null;
139
+ }
140
+ /** One event of a session, one per outbound line type (R8.5.1). */
141
+ export type Event = InitEvent | UserEvent | ReasoningEvent | AssistantEvent | ToolUseEvent | ToolResultEvent | ApprovalEvent | ApprovalRequest | Compacted | Result;
142
+ /** `get_state`'s data; `turn` is `null` when no turn runs. */
143
+ export interface State {
144
+ readonly sessionId: string;
145
+ readonly model: string | null;
146
+ readonly thinking: string | null;
147
+ readonly mode: string | null;
148
+ readonly away: boolean;
149
+ readonly turn: {
150
+ readonly id: string | null;
151
+ readonly promptId: string | null;
152
+ } | null;
153
+ readonly openRequests: readonly string[];
154
+ readonly queued: number;
155
+ readonly context: {
156
+ readonly lastPromptTokens: number | null;
157
+ readonly window: number | null;
158
+ readonly percent: number | null;
159
+ readonly autoCompactAtPercent: number | null;
160
+ };
161
+ }
162
+ /** A `response` line: consumed by the SDK, never yielded. */
163
+ export interface ResponseLine {
164
+ readonly type: "response";
165
+ readonly id: string | null;
166
+ readonly command: string;
167
+ readonly ok: boolean;
168
+ readonly disposition: string | null;
169
+ readonly data: unknown;
170
+ readonly error: {
171
+ readonly code: string;
172
+ readonly message: string;
173
+ } | null;
174
+ }
175
+ /** A `client_tool_call` line (R3.3). */
176
+ export interface ToolCallLine {
177
+ readonly type: "client_tool_call";
178
+ readonly id: string;
179
+ readonly name: string;
180
+ /** `null` when the arguments were nested too deeply (`tooDeep`). */
181
+ readonly input: unknown;
182
+ /** Present (`true`) when the arguments were nested as deep as
183
+ * `INPUT_DEPTH_LIMIT`: the call is answered `is_error` unrun. */
184
+ readonly tooDeep?: true;
185
+ }
186
+ /** A `client_tool_cancel` line (R3.3.5). */
187
+ export interface ToolCancelLine {
188
+ readonly type: "client_tool_cancel";
189
+ readonly id: string;
190
+ }
191
+ /** A line the SDK reads and does not yield. */
192
+ export type ConsumedLine = ResponseLine | ToolCallLine | ToolCancelLine;
193
+ /** One line read: an event, a consumed line, or `null` for a type this SDK does not read. */
194
+ export type Line = Event | ConsumedLine;
195
+ type Obj = Record<string, unknown>;
196
+ /** Answers an approval request; set by the session that read it. */
197
+ export type Responder = (id: string, decision: Decision) => Promise<void>;
198
+ /** `get_state`'s data, typed. */
199
+ export declare function stateFrom(data: unknown): State;
200
+ /** An idle `compact`'s own compaction, from its `response.data` (Built as R8 a). */
201
+ export declare function compactedOf(data: unknown): Compacted | null;
202
+ /** A line read: the line, and `init`'s protocol version. */
203
+ export interface Decoded {
204
+ readonly line: Line | null;
205
+ readonly v?: number;
206
+ }
207
+ /** Parses one line (without its newline). `respond` answers the
208
+ * `approval_request` events it yields. */
209
+ export declare function decode(text: string, respond?: Responder): Decoded;
210
+ /** The shallowest `input` nesting read as too deep: serde_json reads at
211
+ * most 127 levels in a line, and the line's own object is one of them, so
212
+ * the Rust SDK reads such an `input` as `null` (Built as R8 g). */
213
+ export declare const INPUT_DEPTH_LIMIT = 127;
214
+ /** Whether `value` holds containers nested `limit` deep (a container
215
+ * alone is one level). Walks with its own stack, so no depth overflows it. */
216
+ export declare function nestedAtLeast(value: unknown, limit: number): boolean;
217
+ /** A line's first 200 bytes as a diagnostic shows them, a character cut
218
+ * at the end replaced (Rust's `from_utf8_lossy`). */
219
+ export declare function snippet(line: Uint8Array): string;
220
+ /** `text` with each unpaired surrogate replaced by U+FFFD: harness's JSON
221
+ * parser refuses one, escaped or not, before it reads the line's `id`. */
222
+ export declare function wellFormed(text: string): string;
223
+ /** `value` as JSON text, every string in it well-formed, keys included. An
224
+ * object is copied only when a key needs mending, and one object always
225
+ * becomes the same copy, so `JSON.stringify` still meets a cycle as the same
226
+ * object and throws its `TypeError`. */
227
+ export declare function wellFormedJson(value: unknown): string;
228
+ /** `value` as one UTF-8 JSON line, as `wellFormedJson` writes it. */
229
+ export declare function jsonLine(value: unknown): Buffer;
230
+ /** A command's line, measured against harness's limit (R8.5.2): the encoded
231
+ * line with its newline must fit, else `TooLarge`. */
232
+ export declare function encode(command: Obj): Buffer;
233
+ /** `text` cut to at most `limit` UTF-8 bytes, on a character boundary. */
234
+ export declare function cut(text: string, limit: number): string;
235
+ /** `text` quoted as Rust's `{:?}` prints a `str`, so a name reads the same
236
+ * from every SDK: `\0 \t \r \n \\ \"` escaped, a grapheme-extending or
237
+ * non-printable character as `\u{hex}`, anything else as it is. It agrees
238
+ * with Rust 1.97 on every character this runtime's Unicode data assigns; one
239
+ * assigned only in a later Unicode is escaped here, printed there. */
240
+ export declare function debugQuoted(text: string): string;
241
+ export {};