@byfriends/agent-core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-BUBoyyCX.d.mts → index-CSFujlN1.d.mts} +540 -412
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1238 -1327
- package/dist/session/store/index.d.mts +1 -1
- package/dist/session/store/index.mjs +1 -1
- package/dist/{store-DhTph1cB.mjs → store-7tEWsiOk.mjs} +0 -7
- package/package.json +3 -3
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { ChatProvider, ContentPart, FinishReason, Message, ModelCapability, ProviderConfig, ProviderRequestAuth, TextPart, ThinkPart, ThinkingEffort, TokenUsage, Tool, ToolCall, ToolCall as ToolCall$1, generate } from "@byfriends/kosong";
|
|
1
|
+
import { CacheHitRate, ChatProvider, ContentPart, FinishReason, Message, ModelCapability, PromptPlan, ProviderCacheCapability, ProviderConfig, ProviderRequestAuth, TextPart, ThinkPart, ThinkingEffort, TokenUsage, Tool, ToolCall, ToolCall as ToolCall$1, generate } from "@byfriends/kosong";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
4
4
|
import { Kaos, KaosProcess } from "@byfriends/kaos";
|
|
5
5
|
import { ActivateSkillPayload, AgentAPI, AgentEvent, SDKAgentRPC, SDKSessionRPC, UsageStatus } from "#/rpc";
|
|
6
6
|
import { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
7
7
|
import { ByfConfig, ByfConfigPatch, OAuthRef } from "#/config";
|
|
8
|
-
import { AgentType } from "#/agent";
|
|
9
8
|
import { AgentConfigData, AgentConfigUpdateData } from "#/agent/config";
|
|
10
9
|
import { AgentContextData, ContextMessage } from "#/agent/context";
|
|
11
10
|
import { PermissionApprovalResultRecord, PermissionData, PermissionMode } from "#/agent/permission";
|
|
12
|
-
import { PlanData } from "#/agent/plan";
|
|
13
11
|
import { ToolInfo } from "#/agent/tool";
|
|
12
|
+
import { AgentType } from "#/agent";
|
|
14
13
|
import { SessionMeta } from "#/session";
|
|
15
14
|
import { BackgroundTaskInfo } from "#/tools/builtin";
|
|
16
15
|
|
|
@@ -93,8 +92,7 @@ interface RootLogger {
|
|
|
93
92
|
//#region src/config/schema.d.ts
|
|
94
93
|
declare const ProviderTypeSchema: z.ZodEnum<{
|
|
95
94
|
anthropic: "anthropic";
|
|
96
|
-
openai: "openai";
|
|
97
|
-
"openai-compat": "openai-compat";
|
|
95
|
+
"openai-completions": "openai-completions";
|
|
98
96
|
"google-genai": "google-genai";
|
|
99
97
|
openai_responses: "openai_responses";
|
|
100
98
|
vertexai: "vertexai";
|
|
@@ -111,8 +109,7 @@ type OAuthRef$1 = z.infer<typeof OAuthRefSchema>;
|
|
|
111
109
|
declare const ProviderConfigSchema: z.ZodObject<{
|
|
112
110
|
type: z.ZodEnum<{
|
|
113
111
|
anthropic: "anthropic";
|
|
114
|
-
openai: "openai";
|
|
115
|
-
"openai-compat": "openai-compat";
|
|
112
|
+
"openai-completions": "openai-completions";
|
|
116
113
|
"google-genai": "google-genai";
|
|
117
114
|
openai_responses: "openai_responses";
|
|
118
115
|
vertexai: "vertexai";
|
|
@@ -148,7 +145,13 @@ declare const ThinkingConfigSchema: z.ZodObject<{
|
|
|
148
145
|
auto: "auto";
|
|
149
146
|
on: "on";
|
|
150
147
|
}>>;
|
|
151
|
-
effort: z.ZodOptional<z.
|
|
148
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
149
|
+
low: "low";
|
|
150
|
+
medium: "medium";
|
|
151
|
+
high: "high";
|
|
152
|
+
xhigh: "xhigh";
|
|
153
|
+
max: "max";
|
|
154
|
+
}>>;
|
|
152
155
|
}, z.core.$strip>;
|
|
153
156
|
type ThinkingConfig = z.infer<typeof ThinkingConfigSchema>;
|
|
154
157
|
declare const PermissionModeSchema: z.ZodEnum<{
|
|
@@ -337,8 +340,7 @@ declare const ByfConfigSchema: z.ZodObject<{
|
|
|
337
340
|
providers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
338
341
|
type: z.ZodEnum<{
|
|
339
342
|
anthropic: "anthropic";
|
|
340
|
-
openai: "openai";
|
|
341
|
-
"openai-compat": "openai-compat";
|
|
343
|
+
"openai-completions": "openai-completions";
|
|
342
344
|
"google-genai": "google-genai";
|
|
343
345
|
openai_responses: "openai_responses";
|
|
344
346
|
vertexai: "vertexai";
|
|
@@ -374,9 +376,14 @@ declare const ByfConfigSchema: z.ZodObject<{
|
|
|
374
376
|
auto: "auto";
|
|
375
377
|
on: "on";
|
|
376
378
|
}>>;
|
|
377
|
-
effort: z.ZodOptional<z.
|
|
379
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
380
|
+
low: "low";
|
|
381
|
+
medium: "medium";
|
|
382
|
+
high: "high";
|
|
383
|
+
xhigh: "xhigh";
|
|
384
|
+
max: "max";
|
|
385
|
+
}>>;
|
|
378
386
|
}, z.core.$strip>>;
|
|
379
|
-
planMode: z.ZodOptional<z.ZodBoolean>;
|
|
380
387
|
yolo: z.ZodOptional<z.ZodBoolean>;
|
|
381
388
|
defaultThinking: z.ZodOptional<z.ZodBoolean>;
|
|
382
389
|
defaultPermissionMode: z.ZodOptional<z.ZodEnum<{
|
|
@@ -384,7 +391,6 @@ declare const ByfConfigSchema: z.ZodObject<{
|
|
|
384
391
|
yolo: "yolo";
|
|
385
392
|
manual: "manual";
|
|
386
393
|
}>>;
|
|
387
|
-
defaultPlanMode: z.ZodOptional<z.ZodBoolean>;
|
|
388
394
|
permission: z.ZodOptional<z.ZodObject<{
|
|
389
395
|
rules: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
390
396
|
decision: z.ZodEnum<{
|
|
@@ -464,7 +470,6 @@ declare const ByfConfigSchema: z.ZodObject<{
|
|
|
464
470
|
agentTaskTimeoutS: z.ZodOptional<z.ZodNumber>;
|
|
465
471
|
printWaitCeilingS: z.ZodOptional<z.ZodNumber>;
|
|
466
472
|
}, z.core.$strip>>;
|
|
467
|
-
telemetry: z.ZodOptional<z.ZodBoolean>;
|
|
468
473
|
raw: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
469
474
|
}, z.core.$strip>;
|
|
470
475
|
type ByfConfig$1 = z.infer<typeof ByfConfigSchema>;
|
|
@@ -472,8 +477,7 @@ declare const ByfConfigPatchSchema: z.ZodObject<{
|
|
|
472
477
|
providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
473
478
|
type: z.ZodOptional<z.ZodEnum<{
|
|
474
479
|
anthropic: "anthropic";
|
|
475
|
-
openai: "openai";
|
|
476
|
-
"openai-compat": "openai-compat";
|
|
480
|
+
"openai-completions": "openai-completions";
|
|
477
481
|
"google-genai": "google-genai";
|
|
478
482
|
openai_responses: "openai_responses";
|
|
479
483
|
vertexai: "vertexai";
|
|
@@ -509,9 +513,14 @@ declare const ByfConfigPatchSchema: z.ZodObject<{
|
|
|
509
513
|
auto: "auto";
|
|
510
514
|
on: "on";
|
|
511
515
|
}>>>;
|
|
512
|
-
effort: z.ZodOptional<z.ZodOptional<z.
|
|
516
|
+
effort: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
517
|
+
low: "low";
|
|
518
|
+
medium: "medium";
|
|
519
|
+
high: "high";
|
|
520
|
+
xhigh: "xhigh";
|
|
521
|
+
max: "max";
|
|
522
|
+
}>>>;
|
|
513
523
|
}, z.core.$strip>>;
|
|
514
|
-
planMode: z.ZodOptional<z.ZodBoolean>;
|
|
515
524
|
yolo: z.ZodOptional<z.ZodBoolean>;
|
|
516
525
|
defaultThinking: z.ZodOptional<z.ZodBoolean>;
|
|
517
526
|
defaultPermissionMode: z.ZodOptional<z.ZodEnum<{
|
|
@@ -519,7 +528,6 @@ declare const ByfConfigPatchSchema: z.ZodObject<{
|
|
|
519
528
|
yolo: "yolo";
|
|
520
529
|
manual: "manual";
|
|
521
530
|
}>>;
|
|
522
|
-
defaultPlanMode: z.ZodOptional<z.ZodBoolean>;
|
|
523
531
|
permission: z.ZodOptional<z.ZodObject<{
|
|
524
532
|
rules: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
525
533
|
decision: z.ZodEnum<{
|
|
@@ -599,7 +607,6 @@ declare const ByfConfigPatchSchema: z.ZodObject<{
|
|
|
599
607
|
agentTaskTimeoutS: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
600
608
|
printWaitCeilingS: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
601
609
|
}, z.core.$strip>>;
|
|
602
|
-
telemetry: z.ZodOptional<z.ZodBoolean>;
|
|
603
610
|
}, z.core.$strict>;
|
|
604
611
|
type ByfConfigPatch$1 = z.infer<typeof ByfConfigPatchSchema>;
|
|
605
612
|
declare function getDefaultConfig(): ByfConfig$1;
|
|
@@ -1011,8 +1018,6 @@ interface Environment {
|
|
|
1011
1018
|
interface SystemPromptContext {
|
|
1012
1019
|
readonly osEnv: Environment;
|
|
1013
1020
|
readonly cwd: string;
|
|
1014
|
-
readonly now?: string | Date;
|
|
1015
|
-
readonly cwdListing?: string;
|
|
1016
1021
|
readonly agentsMd?: string;
|
|
1017
1022
|
readonly skills?: SkillRegistry | string;
|
|
1018
1023
|
readonly additionalDirsInfo?: string;
|
|
@@ -1029,7 +1034,7 @@ interface ResolvedAgentProfile {
|
|
|
1029
1034
|
}
|
|
1030
1035
|
//#endregion
|
|
1031
1036
|
//#region src/profile/context.d.ts
|
|
1032
|
-
type PreparedSystemPromptContext = Pick<SystemPromptContext, 'cwd' | '
|
|
1037
|
+
type PreparedSystemPromptContext = Pick<SystemPromptContext, 'cwd' | 'agentsMd'>;
|
|
1033
1038
|
//#endregion
|
|
1034
1039
|
//#region src/config/merge.d.ts
|
|
1035
1040
|
declare function mergeConfigPatch(config: ByfConfig$1, patch: ByfConfigPatch$1): ByfConfig$1;
|
|
@@ -1584,6 +1589,8 @@ interface LLMChatResponse {
|
|
|
1584
1589
|
providerFinishReason?: FinishReason | undefined;
|
|
1585
1590
|
rawFinishReason?: string | undefined;
|
|
1586
1591
|
usage: TokenUsage;
|
|
1592
|
+
llmFirstTokenLatencyMs?: number | undefined;
|
|
1593
|
+
llmStreamDurationMs?: number | undefined;
|
|
1587
1594
|
}
|
|
1588
1595
|
interface LLM {
|
|
1589
1596
|
readonly systemPrompt: string;
|
|
@@ -1636,6 +1643,12 @@ interface ExecutableToolErrorResult {
|
|
|
1636
1643
|
* allowed after this tool batch.
|
|
1637
1644
|
*/
|
|
1638
1645
|
readonly stopTurn?: boolean | undefined;
|
|
1646
|
+
/**
|
|
1647
|
+
* Set when the tool was not executed because the approval request was
|
|
1648
|
+
* rejected or cancelled by the user. Distinguishes "blocked by user" from
|
|
1649
|
+
* "tool ran but failed".
|
|
1650
|
+
*/
|
|
1651
|
+
readonly blockedReason?: 'rejected' | 'cancelled' | undefined;
|
|
1639
1652
|
}
|
|
1640
1653
|
type ExecutableToolResult = ExecutableToolSuccessResult | ExecutableToolErrorResult;
|
|
1641
1654
|
interface ToolUpdate$1 {
|
|
@@ -1689,6 +1702,7 @@ interface PrepareToolExecutionResult {
|
|
|
1689
1702
|
readonly updatedArgs?: unknown;
|
|
1690
1703
|
readonly syntheticResult?: ExecutableToolResult | undefined;
|
|
1691
1704
|
readonly executionMetadata?: unknown;
|
|
1705
|
+
readonly blockedReason?: 'rejected' | 'cancelled' | undefined;
|
|
1692
1706
|
}
|
|
1693
1707
|
//#endregion
|
|
1694
1708
|
//#region src/loop/events.d.ts
|
|
@@ -1711,6 +1725,8 @@ interface LoopStepEndEvent {
|
|
|
1711
1725
|
*/
|
|
1712
1726
|
readonly providerFinishReason?: FinishReason | undefined;
|
|
1713
1727
|
readonly rawFinishReason?: string | undefined;
|
|
1728
|
+
readonly llmFirstTokenLatencyMs?: number | undefined;
|
|
1729
|
+
readonly llmStreamDurationMs?: number | undefined;
|
|
1714
1730
|
}
|
|
1715
1731
|
interface LoopContentPartEvent {
|
|
1716
1732
|
readonly type: 'content.part';
|
|
@@ -1752,97 +1768,195 @@ interface ToolStoreUpdate<K extends ToolStoreKey = ToolStoreKey> {
|
|
|
1752
1768
|
readonly value: ToolStoreData[K];
|
|
1753
1769
|
}
|
|
1754
1770
|
//#endregion
|
|
1755
|
-
//#region src/agent/
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
readonly name: string;
|
|
1760
|
-
readonly description: string;
|
|
1761
|
-
readonly parameters: Record<string, unknown>;
|
|
1771
|
+
//#region src/agent/context/types.d.ts
|
|
1772
|
+
interface UserPromptOrigin {
|
|
1773
|
+
readonly kind: 'user';
|
|
1774
|
+
readonly blockedByHook?: string | undefined;
|
|
1762
1775
|
}
|
|
1763
|
-
|
|
1776
|
+
declare const USER_PROMPT_ORIGIN: UserPromptOrigin;
|
|
1777
|
+
interface SkillActivationOrigin {
|
|
1778
|
+
readonly kind: 'skill_activation';
|
|
1779
|
+
readonly activationId: string;
|
|
1780
|
+
readonly skillName: string;
|
|
1781
|
+
readonly skillArgs?: string | undefined;
|
|
1782
|
+
readonly trigger: 'user-slash' | 'model-tool' | 'nested-skill';
|
|
1783
|
+
readonly skillType?: string | undefined;
|
|
1784
|
+
readonly skillPath?: string | undefined;
|
|
1785
|
+
readonly skillSource?: SkillSource | undefined;
|
|
1786
|
+
}
|
|
1787
|
+
interface InjectionOrigin {
|
|
1788
|
+
readonly kind: 'injection';
|
|
1789
|
+
readonly variant: string;
|
|
1790
|
+
}
|
|
1791
|
+
interface CompactionSummaryOrigin {
|
|
1792
|
+
readonly kind: 'compaction_summary';
|
|
1793
|
+
}
|
|
1794
|
+
interface SystemTriggerOrigin {
|
|
1795
|
+
readonly kind: 'system_trigger';
|
|
1764
1796
|
readonly name: string;
|
|
1765
|
-
readonly description: string;
|
|
1766
|
-
readonly active: boolean;
|
|
1767
|
-
readonly source: ToolSource;
|
|
1768
1797
|
}
|
|
1769
|
-
interface
|
|
1770
|
-
readonly
|
|
1771
|
-
readonly
|
|
1772
|
-
readonly
|
|
1773
|
-
|
|
1774
|
-
readonly toolName: string;
|
|
1775
|
-
} | {
|
|
1776
|
-
readonly kind: 'other_server';
|
|
1777
|
-
readonly serverName: string;
|
|
1778
|
-
};
|
|
1798
|
+
interface BackgroundTaskOrigin {
|
|
1799
|
+
readonly kind: 'background_task';
|
|
1800
|
+
readonly taskId: string;
|
|
1801
|
+
readonly status: BackgroundTaskStatus;
|
|
1802
|
+
readonly notificationId: string;
|
|
1779
1803
|
}
|
|
1780
|
-
interface
|
|
1781
|
-
readonly
|
|
1782
|
-
readonly
|
|
1804
|
+
interface HookResultOrigin {
|
|
1805
|
+
readonly kind: 'hook_result';
|
|
1806
|
+
readonly event: string;
|
|
1807
|
+
readonly blocked?: boolean;
|
|
1783
1808
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
readonly
|
|
1788
|
-
|
|
1809
|
+
type PromptOrigin = UserPromptOrigin | SkillActivationOrigin | InjectionOrigin | CompactionSummaryOrigin | SystemTriggerOrigin | BackgroundTaskOrigin | HookResultOrigin;
|
|
1810
|
+
type ContextMessage$1 = Message & {
|
|
1811
|
+
readonly origin?: PromptOrigin | undefined;
|
|
1812
|
+
readonly isError?: boolean;
|
|
1813
|
+
};
|
|
1814
|
+
interface AgentContextData$1 {
|
|
1815
|
+
history: readonly ContextMessage$1[];
|
|
1816
|
+
tokenCount: number;
|
|
1789
1817
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
/**
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
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[];
|
|
1818
|
+
//#endregion
|
|
1819
|
+
//#region src/agent/context/observation-masking.d.ts
|
|
1820
|
+
interface MaskingConfig {
|
|
1821
|
+
/** Effective capacity ratio (default 0.6 = 60% of advertised capacity) */
|
|
1822
|
+
effectiveCapacityRatio: number;
|
|
1823
|
+
/** Low priority masking threshold (default 0.60) */
|
|
1824
|
+
lowPriorityThreshold: number;
|
|
1825
|
+
/** Medium priority masking threshold (default 0.80) */
|
|
1826
|
+
mediumPriorityThreshold: number;
|
|
1827
|
+
/** High priority threshold — unmaskable, goes straight to compaction */
|
|
1828
|
+
highPriorityThreshold: number;
|
|
1829
|
+
}
|
|
1830
|
+
interface MaskingResult {
|
|
1831
|
+
masked: boolean;
|
|
1832
|
+
maskedCount: number;
|
|
1833
|
+
tokensBefore: number;
|
|
1834
|
+
tokensAfter: number;
|
|
1822
1835
|
}
|
|
1823
1836
|
//#endregion
|
|
1824
|
-
//#region src/
|
|
1825
|
-
declare function getRootLogger(): RootLogger;
|
|
1826
|
-
declare function flushDiagnosticLogs(): Promise<boolean>;
|
|
1837
|
+
//#region src/agent/restore-handler.d.ts
|
|
1827
1838
|
/**
|
|
1828
|
-
*
|
|
1829
|
-
* session (CLI startup, harness construction, etc.):
|
|
1839
|
+
* 记录恢复处理器接口。
|
|
1830
1840
|
*
|
|
1831
|
-
*
|
|
1832
|
-
* log.info('byf starting', { version });
|
|
1841
|
+
* 实现此接口的子系统负责恢复特定类型的 AgentRecord。
|
|
1833
1842
|
*
|
|
1834
|
-
*
|
|
1843
|
+
* ## 契约
|
|
1835
1844
|
*
|
|
1836
|
-
*
|
|
1837
|
-
* agent.log.error('turn failed', { turnId, error });
|
|
1845
|
+
* 恢复操作必须遵循以下契约:
|
|
1838
1846
|
*
|
|
1839
|
-
*
|
|
1840
|
-
*
|
|
1841
|
-
*
|
|
1847
|
+
* - **同步操作**:恢复必须是同步的,不返回 Promise。
|
|
1848
|
+
* 恢复是重建内存状态的过程,不应涉及 I/O、网络或其他异步操作。
|
|
1849
|
+
*
|
|
1850
|
+
* - **无副作用**:恢复时不产生任何外部副作用:
|
|
1851
|
+
* - 不调用 `records.logRecord()`
|
|
1852
|
+
* - 不调用 `agent.emitEvent()`
|
|
1853
|
+
* - 不调用 LLM
|
|
1854
|
+
* - 不执行工具
|
|
1855
|
+
* - 不写入文件系统(除了恢复所需的内存操作)
|
|
1856
|
+
*
|
|
1857
|
+
* - **非幂等性**:恢复操作不需要保证幂等性。
|
|
1858
|
+
* 实现时假设每条记录只会被恢复一次。
|
|
1859
|
+
*
|
|
1860
|
+
* - **状态恢复**:恢复操作的目的是将子系统的内存状态
|
|
1861
|
+
* 恢复到记录日志时的状态。
|
|
1862
|
+
*
|
|
1863
|
+
* ## 使用
|
|
1864
|
+
*
|
|
1865
|
+
* 子系统实现此接口后,通过 `AgentRecords.registerHandlers()`
|
|
1866
|
+
* 注册,然后在恢复时被调用。
|
|
1842
1867
|
*/
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1868
|
+
interface RecordRestoreHandler {
|
|
1869
|
+
/**
|
|
1870
|
+
* 恢复一条记录到子系统状态。
|
|
1871
|
+
*
|
|
1872
|
+
* @param record - 要恢复的记录(已通过迁移处理)
|
|
1873
|
+
*
|
|
1874
|
+
* @remarks
|
|
1875
|
+
*
|
|
1876
|
+
* 此方法在 `AgentRecords.replay()` 过程中被调用。
|
|
1877
|
+
* 实现时应根据 `record.type` 分发到相应的恢复逻辑。
|
|
1878
|
+
*
|
|
1879
|
+
* 示例:
|
|
1880
|
+
*
|
|
1881
|
+
* ```typescript
|
|
1882
|
+
* class ContextMemory implements RecordRestoreHandler {
|
|
1883
|
+
* restoreRecord(record: AgentRecord): void {
|
|
1884
|
+
* switch (record.type) {
|
|
1885
|
+
* case 'context.append_message':
|
|
1886
|
+
* this.appendMessage(record.message);
|
|
1887
|
+
* break;
|
|
1888
|
+
* // ...
|
|
1889
|
+
* }
|
|
1890
|
+
* }
|
|
1891
|
+
* }
|
|
1892
|
+
* ```
|
|
1893
|
+
*/
|
|
1894
|
+
restoreRecord(record: AgentRecord): void;
|
|
1895
|
+
}
|
|
1896
|
+
//#endregion
|
|
1897
|
+
//#region src/agent/context/scratch-manager.d.ts
|
|
1898
|
+
interface ScratchManagerConfig {
|
|
1899
|
+
/** 每个 session 的最大 scratch 大小 (bytes),默认 50MB */
|
|
1900
|
+
maxSessionSize: number;
|
|
1901
|
+
/** 每个 session 的最大文件数,默认 100 */
|
|
1902
|
+
maxFileCount: number;
|
|
1903
|
+
/** scratch 目录 */
|
|
1904
|
+
scratchDir: string;
|
|
1905
|
+
}
|
|
1906
|
+
declare class ScratchManager {
|
|
1907
|
+
private readonly kaos;
|
|
1908
|
+
private readonly config;
|
|
1909
|
+
private currentSize;
|
|
1910
|
+
private files;
|
|
1911
|
+
constructor(kaos: Kaos, config: ScratchManagerConfig);
|
|
1912
|
+
writeOutput(toolCallId: string, output: string): Promise<string>;
|
|
1913
|
+
readOutput(filePath: string): Promise<string>;
|
|
1914
|
+
private evictIfNeeded;
|
|
1915
|
+
cleanup(): Promise<void>;
|
|
1916
|
+
}
|
|
1917
|
+
//#endregion
|
|
1918
|
+
//#region src/agent/context/index.d.ts
|
|
1919
|
+
declare class ContextMemory implements RecordRestoreHandler {
|
|
1920
|
+
protected readonly agent: Agent;
|
|
1921
|
+
private _history;
|
|
1922
|
+
private _tokenCount;
|
|
1923
|
+
private tokenCountCoveredMessageCount;
|
|
1924
|
+
private openSteps;
|
|
1925
|
+
private pendingToolResultIds;
|
|
1926
|
+
private deferredMessages;
|
|
1927
|
+
private toolCallInfo;
|
|
1928
|
+
readonly scratchManager: ScratchManager | undefined;
|
|
1929
|
+
constructor(agent: Agent, sessionId?: string);
|
|
1930
|
+
appendUserMessage(content: readonly ContentPart[], origin?: PromptOrigin): void;
|
|
1931
|
+
appendSystemReminder(content: string, origin: PromptOrigin): void;
|
|
1932
|
+
markLastUserPromptBlocked(hookEvent: string): void;
|
|
1933
|
+
clear(): void;
|
|
1934
|
+
applyCompaction(summary: CompactionResult$1): void;
|
|
1935
|
+
data(): AgentContextData$1;
|
|
1936
|
+
get tokenCount(): number;
|
|
1937
|
+
get tokenCountWithPending(): number;
|
|
1938
|
+
get history(): readonly ContextMessage$1[];
|
|
1939
|
+
get messages(): Message[];
|
|
1940
|
+
applyObservationMasking(config?: MaskingConfig): MaskingResult;
|
|
1941
|
+
applyPruning(config?: {
|
|
1942
|
+
effectiveCapacityRatio?: number;
|
|
1943
|
+
pruningThreshold?: number;
|
|
1944
|
+
}): {
|
|
1945
|
+
pruned: boolean;
|
|
1946
|
+
prunedCount: number;
|
|
1947
|
+
};
|
|
1948
|
+
appendLoopEvent(event: LoopRecordedEvent): Promise<void>;
|
|
1949
|
+
appendMessage(message: ContextMessage$1): void;
|
|
1950
|
+
private flushDeferredMessagesIfToolExchangeClosed;
|
|
1951
|
+
private hasOpenToolExchange;
|
|
1952
|
+
private pushHistory;
|
|
1953
|
+
restoreRecord(record: AgentRecord): void;
|
|
1954
|
+
private restoreClear;
|
|
1955
|
+
private restoreApplyCompaction;
|
|
1956
|
+
private restoreMarkLastUserPromptBlocked;
|
|
1957
|
+
private restoreAppendLoopEvent;
|
|
1958
|
+
private restoreObservationMasking;
|
|
1959
|
+
}
|
|
1846
1960
|
//#endregion
|
|
1847
1961
|
//#region src/agent/compaction/types.d.ts
|
|
1848
1962
|
interface CompactionResult$1 {
|
|
@@ -1863,12 +1977,13 @@ interface CompactionStrategy {
|
|
|
1863
1977
|
computeCompactCount(messages: readonly Message[], maxSize: number): number;
|
|
1864
1978
|
readonly checkAfterStep: boolean;
|
|
1865
1979
|
readonly maxCompactionPerTurn: number;
|
|
1980
|
+
readonly maskingConfig?: MaskingConfig | undefined;
|
|
1866
1981
|
}
|
|
1867
1982
|
interface CompactedHistory {
|
|
1868
1983
|
text: string;
|
|
1869
1984
|
}
|
|
1870
1985
|
type CompactionTelemetryTrigger = CompactionBeginData['source'] | 'manual-with-prompt' | 'unknown';
|
|
1871
|
-
declare class FullCompaction {
|
|
1986
|
+
declare class FullCompaction implements RecordRestoreHandler {
|
|
1872
1987
|
protected readonly agent: Agent;
|
|
1873
1988
|
protected compactionCountInTurn: number;
|
|
1874
1989
|
protected compacting: {
|
|
@@ -1903,135 +2018,52 @@ declare class FullCompaction {
|
|
|
1903
2018
|
private triggerPreCompactHook;
|
|
1904
2019
|
private triggerPostCompactHook;
|
|
1905
2020
|
private computeCompactableCount;
|
|
2021
|
+
restoreRecord(record: AgentRecord): void;
|
|
1906
2022
|
}
|
|
1907
2023
|
//#endregion
|
|
1908
|
-
//#region src/agent/
|
|
1909
|
-
interface
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
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;
|
|
2024
|
+
//#region src/agent/config/types.d.ts
|
|
2025
|
+
interface AgentConfigData$1 {
|
|
2026
|
+
cwd: string;
|
|
2027
|
+
provider?: ProviderConfig;
|
|
2028
|
+
modelAlias?: string;
|
|
2029
|
+
modelCapabilities: ModelCapability;
|
|
2030
|
+
profileName?: string;
|
|
2031
|
+
thinkingLevel: string;
|
|
2032
|
+
systemPrompt: string;
|
|
1954
2033
|
}
|
|
2034
|
+
type AgentConfigUpdateData$1 = Partial<{
|
|
2035
|
+
cwd: string;
|
|
2036
|
+
modelAlias: string;
|
|
2037
|
+
profileName: string;
|
|
2038
|
+
thinkingLevel: string;
|
|
2039
|
+
systemPrompt: string;
|
|
2040
|
+
}>;
|
|
1955
2041
|
//#endregion
|
|
1956
|
-
//#region src/agent/
|
|
1957
|
-
declare class
|
|
2042
|
+
//#region src/agent/config/index.d.ts
|
|
2043
|
+
declare class ConfigState implements RecordRestoreHandler {
|
|
1958
2044
|
protected readonly agent: Agent;
|
|
1959
|
-
private
|
|
1960
|
-
private
|
|
1961
|
-
private
|
|
1962
|
-
private
|
|
1963
|
-
private
|
|
1964
|
-
private deferredMessages;
|
|
2045
|
+
private _cwd;
|
|
2046
|
+
private _modelAlias;
|
|
2047
|
+
private _profileName;
|
|
2048
|
+
private _thinkingLevel;
|
|
2049
|
+
private _systemPrompt;
|
|
1965
2050
|
constructor(agent: Agent);
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
get
|
|
1973
|
-
get
|
|
1974
|
-
get
|
|
1975
|
-
get
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
private
|
|
1980
|
-
private
|
|
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;
|
|
2051
|
+
update(input: AgentConfigUpdateData$1): void;
|
|
2052
|
+
data(): AgentConfigData$1;
|
|
2053
|
+
get cwd(): string;
|
|
2054
|
+
get hasModel(): boolean;
|
|
2055
|
+
get hasProvider(): boolean;
|
|
2056
|
+
get providerConfig(): ProviderConfig;
|
|
2057
|
+
get provider(): ChatProvider;
|
|
2058
|
+
get model(): string;
|
|
2059
|
+
get modelAlias(): string | undefined;
|
|
2060
|
+
get thinkingLevel(): ThinkingEffort;
|
|
2061
|
+
get profileName(): string | undefined;
|
|
2062
|
+
get systemPrompt(): string;
|
|
2063
|
+
get modelCapabilities(): ModelCapability;
|
|
2064
|
+
private get resolvedProviderConfig();
|
|
2065
|
+
private tryResolvedProviderConfig;
|
|
2066
|
+
restoreRecord(record: AgentRecord): void;
|
|
2035
2067
|
}
|
|
2036
2068
|
//#endregion
|
|
2037
2069
|
//#region src/agent/permission/types.d.ts
|
|
@@ -2119,7 +2151,7 @@ interface PermissionManagerOptions {
|
|
|
2119
2151
|
readonly policies?: readonly PermissionPolicy[] | undefined;
|
|
2120
2152
|
readonly parent?: PermissionManager | undefined;
|
|
2121
2153
|
}
|
|
2122
|
-
declare class PermissionManager {
|
|
2154
|
+
declare class PermissionManager implements RecordRestoreHandler {
|
|
2123
2155
|
protected readonly agent: Agent;
|
|
2124
2156
|
rules: PermissionRule[];
|
|
2125
2157
|
private modeOverride;
|
|
@@ -2148,6 +2180,259 @@ declare class PermissionManager {
|
|
|
2148
2180
|
}): string;
|
|
2149
2181
|
private pathMatchOptions;
|
|
2150
2182
|
private trackToolApproved;
|
|
2183
|
+
restoreRecord(record: AgentRecord): void;
|
|
2184
|
+
}
|
|
2185
|
+
//#endregion
|
|
2186
|
+
//#region src/agent/usage/index.d.ts
|
|
2187
|
+
type UsageRecordScope = 'session' | 'turn';
|
|
2188
|
+
declare class UsageRecorder implements RecordRestoreHandler {
|
|
2189
|
+
protected readonly agent?: Agent | undefined;
|
|
2190
|
+
private readonly byModel;
|
|
2191
|
+
private currentTurn;
|
|
2192
|
+
constructor(agent?: Agent | undefined);
|
|
2193
|
+
beginTurn(): void;
|
|
2194
|
+
endTurn(): void;
|
|
2195
|
+
record(model: string, usage: TokenUsage, scope?: UsageRecordScope): void;
|
|
2196
|
+
data(): UsageStatus;
|
|
2197
|
+
status(): UsageStatus | undefined;
|
|
2198
|
+
private byModelSnapshot;
|
|
2199
|
+
restoreRecord(record: AgentRecord): void;
|
|
2200
|
+
}
|
|
2201
|
+
//#endregion
|
|
2202
|
+
//#region src/agent/records/types.d.ts
|
|
2203
|
+
interface AgentRecordEvents {
|
|
2204
|
+
metadata: {
|
|
2205
|
+
protocol_version: string;
|
|
2206
|
+
created_at: number;
|
|
2207
|
+
};
|
|
2208
|
+
'turn.prompt': {
|
|
2209
|
+
input: readonly ContentPart[];
|
|
2210
|
+
origin: PromptOrigin;
|
|
2211
|
+
};
|
|
2212
|
+
'turn.steer': {
|
|
2213
|
+
input: readonly ContentPart[];
|
|
2214
|
+
origin: PromptOrigin;
|
|
2215
|
+
};
|
|
2216
|
+
'turn.cancel': {
|
|
2217
|
+
turnId?: number;
|
|
2218
|
+
};
|
|
2219
|
+
'config.update': AgentConfigUpdateData$1;
|
|
2220
|
+
'permission.set_mode': {
|
|
2221
|
+
mode: PermissionMode$1;
|
|
2222
|
+
};
|
|
2223
|
+
'permission.record_approval_result': PermissionApprovalResultRecord$1;
|
|
2224
|
+
'full_compaction.begin': CompactionBeginData;
|
|
2225
|
+
'plan_mode.enter': {
|
|
2226
|
+
id: string;
|
|
2227
|
+
};
|
|
2228
|
+
'plan_mode.cancel': {
|
|
2229
|
+
id?: string;
|
|
2230
|
+
};
|
|
2231
|
+
'plan_mode.exit': {
|
|
2232
|
+
id?: string;
|
|
2233
|
+
};
|
|
2234
|
+
'tools.register_user_tool': UserToolRegistration;
|
|
2235
|
+
'tools.unregister_user_tool': {
|
|
2236
|
+
name: string;
|
|
2237
|
+
};
|
|
2238
|
+
'tools.set_active_tools': {
|
|
2239
|
+
names: readonly string[];
|
|
2240
|
+
};
|
|
2241
|
+
'background.stop': {
|
|
2242
|
+
taskId: string;
|
|
2243
|
+
};
|
|
2244
|
+
'usage.record': {
|
|
2245
|
+
model: string;
|
|
2246
|
+
usage: TokenUsage;
|
|
2247
|
+
usageScope?: UsageRecordScope | undefined;
|
|
2248
|
+
};
|
|
2249
|
+
'full_compaction.cancel': {};
|
|
2250
|
+
'full_compaction.complete': CompactionResult$1;
|
|
2251
|
+
'context.append_message': {
|
|
2252
|
+
message: ContextMessage$1;
|
|
2253
|
+
};
|
|
2254
|
+
'context.mark_last_user_prompt_blocked': {
|
|
2255
|
+
hookEvent: string;
|
|
2256
|
+
};
|
|
2257
|
+
'context.append_loop_event': {
|
|
2258
|
+
event: LoopRecordedEvent;
|
|
2259
|
+
};
|
|
2260
|
+
'context.clear': {};
|
|
2261
|
+
'context.apply_compaction': CompactionResult$1;
|
|
2262
|
+
'context.observation_masking': {
|
|
2263
|
+
maskedCount: number;
|
|
2264
|
+
tokensBefore: number;
|
|
2265
|
+
tokensAfter: number;
|
|
2266
|
+
};
|
|
2267
|
+
'context.output_offloaded': {
|
|
2268
|
+
toolCallId: string;
|
|
2269
|
+
filePath?: string | undefined;
|
|
2270
|
+
};
|
|
2271
|
+
'context.pruning': {
|
|
2272
|
+
prunedCount: number;
|
|
2273
|
+
};
|
|
2274
|
+
'tools.update_store': ToolStoreUpdate;
|
|
2275
|
+
}
|
|
2276
|
+
type AgentRecord = { [K in keyof AgentRecordEvents]: Readonly<AgentRecordEvents[K]> & {
|
|
2277
|
+
readonly type: K;
|
|
2278
|
+
readonly time?: number;
|
|
2279
|
+
} }[keyof AgentRecordEvents];
|
|
2280
|
+
type AgentRecordOf<K extends keyof AgentRecordEvents> = Extract<AgentRecord, {
|
|
2281
|
+
readonly type: K;
|
|
2282
|
+
}>;
|
|
2283
|
+
interface AgentRecordPersistence {
|
|
2284
|
+
read(): AsyncIterable<AgentRecord>;
|
|
2285
|
+
append(input: AgentRecord): void;
|
|
2286
|
+
rewrite(records: readonly AgentRecord[]): void;
|
|
2287
|
+
flush(): Promise<void>;
|
|
2288
|
+
close(): Promise<void>;
|
|
2289
|
+
}
|
|
2290
|
+
//#endregion
|
|
2291
|
+
//#region src/agent/tool/types.d.ts
|
|
2292
|
+
type ToolSource = 'builtin' | 'user' | 'mcp';
|
|
2293
|
+
type BuiltinTool<Input = unknown> = ExecutableTool<Input>;
|
|
2294
|
+
interface UserToolRegistration {
|
|
2295
|
+
readonly name: string;
|
|
2296
|
+
readonly description: string;
|
|
2297
|
+
readonly parameters: Record<string, unknown>;
|
|
2298
|
+
}
|
|
2299
|
+
interface ToolInfo$1 {
|
|
2300
|
+
readonly name: string;
|
|
2301
|
+
readonly description: string;
|
|
2302
|
+
readonly active: boolean;
|
|
2303
|
+
readonly source: ToolSource;
|
|
2304
|
+
}
|
|
2305
|
+
interface McpToolCollision {
|
|
2306
|
+
readonly qualified: string;
|
|
2307
|
+
readonly toolName: string;
|
|
2308
|
+
readonly collidesWith: {
|
|
2309
|
+
readonly kind: 'same_server';
|
|
2310
|
+
readonly toolName: string;
|
|
2311
|
+
} | {
|
|
2312
|
+
readonly kind: 'other_server';
|
|
2313
|
+
readonly serverName: string;
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
interface McpServerRegistrationResult {
|
|
2317
|
+
readonly registered: readonly string[];
|
|
2318
|
+
readonly collisions: readonly McpToolCollision[];
|
|
2319
|
+
}
|
|
2320
|
+
//#endregion
|
|
2321
|
+
//#region src/agent/tool/index.d.ts
|
|
2322
|
+
interface McpToolEntry {
|
|
2323
|
+
readonly tool: ExecutableTool;
|
|
2324
|
+
readonly serverName: string;
|
|
2325
|
+
}
|
|
2326
|
+
declare class ToolManager implements RecordRestoreHandler {
|
|
2327
|
+
protected readonly agent: Agent;
|
|
2328
|
+
protected builtinTools: Map<string, BuiltinTool>;
|
|
2329
|
+
protected readonly userTools: Map<string, ExecutableTool>;
|
|
2330
|
+
protected readonly mcpTools: Map<string, McpToolEntry>;
|
|
2331
|
+
/** server name → list of qualified tool names registered for that server. */
|
|
2332
|
+
protected readonly mcpToolsByServer: Map<string, string[]>;
|
|
2333
|
+
protected enabledTools: Set<string>;
|
|
2334
|
+
/** Glob patterns (e.g. `mcp__*`, `mcp__github__*`) gating which MCP tools the profile exposes. */
|
|
2335
|
+
private mcpAccessPatterns;
|
|
2336
|
+
protected readonly store: Partial<ToolStoreData>;
|
|
2337
|
+
private mcpToolStatusUnsubscribe;
|
|
2338
|
+
constructor(agent: Agent);
|
|
2339
|
+
protected get toolStore(): ToolStore;
|
|
2340
|
+
attachMcpTools(): void;
|
|
2341
|
+
updateStore<K extends ToolStoreKey>(key: K, value: ToolStoreData[K]): void;
|
|
2342
|
+
registerUserTool(input: UserToolRegistration): void;
|
|
2343
|
+
unregisterUserTool(name: string): void;
|
|
2344
|
+
registerMcpServer(serverName: string, client: MCPClient, tools: readonly Tool[], enabledTools?: ReadonlySet<string>): McpServerRegistrationResult;
|
|
2345
|
+
unregisterMcpServer(serverName: string): boolean;
|
|
2346
|
+
private handleMcpServerStatusChange;
|
|
2347
|
+
private registerNeedsAuthMcpServer;
|
|
2348
|
+
private registerConnectedMcpServer;
|
|
2349
|
+
private emitMcpToolCollisions;
|
|
2350
|
+
setActiveTools(names: readonly string[]): void;
|
|
2351
|
+
private isMcpToolEnabled;
|
|
2352
|
+
toolInfos(): Iterable<ToolInfo$1>;
|
|
2353
|
+
data(): readonly ToolInfo$1[];
|
|
2354
|
+
storeData(): Readonly<Record<string, unknown>>;
|
|
2355
|
+
initializeBuiltinTools(): void;
|
|
2356
|
+
private createVideoUploader;
|
|
2357
|
+
get loopTools(): readonly ExecutableTool[];
|
|
2358
|
+
restoreRecord(record: AgentRecord): void;
|
|
2359
|
+
}
|
|
2360
|
+
//#endregion
|
|
2361
|
+
//#region src/logging/logger.d.ts
|
|
2362
|
+
declare function getRootLogger(): RootLogger;
|
|
2363
|
+
declare function flushDiagnosticLogs(): Promise<boolean>;
|
|
2364
|
+
/**
|
|
2365
|
+
* Root logger. Import and use directly for events that don't belong to any
|
|
2366
|
+
* session (CLI startup, harness construction, etc.):
|
|
2367
|
+
*
|
|
2368
|
+
* import { log } from 'byf-sdk';
|
|
2369
|
+
* log.info('byf starting', { version });
|
|
2370
|
+
*
|
|
2371
|
+
* For events scoped to a session or agent, use the parent's `log` field:
|
|
2372
|
+
*
|
|
2373
|
+
* session.log.error('mcp initial load failed', error);
|
|
2374
|
+
* agent.log.error('turn failed', { turnId, error });
|
|
2375
|
+
*
|
|
2376
|
+
* Late-binding: methods look up the current `RootLogger` on every call, so
|
|
2377
|
+
* importing `log` at module load (before `ByfHarness` configures the root)
|
|
2378
|
+
* is safe — calls during the pre-configure window are silent noops.
|
|
2379
|
+
*/
|
|
2380
|
+
declare const log: Logger;
|
|
2381
|
+
declare function redact<T>(value: T): T;
|
|
2382
|
+
declare function resolveGlobalLogPath(homeDir: string): string;
|
|
2383
|
+
//#endregion
|
|
2384
|
+
//#region src/agent/hooks/types.d.ts
|
|
2385
|
+
declare const HOOK_EVENT_TYPES: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "UserPromptSubmit", "Stop", "StopFailure", "SessionStart", "SessionEnd", "SubagentStart", "SubagentStop", "PreCompact", "PostCompact", "Notification"];
|
|
2386
|
+
type HookEventType = (typeof HOOK_EVENT_TYPES)[number];
|
|
2387
|
+
interface HookDef {
|
|
2388
|
+
readonly event: HookEventType;
|
|
2389
|
+
readonly matcher?: string;
|
|
2390
|
+
readonly command: string;
|
|
2391
|
+
readonly timeout?: number;
|
|
2392
|
+
}
|
|
2393
|
+
interface HookResult {
|
|
2394
|
+
readonly action: 'allow' | 'block';
|
|
2395
|
+
readonly message?: string;
|
|
2396
|
+
readonly reason?: string;
|
|
2397
|
+
readonly stdout?: string;
|
|
2398
|
+
readonly stderr?: string;
|
|
2399
|
+
readonly exitCode?: number;
|
|
2400
|
+
readonly timedOut?: boolean;
|
|
2401
|
+
readonly structuredOutput?: boolean;
|
|
2402
|
+
}
|
|
2403
|
+
interface HookBlockDecision {
|
|
2404
|
+
readonly block: true;
|
|
2405
|
+
readonly reason: string;
|
|
2406
|
+
}
|
|
2407
|
+
type HookMatcherValue = string | readonly ContentPart[];
|
|
2408
|
+
interface HookEngineTriggerArgs {
|
|
2409
|
+
readonly matcherValue?: HookMatcherValue;
|
|
2410
|
+
readonly inputData?: Record<string, unknown>;
|
|
2411
|
+
readonly signal?: AbortSignal;
|
|
2412
|
+
}
|
|
2413
|
+
type HookTriggeredCallback = (event: string, target: string, count: number) => void;
|
|
2414
|
+
type HookResolvedCallback = (event: string, target: string, action: string, reason: string | undefined, durationMs: number) => void;
|
|
2415
|
+
interface HookEngineOptions {
|
|
2416
|
+
readonly cwd?: string;
|
|
2417
|
+
readonly sessionId?: string;
|
|
2418
|
+
readonly onTriggered?: HookTriggeredCallback;
|
|
2419
|
+
readonly onResolved?: HookResolvedCallback;
|
|
2420
|
+
}
|
|
2421
|
+
//#endregion
|
|
2422
|
+
//#region src/agent/hooks/engine.d.ts
|
|
2423
|
+
declare class HookEngine {
|
|
2424
|
+
private readonly options;
|
|
2425
|
+
private readonly byEvent;
|
|
2426
|
+
private readonly pendingTriggers;
|
|
2427
|
+
constructor(hooks?: readonly HookDef[], options?: HookEngineOptions);
|
|
2428
|
+
get summary(): Record<string, number>;
|
|
2429
|
+
trigger(event: string, args?: HookEngineTriggerArgs): Promise<HookResult[]>;
|
|
2430
|
+
triggerBlock(event: string, args?: HookEngineTriggerArgs): Promise<HookBlockDecision | undefined>;
|
|
2431
|
+
fireAndForgetTrigger(event: string, args?: HookEngineTriggerArgs): Promise<HookResult[]>;
|
|
2432
|
+
private triggerInner;
|
|
2433
|
+
private matchingHooks;
|
|
2434
|
+
private emitTriggered;
|
|
2435
|
+
private emitResolved;
|
|
2151
2436
|
}
|
|
2152
2437
|
//#endregion
|
|
2153
2438
|
//#region src/telemetry.d.ts
|
|
@@ -2161,8 +2446,6 @@ interface TelemetryClient {
|
|
|
2161
2446
|
withContext?(patch: TelemetryContextPatch): TelemetryClient;
|
|
2162
2447
|
setContext?(patch: TelemetryContextPatch): void;
|
|
2163
2448
|
}
|
|
2164
|
-
declare const noopTelemetryClient: TelemetryClient;
|
|
2165
|
-
declare function withTelemetryContext(telemetry: TelemetryClient, patch: TelemetryContextPatch): TelemetryClient;
|
|
2166
2449
|
//#endregion
|
|
2167
2450
|
//#region src/session/index.d.ts
|
|
2168
2451
|
interface SessionConfig {
|
|
@@ -2375,50 +2658,6 @@ declare class BackgroundManager extends BackgroundProcessManager {
|
|
|
2375
2658
|
_reset(): void;
|
|
2376
2659
|
}
|
|
2377
2660
|
//#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
2661
|
//#region src/agent/injection/manager.d.ts
|
|
2423
2662
|
declare class InjectionManager {
|
|
2424
2663
|
protected readonly agent: Agent;
|
|
@@ -2429,143 +2668,20 @@ declare class InjectionManager {
|
|
|
2429
2668
|
onContextCompacted(compactedCount: number): void;
|
|
2430
2669
|
}
|
|
2431
2670
|
//#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
2671
|
//#region src/agent/records/index.d.ts
|
|
2560
2672
|
declare class AgentRecords {
|
|
2561
2673
|
private readonly agent;
|
|
2562
2674
|
private readonly persistence?;
|
|
2563
2675
|
private _restoring;
|
|
2564
2676
|
private metadataInitialized;
|
|
2677
|
+
private handlers;
|
|
2565
2678
|
constructor(agent: Agent, persistence?: AgentRecordPersistence | undefined);
|
|
2566
2679
|
get restoring(): boolean;
|
|
2680
|
+
registerHandlers(handlers: Record<string, RecordRestoreHandler>): void;
|
|
2567
2681
|
logRecord(record: AgentRecord): void;
|
|
2568
2682
|
restore(record: AgentRecord): void;
|
|
2683
|
+
private routeToHandler;
|
|
2684
|
+
private getHandlerKey;
|
|
2569
2685
|
replay(): Promise<{
|
|
2570
2686
|
warning?: string;
|
|
2571
2687
|
}>;
|
|
@@ -2618,7 +2734,6 @@ declare const ErrorCodes: {
|
|
|
2618
2734
|
readonly SESSION_PERMISSION_MODE_INVALID: "session.permission_mode_invalid";
|
|
2619
2735
|
readonly SESSION_THINKING_EMPTY: "session.thinking_empty";
|
|
2620
2736
|
readonly SESSION_MODEL_EMPTY: "session.model_empty";
|
|
2621
|
-
readonly SESSION_PLAN_MODE_INVALID: "session.plan_mode_invalid";
|
|
2622
2737
|
readonly SESSION_APPROVAL_HANDLER_ERROR: "session.approval_handler_error";
|
|
2623
2738
|
readonly SESSION_QUESTION_HANDLER_ERROR: "session.question_handler_error";
|
|
2624
2739
|
readonly SESSION_INIT_FAILED: "session.init_failed";
|
|
@@ -2758,12 +2873,6 @@ declare const BYF_ERROR_INFO: {
|
|
|
2758
2873
|
readonly public: true;
|
|
2759
2874
|
readonly action: "Provide a non-empty model identifier.";
|
|
2760
2875
|
};
|
|
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
2876
|
readonly 'session.approval_handler_error': {
|
|
2768
2877
|
readonly title: "Approval handler threw";
|
|
2769
2878
|
readonly retryable: false;
|
|
@@ -3022,6 +3131,8 @@ interface UsageStatus$1 {
|
|
|
3022
3131
|
readonly byModel?: Record<string, TokenUsage> | undefined;
|
|
3023
3132
|
readonly currentTurn?: TokenUsage | undefined;
|
|
3024
3133
|
readonly total?: TokenUsage | undefined;
|
|
3134
|
+
/** Cache hit rate across all recorded usage (0–1), undefined when no data. */
|
|
3135
|
+
readonly cacheHitRate?: CacheHitRate | undefined;
|
|
3025
3136
|
}
|
|
3026
3137
|
interface ToolUpdate {
|
|
3027
3138
|
readonly kind: 'stdout' | 'stderr' | 'progress' | 'status' | 'custom';
|
|
@@ -3048,7 +3159,6 @@ interface AgentStatusUpdatedEvent {
|
|
|
3048
3159
|
readonly contextTokens?: number | undefined;
|
|
3049
3160
|
readonly maxContextTokens?: number | undefined;
|
|
3050
3161
|
readonly contextUsage?: number | undefined;
|
|
3051
|
-
readonly planMode?: boolean | undefined;
|
|
3052
3162
|
readonly permission?: PermissionMode$1 | undefined;
|
|
3053
3163
|
readonly usage?: UsageStatus$1 | undefined;
|
|
3054
3164
|
}
|
|
@@ -3100,6 +3210,8 @@ interface TurnStepCompletedEvent {
|
|
|
3100
3210
|
readonly finishReason?: string | undefined;
|
|
3101
3211
|
readonly providerFinishReason?: FinishReason | undefined;
|
|
3102
3212
|
readonly rawFinishReason?: string | undefined;
|
|
3213
|
+
readonly llmFirstTokenLatencyMs?: number | undefined;
|
|
3214
|
+
readonly llmStreamDurationMs?: number | undefined;
|
|
3103
3215
|
}
|
|
3104
3216
|
interface TurnStepRetryingEvent {
|
|
3105
3217
|
readonly type: 'turn.step.retrying';
|
|
@@ -3168,6 +3280,7 @@ interface ToolResultEvent {
|
|
|
3168
3280
|
readonly output: unknown;
|
|
3169
3281
|
readonly isError?: boolean | undefined;
|
|
3170
3282
|
readonly synthetic?: boolean | undefined;
|
|
3283
|
+
readonly blockedReason?: 'rejected' | 'cancelled' | undefined;
|
|
3171
3284
|
}
|
|
3172
3285
|
interface SubagentSpawnedEvent {
|
|
3173
3286
|
readonly type: 'subagent.spawned';
|
|
@@ -3208,6 +3321,16 @@ interface CompactionCompletedEvent {
|
|
|
3208
3321
|
readonly type: 'compaction.completed';
|
|
3209
3322
|
readonly result: CompactionResult;
|
|
3210
3323
|
}
|
|
3324
|
+
interface ObservationMaskingAppliedEvent {
|
|
3325
|
+
readonly type: 'observation_masking.applied';
|
|
3326
|
+
readonly maskedCount: number;
|
|
3327
|
+
readonly tokensBefore: number;
|
|
3328
|
+
readonly tokensAfter: number;
|
|
3329
|
+
}
|
|
3330
|
+
interface PruningAppliedEvent {
|
|
3331
|
+
readonly type: 'pruning.applied';
|
|
3332
|
+
readonly prunedCount: number;
|
|
3333
|
+
}
|
|
3211
3334
|
interface BackgroundTaskStartedEvent {
|
|
3212
3335
|
readonly type: 'background.task.started';
|
|
3213
3336
|
readonly info: BackgroundTaskInfo$1;
|
|
@@ -3237,7 +3360,7 @@ interface McpServerStatusPayload {
|
|
|
3237
3360
|
readonly toolCount: number;
|
|
3238
3361
|
readonly error?: string | undefined;
|
|
3239
3362
|
}
|
|
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;
|
|
3363
|
+
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 | ObservationMaskingAppliedEvent | PruningAppliedEvent | BackgroundTaskStartedEvent | BackgroundTaskUpdatedEvent | BackgroundTaskTerminatedEvent;
|
|
3241
3364
|
type Event = AgentEvent$1 & {
|
|
3242
3365
|
agentId: string;
|
|
3243
3366
|
sessionId: string;
|
|
@@ -3290,6 +3413,7 @@ type WithSessionId<T> = WithExtraPayload<T, {
|
|
|
3290
3413
|
declare function proxyWithExtraPayload<T, U>(methods: RPCMethods<WithExtraPayload<T, U>>, extraPayload: U): RPCMethods<T>;
|
|
3291
3414
|
//#endregion
|
|
3292
3415
|
//#region src/rpc/core-api.d.ts
|
|
3416
|
+
type PlanData = null;
|
|
3293
3417
|
type JsonPrimitive = string | number | boolean | null;
|
|
3294
3418
|
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3295
3419
|
readonly [key: string]: JsonValue;
|
|
@@ -3631,7 +3755,6 @@ interface ByfCoreOptions {
|
|
|
3631
3755
|
readonly byfRequestHeaders?: Record<string, string> | undefined;
|
|
3632
3756
|
readonly resolveOAuthTokenProvider?: OAuthTokenProviderResolver | undefined;
|
|
3633
3757
|
readonly skillDirs?: readonly string[];
|
|
3634
|
-
readonly telemetry?: TelemetryClient | undefined;
|
|
3635
3758
|
}
|
|
3636
3759
|
declare class ByfCore implements PromisableMethods<CoreAPI> {
|
|
3637
3760
|
protected readonly rpcClient: CoreRPCClient;
|
|
@@ -3759,7 +3882,7 @@ declare class ByfCore implements PromisableMethods<CoreAPI> {
|
|
|
3759
3882
|
getPlan({
|
|
3760
3883
|
sessionId,
|
|
3761
3884
|
...payload
|
|
3762
|
-
}: SessionAgentPayload<EmptyPayload>):
|
|
3885
|
+
}: SessionAgentPayload<EmptyPayload>): Promise<null> | null;
|
|
3763
3886
|
getUsage({
|
|
3764
3887
|
sessionId,
|
|
3765
3888
|
...payload
|
|
@@ -3816,10 +3939,11 @@ interface TurnEndResult {
|
|
|
3816
3939
|
readonly event: TurnEndedEvent;
|
|
3817
3940
|
readonly stopReason?: LoopTurnStopReason;
|
|
3818
3941
|
}
|
|
3819
|
-
declare class TurnFlow {
|
|
3942
|
+
declare class TurnFlow implements RecordRestoreHandler {
|
|
3820
3943
|
protected readonly agent: Agent;
|
|
3821
3944
|
private steerBuffer;
|
|
3822
3945
|
private turnId;
|
|
3946
|
+
private _previousTurnMessageCount;
|
|
3823
3947
|
private activeTurn;
|
|
3824
3948
|
private readonly toolCallStartedAt;
|
|
3825
3949
|
private readonly toolCallDupType;
|
|
@@ -3854,6 +3978,7 @@ declare class TurnFlow {
|
|
|
3854
3978
|
private trackTurnInterrupted;
|
|
3855
3979
|
private telemetryMode;
|
|
3856
3980
|
private shouldTrackApiError;
|
|
3981
|
+
restoreRecord(record: AgentRecord): void;
|
|
3857
3982
|
}
|
|
3858
3983
|
//#endregion
|
|
3859
3984
|
//#region src/agent/index.d.ts
|
|
@@ -3898,7 +4023,6 @@ declare class Agent {
|
|
|
3898
4023
|
readonly turn: TurnFlow;
|
|
3899
4024
|
readonly injection: InjectionManager;
|
|
3900
4025
|
readonly permission: PermissionManager;
|
|
3901
|
-
readonly planMode: PlanMode;
|
|
3902
4026
|
readonly usage: UsageRecorder;
|
|
3903
4027
|
readonly tools: ToolManager;
|
|
3904
4028
|
readonly background: BackgroundManager;
|
|
@@ -3912,6 +4036,7 @@ declare class Agent {
|
|
|
3912
4036
|
useProfile(profile: ResolvedAgentProfile, context?: PreparedSystemPromptContext): void;
|
|
3913
4037
|
resume(): Promise<{
|
|
3914
4038
|
warning?: string;
|
|
4039
|
+
error?: Error;
|
|
3915
4040
|
}>;
|
|
3916
4041
|
get rpcMethods(): PromisableMethods<AgentAPI>;
|
|
3917
4042
|
emitEvent(event: AgentEvent): void;
|
|
@@ -3984,4 +4109,7 @@ interface ResolveLoggingInput {
|
|
|
3984
4109
|
*/
|
|
3985
4110
|
declare function resolveLoggingConfig(input: ResolveLoggingInput): LoggingConfig;
|
|
3986
4111
|
//#endregion
|
|
3987
|
-
|
|
4112
|
+
//#region src/prompt-plan/builder.d.ts
|
|
4113
|
+
declare function buildPromptPlan(renderedSystemPrompt: string, providerCacheCapability: ProviderCacheCapability): PromptPlan;
|
|
4114
|
+
//#endregion
|
|
4115
|
+
export { CoreInfo as $, SessionSkillConfig as $n, resolveByfHome as $r, BackgroundTaskUpdatedEvent as $t, QuestionAnswers as A, ProviderType as Ai, TurnStepInterruptedEvent as An, LoopStepEndEvent as Ar, SetModelResult as At, SDKSessionAPI as B, LogEntry as Bi, ByfError as Bn, BackgroundTaskStatus as Br, Unsubscribe as Bt, SDKRPCClient as C, PermissionConfigSchema as Ci, ToolProgressEvent as Cn, PromptOrigin as Cr, ResumeSessionPayload as Ct, ApprovalResponse as D, PermissionRuleScopeSchema as Di, TurnEndedEvent as Dn, LoopContentPartEvent as Dr, SetActiveToolsPayload as Dt, ApprovalRequest as E, PermissionRuleSchema as Ei, TurnEndReason as En, ToolStoreUpdate as Er, SessionSummary as Et, QuestionResult as F, ThinkingConfigSchema as Fi, ByfErrorPayload as Fn, ExecutableToolSuccessResult as Fr, SkillSummary as Ft, AgentAPI$1 as G, RootLogger as Gi, ErrorCodes as Gn, parseConfigString as Gr, AgentReplayRecord as Gt, ToolCallRequest as H, LogPayload as Hi, BYF_ERROR_INFO as Hn, OAuthTokenProviderResolver as Hr, WithAgentId as Ht, SDKAPI as I, formatConfigValidationError as Ii, fromByfErrorPayload as In, ToolInputDisplay as Ir, SteerPayload as It, ByfConfigPatch as J, SubagentHandle as Jn, writeConfigFile as Jr, AgentEvent$1 as Jt, BeginCompactionPayload as K, SessionAttachInput as Ki, RuntimeConfig as Kn, readConfigFile as Kr, ResumeSessionResult as Kt, SDKAgentAPI as L, getDefaultConfig as Li, isByfError as Ln, BackgroundLifecycleEvent as Lr, StopBackgroundPayload as Lt, QuestionOption as M, ServicesConfig as Mi, TurnStepStartedEvent as Mn, LoopToolResultEvent as Mr, SetThinkingPayload as Mt, QuestionRequest as N, ServicesConfigSchema as Ni, UsageStatus$1 as Nn, ExecutableToolErrorResult as Nr, ShellExecPayload as Nt, ApprovalScope as O, ProviderConfig$1 as Oi, TurnStartedEvent as On, LoopRecordedEvent as Or, SetByfConfigPayload as Ot, QuestionResponse as P, ThinkingConfig as Pi, WarningEvent as Pn, ExecutableToolResult as Pr, ShellExecResult as Pt, CoreAPI as Q, SessionMeta$1 as Qn, ensureByfHome as Qr, BackgroundTaskTerminatedEvent as Qt, SDKAgentRPC$1 as R, validateConfig as Ri, makeErrorPayload as Rn, BackgroundTaskInfo$1 as Rr, TextPromptPart as Rt, RPCMethods as S, PermissionConfig as Si, ToolListUpdatedReason as Sn, ContextMessage$1 as Sr, RenameSessionPayload as St, ApprovalDecision as T, PermissionRuleDecisionSchema as Ti, ToolUpdate as Tn, UserPromptOrigin as Tr, SessionMetadataPatch as Tt, ToolCallResponse as U, Logger as Ui, ByfErrorCode as Un, configToTomlData as Ur, WithSessionId as Ut, SDKSessionRPC$1 as V, LogLevel as Vi, ByfErrorOptions as Vn, BearerTokenProvider as Vr, UpdateSessionMetadataPayload as Vt, ActivateSkillPayload$1 as W, LoggingConfig as Wi, ByfErrorInfo as Wn, ensureConfigFile as Wr, proxyWithExtraPayload as Wt, CancelPlanPayload as X, Session as Xn, parseBooleanEnv as Xr, AssistantDeltaEvent as Xt, CancelPayload as Y, AgentMeta as Yn, ResolveConfigValueInput as Yr, AgentStatusUpdatedEvent as Yt, CloseSessionPayload as Z, SessionConfig as Zn, resolveConfigValue as Zr, BackgroundTaskStartedEvent as Zt, ByfCoreOptions as _, McpServerStdioConfigSchema as _i, SubagentSpawnedEvent as _n, PermissionMode$1 as _r, PromptPart as _t, collectFilesRecursive as a, ByfConfigSchema as ai, Event as an, redact as ar, ForkSessionPayload as at, RPCCallOptions as b, OAuthRef$1 as bi, ToolCallStartedEvent as bn, CompactionResult$1 as br, RegisterToolPayload as bt, WIRE_PROTOCOL_VERSION as c, HookDefConfig as ci, McpOAuthAuthorizationUrlUpdateData as cn, ToolInfo$1 as cr, GetBackgroundPayload as ct, normalizeTimestampMs as d, LoopControlSchema as di, ObservationMaskingAppliedEvent as dn, AgentRecord as dr, JsonValue as dt, resolveConfigPath as ei, CompactionBlockedEvent as en, TelemetryClient as er, CreateSessionPayload as et, scanSessionWire as f, McpServerConfig as fi, PruningAppliedEvent as fn, AgentRecordEvents as fr, ListSessionsPayload as ft, ByfCore as g, McpServerStdioConfig as gi, SubagentFailedEvent as gn, PermissionApprovalResultRecord$1 as gr, PromptInput as gt, AgentType$1 as h, McpServerHttpConfigSchema as hi, SubagentCompletedEvent as hn, UsageRecordScope as hr, PlanData as ht, ExtraZipEntry as i, ByfConfigPatchSchema as ii, ErrorEvent as in, log as ir, ExportSessionResult as it, QuestionItem as j, ProviderTypeSchema as ji, TurnStepRetryingEvent as jn, LoopToolCallEvent as jr, SetPermissionPayload as jt, QuestionAnswerMethod as k, ProviderConfigSchema as ki, TurnStepCompletedEvent as kn, LoopStepBeginEvent as kr, SetModelPayload as kt, buildExportManifest as l, HookDefSchema as li, McpServerStatusEvent as ln, ToolSource as lr, JsonObject as lt, AgentConfig as m, McpServerHttpConfig as mi, SkillActivatedEvent as mn, AgentRecordPersistence as mr, McpStartupMetrics as mt, ResolveLoggingInput as n, BackgroundConfig as ni, CompactionCompletedEvent as nn, flushDiagnosticLogs as nr, ExportSessionManifest as nt, writeExportZip as o, ByfServiceConfig as oi, HookResultEvent as on, resolveGlobalLogPath as or, GetBackgroundOutputPathPayload as ot, Agent as p, McpServerConfigSchema as pi, SessionMetaUpdatedEvent as pn, AgentRecordOf as pr, McpServerInfo as pt, ByfConfig as q, SessionLogHandle as qi, SessionSubagentHost as qn, transformTomlData as qr, ResumedAgentState as qt, resolveLoggingConfig as r, BackgroundConfigSchema as ri, CompactionStartedEvent as rn, getRootLogger as rr, ExportSessionPayload as rt, exportSessionDirectory as s, ByfServiceConfigSchema as si, MCP_OAUTH_AUTHORIZATION_URL_TOOL_UPDATE as sn, BuiltinTool as sr, GetBackgroundOutputPayload as st, buildPromptPlan as t, mergeConfigPatch as ti, CompactionCancelledEvent as tn, TelemetryProperties as tr, EmptyPayload as tt, SessionWireScan as u, LoopControl as ui, McpServerStatusPayload as un, UserToolRegistration as ur, JsonPrimitive as ut, CoreRPC as v, ModelAlias as vi, ThinkingDeltaEvent as vn, AgentConfigUpdateData$1 as vr, PromptPayload as vt, createRPC as w, PermissionModeSchema as wi, ToolResultEvent as wn, USER_PROMPT_ORIGIN as wr, SessionAPI as wt, RPCClient as x, OAuthRefSchema as xi, ToolListUpdatedEvent as xn, AgentContextData$1 as xr, RemoveByfProviderPayload as xt, CoreRPCClient as y, ModelAliasSchema as yi, ToolCallDeltaEvent as yn, CompactionBeginData as yr, ReconnectMcpServerPayload as yt, SDKRPC as z, LogContext as zi, toByfErrorPayload as zn, BackgroundTaskKind as zr, UnregisterToolPayload as zt };
|