@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,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* History command - Manage conversation history
|
|
4
|
+
* List, load, and clear saved conversations
|
|
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.historyCommand = void 0;
|
|
11
|
+
const commander_1 = require("commander");
|
|
12
|
+
const history_manager_1 = require("../lib/history-manager");
|
|
13
|
+
const formatter_1 = require("../lib/formatter");
|
|
14
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
+
exports.historyCommand = new commander_1.Command('history')
|
|
16
|
+
.description('Manage conversation history')
|
|
17
|
+
.addCommand(createListCommand())
|
|
18
|
+
.addCommand(createShowCommand())
|
|
19
|
+
.addCommand(createDeleteCommand())
|
|
20
|
+
.addCommand(createClearCommand());
|
|
21
|
+
/**
|
|
22
|
+
* history list - List all saved conversations
|
|
23
|
+
*/
|
|
24
|
+
function createListCommand() {
|
|
25
|
+
return new commander_1.Command('list')
|
|
26
|
+
.description('List all saved conversations')
|
|
27
|
+
.option('-n, --limit <number>', 'Limit number of results', '10')
|
|
28
|
+
.action((options) => {
|
|
29
|
+
try {
|
|
30
|
+
const conversations = (0, history_manager_1.listConversations)();
|
|
31
|
+
const limit = parseInt(options.limit, 10) || 10;
|
|
32
|
+
const limited = conversations.slice(0, limit);
|
|
33
|
+
if (limited.length === 0) {
|
|
34
|
+
console.log(chalk_1.default.yellow('\nNo conversation history found.'));
|
|
35
|
+
console.log(chalk_1.default.gray('Start a chat with: claudemax chat\n'));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.log(chalk_1.default.cyan.bold('\nš Conversation History'));
|
|
39
|
+
console.log(chalk_1.default.gray('ā'.repeat(80)));
|
|
40
|
+
for (const conv of limited) {
|
|
41
|
+
const summary = (0, history_manager_1.getConversationSummary)(conv);
|
|
42
|
+
const timestamp = (0, history_manager_1.formatTimestamp)(conv.timestamp);
|
|
43
|
+
const messageCount = conv.messages.length;
|
|
44
|
+
console.log(chalk_1.default.white('\nID:'), chalk_1.default.yellow(conv.id));
|
|
45
|
+
console.log(chalk_1.default.white('Date:'), chalk_1.default.gray(timestamp), chalk_1.default.white('Model:'), chalk_1.default.blue(conv.model), chalk_1.default.white('Messages:'), chalk_1.default.gray(messageCount));
|
|
46
|
+
console.log(chalk_1.default.white('Summary:'), chalk_1.default.gray(summary));
|
|
47
|
+
}
|
|
48
|
+
console.log(chalk_1.default.gray('\nā'.repeat(80)));
|
|
49
|
+
if (conversations.length > limit) {
|
|
50
|
+
console.log(chalk_1.default.gray(`\nShowing ${limit} of ${conversations.length} conversations. Use --limit to see more.\n`));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
(0, formatter_1.formatError)(error);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* history show - Show a specific conversation
|
|
64
|
+
*/
|
|
65
|
+
function createShowCommand() {
|
|
66
|
+
return new commander_1.Command('show')
|
|
67
|
+
.description('Show a specific conversation')
|
|
68
|
+
.argument('<id>', 'Conversation ID')
|
|
69
|
+
.action((id) => {
|
|
70
|
+
try {
|
|
71
|
+
const conversation = (0, history_manager_1.loadConversation)(id);
|
|
72
|
+
if (!conversation) {
|
|
73
|
+
console.error(chalk_1.default.red(`\nā Conversation not found: ${id}\n`));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
console.log(chalk_1.default.cyan.bold('\nš¬ Conversation'));
|
|
77
|
+
console.log(chalk_1.default.gray('ā'.repeat(80)));
|
|
78
|
+
console.log(chalk_1.default.white('ID:'), chalk_1.default.yellow(conversation.id));
|
|
79
|
+
console.log(chalk_1.default.white('Date:'), chalk_1.default.gray(conversation.timestamp.toLocaleString()));
|
|
80
|
+
console.log(chalk_1.default.white('Model:'), chalk_1.default.blue(conversation.model));
|
|
81
|
+
console.log(chalk_1.default.white('Messages:'), chalk_1.default.gray(conversation.messages.length));
|
|
82
|
+
if (conversation.metadata) {
|
|
83
|
+
const { totalTokens, totalCost, messageCount } = conversation.metadata;
|
|
84
|
+
if (totalTokens) {
|
|
85
|
+
console.log(chalk_1.default.white('Tokens:'), chalk_1.default.gray(totalTokens.toLocaleString()));
|
|
86
|
+
}
|
|
87
|
+
if (totalCost) {
|
|
88
|
+
console.log(chalk_1.default.white('Cost:'), chalk_1.default.gray(`$${totalCost.toFixed(4)}`));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
console.log(chalk_1.default.gray('\nā'.repeat(80)));
|
|
92
|
+
// Display messages
|
|
93
|
+
for (const message of conversation.messages) {
|
|
94
|
+
if (message.role === 'user') {
|
|
95
|
+
console.log(chalk_1.default.blue.bold('\nYou:'));
|
|
96
|
+
console.log(chalk_1.default.white(message.content));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.log(chalk_1.default.green.bold('\nAssistant:'));
|
|
100
|
+
console.log(chalk_1.default.white(message.content));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log(chalk_1.default.gray('\nā'.repeat(80) + '\n'));
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
(0, formatter_1.formatError)(error);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* history delete - Delete a conversation
|
|
113
|
+
*/
|
|
114
|
+
function createDeleteCommand() {
|
|
115
|
+
return new commander_1.Command('delete')
|
|
116
|
+
.description('Delete a conversation')
|
|
117
|
+
.argument('<id>', 'Conversation ID')
|
|
118
|
+
.action((id) => {
|
|
119
|
+
try {
|
|
120
|
+
const success = (0, history_manager_1.deleteConversation)(id);
|
|
121
|
+
if (!success) {
|
|
122
|
+
console.error(chalk_1.default.red(`\nā Conversation not found: ${id}\n`));
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
console.log(chalk_1.default.green('ā Conversation deleted'));
|
|
126
|
+
console.log(chalk_1.default.gray(` ID: ${id}\n`));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
(0, formatter_1.formatError)(error);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* history clear - Clear all conversation history
|
|
136
|
+
*/
|
|
137
|
+
function createClearCommand() {
|
|
138
|
+
return new commander_1.Command('clear')
|
|
139
|
+
.description('Clear all conversation history')
|
|
140
|
+
.option('-f, --force', 'Skip confirmation', false)
|
|
141
|
+
.action(async (options) => {
|
|
142
|
+
try {
|
|
143
|
+
if (!options.force) {
|
|
144
|
+
// Simple confirmation (without prompts library for now)
|
|
145
|
+
console.log(chalk_1.default.yellow('\nā ļø This will delete all conversation history.'));
|
|
146
|
+
console.log(chalk_1.default.gray('Use --force to skip this confirmation.\n'));
|
|
147
|
+
process.exit(0);
|
|
148
|
+
}
|
|
149
|
+
const deletedCount = (0, history_manager_1.clearAllHistory)();
|
|
150
|
+
console.log(chalk_1.default.green(`ā Cleared ${deletedCount} conversations\n`));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
(0, formatter_1.formatError)(error);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/commands/history.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,yCAAoC;AACpC,4DAOgC;AAChC,gDAA+C;AAC/C,kDAA0B;AAEb,QAAA,cAAc,GAAG,IAAI,mBAAO,CAAC,SAAS,CAAC;KACjD,WAAW,CAAC,6BAA6B,CAAC;KAC1C,UAAU,CAAC,iBAAiB,EAAE,CAAC;KAC/B,UAAU,CAAC,iBAAiB,EAAE,CAAC;KAC/B,UAAU,CAAC,mBAAmB,EAAE,CAAC;KACjC,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAC;AAEpC;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO,IAAI,mBAAO,CAAC,MAAM,CAAC;SACvB,WAAW,CAAC,8BAA8B,CAAC;SAC3C,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,EAAE,IAAI,CAAC;SAC/D,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAClB,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,IAAA,mCAAiB,GAAE,CAAC;YAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;YAChD,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAE9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,kCAAkC,CAAC,CAAC,CAAC;gBAC9D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,CAAC;gBAC/D,OAAO;YACT,CAAC;YAED,OAAO,CAA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
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Usage command - Check account balance and usage statistics
|
|
4
|
+
* Fetches data from /api/v1/user endpoint
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.usageCommand = void 0;
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const api_client_1 = require("../lib/api-client");
|
|
10
|
+
const config_manager_1 = require("../lib/config-manager");
|
|
11
|
+
const formatter_1 = require("../lib/formatter");
|
|
12
|
+
exports.usageCommand = new commander_1.Command('usage')
|
|
13
|
+
.description('Check account balance and usage statistics')
|
|
14
|
+
.option('-d, --detailed', 'Show detailed usage breakdown', false)
|
|
15
|
+
.action(async (options) => {
|
|
16
|
+
try {
|
|
17
|
+
// Load and validate config
|
|
18
|
+
const config = (0, config_manager_1.loadConfig)();
|
|
19
|
+
const error = (0, config_manager_1.validateConfig)(config);
|
|
20
|
+
if (error) {
|
|
21
|
+
(0, formatter_1.formatError)(new Error(error), 'configuration_error');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
// Create API client
|
|
25
|
+
const client = new api_client_1.ClaudeAPIClient(config.apiKey, config.baseUrl);
|
|
26
|
+
// Fetch user stats
|
|
27
|
+
const stats = await client.getUserStats();
|
|
28
|
+
// Display stats
|
|
29
|
+
(0, formatter_1.formatUserStats)(stats);
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
(0, formatter_1.formatError)(error);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/commands/usage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAAoC;AACpC,kDAAoD;AACpD,0DAAmE;AACnE,gDAAgE;AAEnD,QAAA,YAAY,GAAG,IAAI,mBAAO,CAAC,OAAO,CAAC;KAC7C,WAAW,CAAC,4CAA4C,CAAC;KACzD,MAAM,CAAC,gBAAgB,EAAE,+BAA+B,EAAE,KAAK,CAAC;KAChE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,CAAC;QACH,2BAA2B;QAC3B,MAAM,MAAM,GAAG,IAAA,2BAAU,GAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,IAAA,+BAAc,EAAC,MAAM,CAAC,CAAC;QACrC,IAAI,KAAK,EAAE,CAAC;YACV,IAAA,uBAAW,EAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,qBAAqB,CAAC,CAAC;YACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,oBAAoB;QACpB,MAAM,MAAM,GAAG,IAAI,4BAAe,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAElE,mBAAmB;QACnB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;QAE1C,gBAAgB;QAChB,IAAA,2BAAe,EAAC,KAAK,CAAC,CAAC;QAEvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,uBAAW,EAAC,KAAc,CAAC,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;GAGG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* ClaudeAPI CLI - Main entry point
|
|
5
|
+
* Command-line interface for ClaudeAPI.Dev
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const ask_1 = require("./commands/ask");
|
|
10
|
+
const chat_1 = require("./commands/chat");
|
|
11
|
+
const config_1 = require("./commands/config");
|
|
12
|
+
const usage_1 = require("./commands/usage");
|
|
13
|
+
const history_1 = require("./commands/history");
|
|
14
|
+
const program = new commander_1.Command();
|
|
15
|
+
program
|
|
16
|
+
.name('claudemax')
|
|
17
|
+
.description('Official CLI tool for ClaudeAPI.Dev - interact with Claude AI from your terminal')
|
|
18
|
+
.version('1.0.0');
|
|
19
|
+
// Register commands
|
|
20
|
+
program.addCommand(ask_1.askCommand);
|
|
21
|
+
program.addCommand(chat_1.chatCommand);
|
|
22
|
+
program.addCommand(config_1.configCommand);
|
|
23
|
+
program.addCommand(usage_1.usageCommand);
|
|
24
|
+
program.addCommand(history_1.historyCommand);
|
|
25
|
+
// Parse arguments
|
|
26
|
+
program.parse(process.argv);
|
|
27
|
+
// Show help if no command provided
|
|
28
|
+
if (!process.argv.slice(2).length) {
|
|
29
|
+
program.outputHelp();
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA;;;GAGG;;AAEH,yCAAoC;AACpC,wCAA4C;AAC5C,0CAA8C;AAC9C,8CAAkD;AAClD,4CAAgD;AAChD,gDAAoD;AAEpD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,kFAAkF,CAAC;KAC/F,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,oBAAoB;AACpB,OAAO,CAAC,UAAU,CAAC,gBAAU,CAAC,CAAC;AAC/B,OAAO,CAAC,UAAU,CAAC,kBAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,sBAAa,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,oBAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,wBAAc,CAAC,CAAC;AAEnC,kBAAkB;AAClB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,mCAAmC;AACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client for ClaudeAPI.Dev
|
|
3
|
+
* Handles HTTP requests with authentication and error handling
|
|
4
|
+
*/
|
|
5
|
+
import { MessageRequest, MessageResponse, UserStats, StreamEvent } from '../types';
|
|
6
|
+
export declare class ClaudeAPIClient {
|
|
7
|
+
private apiKey;
|
|
8
|
+
private baseUrl;
|
|
9
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Send a non-streaming message request
|
|
12
|
+
*/
|
|
13
|
+
sendMessage(params: MessageRequest): Promise<MessageResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Stream a message request (returns AsyncGenerator)
|
|
16
|
+
*/
|
|
17
|
+
streamMessage(params: MessageRequest): AsyncGenerator<StreamEvent>;
|
|
18
|
+
/**
|
|
19
|
+
* Get user stats and usage information
|
|
20
|
+
*/
|
|
21
|
+
getUserStats(): Promise<UserStats>;
|
|
22
|
+
/**
|
|
23
|
+
* Handle error responses from API
|
|
24
|
+
*/
|
|
25
|
+
private handleErrorResponse;
|
|
26
|
+
}
|
|
27
|
+
export declare class APIRequestError extends Error {
|
|
28
|
+
type: string;
|
|
29
|
+
constructor(message: string, type: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class AuthenticationError extends Error {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
export declare class InvalidRequestError extends Error {
|
|
35
|
+
constructor(message: string);
|
|
36
|
+
}
|
|
37
|
+
export declare class RateLimitError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class InsufficientBalanceError extends Error {
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAY,WAAW,EAAE,MAAM,UAAU,CAAC;AAG7F,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,MAAoC;IAKzE;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAiBnE;;OAEG;IACI,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;IAsBzE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAgBxC;;OAEG;YACW,mBAAmB;CAyBlC;AAGD,qBAAa,eAAgB,SAAQ,KAAK;IACJ,IAAI,EAAE,MAAM;gBAApC,OAAO,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM;CAIjD;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Client for ClaudeAPI.Dev
|
|
4
|
+
* Handles HTTP requests with authentication and error handling
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.InsufficientBalanceError = exports.RateLimitError = exports.InvalidRequestError = exports.AuthenticationError = exports.APIRequestError = exports.ClaudeAPIClient = void 0;
|
|
8
|
+
const stream_handler_1 = require("./stream-handler");
|
|
9
|
+
class ClaudeAPIClient {
|
|
10
|
+
apiKey;
|
|
11
|
+
baseUrl;
|
|
12
|
+
constructor(apiKey, baseUrl = 'https://api.claudeapi.dev') {
|
|
13
|
+
this.apiKey = apiKey;
|
|
14
|
+
this.baseUrl = baseUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Send a non-streaming message request
|
|
18
|
+
*/
|
|
19
|
+
async sendMessage(params) {
|
|
20
|
+
const response = await fetch(`${this.baseUrl}/api/v1/messages`, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify({ ...params, stream: false }),
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
await this.handleErrorResponse(response);
|
|
30
|
+
}
|
|
31
|
+
return response.json();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Stream a message request (returns AsyncGenerator)
|
|
35
|
+
*/
|
|
36
|
+
async *streamMessage(params) {
|
|
37
|
+
const response = await fetch(`${this.baseUrl}/api/v1/messages`, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
42
|
+
},
|
|
43
|
+
body: JSON.stringify({ ...params, stream: true }),
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
await this.handleErrorResponse(response);
|
|
47
|
+
}
|
|
48
|
+
if (!response.body) {
|
|
49
|
+
throw new Error('No response body');
|
|
50
|
+
}
|
|
51
|
+
// Parse SSE stream
|
|
52
|
+
yield* (0, stream_handler_1.parseSSEStream)(response.body);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get user stats and usage information
|
|
56
|
+
*/
|
|
57
|
+
async getUserStats() {
|
|
58
|
+
const response = await fetch(`${this.baseUrl}/api/v1/user`, {
|
|
59
|
+
method: 'GET',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
await this.handleErrorResponse(response);
|
|
67
|
+
}
|
|
68
|
+
return response.json();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Handle error responses from API
|
|
72
|
+
*/
|
|
73
|
+
async handleErrorResponse(response) {
|
|
74
|
+
let errorData;
|
|
75
|
+
try {
|
|
76
|
+
errorData = (await response.json());
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
|
|
80
|
+
}
|
|
81
|
+
const { error } = errorData;
|
|
82
|
+
// Throw specific error types
|
|
83
|
+
switch (error.type) {
|
|
84
|
+
case 'authentication_error':
|
|
85
|
+
throw new AuthenticationError(error.message);
|
|
86
|
+
case 'invalid_request_error':
|
|
87
|
+
throw new InvalidRequestError(error.message);
|
|
88
|
+
case 'rate_limit_error':
|
|
89
|
+
throw new RateLimitError(error.message);
|
|
90
|
+
case 'insufficient_balance':
|
|
91
|
+
throw new InsufficientBalanceError(error.message);
|
|
92
|
+
default:
|
|
93
|
+
throw new APIRequestError(error.message, error.type);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.ClaudeAPIClient = ClaudeAPIClient;
|
|
98
|
+
// Custom error classes
|
|
99
|
+
class APIRequestError extends Error {
|
|
100
|
+
type;
|
|
101
|
+
constructor(message, type) {
|
|
102
|
+
super(message);
|
|
103
|
+
this.type = type;
|
|
104
|
+
this.name = 'APIRequestError';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.APIRequestError = APIRequestError;
|
|
108
|
+
class AuthenticationError extends Error {
|
|
109
|
+
constructor(message) {
|
|
110
|
+
super(message);
|
|
111
|
+
this.name = 'AuthenticationError';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.AuthenticationError = AuthenticationError;
|
|
115
|
+
class InvalidRequestError extends Error {
|
|
116
|
+
constructor(message) {
|
|
117
|
+
super(message);
|
|
118
|
+
this.name = 'InvalidRequestError';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.InvalidRequestError = InvalidRequestError;
|
|
122
|
+
class RateLimitError extends Error {
|
|
123
|
+
constructor(message) {
|
|
124
|
+
super(message);
|
|
125
|
+
this.name = 'RateLimitError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.RateLimitError = RateLimitError;
|
|
129
|
+
class InsufficientBalanceError extends Error {
|
|
130
|
+
constructor(message) {
|
|
131
|
+
super(message);
|
|
132
|
+
this.name = 'InsufficientBalanceError';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.InsufficientBalanceError = InsufficientBalanceError;
|
|
136
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,qDAAkD;AAElD,MAAa,eAAe;IAClB,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAc,EAAE,UAAkB,2BAA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config.json
|
|
4
|
+
*/
|
|
5
|
+
import { Config, PartialConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Get the configuration directory path
|
|
8
|
+
*/
|
|
9
|
+
export declare function getConfigDir(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Get the configuration file path
|
|
12
|
+
*/
|
|
13
|
+
export declare function getConfigPath(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Load configuration from file
|
|
16
|
+
* Creates default config if file doesn't exist
|
|
17
|
+
*/
|
|
18
|
+
export declare function loadConfig(): Config;
|
|
19
|
+
/**
|
|
20
|
+
* Save configuration to file
|
|
21
|
+
* @param config - Full or partial config to save
|
|
22
|
+
*/
|
|
23
|
+
export declare function saveConfig(config: Config | PartialConfig): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reset configuration to defaults
|
|
26
|
+
*/
|
|
27
|
+
export declare function resetConfig(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get a specific config value
|
|
30
|
+
* @param key - Config key to retrieve
|
|
31
|
+
* @returns Config value or undefined
|
|
32
|
+
*/
|
|
33
|
+
export declare function getConfigValue<K extends keyof Config>(key: K): Config[K] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Set a specific config value
|
|
36
|
+
* @param key - Config key to set
|
|
37
|
+
* @param value - Value to set
|
|
38
|
+
*/
|
|
39
|
+
export declare function setConfigValue<K extends keyof Config>(key: K, value: Config[K]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Validate config (check required fields)
|
|
42
|
+
* @returns Error message if invalid, null if valid
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateConfig(config: Config): string | null;
|
|
45
|
+
//# sourceMappingURL=config-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-manager.d.ts","sourceRoot":"","sources":["../../src/lib/config-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAajD;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAWD;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAuBnC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAkB/D;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAGpF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAIrF;AASD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsB5D"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration manager for ClaudeAPI CLI
|
|
4
|
+
* Handles reading/writing config file at ~/.claudemax/config.json
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getConfigDir = getConfigDir;
|
|
8
|
+
exports.getConfigPath = getConfigPath;
|
|
9
|
+
exports.loadConfig = loadConfig;
|
|
10
|
+
exports.saveConfig = saveConfig;
|
|
11
|
+
exports.resetConfig = resetConfig;
|
|
12
|
+
exports.getConfigValue = getConfigValue;
|
|
13
|
+
exports.setConfigValue = setConfigValue;
|
|
14
|
+
exports.validateConfig = validateConfig;
|
|
15
|
+
const os_1 = require("os");
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const CONFIG_DIR = (0, path_1.join)((0, os_1.homedir)(), '.claudemax');
|
|
19
|
+
const CONFIG_FILE = (0, path_1.join)(CONFIG_DIR, 'config.json');
|
|
20
|
+
const DEFAULT_CONFIG = {
|
|
21
|
+
apiKey: '',
|
|
22
|
+
baseUrl: 'https://api.claudeapi.dev',
|
|
23
|
+
defaultModel: 'claude-sonnet-4-5',
|
|
24
|
+
maxTokens: 4096,
|
|
25
|
+
temperature: 1.0,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Get the configuration directory path
|
|
29
|
+
*/
|
|
30
|
+
function getConfigDir() {
|
|
31
|
+
return CONFIG_DIR;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the configuration file path
|
|
35
|
+
*/
|
|
36
|
+
function getConfigPath() {
|
|
37
|
+
return CONFIG_FILE;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Ensure config directory exists
|
|
41
|
+
*/
|
|
42
|
+
function ensureConfigDir() {
|
|
43
|
+
if (!(0, fs_1.existsSync)(CONFIG_DIR)) {
|
|
44
|
+
(0, fs_1.mkdirSync)(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load configuration from file
|
|
49
|
+
* Creates default config if file doesn't exist
|
|
50
|
+
*/
|
|
51
|
+
function loadConfig() {
|
|
52
|
+
ensureConfigDir();
|
|
53
|
+
if (!(0, fs_1.existsSync)(CONFIG_FILE)) {
|
|
54
|
+
// Create default config file
|
|
55
|
+
saveConfig(DEFAULT_CONFIG);
|
|
56
|
+
return { ...DEFAULT_CONFIG };
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const data = (0, fs_1.readFileSync)(CONFIG_FILE, 'utf-8');
|
|
60
|
+
const config = JSON.parse(data);
|
|
61
|
+
// Merge with defaults to ensure all fields exist
|
|
62
|
+
return {
|
|
63
|
+
...DEFAULT_CONFIG,
|
|
64
|
+
...config,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Failed to load config file:', error);
|
|
69
|
+
console.error('Using default configuration');
|
|
70
|
+
return { ...DEFAULT_CONFIG };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Save configuration to file
|
|
75
|
+
* @param config - Full or partial config to save
|
|
76
|
+
*/
|
|
77
|
+
function saveConfig(config) {
|
|
78
|
+
ensureConfigDir();
|
|
79
|
+
let finalConfig;
|
|
80
|
+
if (isPartialConfig(config)) {
|
|
81
|
+
// Merge with existing config
|
|
82
|
+
const existingConfig = (0, fs_1.existsSync)(CONFIG_FILE) ? loadConfig() : DEFAULT_CONFIG;
|
|
83
|
+
finalConfig = { ...existingConfig, ...config };
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
finalConfig = config;
|
|
87
|
+
}
|
|
88
|
+
const data = JSON.stringify(finalConfig, null, 2);
|
|
89
|
+
(0, fs_1.writeFileSync)(CONFIG_FILE, data, 'utf-8');
|
|
90
|
+
// Set secure permissions (600 = rw-------)
|
|
91
|
+
(0, fs_1.chmodSync)(CONFIG_FILE, 0o600);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reset configuration to defaults
|
|
95
|
+
*/
|
|
96
|
+
function resetConfig() {
|
|
97
|
+
saveConfig(DEFAULT_CONFIG);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get a specific config value
|
|
101
|
+
* @param key - Config key to retrieve
|
|
102
|
+
* @returns Config value or undefined
|
|
103
|
+
*/
|
|
104
|
+
function getConfigValue(key) {
|
|
105
|
+
const config = loadConfig();
|
|
106
|
+
return config[key];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set a specific config value
|
|
110
|
+
* @param key - Config key to set
|
|
111
|
+
* @param value - Value to set
|
|
112
|
+
*/
|
|
113
|
+
function setConfigValue(key, value) {
|
|
114
|
+
const config = loadConfig();
|
|
115
|
+
config[key] = value;
|
|
116
|
+
saveConfig(config);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if config is partial (type guard)
|
|
120
|
+
*/
|
|
121
|
+
function isPartialConfig(config) {
|
|
122
|
+
return !('apiKey' in config && 'baseUrl' in config && 'defaultModel' in config);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validate config (check required fields)
|
|
126
|
+
* @returns Error message if invalid, null if valid
|
|
127
|
+
*/
|
|
128
|
+
function validateConfig(config) {
|
|
129
|
+
if (!config.apiKey) {
|
|
130
|
+
return 'API key is required. Run: claudemax config set api-key YOUR_KEY';
|
|
131
|
+
}
|
|
132
|
+
if (!config.baseUrl) {
|
|
133
|
+
return 'Base URL is required';
|
|
134
|
+
}
|
|
135
|
+
if (!config.defaultModel) {
|
|
136
|
+
return 'Default model is required';
|
|
137
|
+
}
|
|
138
|
+
if (config.maxTokens < 1 || config.maxTokens > 8192) {
|
|
139
|
+
return 'Max tokens must be between 1 and 8192';
|
|
140
|
+
}
|
|
141
|
+
if (config.temperature < 0 || config.temperature > 1) {
|
|
142
|
+
return 'Temperature must be between 0 and 1';
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=config-manager.js.map
|