@kodax-ai/kodax 0.7.41 → 0.7.43
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/CHANGELOG.md +119 -3
- package/README.md +214 -286
- package/README_CN.md +173 -277
- package/dist/chunks/chunk-7G5PSL6C.js +830 -0
- package/dist/chunks/{chunk-6OB4AJOM.js → chunk-IYSK7LUK.js} +1 -1
- package/dist/chunks/chunk-K75O2CAE.js +31 -0
- package/dist/chunks/chunk-UG4262JI.js +502 -0
- package/dist/chunks/chunk-VHKAJDQD.js +425 -0
- package/dist/chunks/chunk-YMRZBS4G.js +2 -0
- package/dist/chunks/{compaction-config-LT5PEXPT.js → compaction-config-3E57ABCT.js} +1 -1
- package/dist/chunks/{construction-bootstrap-HBCWJFHC.js → construction-bootstrap-JR63KI5N.js} +4 -4
- package/dist/chunks/dist-KWHUKXEL.js +2 -0
- package/dist/chunks/dist-XANXEVTU.js +2 -0
- package/dist/chunks/utils-HQ2QCKJA.js +2 -0
- package/dist/index.d.ts +15 -10
- package/dist/index.js +5 -5
- package/dist/kodax_cli.js +1084 -1054
- package/dist/sdk-agent.d.ts +853 -135
- package/dist/sdk-agent.js +1 -1
- package/dist/sdk-coding.d.ts +932 -981
- package/dist/sdk-coding.js +1 -1
- package/dist/sdk-llm.d.ts +8 -5
- package/dist/sdk-llm.js +1 -1
- package/dist/sdk-mcp.d.ts +17 -0
- package/dist/sdk-mcp.js +2 -0
- package/dist/sdk-repl.d.ts +343 -10
- package/dist/sdk-repl.js +2 -1
- package/dist/sdk-session.d.ts +176 -0
- package/dist/sdk-session.js +2 -0
- package/dist/sdk-skills.d.ts +72 -4
- package/dist/sdk-skills.js +1 -1
- package/dist/types-chunks/{cost-tracker.d-C4dMlQuV.d.ts → base.d-FUJahC0i.d.ts} +22 -112
- package/dist/types-chunks/{bash-prefix-extractor.d-B2iliwdi.d.ts → bash-prefix-extractor.d-DMrGImMl.d.ts} +266 -228
- package/dist/types-chunks/capability.d-3C62G8Eq.d.ts +39 -0
- package/dist/types-chunks/config.d-BfJUXxC0.d.ts +41 -0
- package/dist/types-chunks/cost-tracker.d-wRtyEW9d.d.ts +110 -0
- package/dist/types-chunks/{history-cleanup.d-q1vAvCss.d.ts → file-tracker.d-zaLZeNBK.d.ts} +532 -15
- package/dist/types-chunks/manager.d-87belpiS.d.ts +370 -0
- package/dist/types-chunks/{resolver.d-BwD6TKz7.d.ts → resolver.d-CA68_NeH.d.ts} +150 -5
- package/dist/types-chunks/storage.d-DPAEX7zS.d.ts +115 -0
- package/dist/types-chunks/{capability.d-BxNgd1-c.d.ts → types.d-B1uGoVTE.d.ts} +72 -40
- package/dist/types-chunks/{instance-discovery.d-DZhp77vb.d.ts → types.d-CKJtjo-6.d.ts} +168 -258
- package/dist/types-chunks/types.d-mM8vqvhT.d.ts +254 -0
- package/dist/types-chunks/{storage.d-Bv9T99Qu.d.ts → utils.d-DkLZD_wa.d.ts} +38 -112
- package/package.json +15 -6
- package/dist/chunks/chunk-5TFLMGER.js +0 -2
- package/dist/chunks/chunk-6QO6HWGU.js +0 -30
- package/dist/chunks/chunk-EQ5DGS2W.js +0 -14
- package/dist/chunks/chunk-HYWVRTFA.js +0 -1233
- package/dist/chunks/chunk-SX2IS5JP.js +0 -16
- package/dist/chunks/chunk-ZPJPNLBK.js +0 -462
- package/dist/chunks/dist-M57GIWR4.js +0 -2
- package/dist/chunks/dist-V3BS2NKB.js +0 -2
- package/dist/chunks/utils-FAFUQJ2A.js +0 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer A Primitive: Capability provider contract.
|
|
3
|
+
*
|
|
4
|
+
* FEATURE_082 (v0.7.24): extracted from `@kodax-ai/coding/src/extensions/types.ts`
|
|
5
|
+
* so third-party capability sources (MCP, RAG, custom indexes, …) can
|
|
6
|
+
* implement `CapabilityProvider` without importing from the coding preset.
|
|
7
|
+
*
|
|
8
|
+
* The richer "extension runtime" concept (command registration, file
|
|
9
|
+
* contributions, logger plumbing) stays in `@kodax-ai/coding/src/extensions/`
|
|
10
|
+
* because it is coupled to the coding CLI surface.
|
|
11
|
+
*/
|
|
12
|
+
type CapabilityKind = 'tool' | 'resource' | 'prompt';
|
|
13
|
+
interface CapabilityResult {
|
|
14
|
+
kind: CapabilityKind;
|
|
15
|
+
content?: string;
|
|
16
|
+
structuredContent?: unknown;
|
|
17
|
+
evidence?: unknown[];
|
|
18
|
+
artifacts?: unknown[];
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface CapabilityProvider {
|
|
22
|
+
id: string;
|
|
23
|
+
kinds: CapabilityKind[];
|
|
24
|
+
search?: (query: string, options?: {
|
|
25
|
+
kind?: CapabilityKind;
|
|
26
|
+
limit?: number;
|
|
27
|
+
server?: string;
|
|
28
|
+
}) => Promise<unknown[]>;
|
|
29
|
+
describe?: (id: string) => Promise<unknown>;
|
|
30
|
+
execute?: (id: string, input: Record<string, unknown>) => Promise<CapabilityResult>;
|
|
31
|
+
read?: (id: string, options?: Record<string, unknown>) => Promise<CapabilityResult>;
|
|
32
|
+
getPrompt?: (id: string, args?: Record<string, unknown>) => Promise<unknown>;
|
|
33
|
+
getPromptContext?: () => Promise<string | undefined> | string | undefined;
|
|
34
|
+
getDiagnostics?: () => Record<string, unknown> | undefined;
|
|
35
|
+
refresh?: () => Promise<void>;
|
|
36
|
+
dispose?: () => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type { CapabilityKind as C, CapabilityProvider as a, CapabilityResult as b };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP server configuration shapes.
|
|
3
|
+
*
|
|
4
|
+
* FEATURE_082 (v0.7.24): moved from `@kodax-ai/coding/src/types.ts`. Kept as the
|
|
5
|
+
* `Mcp*` names here; the `KodaXMcp*` aliases continue to re-export from
|
|
6
|
+
* `@kodax-ai/coding` for backward compatibility.
|
|
7
|
+
*/
|
|
8
|
+
type McpTransportKind = 'stdio' | 'sse' | 'streamable-http';
|
|
9
|
+
type McpConnectMode = 'lazy' | 'prewarm' | 'disabled';
|
|
10
|
+
interface McpServerConfig {
|
|
11
|
+
/** Transport type. Defaults to 'stdio' when omitted. */
|
|
12
|
+
type?: McpTransportKind;
|
|
13
|
+
/** stdio: executable command. */
|
|
14
|
+
command?: string;
|
|
15
|
+
/** stdio: command arguments. */
|
|
16
|
+
args?: string[];
|
|
17
|
+
/** stdio: working directory for the spawned process. */
|
|
18
|
+
cwd?: string;
|
|
19
|
+
/** stdio: extra environment variables for the spawned process. */
|
|
20
|
+
env?: Record<string, string>;
|
|
21
|
+
/** sse / streamable-http: server endpoint URL. */
|
|
22
|
+
url?: string;
|
|
23
|
+
/** sse / streamable-http: extra HTTP headers (e.g. Authorization). */
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
connect?: McpConnectMode;
|
|
26
|
+
startupTimeoutMs?: number;
|
|
27
|
+
requestTimeoutMs?: number;
|
|
28
|
+
/** OAuth 2.0 configuration for authenticated MCP servers. */
|
|
29
|
+
auth?: {
|
|
30
|
+
readonly type: 'oauth2';
|
|
31
|
+
readonly clientId: string;
|
|
32
|
+
readonly authorizationUrl: string;
|
|
33
|
+
readonly tokenUrl: string;
|
|
34
|
+
readonly scopes?: readonly string[];
|
|
35
|
+
readonly redirectPort?: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Flat map of MCP server configs, keyed under `mcpServers` in config.json. */
|
|
39
|
+
type McpServersConfig = Record<string, McpServerConfig>;
|
|
40
|
+
|
|
41
|
+
export type { McpConnectMode as M, McpServerConfig as a, McpServersConfig as b, McpTransportKind as c };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KodaX Cost Rates - Multi-Provider pricing table
|
|
3
|
+
*
|
|
4
|
+
* 成本费率表 - 所有 Provider 的计费标准
|
|
5
|
+
* 支持 11 个内置 Provider 的成本追踪,用户可以覆盖默认费率
|
|
6
|
+
*/
|
|
7
|
+
interface CostRate {
|
|
8
|
+
readonly inputPer1M: number;
|
|
9
|
+
readonly outputPer1M: number;
|
|
10
|
+
readonly cachePer1M?: number;
|
|
11
|
+
}
|
|
12
|
+
declare const DEFAULT_COST_RATES: Readonly<Record<string, Readonly<Record<string, CostRate>>>>;
|
|
13
|
+
declare function getCostRate(provider: string, model: string, userOverrides?: Readonly<Record<string, Readonly<Record<string, CostRate>>>>): CostRate | undefined;
|
|
14
|
+
declare function calculateCost(rate: CostRate, inputTokens: number, outputTokens: number, cacheTokens?: number): number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* KodaX Cost Tracker - Immutable session cost tracking
|
|
18
|
+
*
|
|
19
|
+
* 成本追踪器 - 不可变的会话成本追踪
|
|
20
|
+
* 使用 Immutable 模式,每次操作都返回新对象而不修改原有对象
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
interface TokenUsageRecord {
|
|
24
|
+
readonly timestamp: number;
|
|
25
|
+
readonly provider: string;
|
|
26
|
+
readonly model: string;
|
|
27
|
+
readonly inputTokens: number;
|
|
28
|
+
readonly outputTokens: number;
|
|
29
|
+
readonly cacheReadTokens: number;
|
|
30
|
+
readonly cacheWriteTokens: number;
|
|
31
|
+
readonly cost: number;
|
|
32
|
+
readonly role?: string;
|
|
33
|
+
}
|
|
34
|
+
interface ProviderCostSummary {
|
|
35
|
+
readonly cost: number;
|
|
36
|
+
readonly calls: number;
|
|
37
|
+
readonly inputTokens: number;
|
|
38
|
+
readonly outputTokens: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* FEATURE_130 (v0.7.36) — per-retry record. Captures the wait the
|
|
42
|
+
* provider asked us to take so `/cost` can report "X retries, Ys total
|
|
43
|
+
* wait" alongside the token cost. Lives in the same tracker as token
|
|
44
|
+
* records to keep one source of truth for the session.
|
|
45
|
+
*/
|
|
46
|
+
interface RetryRecord {
|
|
47
|
+
readonly timestamp: number;
|
|
48
|
+
readonly provider: string;
|
|
49
|
+
readonly waitMs: number;
|
|
50
|
+
readonly reason: 'rate-limit' | 'overloaded';
|
|
51
|
+
readonly source: 'retry-after-seconds' | 'retry-after-date' | 'retry-after-ms' | 'exponential-backoff';
|
|
52
|
+
}
|
|
53
|
+
interface SessionCostSummary {
|
|
54
|
+
readonly totalCost: number;
|
|
55
|
+
readonly totalInputTokens: number;
|
|
56
|
+
readonly totalOutputTokens: number;
|
|
57
|
+
readonly totalCacheTokens: number;
|
|
58
|
+
/** FEATURE_116 (v0.7.37): cumulative cache-read input tokens across the
|
|
59
|
+
* session. Splits `totalCacheTokens` into the read half so the hit rate
|
|
60
|
+
* (`cacheHitRate = totalCacheReadTokens / totalCacheTokens`) is
|
|
61
|
+
* derivable for `/cost` reporting. */
|
|
62
|
+
readonly totalCacheReadTokens: number;
|
|
63
|
+
/** FEATURE_116 (v0.7.37): cumulative cache-write (creation) input tokens. */
|
|
64
|
+
readonly totalCacheWriteTokens: number;
|
|
65
|
+
/** FEATURE_116 (v0.7.37): cache-read share of all cache tokens this
|
|
66
|
+
* session, in [0, 1]. Computed as `totalCacheReadTokens /
|
|
67
|
+
* (totalCacheReadTokens + totalCacheWriteTokens)`. Returns 0 when no
|
|
68
|
+
* cache activity has been recorded — a session with zero cache
|
|
69
|
+
* activity is not "0% hit rate", just untracked. */
|
|
70
|
+
readonly cacheHitRate: number;
|
|
71
|
+
readonly callCount: number;
|
|
72
|
+
/** FEATURE_130: total retries triggered across the session. */
|
|
73
|
+
readonly retryCount: number;
|
|
74
|
+
/** FEATURE_130: cumulative milliseconds spent in retry-after sleeps. */
|
|
75
|
+
readonly retryWaitMs: number;
|
|
76
|
+
readonly byProvider: Readonly<Record<string, ProviderCostSummary>>;
|
|
77
|
+
readonly byRole: Readonly<Record<string, ProviderCostSummary>>;
|
|
78
|
+
}
|
|
79
|
+
interface CostTracker {
|
|
80
|
+
readonly records: readonly TokenUsageRecord[];
|
|
81
|
+
/** FEATURE_130 (v0.7.36): retry-wait records, append-only and immutable. */
|
|
82
|
+
readonly retries: readonly RetryRecord[];
|
|
83
|
+
}
|
|
84
|
+
declare function createCostTracker(): CostTracker;
|
|
85
|
+
/**
|
|
86
|
+
* FEATURE_130 (v0.7.36): record a retry-after wait. The InkREPL spinner
|
|
87
|
+
* (or any other consumer of `KodaXEvents.onRetryAfter`) calls this so
|
|
88
|
+
* `/cost` can surface accurate session-wide retry telemetry.
|
|
89
|
+
*/
|
|
90
|
+
declare function recordRetry(tracker: CostTracker, entry: {
|
|
91
|
+
readonly provider: string;
|
|
92
|
+
readonly waitMs: number;
|
|
93
|
+
readonly reason: 'rate-limit' | 'overloaded';
|
|
94
|
+
readonly source: 'retry-after-seconds' | 'retry-after-date' | 'retry-after-ms' | 'exponential-backoff';
|
|
95
|
+
}): CostTracker;
|
|
96
|
+
declare function recordUsage(tracker: CostTracker, entry: {
|
|
97
|
+
readonly provider: string;
|
|
98
|
+
readonly model: string;
|
|
99
|
+
readonly inputTokens: number;
|
|
100
|
+
readonly outputTokens: number;
|
|
101
|
+
readonly cacheReadTokens?: number;
|
|
102
|
+
readonly cacheWriteTokens?: number;
|
|
103
|
+
readonly role?: string;
|
|
104
|
+
}, userCostOverrides?: Readonly<Record<string, Readonly<Record<string, CostRate>>>>): CostTracker;
|
|
105
|
+
declare function getSummary(tracker: CostTracker): SessionCostSummary;
|
|
106
|
+
declare function formatCost(usd: number): string;
|
|
107
|
+
declare function formatCostReport(summary: SessionCostSummary): string;
|
|
108
|
+
|
|
109
|
+
export { DEFAULT_COST_RATES as D, createCostTracker as b, calculateCost as c, formatCostReport as d, getSummary as e, formatCost as f, getCostRate as g, recordUsage as h, recordRetry as r };
|
|
110
|
+
export type { CostRate as C, ProviderCostSummary as P, RetryRecord as R, SessionCostSummary as S, TokenUsageRecord as T, CostTracker as a };
|