@botiverse/kimi-code-sdk 0.20.3 → 0.21.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.d.mts CHANGED
@@ -22,6 +22,7 @@ import type { OAuthClientMetadata } from '@modelcontextprotocol/sdk/shared/auth.
22
22
  import type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
23
23
  import type { OAuthDiscoveryState } from '@modelcontextprotocol/sdk/client/auth.js';
24
24
  import type { OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
25
+ import { PluginCommandActivatedEvent } from '@moonshot-ai/protocol';
25
26
  import type { Readable } from 'node:stream';
26
27
  import { SessionMetaUpdatedEvent } from '@moonshot-ai/protocol';
27
28
  import type { SessionWarning } from '@moonshot-ai/protocol';
@@ -52,6 +53,18 @@ import { WarningEvent } from '@moonshot-ai/protocol';
52
53
  import type { Writable } from 'node:stream';
53
54
  import { z } from 'zod';
54
55
 
56
+ declare interface ActivatePluginCommandPayload {
57
+ readonly pluginId: string;
58
+ readonly commandName: string;
59
+ readonly args?: string | undefined;
60
+ }
61
+
62
+ declare interface ActivatePluginCommandRpcInput extends SessionIdRpcInput {
63
+ readonly pluginId: string;
64
+ readonly commandName: string;
65
+ readonly args?: string | undefined;
66
+ }
67
+
55
68
  declare interface ActivateSkillPayload {
56
69
  readonly name: string;
57
70
  readonly args?: string | undefined;
@@ -100,6 +113,7 @@ declare class Agent {
100
113
  readonly rpc?: Partial<SDKAgentRPC>;
101
114
  readonly toolServices?: ToolServices;
102
115
  readonly pluginSessionStarts: readonly EnabledPluginSessionStart[];
116
+ readonly pluginCommands: readonly PluginCommandDef[];
103
117
  readonly rawGenerate: typeof generate;
104
118
  readonly modelProvider?: ModelProvider;
105
119
  readonly subagentHost?: SessionSubagentHost;
@@ -128,13 +142,25 @@ declare class Agent {
128
142
  readonly goal: GoalMode;
129
143
  readonly replayBuilder: ReplayBuilder;
130
144
  private additionalDirs;
145
+ private activeProfile?;
146
+ private brandHome?;
147
+ private readonly systemPromptContextProvider?;
131
148
  constructor(options: AgentOptions);
132
149
  setKaos(kaos: Kaos): void;
133
150
  getAdditionalDirs(): readonly string[];
134
151
  setAdditionalDirs(additionalDirs: readonly string[]): void;
135
152
  get generate(): typeof generate;
136
153
  get llm(): KosongLLM;
137
- useProfile(profile: ResolvedAgentProfile, context?: PreparedSystemPromptContext): void;
154
+ useProfile(profile: ResolvedAgentProfile, context?: PreparedSystemPromptContext, brandHome?: string): void;
155
+ setActiveProfile(profile: ResolvedAgentProfile, brandHome?: string): void;
156
+ /**
157
+ * Re-render the system prompt with freshly gathered runtime context (cwd
158
+ * listing, AGENTS.md, additional-dirs info, skill list). Called after
159
+ * compaction so the post-compaction turns do not keep a snapshot captured
160
+ * at session bootstrap. Invalidates the prompt-cache prefix by design.
161
+ */
162
+ refreshSystemPrompt(): Promise<void>;
163
+ private updateSystemPromptFromProfile;
138
164
  resume(options?: AgentRecordsReplayOptions): Promise<{
139
165
  warning?: string;
140
166
  }>;
@@ -170,6 +196,7 @@ declare interface AgentAPI {
170
196
  detachBackground: (payload: DetachBackgroundPayload) => BackgroundTaskInfo | undefined;
171
197
  clearContext: (payload: EmptyPayload) => void;
172
198
  activateSkill: (payload: ActivateSkillPayload) => void;
199
+ activatePluginCommand: (payload: ActivatePluginCommandPayload) => void;
173
200
  startBtw: (payload: EmptyPayload) => string;
174
201
  createGoal: (payload: CreateGoalPayload) => GoalSnapshot;
175
202
  getGoal: (payload: EmptyPayload) => GoalToolResult;
@@ -202,7 +229,7 @@ declare interface AgentConfigData {
202
229
  modelAlias?: string;
203
230
  modelCapabilities: ModelCapability;
204
231
  profileName?: string;
205
- thinkingLevel: string;
232
+ thinkingEffort: string;
206
233
  systemPrompt: string;
207
234
  }
208
235
 
@@ -210,7 +237,7 @@ declare type AgentConfigUpdateData = Partial<{
210
237
  cwd: string;
211
238
  modelAlias: string;
212
239
  profileName: string;
213
- thinkingLevel: string;
240
+ thinkingEffort: string;
214
241
  systemPrompt: string;
215
242
  }>;
216
243
 
@@ -248,9 +275,11 @@ declare interface AgentOptions {
248
275
  readonly log?: Logger;
249
276
  readonly telemetry?: TelemetryClient | undefined;
250
277
  readonly pluginSessionStarts?: readonly EnabledPluginSessionStart[];
278
+ readonly pluginCommands?: readonly PluginCommandDef[];
251
279
  readonly experimentalFlags?: ExperimentalFlagResolver;
252
280
  readonly replay?: ReplayBuilderOptions;
253
281
  readonly additionalDirs?: readonly string[];
282
+ readonly systemPromptContextProvider?: (() => Promise<PreparedSystemPromptContext>) | undefined;
254
283
  }
255
284
 
256
285
  declare type AgentRecord = {
@@ -951,7 +980,7 @@ declare interface ChatProvider {
951
980
  readonly name: string;
952
981
  /** Model name passed to the upstream API (e.g. `"moonshot-v1-auto"`). */
953
982
  readonly modelName: string;
954
- /** Current thinking-effort level, or `null` if thinking is not configured. */
983
+ /** Current thinking effort, or `null` if thinking is not configured. */
955
984
  readonly thinkingEffort: ThinkingEffort | null;
956
985
  /**
957
986
  * Send a conversation to the LLM and return a streamed response.
@@ -1019,11 +1048,46 @@ export { CompactionCancelledEvent }
1019
1048
 
1020
1049
  export { CompactionCompletedEvent }
1021
1050
 
1051
+ /**
1052
+ * Inputs `ContextMemory.applyCompaction` needs to derive a `CompactionResult`.
1053
+ * `tokensAfter` / `keptUserMessageCount` / `droppedCount` are optional: the live
1054
+ * path fills in what it knows, while restore passes the persisted record so its
1055
+ * historical values are preserved verbatim.
1056
+ */
1057
+ declare type CompactionInput = Pick<CompactionResult, 'summary' | 'compactedCount' | 'tokensBefore'> & Partial<Pick<CompactionResult, 'contextSummary' | 'tokensAfter' | 'keptUserMessageCount' | 'droppedCount'>>;
1058
+
1022
1059
  export declare interface CompactionResult {
1060
+ /** Human-facing summary text produced by the compaction model. */
1023
1061
  summary: string;
1062
+ /**
1063
+ * Exact summary message stored in the live model context. It includes the
1064
+ * compaction prefix that tells the next model this is handoff context rather
1065
+ * than a real user prompt. Optional for backward compatibility with older
1066
+ * wire records, where `summary` was also the model-context text.
1067
+ */
1068
+ contextSummary?: string;
1024
1069
  compactedCount: number;
1025
1070
  tokensBefore: number;
1026
1071
  tokensAfter: number;
1072
+ /**
1073
+ * Number of real user messages kept verbatim ahead of the summary in the
1074
+ * post-compaction live context. Written by `ContextMemory.applyCompaction`
1075
+ * (the single derivation point for the post-compaction shape) so the
1076
+ * wire-transcript reducer can reproduce the live folded length without
1077
+ * re-deriving it from the full transcript. Optional for backward
1078
+ * compatibility with older wire records.
1079
+ */
1080
+ keptUserMessageCount?: number;
1081
+ /**
1082
+ * Number of oldest messages trimmed from the summarizer input when the
1083
+ * compaction request itself overflowed the model window. These messages are
1084
+ * not covered by the produced summary — a real-user message among them may
1085
+ * still be retained verbatim in the live context via `keptUserMessageCount`,
1086
+ * but assistant/tool messages are lost. Surfacing the count lets records and
1087
+ * telemetry report the summary's blind spot honestly. Optional for backward
1088
+ * compatibility with older wire records.
1089
+ */
1090
+ droppedCount?: number;
1027
1091
  }
1028
1092
 
1029
1093
  declare type CompactionSource = 'manual' | 'auto';
@@ -1033,10 +1097,9 @@ export { CompactionStartedEvent }
1033
1097
  declare interface CompactionStrategy {
1034
1098
  shouldCompact(usedSize: number): boolean;
1035
1099
  shouldBlock(usedSize: number): boolean;
1036
- computeCompactCount(messages: readonly Message[], source: CompactionSource): number;
1037
- reduceCompactOnOverflow(messages: readonly Message[]): number;
1038
1100
  readonly checkAfterStep: boolean;
1039
1101
  readonly maxCompactionPerTurn: number;
1102
+ readonly maxOverflowCompactionAttempts: number;
1040
1103
  }
1041
1104
 
1042
1105
  declare interface CompactionSummaryOrigin {
@@ -1065,7 +1128,7 @@ declare class ConfigState {
1065
1128
  private _cwd;
1066
1129
  private _modelAlias;
1067
1130
  private _profileName;
1068
- private _thinkingLevel;
1131
+ private _thinkingEffort;
1069
1132
  private _systemPrompt;
1070
1133
  constructor(agent: Agent);
1071
1134
  update(changed: AgentConfigUpdateData): void;
@@ -1077,8 +1140,8 @@ declare class ConfigState {
1077
1140
  get provider(): ChatProvider;
1078
1141
  get model(): string;
1079
1142
  get modelAlias(): string | undefined;
1080
- get thinkingLevel(): ThinkingEffort;
1081
- private get alwaysThinkingModel();
1143
+ get thinkingEffort(): ThinkingEffort;
1144
+ private get currentModel();
1082
1145
  get profileName(): string | undefined;
1083
1146
  get systemPrompt(): string;
1084
1147
  get modelCapabilities(): ModelCapability;
@@ -1105,6 +1168,7 @@ declare class ContextMemory {
1105
1168
  private pendingToolResultIds;
1106
1169
  private deferredMessages;
1107
1170
  private _lastAssistantAt;
1171
+ private lastProjectionRepairSignature;
1108
1172
  constructor(agent: Agent);
1109
1173
  get lastAssistantAt(): number | null;
1110
1174
  appendUserMessage(content: readonly ContentPart[], origin?: PromptOrigin): void;
@@ -1124,13 +1188,15 @@ declare class ContextMemory {
1124
1188
  popMatchedMessage(matcher: (origin: PromptOrigin | undefined) => boolean): boolean;
1125
1189
  clear(): void;
1126
1190
  undo(count: number): void;
1127
- applyCompaction(result: CompactionResult): void;
1191
+ applyCompaction(input: CompactionInput): CompactionResult;
1128
1192
  data(): AgentContextData;
1129
1193
  get tokenCount(): number;
1130
1194
  get tokenCountWithPending(): number;
1131
1195
  get history(): readonly ContextMessage[];
1132
- project(messages: readonly ContextMessage[]): Message[];
1196
+ project(messages: readonly ContextMessage[], options?: ProjectOptions): Message[];
1197
+ private reportProjectionRepairs;
1133
1198
  get messages(): Message[];
1199
+ get strictMessages(): Message[];
1134
1200
  useProjectedHistoryFrom(source: ContextMemory): void;
1135
1201
  finishResume(): void;
1136
1202
  private closePendingToolResults;
@@ -1912,7 +1978,7 @@ declare const FLAG_DEFINITIONS: readonly [{
1912
1978
  readonly title: "Micro compaction";
1913
1979
  readonly description: "Trim older large tool results from context while keeping recent conversation intact.";
1914
1980
  readonly env: "KIMI_CODE_EXPERIMENTAL_MICRO_COMPACTION";
1915
- readonly default: true;
1981
+ readonly default: false;
1916
1982
  readonly surface: "core";
1917
1983
  }];
1918
1984
 
@@ -1972,6 +2038,8 @@ declare class FullCompaction {
1972
2038
  blockedByTurn: boolean;
1973
2039
  } | null;
1974
2040
  private readonly observedMaxContextTokensByModel;
2041
+ private lastCompactedTokenCount;
2042
+ private consecutiveOverflowCompactions;
1975
2043
  protected readonly strategy: CompactionStrategy;
1976
2044
  constructor(agent: Agent, strategy?: CompactionStrategy);
1977
2045
  get isCompacting(): boolean;
@@ -1992,10 +2060,11 @@ declare class FullCompaction {
1992
2060
  private beginAutoCompaction;
1993
2061
  private block;
1994
2062
  private compactionWorker;
2063
+ private buildInstruction;
2064
+ private postProcessSummary;
1995
2065
  private compactionRound;
1996
2066
  private triggerPreCompactHook;
1997
2067
  private triggerPostCompactHook;
1998
- private postProcessSummary;
1999
2068
  }
2000
2069
 
2001
2070
  /**
@@ -2059,11 +2128,23 @@ declare interface GenerateOptions {
2059
2128
  * provider adapter's generate call.
2060
2129
  */
2061
2130
  onRequestStart?: () => void;
2131
+ /**
2132
+ * Host-side instrumentation hook fired by the provider adapter immediately
2133
+ * before it dispatches the network request to the upstream API. The window
2134
+ * between {@link onRequestStart} and this hook is in-process request-building
2135
+ * time (message serialization, param assembly) spent by the client; the
2136
+ * window between this hook and the first streamed part is network + server
2137
+ * time. Splitting time-to-first-token across this boundary lets hosts
2138
+ * attribute latency to the client vs. the API server.
2139
+ */
2140
+ onRequestSent?: () => void;
2062
2141
  /**
2063
2142
  * Host-side instrumentation hook fired after the provider stream is fully
2064
- * drained, before post-processing the assembled response.
2143
+ * drained, before post-processing the assembled response. Receives the
2144
+ * {@link StreamDecodeStats} accounting accumulated across the stream when at
2145
+ * least one part was streamed, or `undefined` for an empty stream.
2065
2146
  */
2066
- onStreamEnd?: () => void;
2147
+ onStreamEnd?: (stats?: StreamDecodeStats) => void;
2067
2148
  }
2068
2149
 
2069
2150
  /**
@@ -2109,7 +2190,6 @@ declare interface GenerationKwargs {
2109
2190
  presence_penalty?: number | undefined;
2110
2191
  frequency_penalty?: number | undefined;
2111
2192
  stop?: string | string[] | undefined;
2112
- reasoning_effort?: string | undefined;
2113
2193
  prompt_cache_key?: string | undefined;
2114
2194
  extra_body?: ExtraBody;
2115
2195
  }
@@ -2528,8 +2608,19 @@ declare class InjectionManager {
2528
2608
  * mode is off, the agent is not the main agent, or there is nothing to inject.
2529
2609
  */
2530
2610
  injectGoal(): Promise<void>;
2611
+ injectAfterCompaction(): Promise<void>;
2612
+ /**
2613
+ * Post-compaction only: re-surface still-running background tasks. Folding the
2614
+ * live context to [recent user prompts, summary] drops the messages that
2615
+ * started them and their status updates, so without this the model can forget
2616
+ * a task is running and spawn a duplicate. Appended as an `injection`-origin
2617
+ * reminder, so the next compaction drops and rebuilds it — kept fresh, never
2618
+ * stacked. Runs only on the live path: restore replays the persisted reminder
2619
+ * and `FullCompaction.begin` short-circuits before compaction there.
2620
+ */
2621
+ private injectActiveBackgroundTasks;
2531
2622
  onContextClear(): void;
2532
- onContextCompacted(compactedCount: number): void;
2623
+ onContextCompacted(): void;
2533
2624
  onContextMessageRemoved(index: number): void;
2534
2625
  /** Per-step injectors plus the boundary goal injector, for lifecycle events. */
2535
2626
  private lifecycleInjectors;
@@ -3167,19 +3258,16 @@ declare const KimiConfigPatchSchema: z.ZodObject<{
3167
3258
  reasoningKey: z.ZodOptional<z.ZodOptional<z.ZodString>>;
3168
3259
  protocol: z.ZodOptional<z.ZodOptional<z.ZodLiteral<"anthropic">>>;
3169
3260
  adaptiveThinking: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
3261
+ supportEfforts: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString>>>;
3262
+ defaultEffort: z.ZodOptional<z.ZodOptional<z.ZodString>>;
3170
3263
  betaApi: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
3171
3264
  }, z.core.$strip>>>;
3172
3265
  thinking: z.ZodOptional<z.ZodObject<{
3173
- mode: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
3174
- off: "off";
3175
- auto: "auto";
3176
- on: "on";
3177
- }>>>;
3266
+ enabled: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
3178
3267
  effort: z.ZodOptional<z.ZodOptional<z.ZodString>>;
3179
3268
  }, z.core.$strip>>;
3180
3269
  planMode: z.ZodOptional<z.ZodBoolean>;
3181
3270
  yolo: z.ZodOptional<z.ZodBoolean>;
3182
- defaultThinking: z.ZodOptional<z.ZodBoolean>;
3183
3271
  defaultPermissionMode: z.ZodOptional<z.ZodEnum<{
3184
3272
  auto: "auto";
3185
3273
  manual: "manual";
@@ -3326,19 +3414,16 @@ declare const KimiConfigSchema: z.ZodObject<{
3326
3414
  reasoningKey: z.ZodOptional<z.ZodString>;
3327
3415
  protocol: z.ZodOptional<z.ZodLiteral<"anthropic">>;
3328
3416
  adaptiveThinking: z.ZodOptional<z.ZodBoolean>;
3417
+ supportEfforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
3418
+ defaultEffort: z.ZodOptional<z.ZodString>;
3329
3419
  betaApi: z.ZodOptional<z.ZodBoolean>;
3330
3420
  }, z.core.$strip>>>;
3331
3421
  thinking: z.ZodOptional<z.ZodObject<{
3332
- mode: z.ZodOptional<z.ZodEnum<{
3333
- off: "off";
3334
- auto: "auto";
3335
- on: "on";
3336
- }>>;
3422
+ enabled: z.ZodOptional<z.ZodBoolean>;
3337
3423
  effort: z.ZodOptional<z.ZodString>;
3338
3424
  }, z.core.$strip>>;
3339
3425
  planMode: z.ZodOptional<z.ZodBoolean>;
3340
3426
  yolo: z.ZodOptional<z.ZodBoolean>;
3341
- defaultThinking: z.ZodOptional<z.ZodBoolean>;
3342
3427
  defaultPermissionMode: z.ZodOptional<z.ZodEnum<{
3343
3428
  auto: "auto";
3344
3429
  manual: "manual";
@@ -3516,6 +3601,7 @@ declare class KimiCore implements PromisableMethods<CoreAPI> {
3516
3601
  detachBackground({ sessionId, ...payload }: SessionAgentPayload<DetachBackgroundPayload>): Promise<BackgroundTaskInfo | undefined>;
3517
3602
  clearContext({ sessionId, ...payload }: SessionAgentPayload<EmptyPayload>): Promise<void>;
3518
3603
  activateSkill({ sessionId, ...payload }: SessionAgentPayload<ActivateSkillPayload>): Promise<void>;
3604
+ activatePluginCommand({ sessionId, ...payload }: SessionAgentPayload<ActivatePluginCommandPayload>): Promise<void>;
3519
3605
  getBackgroundOutput({ sessionId, ...payload }: SessionAgentPayload<GetBackgroundOutputPayload>): Promise<string>;
3520
3606
  getContext({ sessionId, ...payload }: SessionAgentPayload<EmptyPayload>): Promise<AgentContextData>;
3521
3607
  getConfig({ sessionId, ...payload }: SessionAgentPayload<EmptyPayload>): Promise<AgentConfigData>;
@@ -3527,6 +3613,7 @@ declare class KimiCore implements PromisableMethods<CoreAPI> {
3527
3613
  updateSessionMetadata({ sessionId, ...payload }: UpdateSessionMetadataRequest): Promise<void>;
3528
3614
  getSessionMetadata({ sessionId, ...payload }: SessionScopedPayload<EmptyPayload>): SessionMeta;
3529
3615
  listSkills({ sessionId, ...payload }: SessionScopedPayload<EmptyPayload>): Promise<readonly SkillSummary[]>;
3616
+ listPluginCommands({ sessionId, ...payload }: SessionScopedPayload<EmptyPayload>): readonly PluginCommandDef[];
3530
3617
  listMcpServers({ sessionId, ...payload }: SessionScopedPayload<EmptyPayload>): readonly McpServerInfo[];
3531
3618
  getMcpStartupMetrics({ sessionId, ...payload }: SessionScopedPayload<EmptyPayload>): Promise<McpStartupMetrics>;
3532
3619
  reconnectMcpServer({ sessionId, ...payload }: SessionScopedPayload<ReconnectMcpServerPayload>): Promise<void>;
@@ -3740,6 +3827,10 @@ declare interface KimiOptions {
3740
3827
  stream?: boolean | undefined;
3741
3828
  defaultHeaders?: Record<string, string> | undefined;
3742
3829
  generationKwargs?: GenerationKwargs | undefined;
3830
+ /** Efforts the model advertises (e.g. ["low", "high", "max"]). When
3831
+ * present and non-empty, withThinking sends the chosen effort on the wire;
3832
+ * when absent/empty, only thinking.type is sent. */
3833
+ supportEfforts?: readonly string[] | undefined;
3743
3834
  clientFactory?: (auth: ProviderRequestAuth) => OpenAI;
3744
3835
  }
3745
3836
 
@@ -3852,6 +3943,27 @@ declare class LlmRequestLogger {
3852
3943
  declare interface LLMStreamTiming {
3853
3944
  readonly firstTokenLatencyMs: number;
3854
3945
  readonly streamDurationMs: number;
3946
+ /**
3947
+ * Portion of `firstTokenLatencyMs` spent in-process building the request
3948
+ * (message serialization, param assembly) before the provider dispatched the
3949
+ * network call. `undefined` when the provider does not report the
3950
+ * client/server boundary (no `onRequestSent`).
3951
+ */
3952
+ readonly requestBuildMs?: number;
3953
+ /**
3954
+ * Portion of `firstTokenLatencyMs` spent waiting on the network + API server
3955
+ * from request dispatch to the first streamed token. `undefined` when the
3956
+ * provider does not report the client/server boundary.
3957
+ */
3958
+ readonly serverFirstTokenMs?: number;
3959
+ /**
3960
+ * Split of `streamDurationMs` (the decode window): time spent awaiting parts
3961
+ * from the provider (`serverDecodeMs`, server + network) vs. time spent
3962
+ * processing parts in-process (`clientConsumeMs`, host callbacks / merge).
3963
+ * `undefined` when the provider stream did not report decode accounting.
3964
+ */
3965
+ readonly serverDecodeMs?: number;
3966
+ readonly clientConsumeMs?: number;
3855
3967
  }
3856
3968
 
3857
3969
  /**
@@ -3968,6 +4080,20 @@ declare interface LoopStepEndEvent {
3968
4080
  readonly finishReason?: LoopStepStopReason | undefined;
3969
4081
  readonly llmFirstTokenLatencyMs?: number | undefined;
3970
4082
  readonly llmStreamDurationMs?: number | undefined;
4083
+ /**
4084
+ * Split of `llmFirstTokenLatencyMs`: in-process request-building time on the
4085
+ * client vs. network + API-server time to the first token. Both `undefined`
4086
+ * when the provider does not report the client/server boundary.
4087
+ */
4088
+ readonly llmRequestBuildMs?: number | undefined;
4089
+ readonly llmServerFirstTokenMs?: number | undefined;
4090
+ /**
4091
+ * Split of `llmStreamDurationMs` (the decode window): time awaiting parts
4092
+ * from the provider vs. time processing parts in-process. Both `undefined`
4093
+ * when the provider stream did not report decode accounting.
4094
+ */
4095
+ readonly llmServerDecodeMs?: number | undefined;
4096
+ readonly llmClientConsumeMs?: number | undefined;
3971
4097
  /**
3972
4098
  * Provider diagnostics are optional and must not drive loop control.
3973
4099
  * Use `finishReason` for normalized behavior.
@@ -4442,6 +4568,8 @@ declare const ModelAliasSchema: z.ZodObject<{
4442
4568
  reasoningKey: z.ZodOptional<z.ZodString>;
4443
4569
  protocol: z.ZodOptional<z.ZodLiteral<"anthropic">>;
4444
4570
  adaptiveThinking: z.ZodOptional<z.ZodBoolean>;
4571
+ supportEfforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
4572
+ defaultEffort: z.ZodOptional<z.ZodString>;
4445
4573
  betaApi: z.ZodOptional<z.ZodBoolean>;
4446
4574
  }, z.core.$strip>;
4447
4575
 
@@ -4719,6 +4847,38 @@ declare interface PluginCapabilityState {
4719
4847
  readonly mcpServers?: Readonly<Record<string, PluginMcpServerState>>;
4720
4848
  }
4721
4849
 
4850
+ export { PluginCommandActivatedEvent }
4851
+
4852
+ export declare interface PluginCommandDef {
4853
+ readonly pluginId: string;
4854
+ readonly name: string;
4855
+ readonly description: string;
4856
+ readonly body: string;
4857
+ readonly path: string;
4858
+ }
4859
+
4860
+ /**
4861
+ * A resolved command file plus its namespace-preserving name.
4862
+ *
4863
+ * `name` is the path of the file relative to the declared `commands` entry
4864
+ * (without the `.md` extension, using `/` separators), so a file at
4865
+ * `commands/frontend/component.md` yields the name `frontend/component`.
4866
+ * Frontmatter `name` in the file itself takes precedence over this at load time.
4867
+ */
4868
+ declare interface PluginCommandEntry {
4869
+ readonly path: string;
4870
+ readonly name: string;
4871
+ }
4872
+
4873
+ declare interface PluginCommandOrigin {
4874
+ readonly kind: 'plugin_command';
4875
+ readonly activationId: string;
4876
+ readonly pluginId: string;
4877
+ readonly commandName: string;
4878
+ readonly commandArgs?: string | undefined;
4879
+ readonly trigger: 'user-slash';
4880
+ }
4881
+
4722
4882
  declare interface PluginDiagnostic {
4723
4883
  readonly severity: PluginDiagnosticSeverity;
4724
4884
  readonly message: string;
@@ -4774,6 +4934,7 @@ declare class PluginManager {
4774
4934
  enabledSessionStarts(): readonly EnabledPluginSessionStart[];
4775
4935
  enabledMcpServers(): Record<string, McpServerConfig>;
4776
4936
  enabledHooks(): readonly HookDef[];
4937
+ enabledCommands(): Promise<readonly PluginCommandDef[]>;
4777
4938
  summaries(): readonly PluginSummary[];
4778
4939
  info(id: string): PluginInfo | undefined;
4779
4940
  private persist;
@@ -4796,6 +4957,7 @@ declare interface PluginManifest {
4796
4957
  readonly sessionStart?: PluginSessionStart;
4797
4958
  readonly mcpServers?: Readonly<Record<string, McpServerConfig>>;
4798
4959
  readonly hooks?: readonly HookDefConfig[];
4960
+ readonly commands?: readonly PluginCommandEntry[];
4799
4961
  readonly interface?: PluginInterface;
4800
4962
  readonly skillInstructions?: string;
4801
4963
  }
@@ -4857,6 +5019,7 @@ export declare interface PluginSummary {
4857
5019
  readonly mcpServerCount: number;
4858
5020
  readonly enabledMcpServerCount: number;
4859
5021
  readonly hookCount: number;
5022
+ readonly commandCount: number;
4860
5023
  readonly hasErrors: boolean;
4861
5024
  readonly source: PluginSource;
4862
5025
  readonly originalSource?: string;
@@ -4883,6 +5046,99 @@ export declare interface ProcessBackgroundTaskInfo extends BackgroundTaskInfoBas
4883
5046
  readonly exitCode: number | null;
4884
5047
  }
4885
5048
 
5049
+ /**
5050
+ * A repair the projector applied to make the history wire-valid. Each one means
5051
+ * the stored history was not directly sendable to a strict provider.
5052
+ */
5053
+ declare type ProjectionAnomaly =
5054
+ /** A recorded result was not adjacent to its call and had to be moved up. */
5055
+ {
5056
+ readonly kind: 'tool_result_reordered';
5057
+ readonly toolCallId: string;
5058
+ }
5059
+ /**
5060
+ * No result existed for a call, so a placeholder was synthesized. `trailing`
5061
+ * is true when it closed a still-open tail call (expected under
5062
+ * `synthesizeMissing`), false when it closed a mid-history orphan whose result
5063
+ * was lost (a genuine defect worth investigating).
5064
+ */
5065
+ | {
5066
+ readonly kind: 'tool_result_synthesized';
5067
+ readonly toolCallId: string;
5068
+ readonly trailing: boolean;
5069
+ }
5070
+ /** A result with no matching call anywhere was dropped (strict resend only). */
5071
+ | {
5072
+ readonly kind: 'orphan_tool_result_dropped';
5073
+ readonly toolCallId: string;
5074
+ }
5075
+ /** A leading non-user message was dropped so the first turn is user (strict). */
5076
+ | {
5077
+ readonly kind: 'leading_non_user_dropped';
5078
+ readonly role: string;
5079
+ }
5080
+ /** Two adjacent assistant turns were merged into one (strict). */
5081
+ | {
5082
+ readonly kind: 'consecutive_assistants_merged';
5083
+ }
5084
+ /** A non-empty but all-whitespace text block was dropped (always). */
5085
+ | {
5086
+ readonly kind: 'whitespace_text_dropped';
5087
+ readonly role: string;
5088
+ };
5089
+
5090
+ declare interface ProjectOptions {
5091
+ /**
5092
+ * When `true`, emit a synthetic `tool_result` for *every* assistant `tool_use`
5093
+ * whose result is not present in the provided messages — including a trailing,
5094
+ * still-in-flight call. Used by full compaction, where the compacted prefix is
5095
+ * a slice that may exclude a delayed result preserved in the retained tail; the
5096
+ * synthetic result keeps the exchange closed so the summary request is not
5097
+ * rejected. Leave `false` for normal turns: a *trailing* missing result there
5098
+ * means the call is still in-flight and must not be closed prematurely. (A
5099
+ * *non-trailing* missing result is always closed regardless of this flag — see
5100
+ * `repairToolExchangeAdjacency` — because a later turn proves it is not
5101
+ * in-flight.)
5102
+ */
5103
+ readonly synthesizeMissing?: boolean;
5104
+ /**
5105
+ * When `true`, drop any `tool_result` whose `toolCallId` matches no assistant
5106
+ * `tool_use` anywhere in the provided messages. Strict providers reject such a
5107
+ * stray result as an "unexpected `tool_result`". Off by default so the normal
5108
+ * path never silently discards recorded output; the post-400 strict-resend
5109
+ * fallback enables it (together with `synthesizeMissing`) as a last resort to
5110
+ * force a wire-compliant request out of an otherwise-bricked session.
5111
+ */
5112
+ readonly dropOrphanResults?: boolean;
5113
+ /**
5114
+ * When `true`, drop leading messages until the first one is a user turn. Strict
5115
+ * providers require the first message to be `user`; a history that (after
5116
+ * dropping/compaction) starts with an assistant or tool message is rejected.
5117
+ * Strict-resend only — the normal path keeps the original opening.
5118
+ */
5119
+ readonly dropLeadingNonUser?: boolean;
5120
+ /**
5121
+ * When `true`, merge back-to-back assistant messages into one. Strict providers
5122
+ * reject consecutive same-role turns ("roles must alternate"); consecutive user
5123
+ * turns are already merged at the provider boundary, but consecutive assistant
5124
+ * turns are not. Strict-resend only. Content is concatenated verbatim — callers
5125
+ * must not rely on this when extended-thinking ordering matters, but two
5126
+ * consecutive assistant turns do not arise in well-formed transcripts.
5127
+ */
5128
+ readonly mergeConsecutiveAssistants?: boolean;
5129
+ /**
5130
+ * Optional sink invoked for every repair the projector applies to keep the
5131
+ * outgoing wire valid: a displaced result moved back next to its call, a
5132
+ * synthetic result invented for a missing one, a stray result dropped, a
5133
+ * leading non-user message dropped, or consecutive assistants merged. The
5134
+ * projection itself stays a pure transform; the caller decides whether/how to
5135
+ * surface these (the context logs them so a silently-mangled history is never
5136
+ * papered over without a trace). Not called when the history is already
5137
+ * well-formed.
5138
+ */
5139
+ readonly onAnomaly?: (anomaly: ProjectionAnomaly) => void;
5140
+ }
5141
+
4886
5142
  declare type Promisable<T> = [T] extends [Promise<any>] ? T | Awaited<T> : T | Promise<T>;
4887
5143
 
4888
5144
  declare type PromisableMethods<T> = {
@@ -4893,7 +5149,7 @@ declare type Promisify<T> = [T] extends [Promise<any>] ? T : Promise<T>;
4893
5149
 
4894
5150
  export declare type PromptInput = readonly PromptPart[];
4895
5151
 
4896
- export declare type PromptOrigin = UserPromptOrigin | SkillActivationOrigin | InjectionOrigin | ShellCommandOrigin | CompactionSummaryOrigin | SystemTriggerOrigin | BackgroundTaskOrigin | CronJobOrigin | CronMissedOrigin | HookResultOrigin | RetryOrigin;
5152
+ export declare type PromptOrigin = UserPromptOrigin | SkillActivationOrigin | PluginCommandOrigin | InjectionOrigin | ShellCommandOrigin | CompactionSummaryOrigin | SystemTriggerOrigin | BackgroundTaskOrigin | CronJobOrigin | CronMissedOrigin | HookResultOrigin | RetryOrigin;
4897
5153
 
4898
5154
  export declare type PromptPart = Extract<ContentPart, {
4899
5155
  type: 'text' | 'image_url' | 'video_url';
@@ -5404,6 +5660,7 @@ export declare abstract class SDKRpcClientBase {
5404
5660
  getUsage(input: SessionIdRpcInput): Promise<SessionUsage>;
5405
5661
  getStatus(input: SessionIdRpcInput): Promise<SessionStatus>;
5406
5662
  listSkills(input: SessionIdRpcInput): Promise<readonly SkillSummary[]>;
5663
+ listPluginCommands(input: SessionIdRpcInput): Promise<readonly PluginCommandDef[]>;
5407
5664
  listBackgroundTasks(input: SessionIdRpcInput & {
5408
5665
  activeOnly?: boolean;
5409
5666
  limit?: number;
@@ -5435,6 +5692,7 @@ export declare abstract class SDKRpcClientBase {
5435
5692
  reloadPlugins(): Promise<ReloadSummary>;
5436
5693
  getPluginInfo(id: string): Promise<PluginInfo>;
5437
5694
  activateSkill(input: ActivateSkillRpcInput): Promise<void>;
5695
+ activatePluginCommand(input: ActivatePluginCommandRpcInput): Promise<void>;
5438
5696
  onEvent(listener: (event: Event_2) => void): Unsubscribe;
5439
5697
  receiveEvent(event: Event_2): void;
5440
5698
  setApprovalHandler(sessionId: string, handler: ApprovalHandler | undefined): void;
@@ -5536,7 +5794,7 @@ export declare class Session {
5536
5794
  startBtw(): Promise<string>;
5537
5795
  cancel(): Promise<void>;
5538
5796
  setModel(model: string): Promise<void>;
5539
- setThinking(level: string): Promise<void>;
5797
+ setThinking(effort: ThinkingEffort): Promise<void>;
5540
5798
  setPermission(mode: PermissionMode): Promise<void>;
5541
5799
  setPlanMode(enabled: boolean): Promise<void>;
5542
5800
  setSwarmMode(enabled: boolean, trigger: SwarmModeTrigger): Promise<void>;
@@ -5549,6 +5807,7 @@ export declare class Session {
5549
5807
  getUsage(): Promise<SessionUsage>;
5550
5808
  getStatus(): Promise<SessionStatus>;
5551
5809
  listSkills(): Promise<readonly SkillSummary[]>;
5810
+ listPluginCommands(): Promise<readonly PluginCommandDef[]>;
5552
5811
  /**
5553
5812
  * List background tasks for this session's interactive agent.
5554
5813
  *
@@ -5599,6 +5858,7 @@ export declare class Session {
5599
5858
  reloadPlugins(): Promise<ReloadSummary>;
5600
5859
  getPluginInfo(id: string): Promise<PluginInfo>;
5601
5860
  activateSkill(name: string, args?: string | undefined): Promise<void>;
5861
+ activatePluginCommand(pluginId: string, commandName: string, args?: string | undefined): Promise<void>;
5602
5862
  close(): Promise<void>;
5603
5863
  /** @internal */
5604
5864
  emitMetaUpdated(patch: {
@@ -5623,6 +5883,7 @@ declare class Session_2 {
5623
5883
  private toolKaos;
5624
5884
  private persistenceKaos;
5625
5885
  private additionalDirs;
5886
+ private readonly pluginCommands;
5626
5887
  private agentIdCounter;
5627
5888
  private readonly skillsReady;
5628
5889
  metadata: SessionMeta;
@@ -5689,6 +5950,7 @@ declare class Session_2 {
5689
5950
  readMetadata(): Promise<SessionMeta>;
5690
5951
  flushMetadata(): Promise<void>;
5691
5952
  listSkills(): Promise<readonly SkillSummary_2[]>;
5953
+ listPluginCommands(): readonly PluginCommandDef[];
5692
5954
  private loadSkills;
5693
5955
  private loadMcpServers;
5694
5956
  private emitInitialMcpLoadError;
@@ -5701,6 +5963,8 @@ declare class Session_2 {
5701
5963
  private resolveAgentEntry;
5702
5964
  private resumeAgent;
5703
5965
  private resumePersistedAgent;
5966
+ private restoreAgentProfileHandle;
5967
+ private resolvePersistedProfile;
5704
5968
  private nextGeneratedAgentId;
5705
5969
  private requireMainAgent;
5706
5970
  private triggerSessionStart;
@@ -5714,6 +5978,7 @@ declare interface SessionAPI extends AgentAPIWithId {
5714
5978
  updateSessionMetadata: (payload: UpdateSessionMetadataPayload) => void;
5715
5979
  getSessionMetadata: (payload: EmptyPayload) => SessionMeta;
5716
5980
  listSkills: (payload: EmptyPayload) => readonly SkillSummary[];
5981
+ listPluginCommands: (payload: EmptyPayload) => readonly PluginCommandDef[];
5717
5982
  listMcpServers: (payload: EmptyPayload) => readonly McpServerInfo[];
5718
5983
  getMcpStartupMetrics: (payload: EmptyPayload) => McpStartupMetrics;
5719
5984
  reconnectMcpServer: (payload: ReconnectMcpServerPayload) => void;
@@ -5838,6 +6103,7 @@ declare interface SessionOptions_2 {
5838
6103
  readonly mcpConfig?: SessionMcpConfig;
5839
6104
  readonly telemetry?: TelemetryClient | undefined;
5840
6105
  readonly pluginSessionStarts?: readonly EnabledPluginSessionStart[];
6106
+ readonly pluginCommands?: readonly PluginCommandDef[];
5841
6107
  readonly appVersion?: string;
5842
6108
  readonly experimentalFlags?: ExperimentalFlagResolver;
5843
6109
  readonly additionalDirs?: readonly string[];
@@ -5893,7 +6159,7 @@ declare class SessionSkillRegistry implements SkillRegistry {
5893
6159
 
5894
6160
  export declare interface SessionStatus {
5895
6161
  readonly model?: string;
5896
- readonly thinkingLevel: string;
6162
+ readonly thinkingEffort: string;
5897
6163
  readonly permission: PermissionMode;
5898
6164
  readonly planMode: boolean;
5899
6165
  readonly swarmMode?: boolean | undefined;
@@ -6019,11 +6285,11 @@ declare type SetSessionSwarmModeRpcInput = (SessionIdRpcInput & {
6019
6285
  });
6020
6286
 
6021
6287
  declare interface SetSessionThinkingRpcInput extends SessionIdRpcInput {
6022
- readonly level: string;
6288
+ readonly effort: string;
6023
6289
  }
6024
6290
 
6025
6291
  declare interface SetThinkingPayload {
6026
- readonly level: string;
6292
+ readonly effort: string;
6027
6293
  }
6028
6294
 
6029
6295
  declare interface ShellCommandOrigin {
@@ -6192,6 +6458,24 @@ declare interface StopBackgroundPayload {
6192
6458
  readonly reason?: string;
6193
6459
  }
6194
6460
 
6461
+ /**
6462
+ * Decode-phase accounting for a single streamed generation. Splits the window
6463
+ * from the first streamed part to stream end into the time spent waiting on the
6464
+ * provider for the next part (server + network) versus the time spent
6465
+ * processing each part in-process (deep copy, host callbacks, part merging).
6466
+ *
6467
+ * Because both buckets are wall-clock measured on the single JS thread, a
6468
+ * stop-the-world GC pause that lands while awaiting the next part is counted in
6469
+ * {@link serverDecodeMs}; a non-trivial {@link clientConsumeMs} share is the
6470
+ * unambiguous signal that the host's per-part processing is throttling decode.
6471
+ */
6472
+ declare interface StreamDecodeStats {
6473
+ /** Cumulative time spent awaiting the next streamed part (server + network). */
6474
+ readonly serverDecodeMs: number;
6475
+ /** Cumulative time spent processing streamed parts in-process (client). */
6476
+ readonly clientConsumeMs: number;
6477
+ }
6478
+
6195
6479
  /**
6196
6480
  * An async-iterable stream of message parts produced by a single LLM response.
6197
6481
  *
@@ -6346,31 +6630,33 @@ export declare type ThinkingConfig = z.infer<typeof ThinkingConfigSchema>;
6346
6630
 
6347
6631
  declare interface ThinkingConfig_2 {
6348
6632
  type?: 'enabled' | 'disabled';
6633
+ effort?: string;
6349
6634
  keep?: unknown;
6350
6635
  [key: string]: unknown;
6351
6636
  }
6352
6637
 
6353
6638
  declare const ThinkingConfigSchema: z.ZodObject<{
6354
- mode: z.ZodOptional<z.ZodEnum<{
6355
- off: "off";
6356
- auto: "auto";
6357
- on: "on";
6358
- }>>;
6639
+ enabled: z.ZodOptional<z.ZodBoolean>;
6359
6640
  effort: z.ZodOptional<z.ZodString>;
6360
6641
  }, z.core.$strip>;
6361
6642
 
6362
6643
  export { ThinkingDeltaEvent }
6363
6644
 
6364
6645
  /**
6365
- * Normalized thinking effort level used across providers.
6646
+ * Thinking effort passed to {@link ChatProvider.withThinking}.
6647
+ *
6648
+ * `'off'` and `'on'` are the only reserved values: `'off'` disables thinking,
6649
+ * and `'on'` is the on-signal for boolean models (models that do not declare
6650
+ * `support_efforts`). Everything else is a model-declared effort (e.g.
6651
+ * `"low"`, `"high"`, `"max"`) carried as an open string. The type collapses to
6652
+ * `string` at runtime; it exists purely as a semantic marker that a value is
6653
+ * expected to be `'off'`, `'on'`, or a model-declared effort.
6366
6654
  *
6367
- * Values above `high` are provider/model-specific and may be clamped by the
6368
- * adapter when the native API has no matching level. OpenAI maps `max` to its
6369
- * `xhigh` ceiling; Kimi and Gemini cap `xhigh`/`max` at `high`; Anthropic
6370
- * supports `xhigh`/`max` only on selected models and otherwise clamps to
6371
- * `high`.
6655
+ * The model's `support_efforts` is the single source of truth for which
6656
+ * efforts are valid providers normalize any unrecognized effort by omitting
6657
+ * the effort on the wire rather than rejecting it.
6372
6658
  */
6373
- declare type ThinkingEffort = 'off' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
6659
+ export declare type ThinkingEffort = 'off' | 'on' | (string & {});
6374
6660
 
6375
6661
  declare interface ThinkPart {
6376
6662
  type: 'think';
@@ -6697,6 +6983,16 @@ declare class TurnFlow {
6697
6983
  waitForTurnFirstRequest(): Promise<void>;
6698
6984
  private abortTurn;
6699
6985
  private flushSteerBuffer;
6986
+ /**
6987
+ * Replay inputs (prompts or steers) that were deferred while a manual compaction
6988
+ * held the context. Called by `FullCompaction` once the compaction lifecycle
6989
+ * (summary + reinjection) is done — and on cancel/failure — so deferred input is
6990
+ * never lost or stuck. If a turn is somehow already active (e.g. one that raced
6991
+ * and cancelled the compaction), let it consume the buffer like any other steer;
6992
+ * otherwise launch a fresh turn from the first buffered item, with the rest
6993
+ * draining into it via `flushSteerBuffer`.
6994
+ */
6995
+ onCompactionFinished(): void;
6700
6996
  finishResume(): void;
6701
6997
  /**
6702
6998
  * The body of the single in-flight `activeTurn`. Routes to the goal driver