@claudemax/cli 1.0.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/LICENSE +21 -0
- package/README.md +183 -0
- package/dist/commands/ask.d.ts +7 -0
- package/dist/commands/ask.d.ts.map +1 -0
- package/dist/commands/ask.js +70 -0
- package/dist/commands/ask.js.map +1 -0
- package/dist/commands/chat.d.ts +7 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +152 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config.d.ts +7 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +155 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/history.d.ts +7 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +158 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/usage.d.ts +7 -0
- package/dist/commands/usage.d.ts.map +1 -0
- package/dist/commands/usage.js +37 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-client.d.ts +43 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +136 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/config-manager.d.ts +45 -0
- package/dist/lib/config-manager.d.ts.map +1 -0
- package/dist/lib/config-manager.js +146 -0
- package/dist/lib/config-manager.js.map +1 -0
- package/dist/lib/formatter.d.ts +42 -0
- package/dist/lib/formatter.d.ts.map +1 -0
- package/dist/lib/formatter.js +158 -0
- package/dist/lib/formatter.js.map +1 -0
- package/dist/lib/history-manager.d.ts +45 -0
- package/dist/lib/history-manager.d.ts.map +1 -0
- package/dist/lib/history-manager.js +163 -0
- package/dist/lib/history-manager.js.map +1 -0
- package/dist/lib/model-aliases.d.ts +22 -0
- package/dist/lib/model-aliases.d.ts.map +1 -0
- package/dist/lib/model-aliases.js +53 -0
- package/dist/lib/model-aliases.js.map +1 -0
- package/dist/lib/stream-handler.d.ts +37 -0
- package/dist/lib/stream-handler.d.ts.map +1 -0
- package/dist/lib/stream-handler.js +104 -0
- package/dist/lib/stream-handler.js.map +1 -0
- package/dist/types/index.d.ts +122 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-manager.js","sourceRoot":"","sources":["../../src/lib/config-manager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAqBH,oCAEC;AAKD,sCAEC;AAeD,gCAuBC;AAMD,gCAkBC;AAKD,kCAEC;AAOD,wCAGC;AAOD,wCAIC;AAaD,wCAsBC;AAzJD,2BAA6B;AAC7B,+BAA4B;AAC5B,2BAAmF;AAGnF,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,YAAY,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAEpD,MAAM,cAAc,GAAW;IAC7B,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,2BAA2B;IACpC,YAAY,EAAE,mBAAmB;IACjC,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,GAAG;CACjB,CAAC;AAEF;;GAEG;AACH,SAAgB,YAAY;IAC1B,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAS,eAAe;IACtB,IAAI,CAAC,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,IAAA,cAAS,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED;;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,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatter for terminal display
|
|
3
|
+
* Provides colored and formatted output using chalk
|
|
4
|
+
*/
|
|
5
|
+
import { Usage, UserStats } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Format a message with role indicator
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatMessage(role: 'user' | 'assistant', content: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Format usage stats (tokens, cost)
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatUsage(usage: Usage, model?: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Format user stats (from /api/v1/user)
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatUserStats(stats: UserStats): void;
|
|
18
|
+
/**
|
|
19
|
+
* Format error message
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatError(error: Error, type?: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Format welcome message for chat mode
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatWelcome(model: string, balance?: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Format session summary for chat mode
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatSessionSummary(totalTokens: number, totalCost: number, messageCount: number): void;
|
|
30
|
+
/**
|
|
31
|
+
* Format config list output
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatConfig(config: Record<string, any>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Show spinner-like loading indicator
|
|
36
|
+
*/
|
|
37
|
+
export declare function showLoading(message?: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Clear loading indicator
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearLoading(): void;
|
|
42
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/lib/formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAM/E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAE,MAAiB,GAAG,IAAI,CASxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAuBtD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAc7D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CASnE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAa9D;AA+BD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,MAAqB,GAAG,IAAI,CAEhE;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAEnC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Output formatter for terminal display
|
|
4
|
+
* Provides colored and formatted output using chalk
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.formatMessage = formatMessage;
|
|
11
|
+
exports.formatUsage = formatUsage;
|
|
12
|
+
exports.formatUserStats = formatUserStats;
|
|
13
|
+
exports.formatError = formatError;
|
|
14
|
+
exports.formatWelcome = formatWelcome;
|
|
15
|
+
exports.formatSessionSummary = formatSessionSummary;
|
|
16
|
+
exports.formatConfig = formatConfig;
|
|
17
|
+
exports.showLoading = showLoading;
|
|
18
|
+
exports.clearLoading = clearLoading;
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
+
/**
|
|
21
|
+
* Format a message with role indicator
|
|
22
|
+
*/
|
|
23
|
+
function formatMessage(role, content) {
|
|
24
|
+
if (role === 'user') {
|
|
25
|
+
console.log(chalk_1.default.blue.bold('You: ') + content);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log(chalk_1.default.green.bold('Assistant: ') + content);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Format usage stats (tokens, cost)
|
|
33
|
+
*/
|
|
34
|
+
function formatUsage(usage, model = 'sonnet') {
|
|
35
|
+
const totalTokens = usage.input_tokens + usage.output_tokens;
|
|
36
|
+
const cost = calculateCost(usage.input_tokens, usage.output_tokens, model);
|
|
37
|
+
console.log(chalk_1.default.gray(`\n📊 ${totalTokens.toLocaleString()} tokens · $${cost.toFixed(4)}`));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Format user stats (from /api/v1/user)
|
|
41
|
+
*/
|
|
42
|
+
function formatUserStats(stats) {
|
|
43
|
+
console.log(chalk_1.default.cyan.bold('\n📊 Account Usage'));
|
|
44
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
45
|
+
console.log(chalk_1.default.white('Balance:'), chalk_1.default.yellow(`$${stats.user.balance.toFixed(4)}`));
|
|
46
|
+
console.log(chalk_1.default.white('Tier:'), chalk_1.default.blue(stats.user.tier));
|
|
47
|
+
console.log(chalk_1.default.cyan.bold('\n📈 Today'));
|
|
48
|
+
console.log(chalk_1.default.white(' Requests:'), chalk_1.default.yellow(stats.usage.requests.today.toLocaleString()));
|
|
49
|
+
console.log(chalk_1.default.white(' Tokens:'), chalk_1.default.yellow(stats.usage.tokens.today.toLocaleString()));
|
|
50
|
+
console.log(chalk_1.default.white(' Cost:'), chalk_1.default.yellow(`$${stats.usage.cost.today.toFixed(4)}`));
|
|
51
|
+
console.log(chalk_1.default.cyan.bold('\n📅 This Month'));
|
|
52
|
+
console.log(chalk_1.default.white(' Requests:'), chalk_1.default.yellow(stats.usage.requests.this_month.toLocaleString()));
|
|
53
|
+
console.log(chalk_1.default.white(' Tokens:'), chalk_1.default.yellow(stats.usage.tokens.this_month.toLocaleString()));
|
|
54
|
+
console.log(chalk_1.default.white(' Cost:'), chalk_1.default.yellow(`$${stats.usage.cost.this_month.toFixed(4)}`));
|
|
55
|
+
console.log(chalk_1.default.cyan.bold('\n⚡ Rate Limits'));
|
|
56
|
+
console.log(chalk_1.default.white(' Per minute:'), chalk_1.default.yellow(stats.rate_limits.requests_per_minute));
|
|
57
|
+
console.log(chalk_1.default.white(' Per hour:'), chalk_1.default.yellow(stats.rate_limits.requests_per_hour));
|
|
58
|
+
console.log(chalk_1.default.white(' Per day:'), chalk_1.default.yellow(stats.rate_limits.requests_per_day));
|
|
59
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Format error message
|
|
63
|
+
*/
|
|
64
|
+
function formatError(error, type) {
|
|
65
|
+
console.error(chalk_1.default.red.bold('\n❌ Error: ') + error.message);
|
|
66
|
+
// Provide helpful suggestions based on error type
|
|
67
|
+
if (error.name === 'AuthenticationError' || type === 'authentication_error') {
|
|
68
|
+
console.error(chalk_1.default.yellow('\nFix:'));
|
|
69
|
+
console.error(chalk_1.default.white(' claudemax config set api-key YOUR_KEY'));
|
|
70
|
+
console.error(chalk_1.default.gray('\nGet your API key: https://claudeapi.dev/dashboard/api-keys'));
|
|
71
|
+
}
|
|
72
|
+
else if (error.name === 'InsufficientBalanceError' || type === 'insufficient_balance') {
|
|
73
|
+
console.error(chalk_1.default.yellow('\nTop up:'));
|
|
74
|
+
console.error(chalk_1.default.gray(' https://claudeapi.dev/dashboard/payment'));
|
|
75
|
+
}
|
|
76
|
+
else if (error.name === 'RateLimitError' || type === 'rate_limit_error') {
|
|
77
|
+
console.error(chalk_1.default.yellow('\n⚠️ Rate limit exceeded. Please wait a moment and try again.'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Format welcome message for chat mode
|
|
82
|
+
*/
|
|
83
|
+
function formatWelcome(model, balance) {
|
|
84
|
+
console.log(chalk_1.default.cyan.bold('\n✨ ClaudeAPI Chat'));
|
|
85
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
86
|
+
console.log(chalk_1.default.white('Model:'), chalk_1.default.blue(model));
|
|
87
|
+
if (balance !== undefined) {
|
|
88
|
+
console.log(chalk_1.default.white('Balance:'), chalk_1.default.yellow(`$${balance.toFixed(4)}`));
|
|
89
|
+
}
|
|
90
|
+
console.log(chalk_1.default.gray('\nType "exit" to quit, or start chatting!'));
|
|
91
|
+
console.log(chalk_1.default.gray('━'.repeat(50)) + '\n');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Format session summary for chat mode
|
|
95
|
+
*/
|
|
96
|
+
function formatSessionSummary(totalTokens, totalCost, messageCount) {
|
|
97
|
+
console.log(chalk_1.default.cyan.bold('\n📊 Session Summary'));
|
|
98
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
99
|
+
console.log(chalk_1.default.white('Messages:'), chalk_1.default.yellow(messageCount));
|
|
100
|
+
console.log(chalk_1.default.white('Total tokens:'), chalk_1.default.yellow(totalTokens.toLocaleString()));
|
|
101
|
+
console.log(chalk_1.default.white('Total cost:'), chalk_1.default.yellow(`$${totalCost.toFixed(4)}`));
|
|
102
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
103
|
+
console.log(chalk_1.default.cyan('\nGoodbye! 👋\n'));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Format config list output
|
|
107
|
+
*/
|
|
108
|
+
function formatConfig(config) {
|
|
109
|
+
console.log(chalk_1.default.cyan.bold('\n⚙️ Configuration'));
|
|
110
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
111
|
+
for (const [key, value] of Object.entries(config)) {
|
|
112
|
+
const displayValue = key === 'apiKey' && value
|
|
113
|
+
? maskApiKey(value)
|
|
114
|
+
: value;
|
|
115
|
+
console.log(chalk_1.default.white(` ${key}:`), chalk_1.default.yellow(String(displayValue)));
|
|
116
|
+
}
|
|
117
|
+
console.log(chalk_1.default.gray('━'.repeat(50)));
|
|
118
|
+
console.log(chalk_1.default.gray(`\nConfig file: ~/.claudeapi/config.json\n`));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Mask API key for display (show first 12 chars + ***)
|
|
122
|
+
*/
|
|
123
|
+
function maskApiKey(key) {
|
|
124
|
+
if (key.length <= 16)
|
|
125
|
+
return '***';
|
|
126
|
+
return key.substring(0, 12) + '***' + key.substring(key.length - 4);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Calculate cost based on token usage and model
|
|
130
|
+
* ClaudeAPI.Dev pricing (80% off Anthropic)
|
|
131
|
+
*/
|
|
132
|
+
function calculateCost(inputTokens, outputTokens, model) {
|
|
133
|
+
const pricing = {
|
|
134
|
+
'opus': { input: 3, output: 15 },
|
|
135
|
+
'sonnet': { input: 3, output: 15 },
|
|
136
|
+
'haiku': { input: 0.8, output: 4 },
|
|
137
|
+
'claude-opus-4-5': { input: 3, output: 15 },
|
|
138
|
+
'claude-sonnet-4-5': { input: 3, output: 15 },
|
|
139
|
+
'claude-haiku-4': { input: 0.8, output: 4 },
|
|
140
|
+
};
|
|
141
|
+
const modelPricing = pricing[model] || pricing['sonnet'];
|
|
142
|
+
const inputCost = (inputTokens / 1_000_000) * modelPricing.input;
|
|
143
|
+
const outputCost = (outputTokens / 1_000_000) * modelPricing.output;
|
|
144
|
+
return inputCost + outputCost;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Show spinner-like loading indicator
|
|
148
|
+
*/
|
|
149
|
+
function showLoading(message = 'Loading...') {
|
|
150
|
+
process.stdout.write(chalk_1.default.gray(message));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Clear loading indicator
|
|
154
|
+
*/
|
|
155
|
+
function clearLoading() {
|
|
156
|
+
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/lib/formatter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAQH,sCAMC;AAKD,kCASC;AAKD,0CAuBC;AAKD,kCAcC;AAKD,sCASC;AAKD,oDAYC;AAKD,oCAaC;AAkCD,kCAEC;AAKD,oCAEC;AArKD,kDAA0B;AAG1B;;GAEG;AACH,SAAgB,aAAa,CAAC,IAA0B,EAAE,OAAe;IACvE,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,KAAY,EAAE,QAAgB,QAAQ;IAChE,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC;IAC7D,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAE3E,O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C,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* History manager for conversation storage
|
|
3
|
+
* Saves and loads chat conversations from ~/.claudemax/history/
|
|
4
|
+
*/
|
|
5
|
+
import { Message } from '../types';
|
|
6
|
+
export interface ConversationHistory {
|
|
7
|
+
id: string;
|
|
8
|
+
timestamp: Date;
|
|
9
|
+
model: string;
|
|
10
|
+
messages: Message[];
|
|
11
|
+
metadata?: {
|
|
12
|
+
totalTokens?: number;
|
|
13
|
+
totalCost?: number;
|
|
14
|
+
messageCount?: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Save a conversation to history
|
|
19
|
+
*/
|
|
20
|
+
export declare function saveConversation(model: string, messages: Message[], metadata?: ConversationHistory['metadata']): string;
|
|
21
|
+
/**
|
|
22
|
+
* Load a conversation from history
|
|
23
|
+
*/
|
|
24
|
+
export declare function loadConversation(id: string): ConversationHistory | null;
|
|
25
|
+
/**
|
|
26
|
+
* List all conversations
|
|
27
|
+
*/
|
|
28
|
+
export declare function listConversations(): ConversationHistory[];
|
|
29
|
+
/**
|
|
30
|
+
* Delete a conversation
|
|
31
|
+
*/
|
|
32
|
+
export declare function deleteConversation(id: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Clear all conversation history
|
|
35
|
+
*/
|
|
36
|
+
export declare function clearAllHistory(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Get conversation summary (first user message)
|
|
39
|
+
*/
|
|
40
|
+
export declare function getConversationSummary(conversation: ConversationHistory): string;
|
|
41
|
+
/**
|
|
42
|
+
* Format timestamp for display
|
|
43
|
+
*/
|
|
44
|
+
export declare function formatTimestamp(date: Date): string;
|
|
45
|
+
//# sourceMappingURL=history-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-manager.d.ts","sourceRoot":"","sources":["../../src/lib/history-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAInC,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE;QACT,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AA6BD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,OAAO,EAAE,EACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAC,UAAU,CAAC,GACzC,MAAM,CAgBR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAiBvE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,mBAAmB,EAAE,CAezD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CActD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAgBxC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,mBAAmB,GAAG,MAAM,CAchF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAalD"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* History manager for conversation storage
|
|
4
|
+
* Saves and loads chat conversations from ~/.claudemax/history/
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.saveConversation = saveConversation;
|
|
8
|
+
exports.loadConversation = loadConversation;
|
|
9
|
+
exports.listConversations = listConversations;
|
|
10
|
+
exports.deleteConversation = deleteConversation;
|
|
11
|
+
exports.clearAllHistory = clearAllHistory;
|
|
12
|
+
exports.getConversationSummary = getConversationSummary;
|
|
13
|
+
exports.formatTimestamp = formatTimestamp;
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const fs_1 = require("fs");
|
|
16
|
+
const config_manager_1 = require("./config-manager");
|
|
17
|
+
const HISTORY_DIR = (0, path_1.join)((0, config_manager_1.getConfigDir)(), 'history');
|
|
18
|
+
/**
|
|
19
|
+
* Ensure history directory exists
|
|
20
|
+
*/
|
|
21
|
+
function ensureHistoryDir() {
|
|
22
|
+
if (!(0, fs_1.existsSync)(HISTORY_DIR)) {
|
|
23
|
+
(0, fs_1.mkdirSync)(HISTORY_DIR, { recursive: true, mode: 0o700 });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generate a unique conversation ID
|
|
28
|
+
*/
|
|
29
|
+
function generateConversationId() {
|
|
30
|
+
const date = new Date();
|
|
31
|
+
const dateStr = date.toISOString().split('T')[0].replace(/-/g, '');
|
|
32
|
+
const timeStr = date.toTimeString().split(' ')[0].replace(/:/g, '');
|
|
33
|
+
const random = Math.random().toString(36).substring(2, 6);
|
|
34
|
+
return `${dateStr}-${timeStr}-${random}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the file path for a conversation
|
|
38
|
+
*/
|
|
39
|
+
function getConversationPath(id) {
|
|
40
|
+
return (0, path_1.join)(HISTORY_DIR, `${id}.json`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Save a conversation to history
|
|
44
|
+
*/
|
|
45
|
+
function saveConversation(model, messages, metadata) {
|
|
46
|
+
ensureHistoryDir();
|
|
47
|
+
const id = generateConversationId();
|
|
48
|
+
const conversation = {
|
|
49
|
+
id,
|
|
50
|
+
timestamp: new Date(),
|
|
51
|
+
model,
|
|
52
|
+
messages,
|
|
53
|
+
metadata,
|
|
54
|
+
};
|
|
55
|
+
const filePath = getConversationPath(id);
|
|
56
|
+
(0, fs_1.writeFileSync)(filePath, JSON.stringify(conversation, null, 2), 'utf-8');
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Load a conversation from history
|
|
61
|
+
*/
|
|
62
|
+
function loadConversation(id) {
|
|
63
|
+
const filePath = getConversationPath(id);
|
|
64
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const data = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
69
|
+
const conversation = JSON.parse(data);
|
|
70
|
+
// Convert timestamp string back to Date
|
|
71
|
+
conversation.timestamp = new Date(conversation.timestamp);
|
|
72
|
+
return conversation;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error('Failed to load conversation:', error);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* List all conversations
|
|
81
|
+
*/
|
|
82
|
+
function listConversations() {
|
|
83
|
+
ensureHistoryDir();
|
|
84
|
+
const files = (0, fs_1.readdirSync)(HISTORY_DIR)
|
|
85
|
+
.filter((file) => file.endsWith('.json'))
|
|
86
|
+
.map((file) => file.replace('.json', ''));
|
|
87
|
+
const conversations = files
|
|
88
|
+
.map((id) => loadConversation(id))
|
|
89
|
+
.filter((conv) => conv !== null);
|
|
90
|
+
// Sort by timestamp (newest first)
|
|
91
|
+
conversations.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
|
|
92
|
+
return conversations;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Delete a conversation
|
|
96
|
+
*/
|
|
97
|
+
function deleteConversation(id) {
|
|
98
|
+
const filePath = getConversationPath(id);
|
|
99
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
(0, fs_1.unlinkSync)(filePath);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error('Failed to delete conversation:', error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Clear all conversation history
|
|
113
|
+
*/
|
|
114
|
+
function clearAllHistory() {
|
|
115
|
+
ensureHistoryDir();
|
|
116
|
+
const files = (0, fs_1.readdirSync)(HISTORY_DIR).filter((file) => file.endsWith('.json'));
|
|
117
|
+
let deletedCount = 0;
|
|
118
|
+
for (const file of files) {
|
|
119
|
+
try {
|
|
120
|
+
(0, fs_1.unlinkSync)((0, path_1.join)(HISTORY_DIR, file));
|
|
121
|
+
deletedCount++;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error(`Failed to delete ${file}:`, error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return deletedCount;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get conversation summary (first user message)
|
|
131
|
+
*/
|
|
132
|
+
function getConversationSummary(conversation) {
|
|
133
|
+
const firstUserMessage = conversation.messages.find((m) => m.role === 'user');
|
|
134
|
+
if (!firstUserMessage) {
|
|
135
|
+
return '[Empty conversation]';
|
|
136
|
+
}
|
|
137
|
+
const content = firstUserMessage.content;
|
|
138
|
+
const maxLength = 60;
|
|
139
|
+
if (content.length <= maxLength) {
|
|
140
|
+
return content;
|
|
141
|
+
}
|
|
142
|
+
return content.substring(0, maxLength) + '...';
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Format timestamp for display
|
|
146
|
+
*/
|
|
147
|
+
function formatTimestamp(date) {
|
|
148
|
+
const now = new Date();
|
|
149
|
+
const diff = now.getTime() - date.getTime();
|
|
150
|
+
const minutes = Math.floor(diff / 60000);
|
|
151
|
+
const hours = Math.floor(diff / 3600000);
|
|
152
|
+
const days = Math.floor(diff / 86400000);
|
|
153
|
+
if (minutes < 1)
|
|
154
|
+
return 'Just now';
|
|
155
|
+
if (minutes < 60)
|
|
156
|
+
return `${minutes}m ago`;
|
|
157
|
+
if (hours < 24)
|
|
158
|
+
return `${hours}h ago`;
|
|
159
|
+
if (days < 7)
|
|
160
|
+
return `${days}d ago`;
|
|
161
|
+
return date.toLocaleDateString();
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=history-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-manager.js","sourceRoot":"","sources":["../../src/lib/history-manager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAmDH,4CAoBC;AAKD,4CAiBC;AAKD,8CAeC;AAKD,gDAcC;AAKD,0CAgBC;AAKD,wDAcC;AAKD,0CAaC;AA5LD,+BAA4B;AAC5B,2BAAiG;AACjG,qDAAgD;AAGhD,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,IAAA,6BAAY,GAAE,EAAE,SAAS,CAAC,CAAC;AAcpD;;GAEG;AACH,SAAS,gBAAgB;IACvB,IAAI,CAAC,IAAA,eAAU,EAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,IAAA,cAAS,EAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB;IAC7B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAA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AI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,IAAU;IACxC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAC;IAEzC,IAAI,OAAO,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC;IACnC,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,OAAO,OAAO,CAAC;IAC3C,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,GAAG,KAAK,OAAO,CAAC;IACvC,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,GAAG,IAAI,OAAO,CAAC;IAEpC,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model name aliases for convenience
|
|
3
|
+
* Maps short names to full Claude model IDs
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a model name to its full ID
|
|
7
|
+
* @param name - Short name or full model ID
|
|
8
|
+
* @returns Full Claude model ID
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveModelName(name: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get all available model aliases
|
|
13
|
+
* @returns Record of aliases to full model IDs
|
|
14
|
+
*/
|
|
15
|
+
export declare function getModelAliases(): Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a name is a recognized alias
|
|
18
|
+
* @param name - Model name to check
|
|
19
|
+
* @returns True if it's a recognized alias
|
|
20
|
+
*/
|
|
21
|
+
export declare function isModelAlias(name: string): boolean;
|
|
22
|
+
//# sourceMappingURL=model-aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-aliases.d.ts","sourceRoot":"","sources":["../../src/lib/model-aliases.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAerD;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Model name aliases for convenience
|
|
4
|
+
* Maps short names to full Claude model IDs
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveModelName = resolveModelName;
|
|
8
|
+
exports.getModelAliases = getModelAliases;
|
|
9
|
+
exports.isModelAlias = isModelAlias;
|
|
10
|
+
const MODEL_ALIASES = {
|
|
11
|
+
opus: 'claude-opus-4-5',
|
|
12
|
+
sonnet: 'claude-sonnet-4-5',
|
|
13
|
+
haiku: 'claude-haiku-4',
|
|
14
|
+
// Legacy models
|
|
15
|
+
'opus-3.5': 'claude-opus-3-5',
|
|
16
|
+
'sonnet-3.5': 'claude-sonnet-3-5',
|
|
17
|
+
'haiku-3.5': 'claude-haiku-3-5',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Resolve a model name to its full ID
|
|
21
|
+
* @param name - Short name or full model ID
|
|
22
|
+
* @returns Full Claude model ID
|
|
23
|
+
*/
|
|
24
|
+
function resolveModelName(name) {
|
|
25
|
+
// If it's already a full model ID (starts with "claude-"), return as-is
|
|
26
|
+
if (name.startsWith('claude-')) {
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
// Look up alias (case-insensitive)
|
|
30
|
+
const lowerName = name.toLowerCase();
|
|
31
|
+
if (lowerName in MODEL_ALIASES) {
|
|
32
|
+
return MODEL_ALIASES[lowerName];
|
|
33
|
+
}
|
|
34
|
+
// If no alias found, assume it's a valid model ID and return as-is
|
|
35
|
+
// (will fail at API level if invalid)
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get all available model aliases
|
|
40
|
+
* @returns Record of aliases to full model IDs
|
|
41
|
+
*/
|
|
42
|
+
function getModelAliases() {
|
|
43
|
+
return { ...MODEL_ALIASES };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a name is a recognized alias
|
|
47
|
+
* @param name - Model name to check
|
|
48
|
+
* @returns True if it's a recognized alias
|
|
49
|
+
*/
|
|
50
|
+
function isModelAlias(name) {
|
|
51
|
+
return name.toLowerCase() in MODEL_ALIASES;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=model-aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-aliases.js","sourceRoot":"","sources":["../../src/lib/model-aliases.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiBH,4CAeC;AAMD,0CAEC;AAOD,oCAEC;AA/CD,MAAM,aAAa,GAA2B;IAC5C,IAAI,EAAE,iBAAiB;IACvB,MAAM,EAAE,mBAAmB;IAC3B,KAAK,EAAE,gBAAgB;IACvB,gBAAgB;IAChB,UAAU,EAAE,iBAAiB;IAC7B,YAAY,EAAE,mBAAmB;IACjC,WAAW,EAAE,kBAAkB;CAChC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,wEAAwE;IACxE,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mCAAmC;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,SAAS,IAAI,aAAa,EAAE,CAAC;QAC/B,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,mEAAmE;IACnE,sCAAsC;IACtC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,WAAW,EAAE,IAAI,aAAa,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream handler for Server-Sent Events (SSE)
|
|
3
|
+
* Parses SSE data from ClaudeAPI.Dev streaming responses
|
|
4
|
+
*/
|
|
5
|
+
import { StreamEvent } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Parse SSE stream from ReadableStream
|
|
8
|
+
* @param body - Response body ReadableStream
|
|
9
|
+
* @yields Parsed stream events
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseSSEStream(body: ReadableStream<Uint8Array>): AsyncGenerator<StreamEvent>;
|
|
12
|
+
/**
|
|
13
|
+
* Extract text content from stream events
|
|
14
|
+
* @param events - Async generator of stream events
|
|
15
|
+
* @yields Text delta strings
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractTextFromStream(events: AsyncGenerator<StreamEvent>): AsyncGenerator<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Collect usage information from stream events
|
|
20
|
+
* @param events - Async generator of stream events
|
|
21
|
+
* @returns Usage stats (input/output tokens)
|
|
22
|
+
*/
|
|
23
|
+
export declare function collectUsageFromStream(events: AsyncGenerator<StreamEvent>): Promise<{
|
|
24
|
+
inputTokens: number;
|
|
25
|
+
outputTokens: number;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Process stream with callbacks
|
|
29
|
+
* @param events - Async generator of stream events
|
|
30
|
+
* @param onText - Callback for text deltas
|
|
31
|
+
* @param onUsage - Callback for usage stats
|
|
32
|
+
*/
|
|
33
|
+
export declare function processStream(events: AsyncGenerator<StreamEvent>, onText: (text: string) => void, onUsage?: (usage: {
|
|
34
|
+
inputTokens: number;
|
|
35
|
+
outputTokens: number;
|
|
36
|
+
}) => void): Promise<void>;
|
|
37
|
+
//# sourceMappingURL=stream-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../src/lib/stream-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,wBAAuB,cAAc,CACnC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAC/B,cAAc,CAAC,WAAW,CAAC,CAoC7B;AAED;;;;GAIG;AACH,wBAAuB,qBAAqB,CAC1C,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,GAClC,cAAc,CAAC,MAAM,CAAC,CAMxB;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,GAClC,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAaxD;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,EACnC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,KAAK,IAAI,GACvE,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|