@kodax-ai/kodax 0.7.40 → 0.7.42

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +146 -1
  2. package/README.md +129 -232
  3. package/README_CN.md +128 -253
  4. package/dist/chunks/chunk-3RKBXWZS.js +2 -0
  5. package/dist/chunks/chunk-7JLYVWAF.js +1033 -0
  6. package/dist/chunks/chunk-CD3R5YBH.js +16 -0
  7. package/dist/chunks/chunk-DKXUY5F2.js +209 -0
  8. package/dist/chunks/chunk-HMYEQJGT.js +31 -0
  9. package/dist/chunks/{chunk-FAVPT4P7.js → chunk-IYJ5EPRV.js} +1 -1
  10. package/dist/chunks/chunk-KUX5LRPP.js +2 -0
  11. package/dist/chunks/{chunk-EQ5DGS2W.js → chunk-OWSKU55I.js} +5 -6
  12. package/dist/chunks/chunk-ZZ4KRK2B.js +465 -0
  13. package/dist/chunks/compaction-config-FIFFP4FT.js +2 -0
  14. package/dist/chunks/{construction-bootstrap-OFPUZTXQ.js → construction-bootstrap-J2WOCYEK.js} +1 -1
  15. package/dist/chunks/dist-2ZHWDXMQ.js +2 -0
  16. package/dist/chunks/dist-W4CJWLIH.js +2 -0
  17. package/dist/chunks/utils-A5MWDTWZ.js +2 -0
  18. package/dist/index.d.ts +237 -7
  19. package/dist/index.js +5 -5
  20. package/dist/kodax_cli.js +935 -917
  21. package/dist/sdk-agent.d.ts +1375 -10
  22. package/dist/sdk-agent.js +1 -1
  23. package/dist/sdk-coding.d.ts +4608 -14
  24. package/dist/sdk-coding.js +1 -1
  25. package/dist/sdk-llm.d.ts +210 -10
  26. package/dist/sdk-llm.js +1 -1
  27. package/dist/sdk-mcp.d.ts +17 -0
  28. package/dist/sdk-mcp.js +2 -0
  29. package/dist/sdk-repl.d.ts +3026 -13
  30. package/dist/sdk-repl.js +2 -1
  31. package/dist/sdk-session.d.ts +164 -0
  32. package/dist/sdk-session.js +2 -0
  33. package/dist/sdk-skills.d.ts +553 -9
  34. package/dist/sdk-skills.js +1 -1
  35. package/dist/types-chunks/bash-prefix-extractor.d-CkhaqKkg.d.ts +2571 -0
  36. package/dist/types-chunks/capability.d-3C62G8Eq.d.ts +39 -0
  37. package/dist/types-chunks/config.d-BfJUXxC0.d.ts +41 -0
  38. package/dist/types-chunks/cost-tracker.d-B6vMoLLF.d.ts +360 -0
  39. package/dist/types-chunks/history-cleanup.d-DznrzEiU.d.ts +1475 -0
  40. package/dist/types-chunks/instance-discovery.d-BsKnIwpg.d.ts +990 -0
  41. package/dist/types-chunks/resolver.d-DX9au4NJ.d.ts +263 -0
  42. package/dist/types-chunks/session-storage.d-Cci897iM.d.ts +68 -0
  43. package/dist/types-chunks/storage.d-Bc5DoAwp.d.ts +532 -0
  44. package/dist/types-chunks/transport.d-DuyjG30t.d.ts +180 -0
  45. package/dist/types-chunks/types.d-B1uGoVTE.d.ts +400 -0
  46. package/dist/types-chunks/types.d-C5mHR87z.d.ts +119 -0
  47. package/dist/types-chunks/types.d-mM8vqvhT.d.ts +254 -0
  48. package/package.json +16 -3
  49. package/dist/acp_events.d.ts +0 -109
  50. package/dist/acp_logger.d.ts +0 -20
  51. package/dist/acp_server.d.ts +0 -92
  52. package/dist/chunks/chunk-6QO6HWGU.js +0 -30
  53. package/dist/chunks/chunk-CLS57NPX.js +0 -460
  54. package/dist/chunks/chunk-NDNILSTR.js +0 -2
  55. package/dist/chunks/chunk-QZEDWITG.js +0 -1226
  56. package/dist/chunks/chunk-Z5EBDA6R.js +0 -15
  57. package/dist/chunks/compaction-config-A7XZ6H5Y.js +0 -2
  58. package/dist/chunks/dist-M57GIWR4.js +0 -2
  59. package/dist/chunks/dist-OTUF22DA.js +0 -2
  60. package/dist/chunks/utils-DFMYJUTE.js +0 -2
  61. package/dist/cli_commands.d.ts +0 -17
  62. package/dist/cli_option_helpers.d.ts +0 -49
  63. package/dist/cli_option_helpers.test.d.ts +0 -1
  64. package/dist/constructed_cli.d.ts +0 -82
  65. package/dist/constructed_cli.test.d.ts +0 -1
  66. package/dist/kodax_cli.d.ts +0 -7
  67. package/dist/self_modify_cli.d.ts +0 -81
  68. package/dist/self_modify_cli.test.d.ts +0 -9
  69. package/dist/skill_cli.d.ts +0 -15
  70. package/dist/skill_cli.test.d.ts +0 -1
@@ -0,0 +1,180 @@
1
+ import { a as McpServerConfig, b as McpServersConfig } from './config.d-BfJUXxC0.js';
2
+ import { a as CapabilityProvider, C as CapabilityKind, b as CapabilityResult } from './capability.d-3C62G8Eq.js';
3
+
4
+ type McpCapabilityKind = 'tool' | 'resource' | 'prompt';
5
+ type McpCapabilityRisk = 'read' | 'write' | 'network' | 'exec';
6
+ interface McpCatalogItem {
7
+ id: string;
8
+ serverId: string;
9
+ kind: McpCapabilityKind;
10
+ name: string;
11
+ title?: string;
12
+ summary: string;
13
+ tags?: string[];
14
+ risk?: McpCapabilityRisk;
15
+ annotations?: Record<string, unknown>;
16
+ cachedAt: string;
17
+ }
18
+ interface McpCapabilityDescriptor extends McpCatalogItem {
19
+ inputSchema?: unknown;
20
+ outputSchema?: unknown;
21
+ promptArgsSchema?: unknown;
22
+ uri?: string;
23
+ mimeType?: string;
24
+ }
25
+ interface McpServerCatalogSnapshot {
26
+ serverId: string;
27
+ items: McpCatalogItem[];
28
+ descriptors: McpCapabilityDescriptor[];
29
+ updatedAt: string;
30
+ }
31
+ interface McpCatalogSearchOptions {
32
+ kind?: McpCapabilityKind;
33
+ limit?: number;
34
+ }
35
+ declare function defaultMcpCacheDir(): string;
36
+ declare function createMcpCapabilityId(serverId: string, kind: McpCapabilityKind, name: string): string;
37
+ declare function parseMcpCapabilityId(id: string): {
38
+ serverId: string;
39
+ kind: McpCapabilityKind;
40
+ name: string;
41
+ };
42
+ declare function searchMcpCatalog(items: readonly McpCatalogItem[], query: string, options?: McpCatalogSearchOptions): McpCatalogItem[];
43
+ declare function getMcpCachePaths(cacheDir: string, serverId: string): {
44
+ catalogDir: string;
45
+ indexPath: string;
46
+ itemsPath: string;
47
+ };
48
+
49
+ interface McpServerRuntimeDiagnostics {
50
+ serverId: string;
51
+ connect: 'lazy' | 'prewarm' | 'disabled';
52
+ status: 'idle' | 'connecting' | 'ready' | 'error' | 'disabled';
53
+ dirty: boolean;
54
+ lastError?: string;
55
+ cachedAt?: string;
56
+ tools: number;
57
+ resources: number;
58
+ prompts: number;
59
+ }
60
+ declare class McpServerRuntime {
61
+ private readonly serverId;
62
+ private readonly config;
63
+ private readonly cacheDir;
64
+ private transport?;
65
+ private readonly pending;
66
+ private nextRequestId;
67
+ private initialized;
68
+ private connectPromise?;
69
+ private catalog?;
70
+ private diagnostics;
71
+ constructor(serverId: string, config: McpServerConfig, cacheDir: string);
72
+ getDiagnostics(): McpServerRuntimeDiagnostics;
73
+ prewarmIfNeeded(): Promise<void>;
74
+ /** Load catalog from memory or disk only — never triggers a lazy connection. */
75
+ getCachedCatalog(): Promise<McpServerCatalogSnapshot | undefined>;
76
+ getCatalog(forceRefresh?: boolean): Promise<McpServerCatalogSnapshot>;
77
+ describeCapability(capabilityId: string): Promise<McpCapabilityDescriptor | undefined>;
78
+ callTool(name: string, args: Record<string, unknown>): Promise<{
79
+ content?: string;
80
+ structuredContent?: unknown;
81
+ metadata?: Record<string, unknown>;
82
+ }>;
83
+ readResource(name: string, options: Record<string, unknown>): Promise<{
84
+ content?: string;
85
+ structuredContent?: unknown;
86
+ metadata?: Record<string, unknown>;
87
+ }>;
88
+ getPrompt(name: string, args: Record<string, unknown>): Promise<unknown>;
89
+ refreshCatalog(forceReconnect?: boolean): Promise<void>;
90
+ /** Public teardown — clears everything including the connect lock. */
91
+ dispose(): Promise<void>;
92
+ /** Internal transport teardown — does NOT clear connectPromise so the
93
+ * retry loop inside doConnect() can safely call it between attempts. */
94
+ private resetTransport;
95
+ private connect;
96
+ private doConnect;
97
+ private listDescriptors;
98
+ private request;
99
+ private notify;
100
+ private handleMessage;
101
+ private failPending;
102
+ private applyCatalogSnapshot;
103
+ }
104
+
105
+ /**
106
+ * `McpCapabilityProvider` — implements the Layer A `CapabilityProvider`
107
+ * contract for an MCP server fleet.
108
+ *
109
+ * FEATURE_082 (v0.7.24): moved from
110
+ * `@kodax-ai/coding/src/capabilities/providers/mcp/provider.ts` to this package.
111
+ * The coding-specific `registerConfiguredMcpCapabilityProvider` adapter (which
112
+ * pulls in `KodaXExtensionRuntime`) lives in
113
+ * `@kodax-ai/coding/src/capabilities/providers/mcp-adapter.ts`.
114
+ */
115
+
116
+ interface McpProviderOptions {
117
+ cacheDir?: string;
118
+ }
119
+ declare class McpCapabilityProvider implements CapabilityProvider {
120
+ readonly id = "mcp";
121
+ readonly kinds: CapabilityProvider['kinds'];
122
+ private readonly runtimes;
123
+ private readonly cacheDir;
124
+ /**
125
+ * Construct an MCP capability provider.
126
+ *
127
+ * **Cache-dir capture warning (v0.7.35.1 FEATURE_145)** — when
128
+ * `options.cacheDir` is omitted, this constructor resolves
129
+ * `defaultMcpCacheDir()` ONCE at instantiation time and threads the
130
+ * result into every `McpServerRuntime` it spawns. If a substrate
131
+ * consumer plans to redirect the agent config home via
132
+ * `setAgentConfigHome()` from `@kodax-ai/agent`, that call MUST happen
133
+ * BEFORE constructing this provider. Late calls have no effect on
134
+ * already-constructed runtimes.
135
+ *
136
+ * To bypass the agent-home resolver entirely, pass
137
+ * `options.cacheDir` explicitly — that path wins unconditionally.
138
+ */
139
+ constructor(servers: McpServersConfig | undefined, options?: McpProviderOptions);
140
+ hasActiveServers(): boolean;
141
+ prewarm(): Promise<void>;
142
+ search(query: string, options?: {
143
+ kind?: CapabilityKind;
144
+ limit?: number;
145
+ server?: string;
146
+ }): Promise<unknown[]>;
147
+ describe(id: string): Promise<unknown>;
148
+ execute(id: string, input: Record<string, unknown>): Promise<CapabilityResult>;
149
+ read(id: string, options?: Record<string, unknown>): Promise<CapabilityResult>;
150
+ getPrompt(id: string, args?: Record<string, unknown>): Promise<unknown>;
151
+ getPromptContext(): Promise<string | undefined>;
152
+ getDiagnostics(): Record<string, unknown> | undefined;
153
+ refresh(): Promise<void>;
154
+ dispose(): Promise<void>;
155
+ private collectCatalogItems;
156
+ private listServerDiagnostics;
157
+ private requireRuntime;
158
+ }
159
+
160
+ interface McpTransportEvents {
161
+ /** Called with a complete JSON-RPC message (raw JSON string). */
162
+ onMessage(raw: string): void;
163
+ onError(error: Error): void;
164
+ onClose(reason: string): void;
165
+ }
166
+ interface McpTransport {
167
+ open(events: McpTransportEvents): Promise<void>;
168
+ /** Send a JSON string. The transport handles framing. */
169
+ send(json: string): Promise<void>;
170
+ close(): Promise<void>;
171
+ readonly connected: boolean;
172
+ }
173
+ type StdioFraming = 'content-length' | 'ndjson';
174
+ interface McpTransportOptions {
175
+ stdioFraming?: StdioFraming;
176
+ }
177
+ declare function createMcpTransport(config: McpServerConfig, options?: McpTransportOptions): McpTransport;
178
+
179
+ export { McpCapabilityProvider as b, McpServerRuntime as g, createMcpCapabilityId as k, createMcpTransport as l, defaultMcpCacheDir as m, getMcpCachePaths as n, parseMcpCapabilityId as p, searchMcpCatalog as s };
180
+ export type { McpCapabilityDescriptor as M, McpCapabilityKind as a, McpCapabilityRisk as c, McpCatalogItem as d, McpProviderOptions as e, McpServerCatalogSnapshot as f, McpServerRuntimeDiagnostics as h, McpTransport as i, McpTransportEvents as j };
@@ -0,0 +1,400 @@
1
+ /**
2
+ * KodaX AI Types
3
+ *
4
+ * AI 层类型定义 - 所有 Provider 共享的类型接口
5
+ */
6
+ interface KodaXTextBlock {
7
+ type: 'text';
8
+ text: string;
9
+ }
10
+ interface KodaXToolUseBlock {
11
+ type: 'tool_use';
12
+ id: string;
13
+ name: string;
14
+ input: Record<string, unknown>;
15
+ }
16
+ /**
17
+ * Tool-result content blocks — a structural subset of the full
18
+ * `KodaXContentBlock` union, restricted to what providers actually accept
19
+ * inside a tool_result envelope. Anthropic / OpenAI multimodal APIs accept
20
+ * text and image blocks inside tool_result; thinking / tool_use / nested
21
+ * tool_result / cache-boundary are not valid there.
22
+ *
23
+ * Carrying these as a stricter subtype (instead of the full union) lets
24
+ * provider serializers narrow without exhaustive type assertions and
25
+ * documents to tool authors what they can actually return.
26
+ */
27
+ interface KodaXToolResultTextItem {
28
+ type: 'text';
29
+ text: string;
30
+ }
31
+ interface KodaXToolResultImageItem {
32
+ type: 'image';
33
+ /** Absolute path to the image file. Provider serializers read it into base64 at wire-send time. */
34
+ path: string;
35
+ mediaType?: string;
36
+ }
37
+ type KodaXToolResultContentItem = KodaXToolResultTextItem | KodaXToolResultImageItem;
38
+ interface KodaXToolResultBlock {
39
+ type: 'tool_result';
40
+ tool_use_id: string;
41
+ /**
42
+ * Either a plain text string (backwards-compatible default) OR an array
43
+ * of content items. The array form lets multimodal-capable tools (e.g.
44
+ * `read` on an image path) emit images via tool_result, mirroring
45
+ * claudecode's `Read` tool behavior. Providers serialize each variant
46
+ * to their wire format; text-only providers (e.g. older OpenAI-compat
47
+ * gateways) downgrade image items to a placeholder rather than rejecting.
48
+ */
49
+ content: string | readonly KodaXToolResultContentItem[];
50
+ is_error?: boolean;
51
+ }
52
+ interface KodaXImageBlock {
53
+ type: 'image';
54
+ path: string;
55
+ mediaType?: string;
56
+ }
57
+ interface KodaXThinkingBlock {
58
+ type: 'thinking';
59
+ thinking: string;
60
+ signature?: string;
61
+ }
62
+ interface KodaXRedactedThinkingBlock {
63
+ type: 'redacted_thinking';
64
+ data: string;
65
+ }
66
+ /**
67
+ * FEATURE_116 (v0.7.37) — Cache boundary marker.
68
+ *
69
+ * Marks the end of a cacheable prefix in a request payload. Provider base
70
+ * classes lower this to the wire-level cache mechanism their API supports:
71
+ *
72
+ * - `KodaXAnthropicCompatProvider`: turns the marker into
73
+ * `cache_control: { type: 'ephemeral' }` on the immediately preceding
74
+ * block, then strips the marker itself.
75
+ * - `KodaXOpenAICompatProvider`: strips the marker (OpenAI / DeepSeek
76
+ * auto prefix-cache; Kimi/Zhipu/通义 self-cache via separate cache_id
77
+ * endpoint deferred to v0.7.45+).
78
+ * - `KodaXAcpProvider` (CLI bridge): strips the marker (CLI bridge does
79
+ * not touch wire; avoids leaking marker into subprocess input).
80
+ *
81
+ * Place at the suffix of any stable prefix (system prompt, tools array,
82
+ * role prompt). The marker is purely client-side: it MUST be removed
83
+ * before the request is sent over the wire.
84
+ */
85
+ interface KodaXCacheBoundary {
86
+ type: 'cache-boundary';
87
+ /** Optional hint identifying which logical region this boundary terminates. Diagnostic only. */
88
+ hint?: 'system' | 'tools' | 'role-prompt';
89
+ }
90
+ type KodaXContentBlock = KodaXTextBlock | KodaXToolUseBlock | KodaXToolResultBlock | KodaXImageBlock | KodaXThinkingBlock | KodaXRedactedThinkingBlock | KodaXCacheBoundary;
91
+ interface KodaXMessage {
92
+ role: 'user' | 'assistant' | 'system';
93
+ content: string | KodaXContentBlock[];
94
+ /** Marks messages injected by the system (auto-continue, retry prompts). Hidden in REPL display. */
95
+ _synthetic?: boolean;
96
+ }
97
+ interface KodaXTokenUsage {
98
+ inputTokens: number;
99
+ outputTokens: number;
100
+ totalTokens: number;
101
+ cachedReadTokens?: number;
102
+ cachedWriteTokens?: number;
103
+ thoughtTokens?: number;
104
+ }
105
+ interface KodaXStreamResult {
106
+ textBlocks: KodaXTextBlock[];
107
+ toolBlocks: KodaXToolUseBlock[];
108
+ thinkingBlocks: (KodaXThinkingBlock | KodaXRedactedThinkingBlock)[];
109
+ usage?: KodaXTokenUsage;
110
+ /** Provider stop reason: 'end_turn' (normal), 'max_tokens' (truncated), 'stop_sequence', 'tool_use', etc. */
111
+ stopReason?: string;
112
+ }
113
+ interface KodaXToolDefinition {
114
+ name: string;
115
+ description: string;
116
+ input_schema: {
117
+ type: 'object';
118
+ properties: Record<string, unknown>;
119
+ required?: string[];
120
+ };
121
+ }
122
+ type KodaXReasoningCapability = 'native-effort' | 'native-budget' | 'native-toggle' | 'none' | 'prompt-only' | 'unknown';
123
+ type KodaXProviderTransport = 'native-api' | 'cli-bridge';
124
+ type KodaXProviderConversationSemantics = 'full-history' | 'last-user-message';
125
+ type KodaXProviderMcpSupport = 'native' | 'none';
126
+ type KodaXProviderContextFidelity = 'full' | 'partial' | 'lossy';
127
+ type KodaXProviderToolCallingFidelity = 'full' | 'limited' | 'none';
128
+ type KodaXProviderSessionSupport = 'full' | 'limited' | 'stateless';
129
+ type KodaXProviderLongRunningSupport = 'full' | 'limited' | 'none';
130
+ type KodaXProviderMultimodalSupport = 'none' | 'image-input' | 'full';
131
+ type KodaXProviderEvidenceSupport = 'full' | 'limited' | 'none';
132
+ interface KodaXProviderCapabilityProfile {
133
+ transport: KodaXProviderTransport;
134
+ conversationSemantics: KodaXProviderConversationSemantics;
135
+ mcpSupport: KodaXProviderMcpSupport;
136
+ contextFidelity?: KodaXProviderContextFidelity;
137
+ toolCallingFidelity?: KodaXProviderToolCallingFidelity;
138
+ sessionSupport?: KodaXProviderSessionSupport;
139
+ longRunningSupport?: KodaXProviderLongRunningSupport;
140
+ multimodalSupport?: KodaXProviderMultimodalSupport;
141
+ evidenceSupport?: KodaXProviderEvidenceSupport;
142
+ }
143
+ type KodaXReasoningOverride = 'budget' | 'effort' | 'toggle' | 'none';
144
+ type KodaXReasoningMode = 'off' | 'auto' | 'quick' | 'balanced' | 'deep';
145
+ type KodaXThinkingDepth = 'off' | 'low' | 'medium' | 'high';
146
+ type KodaXTaskType = 'conversation' | 'lookup' | 'review' | 'bugfix' | 'edit' | 'refactor' | 'plan' | 'qa' | 'unknown';
147
+ type KodaXExecutionMode = 'conversation' | 'lookup' | 'pr-review' | 'strict-audit' | 'implementation' | 'planning' | 'investigation';
148
+ type KodaXRiskLevel = 'low' | 'medium' | 'high';
149
+ type KodaXTaskComplexity = 'simple' | 'moderate' | 'complex' | 'systemic';
150
+ type KodaXTaskWorkIntent = 'append' | 'overwrite' | 'new';
151
+ type KodaXTaskFamily = 'conversation' | 'lookup' | 'review' | 'implementation' | 'investigation' | 'planning' | 'ambiguous';
152
+ type KodaXTaskActionability = 'non_actionable' | 'actionable' | 'ambiguous';
153
+ type KodaXExecutionPattern = 'direct' | 'checked-direct' | 'coordinated';
154
+ type KodaXMutationSurface = 'read-only' | 'docs-only' | 'code' | 'system';
155
+ type KodaXAssuranceIntent = 'default' | 'explicit-check';
156
+ type KodaXHarnessProfile = 'H0_DIRECT' | 'H1_EXECUTE_EVAL' | 'H2_PLAN_EXECUTE_EVAL' | 'PLANNED';
157
+ type KodaXReviewScale = 'small' | 'large' | 'massive';
158
+ type KodaXAmaProfile = 'tactical' | 'managed';
159
+ type KodaXAmaTactic = 'direct' | 'child-fanout' | 'planning-pass' | 'verification-pass' | 'repair-loop';
160
+ type KodaXAmaFanoutClass = 'finding-validation' | 'evidence-scan' | 'module-triage' | 'hypothesis-check';
161
+ interface KodaXAmaFanoutPolicy {
162
+ admissible: boolean;
163
+ class?: KodaXAmaFanoutClass;
164
+ reason: string;
165
+ maxChildren?: number;
166
+ requiresReadOnly?: boolean;
167
+ }
168
+ interface KodaXAmaControllerDecision {
169
+ profile: KodaXAmaProfile;
170
+ tactics: KodaXAmaTactic[];
171
+ fanout: KodaXAmaFanoutPolicy;
172
+ reason: string;
173
+ upgradeTriggers: string[];
174
+ }
175
+ interface KodaXTaskRoutingDecision {
176
+ primaryTask: KodaXTaskType;
177
+ secondaryTask?: KodaXTaskType;
178
+ taskFamily?: KodaXTaskFamily;
179
+ actionability?: KodaXTaskActionability;
180
+ executionPattern?: KodaXExecutionPattern;
181
+ mutationSurface?: KodaXMutationSurface;
182
+ assuranceIntent?: KodaXAssuranceIntent;
183
+ confidence: number;
184
+ riskLevel: KodaXRiskLevel;
185
+ recommendedMode: KodaXExecutionMode;
186
+ recommendedThinkingDepth: KodaXThinkingDepth;
187
+ complexity: KodaXTaskComplexity;
188
+ workIntent: KodaXTaskWorkIntent;
189
+ requiresBrainstorm: boolean;
190
+ harnessProfile: KodaXHarnessProfile;
191
+ topologyCeiling?: KodaXHarnessProfile;
192
+ upgradeCeiling?: KodaXHarnessProfile;
193
+ reviewScale?: KodaXReviewScale;
194
+ reviewTarget?: 'general' | 'current-worktree' | 'compare-range';
195
+ soloBoundaryConfidence?: number;
196
+ needsIndependentQA?: boolean;
197
+ routingSource?: 'model' | 'fallback' | 'retried-model' | 'retried-fallback';
198
+ routingAttempts?: number;
199
+ routingNotes?: string[];
200
+ reason: string;
201
+ }
202
+ interface KodaXThinkingBudgetMap {
203
+ low: number;
204
+ medium: number;
205
+ high: number;
206
+ }
207
+ type KodaXTaskBudgetOverrides = Partial<Record<KodaXTaskType, Partial<KodaXThinkingBudgetMap>>>;
208
+ interface KodaXReasoningRequest {
209
+ enabled?: boolean;
210
+ mode?: KodaXReasoningMode;
211
+ depth?: KodaXThinkingDepth;
212
+ taskType?: KodaXTaskType;
213
+ executionMode?: KodaXExecutionMode;
214
+ }
215
+ interface KodaXModelDescriptor {
216
+ id: string;
217
+ displayName?: string;
218
+ contextWindow?: number;
219
+ maxOutputTokens?: number;
220
+ thinkingBudgetCap?: number;
221
+ reasoningCapability?: KodaXReasoningCapability;
222
+ /**
223
+ * Per-model override for `replayReasoningContent`. Falls through to the
224
+ * provider-level flag when undefined. Lets a single gateway endpoint
225
+ * route models that need the flag (DeepSeek V4) alongside models that
226
+ * would 400 if the flag were on (OpenAI proper).
227
+ */
228
+ replayReasoningContent?: boolean;
229
+ /**
230
+ * Per-model override for `strictThinkingSignature`. Falls through to
231
+ * the provider-level flag when undefined.
232
+ */
233
+ strictThinkingSignature?: boolean;
234
+ /**
235
+ * Per-model override for `streamMaxDurationMs`. Falls through to the
236
+ * provider-level cap when undefined; undefined at both levels disables
237
+ * the watchdog.
238
+ */
239
+ streamMaxDurationMs?: number;
240
+ }
241
+ type KodaXProtocolFamily = 'anthropic' | 'openai';
242
+ type KodaXProviderUserAgentMode = 'compat' | 'sdk';
243
+ interface KodaXCustomProviderConfig {
244
+ name: string;
245
+ protocol: KodaXProtocolFamily;
246
+ baseUrl: string;
247
+ apiKeyEnv: string;
248
+ model: string;
249
+ /**
250
+ * Additional available models beyond the default. Accepts either a
251
+ * plain model id string (legacy) or a KodaXModelDescriptor object
252
+ * (FEATURE_098) carrying per-model `contextWindow` / `maxOutputTokens`
253
+ * / `thinkingBudgetCap` / `reasoningCapability` overrides.
254
+ */
255
+ models?: Array<string | KodaXModelDescriptor>;
256
+ /**
257
+ * Controls which User-Agent header compatibility providers send.
258
+ * - compat: send "KodaX" for gateways that block the official SDK UA
259
+ * - sdk: keep the upstream SDK default User-Agent
260
+ */
261
+ userAgentMode?: KodaXProviderUserAgentMode;
262
+ supportsThinking?: boolean;
263
+ reasoningCapability?: KodaXReasoningCapability;
264
+ capabilityProfile?: KodaXProviderCapabilityProfile;
265
+ contextWindow?: number;
266
+ maxOutputTokens?: number;
267
+ thinkingBudgetCap?: number;
268
+ /**
269
+ * Provider-level default for OpenAI-compat `reasoning_content` echo.
270
+ * Required by DeepSeek V4 thinking mode (replay 400s without it).
271
+ * Defaults to false — must stay false for OpenAI proper or any gateway
272
+ * that rejects unknown fields. Per-model values in `models[]` can
273
+ * override on a model-by-model basis.
274
+ */
275
+ replayReasoningContent?: boolean;
276
+ /**
277
+ * Provider-level default for strict Anthropic thinking-signature
278
+ * verification. Only Anthropic proper cryptographically verifies
279
+ * signatures — third-party Anthropic-compat gateways must keep this
280
+ * false (default). Per-model values in `models[]` can override.
281
+ */
282
+ strictThinkingSignature?: boolean;
283
+ /**
284
+ * Provider-level default streaming wall-clock cap (ms). Set just below
285
+ * a known server-side kill window (zhipu-coding 308s → 300_000). Leave
286
+ * unset to disable the watchdog. Per-model values in `models[]` can
287
+ * override.
288
+ */
289
+ streamMaxDurationMs?: number;
290
+ }
291
+ interface KodaXProviderConfig {
292
+ apiKeyEnv: string;
293
+ baseUrl?: string;
294
+ model: string;
295
+ /** Additional available models beyond the default */
296
+ models?: readonly KodaXModelDescriptor[];
297
+ /** Compatibility providers may override the SDK User-Agent when needed. */
298
+ userAgentMode?: KodaXProviderUserAgentMode;
299
+ supportsThinking: boolean;
300
+ reasoningCapability?: KodaXReasoningCapability;
301
+ capabilityProfile?: KodaXProviderCapabilityProfile;
302
+ /** 模型的上下文窗口大小 (tokens) */
303
+ contextWindow?: number;
304
+ /** Provider 允许的最大输出 token */
305
+ maxOutputTokens?: number;
306
+ /** Provider thinking budget 上限 */
307
+ thinkingBudgetCap?: number;
308
+ /** Provider 默认 thinking budget 映射 */
309
+ defaultThinkingBudgets?: Partial<KodaXThinkingBudgetMap>;
310
+ /** 按任务类型覆盖默认 budget */
311
+ taskBudgetOverrides?: KodaXTaskBudgetOverrides;
312
+ /**
313
+ * Echo the prior turn's `reasoning_content` back on replayed assistant
314
+ * messages. Required by DeepSeek V4 thinking mode (replay 400s without it).
315
+ * Other Chinese OpenAI-compat thinking providers use the same field, but
316
+ * each needs per-provider verification before opting in. Must stay false
317
+ * for OpenAI proper.
318
+ */
319
+ replayReasoningContent?: boolean;
320
+ /**
321
+ * Strictly verify Anthropic-style `signature` on `thinking` blocks at
322
+ * serialise time. Only Anthropic proper (anthropic.com) cryptographically
323
+ * verifies signatures — third-party Anthropic-compat servers (kimi-code /
324
+ * ark-coding / mimo-coding / zhipu-coding / minimax-coding) lack the
325
+ * signing key and accept any signature.
326
+ *
327
+ * When true, thinking blocks with empty/cross-provider signatures get
328
+ * converted to a `<prior_reasoning>` text block instead of being passed
329
+ * through (which would 400 on signature verification). Cross-provider
330
+ * `redacted_thinking` blocks (ciphertext signed by their origin) are
331
+ * dropped silently — there's no plaintext to recover and forging the
332
+ * field would also fail server-side decryption.
333
+ *
334
+ * When false (default), thinking blocks pass through unchanged — matches
335
+ * legacy behaviour and works for all third-party Anthropic-compat
336
+ * providers. v0.7.28.
337
+ */
338
+ strictThinkingSignature?: boolean;
339
+ /**
340
+ * Hard cap on a single streaming request's wall-clock duration (ms).
341
+ * When exceeded, the resilience layer aborts the stream with a
342
+ * StreamIncompleteError, which routes through the existing
343
+ * `non_streaming_fallback` path. Mirrors Claude Code's idle watchdog
344
+ * pattern but uses request duration (not idle time) because some
345
+ * providers emit keepalive pings during long tool_use generation.
346
+ *
347
+ * Set per-provider just below the known server-side kill window
348
+ * (e.g. zhipu-coding observed 308s → set 300s here, accounting for
349
+ * the ~RTT margin between client send and server kill timestamp).
350
+ */
351
+ streamMaxDurationMs?: number;
352
+ }
353
+ interface KodaXProviderStreamOptions {
354
+ onTextDelta?: (text: string) => void;
355
+ onThinkingDelta?: (text: string) => void;
356
+ onThinkingEnd?: (thinking: string) => void;
357
+ onToolInputDelta?: (toolName: string, partialJson: string, meta?: {
358
+ toolId?: string;
359
+ }) => void;
360
+ /**
361
+ * Fired on provider-side SSE events to manage idle timers.
362
+ *
363
+ * - Called with no argument (or `false`): reset the idle timer.
364
+ * Fired on every event that indicates active data flow
365
+ * (content_block_start, content_block_delta, message_delta, etc.).
366
+ *
367
+ * - Called with `true`: **pause** the idle timer (clear without restart).
368
+ * Fired on `content_block_stop` when the stream has NOT yet ended,
369
+ * because the server may go silent while generating the next block
370
+ * (e.g. between text output and tool_use JSON generation).
371
+ * The hard request timeout still guards against genuinely stuck connections.
372
+ */
373
+ onHeartbeat?: (pause?: boolean) => void;
374
+ /** 当底层 API 遇到 Rate Limit 进行重试时触发 */
375
+ onRateLimit?: (attempt: number, maxRetries: number, delayMs: number) => void;
376
+ /**
377
+ * FEATURE_130 (v0.7.36): structured retry-after callback. Carries the
378
+ * parsed source (`retry-after-seconds` / `retry-after-date` /
379
+ * `retry-after-ms` / `exponential-backoff`) so UI surfaces and the
380
+ * cost tracker can distinguish "provider-told us to wait" from
381
+ * "we're guessing with backoff". Coexists with the legacy
382
+ * `onRateLimit` flat callback above — both fire if both are wired.
383
+ */
384
+ onRetryAfter?: (event: {
385
+ provider: string;
386
+ waitMs: number;
387
+ reason: 'rate-limit' | 'overloaded';
388
+ source: 'retry-after-seconds' | 'retry-after-date' | 'retry-after-ms' | 'exponential-backoff';
389
+ attempt: number;
390
+ maxAttempts: number;
391
+ }) => void;
392
+ /** 会话标识,用于多轮对话上下文恢复 */
393
+ sessionId?: string;
394
+ /** Override the provider's default model for a single request */
395
+ modelOverride?: string;
396
+ /** AbortSignal for cancelling the stream request */
397
+ signal?: AbortSignal;
398
+ }
399
+
400
+ export type { KodaXToolResultTextItem as $, KodaXProviderToolCallingFidelity as A, KodaXProviderTransport as B, KodaXReasoningCapability as C, KodaXReasoningMode as D, KodaXReasoningOverride as E, KodaXReasoningRequest as F, KodaXRedactedThinkingBlock as G, KodaXReviewScale as H, KodaXRiskLevel as I, KodaXStreamResult as J, KodaXAmaControllerDecision as K, KodaXTaskActionability as L, KodaXTaskBudgetOverrides as M, KodaXTaskComplexity as N, KodaXTaskFamily as O, KodaXTaskRoutingDecision as P, KodaXTaskType as Q, KodaXTaskWorkIntent as R, KodaXTextBlock as S, KodaXThinkingBlock as T, KodaXThinkingBudgetMap as U, KodaXThinkingDepth as V, KodaXTokenUsage as W, KodaXToolDefinition as X, KodaXToolResultBlock as Y, KodaXToolResultContentItem as Z, KodaXToolResultImageItem as _, KodaXAmaFanoutClass as a, KodaXToolUseBlock as a0, KodaXAmaFanoutPolicy as b, KodaXAmaProfile as c, KodaXAmaTactic as d, KodaXAssuranceIntent as e, KodaXCacheBoundary as f, KodaXContentBlock as g, KodaXCustomProviderConfig as h, KodaXExecutionMode as i, KodaXExecutionPattern as j, KodaXHarnessProfile as k, KodaXImageBlock as l, KodaXMessage as m, KodaXModelDescriptor as n, KodaXMutationSurface as o, KodaXProtocolFamily as p, KodaXProviderCapabilityProfile as q, KodaXProviderConfig as r, KodaXProviderContextFidelity as s, KodaXProviderConversationSemantics as t, KodaXProviderEvidenceSupport as u, KodaXProviderLongRunningSupport as v, KodaXProviderMcpSupport as w, KodaXProviderMultimodalSupport as x, KodaXProviderSessionSupport as y, KodaXProviderStreamOptions as z };