@kodax-ai/kodax 0.7.55 → 0.7.57

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 +50 -0
  2. package/README.md +22 -24
  3. package/README_CN.md +16 -18
  4. package/dist/builtin/code-review/SKILL.md +22 -3
  5. package/dist/chunks/agent-EHWQZA4C.js +2 -0
  6. package/dist/chunks/argument-completer-AYDAYGKL.js +2 -0
  7. package/dist/chunks/chunk-3WWPJGPQ.js +2 -0
  8. package/dist/chunks/chunk-4SHP3M67.js +2 -0
  9. package/dist/chunks/chunk-KN6IJMTB.js +636 -0
  10. package/dist/chunks/{chunk-ZBK3DZ3S.js → chunk-LZKGOR2C.js} +1 -1
  11. package/dist/chunks/chunk-MJFPFRGK.js +423 -0
  12. package/dist/chunks/chunk-N2N2W3AQ.js +584 -0
  13. package/dist/chunks/chunk-PCPFLPS4.js +5 -0
  14. package/dist/chunks/chunk-TCLSPUTR.js +31 -0
  15. package/dist/chunks/chunk-VACH6QWN.js +315 -0
  16. package/dist/chunks/chunk-YSVPF6SN.js +597 -0
  17. package/dist/chunks/{compaction-config-NAJEEPG5.js → compaction-config-TLDMFMZO.js} +1 -1
  18. package/dist/chunks/{construction-bootstrap-4CIVZMQ5.js → construction-bootstrap-55B7Q5RX.js} +4 -4
  19. package/dist/chunks/dist-IE4HVWP7.js +2 -0
  20. package/dist/chunks/dist-IKOK2MJQ.js +2 -0
  21. package/dist/chunks/paste-WTL2XN7P.js +2 -0
  22. package/dist/chunks/utils-EJ2VCRTC.js +2 -0
  23. package/dist/index.d.ts +21 -16
  24. package/dist/index.js +6 -6
  25. package/dist/kodax_cli.js +1128 -1099
  26. package/dist/provider-capabilities.json +986 -195
  27. package/dist/sdk-agent.d.ts +20 -12
  28. package/dist/sdk-agent.js +1 -1
  29. package/dist/sdk-coding.d.ts +223 -108
  30. package/dist/sdk-coding.js +1 -1
  31. package/dist/sdk-llm.d.ts +10 -5
  32. package/dist/sdk-llm.js +1 -1
  33. package/dist/sdk-mcp.d.ts +1 -1
  34. package/dist/sdk-mcp.js +1 -1
  35. package/dist/sdk-media.d.ts +142 -0
  36. package/dist/sdk-media.js +2 -0
  37. package/dist/sdk-repl.d.ts +106 -96
  38. package/dist/sdk-repl.js +1 -1
  39. package/dist/sdk-session.d.ts +6 -5
  40. package/dist/sdk-session.js +1 -1
  41. package/dist/sdk-skills.js +1 -1
  42. package/dist/semantic-worker.js +11 -0
  43. package/dist/types-chunks/base.d-BnjQrSVf.d.ts +301 -0
  44. package/dist/types-chunks/{bash-prefix-extractor.d-LUGkQHcd.d.ts → bash-prefix-extractor.d-BgvMbfq6.d.ts} +198 -139
  45. package/dist/types-chunks/{capsule.d-CNonpwAZ.d.ts → capsule.d-DwJp5r63.d.ts} +14 -11
  46. package/dist/types-chunks/{types.d-D4jL-gAA.d.ts → guardrail.d-BP3yyr6u.d.ts} +3 -121
  47. package/dist/types-chunks/{guardrail.d-B18oO1gt.d.ts → guardrail.d-C1DhxnvC.d.ts} +31 -9
  48. package/dist/types-chunks/{manager.d-DLmDhX3i.d.ts → manager.d-DBD7SOTT.d.ts} +7 -2
  49. package/dist/types-chunks/{process.d-Bj82oJhD.d.ts → process.d-BZncyzEj.d.ts} +2 -1
  50. package/dist/types-chunks/{resolver.d-CCX9NXWP.d.ts → resolver.d-ZvKQgl0X.d.ts} +82 -17
  51. package/dist/types-chunks/{sdk-session-SjrnWb4-.d.ts → sdk-session-DAScB0rW.d.ts} +6 -4
  52. package/dist/types-chunks/{storage.d-BAuJ0Ks7.d.ts → storage.d-CPvn9qI0.d.ts} +2 -2
  53. package/dist/types-chunks/{base.d-BBNUF9nz.d.ts → types.d-6VOXvF88.d.ts} +101 -290
  54. package/dist/types-chunks/types.d-D8WcfrOD.d.ts +143 -0
  55. package/dist/types-chunks/{utils.d-C9MUY8n3.d.ts → utils.d-CpgVIjYZ.d.ts} +16 -18
  56. package/package.json +15 -6
  57. package/dist/chunks/agent-PYSVWY7M.js +0 -2
  58. package/dist/chunks/argument-completer-CTDNNWV3.js +0 -2
  59. package/dist/chunks/chunk-7C2QUBLE.js +0 -31
  60. package/dist/chunks/chunk-EVIDQWMF.js +0 -5
  61. package/dist/chunks/chunk-FRI7UQSB.js +0 -2
  62. package/dist/chunks/chunk-HQCLPWRI.js +0 -551
  63. package/dist/chunks/chunk-JCDO2FR4.js +0 -584
  64. package/dist/chunks/chunk-MX4G42EV.js +0 -425
  65. package/dist/chunks/chunk-RGPPZOD5.js +0 -314
  66. package/dist/chunks/chunk-THAKTCPE.js +0 -652
  67. package/dist/chunks/dist-7KTO2PUU.js +0 -2
  68. package/dist/chunks/dist-BNKIZRCP.js +0 -2
  69. package/dist/chunks/paste-5DSTHQGK.js +0 -2
  70. package/dist/chunks/utils-2QXBKYPJ.js +0 -2
@@ -0,0 +1,301 @@
1
+ import { p as KodaXProviderConfig, j as KodaXMessage, _ as KodaXToolDefinition, G as KodaXReasoningRequest, x as KodaXProviderStreamOptions, M as KodaXStreamResult, a4 as KodaXVerifyCredentialResult, k as KodaXModelDescriptor, o as KodaXProviderCapabilityProfile, A as KodaXReasoningCapability, F as KodaXReasoningProfile, m as KodaXNormalizedReasoningRequest, a6 as KodaXWireReasoningEffort } from './types.d-6VOXvF88.js';
2
+
3
+ /**
4
+ * Retry-After header parsing — FEATURE_130 (v0.7.36).
5
+ *
6
+ * Handles the four forms KodaX's 12 provider adapters encounter when a
7
+ * model returns 429 (rate limit) or 503/529 (overloaded):
8
+ *
9
+ * 1. `Retry-After: 120` — integer seconds (HTTP 7231 standard)
10
+ * 2. `Retry-After: <HTTP-date>` — RFC 7231 IMF-fixdate
11
+ * e.g. "Wed, 21 Oct 2026 07:28:00 GMT"
12
+ * 3. `retry-after-ms: 45000` — Anthropic millisecond extension
13
+ * 4. (no Retry-After header present) — falls back to exponential backoff
14
+ * capped at `maxBackoffMs`, with optional jitter for the
15
+ * "thundering herd" protection.
16
+ *
17
+ * All return values are normalized to whole milliseconds and clamped to
18
+ * a sensible upper bound — never block the user for more than 120s, and
19
+ * never honor a header advertising a wait longer than `maxHeaderWaitMs`
20
+ * (default 120s). Beyond that limit we still extract the header but cap
21
+ * it; the calling provider can check `cappedFromHeader` to decide
22
+ * whether to surface a "rate limit exceeded — please wait" error to the
23
+ * user instead of silently sleeping for two minutes.
24
+ *
25
+ * Pattern-B (FEATURE_119) interaction: the helper is referentially
26
+ * transparent and stateless — it can be invoked concurrently by N
27
+ * parallel children without coordination. The retry loop in each
28
+ * provider holds its own attempt counter; this helper only translates
29
+ * headers/attempts into wait durations.
30
+ *
31
+ * Reference: opencode session/retry.ts:14-123 (4-form coverage).
32
+ */
33
+ type RetryAfterSource = 'retry-after-seconds' | 'retry-after-date' | 'retry-after-ms' | 'exponential-backoff';
34
+ type RetryAfterResult = {
35
+ readonly type: 'header';
36
+ readonly waitMs: number;
37
+ readonly source: 'retry-after-seconds' | 'retry-after-date' | 'retry-after-ms';
38
+ /** True when the header value exceeded `maxHeaderWaitMs` and was clamped. */
39
+ readonly cappedFromHeader: boolean;
40
+ } | {
41
+ readonly type: 'backoff';
42
+ readonly waitMs: number;
43
+ readonly source: 'exponential-backoff';
44
+ readonly attempt: number;
45
+ };
46
+ interface ParseRetryAfterOptions {
47
+ /** Zero-based attempt index used by the backoff branch (0 = first retry). */
48
+ readonly attempt: number;
49
+ /** Base delay for exponential backoff. Default 1000ms. */
50
+ readonly baseBackoffMs?: number;
51
+ /** Maximum exponential backoff cap. Default 30000ms. */
52
+ readonly maxBackoffMs?: number;
53
+ /** Maximum wait honored from a header. Default 120000ms. */
54
+ readonly maxHeaderWaitMs?: number;
55
+ /**
56
+ * Override the "now" reference used by the HTTP-date branch.
57
+ * Test-only escape hatch — production code should leave this undefined.
58
+ */
59
+ readonly now?: () => number;
60
+ /**
61
+ * Whether the backoff branch adds 0-25% jitter on top of the base
62
+ * exponential. Default true (matches the legacy `withRateLimit`
63
+ * jitter contract). Tests can pass `false` for deterministic output.
64
+ */
65
+ readonly withJitter?: boolean;
66
+ }
67
+ type HeadersLike = Headers | Record<string, string | string[] | undefined> | undefined;
68
+ /**
69
+ * Parse rate-limit/overload retry-after headers (4 forms) and decide
70
+ * how long the caller should sleep before retrying. Returns either:
71
+ *
72
+ * - `{type: 'header', ...}` when one of the supported headers was found
73
+ * and converted into a wait duration; OR
74
+ * - `{type: 'backoff', ...}` falling back to exponential backoff for
75
+ * the given `attempt` index when no header is present.
76
+ */
77
+ declare function parseRetryAfter(headers: HeadersLike, options: ParseRetryAfterOptions): RetryAfterResult;
78
+ /**
79
+ * Pull headers off a thrown error in the various shapes produced across
80
+ * provider SDKs (Anthropic, OpenAI, fetch-based custom providers).
81
+ * Returns `undefined` when no headers can be located — the helper then
82
+ * falls through to exponential backoff.
83
+ */
84
+ declare function extractHeadersFromError(error: unknown): HeadersLike;
85
+
86
+ /**
87
+ * KodaX Base Provider
88
+ *
89
+ * Provider 抽象基类 - 所有 Provider 的公共基础
90
+ */
91
+
92
+ /**
93
+ * Passive-learning guard threaded into `withRateLimit`: when the request fails
94
+ * with a reasoning-effort rejection, fire `onRejected` (so the REPL records it)
95
+ * and surface a typed error. `effort` is the value that was on the wire (used
96
+ * when the provider error doesn't echo a value).
97
+ */
98
+ interface ReasoningRejectionGuard {
99
+ readonly model: string;
100
+ readonly effort?: string;
101
+ readonly onRejected?: (event: {
102
+ provider: string;
103
+ model: string;
104
+ effort: string;
105
+ }) => void;
106
+ }
107
+
108
+ interface ResolvedV2ReasoningIntent {
109
+ readonly disabled: boolean;
110
+ readonly effort?: KodaXWireReasoningEffort;
111
+ readonly requestedEffort?: KodaXWireReasoningEffort;
112
+ }
113
+ /**
114
+ * FEATURE_130 (v0.7.36): structured payload fired through
115
+ * `KodaXEvents.onRetryAfter` whenever a provider's `withRateLimit`
116
+ * loop catches a 429 / 503 / 529 response and decides to wait. The
117
+ * `source` field carries which retry-after header form (or fallback)
118
+ * produced the wait duration so UI surfaces can show "provider asked
119
+ * us to wait 45s" vs "no header, exp-backoff guess of 4s".
120
+ */
121
+ interface KodaXRetryAfterEvent {
122
+ readonly provider: string;
123
+ readonly waitMs: number;
124
+ readonly reason: 'rate-limit' | 'overloaded';
125
+ readonly source: RetryAfterSource;
126
+ readonly attempt: number;
127
+ readonly maxAttempts: number;
128
+ }
129
+ type KodaXOnRetryAfterCallback = (event: KodaXRetryAfterEvent) => void;
130
+ declare abstract class KodaXBaseProvider {
131
+ abstract readonly name: string;
132
+ abstract readonly supportsThinking: boolean;
133
+ protected abstract readonly config: KodaXProviderConfig;
134
+ /**
135
+ * Per-request override for `max_tokens` in the next provider call. Consumed
136
+ * once and cleared in `withRateLimit` after the next successful response.
137
+ * Two callers set this:
138
+ * 1. Context-overflow recovery inside `withRateLimit` (reduces budget
139
+ * when the model reports "prompt too long").
140
+ * 2. The agent loop's max_tokens escalation path, which flips this to
141
+ * `KODAX_ESCALATED_MAX_OUTPUT_TOKENS` when a capped-budget turn
142
+ * returns `stop_reason: max_tokens`. See `coding/src/agent.ts`.
143
+ */
144
+ protected maxOutputTokensOverride?: number;
145
+ /**
146
+ * One-shot flag for the passive-learning self-heal: when a request is
147
+ * rejected for its reasoning-effort value, `withRateLimit` flips this true
148
+ * and retries the SAME turn. The reasoning-application path then drops the
149
+ * effort param so the retry uses the provider default and the user's turn
150
+ * still completes — no interruption, no re-typed query. Cleared on success.
151
+ */
152
+ protected suppressReasoningEffort: boolean;
153
+ /**
154
+ * Public setter for the one-shot override above. Callers outside the
155
+ * provider package (notably the agent loop's escalation branch) use this
156
+ * to stage a larger budget for the next stream call in the same logical
157
+ * turn. Pass `undefined` to clear a stale override explicitly.
158
+ */
159
+ setMaxOutputTokensOverride(value: number | undefined): void;
160
+ /**
161
+ * Returns the max_tokens value the provider will currently use on its
162
+ * next request. Precedence (highest to lowest):
163
+ * 1. One-shot override (agent escalation, context-overflow recovery)
164
+ * 2. User env var `KODAX_MAX_OUTPUT_TOKENS` (explicit user intent)
165
+ * 3. Active model descriptor's `maxOutputTokens` (FEATURE_098)
166
+ * 4. Provider config default
167
+ * 5. Global `KODAX_MAX_TOKENS` fallback
168
+ * Used by provider stream() paths and by the agent loop to decide
169
+ * whether escalation is applicable (see `coding/src/agent.ts`).
170
+ */
171
+ getEffectiveMaxOutputTokens(model?: string): number;
172
+ /**
173
+ * Hard cap on a single streaming request's wall-clock duration (ms).
174
+ * Returns undefined when no cap is configured. Consumed by the
175
+ * resilience layer to abort a doomed stream before the server-side
176
+ * kill window fires; routed through `non_streaming_fallback`.
177
+ *
178
+ * Cascade (highest to lowest):
179
+ * 1. Active model descriptor's `streamMaxDurationMs`
180
+ * 2. Provider config default
181
+ * 3. undefined (watchdog disabled)
182
+ */
183
+ getStreamMaxDurationMs(model?: string): number | undefined;
184
+ /**
185
+ * Resolves whether OpenAI-compat `reasoning_content` should echo back
186
+ * on replayed assistant messages for the given model. Same cascade as
187
+ * `getStreamMaxDurationMs`. Defaults to false when neither layer sets it.
188
+ */
189
+ getEffectiveReplayReasoningContent(model?: string): boolean;
190
+ /**
191
+ * Resolves whether Anthropic-style thinking signatures must verify
192
+ * strictly (Anthropic proper only). Same cascade as
193
+ * `getStreamMaxDurationMs`. Defaults to false (lenient) when neither
194
+ * layer sets it — matches third-party Anthropic-compat behavior.
195
+ */
196
+ getEffectiveStrictThinkingSignature(model?: string): boolean;
197
+ protected getEffectiveThinkingBudgetCap(model?: string): number | undefined;
198
+ abstract stream(messages: KodaXMessage[], tools: KodaXToolDefinition[], system: string, reasoning?: boolean | KodaXReasoningRequest, streamOptions?: KodaXProviderStreamOptions, signal?: AbortSignal): Promise<KodaXStreamResult>;
199
+ supportsNonStreamingFallback(): boolean;
200
+ complete(_messages: KodaXMessage[], _tools: KodaXToolDefinition[], _system: string, _reasoning?: boolean | KodaXReasoningRequest, _streamOptions?: KodaXProviderStreamOptions, _signal?: AbortSignal): Promise<KodaXStreamResult>;
201
+ isConfigured(): boolean;
202
+ /**
203
+ * FEATURE_216 v0.7.45 — Lightweight credential verification. Returns
204
+ * a never-throws envelope with `ok` + categorized `error`. Concrete
205
+ * compat base classes (`KodaXAnthropicCompatProvider`,
206
+ * `KodaXOpenAICompatProvider`) override this to dispatch by the
207
+ * `verifyStrategy` field. The default here returns `unsupported` so
208
+ * Provider classes that don't extend a compat base — or future ones
209
+ * yet to be wired — fail safely instead of throwing.
210
+ *
211
+ * Distinct from `isConfigured()`: that one is env-only (no network);
212
+ * this one hits the wire (zero or ~7 tokens depending on strategy)
213
+ * and verifies the key is actually accepted by the upstream.
214
+ */
215
+ verifyCredential(_opts?: {
216
+ timeoutMs?: number;
217
+ signal?: AbortSignal;
218
+ }): Promise<KodaXVerifyCredentialResult>;
219
+ getModel(): string;
220
+ getAvailableModels(): string[];
221
+ getModelDescriptor(modelId?: string): KodaXModelDescriptor | undefined;
222
+ getBaseUrl(): string | undefined;
223
+ getApiKeyEnv(): string;
224
+ getCapabilityProfile(): KodaXProviderCapabilityProfile;
225
+ getConfiguredReasoningCapability(modelOverride?: string): KodaXReasoningCapability;
226
+ getReasoningCapability(modelOverride?: string): KodaXReasoningCapability;
227
+ getReasoningProfile(modelOverride?: string): KodaXReasoningProfile | undefined;
228
+ protected shouldFallbackForReasoningError(error: unknown, ...terms: string[]): boolean;
229
+ protected shouldFallbackForSpecificReasoningError(error: unknown, ...terms: string[]): boolean;
230
+ protected shouldFallbackForForcedToolChoiceError(error: unknown): boolean;
231
+ protected isServerError(error: unknown): boolean;
232
+ protected getReasoningFallbackChain(capability: KodaXReasoningCapability): KodaXReasoningCapability[];
233
+ /**
234
+ * 获取模型的上下文窗口大小
235
+ *
236
+ * Backwards-compatible no-arg form: resolves against the provider's
237
+ * default model descriptor. New call sites that know the active
238
+ * model should use `getEffectiveContextWindow(model)` directly.
239
+ * @returns 上下文窗口大小 (tokens)
240
+ */
241
+ getContextWindow(): number;
242
+ /**
243
+ * Resolves the context window for a specific model.
244
+ * Precedence (highest to lowest):
245
+ * 1. Active model descriptor's `contextWindow` (FEATURE_098)
246
+ * 2. Provider config default
247
+ * 3. 200_000 fallback
248
+ * The user-level `compaction.contextWindow` is layered on top of
249
+ * this at the call site, so it remains the highest-priority manual
250
+ * override.
251
+ */
252
+ getEffectiveContextWindow(model?: string): number;
253
+ protected getApiKey(): string;
254
+ protected shouldLogStreamDiagnostics(): boolean;
255
+ protected logStreamDiagnostic(...args: unknown[]): void;
256
+ protected normalizeReasoning(reasoning?: boolean | KodaXReasoningRequest): KodaXNormalizedReasoningRequest;
257
+ protected validateExplicitReasoningEffort(reasoning: KodaXNormalizedReasoningRequest, modelOverride?: string): void;
258
+ protected resolveReasoningProfileIntent(reasoning: KodaXNormalizedReasoningRequest, capability: KodaXReasoningProfile, modelOverride?: string): ResolvedV2ReasoningIntent;
259
+ /**
260
+ * Called when ECONNRESET/EPIPE is detected, indicating a stale keep-alive
261
+ * socket. Subclasses should override to rebuild their HTTP client with a
262
+ * fresh connection pool so the next retry uses a new TCP connection.
263
+ */
264
+ protected onStaleConnection(): void;
265
+ protected isRateLimitError(error: unknown): boolean;
266
+ /**
267
+ * FEATURE_130: classify a rate-limit error as either a 429-style
268
+ * "rate-limit" or a 503/529-style "overloaded" condition. The
269
+ * distinction matters for UI: "rate-limit" usually surfaces a
270
+ * provider-supplied retry-after window; "overloaded" tends to fall
271
+ * through to exponential backoff with no header. Both flow through
272
+ * the same retry path; this only labels the event.
273
+ */
274
+ protected classifyRateLimitReason(error: unknown): 'rate-limit' | 'overloaded';
275
+ /**
276
+ * Extract Retry-After delay from error headers (429/529 responses).
277
+ * Returns milliseconds, or undefined when no usable header is present.
278
+ *
279
+ * FEATURE_130 (v0.7.36): now delegates to the shared `parseRetryAfter`
280
+ * helper so all 12 provider adapters get 4-form coverage without each
281
+ * adapter rolling its own parser. The 4 forms supported are:
282
+ * - `Retry-After: <integer-seconds>`
283
+ * - `Retry-After: <HTTP-date>`
284
+ * - `retry-after-ms: <milliseconds>` (Anthropic extension)
285
+ * - exponential-backoff fallback (returned via `withRateLimit`,
286
+ * not through this helper — it is `undefined` here when no
287
+ * header is present, which the caller then resolves to backoff)
288
+ */
289
+ protected extractRetryAfterMs(error: unknown): number | undefined;
290
+ /**
291
+ * Detect "prompt too long / context window exceeded" errors and compute
292
+ * a reduced max_tokens for retry. Returns undefined if not a context
293
+ * overflow error.
294
+ */
295
+ protected parseContextOverflow(error: unknown): number | undefined;
296
+ protected isContextOverflowError(error: unknown): boolean;
297
+ protected withRateLimit<T>(fn: () => Promise<T>, signal?: AbortSignal, retries?: number, onRateLimit?: (attempt: number, maxRetries: number, delayMs: number) => void, onRetryAfter?: KodaXOnRetryAfterCallback, reasoningGuard?: ReasoningRejectionGuard): Promise<T>;
298
+ }
299
+
300
+ export { KodaXBaseProvider as K, extractHeadersFromError as e, parseRetryAfter as p };
301
+ export type { ParseRetryAfterOptions as P, RetryAfterResult as R, KodaXOnRetryAfterCallback as a, KodaXRetryAfterEvent as b, RetryAfterSource as c };