@byfriends/agent-core 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 +28 -0
- package/README.md +11 -0
- package/dist/agent/records/migration/index.d.mts +2 -0
- package/dist/agent/records/migration/index.mjs +2 -0
- package/dist/index-BUBoyyCX.d.mts +3987 -0
- package/dist/index-DitEeLHK.d.mts +17 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +20021 -0
- package/dist/migration-Bg8uYnT_.mjs +79 -0
- package/dist/session/store/index.d.mts +42 -0
- package/dist/session/store/index.mjs +2 -0
- package/dist/store-DhTph1cB.mjs +813 -0
- package/package.json +93 -0
|
@@ -0,0 +1,3987 @@
|
|
|
1
|
+
import { ChatProvider, ContentPart, FinishReason, Message, ModelCapability, ProviderConfig, ProviderRequestAuth, TextPart, ThinkPart, ThinkingEffort, TokenUsage, Tool, ToolCall, ToolCall as ToolCall$1, generate } from "@byfriends/kosong";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
4
|
+
import { Kaos, KaosProcess } from "@byfriends/kaos";
|
|
5
|
+
import { ActivateSkillPayload, AgentAPI, AgentEvent, SDKAgentRPC, SDKSessionRPC, UsageStatus } from "#/rpc";
|
|
6
|
+
import { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
7
|
+
import { ByfConfig, ByfConfigPatch, OAuthRef } from "#/config";
|
|
8
|
+
import { AgentType } from "#/agent";
|
|
9
|
+
import { AgentConfigData, AgentConfigUpdateData } from "#/agent/config";
|
|
10
|
+
import { AgentContextData, ContextMessage } from "#/agent/context";
|
|
11
|
+
import { PermissionApprovalResultRecord, PermissionData, PermissionMode } from "#/agent/permission";
|
|
12
|
+
import { PlanData } from "#/agent/plan";
|
|
13
|
+
import { ToolInfo } from "#/agent/tool";
|
|
14
|
+
import { SessionMeta } from "#/session";
|
|
15
|
+
import { BackgroundTaskInfo } from "#/tools/builtin";
|
|
16
|
+
|
|
17
|
+
//#region src/logging/types.d.ts
|
|
18
|
+
type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
|
|
19
|
+
type LogContext = Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Second argument to `log.error / warn / info / debug`.
|
|
22
|
+
*
|
|
23
|
+
* Three usage shapes, detected at runtime:
|
|
24
|
+
* - `Error` → stack is extracted onto the entry
|
|
25
|
+
* - `LogContext` (object) → merged into entry context; if it contains
|
|
26
|
+
* `{ error: Error }`, that field is pulled out
|
|
27
|
+
* and its stack extracted (bunyan-style)
|
|
28
|
+
* - `unknown` → typically a `catch` binding; treated as an Error if
|
|
29
|
+
* it's an Error instance, otherwise stringified into a
|
|
30
|
+
* `reason` field
|
|
31
|
+
*/
|
|
32
|
+
type LogPayload = unknown;
|
|
33
|
+
interface Logger {
|
|
34
|
+
error(message: string, payload?: LogPayload): void;
|
|
35
|
+
warn(message: string, payload?: LogPayload): void;
|
|
36
|
+
info(message: string, payload?: LogPayload): void;
|
|
37
|
+
debug(message: string, payload?: LogPayload): void;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a new logger that adds `ctx` to every entry it emits. The bound
|
|
40
|
+
* context wins over per-call payload context, so callers can't accidentally
|
|
41
|
+
* overwrite ownership fields like `sessionId` / `agentId`:
|
|
42
|
+
*
|
|
43
|
+
* finalCtx = { ...payloadCtx, ...boundCtx }
|
|
44
|
+
*
|
|
45
|
+
* Children chain — `parent.createChild({a: 1}).createChild({b: 2})` binds
|
|
46
|
+
* both.
|
|
47
|
+
*/
|
|
48
|
+
createChild(ctx: LogContext): Logger;
|
|
49
|
+
}
|
|
50
|
+
interface LogEntry {
|
|
51
|
+
readonly t: number;
|
|
52
|
+
readonly level: Exclude<LogLevel, 'off'>;
|
|
53
|
+
readonly msg: string;
|
|
54
|
+
readonly ctx?: LogContext | undefined;
|
|
55
|
+
readonly error?: {
|
|
56
|
+
readonly message: string;
|
|
57
|
+
readonly stack?: string;
|
|
58
|
+
} | undefined;
|
|
59
|
+
readonly sessionId?: string | undefined;
|
|
60
|
+
readonly sessionLogId?: string | undefined;
|
|
61
|
+
}
|
|
62
|
+
interface LoggingConfig {
|
|
63
|
+
readonly level: LogLevel;
|
|
64
|
+
readonly globalLogPath: string;
|
|
65
|
+
readonly globalMaxBytes: number;
|
|
66
|
+
readonly globalFiles: number;
|
|
67
|
+
readonly sessionMaxBytes: number;
|
|
68
|
+
readonly sessionFiles: number;
|
|
69
|
+
}
|
|
70
|
+
interface SessionLogHandle {
|
|
71
|
+
readonly logger: Logger;
|
|
72
|
+
flush(): Promise<void>;
|
|
73
|
+
close(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
interface SessionAttachInput {
|
|
76
|
+
readonly sessionId: string;
|
|
77
|
+
readonly sessionDir: string;
|
|
78
|
+
}
|
|
79
|
+
interface RootLogger {
|
|
80
|
+
configure(config: LoggingConfig): Promise<void>;
|
|
81
|
+
attachSession(input: SessionAttachInput): SessionLogHandle;
|
|
82
|
+
/** False if any sink could not flush its pending batch. */
|
|
83
|
+
flush(): Promise<boolean>;
|
|
84
|
+
/** False if the global sink could not flush; true when there is no global sink. */
|
|
85
|
+
flushGlobal(): Promise<boolean>;
|
|
86
|
+
/** False if the session sink could not flush; true when there is no active sink. */
|
|
87
|
+
flushSession(sessionId: string): Promise<boolean>;
|
|
88
|
+
flushSync(): void;
|
|
89
|
+
isConfigured(): boolean;
|
|
90
|
+
getConfig(): LoggingConfig | undefined;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/config/schema.d.ts
|
|
94
|
+
declare const ProviderTypeSchema: z.ZodEnum<{
|
|
95
|
+
anthropic: "anthropic";
|
|
96
|
+
openai: "openai";
|
|
97
|
+
"openai-compat": "openai-compat";
|
|
98
|
+
"google-genai": "google-genai";
|
|
99
|
+
openai_responses: "openai_responses";
|
|
100
|
+
vertexai: "vertexai";
|
|
101
|
+
}>;
|
|
102
|
+
type ProviderType = z.infer<typeof ProviderTypeSchema>;
|
|
103
|
+
declare const OAuthRefSchema: z.ZodObject<{
|
|
104
|
+
storage: z.ZodEnum<{
|
|
105
|
+
file: "file";
|
|
106
|
+
keyring: "keyring";
|
|
107
|
+
}>;
|
|
108
|
+
key: z.ZodString;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
type OAuthRef$1 = z.infer<typeof OAuthRefSchema>;
|
|
111
|
+
declare const ProviderConfigSchema: z.ZodObject<{
|
|
112
|
+
type: z.ZodEnum<{
|
|
113
|
+
anthropic: "anthropic";
|
|
114
|
+
openai: "openai";
|
|
115
|
+
"openai-compat": "openai-compat";
|
|
116
|
+
"google-genai": "google-genai";
|
|
117
|
+
openai_responses: "openai_responses";
|
|
118
|
+
vertexai: "vertexai";
|
|
119
|
+
}>;
|
|
120
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
121
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
122
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
123
|
+
thinkingEffortKey: z.ZodOptional<z.ZodString>;
|
|
124
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
125
|
+
storage: z.ZodEnum<{
|
|
126
|
+
file: "file";
|
|
127
|
+
keyring: "keyring";
|
|
128
|
+
}>;
|
|
129
|
+
key: z.ZodString;
|
|
130
|
+
}, z.core.$strip>>;
|
|
131
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
132
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
type ProviderConfig$1 = z.infer<typeof ProviderConfigSchema>;
|
|
135
|
+
declare const ModelAliasSchema: z.ZodObject<{
|
|
136
|
+
provider: z.ZodString;
|
|
137
|
+
model: z.ZodString;
|
|
138
|
+
maxContextSize: z.ZodNumber;
|
|
139
|
+
maxOutputSize: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
141
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
142
|
+
reasoningKey: z.ZodOptional<z.ZodString>;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
type ModelAlias = z.infer<typeof ModelAliasSchema>;
|
|
145
|
+
declare const ThinkingConfigSchema: z.ZodObject<{
|
|
146
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
147
|
+
off: "off";
|
|
148
|
+
auto: "auto";
|
|
149
|
+
on: "on";
|
|
150
|
+
}>>;
|
|
151
|
+
effort: z.ZodOptional<z.ZodString>;
|
|
152
|
+
}, z.core.$strip>;
|
|
153
|
+
type ThinkingConfig = z.infer<typeof ThinkingConfigSchema>;
|
|
154
|
+
declare const PermissionModeSchema: z.ZodEnum<{
|
|
155
|
+
auto: "auto";
|
|
156
|
+
yolo: "yolo";
|
|
157
|
+
manual: "manual";
|
|
158
|
+
}>;
|
|
159
|
+
declare const PermissionRuleDecisionSchema: z.ZodEnum<{
|
|
160
|
+
allow: "allow";
|
|
161
|
+
deny: "deny";
|
|
162
|
+
ask: "ask";
|
|
163
|
+
}>;
|
|
164
|
+
declare const PermissionRuleScopeSchema: z.ZodEnum<{
|
|
165
|
+
"turn-override": "turn-override";
|
|
166
|
+
"session-runtime": "session-runtime";
|
|
167
|
+
project: "project";
|
|
168
|
+
user: "user";
|
|
169
|
+
}>;
|
|
170
|
+
declare const PermissionRuleSchema: z.ZodObject<{
|
|
171
|
+
decision: z.ZodEnum<{
|
|
172
|
+
allow: "allow";
|
|
173
|
+
deny: "deny";
|
|
174
|
+
ask: "ask";
|
|
175
|
+
}>;
|
|
176
|
+
scope: z.ZodDefault<z.ZodEnum<{
|
|
177
|
+
"turn-override": "turn-override";
|
|
178
|
+
"session-runtime": "session-runtime";
|
|
179
|
+
project: "project";
|
|
180
|
+
user: "user";
|
|
181
|
+
}>>;
|
|
182
|
+
pattern: z.ZodString;
|
|
183
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
184
|
+
}, z.core.$strip>;
|
|
185
|
+
declare const PermissionConfigSchema: z.ZodObject<{
|
|
186
|
+
rules: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
187
|
+
decision: z.ZodEnum<{
|
|
188
|
+
allow: "allow";
|
|
189
|
+
deny: "deny";
|
|
190
|
+
ask: "ask";
|
|
191
|
+
}>;
|
|
192
|
+
scope: z.ZodDefault<z.ZodEnum<{
|
|
193
|
+
"turn-override": "turn-override";
|
|
194
|
+
"session-runtime": "session-runtime";
|
|
195
|
+
project: "project";
|
|
196
|
+
user: "user";
|
|
197
|
+
}>>;
|
|
198
|
+
pattern: z.ZodString;
|
|
199
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
200
|
+
}, z.core.$strip>>>;
|
|
201
|
+
}, z.core.$strip>;
|
|
202
|
+
type PermissionConfig = z.infer<typeof PermissionConfigSchema>;
|
|
203
|
+
declare const LoopControlSchema: z.ZodObject<{
|
|
204
|
+
maxStepsPerTurn: z.ZodOptional<z.ZodNumber>;
|
|
205
|
+
maxRetriesPerStep: z.ZodOptional<z.ZodNumber>;
|
|
206
|
+
maxRalphIterations: z.ZodOptional<z.ZodNumber>;
|
|
207
|
+
reservedContextSize: z.ZodOptional<z.ZodNumber>;
|
|
208
|
+
compactionTriggerRatio: z.ZodOptional<z.ZodNumber>;
|
|
209
|
+
}, z.core.$strip>;
|
|
210
|
+
type LoopControl = z.infer<typeof LoopControlSchema>;
|
|
211
|
+
declare const BackgroundConfigSchema: z.ZodObject<{
|
|
212
|
+
maxRunningTasks: z.ZodOptional<z.ZodNumber>;
|
|
213
|
+
keepAliveOnExit: z.ZodOptional<z.ZodBoolean>;
|
|
214
|
+
killGracePeriodMs: z.ZodOptional<z.ZodNumber>;
|
|
215
|
+
agentTaskTimeoutS: z.ZodOptional<z.ZodNumber>;
|
|
216
|
+
printWaitCeilingS: z.ZodOptional<z.ZodNumber>;
|
|
217
|
+
}, z.core.$strip>;
|
|
218
|
+
type BackgroundConfig = z.infer<typeof BackgroundConfigSchema>;
|
|
219
|
+
declare const HookDefSchema: z.ZodObject<{
|
|
220
|
+
event: z.ZodEnum<{
|
|
221
|
+
PreToolUse: "PreToolUse";
|
|
222
|
+
PostToolUse: "PostToolUse";
|
|
223
|
+
PostToolUseFailure: "PostToolUseFailure";
|
|
224
|
+
UserPromptSubmit: "UserPromptSubmit";
|
|
225
|
+
Stop: "Stop";
|
|
226
|
+
StopFailure: "StopFailure";
|
|
227
|
+
SessionStart: "SessionStart";
|
|
228
|
+
SessionEnd: "SessionEnd";
|
|
229
|
+
SubagentStart: "SubagentStart";
|
|
230
|
+
SubagentStop: "SubagentStop";
|
|
231
|
+
PreCompact: "PreCompact";
|
|
232
|
+
PostCompact: "PostCompact";
|
|
233
|
+
Notification: "Notification";
|
|
234
|
+
}>;
|
|
235
|
+
matcher: z.ZodOptional<z.ZodString>;
|
|
236
|
+
command: z.ZodString;
|
|
237
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
238
|
+
}, z.core.$strict>;
|
|
239
|
+
type HookDefConfig = z.infer<typeof HookDefSchema>;
|
|
240
|
+
declare const ByfServiceConfigSchema: z.ZodObject<{
|
|
241
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
242
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
243
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
244
|
+
storage: z.ZodEnum<{
|
|
245
|
+
file: "file";
|
|
246
|
+
keyring: "keyring";
|
|
247
|
+
}>;
|
|
248
|
+
key: z.ZodString;
|
|
249
|
+
}, z.core.$strip>>;
|
|
250
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
251
|
+
}, z.core.$strip>;
|
|
252
|
+
type ByfServiceConfig = z.infer<typeof ByfServiceConfigSchema>;
|
|
253
|
+
declare const ServicesConfigSchema: z.ZodObject<{
|
|
254
|
+
byfSearch: z.ZodOptional<z.ZodObject<{
|
|
255
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
256
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
257
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
258
|
+
storage: z.ZodEnum<{
|
|
259
|
+
file: "file";
|
|
260
|
+
keyring: "keyring";
|
|
261
|
+
}>;
|
|
262
|
+
key: z.ZodString;
|
|
263
|
+
}, z.core.$strip>>;
|
|
264
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
265
|
+
}, z.core.$strip>>;
|
|
266
|
+
byfFetch: z.ZodOptional<z.ZodObject<{
|
|
267
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
268
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
269
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
270
|
+
storage: z.ZodEnum<{
|
|
271
|
+
file: "file";
|
|
272
|
+
keyring: "keyring";
|
|
273
|
+
}>;
|
|
274
|
+
key: z.ZodString;
|
|
275
|
+
}, z.core.$strip>>;
|
|
276
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
277
|
+
}, z.core.$strip>>;
|
|
278
|
+
}, z.core.$strip>;
|
|
279
|
+
type ServicesConfig = z.infer<typeof ServicesConfigSchema>;
|
|
280
|
+
declare const McpServerStdioConfigSchema: z.ZodObject<{
|
|
281
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
282
|
+
startupTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
283
|
+
toolTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
284
|
+
enabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
285
|
+
disabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
286
|
+
transport: z.ZodLiteral<"stdio">;
|
|
287
|
+
command: z.ZodString;
|
|
288
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
289
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
290
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
291
|
+
executor: z.ZodOptional<z.ZodEnum<{
|
|
292
|
+
local: "local";
|
|
293
|
+
kaos: "kaos";
|
|
294
|
+
}>>;
|
|
295
|
+
}, z.core.$strip>;
|
|
296
|
+
type McpServerStdioConfig = z.infer<typeof McpServerStdioConfigSchema>;
|
|
297
|
+
declare const McpServerHttpConfigSchema: z.ZodObject<{
|
|
298
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
299
|
+
startupTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
300
|
+
toolTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
301
|
+
enabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
302
|
+
disabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
303
|
+
transport: z.ZodLiteral<"http">;
|
|
304
|
+
url: z.ZodString;
|
|
305
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
306
|
+
bearerTokenEnvVar: z.ZodOptional<z.ZodString>;
|
|
307
|
+
}, z.core.$strip>;
|
|
308
|
+
type McpServerHttpConfig = z.infer<typeof McpServerHttpConfigSchema>;
|
|
309
|
+
declare const McpServerConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
310
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
311
|
+
startupTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
312
|
+
toolTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
313
|
+
enabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
314
|
+
disabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
315
|
+
transport: z.ZodLiteral<"stdio">;
|
|
316
|
+
command: z.ZodString;
|
|
317
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
318
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
319
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
320
|
+
executor: z.ZodOptional<z.ZodEnum<{
|
|
321
|
+
local: "local";
|
|
322
|
+
kaos: "kaos";
|
|
323
|
+
}>>;
|
|
324
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
325
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
326
|
+
startupTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
327
|
+
toolTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
328
|
+
enabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
329
|
+
disabledTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
330
|
+
transport: z.ZodLiteral<"http">;
|
|
331
|
+
url: z.ZodString;
|
|
332
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
333
|
+
bearerTokenEnvVar: z.ZodOptional<z.ZodString>;
|
|
334
|
+
}, z.core.$strip>], "transport">>;
|
|
335
|
+
type McpServerConfig = z.infer<typeof McpServerConfigSchema>;
|
|
336
|
+
declare const ByfConfigSchema: z.ZodObject<{
|
|
337
|
+
providers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
338
|
+
type: z.ZodEnum<{
|
|
339
|
+
anthropic: "anthropic";
|
|
340
|
+
openai: "openai";
|
|
341
|
+
"openai-compat": "openai-compat";
|
|
342
|
+
"google-genai": "google-genai";
|
|
343
|
+
openai_responses: "openai_responses";
|
|
344
|
+
vertexai: "vertexai";
|
|
345
|
+
}>;
|
|
346
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
347
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
348
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
349
|
+
thinkingEffortKey: z.ZodOptional<z.ZodString>;
|
|
350
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
351
|
+
storage: z.ZodEnum<{
|
|
352
|
+
file: "file";
|
|
353
|
+
keyring: "keyring";
|
|
354
|
+
}>;
|
|
355
|
+
key: z.ZodString;
|
|
356
|
+
}, z.core.$strip>>;
|
|
357
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
358
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
359
|
+
}, z.core.$strip>>>;
|
|
360
|
+
defaultProvider: z.ZodOptional<z.ZodString>;
|
|
361
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
362
|
+
models: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
363
|
+
provider: z.ZodString;
|
|
364
|
+
model: z.ZodString;
|
|
365
|
+
maxContextSize: z.ZodNumber;
|
|
366
|
+
maxOutputSize: z.ZodOptional<z.ZodNumber>;
|
|
367
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
368
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
369
|
+
reasoningKey: z.ZodOptional<z.ZodString>;
|
|
370
|
+
}, z.core.$strip>>>;
|
|
371
|
+
thinking: z.ZodOptional<z.ZodObject<{
|
|
372
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
373
|
+
off: "off";
|
|
374
|
+
auto: "auto";
|
|
375
|
+
on: "on";
|
|
376
|
+
}>>;
|
|
377
|
+
effort: z.ZodOptional<z.ZodString>;
|
|
378
|
+
}, z.core.$strip>>;
|
|
379
|
+
planMode: z.ZodOptional<z.ZodBoolean>;
|
|
380
|
+
yolo: z.ZodOptional<z.ZodBoolean>;
|
|
381
|
+
defaultThinking: z.ZodOptional<z.ZodBoolean>;
|
|
382
|
+
defaultPermissionMode: z.ZodOptional<z.ZodEnum<{
|
|
383
|
+
auto: "auto";
|
|
384
|
+
yolo: "yolo";
|
|
385
|
+
manual: "manual";
|
|
386
|
+
}>>;
|
|
387
|
+
defaultPlanMode: z.ZodOptional<z.ZodBoolean>;
|
|
388
|
+
permission: z.ZodOptional<z.ZodObject<{
|
|
389
|
+
rules: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
390
|
+
decision: z.ZodEnum<{
|
|
391
|
+
allow: "allow";
|
|
392
|
+
deny: "deny";
|
|
393
|
+
ask: "ask";
|
|
394
|
+
}>;
|
|
395
|
+
scope: z.ZodDefault<z.ZodEnum<{
|
|
396
|
+
"turn-override": "turn-override";
|
|
397
|
+
"session-runtime": "session-runtime";
|
|
398
|
+
project: "project";
|
|
399
|
+
user: "user";
|
|
400
|
+
}>>;
|
|
401
|
+
pattern: z.ZodString;
|
|
402
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
403
|
+
}, z.core.$strip>>>;
|
|
404
|
+
}, z.core.$strip>>;
|
|
405
|
+
hooks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
406
|
+
event: z.ZodEnum<{
|
|
407
|
+
PreToolUse: "PreToolUse";
|
|
408
|
+
PostToolUse: "PostToolUse";
|
|
409
|
+
PostToolUseFailure: "PostToolUseFailure";
|
|
410
|
+
UserPromptSubmit: "UserPromptSubmit";
|
|
411
|
+
Stop: "Stop";
|
|
412
|
+
StopFailure: "StopFailure";
|
|
413
|
+
SessionStart: "SessionStart";
|
|
414
|
+
SessionEnd: "SessionEnd";
|
|
415
|
+
SubagentStart: "SubagentStart";
|
|
416
|
+
SubagentStop: "SubagentStop";
|
|
417
|
+
PreCompact: "PreCompact";
|
|
418
|
+
PostCompact: "PostCompact";
|
|
419
|
+
Notification: "Notification";
|
|
420
|
+
}>;
|
|
421
|
+
matcher: z.ZodOptional<z.ZodString>;
|
|
422
|
+
command: z.ZodString;
|
|
423
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
424
|
+
}, z.core.$strict>>>;
|
|
425
|
+
services: z.ZodOptional<z.ZodObject<{
|
|
426
|
+
byfSearch: z.ZodOptional<z.ZodObject<{
|
|
427
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
428
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
429
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
430
|
+
storage: z.ZodEnum<{
|
|
431
|
+
file: "file";
|
|
432
|
+
keyring: "keyring";
|
|
433
|
+
}>;
|
|
434
|
+
key: z.ZodString;
|
|
435
|
+
}, z.core.$strip>>;
|
|
436
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
437
|
+
}, z.core.$strip>>;
|
|
438
|
+
byfFetch: z.ZodOptional<z.ZodObject<{
|
|
439
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
440
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
441
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
442
|
+
storage: z.ZodEnum<{
|
|
443
|
+
file: "file";
|
|
444
|
+
keyring: "keyring";
|
|
445
|
+
}>;
|
|
446
|
+
key: z.ZodString;
|
|
447
|
+
}, z.core.$strip>>;
|
|
448
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
449
|
+
}, z.core.$strip>>;
|
|
450
|
+
}, z.core.$strip>>;
|
|
451
|
+
mergeAllAvailableSkills: z.ZodOptional<z.ZodBoolean>;
|
|
452
|
+
extraSkillDirs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
453
|
+
loopControl: z.ZodOptional<z.ZodObject<{
|
|
454
|
+
maxStepsPerTurn: z.ZodOptional<z.ZodNumber>;
|
|
455
|
+
maxRetriesPerStep: z.ZodOptional<z.ZodNumber>;
|
|
456
|
+
maxRalphIterations: z.ZodOptional<z.ZodNumber>;
|
|
457
|
+
reservedContextSize: z.ZodOptional<z.ZodNumber>;
|
|
458
|
+
compactionTriggerRatio: z.ZodOptional<z.ZodNumber>;
|
|
459
|
+
}, z.core.$strip>>;
|
|
460
|
+
background: z.ZodOptional<z.ZodObject<{
|
|
461
|
+
maxRunningTasks: z.ZodOptional<z.ZodNumber>;
|
|
462
|
+
keepAliveOnExit: z.ZodOptional<z.ZodBoolean>;
|
|
463
|
+
killGracePeriodMs: z.ZodOptional<z.ZodNumber>;
|
|
464
|
+
agentTaskTimeoutS: z.ZodOptional<z.ZodNumber>;
|
|
465
|
+
printWaitCeilingS: z.ZodOptional<z.ZodNumber>;
|
|
466
|
+
}, z.core.$strip>>;
|
|
467
|
+
telemetry: z.ZodOptional<z.ZodBoolean>;
|
|
468
|
+
raw: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
469
|
+
}, z.core.$strip>;
|
|
470
|
+
type ByfConfig$1 = z.infer<typeof ByfConfigSchema>;
|
|
471
|
+
declare const ByfConfigPatchSchema: z.ZodObject<{
|
|
472
|
+
providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
473
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
474
|
+
anthropic: "anthropic";
|
|
475
|
+
openai: "openai";
|
|
476
|
+
"openai-compat": "openai-compat";
|
|
477
|
+
"google-genai": "google-genai";
|
|
478
|
+
openai_responses: "openai_responses";
|
|
479
|
+
vertexai: "vertexai";
|
|
480
|
+
}>>;
|
|
481
|
+
apiKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
482
|
+
baseUrl: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
483
|
+
defaultModel: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
484
|
+
thinkingEffortKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
485
|
+
oauth: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
486
|
+
storage: z.ZodEnum<{
|
|
487
|
+
file: "file";
|
|
488
|
+
keyring: "keyring";
|
|
489
|
+
}>;
|
|
490
|
+
key: z.ZodString;
|
|
491
|
+
}, z.core.$strip>>>;
|
|
492
|
+
env: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
493
|
+
customHeaders: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
494
|
+
}, z.core.$strip>>>;
|
|
495
|
+
defaultProvider: z.ZodOptional<z.ZodString>;
|
|
496
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
497
|
+
models: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
498
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
499
|
+
model: z.ZodOptional<z.ZodString>;
|
|
500
|
+
maxContextSize: z.ZodOptional<z.ZodNumber>;
|
|
501
|
+
maxOutputSize: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
502
|
+
capabilities: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
503
|
+
displayName: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
504
|
+
reasoningKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
505
|
+
}, z.core.$strip>>>;
|
|
506
|
+
thinking: z.ZodOptional<z.ZodObject<{
|
|
507
|
+
mode: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
508
|
+
off: "off";
|
|
509
|
+
auto: "auto";
|
|
510
|
+
on: "on";
|
|
511
|
+
}>>>;
|
|
512
|
+
effort: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
513
|
+
}, z.core.$strip>>;
|
|
514
|
+
planMode: z.ZodOptional<z.ZodBoolean>;
|
|
515
|
+
yolo: z.ZodOptional<z.ZodBoolean>;
|
|
516
|
+
defaultThinking: z.ZodOptional<z.ZodBoolean>;
|
|
517
|
+
defaultPermissionMode: z.ZodOptional<z.ZodEnum<{
|
|
518
|
+
auto: "auto";
|
|
519
|
+
yolo: "yolo";
|
|
520
|
+
manual: "manual";
|
|
521
|
+
}>>;
|
|
522
|
+
defaultPlanMode: z.ZodOptional<z.ZodBoolean>;
|
|
523
|
+
permission: z.ZodOptional<z.ZodObject<{
|
|
524
|
+
rules: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
525
|
+
decision: z.ZodEnum<{
|
|
526
|
+
allow: "allow";
|
|
527
|
+
deny: "deny";
|
|
528
|
+
ask: "ask";
|
|
529
|
+
}>;
|
|
530
|
+
scope: z.ZodDefault<z.ZodEnum<{
|
|
531
|
+
"turn-override": "turn-override";
|
|
532
|
+
"session-runtime": "session-runtime";
|
|
533
|
+
project: "project";
|
|
534
|
+
user: "user";
|
|
535
|
+
}>>;
|
|
536
|
+
pattern: z.ZodString;
|
|
537
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
538
|
+
}, z.core.$strip>>>>;
|
|
539
|
+
}, z.core.$strip>>;
|
|
540
|
+
hooks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
541
|
+
event: z.ZodEnum<{
|
|
542
|
+
PreToolUse: "PreToolUse";
|
|
543
|
+
PostToolUse: "PostToolUse";
|
|
544
|
+
PostToolUseFailure: "PostToolUseFailure";
|
|
545
|
+
UserPromptSubmit: "UserPromptSubmit";
|
|
546
|
+
Stop: "Stop";
|
|
547
|
+
StopFailure: "StopFailure";
|
|
548
|
+
SessionStart: "SessionStart";
|
|
549
|
+
SessionEnd: "SessionEnd";
|
|
550
|
+
SubagentStart: "SubagentStart";
|
|
551
|
+
SubagentStop: "SubagentStop";
|
|
552
|
+
PreCompact: "PreCompact";
|
|
553
|
+
PostCompact: "PostCompact";
|
|
554
|
+
Notification: "Notification";
|
|
555
|
+
}>;
|
|
556
|
+
matcher: z.ZodOptional<z.ZodString>;
|
|
557
|
+
command: z.ZodString;
|
|
558
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
559
|
+
}, z.core.$strict>>>;
|
|
560
|
+
services: z.ZodOptional<z.ZodObject<{
|
|
561
|
+
byfSearch: z.ZodOptional<z.ZodObject<{
|
|
562
|
+
baseUrl: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
563
|
+
apiKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
564
|
+
oauth: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
565
|
+
storage: z.ZodEnum<{
|
|
566
|
+
file: "file";
|
|
567
|
+
keyring: "keyring";
|
|
568
|
+
}>;
|
|
569
|
+
key: z.ZodString;
|
|
570
|
+
}, z.core.$strip>>>;
|
|
571
|
+
customHeaders: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
572
|
+
}, z.core.$strip>>;
|
|
573
|
+
byfFetch: z.ZodOptional<z.ZodObject<{
|
|
574
|
+
baseUrl: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
575
|
+
apiKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
576
|
+
oauth: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
577
|
+
storage: z.ZodEnum<{
|
|
578
|
+
file: "file";
|
|
579
|
+
keyring: "keyring";
|
|
580
|
+
}>;
|
|
581
|
+
key: z.ZodString;
|
|
582
|
+
}, z.core.$strip>>>;
|
|
583
|
+
customHeaders: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
584
|
+
}, z.core.$strip>>;
|
|
585
|
+
}, z.core.$strip>>;
|
|
586
|
+
mergeAllAvailableSkills: z.ZodOptional<z.ZodBoolean>;
|
|
587
|
+
extraSkillDirs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
588
|
+
loopControl: z.ZodOptional<z.ZodObject<{
|
|
589
|
+
maxStepsPerTurn: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
590
|
+
maxRetriesPerStep: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
591
|
+
maxRalphIterations: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
592
|
+
reservedContextSize: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
593
|
+
compactionTriggerRatio: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
594
|
+
}, z.core.$strip>>;
|
|
595
|
+
background: z.ZodOptional<z.ZodObject<{
|
|
596
|
+
maxRunningTasks: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
597
|
+
keepAliveOnExit: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
|
|
598
|
+
killGracePeriodMs: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
599
|
+
agentTaskTimeoutS: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
600
|
+
printWaitCeilingS: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
601
|
+
}, z.core.$strip>>;
|
|
602
|
+
telemetry: z.ZodOptional<z.ZodBoolean>;
|
|
603
|
+
}, z.core.$strict>;
|
|
604
|
+
type ByfConfigPatch$1 = z.infer<typeof ByfConfigPatchSchema>;
|
|
605
|
+
declare function getDefaultConfig(): ByfConfig$1;
|
|
606
|
+
declare function validateConfig(config: unknown): ByfConfig$1;
|
|
607
|
+
declare function formatConfigValidationError(error: unknown): string;
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/mcp/oauth/store.d.ts
|
|
610
|
+
declare class JsonFileStore {
|
|
611
|
+
private readonly dir;
|
|
612
|
+
constructor(dir?: string);
|
|
613
|
+
read<T>(file: string): T | undefined;
|
|
614
|
+
write(file: string, data: unknown): void;
|
|
615
|
+
remove(file: string): void;
|
|
616
|
+
}
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/mcp/oauth/provider.d.ts
|
|
619
|
+
interface McpOAuthProviderOptions {
|
|
620
|
+
/** Friendly name of the MCP server; used in DCR `client_name`. */
|
|
621
|
+
readonly serverName: string;
|
|
622
|
+
/** Canonical resource identity used to isolate credentials for this server entry. */
|
|
623
|
+
readonly serverUrl: string | URL;
|
|
624
|
+
/** JSON store used for persistence. Tests inject an in-memory dir. */
|
|
625
|
+
readonly store: JsonFileStore;
|
|
626
|
+
/** Identifier embedded in DCR `client_name` ("byf (server)"). */
|
|
627
|
+
readonly clientLabel?: string;
|
|
628
|
+
}
|
|
629
|
+
declare class McpOAuthClientProvider implements OAuthClientProvider {
|
|
630
|
+
readonly storeKey: string;
|
|
631
|
+
readonly serverUrl: string;
|
|
632
|
+
private readonly store;
|
|
633
|
+
private readonly clientLabel;
|
|
634
|
+
private _redirectUrl;
|
|
635
|
+
private _codeVerifier;
|
|
636
|
+
private _state;
|
|
637
|
+
private _lastAuthorizationUrl;
|
|
638
|
+
constructor(options: McpOAuthProviderOptions);
|
|
639
|
+
setRedirectUrl(url: URL): void;
|
|
640
|
+
/** URL captured from the most recent `redirectToAuthorization` call. */
|
|
641
|
+
takeAuthorizationUrl(): URL | undefined;
|
|
642
|
+
/** OAuth `state` value generated for the most recent flow, for callback verification. */
|
|
643
|
+
expectedState(): string | undefined;
|
|
644
|
+
resetFlow(): void;
|
|
645
|
+
get redirectUrl(): string | URL;
|
|
646
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
647
|
+
state(): string;
|
|
648
|
+
clientInformation(): OAuthClientInformationMixed | undefined;
|
|
649
|
+
saveClientInformation(info: OAuthClientInformationMixed): void;
|
|
650
|
+
tokens(): OAuthTokens | undefined;
|
|
651
|
+
saveTokens(tokens: OAuthTokens): void;
|
|
652
|
+
redirectToAuthorization(url: URL): void;
|
|
653
|
+
saveCodeVerifier(codeVerifier: string): void;
|
|
654
|
+
codeVerifier(): string;
|
|
655
|
+
saveDiscoveryState(state: OAuthDiscoveryState): void;
|
|
656
|
+
discoveryState(): OAuthDiscoveryState | undefined;
|
|
657
|
+
invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): void;
|
|
658
|
+
private effectiveRedirectUri;
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/mcp/oauth/service.d.ts
|
|
662
|
+
interface McpOAuthServiceOptions {
|
|
663
|
+
/** Storage backend; overrides `byfHomeDir` when supplied. */
|
|
664
|
+
readonly store?: JsonFileStore;
|
|
665
|
+
/** Resolved Byf home; credentials default to `<byfHomeDir>/credentials/mcp/`. */
|
|
666
|
+
readonly byfHomeDir?: string;
|
|
667
|
+
/** Override for the label embedded in DCR `client_name`. */
|
|
668
|
+
readonly clientLabel?: string;
|
|
669
|
+
}
|
|
670
|
+
interface BeginAuthorizationOptions {
|
|
671
|
+
/** Override the `client_name` embedded in the DCR registration request. */
|
|
672
|
+
readonly clientLabel?: string;
|
|
673
|
+
}
|
|
674
|
+
interface BeginAuthorizationResult {
|
|
675
|
+
/** The authorization URL the user must open in their browser. */
|
|
676
|
+
readonly authorizationUrl: URL;
|
|
677
|
+
/**
|
|
678
|
+
* Awaits the OAuth callback, validates `state`, exchanges the code for
|
|
679
|
+
* tokens, and persists them via the provider. Resolves on success;
|
|
680
|
+
* rejects on abort, timeout, or auth-server error.
|
|
681
|
+
*/
|
|
682
|
+
complete(opts?: {
|
|
683
|
+
signal?: AbortSignal;
|
|
684
|
+
timeoutMs?: number;
|
|
685
|
+
}): Promise<void>;
|
|
686
|
+
/**
|
|
687
|
+
* Tears down the callback listener without finishing the flow. Safe to
|
|
688
|
+
* call repeatedly; called automatically by `complete()`.
|
|
689
|
+
*/
|
|
690
|
+
cancel(): Promise<void>;
|
|
691
|
+
}
|
|
692
|
+
declare class McpOAuthService {
|
|
693
|
+
private readonly store;
|
|
694
|
+
private readonly clientLabel;
|
|
695
|
+
private readonly providers;
|
|
696
|
+
constructor(options?: McpOAuthServiceOptions);
|
|
697
|
+
/** Returns the cached provider for `serverName` + `serverUrl`, constructing it on first use. */
|
|
698
|
+
getProvider(serverName: string, serverUrl: string | URL): McpOAuthClientProvider;
|
|
699
|
+
/** True once the provider has persisted tokens for this server/resource identity. */
|
|
700
|
+
hasTokens(serverName: string, serverUrl: string | URL): boolean;
|
|
701
|
+
/**
|
|
702
|
+
* Drive the SDK `auth()` orchestrator far enough to surface an
|
|
703
|
+
* authorization URL. The caller is responsible for displaying the URL
|
|
704
|
+
* (typically via the synthetic authenticate tool) and then awaiting
|
|
705
|
+
* `complete()` to finish the code exchange.
|
|
706
|
+
*/
|
|
707
|
+
beginAuthorization(serverName: string, serverUrl: string | URL, options?: BeginAuthorizationOptions): Promise<BeginAuthorizationResult>;
|
|
708
|
+
/**
|
|
709
|
+
* Clear stored credentials for a server. Use `'all'` after the user
|
|
710
|
+
* explicitly signs out; use `'tokens'` to force a re-auth while keeping
|
|
711
|
+
* the registered DCR client.
|
|
712
|
+
*/
|
|
713
|
+
invalidate(serverName: string, serverUrl: string | URL, scope?: 'all' | 'client' | 'tokens' | 'discovery'): void;
|
|
714
|
+
}
|
|
715
|
+
//#endregion
|
|
716
|
+
//#region src/mcp/types.d.ts
|
|
717
|
+
/**
|
|
718
|
+
* MCP protocol types and the minimal client contract `ToolManager` consumes.
|
|
719
|
+
*
|
|
720
|
+
* Lives in its own file (rather than `toolset.ts`) because the agent-side
|
|
721
|
+
* tool-runtime layer is `ExecutableTool`, not the legacy `Toolset` interface.
|
|
722
|
+
* What remains here is the wire-level surface: tool definitions returned by
|
|
723
|
+
* `tools/list`, the `tools/call` result shape, and the small interface that
|
|
724
|
+
* lets tests inject a fake transport without pulling in the MCP SDK type graph.
|
|
725
|
+
*/
|
|
726
|
+
/**
|
|
727
|
+
* Inline resource contents nested under an EmbeddedResource block.
|
|
728
|
+
* Exactly one of `text` or `blob` is populated, per the MCP schema's
|
|
729
|
+
* `TextResourceContents | BlobResourceContents` union.
|
|
730
|
+
*/
|
|
731
|
+
interface MCPEmbeddedResourceContents {
|
|
732
|
+
uri: string;
|
|
733
|
+
mimeType?: string;
|
|
734
|
+
text?: string;
|
|
735
|
+
blob?: string;
|
|
736
|
+
[key: string]: unknown;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* A content block as returned by an MCP tool call (`tools/call`).
|
|
740
|
+
*
|
|
741
|
+
* This is a structural subset of the MCP protocol `ContentBlock` union,
|
|
742
|
+
* covering the shapes that {@link convertMCPContentBlock} knows how to convert
|
|
743
|
+
* into kosong `ContentPart`s. Additional fields are ignored.
|
|
744
|
+
*/
|
|
745
|
+
interface MCPContentBlock {
|
|
746
|
+
type: string;
|
|
747
|
+
text?: string;
|
|
748
|
+
data?: string;
|
|
749
|
+
mimeType?: string;
|
|
750
|
+
uri?: string;
|
|
751
|
+
resource?: MCPEmbeddedResourceContents;
|
|
752
|
+
[key: string]: unknown;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Result of a single MCP tool invocation.
|
|
756
|
+
*
|
|
757
|
+
* Matches the shape returned by the MCP protocol's `tools/call` method.
|
|
758
|
+
*/
|
|
759
|
+
interface MCPToolResult {
|
|
760
|
+
content: MCPContentBlock[];
|
|
761
|
+
isError: boolean;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* An MCP tool definition as returned by an MCP server's `tools/list` method.
|
|
765
|
+
*/
|
|
766
|
+
interface MCPToolDefinition {
|
|
767
|
+
name: string;
|
|
768
|
+
description: string;
|
|
769
|
+
inputSchema: unknown;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Minimal MCP client interface consumed by {@link McpConnectionManager} and
|
|
773
|
+
* {@link ToolManager}.
|
|
774
|
+
*
|
|
775
|
+
* This is a transport-agnostic seam: implementations can wrap
|
|
776
|
+
* `@modelcontextprotocol/sdk`, a bespoke stdio client, an HTTP SSE client,
|
|
777
|
+
* or a mock for testing. Keeping the surface small lets tests inject fakes
|
|
778
|
+
* without pulling in the full SDK type graph.
|
|
779
|
+
*/
|
|
780
|
+
interface MCPClient {
|
|
781
|
+
/** List the tools advertised by the MCP server. */
|
|
782
|
+
listTools(): Promise<MCPToolDefinition[]>;
|
|
783
|
+
/**
|
|
784
|
+
* Invoke a tool by name with the given JSON arguments.
|
|
785
|
+
*
|
|
786
|
+
* `signal`, when provided, is forwarded to the underlying transport so an
|
|
787
|
+
* abort from the loop (e.g. user cancellation) propagates all the way to
|
|
788
|
+
* the server instead of leaving the request running in the background.
|
|
789
|
+
*/
|
|
790
|
+
callTool(name: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<MCPToolResult>;
|
|
791
|
+
}
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region src/mcp/connection-manager.d.ts
|
|
794
|
+
type McpServerStatus = 'pending' | 'connected' | 'failed' | 'disabled' | 'needs-auth';
|
|
795
|
+
interface McpServerEntry {
|
|
796
|
+
readonly name: string;
|
|
797
|
+
readonly transport: 'stdio' | 'http';
|
|
798
|
+
readonly status: McpServerStatus;
|
|
799
|
+
readonly toolCount: number;
|
|
800
|
+
readonly error?: string;
|
|
801
|
+
}
|
|
802
|
+
type McpStatusListener = (entry: McpServerEntry) => void;
|
|
803
|
+
interface McpConnectionManagerOptions {
|
|
804
|
+
readonly envLookup?: (name: string) => string | undefined;
|
|
805
|
+
/**
|
|
806
|
+
* Optional OAuth orchestrator. When provided, HTTP servers without a
|
|
807
|
+
* static bearer token participate in the OAuth-via-synthetic-tool flow:
|
|
808
|
+
* - If `oauthService.hasTokens(name, url)` is true, the provider is
|
|
809
|
+
* attached to the transport so the SDK can refresh tokens on 401.
|
|
810
|
+
* - Connection failures that look like 401 / `UnauthorizedError` flip
|
|
811
|
+
* the entry into `needs-auth` instead of `failed`; `/mcp-config`
|
|
812
|
+
* drives the browser flow through the synthetic auth tool.
|
|
813
|
+
*/
|
|
814
|
+
readonly oauthService?: McpOAuthService;
|
|
815
|
+
/**
|
|
816
|
+
* Parent logger. Defaults to the global `log`; Session passes its own
|
|
817
|
+
* `session.log` so MCP events land in the session log too.
|
|
818
|
+
*/
|
|
819
|
+
readonly log?: Logger;
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Owns the lifecycle of every configured MCP server for a Session.
|
|
823
|
+
*
|
|
824
|
+
* Servers are connected in parallel; per-server failures are isolated so a
|
|
825
|
+
* crashed or misconfigured entry never blocks Session startup. State
|
|
826
|
+
* transitions are surfaced through {@link onStatusChange} so callers (the
|
|
827
|
+
* Session) can react — registering tools onto the main agent, emitting
|
|
828
|
+
* wire events, or updating the TUI.
|
|
829
|
+
*/
|
|
830
|
+
declare class McpConnectionManager {
|
|
831
|
+
private readonly options;
|
|
832
|
+
private readonly entries;
|
|
833
|
+
private readonly listeners;
|
|
834
|
+
private initialLoad;
|
|
835
|
+
private initialLoadAttemptId;
|
|
836
|
+
private initialLoadStartedAt;
|
|
837
|
+
private initialLoadFinishedAt;
|
|
838
|
+
/**
|
|
839
|
+
* OAuth orchestrator injected at construction time. Consumed by the
|
|
840
|
+
* {@link ToolManager} `needs-auth` branch to build the synthetic
|
|
841
|
+
* `authenticate` tool.
|
|
842
|
+
*/
|
|
843
|
+
readonly oauthService: McpOAuthService | undefined;
|
|
844
|
+
private readonly log;
|
|
845
|
+
constructor(options?: McpConnectionManagerOptions);
|
|
846
|
+
/**
|
|
847
|
+
* Returns the URL of an HTTP MCP server by name, or `undefined` for
|
|
848
|
+
* unknown / non-HTTP / disabled entries. Used by the synthetic auth tool
|
|
849
|
+
* to drive OAuth discovery against the right base URL.
|
|
850
|
+
*/
|
|
851
|
+
getHttpServerUrl(name: string): string | undefined;
|
|
852
|
+
onStatusChange(listener: McpStatusListener): () => void;
|
|
853
|
+
list(): readonly McpServerEntry[];
|
|
854
|
+
get(name: string): McpServerEntry | undefined;
|
|
855
|
+
/**
|
|
856
|
+
* Returns the MCP client, the discovered tools, and the allow-list of tool
|
|
857
|
+
* names for a given connected server, or `undefined` if the server is not
|
|
858
|
+
* currently connected. The allow-list combines the server's `enabledTools`
|
|
859
|
+
* and `disabledTools` filters; callers should only register names in the
|
|
860
|
+
* set.
|
|
861
|
+
*/
|
|
862
|
+
resolved(name: string): {
|
|
863
|
+
client: MCPClient;
|
|
864
|
+
tools: readonly Tool[];
|
|
865
|
+
enabledNames: ReadonlySet<string>;
|
|
866
|
+
} | undefined;
|
|
867
|
+
connectAll(configs: Record<string, McpServerConfig>): Promise<void>;
|
|
868
|
+
waitForInitialLoad(signal?: AbortSignal): Promise<void>;
|
|
869
|
+
initialLoadDurationMs(): number;
|
|
870
|
+
private connectAllNow;
|
|
871
|
+
reconnect(name: string): Promise<void>;
|
|
872
|
+
shutdown(): Promise<void>;
|
|
873
|
+
private connectOne;
|
|
874
|
+
private watchForUnexpectedClose;
|
|
875
|
+
private beginConnectAttempt;
|
|
876
|
+
private createClient;
|
|
877
|
+
private resolveOAuthProvider;
|
|
878
|
+
private shouldMarkNeedsAuth;
|
|
879
|
+
private connectAndDiscoverTools;
|
|
880
|
+
private closeClient;
|
|
881
|
+
private closeRuntimeClient;
|
|
882
|
+
private isCurrent;
|
|
883
|
+
private emit;
|
|
884
|
+
}
|
|
885
|
+
//#endregion
|
|
886
|
+
//#region src/mcp/session-config.d.ts
|
|
887
|
+
interface SessionMcpConfig {
|
|
888
|
+
readonly servers: Record<string, McpServerConfig>;
|
|
889
|
+
}
|
|
890
|
+
//#endregion
|
|
891
|
+
//#region src/skill/types.d.ts
|
|
892
|
+
type SkillSource = 'project' | 'user' | 'extra' | 'builtin';
|
|
893
|
+
interface SkillMetadata {
|
|
894
|
+
readonly name?: string | undefined;
|
|
895
|
+
readonly description?: string | undefined;
|
|
896
|
+
readonly type?: string | undefined;
|
|
897
|
+
readonly whenToUse?: string | undefined;
|
|
898
|
+
readonly disableModelInvocation?: boolean | undefined;
|
|
899
|
+
readonly safe?: boolean | undefined;
|
|
900
|
+
readonly arguments?: readonly unknown[] | string | undefined;
|
|
901
|
+
readonly [key: string]: unknown;
|
|
902
|
+
}
|
|
903
|
+
interface SkillDefinition {
|
|
904
|
+
readonly name: string;
|
|
905
|
+
readonly description: string;
|
|
906
|
+
readonly path: string;
|
|
907
|
+
readonly dir: string;
|
|
908
|
+
readonly content: string;
|
|
909
|
+
readonly metadata: SkillMetadata;
|
|
910
|
+
readonly source: SkillSource;
|
|
911
|
+
readonly mermaid?: string | undefined;
|
|
912
|
+
readonly d2?: string;
|
|
913
|
+
}
|
|
914
|
+
interface SkillSummary$1 {
|
|
915
|
+
readonly name: string;
|
|
916
|
+
readonly description: string;
|
|
917
|
+
readonly path: string;
|
|
918
|
+
readonly source: SkillSource;
|
|
919
|
+
readonly type?: string | undefined;
|
|
920
|
+
readonly disableModelInvocation?: boolean | undefined;
|
|
921
|
+
}
|
|
922
|
+
interface SkillRoot {
|
|
923
|
+
readonly path: string;
|
|
924
|
+
readonly source: SkillSource;
|
|
925
|
+
}
|
|
926
|
+
interface SkippedSkill {
|
|
927
|
+
readonly path: string;
|
|
928
|
+
readonly type: string;
|
|
929
|
+
readonly reason: string;
|
|
930
|
+
}
|
|
931
|
+
//#endregion
|
|
932
|
+
//#region src/skill/scanner.d.ts
|
|
933
|
+
interface DiscoverSkillsOptions {
|
|
934
|
+
readonly roots: readonly SkillRoot[];
|
|
935
|
+
readonly onWarning?: (message: string, cause?: unknown) => void;
|
|
936
|
+
readonly onSkippedByPolicy?: (skill: SkippedSkill) => void;
|
|
937
|
+
readonly readdir?: (p: string) => Promise<readonly string[]>;
|
|
938
|
+
readonly isFile?: (p: string) => Promise<boolean>;
|
|
939
|
+
readonly isDir?: (p: string) => Promise<boolean>;
|
|
940
|
+
readonly parse?: (input: {
|
|
941
|
+
readonly skillMdPath: string;
|
|
942
|
+
readonly skillDirName: string;
|
|
943
|
+
readonly source: SkillSource;
|
|
944
|
+
}) => Promise<SkillDefinition>;
|
|
945
|
+
}
|
|
946
|
+
declare function discoverSkills(options: DiscoverSkillsOptions): Promise<readonly SkillDefinition[]>;
|
|
947
|
+
//#endregion
|
|
948
|
+
//#region src/skill/registry.d.ts
|
|
949
|
+
interface SkillRegistryOptions {
|
|
950
|
+
readonly discover?: typeof discoverSkills;
|
|
951
|
+
readonly onWarning?: (message: string, cause?: unknown) => void;
|
|
952
|
+
readonly sessionId?: string;
|
|
953
|
+
}
|
|
954
|
+
declare class SkillRegistry {
|
|
955
|
+
private readonly byName;
|
|
956
|
+
private readonly roots;
|
|
957
|
+
private readonly skipped;
|
|
958
|
+
private readonly discoverImpl;
|
|
959
|
+
private readonly onWarning;
|
|
960
|
+
readonly sessionId?: string;
|
|
961
|
+
constructor(options?: SkillRegistryOptions);
|
|
962
|
+
loadRoots(roots: readonly SkillRoot[]): Promise<void>;
|
|
963
|
+
registerBuiltinSkill(skill: SkillDefinition): void;
|
|
964
|
+
register(skill: SkillDefinition, options?: {
|
|
965
|
+
readonly replace?: boolean;
|
|
966
|
+
}): void;
|
|
967
|
+
getSkill(name: string): SkillDefinition | undefined;
|
|
968
|
+
renderSkillPrompt(skill: SkillDefinition, rawArgs: string): string;
|
|
969
|
+
listSkills(): readonly SkillDefinition[];
|
|
970
|
+
listInvocableSkills(): readonly SkillDefinition[];
|
|
971
|
+
getSkillRoots(): readonly string[];
|
|
972
|
+
getSkippedByPolicy(): readonly SkippedSkill[];
|
|
973
|
+
getByfSkillsDescription(): string;
|
|
974
|
+
getModelSkillListing(): string;
|
|
975
|
+
}
|
|
976
|
+
//#endregion
|
|
977
|
+
//#region src/utils/environment.d.ts
|
|
978
|
+
/**
|
|
979
|
+
* Environment — cross-platform probe of OS / shell.
|
|
980
|
+
*
|
|
981
|
+
* Detection is a pure function of injected probes (`platform` / `arch` /
|
|
982
|
+
* `release` / `env` / `isFile` / `findExecutable`) so the same suite runs
|
|
983
|
+
* identically on any host OS. `detectEnvironmentFromNode()` bundles the
|
|
984
|
+
* Node defaults for production callers.
|
|
985
|
+
*
|
|
986
|
+
* On Windows the probe expects Git Bash (the canonical POSIX shell that
|
|
987
|
+
* ships with Git for Windows). If it cannot be located the function
|
|
988
|
+
* throws `ByfError` with code `shell.git_bash_not_found`; the SDK layer
|
|
989
|
+
* can wrap that into a user-facing install hint. Set `BYF_SHELL_PATH`
|
|
990
|
+
* to override.
|
|
991
|
+
*/
|
|
992
|
+
type OsKind = string;
|
|
993
|
+
type ShellName = 'bash' | 'sh';
|
|
994
|
+
interface Environment {
|
|
995
|
+
readonly osKind: OsKind;
|
|
996
|
+
readonly osArch: string;
|
|
997
|
+
readonly osVersion: string;
|
|
998
|
+
readonly shellName: ShellName;
|
|
999
|
+
readonly shellPath: string;
|
|
1000
|
+
}
|
|
1001
|
+
//#endregion
|
|
1002
|
+
//#region src/profile/types.d.ts
|
|
1003
|
+
/**
|
|
1004
|
+
* Runtime context supplied to a system prompt renderer.
|
|
1005
|
+
*
|
|
1006
|
+
* Captures everything determined at render time rather than at profile-load
|
|
1007
|
+
* time: the OS/shell, working directory, AGENTS.md instructions, available
|
|
1008
|
+
* skills, and so on. Loaders return renderers; callers invoke them with
|
|
1009
|
+
* the live context whenever a concrete prompt is needed.
|
|
1010
|
+
*/
|
|
1011
|
+
interface SystemPromptContext {
|
|
1012
|
+
readonly osEnv: Environment;
|
|
1013
|
+
readonly cwd: string;
|
|
1014
|
+
readonly now?: string | Date;
|
|
1015
|
+
readonly cwdListing?: string;
|
|
1016
|
+
readonly agentsMd?: string;
|
|
1017
|
+
readonly skills?: SkillRegistry | string;
|
|
1018
|
+
readonly additionalDirsInfo?: string;
|
|
1019
|
+
readonly roleAdditional?: string;
|
|
1020
|
+
}
|
|
1021
|
+
type SystemPromptRenderer = (context: SystemPromptContext) => string;
|
|
1022
|
+
interface ResolvedAgentProfile {
|
|
1023
|
+
name: string;
|
|
1024
|
+
description?: string;
|
|
1025
|
+
systemPrompt: SystemPromptRenderer;
|
|
1026
|
+
tools: string[];
|
|
1027
|
+
whenToUse?: string;
|
|
1028
|
+
subagents?: Record<string, ResolvedAgentProfile>;
|
|
1029
|
+
}
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region src/profile/context.d.ts
|
|
1032
|
+
type PreparedSystemPromptContext = Pick<SystemPromptContext, 'cwd' | 'cwdListing' | 'agentsMd'>;
|
|
1033
|
+
//#endregion
|
|
1034
|
+
//#region src/config/merge.d.ts
|
|
1035
|
+
declare function mergeConfigPatch(config: ByfConfig$1, patch: ByfConfigPatch$1): ByfConfig$1;
|
|
1036
|
+
//#endregion
|
|
1037
|
+
//#region src/config/path.d.ts
|
|
1038
|
+
declare function resolveByfHome(homeDir?: string | undefined): string;
|
|
1039
|
+
declare function resolveConfigPath(input: {
|
|
1040
|
+
readonly homeDir?: string | undefined;
|
|
1041
|
+
readonly configPath?: string | undefined;
|
|
1042
|
+
}): string;
|
|
1043
|
+
declare function ensureByfHome(homeDir: string): void;
|
|
1044
|
+
//#endregion
|
|
1045
|
+
//#region src/config/resolve.d.ts
|
|
1046
|
+
interface ResolveConfigValueInput<T> {
|
|
1047
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
1048
|
+
readonly envKey: string;
|
|
1049
|
+
readonly configValue?: T;
|
|
1050
|
+
readonly defaultValue: T;
|
|
1051
|
+
readonly parseEnv: (value: string | undefined) => T | undefined;
|
|
1052
|
+
}
|
|
1053
|
+
declare function resolveConfigValue<T>(input: ResolveConfigValueInput<T>): T;
|
|
1054
|
+
declare function parseBooleanEnv(value: string | undefined): boolean | undefined;
|
|
1055
|
+
//#endregion
|
|
1056
|
+
//#region src/config/toml.d.ts
|
|
1057
|
+
declare function ensureConfigFile(filePath: string): Promise<void>;
|
|
1058
|
+
declare function readConfigFile(filePath: string): ByfConfig$1;
|
|
1059
|
+
declare function parseConfigString(tomlText: string, filePath?: string): ByfConfig$1;
|
|
1060
|
+
declare function transformTomlData(data: Record<string, unknown>): Record<string, unknown>;
|
|
1061
|
+
declare function writeConfigFile(filePath: string, config: ByfConfig$1): Promise<void>;
|
|
1062
|
+
declare function configToTomlData(config: ByfConfig$1): Record<string, unknown>;
|
|
1063
|
+
//#endregion
|
|
1064
|
+
//#region src/providers/request-auth.d.ts
|
|
1065
|
+
interface ProviderRequestAuthOptions {
|
|
1066
|
+
readonly forceRefresh?: boolean;
|
|
1067
|
+
}
|
|
1068
|
+
type ProviderRequestAuthResolver = (options?: ProviderRequestAuthOptions) => Promise<ProviderRequestAuth>;
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/providers/runtime-provider.d.ts
|
|
1071
|
+
interface BearerTokenProvider {
|
|
1072
|
+
getAccessToken(options?: {
|
|
1073
|
+
readonly force?: boolean | undefined;
|
|
1074
|
+
}): Promise<string>;
|
|
1075
|
+
}
|
|
1076
|
+
type OAuthTokenProviderResolver = (providerName: string, oauthRef?: OAuthRef | undefined) => BearerTokenProvider | undefined;
|
|
1077
|
+
interface ResolvedRuntimeProvider {
|
|
1078
|
+
readonly modelName: string;
|
|
1079
|
+
readonly providerName?: string | undefined;
|
|
1080
|
+
readonly provider: ProviderConfig;
|
|
1081
|
+
readonly modelCapabilities: ModelCapability;
|
|
1082
|
+
readonly resolveAuth?: ProviderRequestAuthResolver;
|
|
1083
|
+
}
|
|
1084
|
+
//#endregion
|
|
1085
|
+
//#region src/providers/provider-manager.d.ts
|
|
1086
|
+
interface ProviderManagerOptions {
|
|
1087
|
+
readonly config: ByfConfig$1;
|
|
1088
|
+
readonly byfRequestHeaders?: Record<string, string> | undefined;
|
|
1089
|
+
readonly resolveOAuthTokenProvider?: OAuthTokenProviderResolver | undefined;
|
|
1090
|
+
readonly promptCacheKey?: string;
|
|
1091
|
+
}
|
|
1092
|
+
declare class ProviderManager {
|
|
1093
|
+
private readonly options;
|
|
1094
|
+
private readonly state;
|
|
1095
|
+
constructor(options: ProviderManagerOptions, state?: ProviderManagerState);
|
|
1096
|
+
get config(): ByfConfig$1;
|
|
1097
|
+
get providers(): ByfConfig$1['providers'];
|
|
1098
|
+
get models(): NonNullable<ByfConfig$1['models']>;
|
|
1099
|
+
updateConfig(config: ByfConfig$1): void;
|
|
1100
|
+
withPromptCacheKey(promptCacheKey?: string): ProviderManager;
|
|
1101
|
+
resolveProviderConfigForModel(model: string | undefined, options?: {
|
|
1102
|
+
readonly promptCacheKey?: string;
|
|
1103
|
+
}): ResolvedRuntimeProvider | undefined;
|
|
1104
|
+
resolveProviderForModel(model: string | undefined): Promise<ResolvedRuntimeProvider | undefined>;
|
|
1105
|
+
createAuthResolverForModel(model: string | undefined, options?: {
|
|
1106
|
+
readonly log?: Logger;
|
|
1107
|
+
}): ProviderRequestAuthResolver | undefined;
|
|
1108
|
+
resolveThinkingLevel(requestedThinking?: string): ThinkingEffort;
|
|
1109
|
+
resolveSelectedModel(requestedModel: string | undefined): string | undefined;
|
|
1110
|
+
}
|
|
1111
|
+
interface ProviderManagerState {
|
|
1112
|
+
config: ByfConfig$1;
|
|
1113
|
+
}
|
|
1114
|
+
//#endregion
|
|
1115
|
+
//#region src/tools/background/manager.d.ts
|
|
1116
|
+
/**
|
|
1117
|
+
* `'lost'` is a reconcile-only terminal state. Tasks loaded from disk
|
|
1118
|
+
* that were marked `running` at startup but have no live KaosProcess
|
|
1119
|
+
* (the previous CLI process died) are reclassified as lost.
|
|
1120
|
+
*
|
|
1121
|
+
* `'awaiting_approval'` is a non-terminal state entered when a background
|
|
1122
|
+
* agent task is paused waiting for tool-call approval from the root
|
|
1123
|
+
* agent. The BPM state machine is the single source of truth for "is
|
|
1124
|
+
* this task actively running vs. gated on approval" — UI reads from BPM
|
|
1125
|
+
* instead of reverse-querying the ApprovalRuntime. The loop boundary is
|
|
1126
|
+
* preserved because `awaiting_approval` in BPM does not leak permission
|
|
1127
|
+
* vocabulary into the loop.
|
|
1128
|
+
*/
|
|
1129
|
+
type BackgroundTaskStatus = 'running' | 'awaiting_approval' | 'completed' | 'failed' | 'killed' | 'lost';
|
|
1130
|
+
/** Task kinds with distinct id prefixes. */
|
|
1131
|
+
type BackgroundTaskKind = 'bash' | 'agent';
|
|
1132
|
+
/** Lifecycle phases observed by `onLifecycle` subscribers. */
|
|
1133
|
+
type BackgroundLifecycleEvent = 'started' | 'updated' | 'terminated';
|
|
1134
|
+
interface BackgroundTaskInfo$1 {
|
|
1135
|
+
readonly taskId: string;
|
|
1136
|
+
readonly command: string;
|
|
1137
|
+
readonly description: string;
|
|
1138
|
+
readonly status: BackgroundTaskStatus;
|
|
1139
|
+
readonly pid: number;
|
|
1140
|
+
readonly exitCode: number | null;
|
|
1141
|
+
readonly startedAt: number;
|
|
1142
|
+
readonly endedAt: number | null;
|
|
1143
|
+
/** Populated only while `status === 'awaiting_approval'`. */
|
|
1144
|
+
readonly approvalReason?: string | undefined;
|
|
1145
|
+
/** True when an agent task was aborted by its deadline. */
|
|
1146
|
+
readonly timedOut?: boolean | undefined;
|
|
1147
|
+
/** Reason recorded when a task is explicitly stopped. */
|
|
1148
|
+
readonly stopReason?: string | undefined;
|
|
1149
|
+
/**
|
|
1150
|
+
* Deadline (ms) supplied to `registerAgentTask`. Surfaced so shutdown
|
|
1151
|
+
* wait-caps and UI can read the originally-requested timeout without
|
|
1152
|
+
* round-tripping the call site. `undefined` means no deadline.
|
|
1153
|
+
*/
|
|
1154
|
+
readonly timeoutMs?: number | undefined;
|
|
1155
|
+
/** Identifier of the spawned subagent (agent tasks only). */
|
|
1156
|
+
readonly agentId?: string | undefined;
|
|
1157
|
+
/** Profile name of the spawned subagent (agent tasks only). */
|
|
1158
|
+
readonly subagentType?: string | undefined;
|
|
1159
|
+
/**
|
|
1160
|
+
* Human-readable reason recorded when a non-terminal task is reclassified
|
|
1161
|
+
* via reconcile (e.g. a stale heartbeat → lost).
|
|
1162
|
+
*/
|
|
1163
|
+
readonly failureReason?: string | undefined;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Terminal-state info for tasks reconciled as lost on resume. They
|
|
1167
|
+
* have no live KaosProcess and no captured output (the buffer died
|
|
1168
|
+
* with the previous process), so list/get returns this minimal record.
|
|
1169
|
+
*/
|
|
1170
|
+
interface ReconcileResult {
|
|
1171
|
+
/** Task IDs that were marked `lost` because their process is gone. */
|
|
1172
|
+
readonly lost: readonly string[];
|
|
1173
|
+
/** Snapshot of each lost task's persisted info for terminal notifications. */
|
|
1174
|
+
readonly lostInfo: readonly BackgroundTaskInfo$1[];
|
|
1175
|
+
}
|
|
1176
|
+
interface BackgroundProcessManagerOptions {
|
|
1177
|
+
readonly maxRunningTasks?: number;
|
|
1178
|
+
readonly sessionDir?: string;
|
|
1179
|
+
}
|
|
1180
|
+
interface BackgroundTaskReservation {
|
|
1181
|
+
release(): void;
|
|
1182
|
+
}
|
|
1183
|
+
interface BackgroundTaskOutputSnapshot {
|
|
1184
|
+
readonly outputPath?: string;
|
|
1185
|
+
readonly outputSizeBytes: number;
|
|
1186
|
+
readonly previewBytes: number;
|
|
1187
|
+
readonly truncated: boolean;
|
|
1188
|
+
readonly fullOutputAvailable: boolean;
|
|
1189
|
+
readonly preview: string;
|
|
1190
|
+
}
|
|
1191
|
+
declare class BackgroundProcessManager {
|
|
1192
|
+
private readonly options;
|
|
1193
|
+
private readonly processes;
|
|
1194
|
+
private reservedTaskSlots;
|
|
1195
|
+
/**
|
|
1196
|
+
* Ghosts: tasks loaded from disk during reconcile that have no live
|
|
1197
|
+
* KaosProcess. They appear in `list()` / `getTask()` with status
|
|
1198
|
+
* `lost` so users see what was running before the crash/restart.
|
|
1199
|
+
*/
|
|
1200
|
+
private readonly ghosts;
|
|
1201
|
+
/** When set, register/lifecycle changes persist to disk. */
|
|
1202
|
+
private sessionDir;
|
|
1203
|
+
/**
|
|
1204
|
+
* Registered terminal-state callbacks. Fired once per task when the
|
|
1205
|
+
* task reaches a terminal state (completed / failed / killed).
|
|
1206
|
+
*/
|
|
1207
|
+
private readonly terminalCallbacks;
|
|
1208
|
+
/**
|
|
1209
|
+
* Registered lifecycle callbacks. Fired for every observable
|
|
1210
|
+
* transition (started / updated / terminated). Errors thrown by
|
|
1211
|
+
* callbacks are silently swallowed so the BPM main flow never breaks
|
|
1212
|
+
* because of a buggy subscriber.
|
|
1213
|
+
*/
|
|
1214
|
+
private readonly lifecycleCallbacks;
|
|
1215
|
+
constructor(options?: BackgroundProcessManagerOptions);
|
|
1216
|
+
/**
|
|
1217
|
+
* Register a callback that fires when any task reaches a terminal
|
|
1218
|
+
* state. The callback receives the task's `BackgroundTaskInfo`
|
|
1219
|
+
* snapshot. Multiple callbacks may be registered; they are invoked in
|
|
1220
|
+
* registration order. Errors thrown by callbacks are silently swallowed.
|
|
1221
|
+
*/
|
|
1222
|
+
onTerminal(callback: (info: BackgroundTaskInfo$1) => void | Promise<void>): void;
|
|
1223
|
+
/**
|
|
1224
|
+
* Register a callback that fires on every lifecycle transition:
|
|
1225
|
+
* - 'started': task just registered (either bash or agent)
|
|
1226
|
+
* - 'updated': awaiting_approval entered / cleared
|
|
1227
|
+
* - 'terminated': task reached a terminal state (also triggers
|
|
1228
|
+
* onTerminal); fires exactly once per task.
|
|
1229
|
+
*
|
|
1230
|
+
* Synchronous callback. Errors are swallowed so the BPM lifecycle
|
|
1231
|
+
* machinery (status updates, persistence, waiters) cannot be blocked
|
|
1232
|
+
* by a buggy subscriber. Use it for fan-out to RPC events; do not put
|
|
1233
|
+
* heavy work in it (defer to microtask if needed).
|
|
1234
|
+
*/
|
|
1235
|
+
onLifecycle(callback: (event: BackgroundLifecycleEvent, info: BackgroundTaskInfo$1) => void): void;
|
|
1236
|
+
/** Fan out a lifecycle event to subscribers. */
|
|
1237
|
+
private fireLifecycle;
|
|
1238
|
+
/**
|
|
1239
|
+
* Subclasses can react to live task completion here. Restored disk
|
|
1240
|
+
* tasks reconciled as lost do not call this hook.
|
|
1241
|
+
*/
|
|
1242
|
+
protected onLiveTaskTerminal(_info: BackgroundTaskInfo$1): void | Promise<void>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Fire all registered terminal callbacks for a task. Idempotent: the
|
|
1245
|
+
* second invocation for the same task is a no-op so `reconcile()` /
|
|
1246
|
+
* a lagging `wait()` resolver / a race between `stop()` and natural
|
|
1247
|
+
* exit cannot yield duplicate notifications. This is the manager-side
|
|
1248
|
+
* half of the dedupe pact with `NotificationManager.dedupe_key`.
|
|
1249
|
+
*/
|
|
1250
|
+
private fireTerminalCallbacks;
|
|
1251
|
+
private fireTerminalSubscribers;
|
|
1252
|
+
private resolveWaiters;
|
|
1253
|
+
assertCanRegister(): void;
|
|
1254
|
+
reserveSlot(): BackgroundTaskReservation;
|
|
1255
|
+
private activeTaskCount;
|
|
1256
|
+
/**
|
|
1257
|
+
* Register a KaosProcess as a background task.
|
|
1258
|
+
* Starts capturing stdout/stderr and monitors lifecycle via `wait()`.
|
|
1259
|
+
* Returns the assigned task ID.
|
|
1260
|
+
*
|
|
1261
|
+
* `opts.kind` picks the id prefix. Defaults to `'bash'` because bash
|
|
1262
|
+
* subprocess registration is the only caller on the process path
|
|
1263
|
+
* today; agent tasks go through `registerAgentTask` which forces
|
|
1264
|
+
* `'agent'`.
|
|
1265
|
+
*/
|
|
1266
|
+
register(proc: KaosProcess, command: string, description: string, opts?: {
|
|
1267
|
+
kind?: BackgroundTaskKind;
|
|
1268
|
+
/**
|
|
1269
|
+
* Optional shell metadata. Carried so the `/task` UI and the
|
|
1270
|
+
* background persist snapshot can surface which dialect a
|
|
1271
|
+
* task was launched under. Legacy callers omitting this
|
|
1272
|
+
* field keep the implicit 'bash' default.
|
|
1273
|
+
*/
|
|
1274
|
+
shellInfo?: {
|
|
1275
|
+
shellName: string;
|
|
1276
|
+
shellPath: string;
|
|
1277
|
+
cwd: string;
|
|
1278
|
+
};
|
|
1279
|
+
reservation?: BackgroundTaskReservation;
|
|
1280
|
+
} | undefined): string;
|
|
1281
|
+
/** Get info about a specific task. Falls back to reconcile ghosts. */
|
|
1282
|
+
getTask(taskId: string): BackgroundTaskInfo$1 | undefined;
|
|
1283
|
+
/**
|
|
1284
|
+
* Give just-ended processes a short grace period to settle their `wait()`
|
|
1285
|
+
* promise, then return with whatever lifecycle state has been finalized.
|
|
1286
|
+
*/
|
|
1287
|
+
settlePendingExits(): Promise<void>;
|
|
1288
|
+
/**
|
|
1289
|
+
* List tasks, optionally filtering to active-only.
|
|
1290
|
+
*
|
|
1291
|
+
* When `activeOnly=false`, includes reconcile ghosts (lost tasks
|
|
1292
|
+
* from a prior CLI process) so the user sees what survived the
|
|
1293
|
+
* restart. Active-only mode never shows ghosts (they're terminal).
|
|
1294
|
+
*/
|
|
1295
|
+
list(activeOnly?: boolean, limit?: number): BackgroundTaskInfo$1[];
|
|
1296
|
+
/**
|
|
1297
|
+
* Await all pending `output.log` appends for a task to settle.
|
|
1298
|
+
*
|
|
1299
|
+
* Output chunks are persisted to disk on an async queue, so a task can
|
|
1300
|
+
* reach a terminal state before its final chunks have landed on disk.
|
|
1301
|
+
* Callers that read the on-disk log (`getOutputSizeBytes` /
|
|
1302
|
+
* `readOutputBytesFromDisk`) should `await flushOutput()` first so they
|
|
1303
|
+
* observe the complete log. No-op for unknown/ghost tasks.
|
|
1304
|
+
*/
|
|
1305
|
+
flushOutput(taskId: string): Promise<void>;
|
|
1306
|
+
/**
|
|
1307
|
+
* Total byte size of a task's full output as stored on disk.
|
|
1308
|
+
*
|
|
1309
|
+
* Reads `<sessionDir>/tasks/<id>/output.log`, which is the complete,
|
|
1310
|
+
* never-truncated log — unlike the in-memory ring buffer it never drops
|
|
1311
|
+
* old chunks. Returns 0 when the manager is detached, the task is
|
|
1312
|
+
* unknown, or the task has produced no output yet.
|
|
1313
|
+
*/
|
|
1314
|
+
getOutputSizeBytes(taskId: string): Promise<number>;
|
|
1315
|
+
/**
|
|
1316
|
+
* Read a byte range of a task's full output from the on-disk log.
|
|
1317
|
+
*
|
|
1318
|
+
* Reads up to `maxBytes` bytes starting at `offset` of `output.log`,
|
|
1319
|
+
* straight from disk so it never loses the head of a large task the way
|
|
1320
|
+
* the in-memory ring buffer would. Callers derive `offset` and `maxBytes`
|
|
1321
|
+
* from a single `getOutputSizeBytes` snapshot, so the bytes returned stay
|
|
1322
|
+
* consistent with the size used for metadata even when a still-running
|
|
1323
|
+
* task keeps growing its log. Returns an empty string when the manager
|
|
1324
|
+
* is detached, the task is unknown, or the log is absent.
|
|
1325
|
+
*/
|
|
1326
|
+
readOutputBytesFromDisk(taskId: string, offset: number, maxBytes: number): Promise<string>;
|
|
1327
|
+
/**
|
|
1328
|
+
* Return the output snapshot used by TaskOutput.
|
|
1329
|
+
*
|
|
1330
|
+
* Persisted logs are preferred when the task was registered with an
|
|
1331
|
+
* output session directory and `output.log` has actually been created,
|
|
1332
|
+
* because they are the complete, never-truncated source. Detached managers,
|
|
1333
|
+
* tasks registered before a session dir was attached, and silent tasks with
|
|
1334
|
+
* no persisted log fall back to the live ring buffer.
|
|
1335
|
+
*/
|
|
1336
|
+
getOutputSnapshot(taskId: string, maxPreviewBytes: number): Promise<BackgroundTaskOutputSnapshot>;
|
|
1337
|
+
/** Get the combined output of a task (tail of the ring buffer). */
|
|
1338
|
+
getOutput(taskId: string, tail?: number): string;
|
|
1339
|
+
readOutput(taskId: string, tail?: number): Promise<string>;
|
|
1340
|
+
getOutputPath(taskId: string): string | undefined;
|
|
1341
|
+
/** Stop a running task. SIGTERM → 5s grace → SIGKILL. */
|
|
1342
|
+
stop(taskId: string, reason?: string): Promise<BackgroundTaskInfo$1 | undefined>;
|
|
1343
|
+
stopAll(reason?: string): Promise<readonly BackgroundTaskInfo$1[]>;
|
|
1344
|
+
/**
|
|
1345
|
+
* Wait for a task to reach a terminal state.
|
|
1346
|
+
* Returns immediately if already terminal. Times out after `timeoutMs`.
|
|
1347
|
+
*/
|
|
1348
|
+
wait(taskId: string, timeoutMs?: number): Promise<BackgroundTaskInfo$1 | undefined>;
|
|
1349
|
+
/**
|
|
1350
|
+
* Register a Promise-based agent task (no KaosProcess). Used by
|
|
1351
|
+
* AgentTool for background subagent dispatch. Agent tasks appear in
|
|
1352
|
+
* `list()` / `getTask()` but have pid=0 and empty output.
|
|
1353
|
+
*
|
|
1354
|
+
* `opts.timeoutMs` wraps the completion in an external deadline. On
|
|
1355
|
+
* deadline fire, the task is marked `failed` with `timedOut=true`
|
|
1356
|
+
* (distinct from a caller-driven `stop()` which uses `killed`, and
|
|
1357
|
+
* distinct from an internal `TimeoutError` rejection which is a
|
|
1358
|
+
* generic `failed` with `timedOut` left unset).
|
|
1359
|
+
*/
|
|
1360
|
+
registerAgentTask(completion: Promise<{
|
|
1361
|
+
result: string;
|
|
1362
|
+
}>, description: string, opts?: {
|
|
1363
|
+
timeoutMs?: number;
|
|
1364
|
+
abort?: () => void;
|
|
1365
|
+
reservation?: BackgroundTaskReservation; /** Subagent identifier; surfaced on task info. */
|
|
1366
|
+
agentId?: string; /** Subagent profile name; surfaced on task info. */
|
|
1367
|
+
subagentType?: string;
|
|
1368
|
+
}): string;
|
|
1369
|
+
/**
|
|
1370
|
+
* Mark a running task as paused pending approval. The approval reason
|
|
1371
|
+
* (tool call description) is retained until the task either returns
|
|
1372
|
+
* to `'running'` via `clearAwaitingApproval()` or reaches a terminal
|
|
1373
|
+
* state. Calls on terminal or unknown tasks are silently ignored so
|
|
1374
|
+
* the ApprovalRuntime callback path is race-safe.
|
|
1375
|
+
*/
|
|
1376
|
+
markAwaitingApproval(taskId: string, reason: string): void;
|
|
1377
|
+
/**
|
|
1378
|
+
* Drop the approval gate and return to `'running'`. Clears the stored
|
|
1379
|
+
* reason so stale text cannot leak into a future `awaiting_approval`
|
|
1380
|
+
* cycle. No-op unless the task is currently in the awaiting_approval
|
|
1381
|
+
* state.
|
|
1382
|
+
*/
|
|
1383
|
+
clearAwaitingApproval(taskId: string): void;
|
|
1384
|
+
/**
|
|
1385
|
+
* Resolve when the task reaches a terminal state. If the task is
|
|
1386
|
+
* already terminal, resolves synchronously on the next microtask.
|
|
1387
|
+
* Intended for integration code that wants to `await` a specific
|
|
1388
|
+
* task's exit without installing a full `onTerminal` subscriber.
|
|
1389
|
+
* Returns `undefined` for unknown ids (matching `getTask`). Ghost
|
|
1390
|
+
* (reconciled-lost) entries are considered terminal from the
|
|
1391
|
+
* manager's perspective.
|
|
1392
|
+
*/
|
|
1393
|
+
waitForTerminal(taskId: string): Promise<BackgroundTaskInfo$1 | undefined>;
|
|
1394
|
+
/** Reset internal state (for testing). */
|
|
1395
|
+
_reset(): void;
|
|
1396
|
+
/**
|
|
1397
|
+
* Attach the manager to a session directory for persistence. Tasks
|
|
1398
|
+
* created via `register()` after this call are written to
|
|
1399
|
+
* `<sessionDir>/tasks/<task_id>.json` and updated on lifecycle change.
|
|
1400
|
+
* Tasks created before attach are NOT retroactively persisted.
|
|
1401
|
+
*/
|
|
1402
|
+
attachSessionDir(sessionDir: string): void;
|
|
1403
|
+
/**
|
|
1404
|
+
* Load persisted task records into the ghost map. Does NOT reconcile
|
|
1405
|
+
* (call `reconcile()` after `loadFromDisk()`). Idempotent; subsequent
|
|
1406
|
+
* calls overwrite the ghost map.
|
|
1407
|
+
*
|
|
1408
|
+
* Requires `attachSessionDir()` first; no-op otherwise.
|
|
1409
|
+
*/
|
|
1410
|
+
loadFromDisk(): Promise<void>;
|
|
1411
|
+
/**
|
|
1412
|
+
* Reconcile loaded ghost tasks. Any ghost with status `running` is
|
|
1413
|
+
* reclassified as `lost` (its previous CLI process died without
|
|
1414
|
+
* writing a terminal state). Updates the on-disk record and returns
|
|
1415
|
+
* the lost task ids so the caller can emit user-facing notifications.
|
|
1416
|
+
*/
|
|
1417
|
+
protected markLoadedTasksLost(): Promise<ReconcileResult>;
|
|
1418
|
+
reconcile(): Promise<ReconcileResult>;
|
|
1419
|
+
/** Drop a persisted task from disk and ghost map. */
|
|
1420
|
+
forgetTask(taskId: string): Promise<void>;
|
|
1421
|
+
/**
|
|
1422
|
+
* Persist the current state of a live ManagedProcess. Called from
|
|
1423
|
+
* `register()` and the lifecycle finally block. No-op unless attached.
|
|
1424
|
+
*/
|
|
1425
|
+
private persistLive;
|
|
1426
|
+
private appendOutput;
|
|
1427
|
+
private outputSessionDirFor;
|
|
1428
|
+
private settleProcessExit;
|
|
1429
|
+
private observedExitCompletions;
|
|
1430
|
+
private toInfo;
|
|
1431
|
+
private finalizeTerminal;
|
|
1432
|
+
}
|
|
1433
|
+
//#endregion
|
|
1434
|
+
//#region src/tools/display/schemas.d.ts
|
|
1435
|
+
declare const ToolInputDisplaySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1436
|
+
kind: z.ZodLiteral<"command">;
|
|
1437
|
+
command: z.ZodString;
|
|
1438
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
1439
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1440
|
+
language: z.ZodOptional<z.ZodLiteral<"bash">>;
|
|
1441
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1442
|
+
kind: z.ZodLiteral<"file_io">;
|
|
1443
|
+
operation: z.ZodEnum<{
|
|
1444
|
+
read: "read";
|
|
1445
|
+
write: "write";
|
|
1446
|
+
edit: "edit";
|
|
1447
|
+
glob: "glob";
|
|
1448
|
+
grep: "grep";
|
|
1449
|
+
}>;
|
|
1450
|
+
path: z.ZodString;
|
|
1451
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
1452
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1453
|
+
kind: z.ZodLiteral<"diff">;
|
|
1454
|
+
path: z.ZodString;
|
|
1455
|
+
before: z.ZodString;
|
|
1456
|
+
after: z.ZodString;
|
|
1457
|
+
hunks: z.ZodOptional<z.ZodNumber>;
|
|
1458
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1459
|
+
kind: z.ZodLiteral<"search">;
|
|
1460
|
+
query: z.ZodString;
|
|
1461
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
1462
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1463
|
+
kind: z.ZodLiteral<"url_fetch">;
|
|
1464
|
+
url: z.ZodString;
|
|
1465
|
+
method: z.ZodOptional<z.ZodString>;
|
|
1466
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1467
|
+
kind: z.ZodLiteral<"agent_call">;
|
|
1468
|
+
agent_name: z.ZodString;
|
|
1469
|
+
prompt: z.ZodString;
|
|
1470
|
+
background: z.ZodOptional<z.ZodBoolean>;
|
|
1471
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1472
|
+
kind: z.ZodLiteral<"skill_call">;
|
|
1473
|
+
skill_name: z.ZodString;
|
|
1474
|
+
args: z.ZodOptional<z.ZodString>;
|
|
1475
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1476
|
+
kind: z.ZodLiteral<"todo_list">;
|
|
1477
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1478
|
+
title: z.ZodString;
|
|
1479
|
+
status: z.ZodString;
|
|
1480
|
+
}, z.core.$strip>>;
|
|
1481
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1482
|
+
kind: z.ZodLiteral<"background_task">;
|
|
1483
|
+
task_id: z.ZodString;
|
|
1484
|
+
status: z.ZodString;
|
|
1485
|
+
description: z.ZodString;
|
|
1486
|
+
task_kind: z.ZodOptional<z.ZodString>;
|
|
1487
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1488
|
+
kind: z.ZodLiteral<"task_stop">;
|
|
1489
|
+
task_id: z.ZodString;
|
|
1490
|
+
task_description: z.ZodString;
|
|
1491
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1492
|
+
kind: z.ZodLiteral<"plan_review">;
|
|
1493
|
+
plan: z.ZodString;
|
|
1494
|
+
path: z.ZodOptional<z.ZodString>;
|
|
1495
|
+
options: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
1496
|
+
label: z.ZodString;
|
|
1497
|
+
description: z.ZodString;
|
|
1498
|
+
}, z.core.$strip>>>>;
|
|
1499
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1500
|
+
kind: z.ZodLiteral<"generic">;
|
|
1501
|
+
summary: z.ZodString;
|
|
1502
|
+
detail: z.ZodOptional<z.ZodUnknown>;
|
|
1503
|
+
}, z.core.$strip>], "kind">;
|
|
1504
|
+
type ToolInputDisplay = z.infer<typeof ToolInputDisplaySchema>;
|
|
1505
|
+
//#endregion
|
|
1506
|
+
//#region src/loop/tool-access.d.ts
|
|
1507
|
+
type ToolFileAccessOperation = 'read' | 'write' | 'readwrite' | 'search';
|
|
1508
|
+
type ToolResourceAccess = {
|
|
1509
|
+
readonly kind: 'file';
|
|
1510
|
+
readonly operation: ToolFileAccessOperation;
|
|
1511
|
+
/**
|
|
1512
|
+
* Canonical file path when the access can be narrowed. Omitted means the
|
|
1513
|
+
* operation may touch any file in the backend file namespace.
|
|
1514
|
+
*/
|
|
1515
|
+
readonly path?: string;
|
|
1516
|
+
readonly recursive?: boolean;
|
|
1517
|
+
} | {
|
|
1518
|
+
/**
|
|
1519
|
+
* Arbitrary side effects or resources that cannot be represented as a
|
|
1520
|
+
* file access. This is intentionally operation-less and globally
|
|
1521
|
+
* exclusive for concurrency.
|
|
1522
|
+
*/
|
|
1523
|
+
readonly kind: 'all';
|
|
1524
|
+
};
|
|
1525
|
+
type ToolAccesses = readonly ToolResourceAccess[];
|
|
1526
|
+
declare const ToolAccesses: {
|
|
1527
|
+
none(): ToolAccesses;
|
|
1528
|
+
all(): ToolAccesses;
|
|
1529
|
+
file(operation: ToolFileAccessOperation, path?: string, options?: {
|
|
1530
|
+
readonly recursive?: boolean;
|
|
1531
|
+
}): ToolAccesses;
|
|
1532
|
+
readFile(path: string): ToolAccesses;
|
|
1533
|
+
readTree(path: string): ToolAccesses;
|
|
1534
|
+
readAnyFile(): ToolAccesses;
|
|
1535
|
+
writeFile(path: string): ToolAccesses;
|
|
1536
|
+
writeTree(path: string): ToolAccesses;
|
|
1537
|
+
writeAnyFile(): ToolAccesses;
|
|
1538
|
+
readWriteFile(path: string): ToolAccesses;
|
|
1539
|
+
readWriteTree(path: string): ToolAccesses;
|
|
1540
|
+
readWriteAnyFile(): ToolAccesses;
|
|
1541
|
+
searchTree(path: string): ToolAccesses;
|
|
1542
|
+
searchAnyFile(): ToolAccesses;
|
|
1543
|
+
conflict(left: ToolAccesses, right: ToolAccesses): boolean;
|
|
1544
|
+
};
|
|
1545
|
+
//#endregion
|
|
1546
|
+
//#region src/loop/llm.d.ts
|
|
1547
|
+
interface ToolCallDelta {
|
|
1548
|
+
readonly toolCallId: string;
|
|
1549
|
+
readonly name?: string | undefined;
|
|
1550
|
+
readonly argumentsPart?: string | undefined;
|
|
1551
|
+
}
|
|
1552
|
+
interface LLMRequestLogContext {
|
|
1553
|
+
readonly turnId?: string;
|
|
1554
|
+
readonly step?: number;
|
|
1555
|
+
readonly stepUuid?: string;
|
|
1556
|
+
readonly attempt?: number;
|
|
1557
|
+
readonly maxAttempts?: number;
|
|
1558
|
+
}
|
|
1559
|
+
interface LLMChatParams {
|
|
1560
|
+
messages: Message[];
|
|
1561
|
+
tools: readonly Tool[];
|
|
1562
|
+
signal: AbortSignal;
|
|
1563
|
+
requestLogContext?: LLMRequestLogContext;
|
|
1564
|
+
onTextDelta?: ((delta: string) => void) | undefined;
|
|
1565
|
+
onThinkDelta?: ((delta: string) => void) | undefined;
|
|
1566
|
+
onToolCallDelta?: ((delta: ToolCallDelta) => void) | undefined;
|
|
1567
|
+
/**
|
|
1568
|
+
* Fires once per completed text block. Additive relative to
|
|
1569
|
+
* `onTextDelta` — deltas still fire chunk-by-chunk for UI streaming.
|
|
1570
|
+
* Returned promises are awaited by the adapter to preserve transcript append
|
|
1571
|
+
* order. Durable transcript writes receive completed blocks only.
|
|
1572
|
+
*/
|
|
1573
|
+
onTextPart?: ((part: TextPart) => Promise<void> | void) | undefined;
|
|
1574
|
+
/**
|
|
1575
|
+
* Fires once per completed thinking block. Additive relative to
|
|
1576
|
+
* `onThinkDelta` — deltas still fire chunk-by-chunk for UI streaming.
|
|
1577
|
+
* Returned promises are awaited by the adapter to preserve transcript append
|
|
1578
|
+
* order. Durable transcript writes receive completed blocks only.
|
|
1579
|
+
*/
|
|
1580
|
+
onThinkPart?: ((part: ThinkPart) => Promise<void> | void) | undefined;
|
|
1581
|
+
}
|
|
1582
|
+
interface LLMChatResponse {
|
|
1583
|
+
toolCalls: ToolCall[];
|
|
1584
|
+
providerFinishReason?: FinishReason | undefined;
|
|
1585
|
+
rawFinishReason?: string | undefined;
|
|
1586
|
+
usage: TokenUsage;
|
|
1587
|
+
}
|
|
1588
|
+
interface LLM {
|
|
1589
|
+
readonly systemPrompt: string;
|
|
1590
|
+
readonly modelName: string;
|
|
1591
|
+
readonly capability?: ModelCapability | undefined;
|
|
1592
|
+
isRetryableError?(error: unknown): boolean;
|
|
1593
|
+
chat(params: LLMChatParams): Promise<LLMChatResponse>;
|
|
1594
|
+
}
|
|
1595
|
+
//#endregion
|
|
1596
|
+
//#region src/loop/types.d.ts
|
|
1597
|
+
/**
|
|
1598
|
+
* Stop reason for one completed model step.
|
|
1599
|
+
*
|
|
1600
|
+
* `tool_use` is a loop-control signal: the loop executes the requested tools and
|
|
1601
|
+
* continues with another step. The other values are terminal for the current
|
|
1602
|
+
* turn unless a host hook explicitly asks the loop to continue.
|
|
1603
|
+
*/
|
|
1604
|
+
type LoopStepStopReason = 'end_turn' | 'max_tokens' | 'tool_use' | 'filtered' | 'paused' | 'unknown';
|
|
1605
|
+
type LoopTerminalStepStopReason = Exclude<LoopStepStopReason, 'tool_use'>;
|
|
1606
|
+
/**
|
|
1607
|
+
* Stop reasons that can be returned in a normal `TurnResult`.
|
|
1608
|
+
*
|
|
1609
|
+
* `tool_use` is intentionally absent because it cannot be the final result of a
|
|
1610
|
+
* completed turn. Errors and max-step exhaustion are represented by thrown
|
|
1611
|
+
* errors, not by this union. Compaction is a host-level retry concern rather
|
|
1612
|
+
* than a stop reason.
|
|
1613
|
+
*/
|
|
1614
|
+
type LoopTurnStopReason = LoopTerminalStepStopReason | 'aborted';
|
|
1615
|
+
type ExecutableToolOutput = string | ContentPart[];
|
|
1616
|
+
interface ExecutableToolSuccessResult {
|
|
1617
|
+
readonly output: ExecutableToolOutput;
|
|
1618
|
+
readonly isError?: false | undefined;
|
|
1619
|
+
/**
|
|
1620
|
+
* Optional human-readable side channel for tool-result metadata that
|
|
1621
|
+
* should not contaminate the data stream the model sees (e.g. a
|
|
1622
|
+
* "Task snapshot retrieved." brief for TaskOutput). Distinct from
|
|
1623
|
+
* `output`: callers rendering tool results decide whether to surface
|
|
1624
|
+
* this to the user.
|
|
1625
|
+
*/
|
|
1626
|
+
readonly message?: string | undefined;
|
|
1627
|
+
}
|
|
1628
|
+
interface ExecutableToolErrorResult {
|
|
1629
|
+
readonly output: ExecutableToolOutput;
|
|
1630
|
+
readonly isError: true;
|
|
1631
|
+
/** See {@link ExecutableToolSuccessResult.message}. */
|
|
1632
|
+
readonly message?: string | undefined;
|
|
1633
|
+
/**
|
|
1634
|
+
* Internal loop-control hint. Tool result events strip this field before
|
|
1635
|
+
* persistence; it only tells the current turn whether another model step is
|
|
1636
|
+
* allowed after this tool batch.
|
|
1637
|
+
*/
|
|
1638
|
+
readonly stopTurn?: boolean | undefined;
|
|
1639
|
+
}
|
|
1640
|
+
type ExecutableToolResult = ExecutableToolSuccessResult | ExecutableToolErrorResult;
|
|
1641
|
+
interface ToolUpdate$1 {
|
|
1642
|
+
kind: 'stdout' | 'stderr' | 'progress' | 'status' | 'custom';
|
|
1643
|
+
text?: string | undefined;
|
|
1644
|
+
percent?: number | undefined;
|
|
1645
|
+
/** Vendor-defined event identifier when `kind === 'custom'`. */
|
|
1646
|
+
customKind?: string | undefined;
|
|
1647
|
+
/** Opaque payload paired with `customKind`. */
|
|
1648
|
+
customData?: unknown;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Per-call context passed to tool implementations.
|
|
1652
|
+
*/
|
|
1653
|
+
interface ExecutableToolContext {
|
|
1654
|
+
readonly turnId: string;
|
|
1655
|
+
readonly toolCallId: string;
|
|
1656
|
+
readonly metadata?: unknown;
|
|
1657
|
+
readonly signal: AbortSignal;
|
|
1658
|
+
readonly onUpdate?: ((update: ToolUpdate$1) => void) | undefined;
|
|
1659
|
+
}
|
|
1660
|
+
interface RunnableToolExecution {
|
|
1661
|
+
readonly isError?: false | undefined;
|
|
1662
|
+
readonly accesses?: ToolAccesses | undefined;
|
|
1663
|
+
readonly display?: ToolInputDisplay | undefined;
|
|
1664
|
+
readonly description?: string;
|
|
1665
|
+
readonly execute: (ctx: ExecutableToolContext) => Promise<ExecutableToolResult>;
|
|
1666
|
+
}
|
|
1667
|
+
type ToolExecution = RunnableToolExecution | ExecutableToolErrorResult;
|
|
1668
|
+
interface ExecutableTool<Input = unknown> extends Tool {
|
|
1669
|
+
resolveExecution(input: Input): ToolExecution;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Step hooks are aligned to recorded phase boundaries: `beforeStep` runs before
|
|
1673
|
+
* `step.begin`, while `afterStep` runs after `step.end`.
|
|
1674
|
+
*/
|
|
1675
|
+
interface LoopStepHookContext {
|
|
1676
|
+
readonly turnId: string;
|
|
1677
|
+
readonly stepNumber: number;
|
|
1678
|
+
readonly signal: AbortSignal;
|
|
1679
|
+
readonly llm: LLM;
|
|
1680
|
+
}
|
|
1681
|
+
interface ToolExecutionHookContext extends LoopStepHookContext {
|
|
1682
|
+
readonly toolCall: ToolCall$1;
|
|
1683
|
+
readonly tool?: ExecutableTool | undefined;
|
|
1684
|
+
readonly args: unknown;
|
|
1685
|
+
}
|
|
1686
|
+
interface PrepareToolExecutionResult {
|
|
1687
|
+
readonly block?: boolean | undefined;
|
|
1688
|
+
readonly reason?: string | undefined;
|
|
1689
|
+
readonly updatedArgs?: unknown;
|
|
1690
|
+
readonly syntheticResult?: ExecutableToolResult | undefined;
|
|
1691
|
+
readonly executionMetadata?: unknown;
|
|
1692
|
+
}
|
|
1693
|
+
//#endregion
|
|
1694
|
+
//#region src/loop/events.d.ts
|
|
1695
|
+
interface LoopStepBeginEvent {
|
|
1696
|
+
readonly type: 'step.begin';
|
|
1697
|
+
readonly uuid: string;
|
|
1698
|
+
readonly turnId: string;
|
|
1699
|
+
readonly step: number;
|
|
1700
|
+
}
|
|
1701
|
+
interface LoopStepEndEvent {
|
|
1702
|
+
readonly type: 'step.end';
|
|
1703
|
+
readonly uuid: string;
|
|
1704
|
+
readonly turnId: string;
|
|
1705
|
+
readonly step: number;
|
|
1706
|
+
readonly usage?: TokenUsage | undefined;
|
|
1707
|
+
readonly finishReason?: LoopStepStopReason | undefined;
|
|
1708
|
+
/**
|
|
1709
|
+
* Provider diagnostics are optional and must not drive loop control.
|
|
1710
|
+
* Use `finishReason` for normalized behavior.
|
|
1711
|
+
*/
|
|
1712
|
+
readonly providerFinishReason?: FinishReason | undefined;
|
|
1713
|
+
readonly rawFinishReason?: string | undefined;
|
|
1714
|
+
}
|
|
1715
|
+
interface LoopContentPartEvent {
|
|
1716
|
+
readonly type: 'content.part';
|
|
1717
|
+
readonly uuid: string;
|
|
1718
|
+
readonly turnId: string;
|
|
1719
|
+
readonly step: number;
|
|
1720
|
+
readonly stepUuid: string;
|
|
1721
|
+
readonly part: TextPart | ThinkPart;
|
|
1722
|
+
}
|
|
1723
|
+
interface LoopToolCallEvent {
|
|
1724
|
+
readonly type: 'tool.call';
|
|
1725
|
+
readonly uuid: string;
|
|
1726
|
+
readonly turnId: string;
|
|
1727
|
+
readonly step: number;
|
|
1728
|
+
readonly stepUuid: string;
|
|
1729
|
+
readonly toolCallId: string;
|
|
1730
|
+
readonly name: string;
|
|
1731
|
+
readonly args: unknown;
|
|
1732
|
+
readonly description?: string | undefined;
|
|
1733
|
+
readonly display?: ToolInputDisplay | undefined;
|
|
1734
|
+
}
|
|
1735
|
+
interface LoopToolResultEvent {
|
|
1736
|
+
readonly type: 'tool.result';
|
|
1737
|
+
readonly parentUuid: string;
|
|
1738
|
+
readonly toolCallId: string;
|
|
1739
|
+
readonly result: ExecutableToolResult;
|
|
1740
|
+
}
|
|
1741
|
+
type LoopRecordedEvent = LoopStepBeginEvent | LoopStepEndEvent | LoopContentPartEvent | LoopToolCallEvent | LoopToolResultEvent;
|
|
1742
|
+
//#endregion
|
|
1743
|
+
//#region src/tools/store.d.ts
|
|
1744
|
+
interface ToolStoreData {}
|
|
1745
|
+
type ToolStoreKey = Extract<keyof ToolStoreData, string>;
|
|
1746
|
+
interface ToolStore {
|
|
1747
|
+
get<K extends ToolStoreKey>(key: K): ToolStoreData[K] | undefined;
|
|
1748
|
+
set<K extends ToolStoreKey>(key: K, value: ToolStoreData[K]): void;
|
|
1749
|
+
}
|
|
1750
|
+
interface ToolStoreUpdate<K extends ToolStoreKey = ToolStoreKey> {
|
|
1751
|
+
readonly key: K;
|
|
1752
|
+
readonly value: ToolStoreData[K];
|
|
1753
|
+
}
|
|
1754
|
+
//#endregion
|
|
1755
|
+
//#region src/agent/tool/types.d.ts
|
|
1756
|
+
type ToolSource = 'builtin' | 'user' | 'mcp';
|
|
1757
|
+
type BuiltinTool<Input = unknown> = ExecutableTool<Input>;
|
|
1758
|
+
interface UserToolRegistration {
|
|
1759
|
+
readonly name: string;
|
|
1760
|
+
readonly description: string;
|
|
1761
|
+
readonly parameters: Record<string, unknown>;
|
|
1762
|
+
}
|
|
1763
|
+
interface ToolInfo$1 {
|
|
1764
|
+
readonly name: string;
|
|
1765
|
+
readonly description: string;
|
|
1766
|
+
readonly active: boolean;
|
|
1767
|
+
readonly source: ToolSource;
|
|
1768
|
+
}
|
|
1769
|
+
interface McpToolCollision {
|
|
1770
|
+
readonly qualified: string;
|
|
1771
|
+
readonly toolName: string;
|
|
1772
|
+
readonly collidesWith: {
|
|
1773
|
+
readonly kind: 'same_server';
|
|
1774
|
+
readonly toolName: string;
|
|
1775
|
+
} | {
|
|
1776
|
+
readonly kind: 'other_server';
|
|
1777
|
+
readonly serverName: string;
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
interface McpServerRegistrationResult {
|
|
1781
|
+
readonly registered: readonly string[];
|
|
1782
|
+
readonly collisions: readonly McpToolCollision[];
|
|
1783
|
+
}
|
|
1784
|
+
//#endregion
|
|
1785
|
+
//#region src/agent/tool/index.d.ts
|
|
1786
|
+
interface McpToolEntry {
|
|
1787
|
+
readonly tool: ExecutableTool;
|
|
1788
|
+
readonly serverName: string;
|
|
1789
|
+
}
|
|
1790
|
+
declare class ToolManager {
|
|
1791
|
+
protected readonly agent: Agent;
|
|
1792
|
+
protected builtinTools: Map<string, BuiltinTool>;
|
|
1793
|
+
protected readonly userTools: Map<string, ExecutableTool>;
|
|
1794
|
+
protected readonly mcpTools: Map<string, McpToolEntry>;
|
|
1795
|
+
/** server name → list of qualified tool names registered for that server. */
|
|
1796
|
+
protected readonly mcpToolsByServer: Map<string, string[]>;
|
|
1797
|
+
protected enabledTools: Set<string>;
|
|
1798
|
+
/** Glob patterns (e.g. `mcp__*`, `mcp__github__*`) gating which MCP tools the profile exposes. */
|
|
1799
|
+
private mcpAccessPatterns;
|
|
1800
|
+
protected readonly store: Partial<ToolStoreData>;
|
|
1801
|
+
private mcpToolStatusUnsubscribe;
|
|
1802
|
+
constructor(agent: Agent);
|
|
1803
|
+
protected get toolStore(): ToolStore;
|
|
1804
|
+
attachMcpTools(): void;
|
|
1805
|
+
updateStore<K extends ToolStoreKey>(key: K, value: ToolStoreData[K]): void;
|
|
1806
|
+
registerUserTool(input: UserToolRegistration): void;
|
|
1807
|
+
unregisterUserTool(name: string): void;
|
|
1808
|
+
registerMcpServer(serverName: string, client: MCPClient, tools: readonly Tool[], enabledTools?: ReadonlySet<string>): McpServerRegistrationResult;
|
|
1809
|
+
unregisterMcpServer(serverName: string): boolean;
|
|
1810
|
+
private handleMcpServerStatusChange;
|
|
1811
|
+
private registerNeedsAuthMcpServer;
|
|
1812
|
+
private registerConnectedMcpServer;
|
|
1813
|
+
private emitMcpToolCollisions;
|
|
1814
|
+
setActiveTools(names: readonly string[]): void;
|
|
1815
|
+
private isMcpToolEnabled;
|
|
1816
|
+
toolInfos(): Iterable<ToolInfo$1>;
|
|
1817
|
+
data(): readonly ToolInfo$1[];
|
|
1818
|
+
storeData(): Readonly<Record<string, unknown>>;
|
|
1819
|
+
initializeBuiltinTools(): void;
|
|
1820
|
+
private createVideoUploader;
|
|
1821
|
+
get loopTools(): readonly ExecutableTool[];
|
|
1822
|
+
}
|
|
1823
|
+
//#endregion
|
|
1824
|
+
//#region src/logging/logger.d.ts
|
|
1825
|
+
declare function getRootLogger(): RootLogger;
|
|
1826
|
+
declare function flushDiagnosticLogs(): Promise<boolean>;
|
|
1827
|
+
/**
|
|
1828
|
+
* Root logger. Import and use directly for events that don't belong to any
|
|
1829
|
+
* session (CLI startup, harness construction, etc.):
|
|
1830
|
+
*
|
|
1831
|
+
* import { log } from 'byf-sdk';
|
|
1832
|
+
* log.info('byf starting', { version });
|
|
1833
|
+
*
|
|
1834
|
+
* For events scoped to a session or agent, use the parent's `log` field:
|
|
1835
|
+
*
|
|
1836
|
+
* session.log.error('mcp initial load failed', error);
|
|
1837
|
+
* agent.log.error('turn failed', { turnId, error });
|
|
1838
|
+
*
|
|
1839
|
+
* Late-binding: methods look up the current `RootLogger` on every call, so
|
|
1840
|
+
* importing `log` at module load (before `ByfHarness` configures the root)
|
|
1841
|
+
* is safe — calls during the pre-configure window are silent noops.
|
|
1842
|
+
*/
|
|
1843
|
+
declare const log: Logger;
|
|
1844
|
+
declare function redact<T>(value: T): T;
|
|
1845
|
+
declare function resolveGlobalLogPath(homeDir: string): string;
|
|
1846
|
+
//#endregion
|
|
1847
|
+
//#region src/agent/compaction/types.d.ts
|
|
1848
|
+
interface CompactionResult$1 {
|
|
1849
|
+
summary: string;
|
|
1850
|
+
compactedCount: number;
|
|
1851
|
+
tokensBefore: number;
|
|
1852
|
+
tokensAfter: number;
|
|
1853
|
+
}
|
|
1854
|
+
interface CompactionBeginData {
|
|
1855
|
+
instruction?: string;
|
|
1856
|
+
source: 'manual' | 'auto';
|
|
1857
|
+
}
|
|
1858
|
+
//#endregion
|
|
1859
|
+
//#region src/agent/compaction/full.d.ts
|
|
1860
|
+
interface CompactionStrategy {
|
|
1861
|
+
shouldCompact(usedSize: number, maxSize: number): boolean;
|
|
1862
|
+
shouldBlock(usedSize: number, maxSize: number): boolean;
|
|
1863
|
+
computeCompactCount(messages: readonly Message[], maxSize: number): number;
|
|
1864
|
+
readonly checkAfterStep: boolean;
|
|
1865
|
+
readonly maxCompactionPerTurn: number;
|
|
1866
|
+
}
|
|
1867
|
+
interface CompactedHistory {
|
|
1868
|
+
text: string;
|
|
1869
|
+
}
|
|
1870
|
+
type CompactionTelemetryTrigger = CompactionBeginData['source'] | 'manual-with-prompt' | 'unknown';
|
|
1871
|
+
declare class FullCompaction {
|
|
1872
|
+
protected readonly agent: Agent;
|
|
1873
|
+
protected compactionCountInTurn: number;
|
|
1874
|
+
protected compacting: {
|
|
1875
|
+
abortController: AbortController;
|
|
1876
|
+
startedAt: number;
|
|
1877
|
+
telemetryTrigger: CompactionTelemetryTrigger;
|
|
1878
|
+
promise: Promise<void>;
|
|
1879
|
+
} | null;
|
|
1880
|
+
protected _compactedHistory: CompactedHistory[];
|
|
1881
|
+
protected readonly strategy: CompactionStrategy;
|
|
1882
|
+
constructor(agent: Agent, strategy?: CompactionStrategy);
|
|
1883
|
+
get isCompacting(): boolean;
|
|
1884
|
+
begin(data: Readonly<CompactionBeginData>): void;
|
|
1885
|
+
private startCompactionWorker;
|
|
1886
|
+
cancel(): void;
|
|
1887
|
+
private markCanceled;
|
|
1888
|
+
complete(result: CompactionResult$1, llmUsage?: TokenUsage | undefined, retryCount?: number): void;
|
|
1889
|
+
private get tokenCountWithPending();
|
|
1890
|
+
private get maxContextSize();
|
|
1891
|
+
private get shouldCompact();
|
|
1892
|
+
private get shouldBlock();
|
|
1893
|
+
resetForTurn(): void;
|
|
1894
|
+
handleOverflowError(signal: AbortSignal, error: unknown): Promise<void>;
|
|
1895
|
+
beforeStep(signal: AbortSignal): Promise<void>;
|
|
1896
|
+
afterStep(): Promise<void>;
|
|
1897
|
+
private checkAutoCompaction;
|
|
1898
|
+
private beginAutoCompaction;
|
|
1899
|
+
private block;
|
|
1900
|
+
private compactionWorker;
|
|
1901
|
+
private generateCompactionResponse;
|
|
1902
|
+
get compactedHistory(): readonly CompactedHistory[];
|
|
1903
|
+
private triggerPreCompactHook;
|
|
1904
|
+
private triggerPostCompactHook;
|
|
1905
|
+
private computeCompactableCount;
|
|
1906
|
+
}
|
|
1907
|
+
//#endregion
|
|
1908
|
+
//#region src/agent/context/types.d.ts
|
|
1909
|
+
interface UserPromptOrigin {
|
|
1910
|
+
readonly kind: 'user';
|
|
1911
|
+
readonly blockedByHook?: string | undefined;
|
|
1912
|
+
}
|
|
1913
|
+
declare const USER_PROMPT_ORIGIN: UserPromptOrigin;
|
|
1914
|
+
interface SkillActivationOrigin {
|
|
1915
|
+
readonly kind: 'skill_activation';
|
|
1916
|
+
readonly activationId: string;
|
|
1917
|
+
readonly skillName: string;
|
|
1918
|
+
readonly skillArgs?: string | undefined;
|
|
1919
|
+
readonly trigger: 'user-slash' | 'model-tool' | 'nested-skill';
|
|
1920
|
+
readonly skillType?: string | undefined;
|
|
1921
|
+
readonly skillPath?: string | undefined;
|
|
1922
|
+
readonly skillSource?: SkillSource | undefined;
|
|
1923
|
+
}
|
|
1924
|
+
interface InjectionOrigin {
|
|
1925
|
+
readonly kind: 'injection';
|
|
1926
|
+
readonly variant: string;
|
|
1927
|
+
}
|
|
1928
|
+
interface CompactionSummaryOrigin {
|
|
1929
|
+
readonly kind: 'compaction_summary';
|
|
1930
|
+
}
|
|
1931
|
+
interface SystemTriggerOrigin {
|
|
1932
|
+
readonly kind: 'system_trigger';
|
|
1933
|
+
readonly name: string;
|
|
1934
|
+
}
|
|
1935
|
+
interface BackgroundTaskOrigin {
|
|
1936
|
+
readonly kind: 'background_task';
|
|
1937
|
+
readonly taskId: string;
|
|
1938
|
+
readonly status: BackgroundTaskStatus;
|
|
1939
|
+
readonly notificationId: string;
|
|
1940
|
+
}
|
|
1941
|
+
interface HookResultOrigin {
|
|
1942
|
+
readonly kind: 'hook_result';
|
|
1943
|
+
readonly event: string;
|
|
1944
|
+
readonly blocked?: boolean;
|
|
1945
|
+
}
|
|
1946
|
+
type PromptOrigin = UserPromptOrigin | SkillActivationOrigin | InjectionOrigin | CompactionSummaryOrigin | SystemTriggerOrigin | BackgroundTaskOrigin | HookResultOrigin;
|
|
1947
|
+
type ContextMessage$1 = Message & {
|
|
1948
|
+
readonly origin?: PromptOrigin | undefined;
|
|
1949
|
+
readonly isError?: boolean;
|
|
1950
|
+
};
|
|
1951
|
+
interface AgentContextData$1 {
|
|
1952
|
+
history: readonly ContextMessage$1[];
|
|
1953
|
+
tokenCount: number;
|
|
1954
|
+
}
|
|
1955
|
+
//#endregion
|
|
1956
|
+
//#region src/agent/context/index.d.ts
|
|
1957
|
+
declare class ContextMemory {
|
|
1958
|
+
protected readonly agent: Agent;
|
|
1959
|
+
private _history;
|
|
1960
|
+
private _tokenCount;
|
|
1961
|
+
private tokenCountCoveredMessageCount;
|
|
1962
|
+
private openSteps;
|
|
1963
|
+
private pendingToolResultIds;
|
|
1964
|
+
private deferredMessages;
|
|
1965
|
+
constructor(agent: Agent);
|
|
1966
|
+
appendUserMessage(content: readonly ContentPart[], origin?: PromptOrigin): void;
|
|
1967
|
+
appendSystemReminder(content: string, origin: PromptOrigin): void;
|
|
1968
|
+
markLastUserPromptBlocked(hookEvent: string): void;
|
|
1969
|
+
clear(): void;
|
|
1970
|
+
applyCompaction(summary: CompactionResult$1): void;
|
|
1971
|
+
data(): AgentContextData$1;
|
|
1972
|
+
get tokenCount(): number;
|
|
1973
|
+
get tokenCountWithPending(): number;
|
|
1974
|
+
get history(): readonly ContextMessage$1[];
|
|
1975
|
+
get messages(): Message[];
|
|
1976
|
+
appendLoopEvent(event: LoopRecordedEvent): void;
|
|
1977
|
+
appendMessage(message: ContextMessage$1): void;
|
|
1978
|
+
private flushDeferredMessagesIfToolExchangeClosed;
|
|
1979
|
+
private hasOpenToolExchange;
|
|
1980
|
+
private pushHistory;
|
|
1981
|
+
}
|
|
1982
|
+
//#endregion
|
|
1983
|
+
//#region src/agent/hooks/types.d.ts
|
|
1984
|
+
declare const HOOK_EVENT_TYPES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "UserPromptSubmit", "Stop", "StopFailure", "SessionStart", "SessionEnd", "SubagentStart", "SubagentStop", "PreCompact", "PostCompact", "Notification"];
|
|
1985
|
+
type HookEventType = (typeof HOOK_EVENT_TYPES)[number];
|
|
1986
|
+
interface HookDef {
|
|
1987
|
+
readonly event: HookEventType;
|
|
1988
|
+
readonly matcher?: string;
|
|
1989
|
+
readonly command: string;
|
|
1990
|
+
readonly timeout?: number;
|
|
1991
|
+
}
|
|
1992
|
+
interface HookResult {
|
|
1993
|
+
readonly action: 'allow' | 'block';
|
|
1994
|
+
readonly message?: string;
|
|
1995
|
+
readonly reason?: string;
|
|
1996
|
+
readonly stdout?: string;
|
|
1997
|
+
readonly stderr?: string;
|
|
1998
|
+
readonly exitCode?: number;
|
|
1999
|
+
readonly timedOut?: boolean;
|
|
2000
|
+
readonly structuredOutput?: boolean;
|
|
2001
|
+
}
|
|
2002
|
+
interface HookBlockDecision {
|
|
2003
|
+
readonly block: true;
|
|
2004
|
+
readonly reason: string;
|
|
2005
|
+
}
|
|
2006
|
+
type HookMatcherValue = string | readonly ContentPart[];
|
|
2007
|
+
interface HookEngineTriggerArgs {
|
|
2008
|
+
readonly matcherValue?: HookMatcherValue;
|
|
2009
|
+
readonly inputData?: Record<string, unknown>;
|
|
2010
|
+
readonly signal?: AbortSignal;
|
|
2011
|
+
}
|
|
2012
|
+
type HookTriggeredCallback = (event: string, target: string, count: number) => void;
|
|
2013
|
+
type HookResolvedCallback = (event: string, target: string, action: string, reason: string | undefined, durationMs: number) => void;
|
|
2014
|
+
interface HookEngineOptions {
|
|
2015
|
+
readonly cwd?: string;
|
|
2016
|
+
readonly sessionId?: string;
|
|
2017
|
+
readonly onTriggered?: HookTriggeredCallback;
|
|
2018
|
+
readonly onResolved?: HookResolvedCallback;
|
|
2019
|
+
}
|
|
2020
|
+
//#endregion
|
|
2021
|
+
//#region src/agent/hooks/engine.d.ts
|
|
2022
|
+
declare class HookEngine {
|
|
2023
|
+
private readonly options;
|
|
2024
|
+
private readonly byEvent;
|
|
2025
|
+
private readonly pendingTriggers;
|
|
2026
|
+
constructor(hooks?: readonly HookDef[], options?: HookEngineOptions);
|
|
2027
|
+
get summary(): Record<string, number>;
|
|
2028
|
+
trigger(event: string, args?: HookEngineTriggerArgs): Promise<HookResult[]>;
|
|
2029
|
+
triggerBlock(event: string, args?: HookEngineTriggerArgs): Promise<HookBlockDecision | undefined>;
|
|
2030
|
+
fireAndForgetTrigger(event: string, args?: HookEngineTriggerArgs): Promise<HookResult[]>;
|
|
2031
|
+
private triggerInner;
|
|
2032
|
+
private matchingHooks;
|
|
2033
|
+
private emitTriggered;
|
|
2034
|
+
private emitResolved;
|
|
2035
|
+
}
|
|
2036
|
+
//#endregion
|
|
2037
|
+
//#region src/agent/permission/types.d.ts
|
|
2038
|
+
type PermissionRuleDecision = 'allow' | 'deny' | 'ask';
|
|
2039
|
+
/**
|
|
2040
|
+
* Rule provenance. `session-runtime` is the value used by the runtime
|
|
2041
|
+
* "approve for session" path; `turn-override`, `project`, and `user`
|
|
2042
|
+
* are reserved for static-loaded rules surfaced by external callers.
|
|
2043
|
+
*/
|
|
2044
|
+
type PermissionRuleScope = 'turn-override' | 'session-runtime' | 'project' | 'user';
|
|
2045
|
+
/**
|
|
2046
|
+
* Top-level user-facing permission posture. Controls how non-deny rules
|
|
2047
|
+
* are treated when the closure is constructed. Independent of rule
|
|
2048
|
+
* merging: deny rules always fire regardless of mode.
|
|
2049
|
+
*
|
|
2050
|
+
* - `manual` — rule set drives decision; unmatched tool calls ask
|
|
2051
|
+
* - `yolo` — only deny rules can block; everything else allows
|
|
2052
|
+
* - `auto` — caller may bypass rule checks entirely
|
|
2053
|
+
*/
|
|
2054
|
+
type PermissionMode$1 = 'manual' | 'yolo' | 'auto';
|
|
2055
|
+
/**
|
|
2056
|
+
* A single permission rule. `pattern` is the DSL form (`Read(/etc/**)`,
|
|
2057
|
+
* `Bash(rm *)`, or bare `Write`). See `parse-pattern.ts` for the parser
|
|
2058
|
+
* and `matches-rule.ts` for the matcher.
|
|
2059
|
+
*/
|
|
2060
|
+
interface PermissionRule {
|
|
2061
|
+
readonly decision: PermissionRuleDecision;
|
|
2062
|
+
readonly scope: PermissionRuleScope;
|
|
2063
|
+
readonly pattern: string;
|
|
2064
|
+
readonly reason?: string | undefined;
|
|
2065
|
+
}
|
|
2066
|
+
interface ApprovalResponse$1 {
|
|
2067
|
+
decision: 'approved' | 'rejected' | 'cancelled';
|
|
2068
|
+
scope?: 'session';
|
|
2069
|
+
feedback?: string;
|
|
2070
|
+
selectedLabel?: string;
|
|
2071
|
+
}
|
|
2072
|
+
interface PermissionApprovalResultRecord$1 {
|
|
2073
|
+
readonly turnId: number;
|
|
2074
|
+
readonly toolCallId: string;
|
|
2075
|
+
readonly toolName: string;
|
|
2076
|
+
readonly action: string;
|
|
2077
|
+
readonly result: ApprovalResponse$1;
|
|
2078
|
+
}
|
|
2079
|
+
interface PermissionData$1 {
|
|
2080
|
+
mode: PermissionMode$1;
|
|
2081
|
+
rules: PermissionRule[];
|
|
2082
|
+
}
|
|
2083
|
+
//#endregion
|
|
2084
|
+
//#region src/agent/permission/policy.d.ts
|
|
2085
|
+
interface PermissionPolicyContext {
|
|
2086
|
+
readonly agent: Agent;
|
|
2087
|
+
readonly mode: PermissionMode$1;
|
|
2088
|
+
readonly toolCallContext: ToolExecutionHookContext;
|
|
2089
|
+
/**
|
|
2090
|
+
* The rule matched by `checkPermission()`, if any.
|
|
2091
|
+
*
|
|
2092
|
+
* Policies that want to defer to user-defined rules (e.g. a default-allow
|
|
2093
|
+
* policy that should not override an explicit `ask`/`deny` rule) inspect
|
|
2094
|
+
* this to decide whether to fire. `undefined` means the decision came
|
|
2095
|
+
* from the built-in default permission table rather than a user rule.
|
|
2096
|
+
*/
|
|
2097
|
+
readonly matchedRule: PermissionRule | undefined;
|
|
2098
|
+
readonly recordApprovalResult: (record: PermissionApprovalResultRecord$1) => void;
|
|
2099
|
+
}
|
|
2100
|
+
type PermissionPolicyResult = {
|
|
2101
|
+
readonly kind: 'allow';
|
|
2102
|
+
readonly executionMetadata?: unknown;
|
|
2103
|
+
} | {
|
|
2104
|
+
readonly kind: 'result';
|
|
2105
|
+
readonly result: PrepareToolExecutionResult;
|
|
2106
|
+
} | {
|
|
2107
|
+
readonly kind: 'ask';
|
|
2108
|
+
readonly action?: string | undefined;
|
|
2109
|
+
readonly display?: ToolInputDisplay | undefined;
|
|
2110
|
+
};
|
|
2111
|
+
interface PermissionPolicy {
|
|
2112
|
+
readonly name: string;
|
|
2113
|
+
evaluate(context: PermissionPolicyContext): PermissionPolicyResult | undefined | Promise<PermissionPolicyResult | undefined>;
|
|
2114
|
+
}
|
|
2115
|
+
//#endregion
|
|
2116
|
+
//#region src/agent/permission/index.d.ts
|
|
2117
|
+
interface PermissionManagerOptions {
|
|
2118
|
+
readonly initialRules?: readonly PermissionRule[] | undefined;
|
|
2119
|
+
readonly policies?: readonly PermissionPolicy[] | undefined;
|
|
2120
|
+
readonly parent?: PermissionManager | undefined;
|
|
2121
|
+
}
|
|
2122
|
+
declare class PermissionManager {
|
|
2123
|
+
protected readonly agent: Agent;
|
|
2124
|
+
rules: PermissionRule[];
|
|
2125
|
+
private modeOverride;
|
|
2126
|
+
private readonly parent;
|
|
2127
|
+
private readonly sessionApprovedActions;
|
|
2128
|
+
private readonly policies;
|
|
2129
|
+
constructor(agent: Agent, options?: PermissionManagerOptions);
|
|
2130
|
+
get mode(): PermissionMode$1;
|
|
2131
|
+
set mode(mode: PermissionMode$1);
|
|
2132
|
+
data(): PermissionData$1;
|
|
2133
|
+
setMode(mode: PermissionMode$1): void;
|
|
2134
|
+
recordApprovalResult(record: PermissionApprovalResultRecord$1): void;
|
|
2135
|
+
beforeToolCall(context: ToolExecutionHookContext): Promise<PrepareToolExecutionResult | undefined>;
|
|
2136
|
+
private requestToolApproval;
|
|
2137
|
+
private evaluatePolicies;
|
|
2138
|
+
private checkPermission;
|
|
2139
|
+
private checkMatchingPermissionRules;
|
|
2140
|
+
private effectiveRules;
|
|
2141
|
+
private wouldAskInManualMode;
|
|
2142
|
+
private permissionPolicyResultToPrepare;
|
|
2143
|
+
private hasRule;
|
|
2144
|
+
protected formatMessage(toolName: string, reason?: string): string;
|
|
2145
|
+
protected formatApprovalRejectionMessage(toolName: string, result: {
|
|
2146
|
+
decision: 'approved' | 'rejected' | 'cancelled';
|
|
2147
|
+
feedback?: string;
|
|
2148
|
+
}): string;
|
|
2149
|
+
private pathMatchOptions;
|
|
2150
|
+
private trackToolApproved;
|
|
2151
|
+
}
|
|
2152
|
+
//#endregion
|
|
2153
|
+
//#region src/telemetry.d.ts
|
|
2154
|
+
type TelemetryPropertyValue = boolean | number | string | null;
|
|
2155
|
+
type TelemetryProperties = Readonly<Record<string, TelemetryPropertyValue>>;
|
|
2156
|
+
interface TelemetryContextPatch {
|
|
2157
|
+
readonly sessionId?: string | null;
|
|
2158
|
+
}
|
|
2159
|
+
interface TelemetryClient {
|
|
2160
|
+
track(event: string, properties?: TelemetryProperties): void;
|
|
2161
|
+
withContext?(patch: TelemetryContextPatch): TelemetryClient;
|
|
2162
|
+
setContext?(patch: TelemetryContextPatch): void;
|
|
2163
|
+
}
|
|
2164
|
+
declare const noopTelemetryClient: TelemetryClient;
|
|
2165
|
+
declare function withTelemetryContext(telemetry: TelemetryClient, patch: TelemetryContextPatch): TelemetryClient;
|
|
2166
|
+
//#endregion
|
|
2167
|
+
//#region src/session/index.d.ts
|
|
2168
|
+
interface SessionConfig {
|
|
2169
|
+
readonly runtime: RuntimeConfig;
|
|
2170
|
+
readonly id?: string | undefined;
|
|
2171
|
+
readonly homedir: string;
|
|
2172
|
+
readonly byfHomeDir?: string;
|
|
2173
|
+
readonly rpc: SDKSessionRPC;
|
|
2174
|
+
readonly cwd?: string;
|
|
2175
|
+
readonly initializeMainAgent?: boolean | undefined;
|
|
2176
|
+
readonly providerManager?: ProviderManager | undefined;
|
|
2177
|
+
readonly background?: BackgroundConfig | undefined;
|
|
2178
|
+
readonly hooks?: readonly HookDef[];
|
|
2179
|
+
readonly permissionRules?: readonly PermissionRule[];
|
|
2180
|
+
readonly skills?: SessionSkillConfig;
|
|
2181
|
+
readonly mcpConfig?: SessionMcpConfig;
|
|
2182
|
+
readonly telemetry?: TelemetryClient | undefined;
|
|
2183
|
+
}
|
|
2184
|
+
interface SessionSkillConfig {
|
|
2185
|
+
readonly userHomeDir?: string;
|
|
2186
|
+
readonly explicitDirs?: readonly string[];
|
|
2187
|
+
readonly extraDirs?: readonly string[];
|
|
2188
|
+
readonly mergeAllAvailableSkills?: boolean;
|
|
2189
|
+
readonly builtinDir?: string;
|
|
2190
|
+
}
|
|
2191
|
+
interface AgentMeta {
|
|
2192
|
+
readonly homedir: string;
|
|
2193
|
+
readonly type: AgentType$1;
|
|
2194
|
+
readonly parentAgentId: string | null;
|
|
2195
|
+
}
|
|
2196
|
+
interface SessionMeta$1 {
|
|
2197
|
+
createdAt: string;
|
|
2198
|
+
updatedAt: string;
|
|
2199
|
+
title: string;
|
|
2200
|
+
isCustomTitle: boolean;
|
|
2201
|
+
lastPrompt?: string;
|
|
2202
|
+
forkedFrom?: string;
|
|
2203
|
+
agents: Record<string, AgentMeta>;
|
|
2204
|
+
custom: Record<string, any>;
|
|
2205
|
+
}
|
|
2206
|
+
declare class Session {
|
|
2207
|
+
readonly config: SessionConfig;
|
|
2208
|
+
readonly rpc: SDKSessionRPC;
|
|
2209
|
+
readonly telemetry: TelemetryClient;
|
|
2210
|
+
readonly skills: SkillRegistry;
|
|
2211
|
+
readonly agents: Map<string, Agent>;
|
|
2212
|
+
readonly mcp: McpConnectionManager;
|
|
2213
|
+
readonly log: Logger;
|
|
2214
|
+
private readonly logHandle;
|
|
2215
|
+
readonly hookEngine: HookEngine;
|
|
2216
|
+
private agentIdCounter;
|
|
2217
|
+
private readonly skillsReady;
|
|
2218
|
+
metadata: SessionMeta$1;
|
|
2219
|
+
private writeMetadataPromise;
|
|
2220
|
+
constructor(config: SessionConfig);
|
|
2221
|
+
createMain(): Promise<Agent>;
|
|
2222
|
+
resume(): Promise<{
|
|
2223
|
+
warning?: string;
|
|
2224
|
+
}>;
|
|
2225
|
+
close(): Promise<void>;
|
|
2226
|
+
private stopBackgroundTasksOnExit;
|
|
2227
|
+
createAgent(config: Partial<AgentConfig>, profile?: ResolvedAgentProfile, parentAgentId?: string | undefined): Promise<{
|
|
2228
|
+
readonly id: string;
|
|
2229
|
+
readonly agent: Agent;
|
|
2230
|
+
}>;
|
|
2231
|
+
/**
|
|
2232
|
+
* Applies a profile's derived config — cwd, system prompt, active tools — to
|
|
2233
|
+
* an agent. Fresh creation and resume-of-an-incomplete-wire both route
|
|
2234
|
+
* through here so the two paths cannot drift apart.
|
|
2235
|
+
*/
|
|
2236
|
+
private bootstrapAgentProfile;
|
|
2237
|
+
generateAgentsMd(): Promise<void>;
|
|
2238
|
+
get hasActiveTurn(): boolean;
|
|
2239
|
+
protected get metadataPath(): string;
|
|
2240
|
+
writeMetadata(): Promise<void>;
|
|
2241
|
+
readMetadata(): Promise<SessionMeta$1>;
|
|
2242
|
+
flushMetadata(): Promise<void>;
|
|
2243
|
+
listSkills(): Promise<readonly SkillSummary$1[]>;
|
|
2244
|
+
private loadSkills;
|
|
2245
|
+
private loadMcpServers;
|
|
2246
|
+
private emitInitialMcpLoadError;
|
|
2247
|
+
private onMcpServerStatusChange;
|
|
2248
|
+
private backgroundTaskTimeoutMs;
|
|
2249
|
+
private refreshAgentBuiltinTools;
|
|
2250
|
+
private instantiateAgent;
|
|
2251
|
+
private permissionOptions;
|
|
2252
|
+
private ensureResumeAgentInstantiated;
|
|
2253
|
+
private nextGeneratedAgentId;
|
|
2254
|
+
private requireMainAgent;
|
|
2255
|
+
private triggerSessionStart;
|
|
2256
|
+
private triggerSessionEnd;
|
|
2257
|
+
}
|
|
2258
|
+
//#endregion
|
|
2259
|
+
//#region src/session/subagent-host.d.ts
|
|
2260
|
+
type RunSubagentOptions = {
|
|
2261
|
+
readonly parentToolCallId: string;
|
|
2262
|
+
readonly parentToolCallUuid?: string | undefined;
|
|
2263
|
+
readonly prompt: string;
|
|
2264
|
+
readonly description: string;
|
|
2265
|
+
readonly runInBackground: boolean;
|
|
2266
|
+
readonly origin?: PromptOrigin | undefined;
|
|
2267
|
+
readonly signal: AbortSignal;
|
|
2268
|
+
};
|
|
2269
|
+
type SubagentCompletion = {
|
|
2270
|
+
readonly result: string;
|
|
2271
|
+
readonly usage?: TokenUsage;
|
|
2272
|
+
};
|
|
2273
|
+
type SubagentHandle = {
|
|
2274
|
+
readonly agentId: string;
|
|
2275
|
+
readonly profileName: string;
|
|
2276
|
+
readonly resumed: boolean;
|
|
2277
|
+
readonly completion: Promise<SubagentCompletion>;
|
|
2278
|
+
};
|
|
2279
|
+
declare class SessionSubagentHost {
|
|
2280
|
+
private readonly session;
|
|
2281
|
+
private readonly ownerAgentId;
|
|
2282
|
+
readonly backgroundTaskTimeoutMs?: number | undefined;
|
|
2283
|
+
private readonly activeChildren;
|
|
2284
|
+
constructor(session: Session, ownerAgentId: string, backgroundTaskTimeoutMs?: number | undefined);
|
|
2285
|
+
spawn(profileName: string, options: RunSubagentOptions): Promise<SubagentHandle>;
|
|
2286
|
+
resume(agentId: string, options: RunSubagentOptions): Promise<SubagentHandle>;
|
|
2287
|
+
cancelAll(): void;
|
|
2288
|
+
getProfileName(agentId: string): string | undefined;
|
|
2289
|
+
private resolveProfile;
|
|
2290
|
+
private runChild;
|
|
2291
|
+
private configureChild;
|
|
2292
|
+
private triggerSubagentStart;
|
|
2293
|
+
private triggerSubagentStop;
|
|
2294
|
+
}
|
|
2295
|
+
//#endregion
|
|
2296
|
+
//#region src/tools/builtin/state/todo-list.d.ts
|
|
2297
|
+
type TodoStatus = 'pending' | 'in_progress' | 'done';
|
|
2298
|
+
interface TodoItem {
|
|
2299
|
+
readonly title: string;
|
|
2300
|
+
readonly status: TodoStatus;
|
|
2301
|
+
}
|
|
2302
|
+
declare module '../../store' {
|
|
2303
|
+
interface ToolStoreData {
|
|
2304
|
+
todo: readonly TodoItem[];
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
//#endregion
|
|
2308
|
+
//#region src/tools/builtin/web/fetch-url.d.ts
|
|
2309
|
+
/**
|
|
2310
|
+
* How the returned content relates to the original response body.
|
|
2311
|
+
*
|
|
2312
|
+
* - `passthrough` — the body was already plain text / markdown and is
|
|
2313
|
+
* returned verbatim, in full.
|
|
2314
|
+
* - `extracted` — the body was an HTML page; only the main article text
|
|
2315
|
+
* was extracted and returned.
|
|
2316
|
+
*/
|
|
2317
|
+
type UrlFetchKind = 'passthrough' | 'extracted';
|
|
2318
|
+
interface UrlFetchResult {
|
|
2319
|
+
/** The text handed to the LLM. */
|
|
2320
|
+
content: string;
|
|
2321
|
+
/** Whether `content` is a verbatim passthrough or extracted main text. */
|
|
2322
|
+
kind: UrlFetchKind;
|
|
2323
|
+
}
|
|
2324
|
+
interface UrlFetcher {
|
|
2325
|
+
fetch(url: string, options?: {
|
|
2326
|
+
toolCallId?: string;
|
|
2327
|
+
}): Promise<UrlFetchResult>;
|
|
2328
|
+
}
|
|
2329
|
+
//#endregion
|
|
2330
|
+
//#region src/tools/builtin/web/web-search.d.ts
|
|
2331
|
+
interface WebSearchResult {
|
|
2332
|
+
title: string;
|
|
2333
|
+
url: string;
|
|
2334
|
+
snippet: string;
|
|
2335
|
+
date?: string | undefined;
|
|
2336
|
+
content?: string | undefined;
|
|
2337
|
+
}
|
|
2338
|
+
interface WebSearchProvider {
|
|
2339
|
+
search(query: string, options?: {
|
|
2340
|
+
limit?: number;
|
|
2341
|
+
includeContent?: boolean;
|
|
2342
|
+
toolCallId?: string;
|
|
2343
|
+
}): Promise<WebSearchResult[]>;
|
|
2344
|
+
}
|
|
2345
|
+
//#endregion
|
|
2346
|
+
//#region src/runtime-types.d.ts
|
|
2347
|
+
interface RuntimeConfig {
|
|
2348
|
+
readonly kaos: Kaos;
|
|
2349
|
+
readonly osEnv: Environment;
|
|
2350
|
+
readonly urlFetcher?: UrlFetcher | undefined;
|
|
2351
|
+
readonly webSearcher?: WebSearchProvider | undefined;
|
|
2352
|
+
}
|
|
2353
|
+
//#endregion
|
|
2354
|
+
//#region src/utils/types.d.ts
|
|
2355
|
+
type Promisify<T> = [T] extends [Promise<any>] ? T : Promise<T>;
|
|
2356
|
+
type Promisable<T> = [T] extends [Promise<any>] ? T | Awaited<T> : T | Promise<T>;
|
|
2357
|
+
type PromisableMethods<T> = { [K in keyof T]: T[K] extends ((...args: infer Args) => infer Return) ? (...args: Args) => Promisable<Return> : never };
|
|
2358
|
+
//#endregion
|
|
2359
|
+
//#region src/agent/background/index.d.ts
|
|
2360
|
+
declare class BackgroundManager extends BackgroundProcessManager {
|
|
2361
|
+
readonly agent: Agent;
|
|
2362
|
+
private readonly scheduledNotificationKeys;
|
|
2363
|
+
private readonly deliveredNotificationKeys;
|
|
2364
|
+
constructor(agent: Agent, options?: BackgroundProcessManagerOptions);
|
|
2365
|
+
reconcile(): Promise<ReconcileResult>;
|
|
2366
|
+
protected onLiveTaskTerminal(info: BackgroundTaskInfo$1): void | Promise<void>;
|
|
2367
|
+
private restoreBackgroundTaskNotifications;
|
|
2368
|
+
private notifyBackgroundTask;
|
|
2369
|
+
private restoreBackgroundTaskNotification;
|
|
2370
|
+
private buildBackgroundTaskNotificationContext;
|
|
2371
|
+
private fireNotificationHook;
|
|
2372
|
+
markDeliveredNotification(origin: BackgroundTaskOrigin): void;
|
|
2373
|
+
private hasDeliveredNotification;
|
|
2374
|
+
stop(taskId: string, reason?: string): Promise<BackgroundTaskInfo$1 | undefined>;
|
|
2375
|
+
_reset(): void;
|
|
2376
|
+
}
|
|
2377
|
+
//#endregion
|
|
2378
|
+
//#region src/agent/config/types.d.ts
|
|
2379
|
+
interface AgentConfigData$1 {
|
|
2380
|
+
cwd: string;
|
|
2381
|
+
provider?: ProviderConfig;
|
|
2382
|
+
modelAlias?: string;
|
|
2383
|
+
modelCapabilities: ModelCapability;
|
|
2384
|
+
profileName?: string;
|
|
2385
|
+
thinkingLevel: string;
|
|
2386
|
+
systemPrompt: string;
|
|
2387
|
+
}
|
|
2388
|
+
type AgentConfigUpdateData$1 = Partial<{
|
|
2389
|
+
cwd: string;
|
|
2390
|
+
modelAlias: string;
|
|
2391
|
+
profileName: string;
|
|
2392
|
+
thinkingLevel: string;
|
|
2393
|
+
systemPrompt: string;
|
|
2394
|
+
}>;
|
|
2395
|
+
//#endregion
|
|
2396
|
+
//#region src/agent/config/index.d.ts
|
|
2397
|
+
declare class ConfigState {
|
|
2398
|
+
protected readonly agent: Agent;
|
|
2399
|
+
private _cwd;
|
|
2400
|
+
private _modelAlias;
|
|
2401
|
+
private _profileName;
|
|
2402
|
+
private _thinkingLevel;
|
|
2403
|
+
private _systemPrompt;
|
|
2404
|
+
constructor(agent: Agent);
|
|
2405
|
+
update(input: AgentConfigUpdateData$1): void;
|
|
2406
|
+
data(): AgentConfigData$1;
|
|
2407
|
+
get cwd(): string;
|
|
2408
|
+
get hasModel(): boolean;
|
|
2409
|
+
get hasProvider(): boolean;
|
|
2410
|
+
get providerConfig(): ProviderConfig;
|
|
2411
|
+
get provider(): ChatProvider;
|
|
2412
|
+
get model(): string;
|
|
2413
|
+
get modelAlias(): string | undefined;
|
|
2414
|
+
get thinkingLevel(): ThinkingEffort;
|
|
2415
|
+
get profileName(): string | undefined;
|
|
2416
|
+
get systemPrompt(): string;
|
|
2417
|
+
get modelCapabilities(): ModelCapability;
|
|
2418
|
+
private get resolvedProviderConfig();
|
|
2419
|
+
private tryResolvedProviderConfig;
|
|
2420
|
+
}
|
|
2421
|
+
//#endregion
|
|
2422
|
+
//#region src/agent/injection/manager.d.ts
|
|
2423
|
+
declare class InjectionManager {
|
|
2424
|
+
protected readonly agent: Agent;
|
|
2425
|
+
private readonly injectors;
|
|
2426
|
+
constructor(agent: Agent);
|
|
2427
|
+
inject(): Promise<void>;
|
|
2428
|
+
onContextClear(): void;
|
|
2429
|
+
onContextCompacted(compactedCount: number): void;
|
|
2430
|
+
}
|
|
2431
|
+
//#endregion
|
|
2432
|
+
//#region src/agent/plan/index.d.ts
|
|
2433
|
+
type PlanData$1 = null | {
|
|
2434
|
+
id: string;
|
|
2435
|
+
exists: boolean;
|
|
2436
|
+
content: string;
|
|
2437
|
+
path: string;
|
|
2438
|
+
};
|
|
2439
|
+
type PlanFilePath = string | null;
|
|
2440
|
+
declare class PlanMode {
|
|
2441
|
+
protected readonly agent: Agent;
|
|
2442
|
+
protected _isActive: boolean;
|
|
2443
|
+
protected _planId: null | string;
|
|
2444
|
+
protected _planFilePath: PlanFilePath;
|
|
2445
|
+
constructor(agent: Agent);
|
|
2446
|
+
createPlanId(): string;
|
|
2447
|
+
enter(id?: string, createFile?: boolean, emitStatus?: boolean): Promise<void>;
|
|
2448
|
+
restoreEnter({
|
|
2449
|
+
id
|
|
2450
|
+
}: {
|
|
2451
|
+
readonly id: string;
|
|
2452
|
+
}): void;
|
|
2453
|
+
cancel(id?: string): void;
|
|
2454
|
+
clear(): Promise<void>;
|
|
2455
|
+
exit(id?: string): void;
|
|
2456
|
+
get isActive(): boolean;
|
|
2457
|
+
get planFilePath(): PlanFilePath;
|
|
2458
|
+
data(): Promise<PlanData$1>;
|
|
2459
|
+
materializeCurrentPlanFile(): Promise<void>;
|
|
2460
|
+
private materializePlanFile;
|
|
2461
|
+
private ensurePlanDirectory;
|
|
2462
|
+
private planFilePathFor;
|
|
2463
|
+
private planFileExists;
|
|
2464
|
+
private trackPlanLifecycle;
|
|
2465
|
+
}
|
|
2466
|
+
//#endregion
|
|
2467
|
+
//#region src/agent/usage/index.d.ts
|
|
2468
|
+
type UsageRecordScope = 'session' | 'turn';
|
|
2469
|
+
declare class UsageRecorder {
|
|
2470
|
+
protected readonly agent?: Agent | undefined;
|
|
2471
|
+
private readonly byModel;
|
|
2472
|
+
private currentTurn;
|
|
2473
|
+
constructor(agent?: Agent | undefined);
|
|
2474
|
+
beginTurn(): void;
|
|
2475
|
+
endTurn(): void;
|
|
2476
|
+
record(model: string, usage: TokenUsage, scope?: UsageRecordScope): void;
|
|
2477
|
+
data(): UsageStatus;
|
|
2478
|
+
status(): UsageStatus | undefined;
|
|
2479
|
+
private byModelSnapshot;
|
|
2480
|
+
}
|
|
2481
|
+
//#endregion
|
|
2482
|
+
//#region src/agent/records/types.d.ts
|
|
2483
|
+
interface AgentRecordEvents {
|
|
2484
|
+
metadata: {
|
|
2485
|
+
protocol_version: string;
|
|
2486
|
+
created_at: number;
|
|
2487
|
+
};
|
|
2488
|
+
'turn.prompt': {
|
|
2489
|
+
input: readonly ContentPart[];
|
|
2490
|
+
origin: PromptOrigin;
|
|
2491
|
+
};
|
|
2492
|
+
'turn.steer': {
|
|
2493
|
+
input: readonly ContentPart[];
|
|
2494
|
+
origin: PromptOrigin;
|
|
2495
|
+
};
|
|
2496
|
+
'turn.cancel': {
|
|
2497
|
+
turnId?: number;
|
|
2498
|
+
};
|
|
2499
|
+
'config.update': AgentConfigUpdateData$1;
|
|
2500
|
+
'permission.set_mode': {
|
|
2501
|
+
mode: PermissionMode$1;
|
|
2502
|
+
};
|
|
2503
|
+
'permission.record_approval_result': PermissionApprovalResultRecord$1;
|
|
2504
|
+
'full_compaction.begin': CompactionBeginData;
|
|
2505
|
+
'plan_mode.enter': {
|
|
2506
|
+
id: string;
|
|
2507
|
+
};
|
|
2508
|
+
'plan_mode.cancel': {
|
|
2509
|
+
id?: string;
|
|
2510
|
+
};
|
|
2511
|
+
'plan_mode.exit': {
|
|
2512
|
+
id?: string;
|
|
2513
|
+
};
|
|
2514
|
+
'tools.register_user_tool': UserToolRegistration;
|
|
2515
|
+
'tools.unregister_user_tool': {
|
|
2516
|
+
name: string;
|
|
2517
|
+
};
|
|
2518
|
+
'tools.set_active_tools': {
|
|
2519
|
+
names: readonly string[];
|
|
2520
|
+
};
|
|
2521
|
+
'background.stop': {
|
|
2522
|
+
taskId: string;
|
|
2523
|
+
};
|
|
2524
|
+
'usage.record': {
|
|
2525
|
+
model: string;
|
|
2526
|
+
usage: TokenUsage;
|
|
2527
|
+
usageScope?: UsageRecordScope | undefined;
|
|
2528
|
+
};
|
|
2529
|
+
'full_compaction.cancel': {};
|
|
2530
|
+
'full_compaction.complete': CompactionResult$1;
|
|
2531
|
+
'context.append_message': {
|
|
2532
|
+
message: ContextMessage$1;
|
|
2533
|
+
};
|
|
2534
|
+
'context.mark_last_user_prompt_blocked': {
|
|
2535
|
+
hookEvent: string;
|
|
2536
|
+
};
|
|
2537
|
+
'context.append_loop_event': {
|
|
2538
|
+
event: LoopRecordedEvent;
|
|
2539
|
+
};
|
|
2540
|
+
'context.clear': {};
|
|
2541
|
+
'context.apply_compaction': CompactionResult$1;
|
|
2542
|
+
'tools.update_store': ToolStoreUpdate;
|
|
2543
|
+
}
|
|
2544
|
+
type AgentRecord = { [K in keyof AgentRecordEvents]: Readonly<AgentRecordEvents[K]> & {
|
|
2545
|
+
readonly type: K;
|
|
2546
|
+
readonly time?: number;
|
|
2547
|
+
} }[keyof AgentRecordEvents];
|
|
2548
|
+
type AgentRecordOf<K extends keyof AgentRecordEvents> = Extract<AgentRecord, {
|
|
2549
|
+
readonly type: K;
|
|
2550
|
+
}>;
|
|
2551
|
+
interface AgentRecordPersistence {
|
|
2552
|
+
read(): AsyncIterable<AgentRecord>;
|
|
2553
|
+
append(input: AgentRecord): void;
|
|
2554
|
+
rewrite(records: readonly AgentRecord[]): void;
|
|
2555
|
+
flush(): Promise<void>;
|
|
2556
|
+
close(): Promise<void>;
|
|
2557
|
+
}
|
|
2558
|
+
//#endregion
|
|
2559
|
+
//#region src/agent/records/index.d.ts
|
|
2560
|
+
declare class AgentRecords {
|
|
2561
|
+
private readonly agent;
|
|
2562
|
+
private readonly persistence?;
|
|
2563
|
+
private _restoring;
|
|
2564
|
+
private metadataInitialized;
|
|
2565
|
+
constructor(agent: Agent, persistence?: AgentRecordPersistence | undefined);
|
|
2566
|
+
get restoring(): boolean;
|
|
2567
|
+
logRecord(record: AgentRecord): void;
|
|
2568
|
+
restore(record: AgentRecord): void;
|
|
2569
|
+
replay(): Promise<{
|
|
2570
|
+
warning?: string;
|
|
2571
|
+
}>;
|
|
2572
|
+
flush(): Promise<void>;
|
|
2573
|
+
}
|
|
2574
|
+
//#endregion
|
|
2575
|
+
//#region src/agent/replay/index.d.ts
|
|
2576
|
+
declare class ReplayBuilder {
|
|
2577
|
+
readonly agent: Agent;
|
|
2578
|
+
protected readonly records: AgentReplayRecord[];
|
|
2579
|
+
constructor(agent: Agent);
|
|
2580
|
+
push(record: AgentReplayRecord): void;
|
|
2581
|
+
buildResult(): readonly AgentReplayRecord[];
|
|
2582
|
+
}
|
|
2583
|
+
//#endregion
|
|
2584
|
+
//#region src/agent/skill/index.d.ts
|
|
2585
|
+
declare class SkillManager {
|
|
2586
|
+
protected readonly agent: Agent;
|
|
2587
|
+
readonly registry: SkillRegistry;
|
|
2588
|
+
constructor(agent: Agent, registry: SkillRegistry);
|
|
2589
|
+
activate(input: ActivateSkillPayload): void;
|
|
2590
|
+
recordActivation(origin: SkillActivationOrigin, input?: readonly ContentPart[] | undefined): void;
|
|
2591
|
+
}
|
|
2592
|
+
//#endregion
|
|
2593
|
+
//#region src/errors/codes.d.ts
|
|
2594
|
+
/**
|
|
2595
|
+
* Error codes for Byf Core's public error protocol.
|
|
2596
|
+
*
|
|
2597
|
+
* `ErrorCodes` is the source of truth for every code Byf Core may emit.
|
|
2598
|
+
* Downstream consumers (SDK, RPC clients, telemetry, agent-facing docs)
|
|
2599
|
+
* should depend on these string values rather than on class identity.
|
|
2600
|
+
*
|
|
2601
|
+
* Codes follow `domain.reason`. Adding a code is a minor change; renaming
|
|
2602
|
+
* or removing one is a major change.
|
|
2603
|
+
*/
|
|
2604
|
+
declare const ErrorCodes: {
|
|
2605
|
+
readonly CONFIG_INVALID: "config.invalid";
|
|
2606
|
+
readonly SESSION_NOT_FOUND: "session.not_found";
|
|
2607
|
+
readonly SESSION_ALREADY_EXISTS: "session.already_exists";
|
|
2608
|
+
readonly SESSION_ID_INVALID: "session.id_invalid";
|
|
2609
|
+
readonly SESSION_ID_REQUIRED: "session.id_required";
|
|
2610
|
+
readonly SESSION_ID_EMPTY: "session.id_empty";
|
|
2611
|
+
readonly SESSION_TITLE_EMPTY: "session.title_empty";
|
|
2612
|
+
readonly SESSION_STATE_NOT_FOUND: "session.state_not_found";
|
|
2613
|
+
readonly SESSION_STATE_INVALID: "session.state_invalid";
|
|
2614
|
+
readonly SESSION_FORK_ACTIVE_TURN: "session.fork_active_turn";
|
|
2615
|
+
readonly SESSION_EXPORT_NOT_FOUND: "session.export_not_found";
|
|
2616
|
+
readonly SESSION_EXPORT_MISSING_VERSION: "session.export_missing_version";
|
|
2617
|
+
readonly SESSION_CLOSED: "session.closed";
|
|
2618
|
+
readonly SESSION_PERMISSION_MODE_INVALID: "session.permission_mode_invalid";
|
|
2619
|
+
readonly SESSION_THINKING_EMPTY: "session.thinking_empty";
|
|
2620
|
+
readonly SESSION_MODEL_EMPTY: "session.model_empty";
|
|
2621
|
+
readonly SESSION_PLAN_MODE_INVALID: "session.plan_mode_invalid";
|
|
2622
|
+
readonly SESSION_APPROVAL_HANDLER_ERROR: "session.approval_handler_error";
|
|
2623
|
+
readonly SESSION_QUESTION_HANDLER_ERROR: "session.question_handler_error";
|
|
2624
|
+
readonly SESSION_INIT_FAILED: "session.init_failed";
|
|
2625
|
+
readonly AGENT_NOT_FOUND: "agent.not_found";
|
|
2626
|
+
readonly TURN_AGENT_BUSY: "turn.agent_busy";
|
|
2627
|
+
readonly MODEL_NOT_CONFIGURED: "model.not_configured";
|
|
2628
|
+
readonly MODEL_CONFIG_INVALID: "model.config_invalid";
|
|
2629
|
+
readonly AUTH_LOGIN_REQUIRED: "auth.login_required";
|
|
2630
|
+
readonly CONTEXT_OVERFLOW: "context.overflow";
|
|
2631
|
+
readonly LOOP_MAX_STEPS_EXCEEDED: "loop.max_steps_exceeded";
|
|
2632
|
+
readonly PROVIDER_API_ERROR: "provider.api_error";
|
|
2633
|
+
readonly PROVIDER_RATE_LIMIT: "provider.rate_limit";
|
|
2634
|
+
readonly PROVIDER_AUTH_ERROR: "provider.auth_error";
|
|
2635
|
+
readonly PROVIDER_CONNECTION_ERROR: "provider.connection_error";
|
|
2636
|
+
readonly SKILL_NOT_FOUND: "skill.not_found";
|
|
2637
|
+
readonly SKILL_TYPE_UNSUPPORTED: "skill.type_unsupported";
|
|
2638
|
+
readonly SKILL_NAME_EMPTY: "skill.name_empty";
|
|
2639
|
+
readonly RECORDS_WRITE_FAILED: "records.write_failed";
|
|
2640
|
+
readonly COMPACTION_FAILED: "compaction.failed";
|
|
2641
|
+
readonly BACKGROUND_TASK_ID_EMPTY: "background.task_id_empty";
|
|
2642
|
+
readonly MCP_SERVER_NOT_FOUND: "mcp.server_not_found";
|
|
2643
|
+
readonly MCP_SERVER_DISABLED: "mcp.server_disabled";
|
|
2644
|
+
readonly MCP_STARTUP_FAILED: "mcp.startup_failed";
|
|
2645
|
+
readonly MCP_TOOL_NAME_COLLISION: "mcp.tool_name_collision";
|
|
2646
|
+
readonly REQUEST_INVALID: "request.invalid";
|
|
2647
|
+
readonly REQUEST_WORK_DIR_REQUIRED: "request.work_dir_required";
|
|
2648
|
+
readonly REQUEST_PROMPT_INPUT_EMPTY: "request.prompt_input_empty";
|
|
2649
|
+
readonly SHELL_GIT_BASH_NOT_FOUND: "shell.git_bash_not_found";
|
|
2650
|
+
readonly NOT_IMPLEMENTED: "not_implemented";
|
|
2651
|
+
readonly INTERNAL: "internal";
|
|
2652
|
+
};
|
|
2653
|
+
type ByfErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
2654
|
+
interface ByfErrorInfo {
|
|
2655
|
+
readonly title: string;
|
|
2656
|
+
readonly retryable: boolean;
|
|
2657
|
+
/**
|
|
2658
|
+
* Whether the code is a stable public contract. `false` reserves the
|
|
2659
|
+
* right to rename or remove without a major version bump.
|
|
2660
|
+
*/
|
|
2661
|
+
readonly public: boolean;
|
|
2662
|
+
readonly action?: string;
|
|
2663
|
+
}
|
|
2664
|
+
declare const BYF_ERROR_INFO: {
|
|
2665
|
+
readonly 'config.invalid': {
|
|
2666
|
+
readonly title: "Invalid configuration";
|
|
2667
|
+
readonly retryable: false;
|
|
2668
|
+
readonly public: true;
|
|
2669
|
+
readonly action: "Check config.toml and provider/model settings.";
|
|
2670
|
+
};
|
|
2671
|
+
readonly 'session.not_found': {
|
|
2672
|
+
readonly title: "Session not found";
|
|
2673
|
+
readonly retryable: false;
|
|
2674
|
+
readonly public: true;
|
|
2675
|
+
readonly action: "Check the session id or list available sessions.";
|
|
2676
|
+
};
|
|
2677
|
+
readonly 'session.already_exists': {
|
|
2678
|
+
readonly title: "Session already exists";
|
|
2679
|
+
readonly retryable: false;
|
|
2680
|
+
readonly public: true;
|
|
2681
|
+
readonly action: "Use a different session id or remove the existing session first.";
|
|
2682
|
+
};
|
|
2683
|
+
readonly 'session.id_invalid': {
|
|
2684
|
+
readonly title: "Invalid session id";
|
|
2685
|
+
readonly retryable: false;
|
|
2686
|
+
readonly public: true;
|
|
2687
|
+
readonly action: "Use a session id without path-traversal characters.";
|
|
2688
|
+
};
|
|
2689
|
+
readonly 'session.id_required': {
|
|
2690
|
+
readonly title: "Session id required";
|
|
2691
|
+
readonly retryable: false;
|
|
2692
|
+
readonly public: true;
|
|
2693
|
+
readonly action: "Provide a session id when calling this method.";
|
|
2694
|
+
};
|
|
2695
|
+
readonly 'session.id_empty': {
|
|
2696
|
+
readonly title: "Session id is empty";
|
|
2697
|
+
readonly retryable: false;
|
|
2698
|
+
readonly public: true;
|
|
2699
|
+
readonly action: "Provide a non-empty session id.";
|
|
2700
|
+
};
|
|
2701
|
+
readonly 'session.title_empty': {
|
|
2702
|
+
readonly title: "Session title is empty";
|
|
2703
|
+
readonly retryable: false;
|
|
2704
|
+
readonly public: true;
|
|
2705
|
+
readonly action: "Provide a non-empty session title.";
|
|
2706
|
+
};
|
|
2707
|
+
readonly 'session.state_not_found': {
|
|
2708
|
+
readonly title: "Session state missing";
|
|
2709
|
+
readonly retryable: false;
|
|
2710
|
+
readonly public: true;
|
|
2711
|
+
readonly action: "The session directory is corrupted or missing state.json.";
|
|
2712
|
+
};
|
|
2713
|
+
readonly 'session.state_invalid': {
|
|
2714
|
+
readonly title: "Session state invalid";
|
|
2715
|
+
readonly retryable: false;
|
|
2716
|
+
readonly public: true;
|
|
2717
|
+
readonly action: "The session state.json is corrupted; remove the session or repair the file.";
|
|
2718
|
+
};
|
|
2719
|
+
readonly 'session.fork_active_turn': {
|
|
2720
|
+
readonly title: "Cannot fork session during active turn";
|
|
2721
|
+
readonly retryable: true;
|
|
2722
|
+
readonly public: true;
|
|
2723
|
+
readonly action: "Wait for the active turn to complete before forking.";
|
|
2724
|
+
};
|
|
2725
|
+
readonly 'session.export_not_found': {
|
|
2726
|
+
readonly title: "Session export directory missing";
|
|
2727
|
+
readonly retryable: false;
|
|
2728
|
+
readonly public: true;
|
|
2729
|
+
readonly action: "The session has not been persisted to disk yet.";
|
|
2730
|
+
};
|
|
2731
|
+
readonly 'session.export_missing_version': {
|
|
2732
|
+
readonly title: "Export version is missing";
|
|
2733
|
+
readonly retryable: false;
|
|
2734
|
+
readonly public: true;
|
|
2735
|
+
readonly action: "Provide a version when exporting the session.";
|
|
2736
|
+
};
|
|
2737
|
+
readonly 'session.closed': {
|
|
2738
|
+
readonly title: "Session is closed";
|
|
2739
|
+
readonly retryable: false;
|
|
2740
|
+
readonly public: true;
|
|
2741
|
+
readonly action: "Create a new session.";
|
|
2742
|
+
};
|
|
2743
|
+
readonly 'session.permission_mode_invalid': {
|
|
2744
|
+
readonly title: "Invalid permission mode";
|
|
2745
|
+
readonly retryable: false;
|
|
2746
|
+
readonly public: true;
|
|
2747
|
+
readonly action: "Use one of: yolo / manual / auto.";
|
|
2748
|
+
};
|
|
2749
|
+
readonly 'session.thinking_empty': {
|
|
2750
|
+
readonly title: "Thinking value is empty";
|
|
2751
|
+
readonly retryable: false;
|
|
2752
|
+
readonly public: true;
|
|
2753
|
+
readonly action: "Provide a non-empty thinking option.";
|
|
2754
|
+
};
|
|
2755
|
+
readonly 'session.model_empty': {
|
|
2756
|
+
readonly title: "Model is empty";
|
|
2757
|
+
readonly retryable: false;
|
|
2758
|
+
readonly public: true;
|
|
2759
|
+
readonly action: "Provide a non-empty model identifier.";
|
|
2760
|
+
};
|
|
2761
|
+
readonly 'session.plan_mode_invalid': {
|
|
2762
|
+
readonly title: "Invalid plan mode";
|
|
2763
|
+
readonly retryable: false;
|
|
2764
|
+
readonly public: true;
|
|
2765
|
+
readonly action: "Provide a boolean plan mode.";
|
|
2766
|
+
};
|
|
2767
|
+
readonly 'session.approval_handler_error': {
|
|
2768
|
+
readonly title: "Approval handler threw";
|
|
2769
|
+
readonly retryable: false;
|
|
2770
|
+
readonly public: true;
|
|
2771
|
+
readonly action: "Inspect the SDK approval handler for an unhandled exception.";
|
|
2772
|
+
};
|
|
2773
|
+
readonly 'session.question_handler_error': {
|
|
2774
|
+
readonly title: "Question handler threw";
|
|
2775
|
+
readonly retryable: false;
|
|
2776
|
+
readonly public: true;
|
|
2777
|
+
readonly action: "Inspect the SDK question handler for an unhandled exception.";
|
|
2778
|
+
};
|
|
2779
|
+
readonly 'session.init_failed': {
|
|
2780
|
+
readonly title: "Session init failed";
|
|
2781
|
+
readonly retryable: false;
|
|
2782
|
+
readonly public: false;
|
|
2783
|
+
readonly action: "Review the init failure details and try again.";
|
|
2784
|
+
};
|
|
2785
|
+
readonly 'agent.not_found': {
|
|
2786
|
+
readonly title: "Agent not found";
|
|
2787
|
+
readonly retryable: false;
|
|
2788
|
+
readonly public: true;
|
|
2789
|
+
readonly action: "Check the agent id or list available agents.";
|
|
2790
|
+
};
|
|
2791
|
+
readonly 'turn.agent_busy': {
|
|
2792
|
+
readonly title: "Agent is busy";
|
|
2793
|
+
readonly retryable: true;
|
|
2794
|
+
readonly public: true;
|
|
2795
|
+
readonly action: "Wait for the current turn to finish or steer it.";
|
|
2796
|
+
};
|
|
2797
|
+
readonly 'model.not_configured': {
|
|
2798
|
+
readonly title: "No model configured";
|
|
2799
|
+
readonly retryable: false;
|
|
2800
|
+
readonly public: true;
|
|
2801
|
+
readonly action: "Set a default model in config.toml or via setModel.";
|
|
2802
|
+
};
|
|
2803
|
+
readonly 'model.config_invalid': {
|
|
2804
|
+
readonly title: "Invalid model configuration";
|
|
2805
|
+
readonly retryable: false;
|
|
2806
|
+
readonly public: true;
|
|
2807
|
+
readonly action: "Check the model and provider entries in config.toml.";
|
|
2808
|
+
};
|
|
2809
|
+
readonly 'auth.login_required': {
|
|
2810
|
+
readonly title: "Login required";
|
|
2811
|
+
readonly retryable: false;
|
|
2812
|
+
readonly public: true;
|
|
2813
|
+
readonly action: "Run the login flow for the provider before retrying.";
|
|
2814
|
+
};
|
|
2815
|
+
readonly 'context.overflow': {
|
|
2816
|
+
readonly title: "Context window overflow";
|
|
2817
|
+
readonly retryable: true;
|
|
2818
|
+
readonly public: true;
|
|
2819
|
+
readonly action: "Compact the conversation or start a new session.";
|
|
2820
|
+
};
|
|
2821
|
+
readonly 'loop.max_steps_exceeded': {
|
|
2822
|
+
readonly title: "Turn exceeded max steps";
|
|
2823
|
+
readonly retryable: false;
|
|
2824
|
+
readonly public: true;
|
|
2825
|
+
readonly action: "Increase loop_control.max_steps_per_turn or split the task.";
|
|
2826
|
+
};
|
|
2827
|
+
readonly 'provider.api_error': {
|
|
2828
|
+
readonly title: "Provider API error";
|
|
2829
|
+
readonly retryable: false;
|
|
2830
|
+
readonly public: true;
|
|
2831
|
+
readonly action: "Inspect details.statusCode / details.requestId; check provider status.";
|
|
2832
|
+
};
|
|
2833
|
+
readonly 'provider.rate_limit': {
|
|
2834
|
+
readonly title: "Provider rate limit";
|
|
2835
|
+
readonly retryable: true;
|
|
2836
|
+
readonly public: true;
|
|
2837
|
+
readonly action: "Retry after a delay or reduce request frequency.";
|
|
2838
|
+
};
|
|
2839
|
+
readonly 'provider.auth_error': {
|
|
2840
|
+
readonly title: "Provider authentication error";
|
|
2841
|
+
readonly retryable: false;
|
|
2842
|
+
readonly public: true;
|
|
2843
|
+
readonly action: "Re-authenticate with the provider.";
|
|
2844
|
+
};
|
|
2845
|
+
readonly 'provider.connection_error': {
|
|
2846
|
+
readonly title: "Provider connection error";
|
|
2847
|
+
readonly retryable: true;
|
|
2848
|
+
readonly public: true;
|
|
2849
|
+
readonly action: "Check network connectivity and retry.";
|
|
2850
|
+
};
|
|
2851
|
+
readonly 'skill.not_found': {
|
|
2852
|
+
readonly title: "Skill not found";
|
|
2853
|
+
readonly retryable: false;
|
|
2854
|
+
readonly public: true;
|
|
2855
|
+
readonly action: "List available skills via the skill registry.";
|
|
2856
|
+
};
|
|
2857
|
+
readonly 'skill.type_unsupported': {
|
|
2858
|
+
readonly title: "Skill type not supported";
|
|
2859
|
+
readonly retryable: false;
|
|
2860
|
+
readonly public: true;
|
|
2861
|
+
readonly action: "Only inline skills can be activated by the user.";
|
|
2862
|
+
};
|
|
2863
|
+
readonly 'skill.name_empty': {
|
|
2864
|
+
readonly title: "Skill name is empty";
|
|
2865
|
+
readonly retryable: false;
|
|
2866
|
+
readonly public: true;
|
|
2867
|
+
readonly action: "Provide a non-empty skill name.";
|
|
2868
|
+
};
|
|
2869
|
+
readonly 'records.write_failed': {
|
|
2870
|
+
readonly title: "Failed to write records";
|
|
2871
|
+
readonly retryable: true;
|
|
2872
|
+
readonly public: true;
|
|
2873
|
+
readonly action: "Check disk space and permissions on the session directory.";
|
|
2874
|
+
};
|
|
2875
|
+
readonly 'compaction.failed': {
|
|
2876
|
+
readonly title: "Compaction failed";
|
|
2877
|
+
readonly retryable: false;
|
|
2878
|
+
readonly public: true;
|
|
2879
|
+
readonly action: "Inspect logs and consider increasing compaction limits.";
|
|
2880
|
+
};
|
|
2881
|
+
readonly 'background.task_id_empty': {
|
|
2882
|
+
readonly title: "Background task id is empty";
|
|
2883
|
+
readonly retryable: false;
|
|
2884
|
+
readonly public: true;
|
|
2885
|
+
readonly action: "Provide a non-empty task id.";
|
|
2886
|
+
};
|
|
2887
|
+
readonly 'mcp.server_not_found': {
|
|
2888
|
+
readonly title: "MCP server not found";
|
|
2889
|
+
readonly retryable: false;
|
|
2890
|
+
readonly public: true;
|
|
2891
|
+
readonly action: "List configured MCP servers and check the requested name.";
|
|
2892
|
+
};
|
|
2893
|
+
readonly 'mcp.server_disabled': {
|
|
2894
|
+
readonly title: "MCP server is disabled";
|
|
2895
|
+
readonly retryable: false;
|
|
2896
|
+
readonly public: true;
|
|
2897
|
+
readonly action: "Enable the MCP server entry in config before reconnecting.";
|
|
2898
|
+
};
|
|
2899
|
+
readonly 'mcp.startup_failed': {
|
|
2900
|
+
readonly title: "MCP server startup failed";
|
|
2901
|
+
readonly retryable: true;
|
|
2902
|
+
readonly public: true;
|
|
2903
|
+
readonly action: "Inspect the MCP server log or call reconnect once the server is healthy.";
|
|
2904
|
+
};
|
|
2905
|
+
readonly 'mcp.tool_name_collision': {
|
|
2906
|
+
readonly title: "MCP tool name collision";
|
|
2907
|
+
readonly retryable: false;
|
|
2908
|
+
readonly public: true;
|
|
2909
|
+
readonly action: "Rename one of the colliding MCP tools or servers so their qualified names are unique.";
|
|
2910
|
+
};
|
|
2911
|
+
readonly 'request.invalid': {
|
|
2912
|
+
readonly title: "Invalid request";
|
|
2913
|
+
readonly retryable: false;
|
|
2914
|
+
readonly public: true;
|
|
2915
|
+
readonly action: "Check the input shape matches the API contract.";
|
|
2916
|
+
};
|
|
2917
|
+
readonly 'request.work_dir_required': {
|
|
2918
|
+
readonly title: "workDir is required";
|
|
2919
|
+
readonly retryable: false;
|
|
2920
|
+
readonly public: true;
|
|
2921
|
+
readonly action: "Provide workDir in the request payload.";
|
|
2922
|
+
};
|
|
2923
|
+
readonly 'request.prompt_input_empty': {
|
|
2924
|
+
readonly title: "Prompt input is empty";
|
|
2925
|
+
readonly retryable: false;
|
|
2926
|
+
readonly public: true;
|
|
2927
|
+
readonly action: "Provide non-empty prompt input.";
|
|
2928
|
+
};
|
|
2929
|
+
readonly 'shell.git_bash_not_found': {
|
|
2930
|
+
readonly title: "Git Bash not found";
|
|
2931
|
+
readonly retryable: false;
|
|
2932
|
+
readonly public: true;
|
|
2933
|
+
readonly action: "Install Git for Windows from https://gitforwindows.org/ or set BYF_SHELL_PATH to a bash.exe.";
|
|
2934
|
+
};
|
|
2935
|
+
readonly not_implemented: {
|
|
2936
|
+
readonly title: "Not implemented";
|
|
2937
|
+
readonly retryable: false;
|
|
2938
|
+
readonly public: true;
|
|
2939
|
+
readonly action: "This feature is not implemented yet.";
|
|
2940
|
+
};
|
|
2941
|
+
readonly internal: {
|
|
2942
|
+
readonly title: "Internal error";
|
|
2943
|
+
readonly retryable: false;
|
|
2944
|
+
readonly public: true;
|
|
2945
|
+
readonly action: "Inspect logs or report the issue with diagnostics.";
|
|
2946
|
+
};
|
|
2947
|
+
};
|
|
2948
|
+
//#endregion
|
|
2949
|
+
//#region src/errors/classes.d.ts
|
|
2950
|
+
interface ByfErrorOptions {
|
|
2951
|
+
/** JSON-serializable structured details. */
|
|
2952
|
+
readonly details?: Record<string, unknown>;
|
|
2953
|
+
/** Original error or value. Local-only; never serialized to the wire. */
|
|
2954
|
+
readonly cause?: unknown;
|
|
2955
|
+
}
|
|
2956
|
+
/**
|
|
2957
|
+
* The single Byf error class.
|
|
2958
|
+
*
|
|
2959
|
+
* Discrimination is always by `code`. Cross-process consumers receive
|
|
2960
|
+
* `ByfErrorPayload` and must branch on `code` rather than class identity.
|
|
2961
|
+
*/
|
|
2962
|
+
declare class ByfError extends Error {
|
|
2963
|
+
readonly code: ByfErrorCode;
|
|
2964
|
+
readonly details?: Record<string, unknown>;
|
|
2965
|
+
readonly cause?: unknown;
|
|
2966
|
+
constructor(code: ByfErrorCode, message: string, options?: ByfErrorOptions);
|
|
2967
|
+
}
|
|
2968
|
+
//#endregion
|
|
2969
|
+
//#region src/errors/serialize.d.ts
|
|
2970
|
+
/**
|
|
2971
|
+
* Wire-safe payload of a Byf error.
|
|
2972
|
+
*
|
|
2973
|
+
* The structure passed across process / language boundaries (RPC, events,
|
|
2974
|
+
* telemetry, SDK wrappers). Class identity does not survive the boundary;
|
|
2975
|
+
* downstream code must branch on `code` rather than `instanceof`.
|
|
2976
|
+
*
|
|
2977
|
+
* `details` is JSON-serialized. `cause` is intentionally absent -- it is
|
|
2978
|
+
* local-only diagnostic state and must not cross the boundary.
|
|
2979
|
+
*/
|
|
2980
|
+
interface ByfErrorPayload {
|
|
2981
|
+
readonly code: ByfErrorCode;
|
|
2982
|
+
readonly message: string;
|
|
2983
|
+
readonly name?: string;
|
|
2984
|
+
readonly details?: Record<string, unknown>;
|
|
2985
|
+
readonly retryable: boolean;
|
|
2986
|
+
}
|
|
2987
|
+
/** Type guard for ByfError. */
|
|
2988
|
+
declare function isByfError(error: unknown): error is ByfError;
|
|
2989
|
+
/**
|
|
2990
|
+
* Build a ByfErrorPayload directly from a code + message (no Error instance
|
|
2991
|
+
* needed). Use this for synthetic error events that are signaled, not thrown
|
|
2992
|
+
* -- e.g. "turn busy" or "compaction failed". `retryable` is filled from
|
|
2993
|
+
* BYF_ERROR_INFO so callers cannot drift out of sync with the registry.
|
|
2994
|
+
*/
|
|
2995
|
+
declare function makeErrorPayload(code: ByfErrorCode, message: string, options?: {
|
|
2996
|
+
readonly details?: Record<string, unknown>;
|
|
2997
|
+
readonly name?: string;
|
|
2998
|
+
}): ByfErrorPayload;
|
|
2999
|
+
/**
|
|
3000
|
+
* Normalize any value into a ByfErrorPayload.
|
|
3001
|
+
*
|
|
3002
|
+
* Recognized errors:
|
|
3003
|
+
* - `ByfError`: passthrough.
|
|
3004
|
+
* - `APIStatusError`: 429 -> rate_limit, 401 -> auth_error, otherwise -> api_error.
|
|
3005
|
+
* - `APIConnectionError` / `APITimeoutError`: connection_error.
|
|
3006
|
+
* - `ChatProviderError`: api_error.
|
|
3007
|
+
* - Heuristic "Model not set" / "Provider not set" messages: model.not_configured.
|
|
3008
|
+
*
|
|
3009
|
+
* Anything else collapses to `internal`. We never echo `cause` or stack on
|
|
3010
|
+
* the wire.
|
|
3011
|
+
*/
|
|
3012
|
+
declare function toByfErrorPayload(error: unknown): ByfErrorPayload;
|
|
3013
|
+
/**
|
|
3014
|
+
* Rehydrate a ByfErrorPayload into a ByfError. Used by SDK boundary code
|
|
3015
|
+
* receiving errors over RPC to re-surface them with a real class so
|
|
3016
|
+
* in-process consumers can still use `instanceof`.
|
|
3017
|
+
*/
|
|
3018
|
+
declare function fromByfErrorPayload(payload: ByfErrorPayload): ByfError;
|
|
3019
|
+
//#endregion
|
|
3020
|
+
//#region src/rpc/events.d.ts
|
|
3021
|
+
interface UsageStatus$1 {
|
|
3022
|
+
readonly byModel?: Record<string, TokenUsage> | undefined;
|
|
3023
|
+
readonly currentTurn?: TokenUsage | undefined;
|
|
3024
|
+
readonly total?: TokenUsage | undefined;
|
|
3025
|
+
}
|
|
3026
|
+
interface ToolUpdate {
|
|
3027
|
+
readonly kind: 'stdout' | 'stderr' | 'progress' | 'status' | 'custom';
|
|
3028
|
+
readonly text?: string | undefined;
|
|
3029
|
+
readonly percent?: number | undefined;
|
|
3030
|
+
readonly customKind?: string | undefined;
|
|
3031
|
+
readonly customData?: unknown;
|
|
3032
|
+
}
|
|
3033
|
+
declare const MCP_OAUTH_AUTHORIZATION_URL_TOOL_UPDATE = "mcp.oauth.authorization_url";
|
|
3034
|
+
interface McpOAuthAuthorizationUrlUpdateData {
|
|
3035
|
+
readonly serverName: string;
|
|
3036
|
+
readonly authorizationUrl: string;
|
|
3037
|
+
}
|
|
3038
|
+
interface CompactionResult {
|
|
3039
|
+
readonly summary: string;
|
|
3040
|
+
readonly compactedCount: number;
|
|
3041
|
+
readonly tokensBefore: number;
|
|
3042
|
+
readonly tokensAfter: number;
|
|
3043
|
+
}
|
|
3044
|
+
type TurnEndReason = 'completed' | 'cancelled' | 'failed';
|
|
3045
|
+
interface AgentStatusUpdatedEvent {
|
|
3046
|
+
readonly type: 'agent.status.updated';
|
|
3047
|
+
readonly model?: string | undefined;
|
|
3048
|
+
readonly contextTokens?: number | undefined;
|
|
3049
|
+
readonly maxContextTokens?: number | undefined;
|
|
3050
|
+
readonly contextUsage?: number | undefined;
|
|
3051
|
+
readonly planMode?: boolean | undefined;
|
|
3052
|
+
readonly permission?: PermissionMode$1 | undefined;
|
|
3053
|
+
readonly usage?: UsageStatus$1 | undefined;
|
|
3054
|
+
}
|
|
3055
|
+
interface SessionMetaUpdatedEvent {
|
|
3056
|
+
readonly type: 'session.meta.updated';
|
|
3057
|
+
readonly title?: string | undefined;
|
|
3058
|
+
readonly patch?: Record<string, unknown> | undefined;
|
|
3059
|
+
}
|
|
3060
|
+
interface SkillActivatedEvent {
|
|
3061
|
+
readonly type: 'skill.activated';
|
|
3062
|
+
readonly activationId: string;
|
|
3063
|
+
readonly skillName: string;
|
|
3064
|
+
readonly skillArgs?: string | undefined;
|
|
3065
|
+
readonly trigger: 'user-slash' | 'model-tool' | 'nested-skill';
|
|
3066
|
+
readonly skillPath?: string | undefined;
|
|
3067
|
+
readonly skillSource?: SkillSource | undefined;
|
|
3068
|
+
}
|
|
3069
|
+
interface ErrorEvent extends ByfErrorPayload {
|
|
3070
|
+
readonly type: 'error';
|
|
3071
|
+
}
|
|
3072
|
+
interface WarningEvent {
|
|
3073
|
+
readonly type: 'warning';
|
|
3074
|
+
readonly message: string;
|
|
3075
|
+
readonly code?: string | undefined;
|
|
3076
|
+
}
|
|
3077
|
+
interface TurnStartedEvent {
|
|
3078
|
+
readonly type: 'turn.started';
|
|
3079
|
+
readonly turnId: number;
|
|
3080
|
+
readonly origin: PromptOrigin;
|
|
3081
|
+
}
|
|
3082
|
+
interface TurnEndedEvent {
|
|
3083
|
+
readonly type: 'turn.ended';
|
|
3084
|
+
readonly turnId: number;
|
|
3085
|
+
readonly reason: TurnEndReason;
|
|
3086
|
+
readonly error?: ByfErrorPayload | undefined;
|
|
3087
|
+
}
|
|
3088
|
+
interface TurnStepStartedEvent {
|
|
3089
|
+
readonly type: 'turn.step.started';
|
|
3090
|
+
readonly turnId: number;
|
|
3091
|
+
readonly step: number;
|
|
3092
|
+
readonly stepId?: string | undefined;
|
|
3093
|
+
}
|
|
3094
|
+
interface TurnStepCompletedEvent {
|
|
3095
|
+
readonly type: 'turn.step.completed';
|
|
3096
|
+
readonly turnId: number;
|
|
3097
|
+
readonly step: number;
|
|
3098
|
+
readonly stepId?: string | undefined;
|
|
3099
|
+
readonly usage?: TokenUsage | undefined;
|
|
3100
|
+
readonly finishReason?: string | undefined;
|
|
3101
|
+
readonly providerFinishReason?: FinishReason | undefined;
|
|
3102
|
+
readonly rawFinishReason?: string | undefined;
|
|
3103
|
+
}
|
|
3104
|
+
interface TurnStepRetryingEvent {
|
|
3105
|
+
readonly type: 'turn.step.retrying';
|
|
3106
|
+
readonly turnId: number;
|
|
3107
|
+
readonly step: number;
|
|
3108
|
+
readonly stepId?: string;
|
|
3109
|
+
readonly failedAttempt: number;
|
|
3110
|
+
readonly nextAttempt: number;
|
|
3111
|
+
readonly maxAttempts: number;
|
|
3112
|
+
readonly delayMs: number;
|
|
3113
|
+
readonly errorName: string;
|
|
3114
|
+
readonly errorMessage: string;
|
|
3115
|
+
readonly statusCode?: number;
|
|
3116
|
+
}
|
|
3117
|
+
interface TurnStepInterruptedEvent {
|
|
3118
|
+
readonly type: 'turn.step.interrupted';
|
|
3119
|
+
readonly turnId: number;
|
|
3120
|
+
readonly step: number;
|
|
3121
|
+
readonly stepId?: string | undefined;
|
|
3122
|
+
readonly reason: string;
|
|
3123
|
+
readonly message?: string | undefined;
|
|
3124
|
+
}
|
|
3125
|
+
interface AssistantDeltaEvent {
|
|
3126
|
+
readonly type: 'assistant.delta';
|
|
3127
|
+
readonly turnId: number;
|
|
3128
|
+
readonly delta: string;
|
|
3129
|
+
}
|
|
3130
|
+
interface HookResultEvent {
|
|
3131
|
+
readonly type: 'hook.result';
|
|
3132
|
+
readonly turnId: number;
|
|
3133
|
+
readonly hookEvent: string;
|
|
3134
|
+
readonly content: string;
|
|
3135
|
+
readonly blocked?: boolean | undefined;
|
|
3136
|
+
}
|
|
3137
|
+
interface ThinkingDeltaEvent {
|
|
3138
|
+
readonly type: 'thinking.delta';
|
|
3139
|
+
readonly turnId: number;
|
|
3140
|
+
readonly delta: string;
|
|
3141
|
+
}
|
|
3142
|
+
interface ToolCallDeltaEvent {
|
|
3143
|
+
readonly type: 'tool.call.delta';
|
|
3144
|
+
readonly turnId: number;
|
|
3145
|
+
readonly toolCallId: string;
|
|
3146
|
+
readonly name?: string | undefined;
|
|
3147
|
+
readonly argumentsPart?: string | undefined;
|
|
3148
|
+
}
|
|
3149
|
+
interface ToolCallStartedEvent {
|
|
3150
|
+
readonly type: 'tool.call.started';
|
|
3151
|
+
readonly turnId: number;
|
|
3152
|
+
readonly toolCallId: string;
|
|
3153
|
+
readonly name: string;
|
|
3154
|
+
readonly args: unknown;
|
|
3155
|
+
readonly description?: string | undefined;
|
|
3156
|
+
readonly display?: ToolInputDisplay | undefined;
|
|
3157
|
+
}
|
|
3158
|
+
interface ToolProgressEvent {
|
|
3159
|
+
readonly type: 'tool.progress';
|
|
3160
|
+
readonly turnId: number;
|
|
3161
|
+
readonly toolCallId: string;
|
|
3162
|
+
readonly update: ToolUpdate;
|
|
3163
|
+
}
|
|
3164
|
+
interface ToolResultEvent {
|
|
3165
|
+
readonly type: 'tool.result';
|
|
3166
|
+
readonly turnId: number;
|
|
3167
|
+
readonly toolCallId: string;
|
|
3168
|
+
readonly output: unknown;
|
|
3169
|
+
readonly isError?: boolean | undefined;
|
|
3170
|
+
readonly synthetic?: boolean | undefined;
|
|
3171
|
+
}
|
|
3172
|
+
interface SubagentSpawnedEvent {
|
|
3173
|
+
readonly type: 'subagent.spawned';
|
|
3174
|
+
readonly subagentId: string;
|
|
3175
|
+
readonly subagentName: string;
|
|
3176
|
+
readonly parentToolCallId: string;
|
|
3177
|
+
readonly parentToolCallUuid?: string | undefined;
|
|
3178
|
+
readonly parentAgentId?: string | undefined;
|
|
3179
|
+
readonly description?: string | undefined;
|
|
3180
|
+
readonly runInBackground: boolean;
|
|
3181
|
+
}
|
|
3182
|
+
interface SubagentCompletedEvent {
|
|
3183
|
+
readonly type: 'subagent.completed';
|
|
3184
|
+
readonly subagentId: string;
|
|
3185
|
+
readonly parentToolCallId: string;
|
|
3186
|
+
readonly resultSummary: string;
|
|
3187
|
+
readonly usage?: TokenUsage | undefined;
|
|
3188
|
+
}
|
|
3189
|
+
interface SubagentFailedEvent {
|
|
3190
|
+
readonly type: 'subagent.failed';
|
|
3191
|
+
readonly subagentId: string;
|
|
3192
|
+
readonly parentToolCallId: string;
|
|
3193
|
+
readonly error: string;
|
|
3194
|
+
}
|
|
3195
|
+
interface CompactionStartedEvent {
|
|
3196
|
+
readonly type: 'compaction.started';
|
|
3197
|
+
readonly trigger: 'manual' | 'auto';
|
|
3198
|
+
readonly instruction?: string | undefined;
|
|
3199
|
+
}
|
|
3200
|
+
interface CompactionBlockedEvent {
|
|
3201
|
+
readonly type: 'compaction.blocked';
|
|
3202
|
+
readonly turnId?: number | undefined;
|
|
3203
|
+
}
|
|
3204
|
+
interface CompactionCancelledEvent {
|
|
3205
|
+
readonly type: 'compaction.cancelled';
|
|
3206
|
+
}
|
|
3207
|
+
interface CompactionCompletedEvent {
|
|
3208
|
+
readonly type: 'compaction.completed';
|
|
3209
|
+
readonly result: CompactionResult;
|
|
3210
|
+
}
|
|
3211
|
+
interface BackgroundTaskStartedEvent {
|
|
3212
|
+
readonly type: 'background.task.started';
|
|
3213
|
+
readonly info: BackgroundTaskInfo$1;
|
|
3214
|
+
}
|
|
3215
|
+
interface BackgroundTaskUpdatedEvent {
|
|
3216
|
+
readonly type: 'background.task.updated';
|
|
3217
|
+
readonly info: BackgroundTaskInfo$1;
|
|
3218
|
+
}
|
|
3219
|
+
interface BackgroundTaskTerminatedEvent {
|
|
3220
|
+
readonly type: 'background.task.terminated';
|
|
3221
|
+
readonly info: BackgroundTaskInfo$1;
|
|
3222
|
+
}
|
|
3223
|
+
type ToolListUpdatedReason = 'mcp.connected' | 'mcp.disconnected' | 'mcp.failed';
|
|
3224
|
+
interface ToolListUpdatedEvent {
|
|
3225
|
+
readonly type: 'tool.list.updated';
|
|
3226
|
+
readonly reason: ToolListUpdatedReason;
|
|
3227
|
+
readonly serverName: string;
|
|
3228
|
+
}
|
|
3229
|
+
interface McpServerStatusEvent {
|
|
3230
|
+
readonly type: 'mcp.server.status';
|
|
3231
|
+
readonly server: McpServerStatusPayload;
|
|
3232
|
+
}
|
|
3233
|
+
interface McpServerStatusPayload {
|
|
3234
|
+
readonly name: string;
|
|
3235
|
+
readonly transport: 'stdio' | 'http';
|
|
3236
|
+
readonly status: 'pending' | 'connected' | 'failed' | 'disabled' | 'needs-auth';
|
|
3237
|
+
readonly toolCount: number;
|
|
3238
|
+
readonly error?: string | undefined;
|
|
3239
|
+
}
|
|
3240
|
+
type AgentEvent$1 = ErrorEvent | WarningEvent | AgentStatusUpdatedEvent | SessionMetaUpdatedEvent | SkillActivatedEvent | TurnStartedEvent | TurnEndedEvent | TurnStepStartedEvent | TurnStepCompletedEvent | TurnStepRetryingEvent | TurnStepInterruptedEvent | AssistantDeltaEvent | HookResultEvent | ThinkingDeltaEvent | ToolCallDeltaEvent | ToolCallStartedEvent | ToolProgressEvent | ToolResultEvent | ToolListUpdatedEvent | McpServerStatusEvent | SubagentSpawnedEvent | SubagentCompletedEvent | SubagentFailedEvent | CompactionStartedEvent | CompactionBlockedEvent | CompactionCancelledEvent | CompactionCompletedEvent | BackgroundTaskStartedEvent | BackgroundTaskUpdatedEvent | BackgroundTaskTerminatedEvent;
|
|
3241
|
+
type Event = AgentEvent$1 & {
|
|
3242
|
+
agentId: string;
|
|
3243
|
+
sessionId: string;
|
|
3244
|
+
};
|
|
3245
|
+
//#endregion
|
|
3246
|
+
//#region src/rpc/resumed.d.ts
|
|
3247
|
+
type AgentReplayRecord = {
|
|
3248
|
+
type: 'message';
|
|
3249
|
+
message: ContextMessage;
|
|
3250
|
+
} | {
|
|
3251
|
+
type: 'plan_updated';
|
|
3252
|
+
enabled: boolean;
|
|
3253
|
+
} | {
|
|
3254
|
+
type: 'config_updated';
|
|
3255
|
+
config: AgentConfigUpdateData;
|
|
3256
|
+
} | {
|
|
3257
|
+
type: 'permission_updated';
|
|
3258
|
+
mode: PermissionMode;
|
|
3259
|
+
} | {
|
|
3260
|
+
type: 'approval_result';
|
|
3261
|
+
record: PermissionApprovalResultRecord;
|
|
3262
|
+
};
|
|
3263
|
+
interface ResumedAgentState {
|
|
3264
|
+
readonly type: AgentType;
|
|
3265
|
+
readonly config: AgentConfigData;
|
|
3266
|
+
readonly context: AgentContextData;
|
|
3267
|
+
readonly replay: readonly AgentReplayRecord[];
|
|
3268
|
+
readonly permission: PermissionData;
|
|
3269
|
+
readonly plan: PlanData;
|
|
3270
|
+
readonly usage: UsageStatus$1;
|
|
3271
|
+
readonly tools: readonly ToolInfo[];
|
|
3272
|
+
readonly toolStore?: Readonly<Record<string, unknown>>;
|
|
3273
|
+
readonly background: readonly BackgroundTaskInfo[];
|
|
3274
|
+
}
|
|
3275
|
+
interface ResumeSessionResult extends SessionSummary {
|
|
3276
|
+
readonly sessionMetadata: SessionMeta;
|
|
3277
|
+
readonly agents: Readonly<Record<string, ResumedAgentState>>;
|
|
3278
|
+
readonly warning?: string | undefined;
|
|
3279
|
+
}
|
|
3280
|
+
//#endregion
|
|
3281
|
+
//#region src/rpc/types.d.ts
|
|
3282
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
3283
|
+
type WithExtraPayload<T, U> = { [K in keyof T]: T[K] extends ((payload: infer P) => infer R) ? (payload: Prettify<P & U>) => R : never };
|
|
3284
|
+
type WithAgentId<T> = WithExtraPayload<T, {
|
|
3285
|
+
readonly agentId: string;
|
|
3286
|
+
}>;
|
|
3287
|
+
type WithSessionId<T> = WithExtraPayload<T, {
|
|
3288
|
+
readonly sessionId: string;
|
|
3289
|
+
}>;
|
|
3290
|
+
declare function proxyWithExtraPayload<T, U>(methods: RPCMethods<WithExtraPayload<T, U>>, extraPayload: U): RPCMethods<T>;
|
|
3291
|
+
//#endregion
|
|
3292
|
+
//#region src/rpc/core-api.d.ts
|
|
3293
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
3294
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3295
|
+
readonly [key: string]: JsonValue;
|
|
3296
|
+
};
|
|
3297
|
+
type JsonObject = {
|
|
3298
|
+
readonly [key: string]: JsonValue;
|
|
3299
|
+
};
|
|
3300
|
+
type Unsubscribe = () => void;
|
|
3301
|
+
type TextPromptPart = Extract<ContentPart, {
|
|
3302
|
+
type: 'text';
|
|
3303
|
+
}>;
|
|
3304
|
+
type PromptPart = Extract<ContentPart, {
|
|
3305
|
+
type: 'text' | 'image_url' | 'video_url';
|
|
3306
|
+
}>;
|
|
3307
|
+
type PromptInput = readonly PromptPart[];
|
|
3308
|
+
type EmptyPayload = {};
|
|
3309
|
+
type SessionMetadataPatch = Partial<Omit<SessionMeta, 'agents'>>;
|
|
3310
|
+
interface CreateSessionPayload {
|
|
3311
|
+
readonly id?: string | undefined;
|
|
3312
|
+
readonly workDir: string;
|
|
3313
|
+
readonly model?: string | undefined;
|
|
3314
|
+
readonly thinking?: string | undefined;
|
|
3315
|
+
readonly permission?: PermissionMode | undefined;
|
|
3316
|
+
readonly metadata?: JsonObject | undefined;
|
|
3317
|
+
}
|
|
3318
|
+
interface CloseSessionPayload {
|
|
3319
|
+
readonly sessionId: string;
|
|
3320
|
+
}
|
|
3321
|
+
interface ResumeSessionPayload {
|
|
3322
|
+
readonly sessionId: string;
|
|
3323
|
+
}
|
|
3324
|
+
interface ForkSessionPayload {
|
|
3325
|
+
readonly sessionId: string;
|
|
3326
|
+
readonly id?: string;
|
|
3327
|
+
readonly title?: string;
|
|
3328
|
+
readonly metadata?: JsonObject;
|
|
3329
|
+
}
|
|
3330
|
+
interface ExportSessionPayload {
|
|
3331
|
+
readonly sessionId: string;
|
|
3332
|
+
readonly outputPath?: string | undefined;
|
|
3333
|
+
/**
|
|
3334
|
+
* When true, the active global diagnostic log (`$BYF_HOME/logs/byf.log`)
|
|
3335
|
+
* is copied into the zip at `logs/global/byf.log`. Off by default to
|
|
3336
|
+
* avoid bundling events from concurrent sessions / other projects.
|
|
3337
|
+
*/
|
|
3338
|
+
readonly includeGlobalLog?: boolean | undefined;
|
|
3339
|
+
/** Host version to record in the export manifest. */
|
|
3340
|
+
readonly version: string;
|
|
3341
|
+
}
|
|
3342
|
+
interface ExportSessionManifest {
|
|
3343
|
+
readonly sessionId: string;
|
|
3344
|
+
readonly exportedAt: string;
|
|
3345
|
+
readonly byfCodeVersion: string;
|
|
3346
|
+
readonly wireProtocolVersion: string;
|
|
3347
|
+
readonly os: string;
|
|
3348
|
+
readonly nodejsVersion: string;
|
|
3349
|
+
readonly sessionFirstActivity?: string | undefined;
|
|
3350
|
+
readonly sessionLastActivity?: string | undefined;
|
|
3351
|
+
readonly title?: string | undefined;
|
|
3352
|
+
readonly workspaceDir?: string | undefined;
|
|
3353
|
+
/** zip-relative path to the session diagnostic log when present. */
|
|
3354
|
+
readonly sessionLogPath?: string | undefined;
|
|
3355
|
+
/** zip-relative path to the bundled global diagnostic log (only when --include-global-log). */
|
|
3356
|
+
readonly globalLogPath?: string | undefined;
|
|
3357
|
+
}
|
|
3358
|
+
interface ExportSessionResult {
|
|
3359
|
+
readonly zipPath: string;
|
|
3360
|
+
readonly entries: readonly string[];
|
|
3361
|
+
readonly sessionDir: string;
|
|
3362
|
+
readonly manifest: ExportSessionManifest;
|
|
3363
|
+
}
|
|
3364
|
+
interface ListSessionsPayload {
|
|
3365
|
+
readonly workDir: string;
|
|
3366
|
+
}
|
|
3367
|
+
interface CoreInfo {
|
|
3368
|
+
readonly version: string;
|
|
3369
|
+
}
|
|
3370
|
+
interface SessionSummary {
|
|
3371
|
+
readonly id: string;
|
|
3372
|
+
readonly title?: string | undefined;
|
|
3373
|
+
readonly lastPrompt?: string;
|
|
3374
|
+
readonly workDir: string;
|
|
3375
|
+
readonly sessionDir: string;
|
|
3376
|
+
readonly createdAt: number;
|
|
3377
|
+
readonly updatedAt: number;
|
|
3378
|
+
readonly archived?: boolean | undefined;
|
|
3379
|
+
readonly metadata?: JsonObject | undefined;
|
|
3380
|
+
}
|
|
3381
|
+
interface PromptPayload {
|
|
3382
|
+
readonly input: readonly ContentPart[];
|
|
3383
|
+
}
|
|
3384
|
+
interface SteerPayload {
|
|
3385
|
+
readonly input: readonly ContentPart[];
|
|
3386
|
+
}
|
|
3387
|
+
interface CancelPayload {
|
|
3388
|
+
readonly turnId?: number;
|
|
3389
|
+
}
|
|
3390
|
+
interface SetThinkingPayload {
|
|
3391
|
+
readonly level: string;
|
|
3392
|
+
}
|
|
3393
|
+
interface SetPermissionPayload {
|
|
3394
|
+
readonly mode: PermissionMode;
|
|
3395
|
+
}
|
|
3396
|
+
interface SetModelPayload {
|
|
3397
|
+
readonly model: string;
|
|
3398
|
+
}
|
|
3399
|
+
interface SetModelResult {
|
|
3400
|
+
readonly model: string;
|
|
3401
|
+
readonly providerName?: string | undefined;
|
|
3402
|
+
}
|
|
3403
|
+
interface CancelPlanPayload {
|
|
3404
|
+
readonly id?: string;
|
|
3405
|
+
}
|
|
3406
|
+
interface BeginCompactionPayload {
|
|
3407
|
+
readonly instruction?: string;
|
|
3408
|
+
}
|
|
3409
|
+
interface RegisterToolPayload {
|
|
3410
|
+
readonly name: string;
|
|
3411
|
+
readonly description: string;
|
|
3412
|
+
readonly parameters: Record<string, unknown>;
|
|
3413
|
+
}
|
|
3414
|
+
interface UnregisterToolPayload {
|
|
3415
|
+
readonly name: string;
|
|
3416
|
+
}
|
|
3417
|
+
interface SetActiveToolsPayload {
|
|
3418
|
+
readonly names: readonly string[];
|
|
3419
|
+
}
|
|
3420
|
+
interface StopBackgroundPayload {
|
|
3421
|
+
readonly taskId: string;
|
|
3422
|
+
/** Free-form human-readable reason persisted with the task record. */
|
|
3423
|
+
readonly reason?: string;
|
|
3424
|
+
}
|
|
3425
|
+
interface GetBackgroundOutputPayload {
|
|
3426
|
+
readonly taskId: string;
|
|
3427
|
+
readonly tail?: number;
|
|
3428
|
+
}
|
|
3429
|
+
interface GetBackgroundOutputPathPayload {
|
|
3430
|
+
readonly taskId: string;
|
|
3431
|
+
}
|
|
3432
|
+
interface GetBackgroundPayload {
|
|
3433
|
+
/**
|
|
3434
|
+
* When omitted, returns all tasks (including terminal/lost). Pass
|
|
3435
|
+
* `true` to filter down to active-only — useful for model-facing
|
|
3436
|
+
* surfaces. UI/TUI consumers should leave it undefined.
|
|
3437
|
+
*/
|
|
3438
|
+
readonly activeOnly?: boolean;
|
|
3439
|
+
/** Caps the number of tasks returned. When omitted, returns all matching tasks. */
|
|
3440
|
+
readonly limit?: number;
|
|
3441
|
+
}
|
|
3442
|
+
interface SkillSummary {
|
|
3443
|
+
readonly name: string;
|
|
3444
|
+
readonly description: string;
|
|
3445
|
+
readonly path: string;
|
|
3446
|
+
readonly source: 'builtin' | 'user' | 'extra' | 'project';
|
|
3447
|
+
readonly type?: string | undefined;
|
|
3448
|
+
readonly disableModelInvocation?: boolean | undefined;
|
|
3449
|
+
}
|
|
3450
|
+
interface ActivateSkillPayload$1 {
|
|
3451
|
+
readonly name: string;
|
|
3452
|
+
readonly args?: string | undefined;
|
|
3453
|
+
}
|
|
3454
|
+
interface McpServerInfo {
|
|
3455
|
+
readonly name: string;
|
|
3456
|
+
readonly transport: 'stdio' | 'http';
|
|
3457
|
+
readonly status: 'pending' | 'connected' | 'failed' | 'disabled' | 'needs-auth';
|
|
3458
|
+
readonly toolCount: number;
|
|
3459
|
+
readonly error?: string;
|
|
3460
|
+
}
|
|
3461
|
+
interface McpStartupMetrics {
|
|
3462
|
+
readonly durationMs: number;
|
|
3463
|
+
}
|
|
3464
|
+
interface ReconnectMcpServerPayload {
|
|
3465
|
+
readonly name: string;
|
|
3466
|
+
}
|
|
3467
|
+
interface RenameSessionPayload {
|
|
3468
|
+
readonly title: string;
|
|
3469
|
+
}
|
|
3470
|
+
interface UpdateSessionMetadataPayload {
|
|
3471
|
+
readonly metadata: SessionMetadataPatch;
|
|
3472
|
+
}
|
|
3473
|
+
type SetByfConfigPayload = ByfConfigPatch;
|
|
3474
|
+
interface RemoveByfProviderPayload {
|
|
3475
|
+
readonly providerId: string;
|
|
3476
|
+
}
|
|
3477
|
+
interface ShellExecPayload {
|
|
3478
|
+
readonly sessionId: string;
|
|
3479
|
+
readonly command: string;
|
|
3480
|
+
readonly cwd?: string;
|
|
3481
|
+
readonly timeout?: number;
|
|
3482
|
+
}
|
|
3483
|
+
interface ShellExecResult {
|
|
3484
|
+
readonly stdout: string;
|
|
3485
|
+
readonly stderr: string;
|
|
3486
|
+
readonly exitCode: number;
|
|
3487
|
+
readonly timedOut: boolean;
|
|
3488
|
+
}
|
|
3489
|
+
interface AgentAPI$1 {
|
|
3490
|
+
prompt: (payload: PromptPayload) => void;
|
|
3491
|
+
steer: (payload: SteerPayload) => void;
|
|
3492
|
+
cancel: (payload: CancelPayload) => void;
|
|
3493
|
+
setThinking: (payload: SetThinkingPayload) => void;
|
|
3494
|
+
setPermission: (payload: SetPermissionPayload) => void;
|
|
3495
|
+
setModel: (payload: SetModelPayload) => SetModelResult;
|
|
3496
|
+
getModel: (payload: EmptyPayload) => string;
|
|
3497
|
+
enterPlan: (payload: EmptyPayload) => void;
|
|
3498
|
+
cancelPlan: (payload: CancelPlanPayload) => void;
|
|
3499
|
+
clearPlan: (payload: EmptyPayload) => void;
|
|
3500
|
+
beginCompaction: (payload: BeginCompactionPayload) => void;
|
|
3501
|
+
cancelCompaction: (payload: EmptyPayload) => void;
|
|
3502
|
+
registerTool: (payload: RegisterToolPayload) => void;
|
|
3503
|
+
unregisterTool: (payload: UnregisterToolPayload) => void;
|
|
3504
|
+
setActiveTools: (payload: SetActiveToolsPayload) => void;
|
|
3505
|
+
stopBackground: (payload: StopBackgroundPayload) => void;
|
|
3506
|
+
clearContext: (payload: EmptyPayload) => void;
|
|
3507
|
+
activateSkill: (payload: ActivateSkillPayload$1) => void;
|
|
3508
|
+
getBackgroundOutput: (payload: GetBackgroundOutputPayload) => string;
|
|
3509
|
+
getBackgroundOutputPath: (payload: GetBackgroundOutputPathPayload) => string | undefined;
|
|
3510
|
+
getContext: (payload: EmptyPayload) => AgentContextData;
|
|
3511
|
+
getConfig: (payload: EmptyPayload) => AgentConfigData;
|
|
3512
|
+
getPermission: (payload: EmptyPayload) => PermissionData;
|
|
3513
|
+
getPlan: (payload: EmptyPayload) => PlanData;
|
|
3514
|
+
getUsage: (payload: EmptyPayload) => UsageStatus$1;
|
|
3515
|
+
getTools: (payload: EmptyPayload) => readonly ToolInfo[];
|
|
3516
|
+
getBackground: (payload: GetBackgroundPayload) => readonly BackgroundTaskInfo[];
|
|
3517
|
+
}
|
|
3518
|
+
type AgentAPIWithId = WithAgentId<AgentAPI$1>;
|
|
3519
|
+
interface SessionAPI extends AgentAPIWithId {
|
|
3520
|
+
renameSession: (payload: RenameSessionPayload) => void;
|
|
3521
|
+
updateSessionMetadata: (payload: UpdateSessionMetadataPayload) => void;
|
|
3522
|
+
getSessionMetadata: (payload: EmptyPayload) => SessionMeta;
|
|
3523
|
+
listSkills: (payload: EmptyPayload) => readonly SkillSummary[];
|
|
3524
|
+
listMcpServers: (payload: EmptyPayload) => readonly McpServerInfo[];
|
|
3525
|
+
getMcpStartupMetrics: (payload: EmptyPayload) => McpStartupMetrics;
|
|
3526
|
+
reconnectMcpServer: (payload: ReconnectMcpServerPayload) => void;
|
|
3527
|
+
generateAgentsMd: (payload: EmptyPayload) => void;
|
|
3528
|
+
shellExec: (payload: Omit<ShellExecPayload, 'sessionId'>) => Promise<ShellExecResult>;
|
|
3529
|
+
}
|
|
3530
|
+
type SessionAPIWithId = WithSessionId<SessionAPI>;
|
|
3531
|
+
interface CoreAPI extends SessionAPIWithId {
|
|
3532
|
+
getCoreInfo: (payload: EmptyPayload) => CoreInfo;
|
|
3533
|
+
getByfConfig: (payload: EmptyPayload) => ByfConfig;
|
|
3534
|
+
setByfConfig: (payload: SetByfConfigPayload) => ByfConfig;
|
|
3535
|
+
removeByfProvider: (payload: RemoveByfProviderPayload) => ByfConfig;
|
|
3536
|
+
createSession: (payload: CreateSessionPayload) => SessionSummary;
|
|
3537
|
+
closeSession: (payload: CloseSessionPayload) => void;
|
|
3538
|
+
resumeSession: (payload: ResumeSessionPayload) => ResumeSessionResult;
|
|
3539
|
+
forkSession: (payload: ForkSessionPayload) => ResumeSessionResult;
|
|
3540
|
+
listSessions: (payload: ListSessionsPayload) => readonly SessionSummary[];
|
|
3541
|
+
exportSession: (payload: ExportSessionPayload) => ExportSessionResult;
|
|
3542
|
+
}
|
|
3543
|
+
//#endregion
|
|
3544
|
+
//#region src/rpc/sdk-api.d.ts
|
|
3545
|
+
type ApprovalDecision = 'approved' | 'rejected' | 'cancelled';
|
|
3546
|
+
type ApprovalScope = 'session';
|
|
3547
|
+
interface ApprovalResponse {
|
|
3548
|
+
readonly decision: ApprovalDecision;
|
|
3549
|
+
readonly scope?: ApprovalScope | undefined;
|
|
3550
|
+
readonly feedback?: string | undefined;
|
|
3551
|
+
readonly selectedLabel?: string | undefined;
|
|
3552
|
+
}
|
|
3553
|
+
interface ApprovalRequest {
|
|
3554
|
+
readonly turnId?: number | undefined;
|
|
3555
|
+
readonly toolCallId: string;
|
|
3556
|
+
readonly toolName: string;
|
|
3557
|
+
readonly action: string;
|
|
3558
|
+
readonly display: ToolInputDisplay;
|
|
3559
|
+
}
|
|
3560
|
+
interface QuestionOption {
|
|
3561
|
+
readonly label: string;
|
|
3562
|
+
readonly description?: string;
|
|
3563
|
+
}
|
|
3564
|
+
interface QuestionItem {
|
|
3565
|
+
readonly question: string;
|
|
3566
|
+
readonly header?: string;
|
|
3567
|
+
readonly body?: string;
|
|
3568
|
+
readonly options: readonly QuestionOption[];
|
|
3569
|
+
readonly multiSelect?: boolean;
|
|
3570
|
+
readonly otherLabel?: string;
|
|
3571
|
+
readonly otherDescription?: string;
|
|
3572
|
+
}
|
|
3573
|
+
type QuestionAnswerMethod = 'enter' | 'space' | 'number_key';
|
|
3574
|
+
type QuestionAnswers = Record<string, string | true>;
|
|
3575
|
+
interface QuestionResponse {
|
|
3576
|
+
readonly answers: QuestionAnswers;
|
|
3577
|
+
readonly method?: QuestionAnswerMethod | undefined;
|
|
3578
|
+
}
|
|
3579
|
+
type QuestionResult = null | QuestionAnswers | QuestionResponse;
|
|
3580
|
+
interface QuestionRequest {
|
|
3581
|
+
readonly turnId?: number;
|
|
3582
|
+
readonly toolCallId?: string;
|
|
3583
|
+
readonly questions: readonly QuestionItem[];
|
|
3584
|
+
}
|
|
3585
|
+
interface ToolCallRequest {
|
|
3586
|
+
readonly turnId?: number | undefined;
|
|
3587
|
+
readonly toolCallId: string;
|
|
3588
|
+
readonly args: unknown;
|
|
3589
|
+
}
|
|
3590
|
+
interface ToolCallResponse {
|
|
3591
|
+
readonly output: string | ContentPart[];
|
|
3592
|
+
readonly isError?: boolean | undefined;
|
|
3593
|
+
}
|
|
3594
|
+
interface SDKAgentAPI {
|
|
3595
|
+
emitEvent: (event: AgentEvent$1) => void;
|
|
3596
|
+
requestApproval: (request: ApprovalRequest) => Promise<ApprovalResponse>;
|
|
3597
|
+
requestQuestion: (request: QuestionRequest) => Promise<QuestionResult>;
|
|
3598
|
+
toolCall: (request: ToolCallRequest) => Promise<ToolCallResponse>;
|
|
3599
|
+
}
|
|
3600
|
+
type SDKAgentRPC$1 = RPCMethods<SDKAgentAPI>;
|
|
3601
|
+
type SDKSessionAPI = WithAgentId<SDKAgentAPI>;
|
|
3602
|
+
type SDKSessionRPC$1 = RPCMethods<SDKSessionAPI>;
|
|
3603
|
+
type SDKAPI = WithSessionId<SDKSessionAPI>;
|
|
3604
|
+
type SDKRPC = RPCMethods<SDKAPI>;
|
|
3605
|
+
//#endregion
|
|
3606
|
+
//#region src/rpc/client.d.ts
|
|
3607
|
+
interface RPCCallOptions {
|
|
3608
|
+
signal?: AbortSignal;
|
|
3609
|
+
}
|
|
3610
|
+
type RPCMethods<T> = { [K in keyof T]: T[K] extends ((payload: infer Payload) => infer Return) ? (payload: Payload, options?: RPCCallOptions) => Promisify<Return> : never };
|
|
3611
|
+
type RPCClient<Self extends Record<string, any>, Other extends Record<string, any>> = (self: PromisableMethods<Self>) => Promise<RPCMethods<Other>>;
|
|
3612
|
+
declare function createRPC<Left extends Record<string, any>, Right extends Record<string, any>>(): [RPCClient<Left, Right>, RPCClient<Right, Left>];
|
|
3613
|
+
type CoreRPCClient = RPCClient<CoreAPI, SDKAPI>;
|
|
3614
|
+
type SDKRPCClient = RPCClient<SDKAPI, CoreAPI>;
|
|
3615
|
+
type CoreRPC = RPCMethods<CoreAPI>;
|
|
3616
|
+
//#endregion
|
|
3617
|
+
//#region src/rpc/core-impl.d.ts
|
|
3618
|
+
type AgentScopedPayload<T> = T & {
|
|
3619
|
+
readonly agentId: string;
|
|
3620
|
+
};
|
|
3621
|
+
type SessionScopedPayload<T> = T & {
|
|
3622
|
+
readonly sessionId: string;
|
|
3623
|
+
};
|
|
3624
|
+
type SessionAgentPayload<T> = SessionScopedPayload<AgentScopedPayload<T>>;
|
|
3625
|
+
type RenameSessionRequest = SessionScopedPayload<RenameSessionPayload>;
|
|
3626
|
+
type UpdateSessionMetadataRequest = SessionScopedPayload<UpdateSessionMetadataPayload>;
|
|
3627
|
+
interface ByfCoreOptions {
|
|
3628
|
+
readonly homeDir?: string | undefined;
|
|
3629
|
+
readonly configPath?: string | undefined;
|
|
3630
|
+
readonly runtime?: RuntimeConfig | undefined;
|
|
3631
|
+
readonly byfRequestHeaders?: Record<string, string> | undefined;
|
|
3632
|
+
readonly resolveOAuthTokenProvider?: OAuthTokenProviderResolver | undefined;
|
|
3633
|
+
readonly skillDirs?: readonly string[];
|
|
3634
|
+
readonly telemetry?: TelemetryClient | undefined;
|
|
3635
|
+
}
|
|
3636
|
+
declare class ByfCore implements PromisableMethods<CoreAPI> {
|
|
3637
|
+
protected readonly rpcClient: CoreRPCClient;
|
|
3638
|
+
readonly sdk: Promise<SDKRPC>;
|
|
3639
|
+
readonly homeDir: string;
|
|
3640
|
+
readonly configPath: string;
|
|
3641
|
+
readonly sessions: Map<string, Session>;
|
|
3642
|
+
readonly telemetry: TelemetryClient;
|
|
3643
|
+
private runtime;
|
|
3644
|
+
private readonly userHomeDir;
|
|
3645
|
+
private readonly byfRequestHeaders;
|
|
3646
|
+
private readonly resolveOAuthTokenProvider;
|
|
3647
|
+
private readonly skillDirs;
|
|
3648
|
+
private readonly providerManager;
|
|
3649
|
+
private readonly sessionStore;
|
|
3650
|
+
constructor(rpcClient: CoreRPCClient, options?: ByfCoreOptions);
|
|
3651
|
+
createSession(input: CreateSessionPayload): Promise<SessionSummary>;
|
|
3652
|
+
getCoreInfo(): CoreInfo;
|
|
3653
|
+
closeSession({
|
|
3654
|
+
sessionId
|
|
3655
|
+
}: CloseSessionPayload): Promise<void>;
|
|
3656
|
+
resumeSession(input: ResumeSessionPayload): Promise<ResumeSessionResult>;
|
|
3657
|
+
forkSession(input: ForkSessionPayload): Promise<ResumeSessionResult>;
|
|
3658
|
+
listSessions(input: ListSessionsPayload): Promise<readonly SessionSummary[]>;
|
|
3659
|
+
renameSession({
|
|
3660
|
+
sessionId,
|
|
3661
|
+
...payload
|
|
3662
|
+
}: RenameSessionRequest): Promise<void>;
|
|
3663
|
+
exportSession(input: ExportSessionPayload): Promise<ExportSessionResult>;
|
|
3664
|
+
getByfConfig(input?: EmptyPayload): Promise<ByfConfig$1>;
|
|
3665
|
+
setByfConfig(input: SetByfConfigPayload): Promise<ByfConfig$1>;
|
|
3666
|
+
removeByfProvider(input: RemoveByfProviderPayload): Promise<ByfConfig$1>;
|
|
3667
|
+
prompt({
|
|
3668
|
+
sessionId,
|
|
3669
|
+
...payload
|
|
3670
|
+
}: SessionAgentPayload<PromptPayload>): Promise<void>;
|
|
3671
|
+
steer({
|
|
3672
|
+
sessionId,
|
|
3673
|
+
...payload
|
|
3674
|
+
}: SessionAgentPayload<SteerPayload>): void | Promise<void>;
|
|
3675
|
+
cancel({
|
|
3676
|
+
sessionId,
|
|
3677
|
+
...payload
|
|
3678
|
+
}: SessionAgentPayload<CancelPayload>): void | Promise<void>;
|
|
3679
|
+
setModel({
|
|
3680
|
+
sessionId,
|
|
3681
|
+
...payload
|
|
3682
|
+
}: SessionAgentPayload<SetModelPayload>): Promise<SetModelResult>;
|
|
3683
|
+
setThinking({
|
|
3684
|
+
sessionId,
|
|
3685
|
+
...payload
|
|
3686
|
+
}: SessionAgentPayload<SetThinkingPayload>): void | Promise<void>;
|
|
3687
|
+
setPermission({
|
|
3688
|
+
sessionId,
|
|
3689
|
+
...payload
|
|
3690
|
+
}: SessionAgentPayload<SetPermissionPayload>): void | Promise<void>;
|
|
3691
|
+
getModel({
|
|
3692
|
+
sessionId,
|
|
3693
|
+
...payload
|
|
3694
|
+
}: SessionAgentPayload<EmptyPayload>): string | Promise<string>;
|
|
3695
|
+
enterPlan({
|
|
3696
|
+
sessionId,
|
|
3697
|
+
...payload
|
|
3698
|
+
}: SessionAgentPayload<EmptyPayload>): void | Promise<void>;
|
|
3699
|
+
cancelPlan({
|
|
3700
|
+
sessionId,
|
|
3701
|
+
...payload
|
|
3702
|
+
}: SessionAgentPayload<CancelPlanPayload>): void | Promise<void>;
|
|
3703
|
+
clearPlan({
|
|
3704
|
+
sessionId,
|
|
3705
|
+
...payload
|
|
3706
|
+
}: SessionAgentPayload<EmptyPayload>): void | Promise<void>;
|
|
3707
|
+
beginCompaction({
|
|
3708
|
+
sessionId,
|
|
3709
|
+
...payload
|
|
3710
|
+
}: SessionAgentPayload<BeginCompactionPayload>): void | Promise<void>;
|
|
3711
|
+
cancelCompaction({
|
|
3712
|
+
sessionId,
|
|
3713
|
+
...payload
|
|
3714
|
+
}: SessionAgentPayload<EmptyPayload>): void | Promise<void>;
|
|
3715
|
+
registerTool({
|
|
3716
|
+
sessionId,
|
|
3717
|
+
...payload
|
|
3718
|
+
}: SessionAgentPayload<RegisterToolPayload>): void | Promise<void>;
|
|
3719
|
+
unregisterTool({
|
|
3720
|
+
sessionId,
|
|
3721
|
+
...payload
|
|
3722
|
+
}: SessionAgentPayload<UnregisterToolPayload>): void | Promise<void>;
|
|
3723
|
+
setActiveTools({
|
|
3724
|
+
sessionId,
|
|
3725
|
+
...payload
|
|
3726
|
+
}: SessionAgentPayload<SetActiveToolsPayload>): void | Promise<void>;
|
|
3727
|
+
stopBackground({
|
|
3728
|
+
sessionId,
|
|
3729
|
+
...payload
|
|
3730
|
+
}: SessionAgentPayload<StopBackgroundPayload>): void | Promise<void>;
|
|
3731
|
+
clearContext({
|
|
3732
|
+
sessionId,
|
|
3733
|
+
...payload
|
|
3734
|
+
}: SessionAgentPayload<EmptyPayload>): void | Promise<void>;
|
|
3735
|
+
activateSkill({
|
|
3736
|
+
sessionId,
|
|
3737
|
+
...payload
|
|
3738
|
+
}: SessionAgentPayload<ActivateSkillPayload$1>): Promise<void>;
|
|
3739
|
+
getBackgroundOutput({
|
|
3740
|
+
sessionId,
|
|
3741
|
+
...payload
|
|
3742
|
+
}: SessionAgentPayload<GetBackgroundOutputPayload>): string | Promise<string>;
|
|
3743
|
+
getBackgroundOutputPath({
|
|
3744
|
+
sessionId,
|
|
3745
|
+
...payload
|
|
3746
|
+
}: SessionAgentPayload<GetBackgroundOutputPathPayload>): string | Promise<string | undefined> | undefined;
|
|
3747
|
+
getContext({
|
|
3748
|
+
sessionId,
|
|
3749
|
+
...payload
|
|
3750
|
+
}: SessionAgentPayload<EmptyPayload>): AgentContextData$1 | Promise<AgentContextData$1>;
|
|
3751
|
+
getConfig({
|
|
3752
|
+
sessionId,
|
|
3753
|
+
...payload
|
|
3754
|
+
}: SessionAgentPayload<EmptyPayload>): AgentConfigData$1 | Promise<AgentConfigData$1>;
|
|
3755
|
+
getPermission({
|
|
3756
|
+
sessionId,
|
|
3757
|
+
...payload
|
|
3758
|
+
}: SessionAgentPayload<EmptyPayload>): PermissionData$1 | Promise<PermissionData$1>;
|
|
3759
|
+
getPlan({
|
|
3760
|
+
sessionId,
|
|
3761
|
+
...payload
|
|
3762
|
+
}: SessionAgentPayload<EmptyPayload>): PlanData$1 | Promise<PlanData$1>;
|
|
3763
|
+
getUsage({
|
|
3764
|
+
sessionId,
|
|
3765
|
+
...payload
|
|
3766
|
+
}: SessionAgentPayload<EmptyPayload>): UsageStatus$1 | Promise<UsageStatus$1>;
|
|
3767
|
+
getTools({
|
|
3768
|
+
sessionId,
|
|
3769
|
+
...payload
|
|
3770
|
+
}: SessionAgentPayload<EmptyPayload>): readonly ToolInfo$1[] | Promise<readonly ToolInfo$1[]>;
|
|
3771
|
+
getBackground({
|
|
3772
|
+
sessionId,
|
|
3773
|
+
...payload
|
|
3774
|
+
}: SessionAgentPayload<GetBackgroundPayload>): readonly BackgroundTaskInfo$1[] | Promise<readonly BackgroundTaskInfo$1[]>;
|
|
3775
|
+
updateSessionMetadata({
|
|
3776
|
+
sessionId,
|
|
3777
|
+
...payload
|
|
3778
|
+
}: UpdateSessionMetadataRequest): Promise<void>;
|
|
3779
|
+
getSessionMetadata({
|
|
3780
|
+
sessionId,
|
|
3781
|
+
...payload
|
|
3782
|
+
}: SessionScopedPayload<EmptyPayload>): SessionMeta$1;
|
|
3783
|
+
listSkills({
|
|
3784
|
+
sessionId,
|
|
3785
|
+
...payload
|
|
3786
|
+
}: SessionScopedPayload<EmptyPayload>): Promise<readonly SkillSummary[]>;
|
|
3787
|
+
listMcpServers({
|
|
3788
|
+
sessionId,
|
|
3789
|
+
...payload
|
|
3790
|
+
}: SessionScopedPayload<EmptyPayload>): readonly McpServerInfo[];
|
|
3791
|
+
getMcpStartupMetrics({
|
|
3792
|
+
sessionId,
|
|
3793
|
+
...payload
|
|
3794
|
+
}: SessionScopedPayload<EmptyPayload>): Promise<McpStartupMetrics>;
|
|
3795
|
+
reconnectMcpServer({
|
|
3796
|
+
sessionId,
|
|
3797
|
+
...payload
|
|
3798
|
+
}: SessionScopedPayload<ReconnectMcpServerPayload>): Promise<void>;
|
|
3799
|
+
generateAgentsMd({
|
|
3800
|
+
sessionId,
|
|
3801
|
+
...payload
|
|
3802
|
+
}: SessionScopedPayload<EmptyPayload>): Promise<void>;
|
|
3803
|
+
shellExec({
|
|
3804
|
+
sessionId,
|
|
3805
|
+
...payload
|
|
3806
|
+
}: SessionScopedPayload<Omit<ShellExecPayload, 'sessionId'>>): Promise<ShellExecResult>;
|
|
3807
|
+
private resolveRuntime;
|
|
3808
|
+
private resolveSessionSkillConfig;
|
|
3809
|
+
private sessionApi;
|
|
3810
|
+
private reloadProviderManager;
|
|
3811
|
+
private refreshSessionRuntimeConfig;
|
|
3812
|
+
}
|
|
3813
|
+
//#endregion
|
|
3814
|
+
//#region src/agent/turn/index.d.ts
|
|
3815
|
+
interface TurnEndResult {
|
|
3816
|
+
readonly event: TurnEndedEvent;
|
|
3817
|
+
readonly stopReason?: LoopTurnStopReason;
|
|
3818
|
+
}
|
|
3819
|
+
declare class TurnFlow {
|
|
3820
|
+
protected readonly agent: Agent;
|
|
3821
|
+
private steerBuffer;
|
|
3822
|
+
private turnId;
|
|
3823
|
+
private activeTurn;
|
|
3824
|
+
private readonly toolCallStartedAt;
|
|
3825
|
+
private readonly toolCallDupType;
|
|
3826
|
+
private readonly stepToolCallKeys;
|
|
3827
|
+
private readonly telemetryModeByTurn;
|
|
3828
|
+
private readonly currentStepByTurn;
|
|
3829
|
+
private readonly interruptedTelemetryTurnIds;
|
|
3830
|
+
private readonly stepFailureByTurn;
|
|
3831
|
+
private currentStep;
|
|
3832
|
+
constructor(agent: Agent);
|
|
3833
|
+
prompt(input: readonly ContentPart[], origin?: PromptOrigin): number | null;
|
|
3834
|
+
steer(input: readonly ContentPart[], origin?: PromptOrigin): number | null;
|
|
3835
|
+
private launch;
|
|
3836
|
+
restorePrompt(): void;
|
|
3837
|
+
restoreSteer(input: readonly ContentPart[], origin: PromptOrigin): void;
|
|
3838
|
+
cancel(turnId?: number): void;
|
|
3839
|
+
get currentId(): number;
|
|
3840
|
+
get hasActiveTurn(): boolean;
|
|
3841
|
+
waitForCurrentTurn(signal?: AbortSignal | undefined): Promise<TurnEndResult>;
|
|
3842
|
+
private abortTurn;
|
|
3843
|
+
private flushSteerBuffer;
|
|
3844
|
+
finishResume(): void;
|
|
3845
|
+
private turnWorker;
|
|
3846
|
+
private applyUserPromptHook;
|
|
3847
|
+
private runTurn;
|
|
3848
|
+
private buildDispatchEvent;
|
|
3849
|
+
private trackLoopTelemetry;
|
|
3850
|
+
private beginTrackedStep;
|
|
3851
|
+
private trackToolLifecycle;
|
|
3852
|
+
private trackDuplicateToolCall;
|
|
3853
|
+
private hasPriorStepToolCallKey;
|
|
3854
|
+
private trackTurnInterrupted;
|
|
3855
|
+
private telemetryMode;
|
|
3856
|
+
private shouldTrackApiError;
|
|
3857
|
+
}
|
|
3858
|
+
//#endregion
|
|
3859
|
+
//#region src/agent/index.d.ts
|
|
3860
|
+
type AgentType$1 = 'main' | 'sub' | 'independent';
|
|
3861
|
+
interface AgentConfig {
|
|
3862
|
+
readonly runtime: RuntimeConfig;
|
|
3863
|
+
readonly homedir?: string;
|
|
3864
|
+
readonly skills?: SkillRegistry;
|
|
3865
|
+
readonly rpc: SDKAgentRPC;
|
|
3866
|
+
readonly persistence?: AgentRecordPersistence;
|
|
3867
|
+
readonly type?: AgentType$1;
|
|
3868
|
+
readonly generate?: typeof generate;
|
|
3869
|
+
readonly compactionStrategy?: CompactionStrategy;
|
|
3870
|
+
readonly providerManager?: ProviderManager | undefined;
|
|
3871
|
+
readonly sessionId?: string;
|
|
3872
|
+
readonly subagentHost?: SessionSubagentHost | undefined;
|
|
3873
|
+
readonly mcp?: McpConnectionManager;
|
|
3874
|
+
readonly hookEngine?: HookEngine;
|
|
3875
|
+
readonly backgroundMaxRunningTasks?: number;
|
|
3876
|
+
readonly backgroundSessionDir?: string;
|
|
3877
|
+
readonly permission?: PermissionManagerOptions | undefined;
|
|
3878
|
+
/** Parent logger; the agent appends its own ctx (agentId already bound by session). */
|
|
3879
|
+
readonly log?: Logger;
|
|
3880
|
+
readonly telemetry?: TelemetryClient | undefined;
|
|
3881
|
+
}
|
|
3882
|
+
declare class Agent {
|
|
3883
|
+
readonly runtime: RuntimeConfig;
|
|
3884
|
+
readonly homedir?: string;
|
|
3885
|
+
readonly skills?: SkillManager;
|
|
3886
|
+
readonly rawGenerate: typeof generate;
|
|
3887
|
+
readonly rpc: SDKAgentRPC;
|
|
3888
|
+
readonly telemetry: TelemetryClient;
|
|
3889
|
+
readonly providerManager: ProviderManager | undefined;
|
|
3890
|
+
readonly subagentHost: SessionSubagentHost | undefined;
|
|
3891
|
+
readonly mcp: McpConnectionManager | undefined;
|
|
3892
|
+
readonly hooks: HookEngine | undefined;
|
|
3893
|
+
readonly type: AgentType$1;
|
|
3894
|
+
readonly records: AgentRecords;
|
|
3895
|
+
readonly fullCompaction: FullCompaction;
|
|
3896
|
+
readonly context: ContextMemory;
|
|
3897
|
+
readonly config: ConfigState;
|
|
3898
|
+
readonly turn: TurnFlow;
|
|
3899
|
+
readonly injection: InjectionManager;
|
|
3900
|
+
readonly permission: PermissionManager;
|
|
3901
|
+
readonly planMode: PlanMode;
|
|
3902
|
+
readonly usage: UsageRecorder;
|
|
3903
|
+
readonly tools: ToolManager;
|
|
3904
|
+
readonly background: BackgroundManager;
|
|
3905
|
+
readonly replayBuilder: ReplayBuilder;
|
|
3906
|
+
readonly log: Logger;
|
|
3907
|
+
private lastLlmConfigLogSignature?;
|
|
3908
|
+
constructor(config: AgentConfig);
|
|
3909
|
+
get generate(): typeof generate;
|
|
3910
|
+
private logLlmRequest;
|
|
3911
|
+
private logLlmConfigIfChanged;
|
|
3912
|
+
useProfile(profile: ResolvedAgentProfile, context?: PreparedSystemPromptContext): void;
|
|
3913
|
+
resume(): Promise<{
|
|
3914
|
+
warning?: string;
|
|
3915
|
+
}>;
|
|
3916
|
+
get rpcMethods(): PromisableMethods<AgentAPI>;
|
|
3917
|
+
emitEvent(event: AgentEvent): void;
|
|
3918
|
+
emitStatusUpdated(): void;
|
|
3919
|
+
private emitRecordsWriteError;
|
|
3920
|
+
}
|
|
3921
|
+
//#endregion
|
|
3922
|
+
//#region src/session/export/wire-scan.d.ts
|
|
3923
|
+
interface SessionWireScan {
|
|
3924
|
+
readonly firstActivityMs?: number | undefined;
|
|
3925
|
+
readonly lastActivityMs?: number | undefined;
|
|
3926
|
+
readonly lastUserMessageMs?: number | undefined;
|
|
3927
|
+
readonly firstUserInput?: string | undefined;
|
|
3928
|
+
}
|
|
3929
|
+
declare function scanSessionWire(sessionDir: string): Promise<SessionWireScan>;
|
|
3930
|
+
declare function normalizeTimestampMs(value: number): number | undefined;
|
|
3931
|
+
//#endregion
|
|
3932
|
+
//#region src/session/export/manifest.d.ts
|
|
3933
|
+
declare const WIRE_PROTOCOL_VERSION = "1.1";
|
|
3934
|
+
declare function buildExportManifest(args: {
|
|
3935
|
+
readonly summary: SessionSummary;
|
|
3936
|
+
readonly now: Date;
|
|
3937
|
+
readonly version: string;
|
|
3938
|
+
readonly wireProtocolVersion?: string | undefined;
|
|
3939
|
+
readonly sessionScan: SessionWireScan;
|
|
3940
|
+
readonly sessionLogPath?: string | undefined;
|
|
3941
|
+
readonly globalLogPath?: string | undefined;
|
|
3942
|
+
}): ExportSessionManifest;
|
|
3943
|
+
//#endregion
|
|
3944
|
+
//#region src/session/export/session-export.d.ts
|
|
3945
|
+
declare function exportSessionDirectory(input: {
|
|
3946
|
+
readonly request: ExportSessionPayload;
|
|
3947
|
+
readonly summary: SessionSummary;
|
|
3948
|
+
readonly homeDir?: string | undefined;
|
|
3949
|
+
readonly globalLogPath?: string | undefined;
|
|
3950
|
+
}): Promise<ExportSessionResult>;
|
|
3951
|
+
//#endregion
|
|
3952
|
+
//#region src/session/export/zip.d.ts
|
|
3953
|
+
declare function collectFilesRecursive(root: string): Promise<string[]>;
|
|
3954
|
+
type ExtraZipEntry = {
|
|
3955
|
+
/** Absolute path on disk. */readonly source: string; /** zip-relative target path. */
|
|
3956
|
+
readonly target: string;
|
|
3957
|
+
} | {
|
|
3958
|
+
readonly data: Buffer; /** zip-relative target path. */
|
|
3959
|
+
readonly target: string;
|
|
3960
|
+
};
|
|
3961
|
+
declare function writeExportZip(args: {
|
|
3962
|
+
readonly outputPath: string;
|
|
3963
|
+
readonly manifest: ExportSessionManifest;
|
|
3964
|
+
readonly sessionDir: string;
|
|
3965
|
+
readonly sessionFiles: readonly string[];
|
|
3966
|
+
readonly extraEntries?: readonly ExtraZipEntry[];
|
|
3967
|
+
}): Promise<readonly string[]>;
|
|
3968
|
+
//#endregion
|
|
3969
|
+
//#region src/logging/resolve-config.d.ts
|
|
3970
|
+
interface ResolveLoggingInput {
|
|
3971
|
+
readonly homeDir: string;
|
|
3972
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
3973
|
+
}
|
|
3974
|
+
/**
|
|
3975
|
+
* Build the runtime `LoggingConfig` from env vars + defaults.
|
|
3976
|
+
*
|
|
3977
|
+
* v1 deliberately does not read `config.toml [logging]` — the schema is in
|
|
3978
|
+
* flux and reading it adds a startup-time failure surface. Users who need to
|
|
3979
|
+
* override the defaults set env vars:
|
|
3980
|
+
*
|
|
3981
|
+
* BYF_LOG_LEVEL=debug
|
|
3982
|
+
* BYF_LOG_GLOBAL_MAX_BYTES=... BYF_LOG_GLOBAL_FILES=...
|
|
3983
|
+
* BYF_LOG_SESSION_MAX_BYTES=... BYF_LOG_SESSION_FILES=...
|
|
3984
|
+
*/
|
|
3985
|
+
declare function resolveLoggingConfig(input: ResolveLoggingInput): LoggingConfig;
|
|
3986
|
+
//#endregion
|
|
3987
|
+
export { CreateSessionPayload as $, SessionConfig as $n, resolveByfHome as $r, CompactionCancelledEvent as $t, QuestionItem as A, ProviderType as Ai, WarningEvent as An, LoopStepEndEvent as Ar, SetThinkingPayload as At, SDKSessionRPC$1 as B, LogEntry as Bi, ByfErrorInfo as Bn, BackgroundTaskStatus as Br, WithAgentId as Bt, createRPC as C, PermissionConfigSchema as Ci, TurnEndedEvent as Cn, ToolInfo$1 as Cr, SessionMetadataPatch as Ct, ApprovalScope as D, PermissionRuleScopeSchema as Di, TurnStepRetryingEvent as Dn, LoopContentPartEvent as Dr, SetModelPayload as Dt, ApprovalResponse as E, PermissionRuleSchema as Ei, TurnStepInterruptedEvent as En, ToolStoreUpdate as Er, SetByfConfigPayload as Et, SDKAPI as F, ThinkingConfigSchema as Fi, toByfErrorPayload as Fn, ExecutableToolSuccessResult as Fr, StopBackgroundPayload as Ft, BeginCompactionPayload as G, RootLogger as Gi, AgentRecordPersistence as Gn, parseConfigString as Gr, ResumedAgentState as Gt, ToolCallResponse as H, LogPayload as Hi, AgentRecord as Hn, OAuthTokenProviderResolver as Hr, proxyWithExtraPayload as Ht, SDKAgentAPI as I, formatConfigValidationError as Ii, ByfError as In, ToolInputDisplay as Ir, TextPromptPart as It, CancelPayload as J, RuntimeConfig as Jn, writeConfigFile as Jr, AssistantDeltaEvent as Jt, ByfConfig as K, SessionAttachInput as Ki, UsageRecordScope as Kn, readConfigFile as Kr, AgentEvent$1 as Kt, SDKAgentRPC$1 as L, getDefaultConfig as Li, ByfErrorOptions as Ln, BackgroundLifecycleEvent as Lr, UnregisterToolPayload as Lt, QuestionRequest as M, ServicesConfig as Mi, fromByfErrorPayload as Mn, LoopToolResultEvent as Mr, ShellExecResult as Mt, QuestionResponse as N, ServicesConfigSchema as Ni, isByfError as Nn, ExecutableToolErrorResult as Nr, SkillSummary as Nt, QuestionAnswerMethod as O, ProviderConfig$1 as Oi, TurnStepStartedEvent as On, LoopRecordedEvent as Or, SetModelResult as Ot, QuestionResult as P, ThinkingConfig as Pi, makeErrorPayload as Pn, ExecutableToolResult as Pr, SteerPayload as Pt, CoreInfo as Q, Session as Qn, ensureByfHome as Qr, CompactionBlockedEvent as Qt, SDKRPC as R, validateConfig as Ri, BYF_ERROR_INFO as Rn, BackgroundTaskInfo$1 as Rr, Unsubscribe as Rt, SDKRPCClient as S, PermissionConfig as Si, TurnEndReason as Sn, BuiltinTool as Sr, SessionAPI as St, ApprovalRequest as T, PermissionRuleDecisionSchema as Ti, TurnStepCompletedEvent as Tn, UserToolRegistration as Tr, SetActiveToolsPayload as Tt, ActivateSkillPayload$1 as U, Logger as Ui, AgentRecordEvents as Un, configToTomlData as Ur, AgentReplayRecord as Ut, ToolCallRequest as V, LogLevel as Vi, ErrorCodes as Vn, BearerTokenProvider as Vr, WithSessionId as Vt, AgentAPI$1 as W, LoggingConfig as Wi, AgentRecordOf as Wn, ensureConfigFile as Wr, ResumeSessionResult as Wt, CloseSessionPayload as X, SubagentHandle as Xn, parseBooleanEnv as Xr, BackgroundTaskTerminatedEvent as Xt, CancelPlanPayload as Y, SessionSubagentHost as Yn, ResolveConfigValueInput as Yr, BackgroundTaskStartedEvent as Yt, CoreAPI as Z, AgentMeta as Zn, resolveConfigValue as Zr, BackgroundTaskUpdatedEvent as Zt, CoreRPC as _, McpServerStdioConfigSchema as _i, ToolListUpdatedEvent as _n, flushDiagnosticLogs as _r, ReconnectMcpServerPayload as _t, writeExportZip as a, ByfConfigSchema as ai, MCP_OAUTH_AUTHORIZATION_URL_TOOL_UPDATE as an, TelemetryPropertyValue as ar, GetBackgroundOutputPathPayload as at, RPCClient as b, OAuthRef$1 as bi, ToolResultEvent as bn, redact as br, RenameSessionPayload as bt, buildExportManifest as c, HookDefConfig as ci, McpServerStatusPayload as cn, PermissionApprovalResultRecord$1 as cr, JsonObject as ct, scanSessionWire as d, LoopControlSchema as di, SubagentCompletedEvent as dn, ContextMessage$1 as dr, ListSessionsPayload as dt, resolveConfigPath as ei, CompactionCompletedEvent as en, SessionMeta$1 as er, EmptyPayload as et, Agent as f, McpServerConfig as fi, SubagentFailedEvent as fn, PromptOrigin as fr, McpServerInfo as ft, ByfCoreOptions as g, McpServerStdioConfig as gi, ToolCallStartedEvent as gn, CompactionResult$1 as gr, PromptPayload as gt, ByfCore as h, McpServerHttpConfigSchema as hi, ToolCallDeltaEvent as hn, CompactionBeginData as hr, PromptPart as ht, collectFilesRecursive as i, ByfConfigPatchSchema as ii, HookResultEvent as in, TelemetryProperties as ir, ForkSessionPayload as it, QuestionOption as j, ProviderTypeSchema as ji, ByfErrorPayload as jn, LoopToolCallEvent as jr, ShellExecPayload as jt, QuestionAnswers as k, ProviderConfigSchema as ki, UsageStatus$1 as kn, LoopStepBeginEvent as kr, SetPermissionPayload as kt, SessionWireScan as l, HookDefSchema as li, SessionMetaUpdatedEvent as ln, PermissionMode$1 as lr, JsonPrimitive as lt, AgentType$1 as m, McpServerHttpConfig as mi, ThinkingDeltaEvent as mn, UserPromptOrigin as mr, PromptInput as mt, resolveLoggingConfig as n, BackgroundConfig as ni, ErrorEvent as nn, TelemetryClient as nr, ExportSessionPayload as nt, exportSessionDirectory as o, ByfServiceConfig as oi, McpOAuthAuthorizationUrlUpdateData as on, noopTelemetryClient as or, GetBackgroundOutputPayload as ot, AgentConfig as p, McpServerConfigSchema as pi, SubagentSpawnedEvent as pn, USER_PROMPT_ORIGIN as pr, McpStartupMetrics as pt, ByfConfigPatch as q, SessionLogHandle as qi, AgentConfigUpdateData$1 as qn, transformTomlData as qr, AgentStatusUpdatedEvent as qt, ExtraZipEntry as r, BackgroundConfigSchema as ri, Event as rn, TelemetryContextPatch as rr, ExportSessionResult as rt, WIRE_PROTOCOL_VERSION as s, ByfServiceConfigSchema as si, McpServerStatusEvent as sn, withTelemetryContext as sr, GetBackgroundPayload as st, ResolveLoggingInput as t, mergeConfigPatch as ti, CompactionStartedEvent as tn, SessionSkillConfig as tr, ExportSessionManifest as tt, normalizeTimestampMs as u, LoopControl as ui, SkillActivatedEvent as un, AgentContextData$1 as ur, JsonValue as ut, CoreRPCClient as v, ModelAlias as vi, ToolListUpdatedReason as vn, getRootLogger as vr, RegisterToolPayload as vt, ApprovalDecision as w, PermissionModeSchema as wi, TurnStartedEvent as wn, ToolSource as wr, SessionSummary as wt, RPCMethods as x, OAuthRefSchema as xi, ToolUpdate as xn, resolveGlobalLogPath as xr, ResumeSessionPayload as xt, RPCCallOptions as y, ModelAliasSchema as yi, ToolProgressEvent as yn, log as yr, RemoveByfProviderPayload as yt, SDKSessionAPI as z, LogContext as zi, ByfErrorCode as zn, BackgroundTaskKind as zr, UpdateSessionMetadataPayload as zt };
|